This patch adds a new function into libstat:
xml_stats_container_save which handles an xml_stream_t instead of a file.
It dumps the same data stats_container_save with XML format.
Also added two fields to stats: timestamp and cpuid.
Compilation is conditional to LIB_XML.
---
testcases/realtime/include/libstats.h | 16 ++++++++++++
testcases/realtime/lib/libstats.c | 42 +++++++++++++++++++++++++++++++++
2 files changed, 58 insertions(+), 0 deletions(-)
diff --git a/testcases/realtime/include/libstats.h
b/testcases/realtime/include/libstats.h
index 05c26d8..fefad7b 100644
--- a/testcases/realtime/include/libstats.h
+++ b/testcases/realtime/include/libstats.h
@@ -45,6 +45,10 @@
#include <errno.h>
#include <unistd.h>
#include <math.h>
+#include <librttest.h>
+#ifdef LIB_XML
+#include <libxml.h>
+#endif
#define MIN(A,B) ((A)<(B)?(A):(B))
#define MAX(A,B) ((A)>(B)?(A):(B))
@@ -52,6 +56,8 @@
typedef struct stats_record {
long x;
long y;
+ nsec_t timestamp;
+ int cpuid;
} stats_record_t;
typedef struct stats_container {
@@ -162,4 +168,14 @@ void stats_hist_print(stats_container_t *hist);
*/
int stats_container_save(char *filename, char *title, char *labelx, char
*labely, stats_container_t *data, char *mode);
+#ifdef LIB_XML
+/* stats_container_xml_save - save the x,y data to an xml file.
+ * xs: the stream previously created with xml_stream_init.
+ * labelx: the x-axis label
+ * labely: the y-axis label
+ * mode: "points" "lines" "steps" etc, see gnuplot help for plotting types
+ */
+int xml_stats_container_save(xml_stream_t *xs, char *title, char *xlabel, char
*ylabel, stats_container_t *data, char *mode);
+#endif
+
#endif /* LIBSTAT_H */
diff --git a/testcases/realtime/lib/libstats.c
b/testcases/realtime/lib/libstats.c
index 29e7ea7..fccf733 100644
--- a/testcases/realtime/lib/libstats.c
+++ b/testcases/realtime/lib/libstats.c
@@ -43,6 +43,9 @@
#include <unistd.h>
#include <math.h>
#include <libstats.h>
+#ifdef LIB_XML
+#include <libxml.h>
+#endif
int save_stats = 0;
@@ -355,3 +358,42 @@ int stats_container_save(char *filename, char *title, char
*xlabel, char *ylabel
return 0;
}
+
+#ifdef LIB_XML
+int xml_stats_container_save(xml_stream_t *xs, char *title, char *xlabel, char
*ylabel, stats_container_t *data, char *mode)
+{
+ int i;
+ long minx = 0, maxx = 0, miny = 0, maxy = 0;
+ stats_record_t *rec;
+
+ xml_start_tag(xs, "stats");
+ minx = maxx = data->records[0].x;
+ miny = maxy = data->records[0].y;
+ xml_entry(xs, "title",title);
+ xml_entry(xs, "xlabel",xlabel);
+ xml_entry(xs, "ylabel",ylabel);
+ xml_entry(xs, "mode",mode);
+ xml_start_tag(xs, "data");
+
+ for (i = 0; i < data->size; i++) {
+ rec = &data->records[i];
+ minx = MIN(minx, rec->x);
+ maxx = MAX(maxx, rec->x);
+ miny = MIN(miny, rec->y);
+ maxy = MAX(maxy, rec->y);
+
+ /* Self-closing tag with attributes: <e r=... x=... ... /> */
+ xml_tag(xs, XML_TAG_SC, "e", "r=\"%d\" x=\"%ld\" y=\"%d\"
t=\"%lld\" c=\"%d\"", i, rec->x, rec->y, rec->timestamp, rec->cpuid);
+ }
+
+ xml_end_tag(xs); /* data */
+ xml_entry(xs, "sample-size", "%ld", data->size);
+ xml_entry(xs, "minx", "%ld", minx);
+ xml_entry(xs, "maxx", "%ld", maxx);
+ xml_entry(xs, "miny", "%ld", miny);
+ xml_entry(xs, "maxy", "%ld", maxy);
+ xml_end_tag(xs); /* stats */
+
+ return 0;
+}
+#endif
--
1.5.5.GIT
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list