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