Metric.h revision af222500aa2ce2b18149277e561cdf75f2115df2
1//
2//  Metric.h
3//  PerfTestDriver
4//
5//  Created by Enrico Granata on 3/7/13.
6//  Copyright (c) 2013 Apple Inc. All rights reserved.
7//
8
9#ifndef __PerfTestDriver__Metric__
10#define __PerfTestDriver__Metric__
11
12#include <vector>
13#include <string>
14#include <mach/task_info.h>
15
16#include "CFCMutableArray.h"
17
18namespace lldb_perf
19{
20class WriteToPList
21{
22public:
23    virtual void
24    Write (CFCMutableArray& parent) = 0;
25
26    virtual
27    ~WriteToPList () {}
28};
29
30template <class ValueType>
31class Metric : public WriteToPList {
32public:
33    Metric ();
34    Metric (const char*, const char* = NULL);
35
36    void
37    append (ValueType v);
38
39    size_t
40    count ();
41
42    ValueType
43    sum ();
44
45    ValueType
46    average ();
47
48    const char*
49    name ();
50
51    const char*
52    description ();
53
54    virtual void
55    Write (CFCMutableArray& parent)
56    {
57        WriteImpl(parent, identity<ValueType>());
58    }
59
60private:
61
62    template<typename T>
63    struct identity { typedef T type; };
64
65    void WriteImpl (CFCMutableArray& parent, identity<double>);
66
67    void WriteImpl (CFCMutableArray& parent, identity<mach_vm_size_t>);
68
69    std::string m_name;
70    std::string m_description;
71    std::vector<ValueType> m_dataset;
72};
73}
74
75#endif /* defined(__PerfTestDriver__Metric__) */
76