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

Side by Side Diff: runtime/vm/metrics_test.cc

Issue 464953002: Add VMMetric and some sample metrics (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/metrics.cc ('k') | runtime/vm/service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
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.
4
5 #include "platform/assert.h"
6
7 #include "vm/dart_api_impl.h"
8 #include "vm/dart_api_state.h"
9 #include "vm/globals.h"
10 #include "vm/json_stream.h"
11 #include "vm/metrics.h"
12 #include "vm/unit_test.h"
13
14 namespace dart {
15
16 UNIT_TEST_CASE(Metric_Simple) {
17 Isolate* isolate = Isolate::Init(NULL);
18 EXPECT_EQ(isolate, Isolate::Current());
19 Metric metric;
20
21 // Initialize metric.
22 metric.Init(Isolate::Current(), "a.b.c", "foobar", Metric::kCounter);
23 EXPECT_EQ(0, metric.value());
24 metric.increment();
25 EXPECT_EQ(1, metric.value());
26 metric.set_value(44);
27 EXPECT_EQ(44, metric.value());
28 }
29
30 class MyMetric : public Metric {
31 protected:
32 int64_t Value() const {
33 // 99 bytes.
34 return 99;
35 }
36
37 public:
38 // Just used for testing.
39 int64_t LeakyValue() const { return Value(); }
40 };
41
42 UNIT_TEST_CASE(Metric_OnDemand) {
43 Isolate* isolate = Isolate::Init(NULL);
44 EXPECT_EQ(isolate, Isolate::Current());
45 MyMetric metric;
46
47 metric.Init(Isolate::Current(), "a.b.c", "foobar", Metric::kByte);
48 // value is still the default value.
49 EXPECT_EQ(0, metric.value());
50 // Call LeakyValue to confirm that Value returns constant 99.
51 EXPECT_EQ(99, metric.LeakyValue());
52
53 // Serialize to JSON.
54 JSONStream js;
55 metric.PrintJSON(&js);
56 const char* json = js.ToCString();
57 EXPECT_STREQ("{\"type\":\"Counter\",\"name\":\"a.b.c\",\"description\":"
58 "\"foobar\",\"unit\":\"byte\",\"id\":\"metrics\\/vm\\/a.b.c\""
59 ",\"value\":99.000000}", json);
60 }
61
62 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/metrics.cc ('k') | runtime/vm/service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698