summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Moore <timoore@redhat.com>2009-12-01 12:02:24 +0100
committerTim Moore <timoore@redhat.com>2009-12-01 12:30:42 +0100
commit572a176d481c329b370ce52e7bec1a49ed76c225 (patch)
treec4979af7c8089124ee0dd30d63ec14864ea0e9f9
parent211c338e54b096a41170c5bac99eaf33959076f2 (diff)
downloadsystemtap-steved-572a176d481c329b370ce52e7bec1a49ed76c225.tar.gz
systemtap-steved-572a176d481c329b370ce52e7bec1a49ed76c225.tar.xz
systemtap-steved-572a176d481c329b370ce52e7bec1a49ed76c225.zip
change time type from double to int64_t
* grapher/Graph.hxx (Graph): Change variables holding the time limits of the displayed graph from double to int64_t. * grapher/Graph.cxx (Graph::draw): Do calculations of time differences using int64_t. (Graph::getExtents, Graph::setExtents): Change left and right arguments to int64_t. * grapher/GraphData.hxx (GraphDataBase): Change time type to int64_t. (GraphDataBase::elementAsString): New function. (GraphData::elementAsString): Implementation of that function. * grapher/StapParser.cxx (parseData): Parse time values from the stap script as 64 bit values.
-rw-r--r--grapher/Graph.cxx37
-rw-r--r--grapher/Graph.hxx12
-rw-r--r--grapher/GraphData.hxx12
-rw-r--r--grapher/StapParser.cxx6
-rw-r--r--grapher/StapParser.hxx2
5 files changed, 44 insertions, 25 deletions
diff --git a/grapher/Graph.cxx b/grapher/Graph.cxx
index a7fe6fcf..e9aacd55 100644
--- a/grapher/Graph.cxx
+++ b/grapher/Graph.cxx
@@ -30,7 +30,7 @@ namespace systemtap
// line separation
int linesPossible = (int)(_graphWidth / (_lineWidth + 2.0));
// Find latest time.
- double latestTime = 0.0;
+ int64_t latestTime = 0;
for (DatasetList::iterator ditr = _datasets.begin(),
de = _datasets.end();
ditr != de;
@@ -38,13 +38,13 @@ namespace systemtap
{
if (!(*ditr)->times.empty())
{
- double lastDataTime = (*ditr)->times.back();
+ int64_t lastDataTime = (*ditr)->times.back();
if (lastDataTime > latestTime)
latestTime = lastDataTime;
}
}
- double minDiff = 0.0;
- double maxTotal = 0.0;
+ int64_t minDiff = 0;
+ int64_t maxTotal = 0;
for (DatasetList::iterator ditr = _datasets.begin(),
de = _datasets.end();
ditr != de;
@@ -59,11 +59,11 @@ namespace systemtap
ritr + 1 != gtimes.rend();
ritr++)
{
- double timeDiff = *ritr - *(ritr + 1);
+ int64_t timeDiff = *ritr - *(ritr + 1);
if (timeDiff < minDiff || (timeDiff != 0 && minDiff == 0))
minDiff = timeDiff;
if (minDiff != 0
- && (totalDiff + timeDiff) / minDiff > linesPossible)
+ && ((totalDiff + timeDiff) / minDiff + 1) > linesPossible)
break;
totalDiff += timeDiff;
}
@@ -75,10 +75,11 @@ namespace systemtap
if (maxTotal != 0)
_left = latestTime - maxTotal;
else
- _left = _right - 1.0;
+ _left = _right - 1;
}
cr->save();
- double horizScale = _zoomFactor * _graphWidth / ( _right - _left);
+ double horizScale
+ = _zoomFactor * _graphWidth / static_cast<double>(_right - _left);
cr->translate(20.0, 0.0);
cr->set_line_width(_lineWidth);
@@ -186,9 +187,10 @@ namespace systemtap
}
cr->restore();
// Draw axes
- double diff = _right - _left;
- double majorUnit = pow(10.0, floor(log(diff) / log(10.0)));
- double startTime = ceil(_left / majorUnit) * majorUnit;
+ double diff = static_cast<double>(_right - _left);
+ int64_t majorUnit
+ = static_cast<int64_t>(pow(10.0, floor(log(diff) / log(10.0))));
+ int64_t startTime = (_left / majorUnit) * majorUnit;
cr->save();
cr->set_source_rgba(1.0, 1.0, 1.0, .9);
cr->set_line_cap(Cairo::LINE_CAP_BUTT);
@@ -205,14 +207,14 @@ namespace systemtap
dash[0] = _graphHeight / 10;
cr->set_dash(dash, 0);
double prevTextAdvance = 0;
- for (double tickVal = startTime; tickVal <= _right; tickVal += majorUnit)
+ for (int64_t tickVal = startTime; tickVal <= _right; tickVal += majorUnit)
{
double x = (tickVal - _left) * horizScale + 20.0;
cr->move_to(x, 0.0);
cr->line_to(x, _graphHeight);
cr->move_to(x, _graphHeight - 5);
std::ostringstream stream;
- stream << std::fixed << std::setprecision(0) << tickVal;
+ stream << tickVal;
Cairo::TextExtents extents;
cr->get_text_extents(stream.str(), extents);
// Room for this label?
@@ -239,7 +241,7 @@ namespace systemtap
_datasets.push_back(data);
}
- void Graph::getExtents(double& left, double& right, double& top,
+ void Graph::getExtents(int64_t& left, int64_t& right, double& top,
double& bottom) const
{
left = _left;
@@ -248,7 +250,7 @@ namespace systemtap
bottom = _bottom;
}
- void Graph::setExtents(double left, double right, double top, double bottom)
+ void Graph::setExtents(int64_t left, int64_t right, double top, double bottom)
{
_left = left;
_right = right;
@@ -260,4 +262,9 @@ namespace systemtap
{
return x >= _x0 && x < _x0 + _width && y >= _y0 && y < _y0 + _height;
}
+
+ int64_t Graph::getTimeAtPoint(double x)
+ {
+ return _left + (_right - _left) * ((x - 20.0)/_graphWidth);
+ }
}
diff --git a/grapher/Graph.hxx b/grapher/Graph.hxx
index aad63767..e0e864d6 100644
--- a/grapher/Graph.hxx
+++ b/grapher/Graph.hxx
@@ -11,6 +11,7 @@ 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);
@@ -20,9 +21,9 @@ namespace systemtap
bool getAutoScaling() const { return _autoScaling; }
void setAutoScaling(bool val) { _autoScaling = val; }
void addGraphData(std::tr1::shared_ptr<GraphDataBase> data);
- void getExtents(double& left, double& right, double& top, double& bottom)
+ void getExtents(int64_t& left, int64_t& right, double& top, double& bottom)
const;
- void setExtents(double left, double right, double top, double bottom);
+ void setExtents(int64_t left, int64_t right, double top, double bottom);
// extents of the whole graph area
double _width;
double _height;
@@ -36,11 +37,12 @@ namespace systemtap
bool _autoScrolling;
double _zoomFactor;
std::tr1::shared_ptr<CairoPlayButton> _playButton;
+ DatasetList& getDatasets() { return _datasets; }
+ int64_t getTimeAtPoint(double x);
protected:
- typedef std::vector<std::tr1::shared_ptr<GraphDataBase> > DatasetList;
DatasetList _datasets;
- double _left;
- double _right;
+ int64_t _left;
+ int64_t _right;
double _top;
double _bottom;
};
diff --git a/grapher/GraphData.hxx b/grapher/GraphData.hxx
index 0e26fb4d..e06ffdb8 100644
--- a/grapher/GraphData.hxx
+++ b/grapher/GraphData.hxx
@@ -1,6 +1,9 @@
#ifndef SYSTEMTAP_GRAPHDATA_HXX
#define SYSTEMTAP_GRAPHDATA_HXX 1
+#include <stdint.h>
+
+#include <sstream>
#include <string>
#include <utility>
#include <vector>
@@ -18,12 +21,13 @@ namespace systemtap
DOT,
EVENT
};
- typedef boost::circular_buffer<double> TimeList;
+ typedef boost::circular_buffer<int64_t> TimeList;
GraphDataBase(TimeList::capacity_type cap = 50000)
: scale(1.0), style(BAR), times(cap)
{
color[0] = 0.0; color[1] = 1.0; color[2] = 0.0;
}
+ virtual std::string elementAsString(size_t element) = 0;
// size of grid square at "normal" viewing
double scale;
double color[3];
@@ -44,6 +48,12 @@ namespace systemtap
: GraphDataBase(cap), data(cap)
{
}
+ std::string elementAsString(size_t element)
+ {
+ std::ostringstream stream;
+ stream << data[element];
+ return stream.str();
+ }
DataList data;
};
struct CSVData
diff --git a/grapher/StapParser.cxx b/grapher/StapParser.cxx
index 9e42dab6..ddc14b2d 100644
--- a/grapher/StapParser.cxx
+++ b/grapher/StapParser.cxx
@@ -25,7 +25,7 @@ vector<string> commaSplit(const boost::sub_range<Glib::ustring>& range)
}
void StapParser::parseData(shared_ptr<GraphDataBase> gdata,
- double time, const string& dataString)
+ int64_t time, const string& dataString)
{
std::istringstream stream(dataString);
shared_ptr<GraphData<double> > dblptr;
@@ -182,7 +182,7 @@ vector<string> commaSplit(const boost::sub_range<Glib::ustring>& range)
{
vector<string> tokens = commaSplit(dataString);
int i = 0;
- double time;
+ int64_t time;
vector<string>::iterator tokIter = tokens.begin();
std::istringstream timeStream(*tokIter++);
timeStream >> time;
@@ -196,7 +196,7 @@ vector<string> commaSplit(const boost::sub_range<Glib::ustring>& range)
}
else
{
- double time;
+ int64_t time;
string data;
stream >> time >> data;
parseData(itr->second, time, data);
diff --git a/grapher/StapParser.hxx b/grapher/StapParser.hxx
index 40add9fd..a77ad1bc 100644
--- a/grapher/StapParser.hxx
+++ b/grapher/StapParser.hxx
@@ -21,7 +21,7 @@ public:
{
}
void parseData(std::tr1::shared_ptr<GraphDataBase> gdata,
- double time, const std::string& dataString);
+ int64_t time, const std::string& dataString);
bool ioCallback(Glib::IOCondition ioCondition);
bool errIoCallback(Glib::IOCondition ioCondition);
int getErrFd() { return _errFd; }