46 static std::mutex initMutex;
48 std::lock_guard<std::mutex> guard(initMutex);
50 GPUFatal(
"Error handlers for debug dumps already set, cannot set them again");
52 mDebugData = std::make_unique<debugInternal>();
56 struct sigaction sa, oldsa;
57 memset(&sa, 0,
sizeof(sa));
59 sa.sa_flags = SA_SIGINFO;
62 for (uint32_t
i = 0;
i <
sizeof(
mask) * 8;
i++) {
63 if (
mask & (1 <<
i)) {
64 if (sigaction(
i, &sa, &oldsa)) {
65 GPUFatal(
"Error installing signal handler for error dump on signal %d",
i);
72 mDebugData->signalCallback = [
this, &oldActions =
mDebugData->oldActions, myAction = std::move(sa)](int32_t signal, siginfo_t* info,
void* ucontext) {
73 static std::mutex callbackMutex;
74 std::lock_guard<std::mutex> guard(callbackMutex);
76 GPUInfo(
"Running debug callback for signal %d", signal);
82 sigaction(signal, &oldActions[signal],
nullptr);
84 mDebugData->reinstallCallback = [signal, myAction]() { sigaction(signal, &myAction,
nullptr); };
123 std::size_t total_size = 0;
124 std::size_t subfolder_count = 0;
126 if (!std::filesystem::exists(target_dir) || !std::filesystem::is_directory(target_dir)) {
127 GPUError(
"Invalid debugOnFailureDirectory %s",
GetProcessingSettings().debugOnFailureDirectory.c_str());
131 for (
const auto&
entry : std::filesystem::directory_iterator(target_dir)) {
132 if (
entry.is_directory()) {
135 for (
const auto& subentry : std::filesystem::directory_iterator(
entry.path())) {
136 if (subentry.is_regular_file()) {
138 auto size = std::filesystem::file_size(subentry.path(), ec);
148 GPUError(
"Cannot store debug dump files, target storage exceeded: %zu dumps, %zu bytes", subfolder_count, total_size);
152 auto currentTime = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
153 std::ostringstream dateTime;
154 dateTime << std::put_time(std::localtime(¤tTime),
"%Y-%m-%d_%H-%M-%S");
159 if (attempt++ >= 512) {
160 GPUError(
"Error creating debug dump folder");
166 bool created = std::filesystem::create_directory(outname, ec);
167 if (!ec && created) {
172 GPUInfo(
"Debug dump to %s", outname.c_str());