瀏覽代碼

add linux crash3

DevYK 3 年之前
父節點
當前提交
c3b595c06e
共有 1 個文件被更改,包括 36 次插入1 次删除
  1. 36 1
      src/utils/video_similarity.cpp

+ 36 - 1
src/utils/video_similarity.cpp

@@ -10,6 +10,39 @@
 #include "video_similarity.h"
 
 
+#ifdef __APPLE__
+#   include <client/mac/handler/exception_handler.h>
+#elif defined _WIN32
+#   include <client/windows/handler/exception_handler.h>
+#elif defined __linux__
+#   include <client/linux/handler/exception_handler.h>
+#   include <client/linux/handler/minidump_descriptor.h>
+#   include <cstdio>
+#endif
+
+#ifdef _WINDOWS
+static bool minidumpCB(const wchar_t *dump_path, const wchar_t *id, void *context, EXCEPTION_POINTERS *exinfo, MDRawAssertionInfo *assertion, bool succeeded) {
+#else
+static bool minidumpCB(const char* dump_path, const char* id, void* context, bool succeeded) {
+#endif
+    if (succeeded) {
+        printf("\"Mini Dump file:%s dump Path=%s\n",id,dump_path);
+    }
+    return succeeded;
+}
+
+static bool init_carsh(const char *path) {
+    // 开启crash监控
+#ifdef _WINDOWS
+    google_breakpad::ExceptionHandler eh(dumpLocation.toStdWString(), NULL, minidumpCB, NULL, google_breakpad::ExceptionHandler::HANDLER_ALL);
+#elif __linux__
+    google_breakpad::ExceptionHandler eh(path, NULL, minidumpCB, NULL, true, NULL);
+#endif
+    return false;
+}
+
+
+
 const int MAX_STACK_FRAMES = 128;
 
 void sig_crash(int sig) {
@@ -283,6 +316,9 @@ const char *videoSimilarity2json(VideoSimilarity *videoSimilarity) {
 const char *get_video_similarity_list(const char *inputjson) {
     signal(SIGABRT, sig_crash);
     signal(SIGSEGV, sig_crash);
+#if __linux__
+    init_carsh("/datalog/crash.dump");
+#endif
     if (!inputjson)return NULL;
 //    free((void*)inputjson);
     printf("get_video_similarity_list=%s \n", inputjson);
@@ -290,7 +326,6 @@ const char *get_video_similarity_list(const char *inputjson) {
     long id = video_similarity_detection_init(vs->videoPath);
     const char *ret_json = NULL;
     if (id > 0) {
-
         if (!(((VideoSimilarityContext *) id)->log)) {
             int n = strlen(((VideoSimilarityContext *) id)->video_path); //计算字符串的长度(包括'\0')
             const char *name = GetFileName(((VideoSimilarityContext *) id)->video_path, n); //把字符串及其长度传给函数