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

Side by Side Diff: runtime/vm/os_android.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.h ('k') | runtime/vm/os_linux.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_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
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::SCreate(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::SCreate(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::SCreate(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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 341
348 int OS::VSNPrint(char* str, size_t size, const char* format, va_list args) { 342 int OS::VSNPrint(char* str, size_t size, const char* format, va_list args) {
349 int retval = vsnprintf(str, size, format, args); 343 int retval = vsnprintf(str, size, format, args);
350 if (retval < 0) { 344 if (retval < 0) {
351 FATAL1("Fatal error in OS::VSNPrint with format '%s'", format); 345 FATAL1("Fatal error in OS::VSNPrint with format '%s'", format);
352 } 346 }
353 return retval; 347 return retval;
354 } 348 }
355 349
356 350
351 char* OS::SCreate(Zone* zone, const char* format, ...) {
352 va_list args;
353 va_start(args, format);
354 char* buffer = VSCreate(zone, format, args);
355 va_end(args);
356 return buffer;
357 }
358
359
360 char* OS::VSCreate(Zone* zone, const char* format, va_list args) {
361 // Measure.
362 va_list measure_args;
363 va_copy(measure_args, args);
364 intptr_t len = VSNPrint(NULL, 0, format, measure_args);
365 va_end(measure_args);
366
367 char* buffer;
368 if (zone) {
369 buffer = zone->Alloc<char>(len + 1);
370 } else {
371 buffer = reinterpret_cast<char*>(malloc(len + 1));
372 }
373 ASSERT(buffer != NULL);
374
375 // Print.
376 va_list print_args;
377 va_copy(print_args, args);
378 VSNPrint(buffer, len + 1, format, print_args);
379 va_end(print_args);
380 return buffer;
381 }
382
383
357 bool OS::StringToInt64(const char* str, int64_t* value) { 384 bool OS::StringToInt64(const char* str, int64_t* value) {
358 ASSERT(str != NULL && strlen(str) > 0 && value != NULL); 385 ASSERT(str != NULL && strlen(str) > 0 && value != NULL);
359 int32_t base = 10; 386 int32_t base = 10;
360 char* endptr; 387 char* endptr;
361 int i = 0; 388 int i = 0;
362 if (str[0] == '-') { 389 if (str[0] == '-') {
363 i = 1; 390 i = 1;
364 } 391 }
365 if ((str[i] == '0') && 392 if ((str[i] == '0') &&
366 (str[i + 1] == 'x' || str[i + 1] == 'X') && 393 (str[i + 1] == 'x' || str[i + 1] == 'X') &&
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 } 442 }
416 443
417 444
418 void OS::Exit(int code) { 445 void OS::Exit(int code) {
419 exit(code); 446 exit(code);
420 } 447 }
421 448
422 } // namespace dart 449 } // namespace dart
423 450
424 #endif // defined(TARGET_OS_ANDROID) 451 #endif // defined(TARGET_OS_ANDROID)
OLDNEW
« no previous file with comments | « runtime/vm/os.h ('k') | runtime/vm/os_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698