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 "vm/tags.h" | 5 #include "vm/tags.h" |
6 | 6 |
7 #include "vm/isolate.h" | 7 #include "vm/isolate.h" |
8 #include "vm/json_stream.h" | |
8 | 9 |
9 namespace dart { | 10 namespace dart { |
10 | 11 |
11 const char* VMTag::TagName(uword id) { | 12 const char* VMTag::TagName(uword tag) { |
12 ASSERT(id != kInvalidTagId); | 13 ASSERT(tag != kInvalidTagId); |
13 ASSERT(id < kNumVMTags); | 14 ASSERT(tag < kNumVMTags); |
14 const TagEntry& entry = entries_[id]; | 15 const TagEntry& entry = entries_[tag]; |
15 ASSERT(entry.id == id); | 16 ASSERT(entry.id == tag); |
16 return entry.name; | 17 return entry.name; |
17 } | 18 } |
18 | 19 |
19 | 20 |
20 VMTag::TagEntry VMTag::entries_[] = { | 21 VMTag::TagEntry VMTag::entries_[] = { |
21 { "InvalidTag", kInvalidTagId, }, | 22 { "InvalidTag", kInvalidTagId, }, |
22 #define DEFINE_VM_TAG_ENTRY(tag) \ | 23 #define DEFINE_VM_TAG_ENTRY(tag) \ |
23 { ""#tag, k##tag##TagId }, | 24 { ""#tag, k##tag##TagId }, |
24 VM_TAG_LIST(DEFINE_VM_TAG_ENTRY) | 25 VM_TAG_LIST(DEFINE_VM_TAG_ENTRY) |
25 #undef DEFINE_VM_TAG_ENTRY | 26 #undef DEFINE_VM_TAG_ENTRY |
26 { "kNumVMTags", kNumVMTags }, | 27 { "kNumVMTags", kNumVMTags }, |
27 }; | 28 }; |
28 | 29 |
29 | 30 |
30 VMTagScope::VMTagScope(Isolate* base_isolate, uword tag) | 31 VMTagScope::VMTagScope(Isolate* base_isolate, uword tag) |
31 : StackResource(base_isolate) { | 32 : StackResource(base_isolate) { |
32 ASSERT(isolate() != NULL); | 33 ASSERT(isolate() != NULL); |
33 previous_tag_ = isolate()->vm_tag(); | 34 previous_tag_ = isolate()->vm_tag(); |
34 isolate()->set_vm_tag(tag); | 35 isolate()->set_vm_tag(tag); |
35 } | 36 } |
36 | 37 |
37 | 38 |
38 VMTagScope::~VMTagScope() { | 39 VMTagScope::~VMTagScope() { |
39 ASSERT(isolate() != NULL); | 40 ASSERT(isolate() != NULL); |
40 isolate()->set_vm_tag(previous_tag_); | 41 isolate()->set_vm_tag(previous_tag_); |
41 } | 42 } |
42 | 43 |
43 | 44 |
45 VMTagCounters::VMTagCounters() { | |
46 for (intptr_t i = 0; i < VMTag::kNumVMTags; i++) { | |
47 counters_[i] = 0; | |
48 } | |
49 } | |
50 | |
51 | |
52 void VMTagCounters::Increment(uword tag) { | |
53 ASSERT(tag != VMTag::kInvalidTagId); | |
54 ASSERT(tag < VMTag::kNumVMTags); | |
55 counters_[tag]++; | |
56 } | |
57 | |
58 | |
59 int64_t VMTagCounters::count(uword tag) { | |
60 ASSERT(tag != VMTag::kInvalidTagId); | |
61 ASSERT(tag < VMTag::kNumVMTags); | |
62 return counters_[tag]; | |
63 } | |
64 | |
65 | |
66 void VMTagCounters::PrintToJSONObject(JSONObject* obj) { | |
67 { | |
68 JSONArray arr(obj, "names"); | |
69 for (intptr_t i = 1; i < VMTag::kNumVMTags; i++) { | |
70 arr.AddValue(VMTag::TagName(i)); | |
71 } | |
72 } | |
73 { | |
74 JSONArray arr(obj, "counters"); | |
75 for (intptr_t i = 1; i < VMTag::kNumVMTags; i++) { | |
76 arr.AddValue64(counters_[i]); | |
77 } | |
78 } | |
turnidge
2014/03/24 20:22:13
So you split the message into two parallel arrays?
Cutch
2014/03/25 14:39:06
I would prefer to keep them as separate arrays. Ma
| |
79 } | |
80 | |
44 } // namespace dart | 81 } // namespace dart |
OLD | NEW |