mirror of
https://github.com/lltcggie/waifu2x-caffe.git
synced 2025-06-25 21:22:47 +00:00
ダンプファイルを出力するようにした
This commit is contained in:
parent
4942a6d07b
commit
55bcf1b001
@ -12,6 +12,7 @@
|
||||
|
||||
#if defined(WIN32) || defined(WIN64)
|
||||
#include <Windows.h>
|
||||
#include "../waifu2x-caffe-gui/MiniDump.h"
|
||||
|
||||
#undef LoadImage
|
||||
#endif
|
||||
@ -527,11 +528,22 @@ Waifu2x::eWaifu2xError Waifu2x::init(int argc, char** argv, const std::string &M
|
||||
{
|
||||
assert(argc >= 1);
|
||||
|
||||
int tmpargc = 1;
|
||||
char* tmpargvv[] = { argv[0] };
|
||||
int tmpargc = sizeof(tmpargvv) / sizeof(tmpargvv[0]);
|
||||
char** tmpargv = tmpargvv;
|
||||
|
||||
FLAGS_minloglevel = 1;
|
||||
FLAGS_logtostderr = 0;
|
||||
FLAGS_log_dir = "./logs";
|
||||
|
||||
// glog等の初期化
|
||||
caffe::GlobalInit(&tmpargc, &tmpargv);
|
||||
|
||||
::google::InstallFailureFunction([]()
|
||||
{
|
||||
ExceptionHandler(nullptr, 2);
|
||||
abort();
|
||||
});
|
||||
});
|
||||
|
||||
const auto cuDNNCheckStartTime = std::chrono::system_clock::now();
|
||||
|
179
waifu2x-caffe-gui/MiniDump.cpp
Normal file
179
waifu2x-caffe-gui/MiniDump.cpp
Normal file
@ -0,0 +1,179 @@
|
||||
#include <windows.h>
|
||||
#include <tchar.h>
|
||||
#include <dbghelp.h>
|
||||
#include <stdio.h>
|
||||
#include <crtdbg.h>
|
||||
#include <shlwapi.h>
|
||||
#include "MiniDump.h"
|
||||
|
||||
// #pragma comment (lib, "dbghelp.lib")
|
||||
#pragma comment (lib, "shlwapi.lib")
|
||||
|
||||
typedef BOOL (WINAPI *MINIDUMPWRITEDUMP)(HANDLE hProcess, DWORD ProcessId, HANDLE hFile, MINIDUMP_TYPE DumpType, PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam, PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam, PMINIDUMP_CALLBACK_INFORMATION CallbackParam);
|
||||
|
||||
const int DefaultLevel = 2;
|
||||
|
||||
|
||||
void CreateDump(EXCEPTION_POINTERS *pep, DWORD ThreadID, int level)
|
||||
{
|
||||
HMODULE mhLib = ::LoadLibrary(_T("dbghelp_local.dll"));
|
||||
if (!mhLib)
|
||||
return;
|
||||
|
||||
MINIDUMPWRITEDUMP pDump = (MINIDUMPWRITEDUMP)::GetProcAddress(mhLib, "MiniDumpWriteDump");
|
||||
if (!pDump)
|
||||
{
|
||||
FreeLibrary(mhLib);
|
||||
|
||||
if (pep)
|
||||
UnhandledExceptionFilter(pep);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
TCHAR szFilePath[1024];
|
||||
|
||||
::GetModuleFileName(NULL, szFilePath, sizeof(szFilePath));
|
||||
::PathRemoveFileSpec(szFilePath);
|
||||
_tcscat_s(szFilePath, TEXT("\\"));
|
||||
|
||||
TCHAR SettingDir[100] = TEXT("");
|
||||
|
||||
#if !defined(PRODUCT_MODE)
|
||||
{
|
||||
TCHAR iniPath[1024];
|
||||
_tcscpy_s(iniPath, szFilePath);
|
||||
_tcscat_s(iniPath, TEXT("DebugSetting.ini"));
|
||||
GetPrivateProfileString(TEXT("MemoryDump"), TEXT("RelativePath"), TEXT(""), SettingDir, sizeof(SettingDir) / sizeof(SettingDir[0]), iniPath);
|
||||
|
||||
const size_t len = _tcslen(SettingDir);
|
||||
if (len > 0 && (SettingDir[len - 1] != TEXT('\\') || SettingDir[len - 1] != TEXT('/')))
|
||||
_tcscat_s(SettingDir, TEXT("\\"));
|
||||
}
|
||||
#endif
|
||||
|
||||
SYSTEMTIME systime;
|
||||
GetLocalTime(&systime);
|
||||
|
||||
TCHAR buf[100];
|
||||
_stprintf_s(buf, TEXT("%04d_%02d_%02d %02u_%02u_%02u_%03u.dmp"), systime.wYear, systime.wMonth, systime.wDay, systime.wHour, systime.wMinute, systime.wSecond, systime.wMilliseconds);
|
||||
|
||||
|
||||
_tcscat_s(szFilePath, SettingDir);
|
||||
_tcscat_s(szFilePath, buf);
|
||||
|
||||
HANDLE hFile = CreateFile(szFilePath,
|
||||
GENERIC_READ | GENERIC_WRITE,
|
||||
0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
if (hFile == INVALID_HANDLE_VALUE){
|
||||
_tprintf(_T("CreateFile failed. Error: %u \n"),
|
||||
GetLastError());
|
||||
FreeLibrary(mhLib);
|
||||
|
||||
if (pep)
|
||||
UnhandledExceptionFilter(pep);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
MINIDUMP_EXCEPTION_INFORMATION mdei;
|
||||
|
||||
mdei.ThreadId = ThreadID;
|
||||
mdei.ExceptionPointers = pep;
|
||||
mdei.ClientPointers = FALSE;
|
||||
|
||||
MINIDUMP_CALLBACK_INFORMATION mci;
|
||||
|
||||
mci.CallbackRoutine = NULL;
|
||||
mci.CallbackParam = 0;
|
||||
|
||||
MINIDUMP_TYPE mdt;
|
||||
|
||||
switch (level)
|
||||
{
|
||||
case 0:
|
||||
mdt = (MINIDUMP_TYPE)(MiniDumpNormal);
|
||||
break;
|
||||
case 1:
|
||||
mdt = (MINIDUMP_TYPE)(
|
||||
MiniDumpWithIndirectlyReferencedMemory |
|
||||
MiniDumpScanMemory);
|
||||
break;
|
||||
case 2:
|
||||
mdt = (MINIDUMP_TYPE)(
|
||||
MiniDumpWithIndirectlyReferencedMemory |
|
||||
MiniDumpScanMemory |
|
||||
MiniDumpWithDataSegs |
|
||||
MiniDumpWithHandleData |
|
||||
MiniDumpWithFullMemoryInfo |
|
||||
MiniDumpWithThreadInfo |
|
||||
MiniDumpWithUnloadedModules);
|
||||
break;
|
||||
case 3:
|
||||
mdt = (MINIDUMP_TYPE)(
|
||||
MiniDumpWithPrivateReadWriteMemory |
|
||||
MiniDumpWithDataSegs |
|
||||
MiniDumpWithHandleData |
|
||||
MiniDumpWithFullMemoryInfo |
|
||||
MiniDumpWithThreadInfo |
|
||||
MiniDumpWithUnloadedModules);
|
||||
break;
|
||||
default:
|
||||
mdt = (MINIDUMP_TYPE)(
|
||||
MiniDumpWithFullMemory |
|
||||
MiniDumpWithFullMemoryInfo |
|
||||
MiniDumpWithHandleData |
|
||||
MiniDumpWithThreadInfo |
|
||||
MiniDumpWithUnloadedModules);
|
||||
break;
|
||||
}
|
||||
|
||||
BOOL rv = pDump(
|
||||
GetCurrentProcess(), GetCurrentProcessId(),
|
||||
hFile, mdt, (pep != NULL) ? &mdei : NULL, NULL, &mci);
|
||||
if (rv == FALSE){
|
||||
// _tprintf(_T("MiniDumpWriteDump failed. Error: %u \n"), GetLastError());
|
||||
}
|
||||
|
||||
CloseHandle(hFile);
|
||||
|
||||
FreeLibrary(mhLib);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
struct stException
|
||||
{
|
||||
PEXCEPTION_POINTERS ExceptionInfo;
|
||||
DWORD ThreadID;
|
||||
int Level;
|
||||
};
|
||||
|
||||
static stException g_info;
|
||||
|
||||
|
||||
DWORD WINAPI ReportFunc(LPVOID ThreadParam)
|
||||
{
|
||||
CreateDump(g_info.ExceptionInfo, g_info.ThreadID, g_info.Level);
|
||||
return 0;
|
||||
}
|
||||
|
||||
LONG CALLBACK ExceptionHandler(PEXCEPTION_POINTERS ExceptionInfo, int level)
|
||||
{
|
||||
if (!ExceptionInfo || ExceptionInfo->ExceptionRecord->ExceptionCode != 0xE06D7363)
|
||||
{
|
||||
g_info.ExceptionInfo = ExceptionInfo;
|
||||
g_info.ThreadID = GetCurrentThreadId();
|
||||
g_info.Level = level;
|
||||
HANDLE hThread = CreateThread(NULL, 0, ReportFunc, NULL, 0, NULL);
|
||||
WaitForSingleObject(hThread, INFINITE);
|
||||
}
|
||||
|
||||
return EXCEPTION_CONTINUE_SEARCH;
|
||||
}
|
||||
|
||||
LONG CALLBACK ExceptionHandler(PEXCEPTION_POINTERS ExceptionInfo)
|
||||
{
|
||||
return ExceptionHandler(ExceptionInfo, DefaultLevel);
|
||||
}
|
8
waifu2x-caffe-gui/MiniDump.h
Normal file
8
waifu2x-caffe-gui/MiniDump.h
Normal file
@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <dbghelp.h>
|
||||
|
||||
void CreateDump(EXCEPTION_POINTERS *pep, DWORD ThreadID, int level = 2);
|
||||
|
||||
LONG CALLBACK ExceptionHandler(PEXCEPTION_POINTERS ExceptionInfo, int level);
|
||||
LONG CALLBACK ExceptionHandler(PEXCEPTION_POINTERS ExceptionInfo);
|
@ -18,6 +18,7 @@
|
||||
|
||||
#include "CDialog.h"
|
||||
#include "CControl.h"
|
||||
#include "MiniDump.h"
|
||||
|
||||
#define WM_FAILD_CREATE_DIR (WM_APP + 5)
|
||||
#define WM_ON_WAIFU2X_ERROR (WM_APP + 6)
|
||||
@ -824,6 +825,8 @@ int WINAPI WinMain(HINSTANCE hInstance,
|
||||
LPSTR lpCmdLine,
|
||||
int nCmdShow)
|
||||
{
|
||||
//PVOID hVectoredExceptionHandler = AddVectoredExceptionHandler(1, ExceptionHandler);
|
||||
|
||||
// CDialogクラスでダイアログを作成する
|
||||
CDialog cDialog;
|
||||
CDialog cDialog2;
|
||||
@ -876,5 +879,7 @@ int WINAPI WinMain(HINSTANCE hInstance,
|
||||
// ダイアログを表示
|
||||
cDialog.DoModal(hInstance, IDD_DIALOG);
|
||||
|
||||
//RemoveVectoredExceptionHandler(hVectoredExceptionHandler);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -92,6 +92,7 @@
|
||||
<ClCompile Include="CControl.cpp" />
|
||||
<ClCompile Include="CDialog.cpp" />
|
||||
<ClCompile Include="CDialogBase.cpp" />
|
||||
<ClCompile Include="MiniDump.cpp" />
|
||||
<ClCompile Include="Source.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@ -102,6 +103,7 @@
|
||||
<ClInclude Include="CWindow.h" />
|
||||
<ClInclude Include="CWindowBase.h" />
|
||||
<ClInclude Include="GUICommon.h" />
|
||||
<ClInclude Include="MiniDump.h" />
|
||||
<ClInclude Include="resource.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -30,6 +30,9 @@
|
||||
<ClCompile Include="CDialogBase.cpp">
|
||||
<Filter>ソース ファイル</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="MiniDump.cpp">
|
||||
<Filter>ソース ファイル</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\common\waifu2x.h">
|
||||
@ -56,6 +59,9 @@
|
||||
<ClInclude Include="resource.h">
|
||||
<Filter>ヘッダー ファイル</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="MiniDump.h">
|
||||
<Filter>ヘッダー ファイル</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="Resource.rc">
|
||||
|
Loading…
x
Reference in New Issue
Block a user