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

Side by Side Diff: ui/android/resources/resource_manager_impl.cc

Issue 2440393002: [tracing] Implement composable memory usage estimators. (Closed)
Patch Set: Rebase Created 4 years, 1 month 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
« no previous file with comments | « ui/android/resources/resource_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "ui/android/resources/resource_manager_impl.h" 5 #include "ui/android/resources/resource_manager_impl.h"
6 6
7 #include <inttypes.h> 7 #include <inttypes.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/android/jni_array.h" 13 #include "base/android/jni_array.h"
14 #include "base/android/jni_string.h" 14 #include "base/android/jni_string.h"
15 #include "base/memory/ptr_util.h" 15 #include "base/memory/ptr_util.h"
16 #include "base/strings/stringprintf.h" 16 #include "base/strings/stringprintf.h"
17 #include "base/threading/thread_task_runner_handle.h" 17 #include "base/threading/thread_task_runner_handle.h"
18 #include "base/trace_event/estimate_memory_usage.h"
18 #include "base/trace_event/memory_dump_manager.h" 19 #include "base/trace_event/memory_dump_manager.h"
19 #include "base/trace_event/process_memory_dump.h" 20 #include "base/trace_event/process_memory_dump.h"
20 #include "base/trace_event/trace_event.h" 21 #include "base/trace_event/trace_event.h"
21 #include "cc/resources/scoped_ui_resource.h" 22 #include "cc/resources/scoped_ui_resource.h"
22 #include "cc/resources/ui_resource_manager.h" 23 #include "cc/resources/ui_resource_manager.h"
23 #include "jni/ResourceManager_jni.h" 24 #include "jni/ResourceManager_jni.h"
24 #include "third_party/skia/include/core/SkBitmap.h" 25 #include "third_party/skia/include/core/SkBitmap.h"
25 #include "third_party/skia/include/core/SkCanvas.h" 26 #include "third_party/skia/include/core/SkCanvas.h"
26 #include "third_party/skia/include/core/SkColorFilter.h" 27 #include "third_party/skia/include/core/SkColorFilter.h"
27 #include "ui/android/resources/ui_resource_provider.h" 28 #include "ui/android/resources/ui_resource_provider.h"
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 sprite_rect_source, sprite_rect_destination)); 295 sprite_rect_source, sprite_rect_destination));
295 } 296 }
296 src_dst_rects.push_back(frame_src_dst_rects); 297 src_dst_rects.push_back(frame_src_dst_rects);
297 } 298 }
298 return src_dst_rects; 299 return src_dst_rects;
299 } 300 }
300 301
301 bool ResourceManagerImpl::OnMemoryDump( 302 bool ResourceManagerImpl::OnMemoryDump(
302 const base::trace_event::MemoryDumpArgs& args, 303 const base::trace_event::MemoryDumpArgs& args,
303 base::trace_event::ProcessMemoryDump* pmd) { 304 base::trace_event::ProcessMemoryDump* pmd) {
304 size_t size = 0; 305 using base::trace_event::EstimateMemoryUsage;
305 for (const auto& resource_map : resources_) { 306 size_t memory_usage = EstimateMemoryUsage(resources_) +
306 for (const auto& id_and_resource : resource_map) { 307 EstimateMemoryUsage(crushed_sprite_resources_) +
307 if (id_and_resource.second && id_and_resource.second->ui_resource) 308 EstimateMemoryUsage(tinted_resources_);
308 size += id_and_resource.second->ui_resource->GetAllocatedSizeInBytes();
309 }
310 }
311 for (const auto& id_and_resource : crushed_sprite_resources_) {
312 if (id_and_resource.second)
313 size += id_and_resource.second->GetAllocatedSizeInBytes();
314 }
315 for (const auto& color_and_resources : tinted_resources_) {
316 for (const auto& id_and_resource : *color_and_resources.second) {
317 if (id_and_resource.second && id_and_resource.second->ui_resource)
318 size += id_and_resource.second->ui_resource->GetAllocatedSizeInBytes();
319 }
320 }
321 309
322 base::trace_event::MemoryAllocatorDump* dump = pmd->CreateAllocatorDump( 310 base::trace_event::MemoryAllocatorDump* dump = pmd->CreateAllocatorDump(
323 base::StringPrintf("ui/resource_manager_0x%" PRIXPTR, 311 base::StringPrintf("ui/resource_manager_0x%" PRIXPTR,
324 reinterpret_cast<uintptr_t>(this))); 312 reinterpret_cast<uintptr_t>(this)));
325 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize, 313 dump->AddScalar(base::trace_event::MemoryAllocatorDump::kNameSize,
326 base::trace_event::MemoryAllocatorDump::kUnitsBytes, size); 314 base::trace_event::MemoryAllocatorDump::kUnitsBytes,
315 memory_usage);
327 316
328 // Bitmaps are allocated from malloc.
329 const char* system_allocator_name = 317 const char* system_allocator_name =
330 base::trace_event::MemoryDumpManager::GetInstance() 318 base::trace_event::MemoryDumpManager::GetInstance()
331 ->system_allocator_pool_name(); 319 ->system_allocator_pool_name();
332 if (system_allocator_name) { 320 if (system_allocator_name) {
333 pmd->AddSuballocation(dump->guid(), system_allocator_name); 321 pmd->AddSuballocation(dump->guid(), system_allocator_name);
334 } 322 }
335 323
336 return true; 324 return true;
337 } 325 }
338 326
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 TRACE_EVENT2("ui", 368 TRACE_EVENT2("ui",
381 "ResourceManagerImpl::RequestCrushedSpriteResourceFromJava", 369 "ResourceManagerImpl::RequestCrushedSpriteResourceFromJava",
382 "bitmap_res_id", bitmap_res_id, 370 "bitmap_res_id", bitmap_res_id,
383 "metadata_res_id", metadata_res_id); 371 "metadata_res_id", metadata_res_id);
384 Java_ResourceManager_crushedSpriteResourceRequested( 372 Java_ResourceManager_crushedSpriteResourceRequested(
385 base::android::AttachCurrentThread(), java_obj_, bitmap_res_id, 373 base::android::AttachCurrentThread(), java_obj_, bitmap_res_id,
386 metadata_res_id, reloading); 374 metadata_res_id, reloading);
387 } 375 }
388 376
389 } // namespace ui 377 } // namespace ui
OLDNEW
« no previous file with comments | « ui/android/resources/resource_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698