OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 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 #include "platform/assert.h" | 5 #include "platform/assert.h" |
6 | 6 |
7 #include "vm/dart_api_impl.h" | 7 #include "vm/dart_api_impl.h" |
8 #include "vm/dart_api_state.h" | 8 #include "vm/dart_api_state.h" |
9 #include "vm/globals.h" | 9 #include "vm/globals.h" |
10 #include "vm/json_stream.h" | 10 #include "vm/json_stream.h" |
11 #include "vm/metrics.h" | 11 #include "vm/metrics.h" |
12 #include "vm/unit_test.h" | 12 #include "vm/unit_test.h" |
13 | 13 |
14 namespace dart { | 14 namespace dart { |
15 | 15 |
16 UNIT_TEST_CASE(Metric_Simple) { | 16 UNIT_TEST_CASE(Metric_Simple) { |
17 Isolate* isolate = Isolate::Init(NULL); | 17 Isolate::Flags vm_flags; |
| 18 Dart_IsolateFlags api_flags; |
| 19 vm_flags.CopyTo(&api_flags); |
| 20 Isolate* isolate = Isolate::Init(NULL, api_flags); |
18 EXPECT_EQ(isolate, Isolate::Current()); | 21 EXPECT_EQ(isolate, Isolate::Current()); |
19 Metric metric; | 22 Metric metric; |
20 | 23 |
21 // Initialize metric. | 24 // Initialize metric. |
22 metric.Init(Isolate::Current(), "a.b.c", "foobar", Metric::kCounter); | 25 metric.Init(Isolate::Current(), "a.b.c", "foobar", Metric::kCounter); |
23 EXPECT_EQ(0, metric.value()); | 26 EXPECT_EQ(0, metric.value()); |
24 metric.increment(); | 27 metric.increment(); |
25 EXPECT_EQ(1, metric.value()); | 28 EXPECT_EQ(1, metric.value()); |
26 metric.set_value(44); | 29 metric.set_value(44); |
27 EXPECT_EQ(44, metric.value()); | 30 EXPECT_EQ(44, metric.value()); |
28 } | 31 } |
29 | 32 |
30 class MyMetric : public Metric { | 33 class MyMetric : public Metric { |
31 protected: | 34 protected: |
32 int64_t Value() const { | 35 int64_t Value() const { |
33 // 99 bytes. | 36 // 99 bytes. |
34 return 99; | 37 return 99; |
35 } | 38 } |
36 | 39 |
37 public: | 40 public: |
38 // Just used for testing. | 41 // Just used for testing. |
39 int64_t LeakyValue() const { return Value(); } | 42 int64_t LeakyValue() const { return Value(); } |
40 }; | 43 }; |
41 | 44 |
42 UNIT_TEST_CASE(Metric_OnDemand) { | 45 UNIT_TEST_CASE(Metric_OnDemand) { |
43 Isolate* isolate = Isolate::Init(NULL); | 46 Isolate::Flags vm_flags; |
| 47 Dart_IsolateFlags api_flags; |
| 48 vm_flags.CopyTo(&api_flags); |
| 49 Isolate* isolate = Isolate::Init(NULL, api_flags); |
44 EXPECT_EQ(isolate, Isolate::Current()); | 50 EXPECT_EQ(isolate, Isolate::Current()); |
45 MyMetric metric; | 51 MyMetric metric; |
46 | 52 |
47 metric.Init(Isolate::Current(), "a.b.c", "foobar", Metric::kByte); | 53 metric.Init(Isolate::Current(), "a.b.c", "foobar", Metric::kByte); |
48 // value is still the default value. | 54 // value is still the default value. |
49 EXPECT_EQ(0, metric.value()); | 55 EXPECT_EQ(0, metric.value()); |
50 // Call LeakyValue to confirm that Value returns constant 99. | 56 // Call LeakyValue to confirm that Value returns constant 99. |
51 EXPECT_EQ(99, metric.LeakyValue()); | 57 EXPECT_EQ(99, metric.LeakyValue()); |
52 | 58 |
53 // Serialize to JSON. | 59 // Serialize to JSON. |
54 JSONStream js; | 60 JSONStream js; |
55 metric.PrintJSON(&js); | 61 metric.PrintJSON(&js); |
56 const char* json = js.ToCString(); | 62 const char* json = js.ToCString(); |
57 EXPECT_STREQ("{\"type\":\"Counter\",\"name\":\"a.b.c\",\"description\":" | 63 EXPECT_STREQ("{\"type\":\"Counter\",\"name\":\"a.b.c\",\"description\":" |
58 "\"foobar\",\"unit\":\"byte\"," | 64 "\"foobar\",\"unit\":\"byte\"," |
59 "\"fixedId\":true,\"id\":\"metrics\\/native\\/a.b.c\"" | 65 "\"fixedId\":true,\"id\":\"metrics\\/native\\/a.b.c\"" |
60 ",\"value\":99.000000}", json); | 66 ",\"value\":99.000000}", json); |
61 } | 67 } |
62 | 68 |
63 } // namespace dart | 69 } // namespace dart |
OLD | NEW |