summaryrefslogtreecommitdiff
path: root/src/pmchart/tracing.h
blob: 3072808aa5f7263dc14242c927d9c06e501b4682 (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/*
 * Copyright (c) 2012, Red Hat.
 * Copyright (c) 2012, Nathan Scott.  All Rights Reserved.
 * 
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 */ 
#ifndef TRACING_H
#define TRACING_H

#include "chart.h"
#include <qvector.h>
#include <qwt_plot.h>
#include <qwt_scale_draw.h>
#include <qwt_scale_engine.h>
#include <qwt_interval_symbol.h>
#include <qwt_plot_intervalcurve.h>

class TracingEvent
{
public:
    TracingEvent() { }
    TracingEvent(QmcEventRecord const &, pmID, int);
    bool operator<(TracingEvent const& rhs)	// for sorting
	{ return my.timestamp < rhs.timestamp(); }
    virtual ~TracingEvent();

    double timestamp(void) const { return my.timestamp; }
    int missed(void) const { return my.missed; }
    bool hasIdentifier(void) const { return my.flags & PM_EVENT_FLAG_ID; }
    bool hasParent(void) const { return my.flags & PM_EVENT_FLAG_PARENT; }
    bool hasStartFlag(void) const { return my.flags & PM_EVENT_FLAG_START; }
    bool hasEndFlag(void) const { return my.flags & PM_EVENT_FLAG_END; }

    const QString &spanID(void) const { return my.spanID; }
    const QString &rootID(void) const { return my.rootID; }
    const QString &description(void) const { return my.description; }

private:
    struct {
	double		timestamp;	// from PMDA
	int		missed;		// from PMDA
	int		flags;		// from PMDA
	pmID		pmid;		// metric
	int		inst;		// instance
	QString		spanID;		// identifier
	QString		rootID;		// parent ID
	QString 	description;	// parameters, etc
    } my;
};

class TracingItem : public ChartItem
{
public:
    TracingItem() : ChartItem() { }
    TracingItem(Chart *, QmcMetric *, pmMetricSpec *, pmDesc *, const QString &);
    virtual ~TracingItem();

    QwtPlotItem *item();
    QwtPlotCurve *curve();

    void preserveSample(int, int) { }
    void punchoutSample(int) { }
    void resetValues(int, double, double);
    void updateValues(TracingEngine *, double, double);
    void rescaleValues(double *, double *);

    void clearCursor(void);
    bool containsPoint(const QRectF &, int);
    void updateCursor(const QPointF &, int);
    const QString &cursorInfo();

    void setStroke(Chart::Style, QColor, bool);
    void revive(void);
    void remove(void);
    void redraw(void);

private:
    void cullOutlyingDrops(double, double);
    void cullOutlyingSpans(double, double);
    void cullOutlyingPoints(double, double);
    void cullOutlyingEvents(double, double);

    void updateEvents(TracingEngine *, QmcMetric *);
    void updateEventRecords(TracingEngine *, QmcMetric *, int);
    void addTraceSpan(TracingEngine *, const QString &, int);
    void showEventInfo(bool, int);

    struct {
	QVector<TracingEvent> events;		// all events, raw data
	QVector<QPointF> selections;		// time series of selected points
	QString selectionInfo;

	QVector<QPointF> points;		// displayed trace data (point form)
	ChartCurve *pointCurve;
	QwtSymbol *pointSymbol;

	QVector<QPointF> selectionPoints;	// displayed user-selected trace points
	QwtPlotCurve *selectionCurve;
	QwtSymbol *selectionSymbol;

	QVector<QwtIntervalSample> spans;	// displayed trace data (horizontal span)
	QwtPlotIntervalCurve *spanCurve;
	QwtIntervalSymbol *spanSymbol;

	QVector<QwtIntervalSample> drops;	// displayed trace data (vertical drop)
	QwtPlotIntervalCurve *dropCurve;
	QwtIntervalSymbol *dropSymbol;

	double minSpanID;
	double maxSpanID;
	double minSpanTime;
	double maxSpanTime;

	Chart *chart;
    } my;
};

//
// Handles updates to the Y-Axis
//
class TracingScaleEngine : public QwtLinearScaleEngine
{
public:
    TracingScaleEngine(TracingEngine *engine);

    virtual void autoScale(int maxSteps, double &minValue,
                           double &maxValue, double &stepSize) const;
    virtual QwtScaleDiv divideScale(double x1, double x2,
        int numMajorSteps, int numMinorSteps, double stepSize = 0.0) const;

    void getScale(double *minSpanID, double *maxSpanID);
    void setScale(double minSpanID, double maxSpanID);
    bool updateScale(double minSpanID, double maxSpanID);

private:
    struct {
	double	minSpanID;
	double	maxSpanID;
	TracingEngine *engine;
    } my;
};

//
// Implements a mapping from span identifier to span name
// for updating the Y-Axis display.
//
class TracingScaleDraw : public QwtScaleDraw
{
public:
    TracingScaleDraw(TracingEngine *engine) : QwtScaleDraw() { my.engine = engine; }
    virtual QwtText label(double v) const;
    virtual void getBorderDistHint(const QFont &f, int &start, int &end) const;
    void invalidate() { invalidateCache(); }

private:
    struct {
	TracingEngine *engine;
    } my;
};

//
// Implement tracing-specific behaviour within a Chart
//
class TracingEngine : public ChartEngine
{
    friend class Chart;

public:
    TracingEngine(Chart *);

    bool isCompatible(pmDesc &);
    ChartItem *addItem(QmcMetric *, pmMetricSpec *, pmDesc *, const QString &);

    void updateValues(bool, int, int, double, double, double);

    void redoScale(void);
    void setScale(bool, double, double);
    void scale(bool *, double *, double *);
    void setStyle(Chart::Style);

    void addTraceSpan(const QString &, int);
    int getTraceSpan(const QString &, int) const;
    QString getSpanLabel(int) const;

    void selected(const QPolygon &);
    void replot(void);

private:
    TracingItem *tracingItem(int index);

    struct {
	QHash<QString, int> traceSpanMapping;	// map, event ID to y-axis point
	QHash<int, QString> labelSpanMapping;	// reverse -> y-axis point to ID
	TracingScaleEngine *scaleEngine;
	TracingScaleDraw *scaleDraw;		// convert ints to spanID
	Chart *chart;
    } my;
};

#endif	// TRACING_H