TD-1057 set crash in windows
This commit is contained in:
parent
f790a124b1
commit
94d0aa193d
|
@ -21,6 +21,7 @@
|
|||
extern void taosWinSocketInit();
|
||||
|
||||
void osInit() {
|
||||
taosSetCoreDump();
|
||||
if (configDir[0] == 0) {
|
||||
strcpy(configDir, "C:/TDengine/cfg");
|
||||
}
|
||||
|
|
|
@ -16,21 +16,23 @@
|
|||
#define _DEFAULT_SOURCE
|
||||
#include "os.h"
|
||||
#include "taosdef.h"
|
||||
#include "tglobal.h"
|
||||
#include "tconfig.h"
|
||||
#include "tglobal.h"
|
||||
#include "ttimer.h"
|
||||
#include "tulog.h"
|
||||
#include "tutil.h"
|
||||
#if (_WIN64)
|
||||
#include <windows.h>
|
||||
#include <iphlpapi.h>
|
||||
#include <psapi.h>
|
||||
#include <ws2tcpip.h>
|
||||
#include <stdio.h>
|
||||
#include <mswsock.h>
|
||||
#include <psapi.h>
|
||||
#include <stdio.h>
|
||||
#include <windows.h>
|
||||
#include <ws2tcpip.h>
|
||||
#pragma comment(lib, "Mswsock.lib ")
|
||||
#endif
|
||||
|
||||
#include <DbgHelp.h>
|
||||
|
||||
static void taosGetSystemTimezone() {
|
||||
// get and set default timezone
|
||||
SGlobalCfg *cfg_timezone = taosGetConfigOption("timezone");
|
||||
|
@ -52,7 +54,7 @@ static void taosGetSystemLocale() {
|
|||
if (cfg_locale && cfg_locale->cfgStatus < TAOS_CFG_CSTATUS_DEFAULT) {
|
||||
char *locale = setlocale(LC_CTYPE, "chs");
|
||||
if (locale != NULL) {
|
||||
tstrncpy(tsLocale, locale, TSDB_LOCALE_LEN);;
|
||||
tstrncpy(tsLocale, locale, TSDB_LOCALE_LEN);
|
||||
cfg_locale->cfgStatus = TAOS_CFG_CSTATUS_DEFAULT;
|
||||
uInfo("locale not configured, set to default:%s", tsLocale);
|
||||
}
|
||||
|
@ -79,7 +81,7 @@ void taosGetSystemInfo() {
|
|||
}
|
||||
|
||||
bool taosGetDisk() {
|
||||
const double unit = 1024 * 1024 * 1024;
|
||||
const double unit = 1024 * 1024 * 1024;
|
||||
BOOL fResult;
|
||||
unsigned _int64 i64FreeBytesToCaller;
|
||||
unsigned _int64 i64TotalBytes;
|
||||
|
@ -88,15 +90,15 @@ bool taosGetDisk() {
|
|||
int drive_type;
|
||||
|
||||
if (tscEmbedded) {
|
||||
drive_type = GetDriveTypeA(dir);
|
||||
drive_type = GetDriveTypeA(dir);
|
||||
if (drive_type == DRIVE_FIXED) {
|
||||
fResult = GetDiskFreeSpaceExA(dir, (PULARGE_INTEGER)&i64FreeBytesToCaller, (PULARGE_INTEGER)&i64TotalBytes,
|
||||
(PULARGE_INTEGER)&i64FreeBytes);
|
||||
if (fResult) {
|
||||
tsTotalDataDirGB = tsTotalLogDirGB = tsTotalTmpDirGB = (float)(i64TotalBytes / unit);
|
||||
tsAvailDataDirGB = tsAvailLogDirGB = tsAvailTmpDirectorySpace = (float)(i64FreeBytes / unit);
|
||||
}
|
||||
}
|
||||
fResult = GetDiskFreeSpaceExA(dir, (PULARGE_INTEGER)&i64FreeBytesToCaller, (PULARGE_INTEGER)&i64TotalBytes,
|
||||
(PULARGE_INTEGER)&i64FreeBytes);
|
||||
if (fResult) {
|
||||
tsTotalDataDirGB = tsTotalLogDirGB = tsTotalTmpDirGB = (float)(i64TotalBytes / unit);
|
||||
tsAvailDataDirGB = tsAvailLogDirGB = tsAvailTmpDirectorySpace = (float)(i64FreeBytes / unit);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -172,10 +174,12 @@ bool taosGetSysMemory(float *memoryUsedMB) {
|
|||
float nMemTotal;
|
||||
|
||||
memsStat.dwLength = sizeof(memsStat);
|
||||
if (!GlobalMemoryStatusEx(&memsStat)) { return false; }
|
||||
if (!GlobalMemoryStatusEx(&memsStat)) {
|
||||
return false;
|
||||
}
|
||||
nMemFree = memsStat.ullAvailPhys / (1024.0f * 1024.0f);
|
||||
nMemTotal = memsStat.ullTotalPhys / (1024.0f * 1024.0f);
|
||||
*memoryUsedMB = nMemTotal - nMemFree;
|
||||
*memoryUsedMB = nMemTotal - nMemFree;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -184,16 +188,46 @@ int taosSystem(const char *cmd) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
int flock(int fd, int option) {
|
||||
return 0;
|
||||
int flock(int fd, int option) { return 0; }
|
||||
|
||||
int fsync(int filedes) { return 0; }
|
||||
|
||||
int sigaction(int sig, struct sigaction *d, void *p) { return 0; }
|
||||
|
||||
LONG WINAPI FlCrashDump(PEXCEPTION_POINTERS ep) {
|
||||
typedef BOOL(WINAPI * FxMiniDumpWriteDump)(IN HANDLE hProcess, IN DWORD ProcessId, IN HANDLE hFile,
|
||||
IN MINIDUMP_TYPE DumpType,
|
||||
IN CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
|
||||
IN CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
|
||||
IN CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam);
|
||||
|
||||
HMODULE dll = LoadLibrary("dbghelp.dll");
|
||||
if (dll == NULL) return EXCEPTION_CONTINUE_SEARCH;
|
||||
FxMiniDumpWriteDump mdwd = (FxMiniDumpWriteDump)(GetProcAddress(dll, "MiniDumpWriteDump"));
|
||||
if (mdwd == NULL) {
|
||||
FreeLibrary(dll);
|
||||
return EXCEPTION_CONTINUE_SEARCH;
|
||||
}
|
||||
|
||||
TCHAR path[MAX_PATH];
|
||||
DWORD len = GetModuleFileName(NULL, path, _countof(path));
|
||||
path[len - 3] = 'd';
|
||||
path[len - 2] = 'm';
|
||||
path[len - 1] = 'p';
|
||||
|
||||
HANDLE file = CreateFile(path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
|
||||
MINIDUMP_EXCEPTION_INFORMATION mei;
|
||||
mei.ThreadId = GetCurrentThreadId();
|
||||
mei.ExceptionPointers = ep;
|
||||
mei.ClientPointers = FALSE;
|
||||
|
||||
(*mdwd)(GetCurrentProcess(), GetCurrentProcessId(), file, MiniDumpWithHandleData, &mei, NULL, NULL);
|
||||
|
||||
CloseHandle(file);
|
||||
FreeLibrary(dll);
|
||||
|
||||
return EXCEPTION_CONTINUE_SEARCH;
|
||||
}
|
||||
|
||||
int fsync(int filedes) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sigaction(int sig, struct sigaction *d, void *p) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void taosSetCoreDump() {}
|
||||
void taosSetCoreDump() { SetUnhandledExceptionFilter(&FlCrashDump); }
|
Loading…
Reference in New Issue