From 2ee2828719f9a641cccbb150670b7c42bb5239ea Mon Sep 17 00:00:00 2001 From: andrie Date: Sun, 20 Aug 2023 00:17:49 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20gh-pages=20from=20@=20rstudio/?= =?UTF-8?q?r-manuals@c75dd7962caab3caebfab9b3543c220ac0c24b72=20?= =?UTF-8?q?=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- r-exts/Tidying-and-profiling-R-code.html | 2 +- r-exts/search.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/r-exts/Tidying-and-profiling-R-code.html b/r-exts/Tidying-and-profiling-R-code.html index 9dbe7ea..f2eb5d7 100644 --- a/r-exts/Tidying-and-profiling-R-code.html +++ b/r-exts/Tidying-and-profiling-R-code.html @@ -569,7 +569,7 @@

3.4.6 Windows

-

Very Sleepy (https://github.com/VerySleepy/verysleepy) has been used.

+

Very Sleepy (https://github.com/VerySleepy/verysleepy) has been used. There were problems with accessing the debug information, but the best results which included function names were obtained by attaching the profiler to an existing Rterm process, either via GUI or using /a: (pid obtained via Sys.getpid()).

Footnotes

diff --git a/r-exts/search.json b/r-exts/search.json index 460d687..204c0ac 100644 --- a/r-exts/search.json +++ b/r-exts/search.json @@ -228,7 +228,7 @@ "href": "Tidying-and-profiling-R-code.html#profiling-compiled-code", "title": "3  Tidying and profiling R code", "section": "3.4 Profiling compiled code", - "text": "3.4 Profiling compiled code\nProfiling compiled code is highly system-specific, but this section contains some hints gleaned from various R users. Some methods need to be different for a compiled executable and for dynamic/shared libraries/objects as used by R packages.\nThis chapter is based on reports from users and the information may not be current.\n\n3.4.1 Linux\nOptions include using sprof for a shared object, and oprofile (see https://oprofile.sourceforge.io/news/) and perf (see https://perf.wiki.kernel.org/index.php/Tutorial) for any executable or shared object. These seem less widely supplied than they used to be. There is also ‘Google Performance Tools’, also known as gperftools or google-perftools.\nAll of these work best when R and any packages have been built with debugging symbols.\n\n\n3.4.2 perf\nThis seems the most widely distributed tool. Here is an example on x86_64 Linux using R 4.3.1 built with LTO.\nAt its simplest\nperf record R -f tests/Examples/stats-Ex.R\nperf report --sort=dso\nperf report --sort=srcfile\nrm perf.data*\nThe first report is\n 75.67% R\n 9.25% libc.so.6\n 4.87% [unknown]\n 3.75% libz.so.1.2.11\n 3.37% stats.so\n 1.17% libm.so.6\n 0.63% libtirpc.so.3.0.0\n 0.41% graphics.so\n 0.30% grDevices.so\n 0.20% libRblas.so\n 0.09% libpcre2-8.so.0.11.0\n 0.07% methods.so\n ...\nwhich shows which shared libraries (DSOs) the time was spent in.\nperf annotate can be used on an application built with GCC and -ggdb: it interleaves disassembled and source code.\n\n\n3.4.3 oprofile and operf\nThe oprofile project has two modes of operation. Since version 0.9.8 (August 2012), the preferred mode is to use operf, so we discuss only that.\nLet us look at the boot example from §3.2 on x86_64 Linux using R 4.3.1.\nThis can be run under operf and analysed by commands like\noperf R -f boot.R\nopreport\nopreport -l /path/to/R_HOME/bin/exec/R\nopreport -l /path/to/R_HOME/library/stats/src/stats.so\nopannotate --source /path/to/R_HOME/bin/exec/R\nThe first line had to be done as root.\nThe first report shows in which library (etc) the time was spent:\n CPU_CLK_UNHALT...|\n samples| %|\n ------------------\n 278341 91.9947 R\n 18290 6.0450 libc.so.6\n 2277 0.7526 kallsyms\n 1426 0.4713 stats.so\n 739 0.2442 libRblas.so\n 554 0.1831 libz.so.1.2.11\n 373 0.1233 libm.so.6\n 352 0.1163 libtirpc.so.3.0.0\n 153 0.0506 ld-linux-x86-64.so.2\n 12 0.0040 methods.so\n(kallsyms is the kernel.)\nThe rest of the output is voluminous, and only extracts are shown.\nMost of the time within R is spent in\nsamples % image name symbol name\n52955 19.0574 R bcEval.lto_priv.0\n16484 5.9322 R Rf_allocVector3\n14224 5.1189 R Rf_findVarInFrame3\n12581 4.5276 R CONS_NR\n8289 2.9830 R Rf_matchArgs_NR\n8034 2.8913 R Rf_cons\n7114 2.5602 R R_gc_internal.lto_priv.0\n6552 2.3579 R Rf_eval\n5969 2.1481 R VECTOR_ELT\n5684 2.0456 R Rf_applyClosure\n5497 1.9783 R findVarLocInFrame.part.0.lto_priv.0\n4827 1.7371 R Rf_mkPROMISE\n4609 1.6587 R Rf_install\n4317 1.5536 R Rf_findFun3\n4035 1.4521 R getvar.lto_priv.0\n3491 1.2563 R SETCAR\n3179 1.1441 R Rf_defineVar\n2892 1.0408 R duplicate1.lto_priv.0\nand in stats.so\nsamples % image name symbol name\n285 24.4845 stats.so termsform\n284 24.3986 stats.so numeric_deriv\n213 18.2990 stats.so modelframe\n114 9.7938 stats.so nls_iter\n55 4.7251 stats.so ExtractVars\n47 4.0378 stats.so EncodeVars\n37 3.1787 stats.so getListElement\n32 2.7491 stats.so TrimRepeats\n25 2.1478 stats.so InstallVar\n20 1.7182 stats.so MatchVar\n20 1.7182 stats.so isZeroOne\n15 1.2887 stats.so ConvInfoMsg.isra.0\nThe profiling data is by default stored in sub-directory oprofile_data of the current directory, which can be removed at the end of the session.\n\n\n3.4.4 sprof\nYou can select shared objects to be profiled with sprof by setting the environment variable LD_PROFILE. For example\n% setenv LD_PROFILE /path/to/R_HOME/library/stats/libs/stats.so\n% R -f boot.R\n% sprof /path/to/R_HOME/library/stats/libs/stats.so \\\n /var/tmp/path/to/R_HOME/library/stats/libs/stats.so.profile\n\nFlat profile:\n\nEach sample counts as 0.01 seconds.\n % cumulative self self total\n time seconds seconds calls us/call us/call name\n 76.19 0.32 0.32 0 0.00 numeric_deriv\n 16.67 0.39 0.07 0 0.00 nls_iter\n 7.14 0.42 0.03 0 0.00 getListElement\n\n... to clean up ...\nrm /var/tmp/path/to/R_HOME/library/stats/libs/stats.so.profile\nIt is possible that root access will be needed to create the directories used for the profile data.\n\n\n3.4.5 macOS\nDevelopers have recommended Instruments (part of Xcode, see https://help.apple.com/instruments/mac/current/), This had a command-line version prior to macOS 12.\n\n\n3.4.6 Windows\nVery Sleepy (https://github.com/VerySleepy/verysleepy) has been used.\nFootnotes" + "text": "3.4 Profiling compiled code\nProfiling compiled code is highly system-specific, but this section contains some hints gleaned from various R users. Some methods need to be different for a compiled executable and for dynamic/shared libraries/objects as used by R packages.\nThis chapter is based on reports from users and the information may not be current.\n\n3.4.1 Linux\nOptions include using sprof for a shared object, and oprofile (see https://oprofile.sourceforge.io/news/) and perf (see https://perf.wiki.kernel.org/index.php/Tutorial) for any executable or shared object. These seem less widely supplied than they used to be. There is also ‘Google Performance Tools’, also known as gperftools or google-perftools.\nAll of these work best when R and any packages have been built with debugging symbols.\n\n\n3.4.2 perf\nThis seems the most widely distributed tool. Here is an example on x86_64 Linux using R 4.3.1 built with LTO.\nAt its simplest\nperf record R -f tests/Examples/stats-Ex.R\nperf report --sort=dso\nperf report --sort=srcfile\nrm perf.data*\nThe first report is\n 75.67% R\n 9.25% libc.so.6\n 4.87% [unknown]\n 3.75% libz.so.1.2.11\n 3.37% stats.so\n 1.17% libm.so.6\n 0.63% libtirpc.so.3.0.0\n 0.41% graphics.so\n 0.30% grDevices.so\n 0.20% libRblas.so\n 0.09% libpcre2-8.so.0.11.0\n 0.07% methods.so\n ...\nwhich shows which shared libraries (DSOs) the time was spent in.\nperf annotate can be used on an application built with GCC and -ggdb: it interleaves disassembled and source code.\n\n\n3.4.3 oprofile and operf\nThe oprofile project has two modes of operation. Since version 0.9.8 (August 2012), the preferred mode is to use operf, so we discuss only that.\nLet us look at the boot example from §3.2 on x86_64 Linux using R 4.3.1.\nThis can be run under operf and analysed by commands like\noperf R -f boot.R\nopreport\nopreport -l /path/to/R_HOME/bin/exec/R\nopreport -l /path/to/R_HOME/library/stats/src/stats.so\nopannotate --source /path/to/R_HOME/bin/exec/R\nThe first line had to be done as root.\nThe first report shows in which library (etc) the time was spent:\n CPU_CLK_UNHALT...|\n samples| %|\n ------------------\n 278341 91.9947 R\n 18290 6.0450 libc.so.6\n 2277 0.7526 kallsyms\n 1426 0.4713 stats.so\n 739 0.2442 libRblas.so\n 554 0.1831 libz.so.1.2.11\n 373 0.1233 libm.so.6\n 352 0.1163 libtirpc.so.3.0.0\n 153 0.0506 ld-linux-x86-64.so.2\n 12 0.0040 methods.so\n(kallsyms is the kernel.)\nThe rest of the output is voluminous, and only extracts are shown.\nMost of the time within R is spent in\nsamples % image name symbol name\n52955 19.0574 R bcEval.lto_priv.0\n16484 5.9322 R Rf_allocVector3\n14224 5.1189 R Rf_findVarInFrame3\n12581 4.5276 R CONS_NR\n8289 2.9830 R Rf_matchArgs_NR\n8034 2.8913 R Rf_cons\n7114 2.5602 R R_gc_internal.lto_priv.0\n6552 2.3579 R Rf_eval\n5969 2.1481 R VECTOR_ELT\n5684 2.0456 R Rf_applyClosure\n5497 1.9783 R findVarLocInFrame.part.0.lto_priv.0\n4827 1.7371 R Rf_mkPROMISE\n4609 1.6587 R Rf_install\n4317 1.5536 R Rf_findFun3\n4035 1.4521 R getvar.lto_priv.0\n3491 1.2563 R SETCAR\n3179 1.1441 R Rf_defineVar\n2892 1.0408 R duplicate1.lto_priv.0\nand in stats.so\nsamples % image name symbol name\n285 24.4845 stats.so termsform\n284 24.3986 stats.so numeric_deriv\n213 18.2990 stats.so modelframe\n114 9.7938 stats.so nls_iter\n55 4.7251 stats.so ExtractVars\n47 4.0378 stats.so EncodeVars\n37 3.1787 stats.so getListElement\n32 2.7491 stats.so TrimRepeats\n25 2.1478 stats.so InstallVar\n20 1.7182 stats.so MatchVar\n20 1.7182 stats.so isZeroOne\n15 1.2887 stats.so ConvInfoMsg.isra.0\nThe profiling data is by default stored in sub-directory oprofile_data of the current directory, which can be removed at the end of the session.\n\n\n3.4.4 sprof\nYou can select shared objects to be profiled with sprof by setting the environment variable LD_PROFILE. For example\n% setenv LD_PROFILE /path/to/R_HOME/library/stats/libs/stats.so\n% R -f boot.R\n% sprof /path/to/R_HOME/library/stats/libs/stats.so \\\n /var/tmp/path/to/R_HOME/library/stats/libs/stats.so.profile\n\nFlat profile:\n\nEach sample counts as 0.01 seconds.\n % cumulative self self total\n time seconds seconds calls us/call us/call name\n 76.19 0.32 0.32 0 0.00 numeric_deriv\n 16.67 0.39 0.07 0 0.00 nls_iter\n 7.14 0.42 0.03 0 0.00 getListElement\n\n... to clean up ...\nrm /var/tmp/path/to/R_HOME/library/stats/libs/stats.so.profile\nIt is possible that root access will be needed to create the directories used for the profile data.\n\n\n3.4.5 macOS\nDevelopers have recommended Instruments (part of Xcode, see https://help.apple.com/instruments/mac/current/), This had a command-line version prior to macOS 12.\n\n\n3.4.6 Windows\nVery Sleepy (https://github.com/VerySleepy/verysleepy) has been used. There were problems with accessing the debug information, but the best results which included function names were obtained by attaching the profiler to an existing Rterm process, either via GUI or using /a: (pid obtained via Sys.getpid()).\nFootnotes" }, { "objectID": "Debugging.html#browsing",