Skip to content

Commit

Permalink
feat: add Glog APIs for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
homuler committed Nov 29, 2020
1 parent fad3ca1 commit 085f7cc
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 0 deletions.
32 changes: 32 additions & 0 deletions Assets/MediaPipe/SDK/Scripts/External/Glog.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,43 @@
namespace Mediapipe {
public class Glog {
public enum Severity : int {
INFO = 0,
WARNING = 1,
ERROR = 2,
FATAL = 3,
}

public static void Initialize(string name, string dir) {
UnsafeNativeMethods.google_InitGoogleLogging__PKc(name, dir).Assert();
}

public static void Shutdown() {
UnsafeNativeMethods.google_ShutdownGoogleLogging().Assert();
}

public static void Log(Severity severity, string str) {
switch (severity) {
case Severity.INFO: {
UnsafeNativeMethods.glog_LOG_INFO__PKc(str);
break;
}
case Severity.WARNING: {
UnsafeNativeMethods.glog_LOG_WARNING__PKc(str);
break;
}
case Severity.ERROR: {
UnsafeNativeMethods.glog_LOG_ERROR__PKc(str);
break;
}
case Severity.FATAL: {
UnsafeNativeMethods.glog_LOG_FATAL__PKc(str);
break;
}
}
}

public static void FlushLogFiles(Severity severity = Severity.INFO) {
UnsafeNativeMethods.google_FlushLogFiles(severity);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,20 @@ internal static partial class UnsafeNativeMethods {

[DllImport (MediaPipeLibrary, ExactSpelling = true)]
public static extern MpReturnCode google_ShutdownGoogleLogging();

[DllImport (MediaPipeLibrary, ExactSpelling = true)]
public static extern MpReturnCode glog_LOG_INFO__PKc(string str);

[DllImport (MediaPipeLibrary, ExactSpelling = true)]
public static extern MpReturnCode glog_LOG_WARNING__PKc(string str);

[DllImport (MediaPipeLibrary, ExactSpelling = true)]
public static extern MpReturnCode glog_LOG_ERROR__PKc(string str);

[DllImport (MediaPipeLibrary, ExactSpelling = true)]
public static extern MpReturnCode glog_LOG_FATAL__PKc(string str);

[DllImport (MediaPipeLibrary, ExactSpelling = true)]
public static extern MpReturnCode google_FlushLogFiles(Glog.Severity severity);
}
}
1 change: 1 addition & 0 deletions C/mediapipe_api/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ cc_library(
name = "mediapipe_c",
deps = [
":calculators",
"//mediapipe_api/external:glog",
"//mediapipe_api/external:protobuf",
"//mediapipe_api/external:stdlib",
"//mediapipe_api/framework:calculator",
Expand Down
11 changes: 11 additions & 0 deletions C/mediapipe_api/external/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
cc_library(
name = "glog",
srcs = ["glog.cc"],
hdrs = ["glog.h"],
deps = [
"//mediapipe_api:common",
],
visibility = ["//visibility:public"],
alwayslink = True,
)

cc_library(
name = "protobuf",
srcs = ["protobuf.cc"],
Expand Down
21 changes: 21 additions & 0 deletions C/mediapipe_api/external/glog.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "mediapipe_api/external/glog.h"

void glog_LOG_INFO__PKc(const char* str) {
LOG(INFO) << str;
}

void glog_LOG_WARNING__PKc(const char* str) {
LOG(WARNING) << str;
}

void glog_LOG_ERROR__PKc(const char* str) {
LOG(ERROR) << str;
}

void glog_LOG_FATAL__PKc(const char* str) {
LOG(FATAL) << str;
}

void google_FlushLogFiles(google::LogSeverity severity) {
google::FlushLogFiles(severity);
}
18 changes: 18 additions & 0 deletions C/mediapipe_api/external/glog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef C_MEDIAPIPE_API_EXTERNAL_GLOG_H_
#define C_MEDIAPIPE_API_EXTERNAL_GLOG_H_

#include <string>
#include "mediapipe_api/common.h"

extern "C" {

MP_CAPI(void) glog_LOG_INFO__PKc(const char* str);
MP_CAPI(void) glog_LOG_WARNING__PKc(const char* str);
MP_CAPI(void) glog_LOG_ERROR__PKc(const char* str);
MP_CAPI(void) glog_LOG_FATAL__PKc(const char* str);

MP_CAPI(void) google_FlushLogFiles(google::LogSeverity severity);

} // extern "C"

#endif // C_MEDIAPIPE_API_EXTERNAL_GLOG_H_

0 comments on commit 085f7cc

Please sign in to comment.