[Lldb-commits] [lldb] r179550 - Enabling test case to write the average+stddev pair to the results

Enrico Granata egranata at apple.com
Mon Apr 15 12:57:32 PDT 2013


Author: enrico
Date: Mon Apr 15 14:57:32 2013
New Revision: 179550

URL: http://llvm.org/viewvc/llvm-project?rev=179550&view=rev
Log:
Enabling test case to write the average+stddev pair to the results
The sketch test case writes avg+stddev for all its metrics:
	<key>fetch-frames</key>
	<dict>
		<key>description</key>
		<string>time to dump backtrace for every frame in every thread</string>
		<key>stddev</key>
		<real>0.006270938361432314</real>
		<key>value</key>
		<real>0.011568079851851851</real>
	</dict>

Modified:
    lldb/trunk/tools/lldb-perf/darwin/sketch/sketch.cpp
    lldb/trunk/tools/lldb-perf/lib/Measurement.h
    lldb/trunk/tools/lldb-perf/lib/Metric.cpp
    lldb/trunk/tools/lldb-perf/lib/Metric.h
    lldb/trunk/tools/lldb-perf/lib/Results.cpp
    lldb/trunk/tools/lldb-perf/lib/Results.h

Modified: lldb/trunk/tools/lldb-perf/darwin/sketch/sketch.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-perf/darwin/sketch/sketch.cpp?rev=179550&r1=179549&r2=179550&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-perf/darwin/sketch/sketch.cpp (original)
+++ lldb/trunk/tools/lldb-perf/darwin/sketch/sketch.cpp Mon Apr 15 14:57:32 2013
@@ -204,7 +204,8 @@ public:
         switch (counter)
         {
         case 0:
-        case 10:
+            case 10:
+            case 20:
             {
                 DoTest ();
                 if (counter == 0)
@@ -215,6 +216,7 @@ public:
                 
         case 1:
             case 11:
+            case 21:
             {
                 DoTest ();
                 m_run_expr_measurement(m_thread.GetFrameAtIndex(0),"properties");
@@ -228,6 +230,7 @@ public:
 
         case 2:
             case 12:
+            case 22:
             {
                 DoTest ();
                 next_action.Continue();
@@ -236,6 +239,7 @@ public:
 
         case 3:
             case 13:
+            case 23:
             {
                 DoTest ();
                 next_action.StepOver(m_thread);
@@ -244,6 +248,7 @@ public:
 
         case 4:
             case 14:
+            case 24:
                 
             {
                 DoTest ();
@@ -255,6 +260,7 @@ public:
         
         case 5:
             case 15:
+            case 25:
             {
                 DoTest ();
                 next_action.StepOver(m_thread);
@@ -263,6 +269,7 @@ public:
 
         case 6:
             case 16:
+            case 26:
             {
                 DoTest ();
                 next_action.StepOver(m_thread);
@@ -271,6 +278,7 @@ public:
 
         case 7:
             case 17:
+            case 27:
             {
                 DoTest ();
                 m_run_expr_measurement(m_thread.GetFrameAtIndex(0),"@\"an NSString\"");
@@ -282,6 +290,7 @@ public:
 
         case 8:
             case 18:
+            case 28:
             {
                 DoTest ();
                 m_run_expr_measurement(m_thread.GetFrameAtIndex(0),"[graphics description]");
@@ -290,6 +299,7 @@ public:
             }
             break;
         case 9:
+            case 19:
             {
                 next_action.Relaunch(GetLaunchInfo());
                 break;
@@ -306,11 +316,11 @@ public:
     virtual void
     WriteResults (Results &results)
     {
-        m_fetch_frames_measurement.WriteAverageValue(results);
-        m_file_line_bp_measurement.WriteAverageValue(results);
-        m_fetch_modules_measurement.WriteAverageValue(results);
-        m_fetch_vars_measurement.WriteAverageValue(results);
-        m_run_expr_measurement.WriteAverageValue(results);
+        m_fetch_frames_measurement.WriteAverageAndStandardDeviation(results);
+        m_file_line_bp_measurement.WriteAverageAndStandardDeviation(results);
+        m_fetch_modules_measurement.WriteAverageAndStandardDeviation(results);
+        m_fetch_vars_measurement.WriteAverageAndStandardDeviation(results);
+        m_run_expr_measurement.WriteAverageAndStandardDeviation(results);
         results.Write(GetResultFilePath());
     }
     

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=179550&r1=179549&r2=179550&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-perf/lib/Measurement.h (original)
+++ lldb/trunk/tools/lldb-perf/lib/Measurement.h Mon Apr 15 14:57:32 2013
@@ -113,6 +113,17 @@ public:
     }
     
     void
+    WriteAverageAndStandardDeviation (Results &results)
+    {
+        auto metric = GetMetric ();
+        auto dictionary = (Results::Dictionary*)results.GetDictionary().Add(metric.GetName(), metric.GetDescription(), lldb_perf::GetResult<typename GaugeType::ValueType> (NULL, metric.GetAverage())).get();
+        if (dictionary)
+        {
+            dictionary->Add("stddev", NULL, lldb_perf::GetResult<typename GaugeType::ValueType> (NULL, metric.GetStandardDeviation()));
+        }
+    }
+    
+    void
     WriteStandardDeviation (Results &results)
     {
         auto metric = GetMetric ();

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=179550&r1=179549&r2=179550&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-perf/lib/Metric.cpp (original)
+++ lldb/trunk/tools/lldb-perf/lib/Metric.cpp Mon Apr 15 14:57:32 2013
@@ -57,17 +57,28 @@ Metric<T>::GetAverage () const
     return GetSum()/GetCount();
 }
 
+
+// Knuth's algorithm for stddev - massive cancellation resistant
 template <class T>
 T
-Metric<T>::GetStandardDeviation () const
+Metric<T>::GetStandardDeviation (StandardDeviationMode mode) 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);
+    size_t n = 0;
+    T mean = 0;
+    T M2 = 0;
+    for (auto x : m_dataset)
+    {
+        n = n + 1;
+        T delta = x - mean;
+        mean = mean + delta/n;
+        M2 = M2+delta*(x-mean);
+    }
+    T variance;
+    if (mode == StandardDeviationMode::ePopulation || n == 1)
+        variance = M2 / n;
+    else
+        variance = M2 / (n - 1);
+    return sqrt(variance);
 }
 
 template class lldb_perf::Metric<double>;

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=179550&r1=179549&r2=179550&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-perf/lib/Metric.h (original)
+++ lldb/trunk/tools/lldb-perf/lib/Metric.h Mon Apr 15 14:57:32 2013
@@ -22,6 +22,12 @@ template <class ValueType>
 class Metric
 {
 public:
+    enum class StandardDeviationMode
+    {
+        eSample,
+        ePopulation
+    };
+    
     Metric ();
     Metric (const char*, const char* = NULL);
     
@@ -38,7 +44,7 @@ public:
     GetSum () const;
     
     ValueType
-    GetStandardDeviation () const;
+    GetStandardDeviation (StandardDeviationMode mode = StandardDeviationMode::ePopulation) const;
     
     const char*
     GetName () const

Modified: lldb/trunk/tools/lldb-perf/lib/Results.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-perf/lib/Results.cpp?rev=179550&r1=179549&r2=179550&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-perf/lib/Results.cpp (original)
+++ lldb/trunk/tools/lldb-perf/lib/Results.cpp Mon Apr 15 14:57:32 2013
@@ -176,7 +176,7 @@ Results::Write (const char *out_path)
 #endif
 }
 
-void
+Results::ResultSP
 Results::Dictionary::AddUnsigned (const char *name, const char *description, uint64_t value)
 {
     assert (name && name[0]);
@@ -189,9 +189,10 @@ Results::Dictionary::AddUnsigned (const
     }
     else
         m_dictionary[std::string(name)] = ResultSP (new Unsigned (name, description, value));
+    return m_dictionary[std::string(name)];
 }
 
-void
+Results::ResultSP
 Results::Dictionary::AddDouble (const char *name, const char *description, double value)
 {
     assert (name && name[0]);
@@ -205,8 +206,9 @@ Results::Dictionary::AddDouble (const ch
     }
     else
         m_dictionary[std::string(name)] = ResultSP (new Double (name, description, value));
+    return m_dictionary[std::string(name)];
 }
-void
+Results::ResultSP
 Results::Dictionary::AddString (const char *name, const char *description, const char *value)
 {
     assert (name && name[0]);
@@ -219,9 +221,10 @@ Results::Dictionary::AddString (const ch
     }
     else
         m_dictionary[std::string(name)] = ResultSP (new String (name, description, value));
+    return m_dictionary[std::string(name)];
 }
 
-void
+Results::ResultSP
 Results::Dictionary::Add (const char *name, const char *description, const ResultSP &result_sp)
 {
     assert (name && name[0]);
@@ -234,6 +237,7 @@ Results::Dictionary::Add (const char *na
     }
     else
         m_dictionary[std::string(name)] = result_sp;
+    return m_dictionary[std::string(name)];
 }
 
 void
@@ -249,10 +253,11 @@ Results::Dictionary::ForEach (const std:
 
 
 
-void
+Results::ResultSP
 Results::Array::Append (const ResultSP &result_sp)
 {
     m_array.push_back (result_sp);
+    return result_sp;
 }
 
 void

Modified: lldb/trunk/tools/lldb-perf/lib/Results.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/lldb-perf/lib/Results.h?rev=179550&r1=179549&r2=179550&view=diff
==============================================================================
--- lldb/trunk/tools/lldb-perf/lib/Results.h (original)
+++ lldb/trunk/tools/lldb-perf/lib/Results.h Mon Apr 15 14:57:32 2013
@@ -138,7 +138,7 @@ public:
         {
         }
         
-        void
+        ResultSP
         Append (const ResultSP &result_sp);
 
         void
@@ -179,16 +179,16 @@ public:
         void
         ForEach (const std::function <bool (const std::string &, const ResultSP &)> &callback);
     
-        void
+        ResultSP
         Add (const char *name, const char *description, const ResultSP &result_sp);
         
-        void
+        ResultSP
         AddDouble (const char *name, const char *descriptiorn, double value);
         
-        void
+        ResultSP
         AddUnsigned (const char *name, const char *description, uint64_t value);
 
-        void
+        ResultSP
         AddString (const char *name, const char *description, const char *value);
 
     protected:





More information about the lldb-commits mailing list