Skip to content
This repository was archived by the owner on May 21, 2019. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ec87e5c

Browse files
author
Enrico Granata
committedApr 15, 2013
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> git-svn-id: https://llvm.org/svn/llvm-project/lldb/trunk@179550 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent b8158c8 commit ec87e5c

File tree

6 files changed

+68
-25
lines changed

6 files changed

+68
-25
lines changed
 

‎tools/lldb-perf/darwin/sketch/sketch.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ class SketchTest : public TestCase
204204
switch (counter)
205205
{
206206
case 0:
207-
case 10:
207+
case 10:
208+
case 20:
208209
{
209210
DoTest ();
210211
if (counter == 0)
@@ -215,6 +216,7 @@ class SketchTest : public TestCase
215216

216217
case 1:
217218
case 11:
219+
case 21:
218220
{
219221
DoTest ();
220222
m_run_expr_measurement(m_thread.GetFrameAtIndex(0),"properties");
@@ -228,6 +230,7 @@ class SketchTest : public TestCase
228230

229231
case 2:
230232
case 12:
233+
case 22:
231234
{
232235
DoTest ();
233236
next_action.Continue();
@@ -236,6 +239,7 @@ class SketchTest : public TestCase
236239

237240
case 3:
238241
case 13:
242+
case 23:
239243
{
240244
DoTest ();
241245
next_action.StepOver(m_thread);
@@ -244,6 +248,7 @@ class SketchTest : public TestCase
244248

245249
case 4:
246250
case 14:
251+
case 24:
247252

248253
{
249254
DoTest ();
@@ -255,6 +260,7 @@ class SketchTest : public TestCase
255260

256261
case 5:
257262
case 15:
263+
case 25:
258264
{
259265
DoTest ();
260266
next_action.StepOver(m_thread);
@@ -263,6 +269,7 @@ class SketchTest : public TestCase
263269

264270
case 6:
265271
case 16:
272+
case 26:
266273
{
267274
DoTest ();
268275
next_action.StepOver(m_thread);
@@ -271,6 +278,7 @@ class SketchTest : public TestCase
271278

272279
case 7:
273280
case 17:
281+
case 27:
274282
{
275283
DoTest ();
276284
m_run_expr_measurement(m_thread.GetFrameAtIndex(0),"@\"an NSString\"");
@@ -282,6 +290,7 @@ class SketchTest : public TestCase
282290

283291
case 8:
284292
case 18:
293+
case 28:
285294
{
286295
DoTest ();
287296
m_run_expr_measurement(m_thread.GetFrameAtIndex(0),"[graphics description]");
@@ -290,6 +299,7 @@ class SketchTest : public TestCase
290299
}
291300
break;
292301
case 9:
302+
case 19:
293303
{
294304
next_action.Relaunch(GetLaunchInfo());
295305
break;
@@ -306,11 +316,11 @@ class SketchTest : public TestCase
306316
virtual void
307317
WriteResults (Results &results)
308318
{
309-
m_fetch_frames_measurement.WriteAverageValue(results);
310-
m_file_line_bp_measurement.WriteAverageValue(results);
311-
m_fetch_modules_measurement.WriteAverageValue(results);
312-
m_fetch_vars_measurement.WriteAverageValue(results);
313-
m_run_expr_measurement.WriteAverageValue(results);
319+
m_fetch_frames_measurement.WriteAverageAndStandardDeviation(results);
320+
m_file_line_bp_measurement.WriteAverageAndStandardDeviation(results);
321+
m_fetch_modules_measurement.WriteAverageAndStandardDeviation(results);
322+
m_fetch_vars_measurement.WriteAverageAndStandardDeviation(results);
323+
m_run_expr_measurement.WriteAverageAndStandardDeviation(results);
314324
results.Write(GetResultFilePath());
315325
}
316326

‎tools/lldb-perf/lib/Measurement.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,17 @@ class Measurement
112112
results.GetDictionary().Add(metric.GetName(), metric.GetDescription(), lldb_perf::GetResult<typename GaugeType::ValueType> (NULL, metric.GetAverage()));
113113
}
114114

115+
void
116+
WriteAverageAndStandardDeviation (Results &results)
117+
{
118+
auto metric = GetMetric ();
119+
auto dictionary = (Results::Dictionary*)results.GetDictionary().Add(metric.GetName(), metric.GetDescription(), lldb_perf::GetResult<typename GaugeType::ValueType> (NULL, metric.GetAverage())).get();
120+
if (dictionary)
121+
{
122+
dictionary->Add("stddev", NULL, lldb_perf::GetResult<typename GaugeType::ValueType> (NULL, metric.GetStandardDeviation()));
123+
}
124+
}
125+
115126
void
116127
WriteStandardDeviation (Results &results)
117128
{

‎tools/lldb-perf/lib/Metric.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,28 @@ Metric<T>::GetAverage () const
5757
return GetSum()/GetCount();
5858
}
5959

60+
61+
// Knuth's algorithm for stddev - massive cancellation resistant
6062
template <class T>
6163
T
62-
Metric<T>::GetStandardDeviation () const
64+
Metric<T>::GetStandardDeviation (StandardDeviationMode mode) const
6365
{
64-
T average = GetAverage();
65-
T diff_squared = 0;
66-
size_t count = GetCount();
67-
for (auto v : m_dataset)
68-
diff_squared = diff_squared + ( (v-average)*(v-average) );
69-
diff_squared = diff_squared / count;
70-
return sqrt(diff_squared);
66+
size_t n = 0;
67+
T mean = 0;
68+
T M2 = 0;
69+
for (auto x : m_dataset)
70+
{
71+
n = n + 1;
72+
T delta = x - mean;
73+
mean = mean + delta/n;
74+
M2 = M2+delta*(x-mean);
75+
}
76+
T variance;
77+
if (mode == StandardDeviationMode::ePopulation || n == 1)
78+
variance = M2 / n;
79+
else
80+
variance = M2 / (n - 1);
81+
return sqrt(variance);
7182
}
7283

7384
template class lldb_perf::Metric<double>;

‎tools/lldb-perf/lib/Metric.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ template <class ValueType>
2222
class Metric
2323
{
2424
public:
25+
enum class StandardDeviationMode
26+
{
27+
eSample,
28+
ePopulation
29+
};
30+
2531
Metric ();
2632
Metric (const char*, const char* = NULL);
2733

@@ -38,7 +44,7 @@ class Metric
3844
GetSum () const;
3945

4046
ValueType
41-
GetStandardDeviation () const;
47+
GetStandardDeviation (StandardDeviationMode mode = StandardDeviationMode::ePopulation) const;
4248

4349
const char*
4450
GetName () const

‎tools/lldb-perf/lib/Results.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ Results::Write (const char *out_path)
176176
#endif
177177
}
178178

179-
void
179+
Results::ResultSP
180180
Results::Dictionary::AddUnsigned (const char *name, const char *description, uint64_t value)
181181
{
182182
assert (name && name[0]);
@@ -189,9 +189,10 @@ Results::Dictionary::AddUnsigned (const char *name, const char *description, uin
189189
}
190190
else
191191
m_dictionary[std::string(name)] = ResultSP (new Unsigned (name, description, value));
192+
return m_dictionary[std::string(name)];
192193
}
193194

194-
void
195+
Results::ResultSP
195196
Results::Dictionary::AddDouble (const char *name, const char *description, double value)
196197
{
197198
assert (name && name[0]);
@@ -205,8 +206,9 @@ Results::Dictionary::AddDouble (const char *name, const char *description, doubl
205206
}
206207
else
207208
m_dictionary[std::string(name)] = ResultSP (new Double (name, description, value));
209+
return m_dictionary[std::string(name)];
208210
}
209-
void
211+
Results::ResultSP
210212
Results::Dictionary::AddString (const char *name, const char *description, const char *value)
211213
{
212214
assert (name && name[0]);
@@ -219,9 +221,10 @@ Results::Dictionary::AddString (const char *name, const char *description, const
219221
}
220222
else
221223
m_dictionary[std::string(name)] = ResultSP (new String (name, description, value));
224+
return m_dictionary[std::string(name)];
222225
}
223226

224-
void
227+
Results::ResultSP
225228
Results::Dictionary::Add (const char *name, const char *description, const ResultSP &result_sp)
226229
{
227230
assert (name && name[0]);
@@ -234,6 +237,7 @@ Results::Dictionary::Add (const char *name, const char *description, const Resul
234237
}
235238
else
236239
m_dictionary[std::string(name)] = result_sp;
240+
return m_dictionary[std::string(name)];
237241
}
238242

239243
void
@@ -249,10 +253,11 @@ Results::Dictionary::ForEach (const std::function <bool (const std::string &, co
249253

250254

251255

252-
void
256+
Results::ResultSP
253257
Results::Array::Append (const ResultSP &result_sp)
254258
{
255259
m_array.push_back (result_sp);
260+
return result_sp;
256261
}
257262

258263
void

‎tools/lldb-perf/lib/Results.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class Results
138138
{
139139
}
140140

141-
void
141+
ResultSP
142142
Append (const ResultSP &result_sp);
143143

144144
void
@@ -179,16 +179,16 @@ class Results
179179
void
180180
ForEach (const std::function <bool (const std::string &, const ResultSP &)> &callback);
181181

182-
void
182+
ResultSP
183183
Add (const char *name, const char *description, const ResultSP &result_sp);
184184

185-
void
185+
ResultSP
186186
AddDouble (const char *name, const char *descriptiorn, double value);
187187

188-
void
188+
ResultSP
189189
AddUnsigned (const char *name, const char *description, uint64_t value);
190190

191-
void
191+
ResultSP
192192
AddString (const char *name, const char *description, const char *value);
193193

194194
protected:

0 commit comments

Comments
 (0)
This repository has been archived.