From 3c434960a680c459d526bee483a2bc79ce767473 Mon Sep 17 00:00:00 2001 From: Tim Moore Date: Wed, 29 Apr 2009 19:52:50 +0200 Subject: Refactor StapParser into its own files * grapher/StapParser.cxx: new file * grapher/StapParser.hxx: new file * grapher/grapher.cxx: Use external StapParser class. --- grapher/grapher.cxx | 88 +---------------------------------------------------- 1 file changed, 1 insertion(+), 87 deletions(-) (limited to 'grapher/grapher.cxx') 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 #include @@ -12,93 +13,6 @@ using namespace systemtap; -class StapParser -{ - Glib::ustring _buffer; - typedef std::map > 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 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); -- cgit From f7cfc39c07d0cf872559f9716643491b8d79de75 Mon Sep 17 00:00:00 2001 From: Tim Moore Date: Mon, 25 May 2009 18:12:41 +0200 Subject: Incorporate grapher widget in real application * grapher/grapher.cxx (GrapherWindow): New class. (main): Instantiate GrapherWindow. --- grapher/grapher.cxx | 89 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 78 insertions(+), 11 deletions(-) (limited to 'grapher/grapher.cxx') diff --git a/grapher/grapher.cxx b/grapher/grapher.cxx index 4f9ccae8..b7292cfd 100644 --- a/grapher/grapher.cxx +++ b/grapher/grapher.cxx @@ -1,40 +1,107 @@ #include "GraphWidget.hxx" #include "StapParser.hxx" +#include #include +#include +#include #include #include #include +#include +#include #include #include #include #include +#include +#include +#include using namespace systemtap; +class GrapherWindow : public Gtk::Window +{ +public: + GrapherWindow(); + virtual ~GrapherWindow() {} + Gtk::VBox m_Box; + GraphWidget w; +protected: + virtual void on_menu_file_quit(); + // menu support + Glib::RefPtr m_refUIManager; + Glib::RefPtr m_refActionGroup; + +}; + +GrapherWindow::GrapherWindow() +{ + set_title("systemtap grapher"); + add(m_Box); + w.setExtents(0.0, 1.0, 5.0, 0.0); + w.setLineWidth(2); + + + + //Create actions for menus and toolbars: + m_refActionGroup = Gtk::ActionGroup::create(); + //File menu: + m_refActionGroup->add(Gtk::Action::create("FileMenu", "File")); + m_refActionGroup->add(Gtk::Action::create("FileQuit", Gtk::Stock::QUIT), + sigc::mem_fun(*this, &GrapherWindow::on_menu_file_quit)); + m_refUIManager = Gtk::UIManager::create(); + m_refUIManager->insert_action_group(m_refActionGroup); + + add_accel_group(m_refUIManager->get_accel_group()); + //Layout the actions in a menubar and toolbar: + Glib::ustring ui_info = + "" + " " + " " + " " + " " + " " + ""; + try + { + m_refUIManager->add_ui_from_string(ui_info); + } + catch(const Glib::Error& ex) + { + std::cerr << "building menus failed: " << ex.what(); + } + Gtk::Widget* pMenubar = m_refUIManager->get_widget("/MenuBar"); + if(pMenubar) + m_Box.pack_start(*pMenubar, Gtk::PACK_SHRINK); + m_Box.pack_start(w, Gtk::PACK_EXPAND_WIDGET); + w.show(); + + show_all_children(); + +} +void GrapherWindow::on_menu_file_quit() +{ + hide(); +} + int main(int argc, char** argv) { - Gtk::Main app(argc, argv); + Gtk::Main app(argc, argv); - Gtk::Window win; + GrapherWindow win; - win.set_title("Grapher"); - win.set_default_size(600, 200); + win.set_title("Grapher"); + win.set_default_size(600, 200); - GraphWidget w; - - w.setExtents(0.0, 1.0, 5.0, 0.0); - w.setLineWidth(2); + StapParser stapParser(win, win.w); StapParser stapParser(win, w); Glib::signal_io().connect(sigc::mem_fun(stapParser, &StapParser::ioCallback), 0, Glib::IO_IN); - win.add(w); - w.show(); - Gtk::Main::run(win); return 0; -- cgit From 95ddfc079a1d9affdb285f7690f8d5623cd7124a Mon Sep 17 00:00:00 2001 From: Tim Moore Date: Mon, 25 May 2009 18:25:47 +0200 Subject: run stap from grapher * grapher/grapher.cxx (main): Start stap + script from program if supplied as an argument. --- grapher/grapher.cxx | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'grapher/grapher.cxx') diff --git a/grapher/grapher.cxx b/grapher/grapher.cxx index b7292cfd..0013d8b0 100644 --- a/grapher/grapher.cxx +++ b/grapher/grapher.cxx @@ -97,12 +97,42 @@ int main(int argc, char** argv) StapParser stapParser(win, win.w); - StapParser stapParser(win, w); + int childPid = -1; + if (argc > 1) + { + int pipefd[2]; + if (pipe(pipefd) < 0) + { + std::perror("pipe"); + exit(1); + } + if ((childPid = fork()) == -1) + { + exit(1); + } + else if (childPid) + { + dup2(pipefd[0], 0); + close(pipefd[0]); + } + else + { + dup2(pipefd[1], 1); + close(pipefd[1]); + execlp("stap", argv[1]); + exit(1); + return 1; + } + } Glib::signal_io().connect(sigc::mem_fun(stapParser, &StapParser::ioCallback), 0, Glib::IO_IN); Gtk::Main::run(win); - + if (childPid > 0) + kill(childPid, SIGTERM); + int status; + while (wait(&status) != -1) + ; return 0; } -- cgit From a030ced8c0b8109ba7b23bbbc65deddf88154a2f Mon Sep 17 00:00:00 2001 From: Tim Moore Date: Thu, 4 Jun 2009 15:49:16 +0200 Subject: grapher fixups * grapher/grapher.cxx (main): Fix problems with call to execlp. --- grapher/grapher.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'grapher/grapher.cxx') diff --git a/grapher/grapher.cxx b/grapher/grapher.cxx index 0013d8b0..26e5b9b2 100644 --- a/grapher/grapher.cxx +++ b/grapher/grapher.cxx @@ -119,7 +119,7 @@ int main(int argc, char** argv) { dup2(pipefd[1], 1); close(pipefd[1]); - execlp("stap", argv[1]); + execlp("stap", "stap", argv[1], static_cast(0)); exit(1); return 1; } -- cgit From 364ad890e341bb60ae169af69933a382d4bf9f81 Mon Sep 17 00:00:00 2001 From: Tim Moore Date: Mon, 27 Jul 2009 12:46:30 +0200 Subject: Support for presenting multiple graphs * grapher/Graph.hxx: New file; class for single graph display. * grapher/Graph.cxx: New file. * grapher/GraphData.hxx: Associate title and axis labels with graph data and not a graph display. * grapher/GraphWidget.hxx: Move graph-related members to Graph class. * grapher/GraphWidget.cxx (getExtents, setExtents): Move to Graph class (on_expose_event): Move graph rendering to Graph. (on_button_press_event): Delegate to Graph. (on_motion_notify_event, on_scroll_event): Modify "active" graph. * grapher/StapParser.cxx (findTaggedValue): New parsing helper function. (io_callback): Support new syntax where properties are attached to graph data and not the entire graph. * grapher/grapher.cxx (GrapherWindow): Don't set graph values. * grapher/Makefile.am: Add Graph.cxx. * testsuite/systemtap.examples/general/grapher.stp: New property syntax. --- grapher/grapher.cxx | 3 --- 1 file changed, 3 deletions(-) (limited to 'grapher/grapher.cxx') diff --git a/grapher/grapher.cxx b/grapher/grapher.cxx index 26e5b9b2..a0d35017 100644 --- a/grapher/grapher.cxx +++ b/grapher/grapher.cxx @@ -40,9 +40,6 @@ GrapherWindow::GrapherWindow() { set_title("systemtap grapher"); add(m_Box); - w.setExtents(0.0, 1.0, 5.0, 0.0); - w.setLineWidth(2); - //Create actions for menus and toolbars: -- cgit