diff options
author | Tim Moore <timoore@redhat.com> | 2009-12-21 10:46:57 +0100 |
---|---|---|
committer | Tim Moore <timoore@redhat.com> | 2009-12-21 10:46:57 +0100 |
commit | 32902edf1f17bb62144f21ed38ae085bd2755e9f (patch) | |
tree | 7b9c8b185baf80b03e5509cc05ede7cf2f490910 /grapher/StapParser.cxx | |
parent | 261135850dbd4a2efd7d4cbd3d0e3dcde46688ee (diff) | |
download | systemtap-steved-32902edf1f17bb62144f21ed38ae085bd2755e9f.tar.gz systemtap-steved-32902edf1f17bb62144f21ed38ae085bd2755e9f.tar.xz systemtap-steved-32902edf1f17bb62144f21ed38ae085bd2755e9f.zip |
change namespace indentation to 0
A silly change, but this works better with other tools, like git
diff. I should have started the C++ files this way.
Diffstat (limited to 'grapher/StapParser.cxx')
-rw-r--r-- | grapher/StapParser.cxx | 526 |
1 files changed, 263 insertions, 263 deletions
diff --git a/grapher/StapParser.cxx b/grapher/StapParser.cxx index 2595e8cc..803b5fb3 100644 --- a/grapher/StapParser.cxx +++ b/grapher/StapParser.cxx @@ -22,22 +22,22 @@ namespace systemtap { - using namespace std; - using namespace std::tr1; +using namespace std; +using namespace std::tr1; - sigc::signal<void, pid_t>& childDiedSignal() - { - static sigc::signal<void, pid_t> deathSignal; - return deathSignal; - } +sigc::signal<void, pid_t>& childDiedSignal() +{ + static sigc::signal<void, pid_t> deathSignal; + return deathSignal; +} - ParserList parsers; +ParserList parsers; - sigc::signal<void>& parserListChangedSignal() - { - static sigc::signal<void> listChangedSignal; - return listChangedSignal; - } +sigc::signal<void>& parserListChangedSignal() +{ + static sigc::signal<void> listChangedSignal; + return listChangedSignal; +} vector<string> commaSplit(const boost::sub_range<Glib::ustring>& range) { @@ -47,263 +47,263 @@ vector<string> commaSplit(const boost::sub_range<Glib::ustring>& range) return result; } - void StapParser::parseData(shared_ptr<GraphDataBase> gdata, - int64_t time, const string& dataString) - { - std::istringstream stream(dataString); - shared_ptr<GraphData<double> > dblptr; - shared_ptr<GraphData<string> > strptr; - dblptr = dynamic_pointer_cast<GraphData<double> >(gdata); - if (dblptr) - { - double data; - stream >> data; - dblptr->times.push_back(time); - dblptr->data.push_back(data); - } - else if ((strptr = dynamic_pointer_cast<GraphData<string> >(gdata)) - != 0) - { - strptr->times.push_back(time); - strptr->data.push_back(dataString); - } - } +void StapParser::parseData(shared_ptr<GraphDataBase> gdata, + int64_t time, const string& dataString) +{ + std::istringstream stream(dataString); + shared_ptr<GraphData<double> > dblptr; + shared_ptr<GraphData<string> > strptr; + dblptr = dynamic_pointer_cast<GraphData<double> >(gdata); + if (dblptr) + { + double data; + stream >> data; + dblptr->times.push_back(time); + dblptr->data.push_back(data); + } + else if ((strptr = dynamic_pointer_cast<GraphData<string> >(gdata)) + != 0) + { + strptr->times.push_back(time); + strptr->data.push_back(dataString); + } +} - bool findTaggedValue(const string& src, const char* tag, string& result) - { - using namespace boost; - sub_range<const string> found = find_first(src, tag); - if (found.empty()) - return false; - result.insert(result.end(),found.end(), src.end()); - return true; - } +bool findTaggedValue(const string& src, const char* tag, string& result) +{ + using namespace boost; + sub_range<const string> found = find_first(src, tag); + if (found.empty()) + return false; + result.insert(result.end(),found.end(), src.end()); + return true; +} - bool StapParser::ioCallback(Glib::IOCondition ioCondition) - { - using namespace std; - using std::tr1::shared_ptr; - using namespace boost; - if (ioCondition & Glib::IO_HUP) - { - if (_catchHUP) - { - childDiedSignal().emit(getPid()); - _ioConnection.disconnect(); - _errIoConnection.disconnect(); - } - return true; - } - if ((ioCondition & Glib::IO_IN) == 0) +bool StapParser::ioCallback(Glib::IOCondition ioCondition) +{ + using namespace std; + using std::tr1::shared_ptr; + using namespace boost; + if (ioCondition & Glib::IO_HUP) + { + if (_catchHUP) + { + childDiedSignal().emit(getPid()); + _ioConnection.disconnect(); + _errIoConnection.disconnect(); + } return true; - char buf[256]; - ssize_t bytes_read = 0; - bytes_read = read(_inFd, buf, sizeof(buf) - 1); - if (bytes_read <= 0) - { - childDiedSignal().emit(getPid()); - return true; - } - _buffer.append(buf, bytes_read); - string::size_type ret = string::npos; - while ((ret = _buffer.find(_lineEndChar)) != string::npos) - { - Glib::ustring dataString(_buffer, 0, ret); - // %DataSet and %CSV declare a data set; all other - // statements begin with the name of a data set. - // Except %LineEnd :) - sub_range<Glib::ustring> found; - if (dataString[0] == '%') - { - if ((found = find_first(dataString, "%DataSet:"))) - { - string setName; - int hexColor; - double scale; - string style; - istringstream stream(Glib::ustring(found.end(), - dataString.end())); - stream >> setName >> scale >> std::hex >> hexColor - >> style; - if (style == "bar" || style == "dot") - { - std::tr1::shared_ptr<GraphData<double> > - dataSet(new GraphData<double>); - dataSet->name = setName; - if (style == "dot") - dataSet->style = &GraphStyleDot::instance; - dataSet->color[0] = (hexColor >> 16) / 255.0; - dataSet->color[1] = ((hexColor >> 8) & 0xff) / 255.0; - dataSet->color[2] = (hexColor & 0xff) / 255.0; - dataSet->scale = scale; - _dataSets.insert(std::make_pair(setName, dataSet)); - getGraphData().push_back(dataSet); - graphDataSignal().emit(); - } - else if (style == "discreet") - { - std::tr1::shared_ptr<GraphData<string> > - dataSet(new GraphData<string>); - dataSet->name = setName; - dataSet->style = &GraphStyleEvent::instance; - dataSet->color[0] = (hexColor >> 16) / 255.0; - dataSet->color[1] = ((hexColor >> 8) & 0xff) / 255.0; - dataSet->color[2] = (hexColor & 0xff) / 255.0; - dataSet->scale = scale; - _dataSets.insert(std::make_pair(setName, dataSet)); - getGraphData().push_back(dataSet); - graphDataSignal().emit(); - } - } - else if ((found = find_first(dataString, "%CSV:"))) - { - vector<string> tokens - = commaSplit(sub_range<Glib::ustring>(found.end(), - dataString.end())); - 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 if ((found = find_first(dataString, "%LineEnd:"))) - { - istringstream stream(Glib::ustring(found.end(), - dataString.end())); - int charAsInt = 0; - // parse hex and octal numbers too - stream >> std::setbase(0) >> charAsInt; - _lineEndChar = static_cast<char>(charAsInt); - } - else - { - cerr << "Unknown declaration " << dataString << endl; - } - } - else - { - std::istringstream stream(dataString); - string setName; - stream >> setName; - DataMap::iterator itr = _dataSets.find(setName); - if (itr != _dataSets.end()) - { - shared_ptr<GraphDataBase> gdata = itr->second; - string decl; - // Hack: scan from the beginning of dataString again - if (findTaggedValue(dataString, "%Title:", decl)) - { - gdata->title = decl; - } - else if (findTaggedValue(dataString, "%XAxisTitle:", decl)) - { - gdata->xAxisText = decl; - } - else if (findTaggedValue(dataString, "%YAxisTitle:", decl)) - { - gdata->yAxisText = decl; - } - else if ((found = find_first(dataString, "%YMax:"))) - { - double ymax; - std::istringstream - stream(Glib::ustring(found.end(), dataString.end())); - stream >> ymax; - gdata->scale = ymax; - } - else - { - if (!_csv.elements.empty()) - { - vector<string> tokens = commaSplit(dataString); - int i = 0; - int64_t time; - vector<string>::iterator tokIter = tokens.begin(); - std::istringstream timeStream(*tokIter++); - timeStream >> time; - for (vector<string>::iterator e = tokens.end(); - tokIter != e; - ++tokIter, ++i) - { - parseData(_csv.elements[i].second, time, - *tokIter); - } - } - else - { - int64_t time; - stringbuf data; - stream >> time; - stream.get(data, _lineEndChar); - parseData(itr->second, time, data.str()); - } - } - } - } - _buffer.erase(0, ret + 1); - } + } + if ((ioCondition & Glib::IO_IN) == 0) return true; - } - - bool StapParser::errIoCallback(Glib::IOCondition ioCondition) - { - using namespace std; - if ((ioCondition & Glib::IO_IN) == 0) + char buf[256]; + ssize_t bytes_read = 0; + bytes_read = read(_inFd, buf, sizeof(buf) - 1); + if (bytes_read <= 0) + { + childDiedSignal().emit(getPid()); return true; - char buf[256]; - ssize_t bytes_read = 0; - bytes_read = read(_errFd, buf, sizeof(buf) - 1); - if (bytes_read <= 0) - { - cerr << "StapParser: error reading from stderr!\n"; - return true; - } - if (write(STDERR_FILENO, buf, bytes_read) < 0) - ; + } + _buffer.append(buf, bytes_read); + string::size_type ret = string::npos; + while ((ret = _buffer.find(_lineEndChar)) != string::npos) + { + Glib::ustring dataString(_buffer, 0, ret); + // %DataSet and %CSV declare a data set; all other + // statements begin with the name of a data set. + // Except %LineEnd :) + sub_range<Glib::ustring> found; + if (dataString[0] == '%') + { + if ((found = find_first(dataString, "%DataSet:"))) + { + string setName; + int hexColor; + double scale; + string style; + istringstream stream(Glib::ustring(found.end(), + dataString.end())); + stream >> setName >> scale >> std::hex >> hexColor + >> style; + if (style == "bar" || style == "dot") + { + std::tr1::shared_ptr<GraphData<double> > + dataSet(new GraphData<double>); + dataSet->name = setName; + if (style == "dot") + dataSet->style = &GraphStyleDot::instance; + dataSet->color[0] = (hexColor >> 16) / 255.0; + dataSet->color[1] = ((hexColor >> 8) & 0xff) / 255.0; + dataSet->color[2] = (hexColor & 0xff) / 255.0; + dataSet->scale = scale; + _dataSets.insert(std::make_pair(setName, dataSet)); + getGraphData().push_back(dataSet); + graphDataSignal().emit(); + } + else if (style == "discreet") + { + std::tr1::shared_ptr<GraphData<string> > + dataSet(new GraphData<string>); + dataSet->name = setName; + dataSet->style = &GraphStyleEvent::instance; + dataSet->color[0] = (hexColor >> 16) / 255.0; + dataSet->color[1] = ((hexColor >> 8) & 0xff) / 255.0; + dataSet->color[2] = (hexColor & 0xff) / 255.0; + dataSet->scale = scale; + _dataSets.insert(std::make_pair(setName, dataSet)); + getGraphData().push_back(dataSet); + graphDataSignal().emit(); + } + } + else if ((found = find_first(dataString, "%CSV:"))) + { + vector<string> tokens + = commaSplit(sub_range<Glib::ustring>(found.end(), + dataString.end())); + 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 if ((found = find_first(dataString, "%LineEnd:"))) + { + istringstream stream(Glib::ustring(found.end(), + dataString.end())); + int charAsInt = 0; + // parse hex and octal numbers too + stream >> std::setbase(0) >> charAsInt; + _lineEndChar = static_cast<char>(charAsInt); + } + else + { + cerr << "Unknown declaration " << dataString << endl; + } + } + else + { + std::istringstream stream(dataString); + string setName; + stream >> setName; + DataMap::iterator itr = _dataSets.find(setName); + if (itr != _dataSets.end()) + { + shared_ptr<GraphDataBase> gdata = itr->second; + string decl; + // Hack: scan from the beginning of dataString again + if (findTaggedValue(dataString, "%Title:", decl)) + { + gdata->title = decl; + } + else if (findTaggedValue(dataString, "%XAxisTitle:", decl)) + { + gdata->xAxisText = decl; + } + else if (findTaggedValue(dataString, "%YAxisTitle:", decl)) + { + gdata->yAxisText = decl; + } + else if ((found = find_first(dataString, "%YMax:"))) + { + double ymax; + std::istringstream + stream(Glib::ustring(found.end(), dataString.end())); + stream >> ymax; + gdata->scale = ymax; + } + else + { + if (!_csv.elements.empty()) + { + vector<string> tokens = commaSplit(dataString); + int i = 0; + int64_t time; + vector<string>::iterator tokIter = tokens.begin(); + std::istringstream timeStream(*tokIter++); + timeStream >> time; + for (vector<string>::iterator e = tokens.end(); + tokIter != e; + ++tokIter, ++i) + { + parseData(_csv.elements[i].second, time, + *tokIter); + } + } + else + { + int64_t time; + stringbuf data; + stream >> time; + stream.get(data, _lineEndChar); + parseData(itr->second, time, data.str()); + } + } + } + } + _buffer.erase(0, ret + 1); + } + return true; +} + +bool StapParser::errIoCallback(Glib::IOCondition ioCondition) +{ + using namespace std; + if ((ioCondition & Glib::IO_IN) == 0) return true; - } + char buf[256]; + ssize_t bytes_read = 0; + bytes_read = read(_errFd, buf, sizeof(buf) - 1); + if (bytes_read <= 0) + { + cerr << "StapParser: error reading from stderr!\n"; + return true; + } + if (write(STDERR_FILENO, buf, bytes_read) < 0) + ; + return true; +} - void StapParser::initIo(int inFd, int errFd, bool catchHUP) - { - _inFd = inFd; - _errFd = errFd; - _catchHUP = catchHUP; - Glib::IOCondition inCond = Glib::IO_IN; - if (catchHUP) - inCond |= Glib::IO_HUP; - if (_errFd >= 0) - { - _errIoConnection = Glib::signal_io() - .connect(sigc::mem_fun(*this, &StapParser::errIoCallback), - _errFd, Glib::IO_IN); - } - _ioConnection = Glib::signal_io() - .connect(sigc::mem_fun(*this, &StapParser::ioCallback), - _inFd, inCond); +void StapParser::initIo(int inFd, int errFd, bool catchHUP) +{ + _inFd = inFd; + _errFd = errFd; + _catchHUP = catchHUP; + Glib::IOCondition inCond = Glib::IO_IN; + if (catchHUP) + inCond |= Glib::IO_HUP; + if (_errFd >= 0) + { + _errIoConnection = Glib::signal_io() + .connect(sigc::mem_fun(*this, &StapParser::errIoCallback), + _errFd, Glib::IO_IN); + } + _ioConnection = Glib::signal_io() + .connect(sigc::mem_fun(*this, &StapParser::ioCallback), + _inFd, inCond); - } +} - void StapParser::disconnect() - { - if (_ioConnection.connected()) - _ioConnection.disconnect(); - if (_errIoConnection.connected()) - _errIoConnection.disconnect(); - if (_inFd >= 0) - { - close(_inFd); - _inFd = -1; - } - if (_errFd >= 0) - { - close(_errFd); - _errFd = -1; - } - } +void StapParser::disconnect() +{ + if (_ioConnection.connected()) + _ioConnection.disconnect(); + if (_errIoConnection.connected()) + _errIoConnection.disconnect(); + if (_inFd >= 0) + { + close(_inFd); + _inFd = -1; + } + if (_errFd >= 0) + { + close(_errFd); + _errFd = -1; + } +} } |