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

Side by Side Diff: pkg/stack_trace/lib/src/trace.dart

Issue 14647003: Be lazier when capturing stack traces. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 7 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
« no previous file with comments | « pkg/stack_trace/lib/src/lazy_trace.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 trace; 5 library trace;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:uri'; 8 import 'dart:uri';
9 import 'dart:math' as math; 9 import 'dart:math' as math;
10 10
11 import 'frame.dart'; 11 import 'frame.dart';
12 import 'lazy_trace.dart';
12 13
13 final _patchRegExp = new RegExp(r"-patch$"); 14 final _patchRegExp = new RegExp(r"-patch$");
14 15
15 /// A stack trace, comprised of a list of stack frames. 16 /// A stack trace, comprised of a list of stack frames.
16 class Trace implements StackTrace { 17 class Trace implements StackTrace {
17 /// The stack frames that comprise this stack trace. 18 /// The stack frames that comprise this stack trace.
18 final List<Frame> frames; 19 final List<Frame> frames;
19 20
20 /// Returns a human-readable representation of [stackTrace]. If [terse] is 21 /// Returns a human-readable representation of [stackTrace]. If [terse] is
21 /// set, this folds together multiple stack frames from the Dart core 22 /// set, this folds together multiple stack frames from the Dart core
(...skipping 13 matching lines...) Expand all
35 factory Trace.current([int level=0]) { 36 factory Trace.current([int level=0]) {
36 if (level < 0) { 37 if (level < 0) {
37 throw new ArgumentError("Argument [level] must be greater than or equal " 38 throw new ArgumentError("Argument [level] must be greater than or equal "
38 "to 0."); 39 "to 0.");
39 } 40 }
40 41
41 try { 42 try {
42 throw ''; 43 throw '';
43 } catch (_, nativeTrace) { 44 } catch (_, nativeTrace) {
44 var trace = new Trace.from(nativeTrace); 45 var trace = new Trace.from(nativeTrace);
45 return new Trace(trace.frames.skip(level + 1)); 46 return new LazyTrace(() => trace.frames.skip(level + 1));
46 } 47 }
47 } 48 }
48 49
49 /// Returns a new stack trace containing the same data as [trace]. 50 /// Returns a new stack trace containing the same data as [trace].
50 /// 51 ///
51 /// If [trace] is a native [StackTrace], its data will be parsed out; if it's 52 /// If [trace] is a native [StackTrace], its data will be parsed out; if it's
52 /// a [Trace], it will be returned as-is. 53 /// a [Trace], it will be returned as-is.
53 factory Trace.from(StackTrace trace) { 54 factory Trace.from(StackTrace trace) {
54 if (trace is Trace) return trace; 55 if (trace is Trace) return trace;
55 return new Trace.parse(trace.toString()); 56 return new LazyTrace(() => Trace.parse(trace.toString()));
56 } 57 }
57 58
58 /// Parses a string representation of a stack trace. 59 /// Parses a string representation of a stack trace.
59 /// 60 ///
60 /// [trace] should be formatted in the same way as native stack traces. 61 /// [trace] should be formatted in the same way as native stack traces.
61 Trace.parse(String trace) 62 Trace.parse(String trace)
62 : this(trace.trim().split("\n").map((line) => new Frame.parse(line))); 63 : this(trace.trim().split("\n").map((line) => new Frame.parse(line)));
63 64
64 /// Returns a new [Trace] comprised of [frames]. 65 /// Returns a new [Trace] comprised of [frames].
65 Trace(Iterable<Frame> frames) 66 Trace(Iterable<Frame> frames)
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 if (string.length >= length) return string; 133 if (string.length >= length) return string;
133 134
134 var result = new StringBuffer(); 135 var result = new StringBuffer();
135 result.write(string); 136 result.write(string);
136 for (var i = 0; i < length - string.length; i++) { 137 for (var i = 0; i < length - string.length; i++) {
137 result.write(' '); 138 result.write(' ');
138 } 139 }
139 140
140 return result.toString(); 141 return result.toString();
141 } 142 }
OLDNEW
« no previous file with comments | « pkg/stack_trace/lib/src/lazy_trace.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698