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

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

Issue 12342012: Support instruction-level perf event profiling to Dart VM using V8's ll_prof.py. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 9 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 | « no previous file | no next file » | 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_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
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";
Vyacheslav Egorov (Google) 2013/02/26 14:19:25 I like the name. You can consider making ll_prof
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 intptr_t name_size;
80 uword code_address;
81 uword code_size;
82 };
83
84 template <typename T>
85 void LowLevelLogWriteStruct(const T& s) {
Vyacheslav Egorov (Google) 2013/02/26 14:19:25 There is only a single structure so for now we don
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* format = "%s%s";
Vyacheslav Egorov (Google) 2013/02/26 14:24:17 Use Zone::PrintToString here.
103 const char* marker = optimized ? "*" : "";
104 intptr_t len = OS::SNPrint(NULL, 0, format, marker, name);
105 char* buffer = Isolate::Current()->current_zone()->Alloc<char>(len + 1);
106 OS::SNPrint(buffer, len + 1, format, marker, name);
107
108 LowLevelCodeCreateStruct event;
109 event.name_size = len;
110 event.code_address = base;
111 event.code_size = size;
112
113 LowLevelLogWriteStruct(event);
114 LowLevelLogWriteBytes(buffer, len);
115 LowLevelLogWriteBytes(reinterpret_cast<char*>(base), size);
116 }
117
118 private:
119 void* log_file_;
120
121 DISALLOW_COPY_AND_ASSIGN(LowLevelProfileCodeObserver);
122 };
123
124
38 class PerfCodeObserver : public CodeObserver { 125 class PerfCodeObserver : public CodeObserver {
39 public: 126 public:
40 PerfCodeObserver() { 127 PerfCodeObserver() {
41 Dart_FileOpenCallback file_open = Isolate::file_open_callback(); 128 Dart_FileOpenCallback file_open = Isolate::file_open_callback();
42 if (file_open == NULL) { 129 if (file_open == NULL) {
43 return; 130 return;
44 } 131 }
45 const char* format = "/tmp/perf-%ld.map"; 132 const char* format = "/tmp/perf-%ld.map";
46 intptr_t pid = getpid(); 133 intptr_t pid = getpid();
47 intptr_t len = OS::SNPrint(NULL, 0, format, pid); 134 intptr_t len = OS::SNPrint(NULL, 0, format, pid);
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 (str[i + 2] != '\0')) { 458 (str[i + 2] != '\0')) {
372 base = 16; 459 base = 16;
373 } 460 }
374 errno = 0; 461 errno = 0;
375 *value = strtoll(str, &endptr, base); 462 *value = strtoll(str, &endptr, base);
376 return ((errno == 0) && (endptr != str) && (*endptr == 0)); 463 return ((errno == 0) && (endptr != str) && (*endptr == 0));
377 } 464 }
378 465
379 466
380 void OS::RegisterCodeObservers() { 467 void OS::RegisterCodeObservers() {
468 if (FLAG_ll_prof) {
469 CodeObservers::Register(new LowLevelProfileCodeObserver);
470 }
381 if (FLAG_generate_perf_events_symbols) { 471 if (FLAG_generate_perf_events_symbols) {
382 CodeObservers::Register(new PerfCodeObserver); 472 CodeObservers::Register(new PerfCodeObserver);
383 } 473 }
384 if (FLAG_generate_gdb_symbols) { 474 if (FLAG_generate_gdb_symbols) {
385 CodeObservers::Register(new GdbCodeObserver); 475 CodeObservers::Register(new GdbCodeObserver);
386 } 476 }
387 if (FLAG_generate_pprof_symbols != NULL) { 477 if (FLAG_generate_pprof_symbols != NULL) {
388 CodeObservers::Register(new PprofCodeObserver); 478 CodeObservers::Register(new PprofCodeObserver);
389 } 479 }
390 #if defined(DART_VTUNE_SUPPORT) 480 #if defined(DART_VTUNE_SUPPORT)
(...skipping 29 matching lines...) Expand all
420 } 510 }
421 511
422 512
423 void OS::Exit(int code) { 513 void OS::Exit(int code) {
424 exit(code); 514 exit(code);
425 } 515 }
426 516
427 } // namespace dart 517 } // namespace dart
428 518
429 #endif // defined(TARGET_OS_LINUX) 519 #endif // defined(TARGET_OS_LINUX)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698