blob: 6e63c77867ac324e37f3f7955e9a36fff0ce11f6 [file] [log] [blame]
// Copyright 2022 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <lib/zx/event.h>
#include <lib/zx/job.h>
#include <lib/zx/time.h>
#include <thread>
// BacktraceWatchdog is a one-shot watchdog that backtraces all the threads in a job if the timeout
// is reached prior to the watchdog being stopped. The watchdog spawns its own thread and does not
// rely on a thread being available on any dispatcher to trigger the timeout.
class BacktraceWatchdog {
BacktraceWatchdog() = default;
// Start the watchdog with the given job and timeout.
zx_status_t Start(zx::job job, zx::duration wait_time);
// Stop the watchdog early. This happens implicitly on destruction.
void Stop();
int WatchdogThread();
void Backtrace();
bool running_ = false;
zx::time timeout_;
std::thread thread_;
zx::job job_;
zx::event event_;