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

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

Issue 390043002: Fix dartbug.com/19998 (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 5 months 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/native_api_impl.cc ('k') | runtime/vm/os_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 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 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/globals.h" 5 #include "vm/globals.h"
6 #if defined(TARGET_OS_ANDROID) 6 #if defined(TARGET_OS_ANDROID)
7 7
8 #include "vm/os.h" 8 #include "vm/os.h"
9 9
10 #include <android/log.h> // NOLINT 10 #include <android/log.h> // NOLINT
(...skipping 17 matching lines...) Expand all
28 28
29 29
30 namespace dart { 30 namespace dart {
31 31
32 // Android CodeObservers. 32 // Android CodeObservers.
33 33
34 DEFINE_FLAG(bool, generate_gdb_symbols, false, 34 DEFINE_FLAG(bool, generate_gdb_symbols, false,
35 "Generate symbols of generated dart functions for debugging with GDB"); 35 "Generate symbols of generated dart functions for debugging with GDB");
36 DEFINE_FLAG(bool, generate_perf_events_symbols, false, 36 DEFINE_FLAG(bool, generate_perf_events_symbols, false,
37 "Generate events symbols for profiling with perf"); 37 "Generate events symbols for profiling with perf");
38 DEFINE_FLAG(charp, generate_pprof_symbols, NULL, 38
39 "Generate events symbols for profiling with pprof");
40 39
41 class PerfCodeObserver : public CodeObserver { 40 class PerfCodeObserver : public CodeObserver {
42 public: 41 public:
43 PerfCodeObserver() { 42 PerfCodeObserver() : out_file_(NULL) {
44 Dart_FileOpenCallback file_open = Isolate::file_open_callback(); 43 Dart_FileOpenCallback file_open = Isolate::file_open_callback();
45 if (file_open == NULL) { 44 if (file_open == NULL) {
46 return; 45 return;
47 } 46 }
48 const char* format = "/tmp/perf-%ld.map"; 47 const char* format = "/tmp/perf-%ld.map";
49 intptr_t pid = getpid(); 48 intptr_t pid = getpid();
50 intptr_t len = OS::SNPrint(NULL, 0, format, pid); 49 intptr_t len = OS::SNPrint(NULL, 0, format, pid);
51 char* filename = new char[len + 1]; 50 char* filename = new char[len + 1];
52 OS::SNPrint(filename, len + 1, format, pid); 51 OS::SNPrint(filename, len + 1, format, pid);
53 out_file_ = (*file_open)(filename, true); 52 out_file_ = (*file_open)(filename, true);
54 } 53 }
55 54
56 ~PerfCodeObserver() { 55 ~PerfCodeObserver() {
57 Dart_FileCloseCallback file_close = Isolate::file_close_callback(); 56 Dart_FileCloseCallback file_close = Isolate::file_close_callback();
58 if (file_close == NULL) { 57 if ((file_close == NULL) || (out_file_ == NULL)) {
59 return; 58 return;
60 } 59 }
61 ASSERT(out_file_ != NULL);
62 (*file_close)(out_file_); 60 (*file_close)(out_file_);
63 } 61 }
64 62
65 virtual bool IsActive() const { 63 virtual bool IsActive() const {
66 return FLAG_generate_perf_events_symbols; 64 return FLAG_generate_perf_events_symbols && (out_file_ != NULL);
67 } 65 }
68 66
69 virtual void Notify(const char* name, 67 virtual void Notify(const char* name,
70 uword base, 68 uword base,
71 uword prologue_offset, 69 uword prologue_offset,
72 uword size, 70 uword size,
73 bool optimized) { 71 bool optimized) {
74 Dart_FileWriteCallback file_write = Isolate::file_write_callback(); 72 Dart_FileWriteCallback file_write = Isolate::file_write_callback();
75 ASSERT(file_write != NULL); 73 if ((file_write == NULL) || (out_file_ == NULL)) {
74 return;
75 }
76 const char* format = "%" Px " %" Px " %s%s\n"; 76 const char* format = "%" Px " %" Px " %s%s\n";
77 const char* marker = optimized ? "*" : ""; 77 const char* marker = optimized ? "*" : "";
78 intptr_t len = OS::SNPrint(NULL, 0, format, base, size, marker, name); 78 intptr_t len = OS::SNPrint(NULL, 0, format, base, size, marker, name);
79 char* buffer = Isolate::Current()->current_zone()->Alloc<char>(len + 1); 79 char* buffer = Isolate::Current()->current_zone()->Alloc<char>(len + 1);
80 OS::SNPrint(buffer, len + 1, format, base, size, marker, name); 80 OS::SNPrint(buffer, len + 1, format, base, size, marker, name);
81 ASSERT(out_file_ != NULL);
82 (*file_write)(buffer, len, out_file_); 81 (*file_write)(buffer, len, out_file_);
83 } 82 }
84 83
85 private: 84 private:
86 void* out_file_; 85 void* out_file_;
87 86
88 DISALLOW_COPY_AND_ASSIGN(PerfCodeObserver); 87 DISALLOW_COPY_AND_ASSIGN(PerfCodeObserver);
89 }; 88 };
90 89
91 class PprofCodeObserver : public CodeObserver {
92 public:
93 PprofCodeObserver() {
94 pprof_symbol_generator_ = DebugInfo::NewGenerator();
95 }
96
97 ~PprofCodeObserver() {
98 Dart_FileOpenCallback file_open = Isolate::file_open_callback();
99 if (file_open == NULL) {
100 return;
101 }
102 Dart_FileCloseCallback file_close = Isolate::file_close_callback();
103 if (file_close == NULL) {
104 return;
105 }
106 Dart_FileWriteCallback file_write = Isolate::file_write_callback();
107 if (file_write == NULL) {
108 return;
109 }
110 if (FLAG_generate_pprof_symbols == NULL) {
111 return;
112 }
113 const char* filename = FLAG_generate_pprof_symbols;
114 void* out_file = (*file_open)(filename, true);
115 ASSERT(out_file != NULL);
116 DebugInfo::ByteBuffer* debug_region = new DebugInfo::ByteBuffer();
117 ASSERT(debug_region != NULL);
118 pprof_symbol_generator_->WriteToMemory(debug_region);
119 int buffer_size = debug_region->size();
120 void* buffer = debug_region->data();
121 delete debug_region;
122 if (buffer_size > 0) {
123 ASSERT(buffer != NULL);
124 (*file_write)(buffer, buffer_size, out_file);
125 }
126 (*file_close)(out_file);
127 DebugInfo::UnregisterAllSections();
128 }
129
130 virtual bool IsActive() const {
131 return FLAG_generate_pprof_symbols != NULL;
132 }
133
134 virtual void Notify(const char* name,
135 uword base,
136 uword prologue_offset,
137 uword size,
138 bool optimized) {
139 ASSERT(pprof_symbol_generator_ != NULL);
140 pprof_symbol_generator_->AddCode(base, size);
141 pprof_symbol_generator_->AddCodeRegion(name, base, size);
142 }
143
144 private:
145 DebugInfo* pprof_symbol_generator_;
146
147 DISALLOW_COPY_AND_ASSIGN(PprofCodeObserver);
148 };
149 90
150 class GdbCodeObserver : public CodeObserver { 91 class GdbCodeObserver : public CodeObserver {
151 public: 92 public:
152 GdbCodeObserver() { } 93 GdbCodeObserver() { }
153 94
154 virtual bool IsActive() const { 95 virtual bool IsActive() const {
155 return FLAG_generate_gdb_symbols; 96 return FLAG_generate_gdb_symbols;
156 } 97 }
157 98
158 virtual void Notify(const char* name, 99 virtual void Notify(const char* name,
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 } 384 }
444 385
445 386
446 void OS::RegisterCodeObservers() { 387 void OS::RegisterCodeObservers() {
447 if (FLAG_generate_perf_events_symbols) { 388 if (FLAG_generate_perf_events_symbols) {
448 CodeObservers::Register(new PerfCodeObserver); 389 CodeObservers::Register(new PerfCodeObserver);
449 } 390 }
450 if (FLAG_generate_gdb_symbols) { 391 if (FLAG_generate_gdb_symbols) {
451 CodeObservers::Register(new GdbCodeObserver); 392 CodeObservers::Register(new GdbCodeObserver);
452 } 393 }
453 if (FLAG_generate_pprof_symbols != NULL) {
454 CodeObservers::Register(new PprofCodeObserver);
455 }
456 #if defined(DART_VTUNE_SUPPORT) 394 #if defined(DART_VTUNE_SUPPORT)
457 CodeObservers::Register(new VTuneCodeObserver); 395 CodeObservers::Register(new VTuneCodeObserver);
458 #endif 396 #endif
459 } 397 }
460 398
461 399
462 void OS::PrintErr(const char* format, ...) { 400 void OS::PrintErr(const char* format, ...) {
463 va_list args; 401 va_list args;
464 va_start(args, format); 402 va_start(args, format);
465 VFPrint(stderr, format, args); 403 VFPrint(stderr, format, args);
(...skipping 22 matching lines...) Expand all
488 } 426 }
489 427
490 428
491 void OS::Exit(int code) { 429 void OS::Exit(int code) {
492 exit(code); 430 exit(code);
493 } 431 }
494 432
495 } // namespace dart 433 } // namespace dart
496 434
497 #endif // defined(TARGET_OS_ANDROID) 435 #endif // defined(TARGET_OS_ANDROID)
OLDNEW
« no previous file with comments | « runtime/vm/native_api_impl.cc ('k') | runtime/vm/os_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698