| 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 'dart:math'; |
| 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. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 var seconds = millis ~/ millisPerSecond; | 57 var seconds = millis ~/ millisPerSecond; |
| 58 millis = millis % millisPerSecond; | 58 millis = millis % millisPerSecond; |
| 59 | 59 |
| 60 return ("${_zeroPad(hours,2)}" | 60 return ("${_zeroPad(hours,2)}" |
| 61 ":${_zeroPad(minutes,2)}" | 61 ":${_zeroPad(minutes,2)}" |
| 62 ":${_zeroPad(seconds,2)}" | 62 ":${_zeroPad(seconds,2)}" |
| 63 ".${_zeroPad(millis,3)}"); | 63 ".${_zeroPad(millis,3)}"); |
| 64 | 64 |
| 65 } | 65 } |
| 66 | 66 |
| 67 String formatSeconds(double x) { |
| 68 return x.toStringAsFixed(2); |
| 69 } |
| 70 |
| 71 |
| 67 String formatSize(int bytes) { | 72 String formatSize(int bytes) { |
| 68 const int bytesPerKB = 1024; | 73 const int bytesPerKB = 1024; |
| 69 const int bytesPerMB = 1024 * bytesPerKB; | 74 const int bytesPerMB = 1024 * bytesPerKB; |
| 70 const int bytesPerGB = 1024 * bytesPerMB; | 75 const int bytesPerGB = 1024 * bytesPerMB; |
| 71 const int bytesPerTB = 1024 * bytesPerGB; | 76 const int bytesPerTB = 1024 * bytesPerGB; |
| 72 | 77 |
| 73 if (bytes < bytesPerKB) { | 78 if (bytes < bytesPerKB) { |
| 74 return "${bytes}B"; | 79 return "${bytes}B"; |
| 75 } else if (bytes < bytesPerMB) { | 80 } else if (bytes < bytesPerMB) { |
| 76 return "${(bytes / bytesPerKB).round()}KB"; | 81 return "${(bytes / bytesPerKB).round()}KB"; |
| 77 } else if (bytes < bytesPerGB) { | 82 } else if (bytes < bytesPerGB) { |
| 78 return "${(bytes / bytesPerMB).round()}MB"; | 83 return "${(bytes / bytesPerMB).round()}MB"; |
| 79 } else if (bytes < bytesPerTB) { | 84 } else if (bytes < bytesPerTB) { |
| 80 return "${(bytes / bytesPerGB).round()}GB"; | 85 return "${(bytes / bytesPerGB).round()}GB"; |
| 81 } else { | 86 } else { |
| 82 return "${(bytes / bytesPerTB).round()}TB"; | 87 return "${(bytes / bytesPerTB).round()}TB"; |
| 83 } | 88 } |
| 84 } | 89 } |
| 85 | 90 |
| 86 String fileAndLine(Map frame) { | 91 String fileAndLine(Map frame) { |
| 87 var file = frame['script']['user_name']; | 92 var file = frame['script']['user_name']; |
| 88 var shortFile = file.substring(file.lastIndexOf('/') + 1); | 93 var shortFile = file.substring(file.lastIndexOf('/') + 1); |
| 89 return "${shortFile}:${frame['line']}"; | 94 return "${shortFile}:${frame['line']}"; |
| 90 } | 95 } |
| 91 | 96 |
| 92 bool isNullRef(String type) { | 97 bool isNull(String type) { |
| 93 return type == '@Null'; | 98 return type == 'Null'; |
| 94 } | 99 } |
| 95 | 100 |
| 96 bool isIntRef(String type) { | 101 bool isInt(String type) { |
| 97 return (type == '@Smi' || | 102 return (type == 'Smi' || |
| 98 type == '@Mint' || | 103 type == 'Mint' || |
| 99 type == '@Bigint'); | 104 type == 'Bigint'); |
| 100 } | 105 } |
| 101 | 106 |
| 102 bool isBoolRef(String type) { | 107 bool isBool(String type) { |
| 103 return type == '@Bool'; | 108 return type == 'Bool'; |
| 104 } | 109 } |
| 105 | 110 |
| 106 bool isStringRef(String type) { | 111 bool isString(String type) { |
| 107 return type == '@String'; | 112 return type == 'String'; |
| 108 } | 113 } |
| 109 | 114 |
| 110 bool isInstanceRef(String type) { | 115 bool isInstance(String type) { |
| 111 return type == '@Instance'; | 116 return type == 'Instance'; |
| 112 } | 117 } |
| 113 | 118 |
| 114 bool isClosureRef(String type) { | 119 bool isClosure(String type) { |
| 115 return type == '@Closure'; | 120 return type == 'Closure'; |
| 116 } | 121 } |
| 117 | 122 |
| 118 bool isListRef(String type) { | 123 bool isList(String type) { |
| 119 return (type == '@GrowableObjectArray' || | 124 return (type == 'GrowableObjectArray' || |
| 120 type == '@Array'); | 125 type == 'Array'); |
| 121 } | 126 } |
| 122 | 127 |
| 123 bool isUnexpectedRef(String type) { | 128 bool isUnexpected(String type) { |
| 124 return (!['@Null', | 129 return (!['Null', |
| 125 '@Smi', | 130 'Smi', |
| 126 '@Mint', | 131 'Mint', |
| 127 '@Biginit', | 132 'Biginit', |
| 128 '@Bool', | 133 'Bool', |
| 129 '@String', | 134 'String', |
| 130 '@Closure', | 135 'Closure', |
| 131 '@Instance', | 136 'Instance', |
| 132 '@GrowableObjectArray', | 137 'GrowableObjectArray', |
| 133 '@Array'].contains(type)); | 138 'Array'].contains(type)); |
| 134 } | 139 } |
| 135 } | 140 } |
| OLD | NEW |