Metric.h revision f5af85a2946ed4e1ff4766829d328cfb4961f259
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 { namespace 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*); 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 virtual void 52 Write (CFCMutableArray& parent) 53 { 54 WriteImpl(parent, identity<ValueType>()); 55 } 56 57private: 58 59 template<typename T> 60 struct identity { typedef T type; }; 61 62 void WriteImpl (CFCMutableArray& parent, identity<double>); 63 64 void WriteImpl (CFCMutableArray& parent, identity<mach_vm_size_t>); 65 66 std::string m_name; 67 std::vector<ValueType> m_dataset; 68}; 69} } 70 71#endif /* defined(__PerfTestDriver__Metric__) */ 72