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

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

Issue 180223005: Add Chain.foldFrames to pkg/stack_trace. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 6 years, 10 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 | « no previous file | pkg/stack_trace/lib/src/trace.dart » ('j') | 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 stack_trace.chain; 5 library stack_trace.chain;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import 'frame.dart';
10 import 'stack_zone_specification.dart'; 11 import 'stack_zone_specification.dart';
11 import 'trace.dart'; 12 import 'trace.dart';
12 import 'utils.dart'; 13 import 'utils.dart';
13 14
14 /// A function that handles errors in the zone wrapped by [Chain.capture]. 15 /// A function that handles errors in the zone wrapped by [Chain.capture].
15 typedef void ChainHandler(error, Chain chain); 16 typedef void ChainHandler(error, Chain chain);
16 17
17 /// A chain of stack traces. 18 /// A chain of stack traces.
18 /// 19 ///
19 /// A stack chain is a collection of one or more stack traces that collectively 20 /// A stack chain is a collection of one or more stack traces that collectively
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 166
166 // If all the traces contain only internal processing, preserve the last 167 // If all the traces contain only internal processing, preserve the last
167 // (top-most) one so that the chain isn't empty. 168 // (top-most) one so that the chain isn't empty.
168 if (nonEmptyTraces.isEmpty && terseTraces.isNotEmpty) { 169 if (nonEmptyTraces.isEmpty && terseTraces.isNotEmpty) {
169 return new Chain([terseTraces.last]); 170 return new Chain([terseTraces.last]);
170 } 171 }
171 172
172 return new Chain(nonEmptyTraces); 173 return new Chain(nonEmptyTraces);
173 } 174 }
174 175
176 /// Returns a new [Chain] based on [this] where multiple stack frames matching
177 /// [predicate] are folded together.
178 ///
179 /// This means that whenever there are multiple frames in a row that match
180 /// [predicate], only the last one is kept. In addition, traces that are
181 /// composed entirely of frames matching [predicate] are omitted.
182 ///
183 /// This is useful for limiting the amount of library code that appears in a
184 /// stack trace by only showing user code and code that's called by user code.
185 Chain foldFrames(bool predicate(Frame frame)) {
186 var foldedTraces = traces.map((trace) => trace.foldFrames(predicate));
187 var nonEmptyTraces = foldedTraces.where((trace) {
188 // Ignore traces that contain only folded frames. These traces will be
189 // folded into a single frame each.
190 return trace.frames.length > 1;
191 });
192
193 // If all the traces contain only internal processing, preserve the last
194 // (top-most) one so that the chain isn't empty.
195 if (nonEmptyTraces.isEmpty && foldedTraces.isNotEmpty) {
196 return new Chain([foldedTraces.last]);
197 }
198
199 return new Chain(nonEmptyTraces);
200 }
201
175 /// Converts [this] to a [Trace]. 202 /// Converts [this] to a [Trace].
176 /// 203 ///
177 /// The trace version of a chain is just the concatenation of all the traces 204 /// The trace version of a chain is just the concatenation of all the traces
178 /// in the chain. 205 /// in the chain.
179 Trace toTrace() => new Trace(flatten(traces.map((trace) => trace.frames))); 206 Trace toTrace() => new Trace(flatten(traces.map((trace) => trace.frames)));
180 207
181 String toString() => traces.join(_GAP); 208 String toString() => traces.join(_GAP);
182 } 209 }
OLDNEW
« no previous file with comments | « no previous file | pkg/stack_trace/lib/src/trace.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698