[Lldb-commits] [lldb] r178580 - Enabling metrics to calculate (and dump) their standard deviation
Enrico Granata
egranata at apple.com
Tue Apr 2 14:59:39 PDT 2013
Author: enrico
Date: Tue Apr 2 16:59:39 2013
New Revision: 178580
URL: http://llvm.org/viewvc/llvm-project?rev=178580&view=rev
Log:
Enabling metrics to calculate (and dump) their standard deviation
Modified:
lldb/trunk/tools/lldb-perf/lib/Measurement.h
lldb/trunk/tools/lldb-perf/lib/MemoryGauge.cpp
lldb/trunk/tools/lldb-perf/lib/MemoryGauge.h
lldb/trunk/tools/lldb-perf/lib/Metric.cpp
lldb/trunk/tools/lldb-perf/lib/Metric.h
Modified: lldb/trunk/tools/lldb-perf/lib/Measurement.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-perf/lib/Measurement.h?rev=178580&r1=178579&r2=178580&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-perf/lib/Measurement.h (original)
+++ lldb/trunk/tools/lldb-perf/lib/Measurement.h Tue Apr 2 16:59:39 2013
@@ -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;
Modified: lldb/trunk/tools/lldb-perf/lib/MemoryGauge.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-perf/lib/MemoryGauge.cpp?rev=178580&r1=178579&r2=178580&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-perf/lib/MemoryGauge.cpp (original)
+++ lldb/trunk/tools/lldb-perf/lib/MemoryGauge.cpp Tue Apr 2 16:59:39 2013
@@ -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 MemorySta
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 *descri
{
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);
+}
Modified: lldb/trunk/tools/lldb-perf/lib/MemoryGauge.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-perf/lib/MemoryGauge.h?rev=178580&r1=178579&r2=178580&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-perf/lib/MemoryGauge.h (original)
+++ lldb/trunk/tools/lldb-perf/lib/MemoryGauge.h Tue Apr 2 16:59:39 2013
@@ -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, Memo
} // namespace lldb_perf
+lldb_perf::MemoryStats
+sqrt (const lldb_perf::MemoryStats& arg);
+
#endif // #ifndef __PerfTestDriver__MemoryGauge__
Modified: lldb/trunk/tools/lldb-perf/lib/Metric.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-perf/lib/Metric.cpp?rev=178580&r1=178579&r2=178580&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-perf/lib/Metric.cpp (original)
+++ lldb/trunk/tools/lldb-perf/lib/Metric.cpp Tue Apr 2 16:59:39 2013
@@ -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>;
Modified: lldb/trunk/tools/lldb-perf/lib/Metric.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-perf/lib/Metric.h?rev=178580&r1=178579&r2=178580&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-perf/lib/Metric.h (original)
+++ lldb/trunk/tools/lldb-perf/lib/Metric.h Tue Apr 2 16:59:39 2013
@@ -37,6 +37,9 @@ public:
ValueType
GetSum () const;
+ ValueType
+ GetStandardDeviation () const;
+
const char*
GetName () const
{
More information about the lldb-commits
mailing list