Skip to content

Commit

Permalink
Improve context-lost related crash keys
Browse files Browse the repository at this point in the history
Sometimes, we cannot get correct process creation time, for example
/proc fs is not mounted or cannot be read. To workaround it, we just
use creation time of |GpuChannelManager| as the creation time for the
GPU process. This CL also adds "context-lost-interval" crash key.

Bug: none
Change-Id: I03b85de21d82ccc95d326ddcbd5b10ddcf2c9f08
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2710527
Commit-Queue: Peng Huang <penghuang@chromium.org>
Auto-Submit: Peng Huang <penghuang@chromium.org>
Reviewed-by: Vasiliy Telezhnikov <vasilyt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#856282}
  • Loading branch information
phuang authored and Chromium LUCI CQ committed Feb 22, 2021
1 parent d0b1547 commit 108cd40
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 19 deletions.
52 changes: 33 additions & 19 deletions gpu/ipc/service/gpu_channel_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "base/debug/crash_logging.h"
#include "base/location.h"
#include "base/metrics/histogram_macros.h"
#include "base/process/process.h"
#include "base/run_loop.h"
#include "base/single_thread_task_runner.h"
#include "base/strings/stringprintf.h"
Expand Down Expand Up @@ -101,6 +100,15 @@ void FormatAllocationSourcesForTracing(
allocation_sources[GpuPeakMemoryAllocationSource::SKIA]);
}

void SetCrashKeyTimeDelta(base::debug::CrashKeyString* key,
base::TimeDelta time_delta) {
auto str = base::StringPrintf(
"%d hours, %d min, %lld sec, %lld ms", time_delta.InHours(),
time_delta.InMinutes() % 60, time_delta.InSeconds() % 60ll,
time_delta.InMilliseconds() % 1000ll);
base::debug::SetCrashKeyString(key, str);
}

} // namespace

GpuChannelManager::GpuPeakMemoryMonitor::GpuPeakMemoryMonitor(
Expand Down Expand Up @@ -837,6 +845,30 @@ scoped_refptr<SharedContextState> GpuChannelManager::GetSharedContextState(
void GpuChannelManager::OnContextLost(bool synthetic_loss) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);

// Add crash keys for context lost count and time.
static auto* const lost_count_crash_key = base::debug::AllocateCrashKeyString(
"context-lost-count", base::debug::CrashKeySize::Size32);
// The context lost time since creation of |GpuChannelManager|.
static auto* const lost_time_crash_key = base::debug::AllocateCrashKeyString(
"context-lost-time", base::debug::CrashKeySize::Size64);
// The context lost interval since last context lost event.
static auto* const lost_interval_crash_key =
base::debug::AllocateCrashKeyString("context-lost-interval",
base::debug::CrashKeySize::Size64);

base::debug::SetCrashKeyString(
lost_count_crash_key, base::StringPrintf("%d", ++context_lost_count_));

auto lost_time = base::TimeTicks::Now() - creation_time_;
SetCrashKeyTimeDelta(lost_time_crash_key, lost_time);

if (!context_lost_time_.is_zero()) {
auto interval = lost_time - context_lost_time_;
SetCrashKeyTimeDelta(lost_interval_crash_key, interval);
}

context_lost_time_ = lost_time;

if (synthetic_loss)
return;

Expand All @@ -851,25 +883,7 @@ void GpuChannelManager::OnContextLost(bool synthetic_loss) {
if (gpu_driver_bug_workarounds_.exit_on_context_lost ||
(shared_context_state_ && !shared_context_state_->GrContextIsGL())) {
delegate_->MaybeExitOnContextLost();
return;
}

// Add crash keys for context lost count and time.
static auto* const lost_count_crash_key = base::debug::AllocateCrashKeyString(
"context-lost-count", base::debug::CrashKeySize::Size32);
static int lost_count = 0;
base::debug::SetCrashKeyString(lost_count_crash_key,
base::StringPrintf("%d", ++lost_count));

static auto* const lost_time_crash_key = base::debug::AllocateCrashKeyString(
"context-lost-time", base::debug::CrashKeySize::Size64);
auto process = base::Process::Current();
auto lost_time = base::Time::Now() - process.CreationTime();
auto lost_time_string = base::StringPrintf(
"%d hours, %d min, %lld sec, %lld ms", lost_time.InHours(),
lost_time.InMinutes() % 60, lost_time.InSeconds() % 60ll,
lost_time.InMilliseconds() % 1000ll);
base::debug::SetCrashKeyString(lost_time_crash_key, lost_time_string);
}

void GpuChannelManager::ScheduleGrContextCleanup() {
Expand Down
9 changes: 9 additions & 0 deletions gpu/ipc/service/gpu_channel_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,15 @@ class GPU_IPC_SERVICE_EXPORT GpuChannelManager

GpuPeakMemoryMonitor peak_memory_monitor_;

// Creation time of GpuChannelManger.
const base::TimeTicks creation_time_ = base::TimeTicks::Now();

// Context lost time since creation of |GpuChannelManger|.
base::TimeDelta context_lost_time_;

// Count of context lost.
int context_lost_count_ = 0;

THREAD_CHECKER(thread_checker_);

// Member variables should appear before the WeakPtrFactory, to ensure
Expand Down

0 comments on commit 108cd40

Please sign in to comment.