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

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: Format string fixes 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
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 = NULL;
50 char* filename = new char[len + 1]; 49 SNPRINT(filename, malloc, "/tmp/perf-%" Pd ".map", pid);
51 OS::SNPrint(filename, len + 1, format, pid);
52 out_file_ = (*file_open)(filename, true); 50 out_file_ = (*file_open)(filename, true);
51 free(filename);
53 } 52 }
54 53
55 ~PerfCodeObserver() { 54 ~PerfCodeObserver() {
56 Dart_FileCloseCallback file_close = Isolate::file_close_callback(); 55 Dart_FileCloseCallback file_close = Isolate::file_close_callback();
57 if ((file_close == NULL) || (out_file_ == NULL)) { 56 if ((file_close == NULL) || (out_file_ == NULL)) {
58 return; 57 return;
59 } 58 }
60 (*file_close)(out_file_); 59 (*file_close)(out_file_);
61 } 60 }
62 61
63 virtual bool IsActive() const { 62 virtual bool IsActive() const {
64 return FLAG_generate_perf_events_symbols && (out_file_ != NULL); 63 return FLAG_generate_perf_events_symbols && (out_file_ != NULL);
65 } 64 }
66 65
67 virtual void Notify(const char* name, 66 virtual void Notify(const char* name,
68 uword base, 67 uword base,
69 uword prologue_offset, 68 uword prologue_offset,
70 uword size, 69 uword size,
71 bool optimized) { 70 bool optimized) {
72 Dart_FileWriteCallback file_write = Isolate::file_write_callback(); 71 Dart_FileWriteCallback file_write = Isolate::file_write_callback();
73 if ((file_write == NULL) || (out_file_ == NULL)) { 72 if ((file_write == NULL) || (out_file_ == NULL)) {
74 return; 73 return;
75 } 74 }
76 const char* format = "%" Px " %" Px " %s%s\n";
77 const char* marker = optimized ? "*" : ""; 75 const char* marker = optimized ? "*" : "";
78 intptr_t len = OS::SNPrint(NULL, 0, format, base, size, marker, name); 76 char* buffer = NULL;
79 char* buffer = Thread::Current()->zone()->Alloc<char>(len + 1); 77 SNPRINT(buffer, Thread::Current()->zone()->Alloc<char>,
80 OS::SNPrint(buffer, len + 1, format, base, size, marker, name); 78 "%" Px " %" Px " %s%s\n", base, size, marker, name);
81 (*file_write)(buffer, len, out_file_); 79 (*file_write)(buffer, strlen(buffer), out_file_);
82 } 80 }
83 81
84 private: 82 private:
85 void* out_file_; 83 void* out_file_;
86 84
87 DISALLOW_COPY_AND_ASSIGN(PerfCodeObserver); 85 DISALLOW_COPY_AND_ASSIGN(PerfCodeObserver);
88 }; 86 };
89 87
90 88
91 class GdbCodeObserver : public CodeObserver { 89 class GdbCodeObserver : public CodeObserver {
92 public: 90 public:
93 GdbCodeObserver() { } 91 GdbCodeObserver() { }
94 92
95 virtual bool IsActive() const { 93 virtual bool IsActive() const {
96 return FLAG_generate_gdb_symbols; 94 return FLAG_generate_gdb_symbols;
97 } 95 }
98 96
99 virtual void Notify(const char* name, 97 virtual void Notify(const char* name,
100 uword base, 98 uword base,
101 uword prologue_offset, 99 uword prologue_offset,
102 uword size, 100 uword size,
103 bool optimized) { 101 bool optimized) {
104 if (prologue_offset > 0) { 102 if (prologue_offset > 0) {
105 // In order to ensure that gdb sees the first instruction of a function 103 // 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 104 // as the prologue sequence we register two symbols for the cases when
107 // the prologue sequence is not the first instruction: 105 // the prologue sequence is not the first instruction:
108 // <name>_entry is used for code preceding the prologue sequence. 106 // <name>_entry is used for code preceding the prologue sequence.
109 // <name> for rest of the code (first instruction is prologue sequence). 107 // <name> for rest of the code (first instruction is prologue sequence).
110 const char* kFormat = "%s_%s"; 108 char* pname = NULL;
111 intptr_t len = OS::SNPrint(NULL, 0, kFormat, name, "entry"); 109 SNPRINT(pname, Thread::Current()->zone()->Alloc<char>, "%s_%s",
112 char* pname = Thread::Current()->zone()->Alloc<char>(len + 1); 110 name, "entry");
113 OS::SNPrint(pname, (len + 1), kFormat, name, "entry");
114 DebugInfo::RegisterSection(pname, base, size); 111 DebugInfo::RegisterSection(pname, base, size);
115 DebugInfo::RegisterSection(name, 112 DebugInfo::RegisterSection(name,
116 (base + prologue_offset), 113 (base + prologue_offset),
117 (size - prologue_offset)); 114 (size - prologue_offset));
118 } else { 115 } else {
119 DebugInfo::RegisterSection(name, base, size); 116 DebugInfo::RegisterSection(name, base, size);
120 } 117 }
121 } 118 }
122 119
123 private: 120 private:
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 } 412 }
416 413
417 414
418 void OS::Exit(int code) { 415 void OS::Exit(int code) {
419 exit(code); 416 exit(code);
420 } 417 }
421 418
422 } // namespace dart 419 } // namespace dart
423 420
424 #endif // defined(TARGET_OS_ANDROID) 421 #endif // defined(TARGET_OS_ANDROID)
OLDNEW
« runtime/vm/object.cc ('K') | « 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