socsvn commit: r240177 - in soc2012/gmiller/locking-head: .
lib/libthr/thread
gmiller at FreeBSD.org
gmiller at FreeBSD.org
Tue Aug 7 19:26:05 UTC 2012
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 at 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 *
More information about the svn-soc-all
mailing list