Metric.h revision 75fc5a74d95804e2ddc87bcade177640521147e0
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 MemoryStats; 21 22class WriteToPList 23{ 24public: 25 virtual void 26 Write (CFCMutableArray& parent) = 0; 27 28 virtual 29 ~WriteToPList () {} 30}; 31 32template <class ValueType> 33class Metric : public WriteToPList 34{ 35public: 36 Metric (); 37 Metric (const char*, const char* = NULL); 38 39 void 40 Append (ValueType v); 41 42 ValueType 43 GetAverage () const; 44 45 size_t 46 GetCount () const; 47 48 ValueType 49 GetSum () const; 50 51 const char* 52 GetName () 53 { 54 return m_name.c_str(); 55 } 56 57 const char* 58 GetDescription () 59 { 60 return m_description.c_str(); 61 } 62 63 virtual void 64 Write (CFCMutableArray& parent) 65 { 66 WriteImpl(parent, identity<ValueType>()); 67 } 68 69private: 70 71 template<typename T> 72 struct identity { typedef T type; }; 73 74 void WriteImpl (CFCMutableArray& parent, identity<double>); 75 76 void WriteImpl (CFCMutableArray& parent, identity<MemoryStats>); 77 78 std::string m_name; 79 std::string m_description; 80 std::vector<ValueType> m_dataset; 81}; 82} 83 84#endif /* defined(__PerfTestDriver__Metric__) */ 85