diff options
-rw-r--r-- | grapher/Makefile.am | 2 | ||||
-rw-r--r-- | grapher/Makefile.in | 21 | ||||
-rw-r--r-- | grapher/StapParser.cxx | 81 | ||||
-rw-r--r-- | grapher/StapParser.hxx | 21 | ||||
-rw-r--r-- | grapher/grapher.cxx | 88 |
5 files changed, 123 insertions, 90 deletions
diff --git a/grapher/Makefile.am b/grapher/Makefile.am index fdb52ef7..bd651352 100644 --- a/grapher/Makefile.am +++ b/grapher/Makefile.am @@ -2,6 +2,6 @@ if BUILD_GRAPHER bin_PROGRAMS = grapher grapher_CXXFLAGS = $(GRAPHER_CFLAGS) -grapher_SOURCES = grapher.cxx GraphWidget.cxx CairoWidget.cxx +grapher_SOURCES = grapher.cxx StapParser.cxx GraphWidget.cxx CairoWidget.cxx grapher_LDADD = $(GRAPHER_LIBS) endif
\ No newline at end of file diff --git a/grapher/Makefile.in b/grapher/Makefile.in index 88caeda1..3e65401e 100644 --- a/grapher/Makefile.in +++ b/grapher/Makefile.in @@ -43,8 +43,10 @@ CONFIG_CLEAN_FILES = am__installdirs = "$(DESTDIR)$(bindir)" binPROGRAMS_INSTALL = $(INSTALL_PROGRAM) PROGRAMS = $(bin_PROGRAMS) -am__grapher_SOURCES_DIST = grapher.cxx GraphWidget.cxx CairoWidget.cxx +am__grapher_SOURCES_DIST = grapher.cxx StapParser.cxx GraphWidget.cxx \ + CairoWidget.cxx @BUILD_GRAPHER_TRUE@am_grapher_OBJECTS = grapher-grapher.$(OBJEXT) \ +@BUILD_GRAPHER_TRUE@ grapher-StapParser.$(OBJEXT) \ @BUILD_GRAPHER_TRUE@ grapher-GraphWidget.$(OBJEXT) \ @BUILD_GRAPHER_TRUE@ grapher-CairoWidget.$(OBJEXT) grapher_OBJECTS = $(am_grapher_OBJECTS) @@ -184,7 +186,7 @@ top_build_prefix = @top_build_prefix@ top_builddir = @top_builddir@ top_srcdir = @top_srcdir@ @BUILD_GRAPHER_TRUE@grapher_CXXFLAGS = $(GRAPHER_CFLAGS) -@BUILD_GRAPHER_TRUE@grapher_SOURCES = grapher.cxx GraphWidget.cxx CairoWidget.cxx +@BUILD_GRAPHER_TRUE@grapher_SOURCES = grapher.cxx StapParser.cxx GraphWidget.cxx CairoWidget.cxx @BUILD_GRAPHER_TRUE@grapher_LDADD = $(GRAPHER_LIBS) all: all-am @@ -254,6 +256,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/grapher-CairoWidget.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/grapher-GraphWidget.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/grapher-StapParser.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/grapher-grapher.Po@am__quote@ .cxx.o: @@ -284,6 +287,20 @@ grapher-grapher.obj: grapher.cxx @AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(grapher_CXXFLAGS) $(CXXFLAGS) -c -o grapher-grapher.obj `if test -f 'grapher.cxx'; then $(CYGPATH_W) 'grapher.cxx'; else $(CYGPATH_W) '$(srcdir)/grapher.cxx'; fi` +grapher-StapParser.o: StapParser.cxx +@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(grapher_CXXFLAGS) $(CXXFLAGS) -MT grapher-StapParser.o -MD -MP -MF $(DEPDIR)/grapher-StapParser.Tpo -c -o grapher-StapParser.o `test -f 'StapParser.cxx' || echo '$(srcdir)/'`StapParser.cxx +@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/grapher-StapParser.Tpo $(DEPDIR)/grapher-StapParser.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='StapParser.cxx' object='grapher-StapParser.o' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(grapher_CXXFLAGS) $(CXXFLAGS) -c -o grapher-StapParser.o `test -f 'StapParser.cxx' || echo '$(srcdir)/'`StapParser.cxx + +grapher-StapParser.obj: StapParser.cxx +@am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(grapher_CXXFLAGS) $(CXXFLAGS) -MT grapher-StapParser.obj -MD -MP -MF $(DEPDIR)/grapher-StapParser.Tpo -c -o grapher-StapParser.obj `if test -f 'StapParser.cxx'; then $(CYGPATH_W) 'StapParser.cxx'; else $(CYGPATH_W) '$(srcdir)/StapParser.cxx'; fi` +@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/grapher-StapParser.Tpo $(DEPDIR)/grapher-StapParser.Po +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='StapParser.cxx' object='grapher-StapParser.obj' libtool=no @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(grapher_CXXFLAGS) $(CXXFLAGS) -c -o grapher-StapParser.obj `if test -f 'StapParser.cxx'; then $(CYGPATH_W) 'StapParser.cxx'; else $(CYGPATH_W) '$(srcdir)/StapParser.cxx'; fi` + grapher-GraphWidget.o: GraphWidget.cxx @am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(grapher_CXXFLAGS) $(CXXFLAGS) -MT grapher-GraphWidget.o -MD -MP -MF $(DEPDIR)/grapher-GraphWidget.Tpo -c -o grapher-GraphWidget.o `test -f 'GraphWidget.cxx' || echo '$(srcdir)/'`GraphWidget.cxx @am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/grapher-GraphWidget.Tpo $(DEPDIR)/grapher-GraphWidget.Po diff --git a/grapher/StapParser.cxx b/grapher/StapParser.cxx new file mode 100644 index 00000000..2bf26324 --- /dev/null +++ b/grapher/StapParser.cxx @@ -0,0 +1,81 @@ +#include "StapParser.hxx" + +#include <gtkmm/window.h> + +namespace systemtap +{ +bool StapParser::ioCallback(Glib::IOCondition ioCondition) +{ + if ((ioCondition & Glib::IO_IN) == 0) + return true; + char buf[256]; + ssize_t bytes_read = 0; + bytes_read = read(0, buf, sizeof(buf) - 1); + if (bytes_read <= 0) + { + _win.hide(); + return true; + } + buf[bytes_read] = '\0'; + _buffer += buf; + std::string::size_type ret = std::string::npos; + while ((ret = _buffer.find('\n')) != std::string::npos) + { + Glib::ustring dataString(_buffer, 0, ret); + if (dataString[0] == '%') + { + size_t found; + if ((found = dataString.find("%Title:") == 0)) + { + std::string title = dataString.substr(7); + _widget.setTitle(title); + } + else if ((found = dataString.find("%XAxisTitle:") == 0)) + { + _widget.setXAxisText(dataString.substr(12)); + } + else if ((found = dataString.find("%YAxisTitle:") == 0)) + { + _widget.setYAxisText(dataString.substr(12)); + } + else if ((found = dataString.find("%YMax:") == 0)) + { + double ymax; + std::istringstream stream(dataString.substr(6)); + stream >> ymax; + // _gdata->scale = ymax; + } + else if ((found = dataString.find("%DataSet:") == 0)) + { + std::tr1::shared_ptr<GraphData> dataSet(new GraphData); + std::string setName; + int hexColor; + std::string style; + std::istringstream stream(dataString.substr(9)); + stream >> setName >> dataSet->scale >> std::hex >> hexColor + >> style; + dataSet->color[0] = (hexColor >> 16) / 255.0; + dataSet->color[1] = ((hexColor >> 8) & 0xff) / 255.0; + dataSet->color[2] = (hexColor & 0xff) / 255.0; + if (style == "dot") + dataSet->style = GraphData::DOT; + _dataSets.insert(std::make_pair(setName, dataSet)); + _widget.addGraphData(dataSet); + } + } + else + { + std::string dataSet; + double time; + double data; + std::istringstream stream(dataString); + stream >> dataSet >> time >> data; + DataMap::iterator itr = _dataSets.find(dataSet); + if (itr != _dataSets.end()) + itr->second->data.push_back(std::make_pair(time, data)); + } + _buffer.erase(0, ret + 1); + } + return true; +} +} diff --git a/grapher/StapParser.hxx b/grapher/StapParser.hxx new file mode 100644 index 00000000..a94b0a9b --- /dev/null +++ b/grapher/StapParser.hxx @@ -0,0 +1,21 @@ +#include "GraphData.hxx" +#include "GraphWidget.hxx" + +#include <string> +namespace systemtap +{ +class StapParser +{ + std::string _buffer; + typedef std::map<std::string, std::tr1::shared_ptr<GraphData> > DataMap; + DataMap _dataSets; + Gtk::Window& _win; + GraphWidget& _widget; +public: + StapParser(Gtk::Window& win, + GraphWidget& widget) : _win(win), _widget(widget) {} + + bool ioCallback(Glib::IOCondition ioCondition); + +}; +} diff --git a/grapher/grapher.cxx b/grapher/grapher.cxx index 46182178..4f9ccae8 100644 --- a/grapher/grapher.cxx +++ b/grapher/grapher.cxx @@ -1,4 +1,5 @@ #include "GraphWidget.hxx" +#include "StapParser.hxx" #include <cmath> #include <sstream> @@ -12,93 +13,6 @@ using namespace systemtap; -class StapParser -{ - Glib::ustring _buffer; - typedef std::map<std::string, std::tr1::shared_ptr<GraphData> > DataMap; - DataMap _dataSets; - Gtk::Window& _win; - GraphWidget& _widget; -public: - StapParser(Gtk::Window& win, - GraphWidget& widget) : _win(win), _widget(widget) {} - - bool ioCallback(Glib::IOCondition ioCondition) - { - if ((ioCondition & Glib::IO_IN) == 0) - return true; - char buf[256]; - ssize_t bytes_read = 0; - bytes_read = read(0, buf, sizeof(buf) - 1); - if (bytes_read <= 0) - { - _win.hide(); - return true; - } - buf[bytes_read] = '\0'; - _buffer += buf; - Glib::ustring::size_type ret = Glib::ustring::npos; - while ((ret = _buffer.find('\n')) != Glib::ustring::npos) - { - Glib::ustring dataString(_buffer, 0, ret); - if (dataString[0] == '%') - { - size_t found; - if ((found = dataString.find("%Title:") == 0)) - { - std::string title = dataString.substr(7); - _widget.setTitle(title); - } - else if ((found = dataString.find("%XAxisTitle:") == 0)) - { - _widget.setXAxisText(dataString.substr(12)); - } - else if ((found = dataString.find("%YAxisTitle:") == 0)) - { - _widget.setYAxisText(dataString.substr(12)); - } - else if ((found = dataString.find("%YMax:") == 0)) - { - double ymax; - std::istringstream stream(dataString.substr(6)); - stream >> ymax; - // _gdata->scale = ymax; - } - else if ((found = dataString.find("%DataSet:") == 0)) - { - std::tr1::shared_ptr<GraphData> dataSet(new GraphData); - std::string setName; - int hexColor; - std::string style; - std::istringstream stream(dataString.substr(9)); - stream >> setName >> dataSet->scale >> std::hex >> hexColor - >> style; - dataSet->color[0] = (hexColor >> 16) / 255.0; - dataSet->color[1] = ((hexColor >> 8) & 0xff) / 255.0; - dataSet->color[2] = (hexColor & 0xff) / 255.0; - if (style == "dot") - dataSet->style = GraphData::DOT; - _dataSets.insert(std::make_pair(setName, dataSet)); - _widget.addGraphData(dataSet); - } - } - else - { - std::string dataSet; - double time; - double data; - std::istringstream stream(dataString); - stream >> dataSet >> time >> data; - DataMap::iterator itr = _dataSets.find(dataSet); - if (itr != _dataSets.end()) - itr->second->data.push_back(std::make_pair(time, data)); - } - _buffer.erase(0, ret + 1); - } - return true; - } -}; - int main(int argc, char** argv) { Gtk::Main app(argc, argv); |