Enrico Granata | f58cece | 2013-03-08 20:29:13 +0000 | [diff] [blame^] | 1 | // |
| 2 | // Metric.cpp |
| 3 | // PerfTestDriver |
| 4 | // |
| 5 | // Created by Enrico Granata on 3/7/13. |
| 6 | // Copyright (c) 2013 Apple Inc. All rights reserved. |
| 7 | // |
| 8 | |
| 9 | #include "Metric.h" |
| 10 | |
| 11 | #include "CFCMutableArray.h" |
| 12 | #include "CFCMutableDictionary.h" |
| 13 | #include "CFCString.h" |
| 14 | |
| 15 | using namespace lldb::perf; |
| 16 | |
| 17 | template <class T> |
| 18 | Metric<T>::Metric () : Metric ("") |
| 19 | {} |
| 20 | |
| 21 | template <class T> |
| 22 | Metric<T>::Metric (const char* n) : |
| 23 | m_name(n ? n : ""), |
| 24 | m_dataset () |
| 25 | {} |
| 26 | |
| 27 | template <class T> |
| 28 | void |
| 29 | Metric<T>::append (T v) |
| 30 | { |
| 31 | m_dataset.push_back(v); |
| 32 | } |
| 33 | |
| 34 | template <class T> |
| 35 | size_t |
| 36 | Metric<T>::count () |
| 37 | { |
| 38 | return m_dataset.size(); |
| 39 | } |
| 40 | |
| 41 | template <class T> |
| 42 | T |
| 43 | Metric<T>::sum () |
| 44 | { |
| 45 | T sum = 0; |
| 46 | for (auto v : m_dataset) |
| 47 | sum += v; |
| 48 | return sum; |
| 49 | } |
| 50 | |
| 51 | template <class T> |
| 52 | T |
| 53 | Metric<T>::average () |
| 54 | { |
| 55 | return sum()/count(); |
| 56 | } |
| 57 | |
| 58 | template <class T> |
| 59 | const char* |
| 60 | Metric<T>::name () |
| 61 | { |
| 62 | return m_name.c_str(); |
| 63 | } |
| 64 | |
| 65 | template <class T> |
| 66 | void Metric<T>::WriteImpl (CFCMutableArray& parent, identity<double>) |
| 67 | { |
| 68 | CFCMutableDictionary dict; |
| 69 | dict.AddValueCString(CFCString("name").get(),m_name.c_str(), true); |
| 70 | dict.AddValueDouble(CFCString("value").get(),this->average(), true); |
| 71 | parent.AppendValue(dict.get(), true); |
| 72 | } |
| 73 | |
| 74 | template <class T> |
| 75 | void Metric<T>::WriteImpl (CFCMutableArray& parent, identity<mach_vm_size_t>) |
| 76 | { |
| 77 | CFCMutableDictionary dict; |
| 78 | dict.AddValueCString(CFCString("name").get(),m_name.c_str(), true); |
| 79 | dict.AddValueUInt64(CFCString("value").get(),this->average(), true); |
| 80 | parent.AppendValue(dict.get(), true); |
| 81 | } |
| 82 | |
| 83 | template class lldb::perf::Metric<double>; |
| 84 | template class lldb::perf::Metric<mach_vm_size_t>; |