From 3f1e092ed414ab2a9f73eafe87f35e868030463c Mon Sep 17 00:00:00 2001 From: Steven Rostedt Date: Wed, 31 Mar 2010 05:32:43 -0400 Subject: trace-view: Added saving of filters Add "Save filters" to "File" menu, where it will allow the user to save the filters to a file in XML format. Signed-off-by: Steven Rostedt --- trace-xml.c | 127 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 trace-xml.c (limited to 'trace-xml.c') diff --git a/trace-xml.c b/trace-xml.c new file mode 100644 index 0000000..0bc130c --- /dev/null +++ b/trace-xml.c @@ -0,0 +1,127 @@ +/* + * Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt + * + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License (not later!) + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + */ +#include +#include +#include +#include + +#include +#include +#include + +#include "trace-cmd.h" +#include "trace-xml.h" + +struct tracecmd_xml_handle { + xmlTextWriterPtr writer; +}; + +#define TRACE_ENCODING "UTF-8" + +int tracecmd_xml_write_element(struct tracecmd_xml_handle *handle, + const char *obj, + const char *fmt, ...) +{ + va_list ap; + int ret; + + va_start(ap, fmt); + ret = xmlTextWriterWriteVFormatElement(handle->writer, + BAD_CAST obj, fmt, ap); + va_end(ap); + + return ret; +} + +struct tracecmd_xml_handle *tracecmd_xml_create(const char *name) +{ + struct tracecmd_xml_handle *handle; + int ret; + + handle = malloc_or_die(sizeof(*handle)); + memset(handle, 0, sizeof(*handle)); + + handle->writer = xmlNewTextWriterFilename(name, 0); + if (!handle->writer) + goto fail_free; + + ret = xmlTextWriterStartDocument(handle->writer, NULL, + TRACE_ENCODING, NULL); + if (ret < 0) + goto fail_close; + + return handle; + + fail_close: + xmlFreeTextWriter(handle->writer); + fail_free: + free(handle); + return NULL; +} + +int tracecmd_xml_start_system(struct tracecmd_xml_handle *handle, + const char *system, const char *version) +{ + int ret; + + ret = xmlTextWriterStartElement(handle->writer, + BAD_CAST system); + + if (ret < 0) + return ret; + + ret = tracecmd_xml_write_element(handle, "Version", "%s", version); + if (ret < 0) + return ret; + + return 0; +} + +int tracecmd_xml_start_sub_system(struct tracecmd_xml_handle *handle, + const char *subsystem) +{ + int ret; + + ret = xmlTextWriterStartElement(handle->writer, + BAD_CAST subsystem); + + return ret; +} + +void tracecmd_xml_end_system(struct tracecmd_xml_handle *handle) +{ + xmlTextWriterEndElement(handle->writer); +} + +void tracecmd_xml_end_sub_system(struct tracecmd_xml_handle *handle) +{ + xmlTextWriterEndElement(handle->writer); +} + +void tracecmd_xml_close(struct tracecmd_xml_handle *handle) +{ + if (handle->writer) { + xmlTextWriterEndDocument(handle->writer); + xmlFreeTextWriter(handle->writer); + } + + free(handle); +} -- cgit v1.2.2 From b2a9cd2f38f6c3c30e9ef4c47eb004b41b50fe5e Mon Sep 17 00:00:00 2001 From: Steven Rostedt Date: Mon, 5 Apr 2010 12:40:51 -0400 Subject: trace-view: Add loading of saved event filters Add "Load filters" to trace-view that loads the event filters saved with a "Save filters". Signed-off-by: Steven Rostedt --- trace-xml.c | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 103 insertions(+), 1 deletion(-) (limited to 'trace-xml.c') diff --git a/trace-xml.c b/trace-xml.c index 0bc130c..47cb3c9 100644 --- a/trace-xml.c +++ b/trace-xml.c @@ -25,13 +25,20 @@ #include #include -#include +#include #include "trace-cmd.h" #include "trace-xml.h" struct tracecmd_xml_handle { xmlTextWriterPtr writer; + xmlDocPtr doc; +}; + +struct tracecmd_xml_system { + struct tracecmd_xml_handle *handle; + xmlXPathObjectPtr result; + xmlNodePtr cur; }; #define TRACE_ENCODING "UTF-8" @@ -122,6 +129,101 @@ void tracecmd_xml_close(struct tracecmd_xml_handle *handle) xmlTextWriterEndDocument(handle->writer); xmlFreeTextWriter(handle->writer); } + if (handle->doc) { + xmlFreeDoc(handle->doc); + } + free(handle); +} + +/***********************************************************/ +/*** Reading XML files ***/ +/***********************************************************/ + + +struct tracecmd_xml_handle *tracecmd_xml_open(const char *file) +{ + struct tracecmd_xml_handle *handle; + handle = malloc_or_die(sizeof(*handle)); + memset(handle, 0, sizeof(*handle)); + + handle->doc = xmlParseFile(file); + if (!handle->doc) + goto fail_free; + + return handle; + + fail_free: free(handle); + return NULL; +} + +struct tracecmd_xml_system * +tracecmd_xml_find_system(struct tracecmd_xml_handle *handle, + const char *system) +{ + struct tracecmd_xml_system *sys; + xmlXPathContextPtr context; + xmlXPathObjectPtr result; + xmlChar *xpath; + char *path; + + path = malloc_or_die(strlen(system) + 3); + sprintf(path, "//%s", system); + xpath = BAD_CAST path; + + context = xmlXPathNewContext(handle->doc); + result = xmlXPathEvalExpression(xpath, context); + free(path); + + if (xmlXPathNodeSetIsEmpty(result->nodesetval)) { + xmlXPathFreeObject(result); + return NULL; + } + + sys = malloc_or_die(sizeof(*sys)); + sys->handle = handle; + sys->result = result; + sys->cur = result->nodesetval->nodeTab[0]->xmlChildrenNode; + + return sys; +} + +struct tracecmd_xml_system_node * +tracecmd_xml_system_node(struct tracecmd_xml_system *system) +{ + return (struct tracecmd_xml_system_node *)system->cur; +} + +const char *tracecmd_xml_node_type(struct tracecmd_xml_system_node *tnode) +{ + xmlNodePtr node = (xmlNodePtr)tnode; + return (const char *)node->name; +} + +struct tracecmd_xml_system_node * +tracecmd_xml_node_child(struct tracecmd_xml_system_node *tnode) +{ + xmlNodePtr node = (xmlNodePtr)tnode; + return (struct tracecmd_xml_system_node *)node->xmlChildrenNode; +} + +struct tracecmd_xml_system_node * +tracecmd_xml_node_next(struct tracecmd_xml_system_node *tnode) +{ + xmlNodePtr node = (xmlNodePtr)tnode; + return (struct tracecmd_xml_system_node *)node->next; +} + +const char *tracecmd_xml_node_value(struct tracecmd_xml_handle *handle, + struct tracecmd_xml_system_node *tnode) +{ + xmlNodePtr node = (xmlNodePtr)tnode; + return (const char *)xmlNodeListGetString(handle->doc, node->xmlChildrenNode, 1); +} + +void tracecmd_xml_free_system(struct tracecmd_xml_system *system) +{ + xmlXPathFreeObject(system->result); + free(system); } -- cgit v1.2.2 From 20359fdc358744dee36b8e59c234e965fc7d2a69 Mon Sep 17 00:00:00 2001 From: Steven Rostedt Date: Mon, 5 Apr 2010 22:40:54 -0400 Subject: kernelshark: Make all saved filters under KernelShark Make the xml doc under ... for trace-view and trace-graph. Also pull out the task filters since the view and graph in kernelshark share the same filters. Signed-off-by: Steven Rostedt --- trace-xml.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'trace-xml.c') diff --git a/trace-xml.c b/trace-xml.c index 47cb3c9..62473fb 100644 --- a/trace-xml.c +++ b/trace-xml.c @@ -58,7 +58,8 @@ int tracecmd_xml_write_element(struct tracecmd_xml_handle *handle, return ret; } -struct tracecmd_xml_handle *tracecmd_xml_create(const char *name) +struct tracecmd_xml_handle *tracecmd_xml_create(const char *name, + const char *version) { struct tracecmd_xml_handle *handle; int ret; @@ -75,6 +76,11 @@ struct tracecmd_xml_handle *tracecmd_xml_create(const char *name) if (ret < 0) goto fail_close; + ret = xmlTextWriterStartElement(handle->writer, + BAD_CAST "KernelShark"); + if (ret < 0) + goto fail_close; + return handle; fail_close: @@ -85,7 +91,7 @@ struct tracecmd_xml_handle *tracecmd_xml_create(const char *name) } int tracecmd_xml_start_system(struct tracecmd_xml_handle *handle, - const char *system, const char *version) + const char *system) { int ret; @@ -95,10 +101,6 @@ int tracecmd_xml_start_system(struct tracecmd_xml_handle *handle, if (ret < 0) return ret; - ret = tracecmd_xml_write_element(handle, "Version", "%s", version); - if (ret < 0) - return ret; - return 0; } @@ -126,6 +128,7 @@ void tracecmd_xml_end_sub_system(struct tracecmd_xml_handle *handle) void tracecmd_xml_close(struct tracecmd_xml_handle *handle) { if (handle->writer) { + xmlTextWriterEndElement(handle->writer); xmlTextWriterEndDocument(handle->writer); xmlFreeTextWriter(handle->writer); } -- cgit v1.2.2 From ce6dcdc247fc6194566360e74fcb986fa656043a Mon Sep 17 00:00:00 2001 From: Steven Rostedt Date: Thu, 10 Jun 2010 16:15:19 -0400 Subject: kernelshark: Fix the xml save/load to handle separate task filters Update the save/load of the filters to handle the change to make the List and Graph have separate task filters. Signed-off-by: Steven Rostedt --- trace-xml.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'trace-xml.c') diff --git a/trace-xml.c b/trace-xml.c index 62473fb..bef1f9f 100644 --- a/trace-xml.c +++ b/trace-xml.c @@ -230,3 +230,19 @@ void tracecmd_xml_free_system(struct tracecmd_xml_system *system) xmlXPathFreeObject(system->result); free(system); } + +int tracecmd_xml_system_exists(struct tracecmd_xml_handle *handle, + const char *system) +{ + struct tracecmd_xml_system *sys; + int exists = 0; + + sys = tracecmd_xml_find_system(handle, system); + if (sys) { + exists = 1; + tracecmd_xml_free_system(sys); + } + + return exists; +} + -- cgit v1.2.2