Skip to content

Commit

Permalink
Added memory dump for GrShaderCache
Browse files Browse the repository at this point in the history
Bug: 913935
Change-Id: Iaf5f1a27215a3802d9baa62681787aee7de45259
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1503415
Commit-Queue: Tanmoy Mollik <[email protected]>
Reviewed-by: Khushal <[email protected]>
Reviewed-by: Antoine Labour <[email protected]>
Reviewed-by: Eric Karl <[email protected]>
Cr-Commit-Position: refs/heads/master@{#640287}
  • Loading branch information
Tanmoy Mollik authored and Commit Bot committed Mar 13, 2019
1 parent 3a9a601 commit 84f141f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
31 changes: 29 additions & 2 deletions gpu/command_buffer/service/gr_shader_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

#include "gpu/command_buffer/service/gr_shader_cache.h"

#include <inttypes.h>

#include "base/base64.h"
#include "base/strings/stringprintf.h"
#include "base/threading/thread_task_runner_handle.h"
#include "base/trace_event/memory_dump_manager.h"
#include "base/trace_event/trace_event.h"

namespace gpu {
Expand All @@ -24,9 +29,17 @@ sk_sp<SkData> MakeData(const std::string& str) {
GrShaderCache::GrShaderCache(size_t max_cache_size_bytes, Client* client)
: cache_size_limit_(max_cache_size_bytes),
store_(Store::NO_AUTO_EVICT),
client_(client) {}
client_(client) {
if (base::ThreadTaskRunnerHandle::IsSet()) {
base::trace_event::MemoryDumpManager::GetInstance()->RegisterDumpProvider(
this, "GrShaderCache", base::ThreadTaskRunnerHandle::Get());
}
}

GrShaderCache::~GrShaderCache() = default;
GrShaderCache::~GrShaderCache() {
base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider(
this);
}

sk_sp<SkData> GrShaderCache::load(const SkData& key) {
TRACE_EVENT0("gpu", "GrShaderCache::load");
Expand Down Expand Up @@ -128,6 +141,20 @@ void GrShaderCache::PurgeMemory(
cache_size_limit_ = original_limit;
}

bool GrShaderCache::OnMemoryDump(const base::trace_event::MemoryDumpArgs& args,
base::trace_event::ProcessMemoryDump* pmd) {
using base::trace_event::MemoryAllocatorDump;
// TODO(triploblastic): Add UMA metric collection for background tracing mode
std::string dump_name =
base::StringPrintf("gpu/gr_shader_cache/cache_0x%" PRIXPTR,
reinterpret_cast<uintptr_t>(this));
MemoryAllocatorDump* dump = pmd->CreateAllocatorDump(dump_name);
dump->AddScalar(MemoryAllocatorDump::kNameSize,
MemoryAllocatorDump::kUnitsBytes, curr_size_bytes_);

return true;
}

void GrShaderCache::WriteToDisk(const CacheKey& key, CacheData* data) {
DCHECK_NE(current_client_id_, kInvalidClientId);

Expand Down
7 changes: 6 additions & 1 deletion gpu/command_buffer/service/gr_shader_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
#include "base/containers/mru_cache.h"
#include "base/hash.h"
#include "base/memory/memory_pressure_listener.h"
#include "base/trace_event/memory_dump_provider.h"
#include "gpu/gpu_gles2_export.h"
#include "third_party/skia/include/gpu/GrContextOptions.h"

namespace gpu {
namespace raster {

class GPU_GLES2_EXPORT GrShaderCache
: public GrContextOptions::PersistentCache {
: public GrContextOptions::PersistentCache,
public base::trace_event::MemoryDumpProvider {
public:
class GPU_GLES2_EXPORT Client {
public:
Expand Down Expand Up @@ -47,6 +49,9 @@ class GPU_GLES2_EXPORT GrShaderCache
void PurgeMemory(
base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level);

bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args,
base::trace_event::ProcessMemoryDump* pmd) override;

size_t num_cache_entries() const { return store_.size(); }
size_t curr_size_bytes_for_testing() const { return curr_size_bytes_; }

Expand Down

0 comments on commit 84f141f

Please sign in to comment.