提交 94d0aa19 编写于 作者: S Shengliang Guan

TD-1057 set crash in windows

上级 f790a124
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
extern void taosWinSocketInit(); extern void taosWinSocketInit();
void osInit() { void osInit() {
taosSetCoreDump();
if (configDir[0] == 0) { if (configDir[0] == 0) {
strcpy(configDir, "C:/TDengine/cfg"); strcpy(configDir, "C:/TDengine/cfg");
} }
......
...@@ -16,21 +16,23 @@ ...@@ -16,21 +16,23 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#include "taosdef.h" #include "taosdef.h"
#include "tglobal.h"
#include "tconfig.h" #include "tconfig.h"
#include "tglobal.h"
#include "ttimer.h" #include "ttimer.h"
#include "tulog.h" #include "tulog.h"
#include "tutil.h" #include "tutil.h"
#if (_WIN64) #if (_WIN64)
#include <windows.h>
#include <iphlpapi.h> #include <iphlpapi.h>
#include <psapi.h>
#include <ws2tcpip.h>
#include <stdio.h>
#include <mswsock.h> #include <mswsock.h>
#include <psapi.h>
#include <stdio.h>
#include <windows.h>
#include <ws2tcpip.h>
#pragma comment(lib, "Mswsock.lib ") #pragma comment(lib, "Mswsock.lib ")
#endif #endif
#include <DbgHelp.h>
static void taosGetSystemTimezone() { static void taosGetSystemTimezone() {
// get and set default timezone // get and set default timezone
SGlobalCfg *cfg_timezone = taosGetConfigOption("timezone"); SGlobalCfg *cfg_timezone = taosGetConfigOption("timezone");
...@@ -52,7 +54,7 @@ static void taosGetSystemLocale() { ...@@ -52,7 +54,7 @@ static void taosGetSystemLocale() {
if (cfg_locale && cfg_locale->cfgStatus < TAOS_CFG_CSTATUS_DEFAULT) { if (cfg_locale && cfg_locale->cfgStatus < TAOS_CFG_CSTATUS_DEFAULT) {
char *locale = setlocale(LC_CTYPE, "chs"); char *locale = setlocale(LC_CTYPE, "chs");
if (locale != NULL) { if (locale != NULL) {
tstrncpy(tsLocale, locale, TSDB_LOCALE_LEN);; tstrncpy(tsLocale, locale, TSDB_LOCALE_LEN);
cfg_locale->cfgStatus = TAOS_CFG_CSTATUS_DEFAULT; cfg_locale->cfgStatus = TAOS_CFG_CSTATUS_DEFAULT;
uInfo("locale not configured, set to default:%s", tsLocale); uInfo("locale not configured, set to default:%s", tsLocale);
} }
...@@ -79,7 +81,7 @@ void taosGetSystemInfo() { ...@@ -79,7 +81,7 @@ void taosGetSystemInfo() {
} }
bool taosGetDisk() { bool taosGetDisk() {
const double unit = 1024 * 1024 * 1024; const double unit = 1024 * 1024 * 1024;
BOOL fResult; BOOL fResult;
unsigned _int64 i64FreeBytesToCaller; unsigned _int64 i64FreeBytesToCaller;
unsigned _int64 i64TotalBytes; unsigned _int64 i64TotalBytes;
...@@ -88,15 +90,15 @@ bool taosGetDisk() { ...@@ -88,15 +90,15 @@ bool taosGetDisk() {
int drive_type; int drive_type;
if (tscEmbedded) { if (tscEmbedded) {
drive_type = GetDriveTypeA(dir); drive_type = GetDriveTypeA(dir);
if (drive_type == DRIVE_FIXED) { if (drive_type == DRIVE_FIXED) {
fResult = GetDiskFreeSpaceExA(dir, (PULARGE_INTEGER)&i64FreeBytesToCaller, (PULARGE_INTEGER)&i64TotalBytes, fResult = GetDiskFreeSpaceExA(dir, (PULARGE_INTEGER)&i64FreeBytesToCaller, (PULARGE_INTEGER)&i64TotalBytes,
(PULARGE_INTEGER)&i64FreeBytes); (PULARGE_INTEGER)&i64FreeBytes);
if (fResult) { if (fResult) {
tsTotalDataDirGB = tsTotalLogDirGB = tsTotalTmpDirGB = (float)(i64TotalBytes / unit); tsTotalDataDirGB = tsTotalLogDirGB = tsTotalTmpDirGB = (float)(i64TotalBytes / unit);
tsAvailDataDirGB = tsAvailLogDirGB = tsAvailTmpDirectorySpace = (float)(i64FreeBytes / unit); tsAvailDataDirGB = tsAvailLogDirGB = tsAvailTmpDirectorySpace = (float)(i64FreeBytes / unit);
} }
} }
} }
return true; return true;
} }
...@@ -172,10 +174,12 @@ bool taosGetSysMemory(float *memoryUsedMB) { ...@@ -172,10 +174,12 @@ bool taosGetSysMemory(float *memoryUsedMB) {
float nMemTotal; float nMemTotal;
memsStat.dwLength = sizeof(memsStat); memsStat.dwLength = sizeof(memsStat);
if (!GlobalMemoryStatusEx(&memsStat)) { return false; } if (!GlobalMemoryStatusEx(&memsStat)) {
return false;
}
nMemFree = memsStat.ullAvailPhys / (1024.0f * 1024.0f); nMemFree = memsStat.ullAvailPhys / (1024.0f * 1024.0f);
nMemTotal = memsStat.ullTotalPhys / (1024.0f * 1024.0f); nMemTotal = memsStat.ullTotalPhys / (1024.0f * 1024.0f);
*memoryUsedMB = nMemTotal - nMemFree; *memoryUsedMB = nMemTotal - nMemFree;
return true; return true;
} }
...@@ -184,16 +188,46 @@ int taosSystem(const char *cmd) { ...@@ -184,16 +188,46 @@ int taosSystem(const char *cmd) {
return -1; return -1;
} }
int flock(int fd, int option) { int flock(int fd, int option) { return 0; }
return 0;
}
int fsync(int filedes) { int fsync(int filedes) { return 0; }
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);
int sigaction(int sig, struct sigaction *d, void *p) { return EXCEPTION_CONTINUE_SEARCH;
return 0;
} }
void taosSetCoreDump() {} void taosSetCoreDump() { SetUnhandledExceptionFilter(&FlCrashDump); }
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册