[PATCH 1/4] ldv/unwind: enable cache feature of libunwind

Masatake YAMATO yamato at redhat.com
Wed Apr 9 16:52:08 UTC 2014


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 <yamato at redhat.com>
Ready-to-Merge: yes
---
 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.5.3





More information about the Strace-devel mailing list