Chromium Code Reviews| 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/os.h" | 5 #include "vm/os.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <limits.h> | 8 #include <limits.h> |
| 9 #include <malloc.h> | 9 #include <malloc.h> |
| 10 #include <time.h> | 10 #include <time.h> |
| 11 #include <sys/resource.h> | 11 #include <sys/resource.h> |
| 12 #include <sys/time.h> | 12 #include <sys/time.h> |
| 13 #include <sys/types.h> | 13 #include <sys/types.h> |
| 14 #include <unistd.h> | 14 #include <unistd.h> |
| 15 | 15 |
| 16 #include "platform/utils.h" | 16 #include "platform/utils.h" |
| 17 #include "vm/code_observers.h" | |
| 18 #include "vm/dart.h" | |
| 19 #include "vm/debuginfo.h" | |
| 17 #include "vm/isolate.h" | 20 #include "vm/isolate.h" |
| 21 #include "vm/zone.h" | |
| 22 | |
| 18 | 23 |
| 19 namespace dart { | 24 namespace dart { |
| 20 | 25 |
| 26 // Linux-specific CodeObservers | |
|
siva
2012/12/14 19:13:40
Ditto.
Max Heinritz (Google)
2012/12/14 19:59:47
Done.
| |
| 27 | |
| 28 DEFINE_FLAG(bool, generate_gdb_symbols, false, | |
| 29 "Generate symbols of generated dart functions for debugging with GDB"); | |
| 30 DEFINE_FLAG(bool, generate_perf_events_symbols, false, | |
| 31 "Generate events symbols for profiling with perf"); | |
| 32 | |
| 33 class PerfCodeObserver : public CodeObserver { | |
| 34 public: | |
| 35 PerfCodeObserver() { | |
| 36 Dart_FileOpenCallback file_open = Isolate::file_open_callback(); | |
| 37 if (file_open == NULL) { | |
| 38 return; | |
| 39 } | |
| 40 const char* format = "/tmp/perf-%ld.map"; | |
| 41 intptr_t pid = getpid(); | |
| 42 intptr_t len = OS::SNPrint(NULL, 0, format, pid); | |
| 43 char* filename = new char[len + 1]; | |
| 44 OS::SNPrint(filename, len + 1, format, pid); | |
| 45 out_file_ = (*file_open)(filename); | |
| 46 } | |
| 47 | |
| 48 ~PerfCodeObserver() { | |
| 49 Dart_FileCloseCallback file_close = Isolate::file_close_callback(); | |
| 50 if (file_close == NULL) { | |
| 51 return; | |
| 52 } | |
| 53 ASSERT(out_file_ != NULL); | |
| 54 (*file_close)(out_file_); | |
| 55 } | |
| 56 | |
| 57 virtual bool IsActive() const { | |
| 58 return FLAG_generate_perf_events_symbols; | |
| 59 } | |
| 60 | |
| 61 virtual void Notify(const char* name, | |
| 62 uword base, | |
| 63 uword prologue_offset, | |
| 64 uword size, | |
| 65 bool optimized) { | |
| 66 Dart_FileWriteCallback file_write = Isolate::file_write_callback(); | |
| 67 ASSERT(file_write != NULL); | |
| 68 const char* format = "%"Px" %"Px" %s%s\n"; | |
| 69 const char* marker = optimized ? "*" : ""; | |
| 70 intptr_t len = OS::SNPrint(NULL, 0, format, base, size, marker, name); | |
| 71 char* buffer = Isolate::Current()->current_zone()->Alloc<char>(len + 1); | |
| 72 OS::SNPrint(buffer, len + 1, format, base, size, marker, name); | |
| 73 ASSERT(out_file_ != NULL); | |
| 74 (*file_write)(buffer, len, out_file_); | |
| 75 } | |
| 76 | |
| 77 private: | |
| 78 void* out_file_; | |
| 79 | |
| 80 DISALLOW_COPY_AND_ASSIGN(PerfCodeObserver); | |
| 81 }; | |
| 82 | |
| 83 class PprofCodeObserver : public CodeObserver { | |
| 84 public: | |
| 85 PprofCodeObserver() { } | |
| 86 | |
| 87 virtual bool IsActive() const { | |
| 88 return Dart::pprof_symbol_generator() != NULL; | |
| 89 } | |
| 90 | |
| 91 virtual void Notify(const char* name, | |
| 92 uword base, | |
| 93 uword prologue_offset, | |
| 94 uword size, | |
| 95 bool optimized) { | |
| 96 DebugInfo* pprof_symbol_generator = Dart::pprof_symbol_generator(); | |
| 97 ASSERT(pprof_symbol_generator != NULL); | |
| 98 pprof_symbol_generator->AddCode(base, size); | |
| 99 pprof_symbol_generator->AddCodeRegion(name, base, size); | |
| 100 } | |
| 101 | |
| 102 private: | |
| 103 DISALLOW_COPY_AND_ASSIGN(PprofCodeObserver); | |
| 104 }; | |
| 105 | |
| 106 class GdbCodeObserver : public CodeObserver { | |
| 107 public: | |
| 108 GdbCodeObserver() { } | |
| 109 | |
| 110 virtual bool IsActive() const { | |
| 111 return FLAG_generate_gdb_symbols; | |
| 112 } | |
| 113 | |
| 114 virtual void Notify(const char* name, | |
| 115 uword base, | |
| 116 uword prologue_offset, | |
| 117 uword size, | |
| 118 bool optimized) { | |
| 119 if (prologue_offset > 0) { | |
| 120 // In order to ensure that gdb sees the first instruction of a function | |
| 121 // as the prologue sequence we register two symbols for the cases when | |
| 122 // the prologue sequence is not the first instruction: | |
| 123 // <name>_entry is used for code preceding the prologue sequence. | |
| 124 // <name> for rest of the code (first instruction is prologue sequence). | |
| 125 const char* kFormat = "%s_%s"; | |
| 126 intptr_t len = OS::SNPrint(NULL, 0, kFormat, name, "entry"); | |
| 127 char* pname = Isolate::Current()->current_zone()->Alloc<char>(len + 1); | |
| 128 OS::SNPrint(pname, (len + 1), kFormat, name, "entry"); | |
| 129 DebugInfo::RegisterSection(pname, base, size); | |
| 130 DebugInfo::RegisterSection(name, | |
| 131 (base + prologue_offset), | |
| 132 (size - prologue_offset)); | |
| 133 } else { | |
| 134 DebugInfo::RegisterSection(name, base, size); | |
| 135 } | |
| 136 } | |
| 137 | |
| 138 private: | |
| 139 DISALLOW_COPY_AND_ASSIGN(GdbCodeObserver); | |
| 140 }; | |
| 141 | |
| 142 | |
| 21 static bool LocalTime(int64_t seconds_since_epoch, tm* tm_result) { | 143 static bool LocalTime(int64_t seconds_since_epoch, tm* tm_result) { |
| 22 time_t seconds = static_cast<time_t>(seconds_since_epoch); | 144 time_t seconds = static_cast<time_t>(seconds_since_epoch); |
| 23 if (seconds != seconds_since_epoch) return false; | 145 if (seconds != seconds_since_epoch) return false; |
| 24 struct tm* error_code = localtime_r(&seconds, tm_result); | 146 struct tm* error_code = localtime_r(&seconds, tm_result); |
| 25 return error_code != NULL; | 147 return error_code != NULL; |
| 26 } | 148 } |
| 27 | 149 |
| 28 | 150 |
| 29 const char* OS::GetTimeZoneName(int64_t seconds_since_epoch) { | 151 const char* OS::GetTimeZoneName(int64_t seconds_since_epoch) { |
| 30 tm decomposed; | 152 tm decomposed; |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 (str[i + 1] == 'x' || str[i + 1] == 'X') && | 314 (str[i + 1] == 'x' || str[i + 1] == 'X') && |
| 193 (str[i + 2] != '\0')) { | 315 (str[i + 2] != '\0')) { |
| 194 base = 16; | 316 base = 16; |
| 195 } | 317 } |
| 196 errno = 0; | 318 errno = 0; |
| 197 *value = strtoll(str, &endptr, base); | 319 *value = strtoll(str, &endptr, base); |
| 198 return ((errno == 0) && (endptr != str) && (*endptr == 0)); | 320 return ((errno == 0) && (endptr != str) && (*endptr == 0)); |
| 199 } | 321 } |
| 200 | 322 |
| 201 | 323 |
| 324 void OS::RegisterCodeObservers() { | |
| 325 if (FLAG_generate_perf_events_symbols) { | |
| 326 CodeObservers::Register(new PerfCodeObserver); | |
| 327 } | |
| 328 if (FLAG_generate_gdb_symbols) { | |
| 329 CodeObservers::Register(new GdbCodeObserver); | |
| 330 } | |
| 331 CodeObservers::Register(new PprofCodeObserver); | |
| 332 #if defined(DART_VTUNE_SUPPORT) | |
| 333 Register(new VTuneCodeObserver); | |
| 334 #endif | |
| 335 } | |
|
siva
2012/12/14 19:13:40
You need to add the same setup to os_android.cc al
Max Heinritz (Google)
2012/12/14 19:59:47
Done.
| |
| 336 | |
| 337 | |
| 202 void OS::PrintErr(const char* format, ...) { | 338 void OS::PrintErr(const char* format, ...) { |
| 203 va_list args; | 339 va_list args; |
| 204 va_start(args, format); | 340 va_start(args, format); |
| 205 VFPrint(stderr, format, args); | 341 VFPrint(stderr, format, args); |
| 206 va_end(args); | 342 va_end(args); |
| 207 } | 343 } |
| 208 | 344 |
| 209 | 345 |
| 210 void OS::InitOnce() { | 346 void OS::InitOnce() { |
| 211 // TODO(5411554): For now we check that initonce is called only once, | 347 // TODO(5411554): For now we check that initonce is called only once, |
| 212 // Once there is more formal mechanism to call InitOnce we can move | 348 // Once there is more formal mechanism to call InitOnce we can move |
| 213 // this check there. | 349 // this check there. |
| 214 static bool init_once_called = false; | 350 static bool init_once_called = false; |
| 215 ASSERT(init_once_called == false); | 351 ASSERT(init_once_called == false); |
| 216 init_once_called = true; | 352 init_once_called = true; |
| 217 } | 353 } |
| 218 | 354 |
| 219 | 355 |
| 220 void OS::Shutdown() { | 356 void OS::Shutdown() { |
| 221 } | 357 } |
| 222 | 358 |
| 223 | 359 |
| 224 void OS::Abort() { | 360 void OS::Abort() { |
| 225 abort(); | 361 abort(); |
| 226 } | 362 } |
| 227 | 363 |
| 228 | 364 |
| 229 void OS::Exit(int code) { | 365 void OS::Exit(int code) { |
| 366 CodeObservers::DeleteAll(); | |
| 230 exit(code); | 367 exit(code); |
| 231 } | 368 } |
| 232 | 369 |
| 233 } // namespace dart | 370 } // namespace dart |
| OLD | NEW |