diff options
author | Tim Moore <timoore@redhat.com> | 2009-05-20 13:29:54 +0200 |
---|---|---|
committer | Tim Moore <timoore@redhat.com> | 2009-07-28 10:14:53 +0200 |
commit | 0f262fd10d337db0ec435d840b541d629879ce9f (patch) | |
tree | 6f56660cf0d766958aae66d03cfb59d2c8e083ff | |
parent | 3c434960a680c459d526bee483a2bc79ce767473 (diff) | |
download | systemtap-steved-0f262fd10d337db0ec435d840b541d629879ce9f.tar.gz systemtap-steved-0f262fd10d337db0ec435d840b541d629879ce9f.tar.xz systemtap-steved-0f262fd10d337db0ec435d840b541d629879ce9f.zip |
Add CSV syntax support to the grapher
* grapher/GraphData.hxx (CSVData): new class
* grapher/GraphData.cxx (commaSplit): new function
(ioCallback): handle CSV definition and data
-rw-r--r-- | grapher/GraphData.hxx | 7 | ||||
-rw-r--r-- | grapher/StapParser.cxx | 80 | ||||
-rw-r--r-- | grapher/StapParser.hxx | 1 |
3 files changed, 78 insertions, 10 deletions
diff --git a/grapher/GraphData.hxx b/grapher/GraphData.hxx index 0f3b0b31..2c0783c6 100644 --- a/grapher/GraphData.hxx +++ b/grapher/GraphData.hxx @@ -3,6 +3,7 @@ #include <utility> #include <vector> +#include <tr1/memory> namespace systemtap { @@ -40,5 +41,11 @@ namespace systemtap } }; }; + + struct CSVData + { + typedef std::pair<std::string, std::tr1::shared_ptr<GraphData> > Element; + std::vector<Element> elements; + }; } #endif diff --git a/grapher/StapParser.cxx b/grapher/StapParser.cxx index 2bf26324..c973b0aa 100644 --- a/grapher/StapParser.cxx +++ b/grapher/StapParser.cxx @@ -4,8 +4,32 @@ namespace systemtap { +using namespace std; + +vector<string> commaSplit(const string& inStr, size_t pos = 0) +{ + size_t found = pos; + vector<string> result; + while (1) + { + + size_t commaPos = inStr.find(',', found); + string token + = inStr.substr(found, (commaPos == string::npos + ? string::npos + : commaPos - 1 - found)); + result.push_back(token); + if (commaPos != string::npos) + found = commaPos + 1; + else + break; + } + return result; +} + bool StapParser::ioCallback(Glib::IOCondition ioCondition) { + using namespace std; if ((ioCondition & Glib::IO_IN) == 0) return true; char buf[256]; @@ -18,8 +42,8 @@ bool StapParser::ioCallback(Glib::IOCondition ioCondition) } buf[bytes_read] = '\0'; _buffer += buf; - std::string::size_type ret = std::string::npos; - while ((ret = _buffer.find('\n')) != std::string::npos) + string::size_type ret = string::npos; + while ((ret = _buffer.find('\n')) != string::npos) { Glib::ustring dataString(_buffer, 0, ret); if (dataString[0] == '%') @@ -62,17 +86,53 @@ bool StapParser::ioCallback(Glib::IOCondition ioCondition) _dataSets.insert(std::make_pair(setName, dataSet)); _widget.addGraphData(dataSet); } + else if ((found = dataString.find("%CSV:") == 0)) + { + vector<string> tokens = commaSplit(dataString, found + 5); + for (vector<string>::iterator tokIter = tokens.begin(), + e = tokens.end(); + tokIter != e; + ++tokIter) + { + DataMap::iterator setIter = _dataSets.find(*tokIter); + if (setIter != _dataSets.end()) + _csv.elements.push_back(CSVData::Element(*tokIter, + setIter->second)); + } + } } 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)); + if (!_csv.elements.empty()) + { + vector<string> tokens = commaSplit(dataString); + int i = 0; + double time; + vector<string>::iterator tokIter = tokens.begin(); + std::istringstream timeStream(*tokIter++); + timeStream >> time; + for (vector<string>::iterator e = tokens.end(); + tokIter != e; + ++tokIter, ++i) + { + std::istringstream stream(*tokIter); + double data; + stream >> data; + _csv.elements[i].second + ->data.push_back(std::make_pair(time, data)); + } + } + 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); } diff --git a/grapher/StapParser.hxx b/grapher/StapParser.hxx index a94b0a9b..624accc7 100644 --- a/grapher/StapParser.hxx +++ b/grapher/StapParser.hxx @@ -9,6 +9,7 @@ class StapParser std::string _buffer; typedef std::map<std::string, std::tr1::shared_ptr<GraphData> > DataMap; DataMap _dataSets; + CSVData _csv; Gtk::Window& _win; GraphWidget& _widget; public: |