| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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/timer.h" | 5 #include "vm/timer.h" |
| 6 #include "vm/json_stream.h" | 6 #include "vm/json_stream.h" |
| 7 | 7 |
| 8 namespace dart { | 8 namespace dart { |
| 9 | 9 |
| 10 // Define timer command line flags. | 10 // Define timer command line flags. |
| 11 #define DEFINE_TIMER_FLAG(name, msg) \ | 11 #define DEFINE_TIMER_FLAG(name, msg) \ |
| 12 DEFINE_FLAG(bool, name, false, ""#name); | 12 DEFINE_FLAG(bool, name, false, ""#name); |
| 13 TIMER_LIST(DEFINE_TIMER_FLAG) | 13 TIMER_LIST(DEFINE_TIMER_FLAG) |
| 14 #undef DEFINE_TIMER_FLAG | 14 #undef DEFINE_TIMER_FLAG |
| 15 DEFINE_FLAG(bool, time_all, false, "Time all functionality"); | 15 DEFINE_FLAG(bool, time_all, false, "Time all functionality"); |
| 16 | 16 |
| 17 | 17 |
| 18 // Maintains a list of timers per isolate. | 18 // Maintains a list of timers per isolate. |
| 19 #define INIT_TIMERS(name, msg) \ | 19 #define INIT_TIMERS(name, msg) \ |
| 20 name##_((FLAG_##name || FLAG_time_all), msg), | 20 name##_((FLAG_##name || FLAG_time_all), msg), |
| 21 TimerList::TimerList() | 21 TimerList::TimerList() |
| 22 : TIMER_LIST(INIT_TIMERS) | 22 : TIMER_LIST(INIT_TIMERS) |
| 23 padding_(false) { | 23 padding_(false) { |
| 24 } | 24 } |
| 25 #undef INIT_TIMERS | 25 #undef INIT_TIMERS |
| 26 | 26 |
| 27 | 27 |
| 28 #define TIMER_FIELD_REPORT(name, msg) \ | 28 #define TIMER_FIELD_REPORT(name, msg) \ |
| 29 if (name().report() && name().message() != NULL) { \ | 29 if (name().report() && name().message() != NULL) { \ |
| 30 OS::Print("%s : %" Pd64 " micros.\n", \ | 30 OS::Print("%s : %" Pd64 " micros.\n", \ |
| 31 name().message(), \ | 31 name().message(), \ |
| 32 name().TotalElapsedTime()); \ | 32 name().TotalElapsedTime()); \ |
| 33 } | 33 } |
| 34 void TimerList::ReportTimers() { | 34 void TimerList::ReportTimers() { |
| 35 TIMER_LIST(TIMER_FIELD_REPORT); | 35 TIMER_LIST(TIMER_FIELD_REPORT); |
| 36 } | 36 } |
| 37 #undef TIMER_FIELD_REPORT | 37 #undef TIMER_FIELD_REPORT |
| 38 | 38 |
| 39 | 39 |
| 40 #define JSON_TIMER(name, msg) \ | 40 #define JSON_TIMER(name, msg) \ |
| 41 { \ | 41 { \ |
| 42 JSONObject jsobj(&jsarr); \ | 42 JSONObject jsobj(&jsarr); \ |
| 43 jsobj.AddProperty("name", #name); \ | 43 jsobj.AddProperty("name", #name); \ |
| 44 double seconds = static_cast<double>(name().TotalElapsedTime()) / \ | 44 double seconds = static_cast<double>(name().TotalElapsedTime()) / \ |
| 45 static_cast<double>(kMicrosecondsPerSecond); \ | 45 static_cast<double>(kMicrosecondsPerSecond); \ |
| 46 jsobj.AddProperty("time", seconds); \ | 46 jsobj.AddProperty("time", seconds); \ |
| 47 } | 47 } |
| 48 void TimerList::PrintTimersToJSONProperty(JSONObject* jsobj) { | 48 void TimerList::PrintTimersToJSONProperty(JSONObject* jsobj) { |
| 49 JSONArray jsarr(jsobj, "timers"); | 49 JSONArray jsarr(jsobj, "timers"); |
| 50 TIMER_LIST(JSON_TIMER); | 50 TIMER_LIST(JSON_TIMER); |
| 51 } | 51 } |
| 52 #undef JSON_TIMER | 52 #undef JSON_TIMER |
| 53 | 53 |
| 54 } // namespace dart | 54 } // namespace dart |
| OLD | NEW |