| 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_LINUX) | 6 #if defined(TARGET_OS_LINUX) |
| 7 | 7 |
| 8 #include "vm/os.h" | 8 #include "vm/os.h" |
| 9 | 9 |
| 10 #include <errno.h> // NOLINT | 10 #include <errno.h> // NOLINT |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 | 26 |
| 27 namespace dart { | 27 namespace dart { |
| 28 | 28 |
| 29 // Linux CodeObservers. | 29 // Linux CodeObservers. |
| 30 | 30 |
| 31 DEFINE_FLAG(bool, generate_gdb_symbols, false, | 31 DEFINE_FLAG(bool, generate_gdb_symbols, false, |
| 32 "Generate symbols of generated dart functions for debugging with GDB"); | 32 "Generate symbols of generated dart functions for debugging with GDB"); |
| 33 DEFINE_FLAG(bool, generate_perf_events_symbols, false, | 33 DEFINE_FLAG(bool, generate_perf_events_symbols, false, |
| 34 "Generate events symbols for profiling with perf"); | 34 "Generate events symbols for profiling with perf"); |
| 35 DEFINE_FLAG(bool, ll_prof, false, |
| 36 "Generate compiled code log file for processing with ll_prof.py."); |
| 35 DEFINE_FLAG(charp, generate_pprof_symbols, NULL, | 37 DEFINE_FLAG(charp, generate_pprof_symbols, NULL, |
| 36 "Writes pprof events symbols to the provided file"); | 38 "Writes pprof events symbols to the provided file"); |
| 37 | 39 |
| 40 class LowLevelProfileCodeObserver : public CodeObserver { |
| 41 public: |
| 42 LowLevelProfileCodeObserver() { |
| 43 Dart_FileOpenCallback file_open = Isolate::file_open_callback(); |
| 44 if (file_open == NULL) { |
| 45 return; |
| 46 } |
| 47 const char* filename = "v8.log.ll"; |
| 48 log_file_ = (*file_open)(filename); |
| 49 #if defined(TARGET_ARCH_IA32) |
| 50 const char arch[] = "ia32"; |
| 51 #elif defined(TARGET_ARCH_X64) |
| 52 const char arch[] = "x64"; |
| 53 #elif defined(TARGET_ARCH_ARM) |
| 54 const char arch[] = "arm"; |
| 55 #elif defined(TARGET_ARCH_MIPS) |
| 56 const char arch[] = "mips"; |
| 57 #else |
| 58 const char arch[] = "unknown"; |
| 59 #endif |
| 60 LowLevelLogWriteBytes(arch, sizeof(arch)); |
| 61 } |
| 62 |
| 63 ~LowLevelProfileCodeObserver() { |
| 64 Dart_FileCloseCallback file_close = Isolate::file_close_callback(); |
| 65 if (file_close == NULL) { |
| 66 return; |
| 67 } |
| 68 ASSERT(log_file_ != NULL); |
| 69 (*file_close)(log_file_); |
| 70 } |
| 71 |
| 72 virtual bool IsActive() const { |
| 73 return FLAG_ll_prof; |
| 74 } |
| 75 |
| 76 struct LowLevelCodeCreateStruct { |
| 77 static const char kTag = 'C'; |
| 78 |
| 79 int32_t name_size; |
| 80 uword code_address; |
| 81 int32_t code_size; |
| 82 }; |
| 83 |
| 84 template <typename T> |
| 85 void LowLevelLogWriteStruct(const T& s) { |
| 86 char tag = T::kTag; |
| 87 LowLevelLogWriteBytes(reinterpret_cast<const char*>(&tag), sizeof(tag)); |
| 88 LowLevelLogWriteBytes(reinterpret_cast<const char*>(&s), sizeof(s)); |
| 89 } |
| 90 |
| 91 void LowLevelLogWriteBytes(const char* bytes, int size) { |
| 92 Dart_FileWriteCallback file_write = Isolate::file_write_callback(); |
| 93 ASSERT(file_write != NULL); |
| 94 (file_write)(bytes, size, log_file_); |
| 95 } |
| 96 |
| 97 virtual void Notify(const char* name, |
| 98 uword base, |
| 99 uword prologue_offset, |
| 100 uword size, |
| 101 bool optimized) { |
| 102 const char* marker = optimized ? "*" : ""; |
| 103 char* name_buffer = |
| 104 Isolate::Current()->current_zone()->PrintToString("%s%s", marker, name); |
| 105 intptr_t len = strlen(name_buffer); |
| 106 |
| 107 LowLevelCodeCreateStruct event; |
| 108 event.name_size = len; |
| 109 event.code_address = base; |
| 110 event.code_size = size; |
| 111 |
| 112 LowLevelLogWriteStruct(event); |
| 113 LowLevelLogWriteBytes(name_buffer, len); |
| 114 LowLevelLogWriteBytes(reinterpret_cast<char*>(base), size); |
| 115 } |
| 116 |
| 117 private: |
| 118 void* log_file_; |
| 119 |
| 120 DISALLOW_COPY_AND_ASSIGN(LowLevelProfileCodeObserver); |
| 121 }; |
| 122 |
| 123 |
| 38 class PerfCodeObserver : public CodeObserver { | 124 class PerfCodeObserver : public CodeObserver { |
| 39 public: | 125 public: |
| 40 PerfCodeObserver() { | 126 PerfCodeObserver() { |
| 41 Dart_FileOpenCallback file_open = Isolate::file_open_callback(); | 127 Dart_FileOpenCallback file_open = Isolate::file_open_callback(); |
| 42 if (file_open == NULL) { | 128 if (file_open == NULL) { |
| 43 return; | 129 return; |
| 44 } | 130 } |
| 45 const char* format = "/tmp/perf-%ld.map"; | 131 const char* format = "/tmp/perf-%ld.map"; |
| 46 intptr_t pid = getpid(); | 132 intptr_t pid = getpid(); |
| 47 intptr_t len = OS::SNPrint(NULL, 0, format, pid); | 133 intptr_t len = OS::SNPrint(NULL, 0, format, pid); |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 (str[i + 2] != '\0')) { | 457 (str[i + 2] != '\0')) { |
| 372 base = 16; | 458 base = 16; |
| 373 } | 459 } |
| 374 errno = 0; | 460 errno = 0; |
| 375 *value = strtoll(str, &endptr, base); | 461 *value = strtoll(str, &endptr, base); |
| 376 return ((errno == 0) && (endptr != str) && (*endptr == 0)); | 462 return ((errno == 0) && (endptr != str) && (*endptr == 0)); |
| 377 } | 463 } |
| 378 | 464 |
| 379 | 465 |
| 380 void OS::RegisterCodeObservers() { | 466 void OS::RegisterCodeObservers() { |
| 467 if (FLAG_ll_prof) { |
| 468 CodeObservers::Register(new LowLevelProfileCodeObserver); |
| 469 } |
| 381 if (FLAG_generate_perf_events_symbols) { | 470 if (FLAG_generate_perf_events_symbols) { |
| 382 CodeObservers::Register(new PerfCodeObserver); | 471 CodeObservers::Register(new PerfCodeObserver); |
| 383 } | 472 } |
| 384 if (FLAG_generate_gdb_symbols) { | 473 if (FLAG_generate_gdb_symbols) { |
| 385 CodeObservers::Register(new GdbCodeObserver); | 474 CodeObservers::Register(new GdbCodeObserver); |
| 386 } | 475 } |
| 387 if (FLAG_generate_pprof_symbols != NULL) { | 476 if (FLAG_generate_pprof_symbols != NULL) { |
| 388 CodeObservers::Register(new PprofCodeObserver); | 477 CodeObservers::Register(new PprofCodeObserver); |
| 389 } | 478 } |
| 390 #if defined(DART_VTUNE_SUPPORT) | 479 #if defined(DART_VTUNE_SUPPORT) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 420 } | 509 } |
| 421 | 510 |
| 422 | 511 |
| 423 void OS::Exit(int code) { | 512 void OS::Exit(int code) { |
| 424 exit(code); | 513 exit(code); |
| 425 } | 514 } |
| 426 | 515 |
| 427 } // namespace dart | 516 } // namespace dart |
| 428 | 517 |
| 429 #endif // defined(TARGET_OS_LINUX) | 518 #endif // defined(TARGET_OS_LINUX) |
| OLD | NEW |