OLD | NEW |
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 |
11 #include <endian.h> // NOLINT | 11 #include <endian.h> // NOLINT |
12 #include <errno.h> // NOLINT | 12 #include <errno.h> // NOLINT |
13 #include <limits.h> // NOLINT | 13 #include <limits.h> // NOLINT |
14 #include <malloc.h> // NOLINT | 14 #include <malloc.h> // NOLINT |
15 #include <time.h> // NOLINT | 15 #include <time.h> // NOLINT |
16 #include <sys/resource.h> // NOLINT | 16 #include <sys/resource.h> // NOLINT |
17 #include <sys/time.h> // NOLINT | 17 #include <sys/time.h> // NOLINT |
18 #include <sys/types.h> // NOLINT | 18 #include <sys/types.h> // NOLINT |
19 #include <unistd.h> // NOLINT | 19 #include <unistd.h> // NOLINT |
20 | 20 |
21 #include "platform/utils.h" | 21 #include "platform/utils.h" |
22 #include "vm/code_observers.h" | 22 #include "vm/code_observers.h" |
23 #include "vm/dart.h" | 23 #include "vm/dart.h" |
24 #include "vm/debuginfo.h" | |
25 #include "vm/isolate.h" | 24 #include "vm/isolate.h" |
26 #include "vm/vtune.h" | |
27 #include "vm/zone.h" | 25 #include "vm/zone.h" |
28 | 26 |
29 | 27 |
30 namespace dart { | 28 namespace dart { |
31 | 29 |
32 // Android CodeObservers. | 30 // Android CodeObservers. |
33 | 31 |
34 DEFINE_FLAG(bool, generate_gdb_symbols, false, | 32 #ifndef PRODUCT |
35 "Generate symbols of generated dart functions for debugging with GDB"); | 33 |
36 DEFINE_FLAG(bool, generate_perf_events_symbols, false, | 34 DEFINE_FLAG(bool, generate_perf_events_symbols, false, |
37 "Generate events symbols for profiling with perf"); | 35 "Generate events symbols for profiling with perf"); |
38 | 36 |
39 | |
40 class PerfCodeObserver : public CodeObserver { | 37 class PerfCodeObserver : public CodeObserver { |
41 public: | 38 public: |
42 PerfCodeObserver() : out_file_(NULL) { | 39 PerfCodeObserver() : out_file_(NULL) { |
43 Dart_FileOpenCallback file_open = Isolate::file_open_callback(); | 40 Dart_FileOpenCallback file_open = Isolate::file_open_callback(); |
44 if (file_open == NULL) { | 41 if (file_open == NULL) { |
45 return; | 42 return; |
46 } | 43 } |
47 intptr_t pid = getpid(); | 44 intptr_t pid = getpid(); |
48 char* filename = OS::SCreate(NULL, "/tmp/perf-%" Pd ".map", pid); | 45 char* filename = OS::SCreate(NULL, "/tmp/perf-%" Pd ".map", pid); |
49 out_file_ = (*file_open)(filename, true); | 46 out_file_ = (*file_open)(filename, true); |
(...skipping 26 matching lines...) Expand all Loading... |
76 "%" Px " %" Px " %s%s\n", base, size, marker, name); | 73 "%" Px " %" Px " %s%s\n", base, size, marker, name); |
77 (*file_write)(buffer, strlen(buffer), out_file_); | 74 (*file_write)(buffer, strlen(buffer), out_file_); |
78 } | 75 } |
79 | 76 |
80 private: | 77 private: |
81 void* out_file_; | 78 void* out_file_; |
82 | 79 |
83 DISALLOW_COPY_AND_ASSIGN(PerfCodeObserver); | 80 DISALLOW_COPY_AND_ASSIGN(PerfCodeObserver); |
84 }; | 81 }; |
85 | 82 |
86 | 83 #endif // !PRODUCT |
87 class GdbCodeObserver : public CodeObserver { | |
88 public: | |
89 GdbCodeObserver() { } | |
90 | |
91 virtual bool IsActive() const { | |
92 return FLAG_generate_gdb_symbols; | |
93 } | |
94 | |
95 virtual void Notify(const char* name, | |
96 uword base, | |
97 uword prologue_offset, | |
98 uword size, | |
99 bool optimized) { | |
100 if (prologue_offset > 0) { | |
101 // In order to ensure that gdb sees the first instruction of a function | |
102 // as the prologue sequence we register two symbols for the cases when | |
103 // the prologue sequence is not the first instruction: | |
104 // <name>_entry is used for code preceding the prologue sequence. | |
105 // <name> for rest of the code (first instruction is prologue sequence). | |
106 char* pname = OS::SCreate(Thread::Current()->zone(), | |
107 "%s_%s", name, "entry"); | |
108 DebugInfo::RegisterSection(pname, base, size); | |
109 DebugInfo::RegisterSection(name, | |
110 (base + prologue_offset), | |
111 (size - prologue_offset)); | |
112 } else { | |
113 DebugInfo::RegisterSection(name, base, size); | |
114 } | |
115 } | |
116 | |
117 private: | |
118 DISALLOW_COPY_AND_ASSIGN(GdbCodeObserver); | |
119 }; | |
120 | |
121 | 84 |
122 const char* OS::Name() { | 85 const char* OS::Name() { |
123 return "android"; | 86 return "android"; |
124 } | 87 } |
125 | 88 |
126 | 89 |
127 intptr_t OS::ProcessId() { | 90 intptr_t OS::ProcessId() { |
128 return static_cast<intptr_t>(getpid()); | 91 return static_cast<intptr_t>(getpid()); |
129 } | 92 } |
130 | 93 |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 (str[i + 2] != '\0')) { | 383 (str[i + 2] != '\0')) { |
421 base = 16; | 384 base = 16; |
422 } | 385 } |
423 errno = 0; | 386 errno = 0; |
424 *value = strtoll(str, &endptr, base); | 387 *value = strtoll(str, &endptr, base); |
425 return ((errno == 0) && (endptr != str) && (*endptr == 0)); | 388 return ((errno == 0) && (endptr != str) && (*endptr == 0)); |
426 } | 389 } |
427 | 390 |
428 | 391 |
429 void OS::RegisterCodeObservers() { | 392 void OS::RegisterCodeObservers() { |
| 393 #ifndef PRODUCT |
430 if (FLAG_generate_perf_events_symbols) { | 394 if (FLAG_generate_perf_events_symbols) { |
431 CodeObservers::Register(new PerfCodeObserver); | 395 CodeObservers::Register(new PerfCodeObserver); |
432 } | 396 } |
433 if (FLAG_generate_gdb_symbols) { | 397 #endif // !PRODUCT |
434 CodeObservers::Register(new GdbCodeObserver); | |
435 } | |
436 #if defined(DART_VTUNE_SUPPORT) | |
437 CodeObservers::Register(new VTuneCodeObserver); | |
438 #endif | |
439 } | 398 } |
440 | 399 |
441 | 400 |
442 void OS::PrintErr(const char* format, ...) { | 401 void OS::PrintErr(const char* format, ...) { |
443 va_list args; | 402 va_list args; |
444 va_start(args, format); | 403 va_start(args, format); |
445 VFPrint(stderr, format, args); | 404 VFPrint(stderr, format, args); |
446 // Forward to the Android log for remote access. | 405 // Forward to the Android log for remote access. |
447 __android_log_vprint(ANDROID_LOG_ERROR, "DartVM", format, args); | 406 __android_log_vprint(ANDROID_LOG_ERROR, "DartVM", format, args); |
448 va_end(args); | 407 va_end(args); |
(...skipping 19 matching lines...) Expand all Loading... |
468 } | 427 } |
469 | 428 |
470 | 429 |
471 void OS::Exit(int code) { | 430 void OS::Exit(int code) { |
472 exit(code); | 431 exit(code); |
473 } | 432 } |
474 | 433 |
475 } // namespace dart | 434 } // namespace dart |
476 | 435 |
477 #endif // defined(TARGET_OS_ANDROID) | 436 #endif // defined(TARGET_OS_ANDROID) |
OLD | NEW |