This patch extends -C option to print the hit rate of socket address cache.
It is printed only if both -C and -yy options are given.

Example output:

        $ time ./strace -yy -C -o /tmp/LOG ./a.out; tail -5 /tmp/LOG
          0.07    0.000004           4         1           brk
          0.05    0.000003           3         1           arch_prctl
        ------ ----------- ----------- --------- --------- ----------------
        100.00    0.006060                  5231         1 total
        socket info cache hit: 10100/10153

Changes:
* socketutils.c (scache_hit_count, scache_mishit_count): New variables.
  (sockaddr_cache_summary): New function.
  (print_sockaddr_in_cache): Count the hits and mishit.

* strace.c (cleanup): Print the hit rate of socket address cache if
  -C option is given.

* defs.h (sockaddr_cache_summary): New declaration.

Signed-off-by: Masatake YAMATO <yam...@redhat.com>
---
 defs.h        |  1 +
 socketutils.c | 15 ++++++++++++++-
 strace.c      |  5 ++++-
 3 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/defs.h b/defs.h
index 5915da1..91ac41a 100644
--- a/defs.h
+++ b/defs.h
@@ -492,6 +492,7 @@ extern void printsiginfo(const siginfo_t *, int);
 extern void printsiginfo_at(struct tcb *tcp, long addr);
 extern void printfd(struct tcb *, int);
 extern bool print_sockaddr_in_cache(const unsigned long);
+extern void sockaddr_cache_summary(FILE *);
 extern bool print_sockaddr_by_inode(const unsigned long, const char *);
 extern void print_dirfd(struct tcb *, int);
 extern void printsock(struct tcb *, long, int);
diff --git a/socketutils.c b/socketutils.c
index 1c7c69d..7d8df75 100644
--- a/socketutils.c
+++ b/socketutils.c
@@ -481,14 +481,27 @@ unix_print(int fd, const unsigned long inode)
                && receive_responses(fd, inode, "UNIX", unix_parse_response);
 }
 
+static unsigned long scache_hit_count;
+static unsigned long scache_mishit_count;
+
+void
+sockaddr_cache_summary(FILE * outf)
+{
+       fprintf(outf, "socket info cache hit: %lu/%lu\n",
+               scache_hit_count, scache_hit_count + scache_mishit_count);
+}
+
 bool
 print_sockaddr_in_cache(const unsigned long inode)
 {
        struct scache_entry *r;
 
        r = scache_entries_find(inode);
-       if (r)
+       if (r) {
                scache_entry_print(r);
+               scache_hit_count++;
+       } else
+               scache_mishit_count++;
 
        return r? true: false;
 }
diff --git a/strace.c b/strace.c
index b714255..3304cdb 100644
--- a/strace.c
+++ b/strace.c
@@ -1807,8 +1807,11 @@ cleanup(void)
                }
                detach(tcp);
        }
-       if (cflag)
+       if (cflag) {
                call_summary(shared_log);
+               if (show_fd_path)
+                       sockaddr_cache_summary(shared_log);
+       }
 }
 
 static void
-- 
2.1.0


------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Strace-devel mailing list
Strace-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/strace-devel

Reply via email to