forked from OSchip/llvm-project
Enabling metrics to calculate (and dump) their standard deviation
llvm-svn: 178580
This commit is contained in:
parent
516487765a
commit
1ed58f7baf
|
@ -111,6 +111,13 @@ public:
|
|||
auto metric = GetMetric ();
|
||||
results.GetDictionary().Add(metric.GetName(), metric.GetDescription(), lldb_perf::GetResult<typename GaugeType::ValueType> (NULL, metric.GetAverage()));
|
||||
}
|
||||
|
||||
void
|
||||
WriteStandardDeviation (Results &results)
|
||||
{
|
||||
auto metric = GetMetric ();
|
||||
results.GetDictionary().Add(metric.GetName(), metric.GetDescription(), lldb_perf::GetResult<typename GaugeType::ValueType> (NULL, metric.GetStandardDeviation()));
|
||||
}
|
||||
|
||||
protected:
|
||||
GaugeType m_gauge;
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include "MemoryGauge.h"
|
||||
#include <assert.h>
|
||||
#include <cmath>
|
||||
#include <mach/mach.h>
|
||||
#include <mach/task.h>
|
||||
#include <mach/mach_traps.h>
|
||||
|
@ -61,13 +62,30 @@ MemoryStats::operator - (const MemoryStats& rhs)
|
|||
m_max_resident_size - rhs.m_max_resident_size);
|
||||
}
|
||||
|
||||
MemoryStats&
|
||||
MemoryStats
|
||||
MemoryStats::operator + (const MemoryStats& rhs)
|
||||
{
|
||||
return MemoryStats(m_virtual_size + rhs.m_virtual_size,
|
||||
m_resident_size + rhs.m_resident_size,
|
||||
m_max_resident_size + rhs.m_max_resident_size);
|
||||
}
|
||||
|
||||
MemoryStats
|
||||
MemoryStats::operator / (size_t n)
|
||||
{
|
||||
m_virtual_size /= n;
|
||||
m_resident_size /= n;
|
||||
m_max_resident_size /= n;
|
||||
return *this;
|
||||
MemoryStats result(*this);
|
||||
result.m_virtual_size /= n;
|
||||
result.m_resident_size /= n;
|
||||
result.m_max_resident_size /= n;
|
||||
return result;
|
||||
}
|
||||
|
||||
MemoryStats
|
||||
MemoryStats::operator * (const MemoryStats& rhs)
|
||||
{
|
||||
return MemoryStats(m_virtual_size * rhs.m_virtual_size,
|
||||
m_resident_size * rhs.m_resident_size,
|
||||
m_max_resident_size * rhs.m_max_resident_size);
|
||||
}
|
||||
|
||||
Results::ResultSP
|
||||
|
@ -130,3 +148,17 @@ lldb_perf::GetResult (const char *description, MemoryStats value)
|
|||
{
|
||||
return value.GetResult (NULL, description);
|
||||
}
|
||||
|
||||
MemoryStats
|
||||
sqrt (const MemoryStats& arg)
|
||||
{
|
||||
long double virt_size = arg.GetVirtualSize();
|
||||
long double resident_size = arg.GetResidentSize();
|
||||
long double max_resident_size = arg.GetMaxResidentSize();
|
||||
|
||||
virt_size = sqrtl(virt_size);
|
||||
resident_size = sqrtl(resident_size);
|
||||
max_resident_size = sqrtl(max_resident_size);
|
||||
|
||||
return MemoryStats(virt_size,resident_size,max_resident_size);
|
||||
}
|
||||
|
|
|
@ -34,9 +34,15 @@ public:
|
|||
MemoryStats
|
||||
operator - (const MemoryStats& rhs);
|
||||
|
||||
MemoryStats&
|
||||
MemoryStats
|
||||
operator + (const MemoryStats& rhs);
|
||||
|
||||
MemoryStats
|
||||
operator / (size_t rhs);
|
||||
|
||||
MemoryStats
|
||||
operator * (const MemoryStats& rhs);
|
||||
|
||||
mach_vm_size_t
|
||||
GetVirtualSize () const
|
||||
{
|
||||
|
@ -80,7 +86,7 @@ private:
|
|||
mach_vm_size_t m_resident_size;
|
||||
mach_vm_size_t m_max_resident_size;
|
||||
};
|
||||
|
||||
|
||||
class MemoryGauge : public Gauge<MemoryStats>
|
||||
{
|
||||
public:
|
||||
|
@ -135,4 +141,7 @@ GetResult (const char *description, MemoryStats value);
|
|||
|
||||
} // namespace lldb_perf
|
||||
|
||||
lldb_perf::MemoryStats
|
||||
sqrt (const lldb_perf::MemoryStats& arg);
|
||||
|
||||
#endif // #ifndef __PerfTestDriver__MemoryGauge__
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include "Metric.h"
|
||||
#include "MemoryGauge.h"
|
||||
#include <cmath>
|
||||
|
||||
using namespace lldb_perf;
|
||||
|
||||
|
@ -56,5 +57,18 @@ Metric<T>::GetAverage () const
|
|||
return GetSum()/GetCount();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
template class lldb_perf::Metric<double>;
|
||||
template class lldb_perf::Metric<MemoryStats>;
|
||||
|
|
|
@ -37,6 +37,9 @@ public:
|
|||
ValueType
|
||||
GetSum () const;
|
||||
|
||||
ValueType
|
||||
GetStandardDeviation () const;
|
||||
|
||||
const char*
|
||||
GetName () const
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue