Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(301)

Side by Side Diff: third_party/pkg/perf_api/lib/console_impl.dart

Issue 124053002: Adding Angular and dependent packages for testing (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 library perf_api.console_impl;
2
3 import 'dart:html' as dom;
4 import 'dart:collection';
5 import 'perf_api.dart';
6
7 /**
8 * Simple window.console based implementation.
9 */
10 class ConsoleProfiler extends Profiler {
11 int _timerIds = 0;
12 Map<int, String> _timers = new Map<int, String>();
13 Map<int, String> _timerNames = new LinkedHashMap<int, String>();
14 final dom.Window window;
15
16 ConsoleProfiler() :this.window = dom.window;
17
18 ConsoleProfiler.forWindow(this.window);
19
20 dynamic startTimer(String name, [dynamic extraData]) {
21 var timerId = _timerIds++;
22 _timers[timerId] = _timerName(name, extraData);
23 _timerNames[timerId] = name;
24 window.console.time(_timerStr(timerId, _timers[timerId]));
25 return timerId;
26 }
27
28 String _timerName(String name, dynamic extraData) =>
29 '$name${_stringifyExtraData(extraData)}';
30
31 String _stringifyExtraData(extraData) =>
32 (extraData == null || extraData is! String) ? '' : ' $extraData';
33
34 String _timerStr(id, name) => '${name} ($id)';
35
36 void stopTimer(dynamic idOrName) {
37 int timerId;
38 if (idOrName is int) {
39 timerId = idOrName;
40 } else {
41 // TODO: change this to use a multimap.
42 for (var id in _timerNames.keys) {
43 if (_timerNames[id] == idOrName) {
44 timerId = id;
45 break;
46 }
47 }
48 }
49 if (timerId == null) {
50 throw new ProfilerError('Unable for find timer for $idOrName');
51 }
52 window.console.timeEnd(_timerStr(timerId, _timers[timerId]));
53 _timerNames.remove(timerId);
54 _timers.remove(timerId);
55 }
56
57 void markTime(String name, [dynamic extraData]) {
58 window.console.timeStamp(_timerName(name, extraData));
59 }
60 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698