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

Side by Side Diff: base/trace_event/memory_profiler_allocation_context_unittest.cc

Issue 1419633004: [Tracing] Introduce HeapDumpWriter helper class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove WriteStackFrames, DISALLOW_COPY_AND_ASSIGN Created 5 years, 2 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/trace_event/memory_profiler_allocation_context.h" 5 #include "base/trace_event/memory_profiler_allocation_context.h"
6 #include "base/trace_event/trace_event.h" 6 #include "base/trace_event/trace_event.h"
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 8
9 namespace base { 9 namespace base {
10 namespace trace_event { 10 namespace trace_event {
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 } 224 }
225 225
226 { 226 {
227 AllocationContext ctx = AllocationContextTracker::GetContextSnapshot(); 227 AllocationContext ctx = AllocationContextTracker::GetContextSnapshot();
228 ASSERT_EQ(kCupcake, ctx.backtrace.frames[0]); 228 ASSERT_EQ(kCupcake, ctx.backtrace.frames[0]);
229 ASSERT_EQ(kFroyo, ctx.backtrace.frames[11]); 229 ASSERT_EQ(kFroyo, ctx.backtrace.frames[11]);
230 } 230 }
231 } 231 }
232 232
233 TEST_F(StackFrameDeduplicatorTest, SingleBacktrace) { 233 TEST_F(StackFrameDeduplicatorTest, SingleBacktrace) {
234 AllocationContext::Backtrace bt = { 234 Backtrace bt = {
Primiano Tucci (use gerrit) 2015/10/26 11:52:06 If the problem is breaking lines here you can just
Ruud van Asseldonk 2015/10/26 14:51:26 That is what I did at first but then I though I mi
235 {kBrowserMain, kCreateWidget, kMalloc, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; 235 {kBrowserMain, kCreateWidget, kMalloc, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
236 236
237 // The call tree should look like this (index in brackets). 237 // The call tree should look like this (index in brackets).
238 // 238 //
239 // BrowserMain [0] 239 // BrowserMain [0]
240 // + CreateWidget [1] 240 // + CreateWidget [1]
241 // + malloc [2] 241 // + malloc [2]
242 242
243 StackFrameDeduplicator dedup; 243 StackFrameDeduplicator dedup;
244 ASSERT_EQ(2, dedup.Insert(bt)); 244 ASSERT_EQ(2, dedup.Insert(bt));
245 245
246 auto iter = dedup.begin(); 246 auto iter = dedup.begin();
247 ASSERT_EQ(kBrowserMain, (iter + 0)->frame); 247 ASSERT_EQ(kBrowserMain, (iter + 0)->frame);
248 ASSERT_EQ(-1, (iter + 0)->parent_frame_index); 248 ASSERT_EQ(-1, (iter + 0)->parent_frame_index);
249 249
250 ASSERT_EQ(kCreateWidget, (iter + 1)->frame); 250 ASSERT_EQ(kCreateWidget, (iter + 1)->frame);
251 ASSERT_EQ(0, (iter + 1)->parent_frame_index); 251 ASSERT_EQ(0, (iter + 1)->parent_frame_index);
252 252
253 ASSERT_EQ(kMalloc, (iter + 2)->frame); 253 ASSERT_EQ(kMalloc, (iter + 2)->frame);
254 ASSERT_EQ(1, (iter + 2)->parent_frame_index); 254 ASSERT_EQ(1, (iter + 2)->parent_frame_index);
255 255
256 ASSERT_EQ(iter + 3, dedup.end()); 256 ASSERT_EQ(iter + 3, dedup.end());
257 } 257 }
258 258
259 // Test that there can be different call trees (there can be multiple bottom 259 // Test that there can be different call trees (there can be multiple bottom
260 // frames). Also verify that frames with the same name but a different caller 260 // frames). Also verify that frames with the same name but a different caller
261 // are represented as distinct nodes. 261 // are represented as distinct nodes.
262 TEST_F(StackFrameDeduplicatorTest, MultipleRoots) { 262 TEST_F(StackFrameDeduplicatorTest, MultipleRoots) {
263 AllocationContext::Backtrace bt0 = { 263 Backtrace bt0 = {{kBrowserMain, kCreateWidget, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
264 {kBrowserMain, kCreateWidget, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; 264 Backtrace bt1 = {{kRendererMain, kCreateWidget, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
265 AllocationContext::Backtrace bt1 = {
266 {kRendererMain, kCreateWidget, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
267 265
268 // The call tree should look like this (index in brackets). 266 // The call tree should look like this (index in brackets).
269 // 267 //
270 // BrowserMain [0] 268 // BrowserMain [0]
271 // + CreateWidget [1] 269 // + CreateWidget [1]
272 // RendererMain [2] 270 // RendererMain [2]
273 // + CreateWidget [3] 271 // + CreateWidget [3]
274 // 272 //
275 // Note that there will be two instances of Donut, with different parents. 273 // Note that there will be two instances of Donut, with different parents.
276 274
(...skipping 11 matching lines...) Expand all
288 ASSERT_EQ(kRendererMain, (iter + 2)->frame); 286 ASSERT_EQ(kRendererMain, (iter + 2)->frame);
289 ASSERT_EQ(-1, (iter + 2)->parent_frame_index); 287 ASSERT_EQ(-1, (iter + 2)->parent_frame_index);
290 288
291 ASSERT_EQ(kCreateWidget, (iter + 3)->frame); 289 ASSERT_EQ(kCreateWidget, (iter + 3)->frame);
292 ASSERT_EQ(2, (iter + 3)->parent_frame_index); 290 ASSERT_EQ(2, (iter + 3)->parent_frame_index);
293 291
294 ASSERT_EQ(iter + 4, dedup.end()); 292 ASSERT_EQ(iter + 4, dedup.end());
295 } 293 }
296 294
297 TEST_F(StackFrameDeduplicatorTest, Deduplication) { 295 TEST_F(StackFrameDeduplicatorTest, Deduplication) {
298 AllocationContext::Backtrace bt0 = { 296 Backtrace bt0 = {{kBrowserMain, kCreateWidget, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
299 {kBrowserMain, kCreateWidget, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}; 297 Backtrace bt1 = {{kBrowserMain, kInitialize, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
300 AllocationContext::Backtrace bt1 = {
301 {kBrowserMain, kInitialize, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}};
302 298
303 // The call tree should look like this (index in brackets). 299 // The call tree should look like this (index in brackets).
304 // 300 //
305 // BrowserMain [0] 301 // BrowserMain [0]
306 // + CreateWidget [1] 302 // + CreateWidget [1]
307 // + Initialize [2] 303 // + Initialize [2]
308 // 304 //
309 // Note that Cupcake will be re-used. 305 // Note that Cupcake will be re-used.
310 306
311 StackFrameDeduplicator dedup; 307 StackFrameDeduplicator dedup;
(...skipping 14 matching lines...) Expand all
326 322
327 // Inserting the same backtrace again should return the index of the existing 323 // Inserting the same backtrace again should return the index of the existing
328 // node. 324 // node.
329 ASSERT_EQ(1, dedup.Insert(bt0)); 325 ASSERT_EQ(1, dedup.Insert(bt0));
330 ASSERT_EQ(2, dedup.Insert(bt1)); 326 ASSERT_EQ(2, dedup.Insert(bt1));
331 ASSERT_EQ(dedup.begin() + 3, dedup.end()); 327 ASSERT_EQ(dedup.begin() + 3, dedup.end());
332 } 328 }
333 329
334 } // namespace trace_event 330 } // namespace trace_event
335 } // namespace base 331 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698