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
|
//
// Metric.cpp
// PerfTestDriver
//
// Created by Enrico Granata on 3/7/13.
// Copyright (c) 2013 Apple Inc. All rights reserved.
//
#include "Metric.h"
#include "CFCMutableArray.h"
#include "CFCMutableDictionary.h"
#include "CFCString.h"
using namespace lldb::perf;
template <class T>
Metric<T>::Metric () : Metric ("")
{}
template <class T>
Metric<T>::Metric (const char* n) :
m_name(n ? n : ""),
m_dataset ()
{}
template <class T>
void
Metric<T>::append (T v)
{
m_dataset.push_back(v);
}
template <class T>
size_t
Metric<T>::count ()
{
return m_dataset.size();
}
template <class T>
T
Metric<T>::sum ()
{
T sum = 0;
for (auto v : m_dataset)
sum += v;
return sum;
}
template <class T>
T
Metric<T>::average ()
{
return sum()/count();
}
template <class T>
const char*
Metric<T>::name ()
{
return m_name.c_str();
}
template <class T>
void Metric<T>::WriteImpl (CFCMutableArray& parent, identity<double>)
{
CFCMutableDictionary dict;
dict.AddValueCString(CFCString("name").get(),m_name.c_str(), true);
dict.AddValueDouble(CFCString("value").get(),this->average(), true);
parent.AppendValue(dict.get(), true);
}
template <class T>
void Metric<T>::WriteImpl (CFCMutableArray& parent, identity<mach_vm_size_t>)
{
CFCMutableDictionary dict;
dict.AddValueCString(CFCString("name").get(),m_name.c_str(), true);
dict.AddValueUInt64(CFCString("value").get(),this->average(), true);
parent.AppendValue(dict.get(), true);
}
template class lldb::perf::Metric<double>;
template class lldb::perf::Metric<mach_vm_size_t>;
|