summaryrefslogtreecommitdiffstats
path: root/grapher/GraphData.hxx
blob: fb1ca9f528f992545b2a6af44f6a5436e398595c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// 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_GRAPHDATA_HXX
#define SYSTEMTAP_GRAPHDATA_HXX 1

#include <stdint.h>

#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include <tr1/memory>

#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() {}

    typedef boost::circular_buffer<int64_t> TimeList;
    GraphDataBase(TimeList::capacity_type cap = 50000)
      : scale(1.0), style(&GraphStyleBar::instance), 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
    std::string name;
    double scale;
    double color[3];
    GraphStyle* style;
    std::string title;
    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>
  class GraphData : public GraphDataBase
  {
  public:
    typedef T data_type;
    typedef boost::circular_buffer<data_type> DataList;
    GraphData(typename DataList::capacity_type cap = 50000)
      : GraphDataBase(cap), data(cap)
    {
    }
    std::string elementAsString(size_t element)
    {
      std::ostringstream stream;
      stream << data[element];
      return stream.str();
    }
    DataList data;
  };
  struct CSVData
  {
    typedef std::pair<std::string, std::tr1::shared_ptr<GraphDataBase> >
    Element;
    std::vector<Element> elements;
  };

  inline GraphDataList& getGraphData() { return GraphDataBase::graphData; }

  inline sigc::signal<void>& graphDataSignal()
  {
    return GraphDataBase::graphDataChanged;
  }
}
#endif