| 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" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 EXPECT_EQ(isolate, Isolate::Current()); | 21 EXPECT_EQ(isolate, Isolate::Current()); |
| 22 Metric metric; | 22 Metric metric; |
| 23 | 23 |
| 24 // Initialize metric. | 24 // Initialize metric. |
| 25 metric.Init(Isolate::Current(), "a.b.c", "foobar", Metric::kCounter); | 25 metric.Init(Isolate::Current(), "a.b.c", "foobar", Metric::kCounter); |
| 26 EXPECT_EQ(0, metric.value()); | 26 EXPECT_EQ(0, metric.value()); |
| 27 metric.increment(); | 27 metric.increment(); |
| 28 EXPECT_EQ(1, metric.value()); | 28 EXPECT_EQ(1, metric.value()); |
| 29 metric.set_value(44); | 29 metric.set_value(44); |
| 30 EXPECT_EQ(44, metric.value()); | 30 EXPECT_EQ(44, metric.value()); |
| 31 |
| 32 Dart::ShutdownIsolate(); |
| 31 } | 33 } |
| 32 | 34 |
| 33 class MyMetric : public Metric { | 35 class MyMetric : public Metric { |
| 34 protected: | 36 protected: |
| 35 int64_t Value() const { | 37 int64_t Value() const { |
| 36 // 99 bytes. | 38 // 99 bytes. |
| 37 return 99; | 39 return 99; |
| 38 } | 40 } |
| 39 | 41 |
| 40 public: | 42 public: |
| (...skipping 16 matching lines...) Expand all Loading... |
| 57 EXPECT_EQ(99, metric.LeakyValue()); | 59 EXPECT_EQ(99, metric.LeakyValue()); |
| 58 | 60 |
| 59 // Serialize to JSON. | 61 // Serialize to JSON. |
| 60 JSONStream js; | 62 JSONStream js; |
| 61 metric.PrintJSON(&js); | 63 metric.PrintJSON(&js); |
| 62 const char* json = js.ToCString(); | 64 const char* json = js.ToCString(); |
| 63 EXPECT_STREQ("{\"type\":\"Counter\",\"name\":\"a.b.c\",\"description\":" | 65 EXPECT_STREQ("{\"type\":\"Counter\",\"name\":\"a.b.c\",\"description\":" |
| 64 "\"foobar\",\"unit\":\"byte\"," | 66 "\"foobar\",\"unit\":\"byte\"," |
| 65 "\"fixedId\":true,\"id\":\"metrics\\/native\\/a.b.c\"" | 67 "\"fixedId\":true,\"id\":\"metrics\\/native\\/a.b.c\"" |
| 66 ",\"value\":99.000000}", json); | 68 ",\"value\":99.000000}", json); |
| 69 |
| 70 Dart::ShutdownIsolate(); |
| 67 } | 71 } |
| 68 | 72 |
| 69 } // namespace dart | 73 } // namespace dart |
| OLD | NEW |