summaryrefslogtreecommitdiffstats
path: root/grapher
diff options
context:
space:
mode:
authorTim Moore <timoore@redhat.com>2009-12-08 12:44:03 +0100
committerTim Moore <timoore@redhat.com>2009-12-08 23:25:20 +0100
commitcfd482078cd4805076cc6fd7e4e8642b97a03b25 (patch)
tree2d12ccdcfb9eee27d73f1c09d4da72e70fec82c4 /grapher
parent72a9e5a2d3788f5465eb5e1610f2402744054f2e (diff)
downloadsystemtap-steved-cfd482078cd4805076cc6fd7e4e8642b97a03b25.tar.gz
systemtap-steved-cfd482078cd4805076cc6fd7e4e8642b97a03b25.tar.xz
systemtap-steved-cfd482078cd4805076cc6fd7e4e8642b97a03b25.zip
refactor list of data sets out of GraphWidget into a global data structure.
Also, add a sigc signal for broadcasting data set changes. * grapher/GraphData.hxx (GraphDataList) new typedef (getGraphData, graphDataSignal): new functions * grapher/Graph.hxx (DatasetList): remove typedef in favor of systemtap::GraphDataList * grapher/GraphWidget.cxx (GraphWidget, onGraphDataChanged): Use graphDataSignal to notice new data sets that need to be added. Use the global data set list instead of one embedded in GraphWidget. * grapher/StapParser.hxx: delete the _widget member; use signals to broadcast that there are new data sets instead of calling into the widget.
Diffstat (limited to 'grapher')
-rw-r--r--grapher/Graph.cxx9
-rw-r--r--grapher/Graph.hxx5
-rw-r--r--grapher/GraphData.hxx14
-rw-r--r--grapher/GraphWidget.cxx52
-rw-r--r--grapher/GraphWidget.hxx4
-rw-r--r--grapher/StapParser.cxx6
-rw-r--r--grapher/StapParser.hxx7
-rw-r--r--grapher/grapher.cxx4
8 files changed, 69 insertions, 32 deletions
diff --git a/grapher/Graph.cxx b/grapher/Graph.cxx
index 2d203ead..ea1bd091 100644
--- a/grapher/Graph.cxx
+++ b/grapher/Graph.cxx
@@ -16,6 +16,9 @@ namespace systemtap
{
using namespace std;
using namespace std::tr1;
+
+ GraphDataList GraphDataBase::graphData;
+ sigc::signal<void> GraphDataBase::graphDataChanged;
Graph::Graph(double x, double y)
: _width(600), _height(200), _graphX(0), _graphY(0),
@@ -40,7 +43,7 @@ namespace systemtap
int linesPossible = (int)(_graphWidth / (_lineWidth + 2.0));
// Find latest time.
int64_t latestTime = 0;
- for (DatasetList::iterator ditr = _datasets.begin(),
+ for (GraphDataList::iterator ditr = _datasets.begin(),
de = _datasets.end();
ditr != de;
++ditr)
@@ -54,7 +57,7 @@ namespace systemtap
}
int64_t minDiff = 0;
int64_t maxTotal = 0;
- for (DatasetList::iterator ditr = _datasets.begin(),
+ for (GraphDataList::iterator ditr = _datasets.begin(),
de = _datasets.end();
ditr != de;
++ditr)
@@ -92,7 +95,7 @@ namespace systemtap
cr->translate(_xOffset, _yOffset);
cr->set_line_width(_lineWidth);
- for (DatasetList::iterator itr = _datasets.begin(), e = _datasets.end();
+ for (GraphDataList::iterator itr = _datasets.begin(), e = _datasets.end();
itr != e;
++itr)
{
diff --git a/grapher/Graph.hxx b/grapher/Graph.hxx
index 4dcb5169..c928fec2 100644
--- a/grapher/Graph.hxx
+++ b/grapher/Graph.hxx
@@ -19,7 +19,6 @@ namespace systemtap
class Graph : public CairoWidget
{
public:
- typedef std::vector<std::tr1::shared_ptr<GraphDataBase> > DatasetList;
friend class GraphWidget;
Graph(double x = 0.0, double y = 0.0);
virtual void draw(Cairo::RefPtr<Cairo::Context> cr);
@@ -48,11 +47,11 @@ namespace systemtap
double _yOffset;
std::tr1::shared_ptr<CairoPlayButton> _playButton;
int64_t _timeBase;
- DatasetList& getDatasets() { return _datasets; }
+ GraphDataList& getDatasets() { return _datasets; }
int64_t getTimeAtPoint(double x);
void window2GraphCoords(double x, double y, double& xgraph, double& ygraph);
protected:
- DatasetList _datasets;
+ GraphDataList _datasets;
int64_t _left;
int64_t _right;
double _top;
diff --git a/grapher/GraphData.hxx b/grapher/GraphData.hxx
index fbb2bb8f..fb1ca9f5 100644
--- a/grapher/GraphData.hxx
+++ b/grapher/GraphData.hxx
@@ -19,10 +19,14 @@
#include <boost/circular_buffer.hpp>
+#include <gtkmm.h>
+
#include "GraphStyle.hxx"
namespace systemtap
{
+ struct GraphDataBase;
+ typedef std::vector<std::tr1::shared_ptr<GraphDataBase> > GraphDataList;
struct GraphDataBase
{
virtual ~GraphDataBase() {}
@@ -43,6 +47,9 @@ namespace systemtap
std::string xAxisText;
std::string yAxisText;
TimeList times;
+ static GraphDataList graphData;
+ // signal stuff for telling everyone about changes to the data set list
+ static sigc::signal<void> graphDataChanged;
};
template<typename T>
@@ -69,5 +76,12 @@ namespace systemtap
Element;
std::vector<Element> elements;
};
+
+ inline GraphDataList& getGraphData() { return GraphDataBase::graphData; }
+
+ inline sigc::signal<void>& graphDataSignal()
+ {
+ return GraphDataBase::graphDataChanged;
+ }
}
#endif
diff --git a/grapher/GraphWidget.cxx b/grapher/GraphWidget.cxx
index 8335fda2..bdf60ed2 100644
--- a/grapher/GraphWidget.cxx
+++ b/grapher/GraphWidget.cxx
@@ -87,7 +87,8 @@ namespace systemtap
&GraphWidget::onRelativeTimesButtonClicked));
// Set button's initial value from that in .glade file
_displayRelativeTimes = _relativeTimesButton->get_active();
-
+ graphDataSignal()
+ .connect(sigc::mem_fun(*this, &GraphWidget::onGraphDataChanged));
}
catch (const Gnome::Glade::XmlError& ex )
{
@@ -100,10 +101,32 @@ namespace systemtap
{
}
- void GraphWidget::addGraphData(shared_ptr<GraphDataBase> data)
+ void GraphWidget::onGraphDataChanged()
{
- _graphs.back()->addGraphData(data);
- _graphData.push_back(data);
+ // add any new graph data to the last graph
+ GraphDataList newData;
+ GraphDataList& allData = getGraphData();
+ for (GraphDataList::iterator gditr = allData.begin(), gdend = allData.end();
+ gditr != gdend;
+ ++gditr)
+ {
+ bool found = false;
+ for (GraphList::iterator gitr = _graphs.begin(), gend = _graphs.end();
+ gitr != gend;
+ ++gitr)
+ {
+ GraphDataList& gdata = (*gitr)->getDatasets();
+ if (find(gdata.begin(), gdata.end(), *gditr) != gdata.end())
+ {
+ found = true;
+ break;
+ }
+ }
+ if (!found)
+ newData.push_back(*gditr);
+ }
+ copy(newData.begin(), newData.end(),
+ back_inserter(_graphs.back()->getDatasets()));
}
void GraphWidget::addGraph()
@@ -134,11 +157,12 @@ namespace systemtap
cr->save();
cr->set_source_rgba(0.0, 0.0, 0.0, 1.0);
cr->paint();
- if (!_timeBaseInitialized && !_graphData.empty())
+ if (!_timeBaseInitialized && !getGraphData().empty())
{
+ GraphDataList& graphData = getGraphData();
int64_t earliest = INT64_MAX;
- for (GraphDataList::iterator gd = _graphData.begin(),
- end = _graphData.end();
+ for (GraphDataList::iterator gd = graphData.begin(),
+ end = graphData.end();
gd != end;
++gd)
{
@@ -285,8 +309,8 @@ namespace systemtap
void GraphWidget::onDataDialogOpen()
{
_listStore->clear();
- for (GraphDataList::iterator itr = _graphData.begin(),
- end = _graphData.end();
+ for (GraphDataList::iterator itr = getGraphData().begin(),
+ end = getGraphData().end();
itr != end;
++itr)
{
@@ -296,8 +320,8 @@ namespace systemtap
if (!(*itr)->title.empty())
row[_dataColumns._dataTitle] = (*itr)->title;
row[_dataColumns._graphData] = *itr;
- Graph::DatasetList& gsets = _activeGraph->getDatasets();
- Graph::DatasetList::iterator setItr
+ GraphDataList& gsets = _activeGraph->getDatasets();
+ GraphDataList::iterator setItr
= find(gsets.begin(), gsets.end(), *itr);
row[_dataColumns._dataEnabled] = (setItr != gsets.end());
}
@@ -320,8 +344,8 @@ namespace systemtap
if (!_hoverText)
_hoverText = shared_ptr<CairoTextBox>(new CairoTextBox());
_hoverText->setOrigin(_mouseX + 10, _mouseY - 5);
- Graph::DatasetList& dataSets = g->getDatasets();
- for (Graph::DatasetList::reverse_iterator ritr = dataSets.rbegin(),
+ GraphDataList& dataSets = g->getDatasets();
+ for (GraphDataList::reverse_iterator ritr = dataSets.rbegin(),
end = dataSets.rend();
ritr != end;
++ritr)
@@ -374,7 +398,7 @@ namespace systemtap
Gtk::TreeModel::Row row = *litr;
bool val = row[_dataColumns._dataEnabled];
shared_ptr<GraphDataBase> data = row[_dataColumns._graphData];
- Graph::DatasetList& graphData = _activeGraph->getDatasets();
+ GraphDataList& graphData = _activeGraph->getDatasets();
if (val
&& find(graphData.begin(), graphData.end(), data) == graphData.end())
{
diff --git a/grapher/GraphWidget.hxx b/grapher/GraphWidget.hxx
index 0e9f2a29..89b86db9 100644
--- a/grapher/GraphWidget.hxx
+++ b/grapher/GraphWidget.hxx
@@ -42,14 +42,11 @@ namespace systemtap
public:
GraphWidget();
virtual ~GraphWidget();
- void addGraphData(std::tr1::shared_ptr<GraphDataBase> data);
void addGraph();
protected:
typedef std::vector<std::tr1::shared_ptr<Graph> > GraphList;
GraphList _graphs;
- typedef std::vector<std::tr1::shared_ptr<GraphDataBase> > GraphDataList;
- GraphDataList _graphData;
// For click and drag
std::tr1::shared_ptr<Graph> _activeGraph;
// Dragging all graphs simultaneously, or perhaps seperately
@@ -99,6 +96,7 @@ namespace systemtap
{
return false;
}
+ void onGraphDataChanged();
};
}
#endif // SYSTEMTAP_GRAPHWIDGET_H
diff --git a/grapher/StapParser.cxx b/grapher/StapParser.cxx
index edb7f5f2..653c00de 100644
--- a/grapher/StapParser.cxx
+++ b/grapher/StapParser.cxx
@@ -118,7 +118,8 @@ vector<string> commaSplit(const boost::sub_range<Glib::ustring>& range)
dataSet->color[2] = (hexColor & 0xff) / 255.0;
dataSet->scale = scale;
_dataSets.insert(std::make_pair(setName, dataSet));
- _widget->addGraphData(dataSet);
+ getGraphData().push_back(dataSet);
+ graphDataSignal().emit();
}
else if (style == "discreet")
{
@@ -131,7 +132,8 @@ vector<string> commaSplit(const boost::sub_range<Glib::ustring>& range)
dataSet->color[2] = (hexColor & 0xff) / 255.0;
dataSet->scale = scale;
_dataSets.insert(std::make_pair(setName, dataSet));
- _widget->addGraphData(dataSet);
+ getGraphData().push_back(dataSet);
+ graphDataSignal().emit();
}
}
else if ((found = find_first(dataString, "%CSV:")))
diff --git a/grapher/StapParser.hxx b/grapher/StapParser.hxx
index 476b0071..eba8a7af 100644
--- a/grapher/StapParser.hxx
+++ b/grapher/StapParser.hxx
@@ -7,7 +7,6 @@
// later version.
#include "GraphData.hxx"
-#include "GraphWidget.hxx"
#include <string>
namespace systemtap
@@ -19,14 +18,12 @@ class StapParser
DataMap _dataSets;
CSVData _csv;
Gtk::Window* _win;
- GraphWidget* _widget;
int _errFd;
int _inFd;
unsigned char _lineEndChar;
public:
- StapParser(Gtk::Window* win,
- GraphWidget* widget) : _win(win), _widget(widget), _errFd(-1),
- _inFd(-1), _lineEndChar('\n')
+ StapParser(Gtk::Window* win)
+ : _win(win), _errFd(-1), _inFd(-1), _lineEndChar('\n')
{
}
void parseData(std::tr1::shared_ptr<GraphDataBase> gdata,
diff --git a/grapher/grapher.cxx b/grapher/grapher.cxx
index 567b0405..4769877f 100644
--- a/grapher/grapher.cxx
+++ b/grapher/grapher.cxx
@@ -161,7 +161,7 @@ public:
void cleanUp();
tr1::shared_ptr<StapParser> makeStapParser()
{
- tr1::shared_ptr<StapParser> result(new StapParser(_win, _widget));
+ tr1::shared_ptr<StapParser> result(new StapParser(_win));
_parsers.push_back(ParserInstance(-1, result));
return result;
}
@@ -274,7 +274,7 @@ int StapLauncher::launch()
}
_exit(1);
}
- tr1::shared_ptr<StapParser> sp(new StapParser(_win, _widget));
+ tr1::shared_ptr<StapParser> sp(new StapParser(_win));
_parsers.push_back(ParserInstance(childPid, sp));
sp->setErrFd(pipefd[2]);
sp->setInFd(pipefd[0]);