OLD | NEW |
---|---|
(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 VMMetric metric; | |
20 | |
21 // Initialize metric. | |
22 metric.Init(Isolate::Current(), "a.b.c", "foobar", VMMetric::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 VMMetric { | |
31 protected: | |
32 int64_t Value() const { | |
33 // 99 bytes. | |
koda
2014/08/13 22:43:00
It would be nicer if the unit (and also name and d
Cutch
2014/08/14 20:56:19
Yes. Although overriding is probably more verbose
| |
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", VMMetric::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 | |
OLD | NEW |