Flutter Engine
The Flutter Engine
Stats.h
Go to the documentation of this file.
1/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef Stats_DEFINED
9#define Stats_DEFINED
10
11#include <algorithm>
12#include <vector>
13
16
17#ifdef SK_BUILD_FOR_WIN
18 static const char* kBars[] = { ".", "o", "O" };
19#else
20 static const char* kBars[] = { "▁", "▂", "▃", "▄", "▅", "▆", "▇", "█" };
21#endif
22
23struct Stats {
24 Stats(const skia_private::TArray<double>& samples, bool want_plot) {
25 int n = samples.size();
26 if (!n) {
27 min = max = mean = var = median = 0;
28 return;
29 }
30
31 min = samples[0];
32 max = samples[0];
33 for (int i = 0; i < n; i++) {
34 if (samples[i] < min) { min = samples[i]; }
35 if (samples[i] > max) { max = samples[i]; }
36 }
37
38 double sum = 0.0;
39 for (int i = 0 ; i < n; i++) {
40 sum += samples[i];
41 }
42 mean = sum / n;
43
44 double err = 0.0;
45 for (int i = 0 ; i < n; i++) {
46 err += (samples[i] - mean) * (samples[i] - mean);
47 }
48 var = sk_ieee_double_divide(err, n-1);
49
50 std::vector<double> sorted(samples.begin(), samples.end());
51 std::sort(sorted.begin(), sorted.end());
52 median = sorted[n/2];
53
54 // Normalize samples to [min, max] in as many quanta as we have distinct bars to print.
55 for (int i = 0; want_plot && i < n; i++) {
56 if (min == max) {
57 // All samples are the same value. Don't divide by zero.
58 plot.append(kBars[0]);
59 continue;
60 }
61
62 double s = samples[i];
63 s -= min;
64 s /= (max - min);
65 s *= (std::size(kBars) - 1);
66 const size_t bar = (size_t)(s + 0.5);
68 plot.append(kBars[bar]);
69 }
70 }
71
72 double min;
73 double max;
74 double mean; // Estimate of population mean.
75 double var; // Estimate of population variance.
76 double median;
77 SkString plot; // A single-line bar chart (_not_ histogram) of the samples.
78};
79
80#endif//Stats_DEFINED
#define SkASSERT_RELEASE(cond)
Definition: SkAssert.h:100
static constexpr double sk_ieee_double_divide(double numer, double denom)
static std::vector< SkPDFIndirectReference > sort(const THashSet< SkPDFIndirectReference > &src)
static const char * kBars[]
Definition: Stats.h:20
void append(const char text[])
Definition: SkString.h:203
int size() const
Definition: SkTArray.h:421
struct MyStruct s
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
double var
Definition: Stats.h:75
double max
Definition: Stats.h:73
double min
Definition: Stats.h:72
double mean
Definition: Stats.h:74
SkString plot
Definition: Stats.h:77
double median
Definition: Stats.h:76
Stats(const skia_private::TArray< double > &samples, bool want_plot)
Definition: Stats.h:24