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

Unified Diff: base/trace_event/heap_profiler_stack_frame_deduplicator_unittest.cc

Issue 1891543003: [tracing] Turn StackFrame into struct. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 8 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
Index: base/trace_event/heap_profiler_stack_frame_deduplicator_unittest.cc
diff --git a/base/trace_event/heap_profiler_stack_frame_deduplicator_unittest.cc b/base/trace_event/heap_profiler_stack_frame_deduplicator_unittest.cc
index 72cb743ad0c22162c1804d864de9aae68ea329eb..2215edebb56fd5920eb7ccade2bb103f3dd9f165 100644
--- a/base/trace_event/heap_profiler_stack_frame_deduplicator_unittest.cc
+++ b/base/trace_event/heap_profiler_stack_frame_deduplicator_unittest.cc
@@ -16,11 +16,11 @@ namespace trace_event {
// Define all strings once, because the deduplicator requires pointer equality,
// and string interning is unreliable.
-const char kBrowserMain[] = "BrowserMain";
-const char kRendererMain[] = "RendererMain";
-const char kCreateWidget[] = "CreateWidget";
-const char kInitialize[] = "Initialize";
-const char kMalloc[] = "malloc";
+StackFrame kBrowserMain = StackFrame::FromTraceEventName("BrowserMain");
+StackFrame kRendererMain = StackFrame::FromTraceEventName("RendererMain");
+StackFrame kCreateWidget = StackFrame::FromTraceEventName("CreateWidget");
+StackFrame kInitialize = StackFrame::FromTraceEventName("Initialize");
+StackFrame kMalloc = StackFrame::FromTraceEventName("malloc");
TEST(StackFrameDeduplicatorTest, SingleBacktrace) {
StackFrame bt[] = {kBrowserMain, kCreateWidget, kMalloc};
@@ -47,6 +47,35 @@ TEST(StackFrameDeduplicatorTest, SingleBacktrace) {
ASSERT_EQ(iter + 3, dedup->end());
}
+TEST(StackFrameDeduplicatorTest, SingleBacktraceWithNull) {
Primiano Tucci (use gerrit) 2016/04/19 19:45:06 thanks, really appreciate this :)
Dmitry Skiba 2016/04/19 22:14:14 Acknowledged :)
+ StackFrame null_frame = StackFrame::FromTraceEventName(nullptr);
+ StackFrame bt[] = {kBrowserMain, null_frame, kMalloc};
+
+ // Deduplicator doesn't care about what's inside StackFrames,
+ // and handles nullptr StackFrame values as any other.
+ //
+ // So the call tree should look like this (index in brackets).
+ //
+ // BrowserMain [0]
+ // (null) [1]
+ // malloc [2]
+
+ std::unique_ptr<StackFrameDeduplicator> dedup(new StackFrameDeduplicator);
+ ASSERT_EQ(2, dedup->Insert(std::begin(bt), std::end(bt)));
+
+ auto iter = dedup->begin();
+ ASSERT_EQ(kBrowserMain, (iter + 0)->frame);
+ ASSERT_EQ(-1, (iter + 0)->parent_frame_index);
+
+ ASSERT_EQ(null_frame, (iter + 1)->frame);
+ ASSERT_EQ(0, (iter + 1)->parent_frame_index);
+
+ ASSERT_EQ(kMalloc, (iter + 2)->frame);
+ ASSERT_EQ(1, (iter + 2)->parent_frame_index);
+
+ ASSERT_EQ(iter + 3, dedup->end());
+}
+
// Test that there can be different call trees (there can be multiple bottom
// frames). Also verify that frames with the same name but a different caller
// are represented as distinct nodes.
@@ -119,17 +148,5 @@ TEST(StackFrameDeduplicatorTest, Deduplication) {
ASSERT_EQ(dedup->begin() + 3, dedup->end());
}
-TEST(StackFrameDeduplicatorTest, NullPaddingIsRemoved) {
- StackFrame bt0[] = {kBrowserMain, nullptr, nullptr, nullptr};
-
- std::unique_ptr<StackFrameDeduplicator> dedup(new StackFrameDeduplicator);
-
- // There are four frames in the backtrace, but the null pointers should be
- // skipped, so only one frame is inserted, which will have index 0.
- ASSERT_EQ(4u, arraysize(bt0));
- ASSERT_EQ(0, dedup->Insert(std::begin(bt0), std::end(bt0)));
- ASSERT_EQ(dedup->begin() + 1, dedup->end());
-}
-
} // namespace trace_event
} // namespace base

Powered by Google App Engine
This is Rietveld 408576698