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

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

Issue 11412106: Support VTune's JIT interface. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments Created 8 years 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/code_observers.h ('k') | runtime/vm/dart.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) 2012, 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 "vm/code_observers.h"
6
7 #include "vm/dart.h"
8 #include "vm/debuginfo.h"
9 #include "vm/flags.h"
10 #include "vm/isolate.h"
11 #include "vm/os.h"
12 #include "vm/vtune.h"
13 #include "vm/zone.h"
14
15 namespace dart {
16
17 DEFINE_FLAG(bool, generate_gdb_symbols, false,
18 "Generate symbols of generated dart functions for debugging with GDB");
19
20 intptr_t CodeObservers::observers_length_ = 0;
21 CodeObserver** CodeObservers::observers_ = NULL;
22
23
24 void CodeObservers::Register(CodeObserver* observer) {
25 observers_length_++;
26 observers_ = reinterpret_cast<CodeObserver**>(
27 realloc(observers_, sizeof(observer) * observers_length_));
28 if (observers_ == NULL) {
29 FATAL("failed to grow code observers array");
30 }
31 observers_[observers_length_ - 1] = observer;
32 }
33
34
35 void CodeObservers::NotifyAll(const char* name,
36 uword base,
37 uword prologue_offset,
38 uword size,
39 bool optimized) {
40 ASSERT(!AreActive() || (strlen(name) != 0));
41 for (intptr_t i = 0; i < observers_length_; i++) {
42 if (observers_[i]->IsActive()) {
43 observers_[i]->Notify(name, base, prologue_offset, size, optimized);
44 }
45 }
46 }
47
48
49 bool CodeObservers::AreActive() {
50 for (intptr_t i = 0; i < observers_length_; i++) {
51 if (observers_[i]->IsActive()) return true;
52 }
53 return false;
54 }
55
56
57 class PerfCodeObserver : public CodeObserver {
58 public:
59 virtual bool IsActive() const {
60 return Dart::perf_events_writer() != NULL;
61 }
62
63 virtual void Notify(const char* name,
64 uword base,
65 uword prologue_offset,
66 uword size,
67 bool optimized) {
68 Dart_FileWriterFunction perf_events_writer = Dart::perf_events_writer();
69 ASSERT(perf_events_writer != NULL);
70
71 const char* format = "%"Px" %"Px" %s%s\n";
72 const char* marker = optimized ? "*" : "";
73 intptr_t len = OS::SNPrint(NULL, 0, format, base, size, marker, name);
74 char* buffer = Isolate::Current()->current_zone()->Alloc<char>(len + 1);
75 OS::SNPrint(buffer, len + 1, format, base, size, marker, name);
76 (*perf_events_writer)(buffer, len);
77 }
78 };
79
80
81 class PprofCodeObserver : public CodeObserver {
82 public:
83 virtual bool IsActive() const {
84 return Dart::pprof_symbol_generator() != NULL;
85 }
86
87 virtual void Notify(const char* name,
88 uword base,
89 uword prologue_offset,
90 uword size,
91 bool optimized) {
92 DebugInfo* pprof_symbol_generator = Dart::pprof_symbol_generator();
93 ASSERT(pprof_symbol_generator != NULL);
94 pprof_symbol_generator->AddCode(base, size);
95 pprof_symbol_generator->AddCodeRegion(name, base, size);
96 }
97 };
98
99
100 class GdbCodeObserver : public CodeObserver {
101 public:
102 virtual bool IsActive() const {
103 return FLAG_generate_gdb_symbols;
104 }
105
106 virtual void Notify(const char* name,
107 uword base,
108 uword prologue_offset,
109 uword size,
110 bool optimized) {
111 if (prologue_offset > 0) {
112 // In order to ensure that gdb sees the first instruction of a function
113 // as the prologue sequence we register two symbols for the cases when
114 // the prologue sequence is not the first instruction:
115 // <name>_entry is used for code preceding the prologue sequence.
116 // <name> for rest of the code (first instruction is prologue sequence).
117 const char* kFormat = "%s_%s";
118 intptr_t len = OS::SNPrint(NULL, 0, kFormat, name, "entry");
119 char* pname = Isolate::Current()->current_zone()->Alloc<char>(len + 1);
120 OS::SNPrint(pname, (len + 1), kFormat, name, "entry");
121 DebugInfo::RegisterSection(pname, base, size);
122 DebugInfo::RegisterSection(name,
123 (base + prologue_offset),
124 (size - prologue_offset));
125 } else {
126 DebugInfo::RegisterSection(name, base, size);
127 }
128 }
129 };
130
131
132 void CodeObservers::InitOnce() {
133 Register(new PerfCodeObserver);
134 Register(new PprofCodeObserver);
135 Register(new GdbCodeObserver);
136 #if defined(DART_VTUNE_SUPPORT)
137 Register(new VTuneCodeObserver);
138 #endif
139 }
140
141
142 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/code_observers.h ('k') | runtime/vm/dart.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698