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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/stack_trace/lib/src/trace.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/stack_trace/lib/src/chain.dart
diff --git a/pkg/stack_trace/lib/src/chain.dart b/pkg/stack_trace/lib/src/chain.dart
index 4055bc847c7e1bb70f229627f4a55b371d7273c4..2500e5ed2715e36f6b71be9d77d7d22d95c24c02 100644
--- a/pkg/stack_trace/lib/src/chain.dart
+++ b/pkg/stack_trace/lib/src/chain.dart
@@ -7,6 +7,7 @@ library stack_trace.chain;
import 'dart:async';
import 'dart:collection';
+import 'frame.dart';
import 'stack_zone_specification.dart';
import 'trace.dart';
import 'utils.dart';
@@ -172,6 +173,32 @@ class Chain implements StackTrace {
return new Chain(nonEmptyTraces);
}
+ /// Returns a new [Chain] based on [this] where multiple stack frames matching
+ /// [predicate] are folded together.
+ ///
+ /// This means that whenever there are multiple frames in a row that match
+ /// [predicate], only the last one is kept. In addition, traces that are
+ /// composed entirely of frames matching [predicate] are omitted.
+ ///
+ /// This is useful for limiting the amount of library code that appears in a
+ /// stack trace by only showing user code and code that's called by user code.
+ Chain foldFrames(bool predicate(Frame frame)) {
+ var foldedTraces = traces.map((trace) => trace.foldFrames(predicate));
+ var nonEmptyTraces = foldedTraces.where((trace) {
+ // Ignore traces that contain only folded frames. These traces will be
+ // folded into a single frame each.
+ return trace.frames.length > 1;
+ });
+
+ // If all the traces contain only internal processing, preserve the last
+ // (top-most) one so that the chain isn't empty.
+ if (nonEmptyTraces.isEmpty && foldedTraces.isNotEmpty) {
+ return new Chain([foldedTraces.last]);
+ }
+
+ return new Chain(nonEmptyTraces);
+ }
+
/// Converts [this] to a [Trace].
///
/// The trace version of a chain is just the concatenation of all the traces
« 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