2013-03-21 11:39:51 +08:00
|
|
|
//===-- Metric.cpp ----------------------------------------------*- C++ -*-===//
|
2013-03-09 04:29:13 +08:00
|
|
|
//
|
2013-03-21 11:39:51 +08:00
|
|
|
// The LLVM Compiler Infrastructure
|
2013-03-09 04:29:13 +08:00
|
|
|
//
|
2013-03-21 11:39:51 +08:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2013-03-09 04:29:13 +08:00
|
|
|
//
|
2013-03-21 11:39:51 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2013-03-09 04:29:13 +08:00
|
|
|
|
|
|
|
#include "Metric.h"
|
2013-03-21 05:18:20 +08:00
|
|
|
#include "MemoryGauge.h"
|
2013-04-03 05:59:39 +08:00
|
|
|
#include <cmath>
|
2013-03-09 04:29:13 +08:00
|
|
|
|
2013-03-19 06:34:00 +08:00
|
|
|
using namespace lldb_perf;
|
2013-03-09 04:29:13 +08:00
|
|
|
|
|
|
|
template <class T>
|
|
|
|
Metric<T>::Metric () : Metric ("")
|
2013-03-22 10:31:35 +08:00
|
|
|
{
|
|
|
|
}
|
2013-03-09 04:29:13 +08:00
|
|
|
|
|
|
|
template <class T>
|
2013-03-15 03:00:42 +08:00
|
|
|
Metric<T>::Metric (const char* n, const char* d) :
|
2013-03-22 10:31:35 +08:00
|
|
|
m_name(n ? n : ""),
|
|
|
|
m_description(d ? d : ""),
|
|
|
|
m_dataset ()
|
|
|
|
{
|
|
|
|
}
|
2013-03-09 04:29:13 +08:00
|
|
|
|
|
|
|
template <class T>
|
|
|
|
void
|
2013-03-21 11:32:24 +08:00
|
|
|
Metric<T>::Append (T v)
|
2013-03-09 04:29:13 +08:00
|
|
|
{
|
|
|
|
m_dataset.push_back(v);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
size_t
|
2013-03-21 11:32:24 +08:00
|
|
|
Metric<T>::GetCount () const
|
2013-03-09 04:29:13 +08:00
|
|
|
{
|
|
|
|
return m_dataset.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
T
|
2013-03-21 11:32:24 +08:00
|
|
|
Metric<T>::GetSum () const
|
2013-03-09 04:29:13 +08:00
|
|
|
{
|
|
|
|
T sum = 0;
|
|
|
|
for (auto v : m_dataset)
|
|
|
|
sum += v;
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
T
|
2013-03-21 11:32:24 +08:00
|
|
|
Metric<T>::GetAverage () const
|
2013-03-09 04:29:13 +08:00
|
|
|
{
|
2013-03-21 11:32:24 +08:00
|
|
|
return GetSum()/GetCount();
|
2013-03-15 03:00:42 +08:00
|
|
|
}
|
|
|
|
|
2013-04-03 05:59:39 +08:00
|
|
|
template <class T>
|
|
|
|
T
|
|
|
|
Metric<T>::GetStandardDeviation () const
|
|
|
|
{
|
|
|
|
T average = GetAverage();
|
|
|
|
T diff_squared = 0;
|
|
|
|
size_t count = GetCount();
|
|
|
|
for (auto v : m_dataset)
|
|
|
|
diff_squared = diff_squared + ( (v-average)*(v-average) );
|
|
|
|
diff_squared = diff_squared / count;
|
|
|
|
return sqrt(diff_squared);
|
|
|
|
}
|
|
|
|
|
2013-03-19 06:34:00 +08:00
|
|
|
template class lldb_perf::Metric<double>;
|
2013-03-21 05:18:20 +08:00
|
|
|
template class lldb_perf::Metric<MemoryStats>;
|