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

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

Issue 1717283003: tracing: Make ConvertableToTraceFormat move-only scoped_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 9 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 9
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
14 #include "base/trace_event/heap_profiler_allocation_context.h" 13 #include "base/trace_event/heap_profiler_allocation_context.h"
15 #include "base/trace_event/heap_profiler_heap_dump_writer.h" 14 #include "base/trace_event/heap_profiler_heap_dump_writer.h"
16 #include "base/trace_event/heap_profiler_stack_frame_deduplicator.h" 15 #include "base/trace_event/heap_profiler_stack_frame_deduplicator.h"
17 #include "base/trace_event/heap_profiler_type_name_deduplicator.h" 16 #include "base/trace_event/heap_profiler_type_name_deduplicator.h"
18 #include "base/trace_event/trace_event_argument.h" 17 #include "base/trace_event/trace_event_argument.h"
19 #include "base/values.h" 18 #include "base/values.h"
20 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
21 20
22 namespace { 21 namespace {
(...skipping 10 matching lines...) Expand all
33 const char kBool[] = "bool"; 32 const char kBool[] = "bool";
34 const char kString[] = "string"; 33 const char kString[] = "string";
35 34
36 } // namespace 35 } // namespace
37 36
38 namespace base { 37 namespace base {
39 namespace trace_event { 38 namespace trace_event {
40 namespace internal { 39 namespace internal {
41 40
42 scoped_ptr<const Value> WriteAndReadBack(const std::set<Entry>& entries) { 41 scoped_ptr<const Value> WriteAndReadBack(const std::set<Entry>& entries) {
43 scoped_refptr<TracedValue> traced_value = Serialize(entries); 42 scoped_ptr<TracedValue> traced_value = Serialize(entries);
44 std::string json; 43 std::string json;
45 traced_value->AppendAsTraceFormat(&json); 44 traced_value->AppendAsTraceFormat(&json);
46 return JSONReader::Read(json); 45 return JSONReader::Read(json);
47 } 46 }
48 47
49 scoped_ptr<const DictionaryValue> WriteAndReadBackEntry(Entry entry) { 48 scoped_ptr<const DictionaryValue> WriteAndReadBackEntry(Entry entry) {
50 std::set<Entry> input_entries; 49 std::set<Entry> input_entries;
51 input_entries.insert(entry); 50 input_entries.insert(entry);
52 51
53 scoped_ptr<const Value> json_dict = WriteAndReadBack(input_entries); 52 scoped_ptr<const Value> json_dict = WriteAndReadBack(input_entries);
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 // At this point the heap looks like this: 190 // At this point the heap looks like this:
192 // 191 //
193 // | | CrWidget <- BrMain | Init <- RenMain | Sum | 192 // | | CrWidget <- BrMain | Init <- RenMain | Sum |
194 // +--------+--------------------+-----------------+-----+ 193 // +--------+--------------------+-----------------+-----+
195 // | int | 10 | 0 | 10 | 194 // | int | 10 | 0 | 10 |
196 // | bool | 18 | 30 | 48 | 195 // | bool | 18 | 30 | 48 |
197 // | string | 0 | 19 | 19 | 196 // | string | 0 | 19 | 19 |
198 // +--------+--------------------+-----------------+-----+ 197 // +--------+--------------------+-----------------+-----+
199 // | Sum | 28 | 49 | 77 | 198 // | Sum | 28 | 49 | 77 |
200 199
201 auto sf_deduplicator = make_scoped_refptr(new StackFrameDeduplicator); 200 auto sf_deduplicator = make_scoped_ptr(new StackFrameDeduplicator);
202 auto tn_deduplicator = make_scoped_refptr(new TypeNameDeduplicator); 201 auto tn_deduplicator = make_scoped_ptr(new TypeNameDeduplicator);
203 HeapDumpWriter writer(sf_deduplicator.get(), tn_deduplicator.get()); 202 HeapDumpWriter writer(sf_deduplicator.get(), tn_deduplicator.get());
204 const std::set<Entry>& dump = writer.Summarize(bytes_by_context); 203 const std::set<Entry>& dump = writer.Summarize(bytes_by_context);
205 204
206 // Get the indices of the backtraces and types by adding them again to the 205 // Get the indices of the backtraces and types by adding them again to the
207 // deduplicator. Because they were added before, the same number is returned. 206 // deduplicator. Because they were added before, the same number is returned.
208 StackFrame bt0[] = {kRendererMain, kInitialize}; 207 StackFrame bt0[] = {kRendererMain, kInitialize};
209 StackFrame bt1[] = {kBrowserMain, kCreateWidget}; 208 StackFrame bt1[] = {kBrowserMain, kCreateWidget};
210 int bt_renderer_main = sf_deduplicator->Insert(bt0, bt0 + 1); 209 int bt_renderer_main = sf_deduplicator->Insert(bt0, bt0 + 1);
211 int bt_browser_main = sf_deduplicator->Insert(bt1, bt1 + 1); 210 int bt_browser_main = sf_deduplicator->Insert(bt1, bt1 + 1);
212 int bt_renderer_main_initialize = sf_deduplicator->Insert(bt0, bt0 + 2); 211 int bt_renderer_main_initialize = sf_deduplicator->Insert(bt0, bt0 + 2);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 bytes_by_context[ctx] = 512; 255 bytes_by_context[ctx] = 512;
257 256
258 // 1 MiB in BrowserMain -> CreateWidget -> GetBitmap. 257 // 1 MiB in BrowserMain -> CreateWidget -> GetBitmap.
259 ctx.backtrace.frames[2] = kGetBitmap; 258 ctx.backtrace.frames[2] = kGetBitmap;
260 bytes_by_context[ctx] = 1024 * 1024; 259 bytes_by_context[ctx] = 1024 * 1024;
261 260
262 // 0.5 KiB in BrowserMain -> CreateWidget -> Initialize. 261 // 0.5 KiB in BrowserMain -> CreateWidget -> Initialize.
263 ctx.backtrace.frames[2] = kInitialize; 262 ctx.backtrace.frames[2] = kInitialize;
264 bytes_by_context[ctx] = 512; 263 bytes_by_context[ctx] = 512;
265 264
266 auto sf_deduplicator = make_scoped_refptr(new StackFrameDeduplicator); 265 auto sf_deduplicator = make_scoped_ptr(new StackFrameDeduplicator);
267 auto tn_deduplicator = make_scoped_refptr(new TypeNameDeduplicator); 266 auto tn_deduplicator = make_scoped_ptr(new TypeNameDeduplicator);
268 HeapDumpWriter writer(sf_deduplicator.get(), tn_deduplicator.get()); 267 HeapDumpWriter writer(sf_deduplicator.get(), tn_deduplicator.get());
269 const std::set<Entry>& dump = writer.Summarize(bytes_by_context); 268 const std::set<Entry>& dump = writer.Summarize(bytes_by_context);
270 269
271 // Get the indices of the backtraces and types by adding them again to the 270 // Get the indices of the backtraces and types by adding them again to the
272 // deduplicator. Because they were added before, the same number is returned. 271 // deduplicator. Because they were added before, the same number is returned.
273 StackFrame bt0[] = {kBrowserMain, kCreateWidget, kGetBitmap}; 272 StackFrame bt0[] = {kBrowserMain, kCreateWidget, kGetBitmap};
274 StackFrame bt1[] = {kBrowserMain, kCreateWidget, kInitialize}; 273 StackFrame bt1[] = {kBrowserMain, kCreateWidget, kInitialize};
275 int bt_browser_main = sf_deduplicator->Insert(bt0, bt0 + 1); 274 int bt_browser_main = sf_deduplicator->Insert(bt0, bt0 + 1);
276 int bt_create_widget = sf_deduplicator->Insert(bt0, bt0 + 2); 275 int bt_create_widget = sf_deduplicator->Insert(bt0, bt0 + 2);
277 int bt_get_bitmap = sf_deduplicator->Insert(bt0, bt0 + 3); 276 int bt_get_bitmap = sf_deduplicator->Insert(bt0, bt0 + 3);
(...skipping 11 matching lines...) Expand all
289 AssertSizeEq(dump, bt_create_widget, -1, 1024 * 1024 + 512 + 512); 288 AssertSizeEq(dump, bt_create_widget, -1, 1024 * 1024 + 512 + 512);
290 AssertSizeEq(dump, bt_browser_main, -1, 1024 * 1024 + 512 + 512); 289 AssertSizeEq(dump, bt_browser_main, -1, 1024 * 1024 + 512 + 512);
291 290
292 // Initialize was not significant, it should not have been dumped. 291 // Initialize was not significant, it should not have been dumped.
293 AssertNotDumped(dump, bt_initialize, -1); 292 AssertNotDumped(dump, bt_initialize, -1);
294 } 293 }
295 294
296 } // namespace internal 295 } // namespace internal
297 } // namespace trace_event 296 } // namespace trace_event
298 } // namespace base 297 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698