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

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

Issue 1331623002: Uses SNPRINT macro where possible. Otherwise uses #define for format. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: add missing include Created 5 years, 3 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
« no previous file with comments | « runtime/vm/os_android.cc ('k') | runtime/vm/os_macos.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_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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 "Writes jitdump data for profiling with perf annotate"); 42 "Writes jitdump data for profiling with perf annotate");
43 43
44 44
45 class PerfCodeObserver : public CodeObserver { 45 class PerfCodeObserver : public CodeObserver {
46 public: 46 public:
47 PerfCodeObserver() : out_file_(NULL) { 47 PerfCodeObserver() : out_file_(NULL) {
48 Dart_FileOpenCallback file_open = Isolate::file_open_callback(); 48 Dart_FileOpenCallback file_open = Isolate::file_open_callback();
49 if (file_open == NULL) { 49 if (file_open == NULL) {
50 return; 50 return;
51 } 51 }
52 const char* format = "/tmp/perf-%" Pd ".map";
53 intptr_t pid = getpid(); 52 intptr_t pid = getpid();
54 intptr_t len = OS::SNPrint(NULL, 0, format, pid); 53 char* filename = OS::SCreate(NULL, "/tmp/perf-%" Pd ".map", pid);
55 char* filename = new char[len + 1];
56 OS::SNPrint(filename, len + 1, format, pid);
57 out_file_ = (*file_open)(filename, true); 54 out_file_ = (*file_open)(filename, true);
58 delete[] filename; 55 free(filename);
59 } 56 }
60 57
61 ~PerfCodeObserver() { 58 ~PerfCodeObserver() {
62 Dart_FileCloseCallback file_close = Isolate::file_close_callback(); 59 Dart_FileCloseCallback file_close = Isolate::file_close_callback();
63 if ((file_close == NULL) || (out_file_ == NULL)) { 60 if ((file_close == NULL) || (out_file_ == NULL)) {
64 return; 61 return;
65 } 62 }
66 (*file_close)(out_file_); 63 (*file_close)(out_file_);
67 } 64 }
68 65
69 virtual bool IsActive() const { 66 virtual bool IsActive() const {
70 return FLAG_generate_perf_events_symbols && (out_file_ != NULL); 67 return FLAG_generate_perf_events_symbols && (out_file_ != NULL);
71 } 68 }
72 69
73 virtual void Notify(const char* name, 70 virtual void Notify(const char* name,
74 uword base, 71 uword base,
75 uword prologue_offset, 72 uword prologue_offset,
76 uword size, 73 uword size,
77 bool optimized) { 74 bool optimized) {
78 Dart_FileWriteCallback file_write = Isolate::file_write_callback(); 75 Dart_FileWriteCallback file_write = Isolate::file_write_callback();
79 if ((file_write == NULL) || (out_file_ == NULL)) { 76 if ((file_write == NULL) || (out_file_ == NULL)) {
80 return; 77 return;
81 } 78 }
82 const char* format = "%" Px " %" Px " %s%s\n";
83 const char* marker = optimized ? "*" : ""; 79 const char* marker = optimized ? "*" : "";
84 intptr_t len = OS::SNPrint(NULL, 0, format, base, size, marker, name); 80 char* buffer = OS::SCreate(Thread::Current()->zone(),
85 char* buffer = Thread::Current()->zone()->Alloc<char>(len + 1); 81 "%" Px " %" Px " %s%s\n", base, size, marker, name);
86 OS::SNPrint(buffer, len + 1, format, base, size, marker, name);
87 { 82 {
88 MutexLocker ml(CodeObservers::mutex()); 83 MutexLocker ml(CodeObservers::mutex());
89 (*file_write)(buffer, len, out_file_); 84 (*file_write)(buffer, strlen(buffer), out_file_);
90 } 85 }
91 } 86 }
92 87
93 private: 88 private:
94 void* out_file_; 89 void* out_file_;
95 90
96 DISALLOW_COPY_AND_ASSIGN(PerfCodeObserver); 91 DISALLOW_COPY_AND_ASSIGN(PerfCodeObserver);
97 }; 92 };
98 93
99 94
100 class GdbCodeObserver : public CodeObserver { 95 class GdbCodeObserver : public CodeObserver {
101 public: 96 public:
102 GdbCodeObserver() { } 97 GdbCodeObserver() { }
103 98
104 virtual bool IsActive() const { 99 virtual bool IsActive() const {
105 return FLAG_generate_gdb_symbols; 100 return FLAG_generate_gdb_symbols;
106 } 101 }
107 102
108 virtual void Notify(const char* name, 103 virtual void Notify(const char* name,
109 uword base, 104 uword base,
110 uword prologue_offset, 105 uword prologue_offset,
111 uword size, 106 uword size,
112 bool optimized) { 107 bool optimized) {
113 if (prologue_offset > 0) { 108 if (prologue_offset > 0) {
114 // In order to ensure that gdb sees the first instruction of a function 109 // In order to ensure that gdb sees the first instruction of a function
115 // as the prologue sequence we register two symbols for the cases when 110 // as the prologue sequence we register two symbols for the cases when
116 // the prologue sequence is not the first instruction: 111 // the prologue sequence is not the first instruction:
117 // <name>_entry is used for code preceding the prologue sequence. 112 // <name>_entry is used for code preceding the prologue sequence.
118 // <name> for rest of the code (first instruction is prologue sequence). 113 // <name> for rest of the code (first instruction is prologue sequence).
119 const char* kFormat = "%s_%s"; 114 char* pname = OS::SCreate(Thread::Current()->zone(),
120 intptr_t len = OS::SNPrint(NULL, 0, kFormat, name, "entry"); 115 "%s_%s", name, "entry");
121 char* pname = Thread::Current()->zone()->Alloc<char>(len + 1);
122 OS::SNPrint(pname, (len + 1), kFormat, name, "entry");
123 DebugInfo::RegisterSection(pname, base, size); 116 DebugInfo::RegisterSection(pname, base, size);
124 DebugInfo::RegisterSection(name, 117 DebugInfo::RegisterSection(name,
125 (base + prologue_offset), 118 (base + prologue_offset),
126 (size - prologue_offset)); 119 (size - prologue_offset));
127 } else { 120 } else {
128 DebugInfo::RegisterSection(name, base, size); 121 DebugInfo::RegisterSection(name, base, size);
129 } 122 }
130 } 123 }
131 124
132 private: 125 private:
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 struct jr_prefix prefix; 231 struct jr_prefix prefix;
239 uint32_t pid; 232 uint32_t pid;
240 uint32_t tid; 233 uint32_t tid;
241 uint64_t vma; 234 uint64_t vma;
242 uint64_t code_addr; 235 uint64_t code_addr;
243 uint64_t code_size; 236 uint64_t code_size;
244 uint64_t code_index; 237 uint64_t code_index;
245 }; 238 };
246 239
247 const char* GenerateCodeName(const char* name, bool optimized) { 240 const char* GenerateCodeName(const char* name, bool optimized) {
248 const char* format = "%s%s";
249 const char* marker = optimized ? "*" : ""; 241 const char* marker = optimized ? "*" : "";
250 intptr_t len = OS::SNPrint(NULL, 0, format, marker, name); 242 return OS::SCreate(Thread::Current()->zone(), "%s%s", marker, name);
251 char* buffer = Thread::Current()->zone()->Alloc<char>(len + 1);
252 OS::SNPrint(buffer, len + 1, format, marker, name);
253 return buffer;
254 } 243 }
255 244
256 uint32_t GetElfMach() { 245 uint32_t GetElfMach() {
257 #if defined(TARGET_ARCH_IA32) 246 #if defined(TARGET_ARCH_IA32)
258 return kElfMachIA32; 247 return kElfMachIA32;
259 #elif defined(TARGET_ARCH_X64) 248 #elif defined(TARGET_ARCH_X64)
260 return kElfMachX64; 249 return kElfMachX64;
261 #elif defined(TARGET_ARCH_ARM) 250 #elif defined(TARGET_ARCH_ARM)
262 return kElfMachARM; 251 return kElfMachARM;
263 #elif defined(TARGET_ARCH_ARM64) 252 #elif defined(TARGET_ARCH_ARM64)
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 531
543 int OS::VSNPrint(char* str, size_t size, const char* format, va_list args) { 532 int OS::VSNPrint(char* str, size_t size, const char* format, va_list args) {
544 int retval = vsnprintf(str, size, format, args); 533 int retval = vsnprintf(str, size, format, args);
545 if (retval < 0) { 534 if (retval < 0) {
546 FATAL1("Fatal error in OS::VSNPrint with format '%s'", format); 535 FATAL1("Fatal error in OS::VSNPrint with format '%s'", format);
547 } 536 }
548 return retval; 537 return retval;
549 } 538 }
550 539
551 540
541 char* OS::SCreate(Zone* zone, const char* format, ...) {
542 va_list args;
543 va_start(args, format);
544 char* buffer = VSCreate(zone, format, args);
545 va_end(args);
546 return buffer;
547 }
548
549
550 char* OS::VSCreate(Zone* zone, const char* format, va_list args) {
551 // Measure.
552 va_list measure_args;
553 va_copy(measure_args, args);
554 intptr_t len = VSNPrint(NULL, 0, format, measure_args);
555 va_end(measure_args);
556
557 char* buffer;
558 if (zone) {
559 buffer = zone->Alloc<char>(len + 1);
560 } else {
561 buffer = reinterpret_cast<char*>(malloc(len + 1));
562 }
563 ASSERT(buffer != NULL);
564
565 // Print.
566 va_list print_args;
567 va_copy(print_args, args);
568 VSNPrint(buffer, len + 1, format, print_args);
569 va_end(print_args);
570 return buffer;
571 }
572
573
552 bool OS::StringToInt64(const char* str, int64_t* value) { 574 bool OS::StringToInt64(const char* str, int64_t* value) {
553 ASSERT(str != NULL && strlen(str) > 0 && value != NULL); 575 ASSERT(str != NULL && strlen(str) > 0 && value != NULL);
554 int32_t base = 10; 576 int32_t base = 10;
555 char* endptr; 577 char* endptr;
556 int i = 0; 578 int i = 0;
557 if (str[0] == '-') { 579 if (str[0] == '-') {
558 i = 1; 580 i = 1;
559 } 581 }
560 if ((str[i] == '0') && 582 if ((str[i] == '0') &&
561 (str[i + 1] == 'x' || str[i + 1] == 'X') && 583 (str[i + 1] == 'x' || str[i + 1] == 'X') &&
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 } 633 }
612 634
613 635
614 void OS::Exit(int code) { 636 void OS::Exit(int code) {
615 exit(code); 637 exit(code);
616 } 638 }
617 639
618 } // namespace dart 640 } // namespace dart
619 641
620 #endif // defined(TARGET_OS_LINUX) 642 #endif // defined(TARGET_OS_LINUX)
OLDNEW
« no previous file with comments | « runtime/vm/os_android.cc ('k') | runtime/vm/os_macos.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698