Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(512)

Side by Side Diff: runtime/observatory/lib/src/repositories/metric.dart

Issue 2345023003: Use dartfmt on Observatory code (Closed)
Patch Set: merge Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file 3 // BSD-style license that can be found in the LICENSE file
4 4
5 part of repositories; 5 part of repositories;
6 6
7 class Metric implements M.Metric { 7 class Metric implements M.Metric {
8 final String id; 8 final String id;
9 String get name => internal.name; 9 String get name => internal.name;
10 String get description => internal.description; 10 String get description => internal.description;
11 final internal; 11 final internal;
12 12
13 Metric(this.id, this.internal); 13 Metric(this.id, this.internal);
14 } 14 }
15 15
16 class MetricSample implements M.MetricSample { 16 class MetricSample implements M.MetricSample {
17 final double value; 17 final double value;
18 final DateTime time = new DateTime.now(); 18 final DateTime time = new DateTime.now();
19 MetricSample(this.value); 19 MetricSample(this.value);
20 } 20 }
21 21
22 class MetricRepository implements M.MetricRepository { 22 class MetricRepository implements M.MetricRepository {
23 final Map<S.Isolate, Map<Metric, List<M.MetricSample>>> _samples 23 final Map<S.Isolate, Map<Metric, List<M.MetricSample>>> _samples =
24 = <S.Isolate, Map<Metric, List<M.MetricSample>>>{}; 24 <S.Isolate, Map<Metric, List<M.MetricSample>>>{};
25 final Map<S.Isolate, Map<Metric, int>> _rates 25 final Map<S.Isolate, Map<Metric, int>> _rates =
26 = <S.Isolate, Map<Metric, int>>{}; 26 <S.Isolate, Map<Metric, int>>{};
27 final Map<S.Isolate, Map<Metric, int>> _sizes 27 final Map<S.Isolate, Map<Metric, int>> _sizes =
28 = <S.Isolate, Map<Metric, int>>{}; 28 <S.Isolate, Map<Metric, int>>{};
29 Timer _timer; 29 Timer _timer;
30 int count = 0; 30 int count = 0;
31 31
32 Future<Iterable<Metric>> list(M.IsolateRef i) async{ 32 Future<Iterable<Metric>> list(M.IsolateRef i) async {
33 S.Isolate isolate = i as S.Isolate; 33 S.Isolate isolate = i as S.Isolate;
34 assert(isolate != null); 34 assert(isolate != null);
35 if (_samples.containsKey(isolate)) { 35 if (_samples.containsKey(isolate)) {
36 return _samples[isolate].keys; 36 return _samples[isolate].keys;
37 } 37 }
38 return const []; 38 return const [];
39 } 39 }
40 40
41 Future startSampling(M.IsolateRef i) async { 41 Future startSampling(M.IsolateRef i) async {
42 S.Isolate isolate = i as S.Isolate; 42 S.Isolate isolate = i as S.Isolate;
43 assert(isolate != null); 43 assert(isolate != null);
44 if (!_samples.containsKey(isolate)) { 44 if (!_samples.containsKey(isolate)) {
45 await isolate.refreshMetrics(); 45 await isolate.refreshMetrics();
46 final samples = _samples[isolate] = <Metric, List<M.MetricSample>>{}; 46 final samples = _samples[isolate] = <Metric, List<M.MetricSample>>{};
47 final rates = _rates[isolate] = <Metric, int>{}; 47 final rates = _rates[isolate] = <Metric, int>{};
48 final sizes = _sizes[isolate] = <Metric, int>{}; 48 final sizes = _sizes[isolate] = <Metric, int>{};
49 final metrics = [] 49 final metrics = []
50 ..addAll(isolate.dartMetrics.keys.map((name) => 50 ..addAll(isolate.dartMetrics.keys
51 new Metric(name, isolate.dartMetrics[name])).toList()) 51 .map((name) => new Metric(name, isolate.dartMetrics[name]))
52 ..addAll(isolate.nativeMetrics.keys.map((name) => 52 .toList())
53 new Metric(name, isolate.nativeMetrics[name])).toList()); 53 ..addAll(isolate.nativeMetrics.keys
54 .map((name) => new Metric(name, isolate.nativeMetrics[name]))
55 .toList());
54 for (final metric in metrics) { 56 for (final metric in metrics) {
55 samples[metric] = [new MetricSample(metric.internal.value)]; 57 samples[metric] = [new MetricSample(metric.internal.value)];
56 rates[metric] = _rateToInteger(M.MetricSamplingRate.off); 58 rates[metric] = _rateToInteger(M.MetricSamplingRate.off);
57 sizes[metric] = _sizeToInteger(M.MetricBufferSize.n100samples); 59 sizes[metric] = _sizeToInteger(M.MetricBufferSize.n100samples);
58 } 60 }
59 if (_samples.length == 1) { 61 if (_samples.length == 1) {
60 count = 0; 62 count = 0;
61 _timer = new Timer.periodic(new Duration(milliseconds: 100), _update); 63 _timer = new Timer.periodic(new Duration(milliseconds: 100), _update);
62 } 64 }
63 } 65 }
64 } 66 }
65 67
66 Future stopSampling(M.IsolateRef isolate) async { 68 Future stopSampling(M.IsolateRef isolate) async {
67 if (_samples.containsKey(isolate)) { 69 if (_samples.containsKey(isolate)) {
68 _samples.remove(isolate); 70 _samples.remove(isolate);
69 _rates.remove(isolate); 71 _rates.remove(isolate);
70 _sizes.remove(isolate); 72 _sizes.remove(isolate);
71 if (_samples.isEmpty) { 73 if (_samples.isEmpty) {
72 _timer.cancel(); 74 _timer.cancel();
73 } 75 }
74 } 76 }
75 } 77 }
76 78
77 M.MetricSamplingRate getSamplingRate(M.IsolateRef i, M.Metric m) { 79 M.MetricSamplingRate getSamplingRate(M.IsolateRef i, M.Metric m) {
78 if (_rates.containsKey(i)) { 80 if (_rates.containsKey(i)) {
79 final metrics = _rates[i]; 81 final metrics = _rates[i];
80 if (metrics.containsKey(m)) { 82 if (metrics.containsKey(m)) {
81 switch (metrics[m]) { 83 switch (metrics[m]) {
82 case 0: return M.MetricSamplingRate.off; 84 case 0:
83 case 1: return M.MetricSamplingRate.e100ms; 85 return M.MetricSamplingRate.off;
84 case 10: return M.MetricSamplingRate.e1s; 86 case 1:
85 case 20: return M.MetricSamplingRate.e2s; 87 return M.MetricSamplingRate.e100ms;
86 case 40: return M.MetricSamplingRate.e4s; 88 case 10:
87 case 80: return M.MetricSamplingRate.e8s; 89 return M.MetricSamplingRate.e1s;
90 case 20:
91 return M.MetricSamplingRate.e2s;
92 case 40:
93 return M.MetricSamplingRate.e4s;
94 case 80:
95 return M.MetricSamplingRate.e8s;
88 } 96 }
89 } 97 }
90 } 98 }
91 throw new Exception('Sampling for isolate ${i.id} is not started'); 99 throw new Exception('Sampling for isolate ${i.id} is not started');
92 } 100 }
93 101
94 void setSamplingRate(M.IsolateRef i, M.Metric m, M.MetricSamplingRate r) { 102 void setSamplingRate(M.IsolateRef i, M.Metric m, M.MetricSamplingRate r) {
95 if (_rates.containsKey(i)) { 103 if (_rates.containsKey(i)) {
96 final metrics = _rates[i]; 104 final metrics = _rates[i];
97 if (metrics.containsKey(m)) { 105 if (metrics.containsKey(m)) {
98 metrics[m] = _rateToInteger(r); 106 metrics[m] = _rateToInteger(r);
99 } 107 }
100 } else { 108 } else {
101 throw new Exception('Sampling for isolate ${i.id} is not started'); 109 throw new Exception('Sampling for isolate ${i.id} is not started');
102 } 110 }
103 } 111 }
104 112
105 M.MetricBufferSize getBufferSize(M.IsolateRef i, M.Metric m) { 113 M.MetricBufferSize getBufferSize(M.IsolateRef i, M.Metric m) {
106 if (_sizes.containsKey(i)) { 114 if (_sizes.containsKey(i)) {
107 final metrics = _sizes[i]; 115 final metrics = _sizes[i];
108 if (metrics.containsKey(m)) { 116 if (metrics.containsKey(m)) {
109 switch (metrics[m]) { 117 switch (metrics[m]) {
110 case 10: return M.MetricBufferSize.n10samples; 118 case 10:
111 case 100: return M.MetricBufferSize.n100samples; 119 return M.MetricBufferSize.n10samples;
112 case 1000: return M.MetricBufferSize.n1000samples; 120 case 100:
121 return M.MetricBufferSize.n100samples;
122 case 1000:
123 return M.MetricBufferSize.n1000samples;
113 } 124 }
114 } 125 }
115 } 126 }
116 throw new Exception('Sampling for isolate ${i.id} is not started'); 127 throw new Exception('Sampling for isolate ${i.id} is not started');
117 } 128 }
118 129
119 void setBufferSize(M.IsolateRef i, M.Metric m, M.MetricBufferSize s) { 130 void setBufferSize(M.IsolateRef i, M.Metric m, M.MetricBufferSize s) {
120 if (_sizes.containsKey(i)) { 131 if (_sizes.containsKey(i)) {
121 final metrics = _sizes[i]; 132 final metrics = _sizes[i];
122 if (metrics.containsKey(m)) { 133 if (metrics.containsKey(m)) {
123 metrics[m] = _sizeToInteger(s); 134 metrics[m] = _sizeToInteger(s);
124 } 135 }
125 } else { 136 } else {
126 throw new Exception('Sampling for isolate ${i.id} is not started'); 137 throw new Exception('Sampling for isolate ${i.id} is not started');
127 } 138 }
128 } 139 }
129 140
130 static int _rateToInteger(M.MetricSamplingRate r) { 141 static int _rateToInteger(M.MetricSamplingRate r) {
131 switch (r) { 142 switch (r) {
132 case M.MetricSamplingRate.off: return 0; 143 case M.MetricSamplingRate.off:
133 case M.MetricSamplingRate.e100ms: return 1; 144 return 0;
134 case M.MetricSamplingRate.e1s: return 10; 145 case M.MetricSamplingRate.e100ms:
135 case M.MetricSamplingRate.e2s: return 20; 146 return 1;
136 case M.MetricSamplingRate.e4s: return 40; 147 case M.MetricSamplingRate.e1s:
137 case M.MetricSamplingRate.e8s: return 80; 148 return 10;
149 case M.MetricSamplingRate.e2s:
150 return 20;
151 case M.MetricSamplingRate.e4s:
152 return 40;
153 case M.MetricSamplingRate.e8s:
154 return 80;
138 } 155 }
139 throw new Exception('Unknown MetricSamplingRate ($r)'); 156 throw new Exception('Unknown MetricSamplingRate ($r)');
140 } 157 }
141 158
142 static int _sizeToInteger(M.MetricBufferSize s) { 159 static int _sizeToInteger(M.MetricBufferSize s) {
143 switch (s) { 160 switch (s) {
144 case M.MetricBufferSize.n10samples: return 10; 161 case M.MetricBufferSize.n10samples:
145 case M.MetricBufferSize.n100samples: return 100; 162 return 10;
146 case M.MetricBufferSize.n1000samples: return 1000; 163 case M.MetricBufferSize.n100samples:
164 return 100;
165 case M.MetricBufferSize.n1000samples:
166 return 1000;
147 } 167 }
148 throw new Exception('Unknown MetricBufferSize ($s)'); 168 throw new Exception('Unknown MetricBufferSize ($s)');
149 } 169 }
150 170
151 Iterable<M.MetricSample> getSamples(M.IsolateRef i, M.Metric m) { 171 Iterable<M.MetricSample> getSamples(M.IsolateRef i, M.Metric m) {
152 if (_samples.containsKey(i)) { 172 if (_samples.containsKey(i)) {
153 final metrics = _samples[i]; 173 final metrics = _samples[i];
154 if (metrics.containsKey(m)) { 174 if (metrics.containsKey(m)) {
155 return metrics[m]; 175 return metrics[m];
156 } 176 }
(...skipping 26 matching lines...) Expand all
183 samples.removeRange(0, samples.length - size + 1); 203 samples.removeRange(0, samples.length - size + 1);
184 } 204 }
185 samples.add(new MetricSample(m.value)); 205 samples.add(new MetricSample(m.value));
186 }); 206 });
187 } 207 }
188 } 208 }
189 } 209 }
190 ++count; 210 ++count;
191 } 211 }
192 } 212 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698