| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 library observatory_element; | 5 library observatory_element; |
| 6 | 6 |
| 7 import 'dart:math'; | 7 import 'package:observatory/app.dart'; |
| 8 import 'package:polymer/polymer.dart'; | 8 import 'package:polymer/polymer.dart'; |
| 9 | 9 |
| 10 /// Base class for all Observatory custom elements. | 10 /// Base class for all Observatory custom elements. |
| 11 @CustomTag('observatory-element') | 11 @CustomTag('observatory-element') |
| 12 class ObservatoryElement extends PolymerElement { | 12 class ObservatoryElement extends PolymerElement { |
| 13 ObservatoryElement.created() : super.created(); | 13 ObservatoryElement.created() : super.created(); |
| 14 | 14 |
| 15 void enteredView() { | 15 void enteredView() { |
| 16 super.enteredView(); | 16 super.enteredView(); |
| 17 } | 17 } |
| 18 | 18 |
| 19 void leftView() { | 19 void leftView() { |
| 20 super.leftView(); | 20 super.leftView(); |
| 21 } | 21 } |
| 22 | 22 |
| 23 void attributeChanged(String name, var oldValue, var newValue) { | 23 void attributeChanged(String name, var oldValue, var newValue) { |
| 24 super.attributeChanged(name, oldValue, newValue); | 24 super.attributeChanged(name, oldValue, newValue); |
| 25 } | 25 } |
| 26 | 26 |
| 27 bool get applyAuthorStyles => true; | 27 String formatTimePrecise(double time) => Utils.formatTimePrecise(time); |
| 28 | 28 |
| 29 static String _zeroPad(int value, int pad) { | 29 String formatTime(double time) => Utils.formatTime(time); |
| 30 String prefix = ""; | |
| 31 while (pad > 1) { | |
| 32 int pow10 = pow(10, pad - 1); | |
| 33 if (value < pow10) { | |
| 34 prefix = prefix + "0"; | |
| 35 } | |
| 36 pad--; | |
| 37 } | |
| 38 return "${prefix}${value}"; | |
| 39 } | |
| 40 | 30 |
| 41 String formatTimePrecise(double time) { | 31 String formatSeconds(double x) => Utils.formatSeconds(x); |
| 42 if (time == null) { | |
| 43 return "-"; | |
| 44 } | |
| 45 const millisPerHour = 60 * 60 * 1000; | |
| 46 const millisPerMinute = 60 * 1000; | |
| 47 const millisPerSecond = 1000; | |
| 48 | |
| 49 var millis = (time * millisPerSecond).round(); | |
| 50 | |
| 51 var hours = millis ~/ millisPerHour; | |
| 52 millis = millis % millisPerHour; | |
| 53 | |
| 54 var minutes = millis ~/ millisPerMinute; | |
| 55 millis = millis % millisPerMinute; | |
| 56 | |
| 57 var seconds = millis ~/ millisPerSecond; | |
| 58 millis = millis % millisPerSecond; | |
| 59 | |
| 60 return ("${_zeroPad(hours,2)}" | |
| 61 ":${_zeroPad(minutes,2)}" | |
| 62 ":${_zeroPad(seconds,2)}" | |
| 63 ".${_zeroPad(millis,3)}"); | |
| 64 | |
| 65 } | |
| 66 | |
| 67 String formatTime(double time) { | |
| 68 if (time == null) { | |
| 69 return "-"; | |
| 70 } | |
| 71 const millisPerHour = 60 * 60 * 1000; | |
| 72 const millisPerMinute = 60 * 1000; | |
| 73 const millisPerSecond = 1000; | |
| 74 | |
| 75 var millis = (time * millisPerSecond).round(); | |
| 76 | |
| 77 var hours = millis ~/ millisPerHour; | |
| 78 millis = millis % millisPerHour; | |
| 79 | |
| 80 var minutes = millis ~/ millisPerMinute; | |
| 81 millis = millis % millisPerMinute; | |
| 82 | |
| 83 var seconds = millis ~/ millisPerSecond; | |
| 84 | |
| 85 StringBuffer out = new StringBuffer(); | |
| 86 if (hours != 0) { | |
| 87 return '${hours}h ${minutes}m ${seconds}s'; | |
| 88 } | |
| 89 if (minutes != 0) { | |
| 90 return '${minutes}m ${seconds}s'; | |
| 91 } | |
| 92 return '${seconds}s'; | |
| 93 } | |
| 94 | |
| 95 String formatSeconds(double x) { | |
| 96 return x.toStringAsFixed(2); | |
| 97 } | |
| 98 | 32 |
| 99 | 33 |
| 100 String formatSize(int bytes) { | 34 String formatSize(int bytes) => Utils.formatSize(bytes); |
| 101 const int bytesPerKB = 1024; | |
| 102 const int bytesPerMB = 1024 * bytesPerKB; | |
| 103 const int bytesPerGB = 1024 * bytesPerMB; | |
| 104 const int bytesPerTB = 1024 * bytesPerGB; | |
| 105 | |
| 106 if (bytes < bytesPerKB) { | |
| 107 return "${bytes}B"; | |
| 108 } else if (bytes < bytesPerMB) { | |
| 109 return "${(bytes / bytesPerKB).round()}KB"; | |
| 110 } else if (bytes < bytesPerGB) { | |
| 111 return "${(bytes / bytesPerMB).round()}MB"; | |
| 112 } else if (bytes < bytesPerTB) { | |
| 113 return "${(bytes / bytesPerGB).round()}GB"; | |
| 114 } else { | |
| 115 return "${(bytes / bytesPerTB).round()}TB"; | |
| 116 } | |
| 117 } | |
| 118 | 35 |
| 119 String fileAndLine(Map frame) { | 36 String fileAndLine(Map frame) { |
| 120 var file = frame['script']['user_name']; | 37 var file = frame['script']['user_name']; |
| 121 var shortFile = file.substring(file.lastIndexOf('/') + 1); | 38 var shortFile = file.substring(file.lastIndexOf('/') + 1); |
| 122 return "${shortFile}:${frame['line']}"; | 39 return "${shortFile}:${frame['line']}"; |
| 123 } | 40 } |
| 124 | 41 |
| 125 bool isNull(String type) { | 42 bool isNull(String type) { |
| 126 return type == 'Null'; | 43 return type == 'Null'; |
| 127 } | 44 } |
| 128 | 45 |
| 129 bool isError(String type) { | 46 bool isError(String type) { |
| 130 return type == 'Error'; | 47 return type == 'Error'; |
| 131 } | 48 } |
| 132 | 49 |
| 133 bool isInt(String type) { | 50 bool isInt(String type) { |
| 134 return (type == 'Smi' || | 51 return (type == 'Smi' || |
| 135 type == 'Mint' || | 52 type == 'Mint' || |
| 136 type == 'Bigint'); | 53 type == 'Bigint'); |
| 137 } | 54 } |
| 138 | 55 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 169 'Bool', | 86 'Bool', |
| 170 'String', | 87 'String', |
| 171 'Double', | 88 'Double', |
| 172 'Instance', | 89 'Instance', |
| 173 'GrowableObjectArray', | 90 'GrowableObjectArray', |
| 174 'Array', | 91 'Array', |
| 175 'Type', | 92 'Type', |
| 176 'Error'].contains(type)); | 93 'Error'].contains(type)); |
| 177 } | 94 } |
| 178 } | 95 } |
| OLD | NEW |