Date: Tue, 07 Aug 2012 19:26:03 +0000 From: gmiller@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r240177 - in soc2012/gmiller/locking-head: . lib/libthr/thread Message-ID: <20120807192603.9BBBA106564A@hub.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: gmiller Date: Tue Aug 7 19:26:02 2012 New Revision: 240177 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=240177 Log: r240208@FreeBSD-dev: root | 2012-07-25 03:47:07 -0500 Add XML output for lock profiling data. Modified: soc2012/gmiller/locking-head/ (props changed) soc2012/gmiller/locking-head/lib/libthr/thread/thr_profile.c Modified: soc2012/gmiller/locking-head/lib/libthr/thread/thr_profile.c ============================================================================== --- soc2012/gmiller/locking-head/lib/libthr/thread/thr_profile.c Tue Aug 7 18:50:33 2012 (r240176) +++ soc2012/gmiller/locking-head/lib/libthr/thread/thr_profile.c Tue Aug 7 19:26:02 2012 (r240177) @@ -73,9 +73,90 @@ }; static int lockprof_enabled; +static int xml_indent = 0; +static FILE *xml_file; + +static void +indent(void) +{ + int i; + + for (i = 0; i < xml_indent; i++) { + fputc(' ', xml_file); + } +} + +static void +open_element(const char *tag) +{ + indent(); + fprintf(xml_file, "<%s>\n", tag); + + xml_indent += 2; +} + +static void +close_element(const char *tag) +{ + xml_indent -= 2; + + indent(); + fprintf(xml_file, "</%s>\n", tag); +} + +static void +write_element_string(const char *tag, const char *str) +{ + indent(); + fprintf(xml_file, "<%s>%s</%s>\n", tag, str, tag); +} + +static void +write_element_numeric(const char *tag, long value) +{ + indent(); + fprintf(xml_file, "<%s>%ld</%s>\n", tag, value, tag); +} + +static void +write_element_timespec(const char *tag, struct timespec *ts) +{ + long tm; + + tm = ts->tv_sec * 1000000L + ts->tv_nsec / 1000; + write_element_numeric(tag, tm); + +} + +static void +write_xml(void) +{ + struct pthread_statistics_np stats; + + xml_file = fopen("lockprof.xml", "wt"); + + open_element("lockprof"); + + pthread_statistics_begin_np(&stats); + while (pthread_statistics_next_np(&stats)) { + write_element_string("file", stats.file); + write_element_numeric("line", stats.line); + write_element_timespec("wait_max", &stats.wait_max); + write_element_timespec("hold_max", &stats.hold_max); + write_element_numeric("contest_count", stats.contest_count); + write_element_timespec("wait_time", &stats.wait_time); + write_element_timespec("hold_time", &stats.hold_time); + write_element_numeric("acq_count", stats.acq_count); + } + pthread_statistics_end_np(&stats); + + close_element("lockprof"); + + fclose(xml_file); +} void -_lock_profile_init() +_lock_profile_init(void) { int i; @@ -84,6 +165,8 @@ } lockprof_enabled = 1; + + atexit(write_xml); } static struct acquisition *
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120807192603.9BBBA106564A>