-
Notifications
You must be signed in to change notification settings - Fork 0
/
statistic.h
96 lines (78 loc) · 1.83 KB
/
statistic.h
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
#ifndef STATISTIC_H
#define STATISTIC_H
#include <memory>
#include <math.h>
#include <map>
#include "expression.h"
#include "pmccontext.h"
class Statistic
{
std::auto_ptr<std::string> name;
std::auto_ptr<Expression> expr;
double goodThreshold;
double okThreshold;
double badThreshold;
std::map<int, double> cachedValues;
enum { ALL_CPUS = -1 };
/* true if a larger value is better */
bool ascending() const
{
return (goodThreshold > okThreshold);
}
public:
enum Status { STAT_GOOD = 1, STAT_OK, STAT_BAD, STAT_TERRIBLE };
Statistic(std::string *n, Expression *e, double good, double ok,
double bad)
: name(n), expr(e), goodThreshold(good), okThreshold(ok),
badThreshold(bad)
{
}
Statistic(const std::string &n, Expression *e, double good, double ok,
double bad)
: name(new std::string(n)), expr(e), goodThreshold(good),
okThreshold(ok), badThreshold(bad)
{
}
const std::string &getName() const
{
return *name.get();
}
Expression &getExpr() const
{
return *expr.get();
}
Status getStatus(double value) const
{
if (ascending()) {
if (isgreater(value, goodThreshold))
return (STAT_GOOD);
else if (isgreater(value, okThreshold))
return (STAT_OK);
else if (isgreater(value, badThreshold))
return (STAT_BAD);
else
return (STAT_TERRIBLE);
} else {
if (isless(value, goodThreshold))
return (STAT_GOOD);
else if (isless(value, okThreshold))
return (STAT_OK);
else if (isless(value, badThreshold))
return (STAT_BAD);
else
return (STAT_TERRIBLE);
}
}
void setLastValue(double value, int cpu = ALL_CPUS)
{
cachedValues[cpu] = value;
}
double getLastValue(int cpu = ALL_CPUS)
{
std::map<int, double>::iterator it = cachedValues.find(cpu);
if(it == cachedValues.end())
throw PmcNotLoaded();
return (it->second);
}
};
#endif