summaryrefslogtreecommitdiffstats
path: root/grapher/Time.hxx
diff options
context:
space:
mode:
authorTim Moore <timoore@redhat.com>2009-12-22 11:35:38 +0100
committerTim Moore <timoore@redhat.com>2009-12-23 00:04:11 +0100
commite3a546d81cd115d7cd9105fc31ecccecfb48b71d (patch)
treeedaf59835ce9774b69c72ddbe9ec28dfb925b188 /grapher/Time.hxx
parent2d0ddea123e8d5d1113b80692689a80f37d46e6f (diff)
downloadsystemtap-steved-e3a546d81cd115d7cd9105fc31ecccecfb48b71d.tar.gz
systemtap-steved-e3a546d81cd115d7cd9105fc31ecccecfb48b71d.tar.xz
systemtap-steved-e3a546d81cd115d7cd9105fc31ecccecfb48b71d.zip
grapher: scroll continuously with time
Don't scale graph based on how much data will fit. This didn't work very well and resulted in distracting, weird scale changes. We now assume that scripts output their time (x axis) in milliseconds. * grapher/Graph.hxx (setCurrentTime): New function. * grapher/Graph.cxx (Graph::draw): Assume a fixed default scale of 1 pixel = 5 milliseconds and don't do any autoscaling. * grapher/GraphWidget.cxx (GraphWidget constructor): Set global time base on startup. (on_expose_event): Don't search graphs for earliest time. * grapher/GraphWidget.hxx (_timeBaseInitialized): delete * grapher/Time.hxx: new file; interface to timeval.
Diffstat (limited to 'grapher/Time.hxx')
-rw-r--r--grapher/Time.hxx83
1 files changed, 83 insertions, 0 deletions
diff --git a/grapher/Time.hxx b/grapher/Time.hxx
new file mode 100644
index 00000000..7e16b7b2
--- /dev/null
+++ b/grapher/Time.hxx
@@ -0,0 +1,83 @@
+// systemtap grapher
+// Copyright (C) 2009 Red Hat Inc.
+//
+// This file is part of systemtap, and is free software. You can
+// redistribute it and/or modify it under the terms of the GNU General
+// Public License (GPL); either version 2, or (at your option) any
+// later version.
+
+#ifndef SYSTEMTAP_GRAPHER_TIME_HXX
+#define SYSTEMTAP_GRAPHER_TIME_HXX 1
+
+#include <stdint.h>
+#include <sys/time.h>
+
+namespace systemtap
+{
+
+template<typename T>
+class Singleton
+{
+public:
+ static T& instance()
+ {
+ static T _instance;
+ return _instance;
+ }
+protected:
+ Singleton() {}
+private:
+ // Insure that singleton is constructed before main() is called.
+ struct InstanceBuilder
+ {
+ InstanceBuilder()
+ {
+ instance();
+ }
+ };
+ static InstanceBuilder _instanceBuilder;
+};
+
+template<typename T>
+typename Singleton<T>::InstanceBuilder Singleton<T>::_instanceBuilder;
+
+class Time : public Singleton<Time>
+{
+public:
+ Time()
+ : origin(0)
+ {
+ origin = getTime();
+ }
+
+ int64_t getTime()
+ {
+ timeval tval;
+ gettimeofday(&tval, 0);
+ int64_t now = toUs(tval);
+ return now - origin;
+ }
+
+ static int64_t get()
+ {
+ return instance().getTime();
+ }
+
+ static int64_t getAbs()
+ {
+ timeval tval;
+ gettimeofday(&tval, 0);
+ return toUs(tval);
+ }
+
+ static int64_t toUs(const timeval& t)
+ {
+ int64_t result = t.tv_sec * 1000000;
+ result += t.tv_usec;
+ return result;
+ }
+
+ int64_t origin;
+};
+}
+#endif