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