From: Masatake Y. <ya...@re...> - 2013-11-12 09:27:57
|
With turning on cache feature of libunwind, stack tracing becomes two times faster(in my small test). Target program: #include <unistd.h> #include <sys/types.h> #define N 0xfff int main(void) { uid_t uid; int i; for (i = 0; i < N; i++) getuid(); return 0; } With enabling cache of libunwind: % /usr/bin/time ./strace -o /dev/null -e'getuid' -k ./a.out 0.61user 1.33system 0:01.97elapsed 98%CPU (0avgtext+0avgdata 1376maxresident)k 0inputs+0outputs (0major+590269minor)pagefaults 0swaps Without enabling cache of libunwind: % /usr/bin/time ./strace -o /dev/null -e'getuid' -k ./a.out 0.80user 2.61system 0:03.46elapsed 98%CPU (0avgtext+0avgdata 1372maxresident)k 0inputs+0outputs (0major+639381minor)pagefaults 0swaps Signed-off-by: Masatake YAMATO <ya...@re...> --- unwind.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/unwind.c b/unwind.c index 4cb6325..ed2d141 100644 --- a/unwind.c +++ b/unwind.c @@ -80,6 +80,7 @@ init_unwind_addr_space(void) libunwind_as = unw_create_addr_space(&_UPT_accessors, 0); if (!libunwind_as) error_msg_and_die("failed to create address space for stack tracing"); + unw_set_caching_policy(libunwind_as, UNW_CACHE_GLOBAL); } static void @@ -135,6 +136,8 @@ build_mmap_cache(struct tcb *tcp) struct mmap_cache_t *cache_head; FILE *fp; + unw_flush_cache (libunwind_as, 0, 0); + sprintf(filename, "/proc/%d/maps", tcp->pid); fp = fopen(filename, "r"); if (!fp) { -- 1.8.3.1 |
From: Luca C. <luc...@gm...> - 2013-11-16 19:57:42
|
On Tue, Nov 12, 2013 at 1:27 AM, Masatake YAMATO <ya...@re...> wrote: > With turning on cache feature of libunwind, stack tracing > becomes two times faster(in my small test). > Nice improvement. With this patch applied it reads the maps file 1432 times: $ strace -e trace=open -o tmp ./strace -k -o /dev/null ls $ grep maps tmp | grep proc |wc -l 1432 Without the patch: $ strace -e trace=open -o tmp ./strace -k -o /dev/null ls $ grep maps tmp | grep proc |wc -l 1539 Luca |
From: Masatake Y. <ya...@re...> - 2013-11-19 05:04:04
|
I've submitted two patches to libunwind-devel: http://lists.gnu.org/archive/html/libunwind-devel/2013-11/msg00003.html http://lists.gnu.org/archive/html/libunwind-devel/2013-11/msg00004.html The patch introduces the mechanism to cache /proc/$PID/maps to libunwind. With patched libunwind: % LD_LIBRARY_PATH=/usr/local/lib strace -e trace=open -o tmp ./strace -k -o /dev/null ls > /dev/null % grep maps tmp | grep proc |wc -l 165 Without patched libunwind: % grep maps tmp | grep proc |wc -l 1251 About strace side following small patch is needed. diff --git a/unwind.c b/unwind.c index ed2d141..d620441 100644 --- a/unwind.c +++ b/unwind.c @@ -89,6 +89,7 @@ init_libunwind_ui(struct tcb *tcp) tcp->libunwind_ui = _UPT_create(tcp->pid); if (!tcp->libunwind_ui) die_out_of_memory(); + _UPT_set_map_caching_policy(tcp->libunwind_ui, 1); } static void @@ -137,6 +138,7 @@ build_mmap_cache(struct tcb *tcp) FILE *fp; unw_flush_cache (libunwind_as, 0, 0); + _UPT_flush_map_cache(tcp->libunwind_ui); sprintf(filename, "/proc/%d/maps", tcp->pid); fp = fopen(filename, "r"); Removing strace own mmap cache is the next step. Masatake YAMATO > On Tue, Nov 12, 2013 at 1:27 AM, Masatake YAMATO <ya...@re...> wrote: >> With turning on cache feature of libunwind, stack tracing >> becomes two times faster(in my small test). >> > > Nice improvement. > > With this patch applied it reads the maps file 1432 times: > $ strace -e trace=open -o tmp ./strace -k -o /dev/null ls > $ grep maps tmp | grep proc |wc -l > 1432 > > Without the patch: > $ strace -e trace=open -o tmp ./strace -k -o /dev/null ls > $ grep maps tmp | grep proc |wc -l > 1539 > > Luca > > ------------------------------------------------------------------------------ > DreamFactory - Open Source REST & JSON Services for HTML5 & Native Apps > OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access > Free app hosting. Or install the open source package on any LAMP server. > Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native! > http://pubads.g.doubleclick.net/gampad/clk?id=63469471&iu=/4140/ostg.clktrk > _______________________________________________ > Strace-devel mailing list > Str...@li... > https://lists.sourceforge.net/lists/listinfo/strace-devel |