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 |
(...skipping 26 matching lines...) Expand all Loading... | |
37 "Generate events symbols for profiling with perf"); | 37 "Generate events symbols for profiling with perf"); |
38 | 38 |
39 | 39 |
40 class PerfCodeObserver : public CodeObserver { | 40 class PerfCodeObserver : public CodeObserver { |
41 public: | 41 public: |
42 PerfCodeObserver() : out_file_(NULL) { | 42 PerfCodeObserver() : out_file_(NULL) { |
43 Dart_FileOpenCallback file_open = Isolate::file_open_callback(); | 43 Dart_FileOpenCallback file_open = Isolate::file_open_callback(); |
44 if (file_open == NULL) { | 44 if (file_open == NULL) { |
45 return; | 45 return; |
46 } | 46 } |
47 const char* format = "/tmp/perf-%ld.map"; | |
48 intptr_t pid = getpid(); | 47 intptr_t pid = getpid(); |
49 intptr_t len = OS::SNPrint(NULL, 0, format, pid); | 48 char* filename = OS::SNCreate(NULL, "/tmp/perf-%" Pd ".map", pid); |
50 char* filename = new char[len + 1]; | |
51 OS::SNPrint(filename, len + 1, format, pid); | |
52 out_file_ = (*file_open)(filename, true); | 49 out_file_ = (*file_open)(filename, true); |
50 free(filename); | |
53 } | 51 } |
54 | 52 |
55 ~PerfCodeObserver() { | 53 ~PerfCodeObserver() { |
56 Dart_FileCloseCallback file_close = Isolate::file_close_callback(); | 54 Dart_FileCloseCallback file_close = Isolate::file_close_callback(); |
57 if ((file_close == NULL) || (out_file_ == NULL)) { | 55 if ((file_close == NULL) || (out_file_ == NULL)) { |
58 return; | 56 return; |
59 } | 57 } |
60 (*file_close)(out_file_); | 58 (*file_close)(out_file_); |
61 } | 59 } |
62 | 60 |
63 virtual bool IsActive() const { | 61 virtual bool IsActive() const { |
64 return FLAG_generate_perf_events_symbols && (out_file_ != NULL); | 62 return FLAG_generate_perf_events_symbols && (out_file_ != NULL); |
65 } | 63 } |
66 | 64 |
67 virtual void Notify(const char* name, | 65 virtual void Notify(const char* name, |
68 uword base, | 66 uword base, |
69 uword prologue_offset, | 67 uword prologue_offset, |
70 uword size, | 68 uword size, |
71 bool optimized) { | 69 bool optimized) { |
72 Dart_FileWriteCallback file_write = Isolate::file_write_callback(); | 70 Dart_FileWriteCallback file_write = Isolate::file_write_callback(); |
73 if ((file_write == NULL) || (out_file_ == NULL)) { | 71 if ((file_write == NULL) || (out_file_ == NULL)) { |
74 return; | 72 return; |
75 } | 73 } |
76 const char* format = "%" Px " %" Px " %s%s\n"; | |
77 const char* marker = optimized ? "*" : ""; | 74 const char* marker = optimized ? "*" : ""; |
78 intptr_t len = OS::SNPrint(NULL, 0, format, base, size, marker, name); | 75 char* buffer = OS::SNCreate(Thread::Current()->zone(), |
79 char* buffer = Thread::Current()->zone()->Alloc<char>(len + 1); | 76 "%" Px " %" Px " %s%s\n", base, size, marker, name); |
80 OS::SNPrint(buffer, len + 1, format, base, size, marker, name); | 77 (*file_write)(buffer, strlen(buffer), out_file_); |
81 (*file_write)(buffer, len, out_file_); | |
82 } | 78 } |
83 | 79 |
84 private: | 80 private: |
85 void* out_file_; | 81 void* out_file_; |
86 | 82 |
87 DISALLOW_COPY_AND_ASSIGN(PerfCodeObserver); | 83 DISALLOW_COPY_AND_ASSIGN(PerfCodeObserver); |
88 }; | 84 }; |
89 | 85 |
90 | 86 |
91 class GdbCodeObserver : public CodeObserver { | 87 class GdbCodeObserver : public CodeObserver { |
92 public: | 88 public: |
93 GdbCodeObserver() { } | 89 GdbCodeObserver() { } |
94 | 90 |
95 virtual bool IsActive() const { | 91 virtual bool IsActive() const { |
96 return FLAG_generate_gdb_symbols; | 92 return FLAG_generate_gdb_symbols; |
97 } | 93 } |
98 | 94 |
99 virtual void Notify(const char* name, | 95 virtual void Notify(const char* name, |
100 uword base, | 96 uword base, |
101 uword prologue_offset, | 97 uword prologue_offset, |
102 uword size, | 98 uword size, |
103 bool optimized) { | 99 bool optimized) { |
104 if (prologue_offset > 0) { | 100 if (prologue_offset > 0) { |
105 // In order to ensure that gdb sees the first instruction of a function | 101 // In order to ensure that gdb sees the first instruction of a function |
106 // as the prologue sequence we register two symbols for the cases when | 102 // as the prologue sequence we register two symbols for the cases when |
107 // the prologue sequence is not the first instruction: | 103 // the prologue sequence is not the first instruction: |
108 // <name>_entry is used for code preceding the prologue sequence. | 104 // <name>_entry is used for code preceding the prologue sequence. |
109 // <name> for rest of the code (first instruction is prologue sequence). | 105 // <name> for rest of the code (first instruction is prologue sequence). |
110 const char* kFormat = "%s_%s"; | 106 char* pname = OS::SNCreate(Thread::Current()->zone(), |
111 intptr_t len = OS::SNPrint(NULL, 0, kFormat, name, "entry"); | 107 "%s_%s", name, "entry"); |
112 char* pname = Thread::Current()->zone()->Alloc<char>(len + 1); | |
113 OS::SNPrint(pname, (len + 1), kFormat, name, "entry"); | |
114 DebugInfo::RegisterSection(pname, base, size); | 108 DebugInfo::RegisterSection(pname, base, size); |
115 DebugInfo::RegisterSection(name, | 109 DebugInfo::RegisterSection(name, |
116 (base + prologue_offset), | 110 (base + prologue_offset), |
117 (size - prologue_offset)); | 111 (size - prologue_offset)); |
118 } else { | 112 } else { |
119 DebugInfo::RegisterSection(name, base, size); | 113 DebugInfo::RegisterSection(name, base, size); |
120 } | 114 } |
121 } | 115 } |
122 | 116 |
123 private: | 117 private: |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
338 | 332 |
339 int OS::SNPrint(char* str, size_t size, const char* format, ...) { | 333 int OS::SNPrint(char* str, size_t size, const char* format, ...) { |
340 va_list args; | 334 va_list args; |
341 va_start(args, format); | 335 va_start(args, format); |
342 int retval = VSNPrint(str, size, format, args); | 336 int retval = VSNPrint(str, size, format, args); |
343 va_end(args); | 337 va_end(args); |
344 return retval; | 338 return retval; |
345 } | 339 } |
346 | 340 |
347 | 341 |
342 char* OS::SNCreate(Zone* zone, const char* format, ...) { | |
Ivan Posva
2015/09/10 18:08:11
P.S. Please drop the N as we are not passing a len
zra
2015/09/10 21:58:38
Done.
| |
343 va_list args; | |
344 va_start(args, format); | |
345 | |
346 // Measure. | |
347 va_list measure_args; | |
348 va_copy(measure_args, args); | |
349 intptr_t len = VSNPrint(NULL, 0, format, measure_args); | |
350 va_end(measure_args); | |
351 | |
352 char* buffer; | |
353 if (zone) { | |
354 buffer = zone->Alloc<char>(len + 1); | |
Cutch
2015/09/10 18:01:04
Note that Zone already has the following utility f
Ivan Posva
2015/09/10 18:08:11
Thanks for pointing that out. I find that API a bi
zra
2015/09/10 21:58:38
Changed as discussed this morning.
| |
355 } else { | |
356 buffer = reinterpret_cast<char*>(malloc(len + 1)); | |
357 } | |
358 ASSERT(buffer != NULL); | |
359 | |
360 // Print. | |
361 va_list print_args; | |
362 va_copy(print_args, args); | |
363 VSNPrint(buffer, len + 1, format, print_args); | |
364 va_end(print_args); | |
365 va_end(args); | |
366 return buffer; | |
367 } | |
368 | |
369 | |
348 int OS::VSNPrint(char* str, size_t size, const char* format, va_list args) { | 370 int OS::VSNPrint(char* str, size_t size, const char* format, va_list args) { |
349 int retval = vsnprintf(str, size, format, args); | 371 int retval = vsnprintf(str, size, format, args); |
350 if (retval < 0) { | 372 if (retval < 0) { |
351 FATAL1("Fatal error in OS::VSNPrint with format '%s'", format); | 373 FATAL1("Fatal error in OS::VSNPrint with format '%s'", format); |
352 } | 374 } |
353 return retval; | 375 return retval; |
354 } | 376 } |
355 | 377 |
356 | 378 |
357 bool OS::StringToInt64(const char* str, int64_t* value) { | 379 bool OS::StringToInt64(const char* str, int64_t* value) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
415 } | 437 } |
416 | 438 |
417 | 439 |
418 void OS::Exit(int code) { | 440 void OS::Exit(int code) { |
419 exit(code); | 441 exit(code); |
420 } | 442 } |
421 | 443 |
422 } // namespace dart | 444 } // namespace dart |
423 | 445 |
424 #endif // defined(TARGET_OS_ANDROID) | 446 #endif // defined(TARGET_OS_ANDROID) |
OLD | NEW |