-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from edgenai/feat/c-tracing
Feat/c tracing
- Loading branch information
Showing
18 changed files
with
241 additions
and
47 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
[package] | ||
name = "memonitor-sys" | ||
description = "Automatically generated bindings for some of memonitor's backends." | ||
version = "0.2.3" | ||
version = "0.2.4" | ||
authors = ["Pedro Valente <[email protected]>"] | ||
license = "Apache-2.0" | ||
repository = "https://github.com/edgenai/memonitor" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
cmake_minimum_required(VERSION 3.5) | ||
|
||
set(CMAKE_C_STANDARD 11) | ||
set(CMAKE_C_STANDARD_REQUIRED true) | ||
|
||
project(memonitor-log LANGUAGES C) | ||
|
||
add_library(memonitor-log STATIC "include/log.h" "src/log.c") | ||
target_include_directories(memonitor-log PUBLIC "include") | ||
|
||
install(TARGETS memonitor-log | ||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#pragma once | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif // __cplusplus | ||
|
||
#include <stdio.h> | ||
|
||
/** | ||
* The verbosity level of a log event. | ||
*/ | ||
enum log_Level { | ||
Trace, //!< Designates very low priority, often extremely verbose, information. | ||
Debug, //!< Designates lower priority information. | ||
Info, //!< Designates useful information. | ||
Warn, //!< Designates hazardous situations. | ||
Error, //!< Designates very serious errors. | ||
}; | ||
|
||
/** | ||
* The type of a log event function. | ||
* | ||
* @param level The verbosity level of the event. | ||
* @param msg The string message to be logged. | ||
*/ | ||
typedef void (*log_LogFn)(enum log_Level level, const char *msg); | ||
|
||
/** | ||
* Set the global event logging function. | ||
* | ||
* @param fn_ptr A pointer to the event logging function. If `NULL`, the global logger is unset. | ||
*/ | ||
void log_set(log_LogFn fn_ptr); | ||
|
||
/** | ||
* The inner logging function, this should not be called directly, instead the macros defined in the same header | ||
* should be used.. | ||
* | ||
* @param level The verbosity level of the event. | ||
* @param msg The string message to be logged. | ||
*/ | ||
void inner_log(enum log_Level level, const char *msg); | ||
|
||
#define LOG_MSG_SIZE(message, ...) sizeof(message) | ||
#define INNER_LOG(level, ...) { char tmp[LOG_MSG_SIZE(__VA_ARGS__) + 256]; snprintf(tmp, sizeof(tmp), __VA_ARGS__); inner_log(level, tmp); }(0) | ||
|
||
#define LOG_TRACE(...) INNER_LOG(Trace, __VA_ARGS__) | ||
#define LOG_DEBUG(...) INNER_LOG(Debug, __VA_ARGS__) | ||
#define LOG_INFO(...) INNER_LOG(Info, __VA_ARGS__) | ||
#define LOG_WARN(...) INNER_LOG(Warn, __VA_ARGS__) | ||
#define LOG_ERROR(...) INNER_LOG(Error, __VA_ARGS__) | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif // __cplusplus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include <stdlib.h> | ||
|
||
#include <log.h> | ||
|
||
static log_LogFn logger = NULL; | ||
|
||
void log_set(log_LogFn fn_ptr) { | ||
logger = fn_ptr; | ||
} | ||
|
||
void inner_log(enum log_Level level, const char *msg) { | ||
if (logger) { | ||
logger(level, msg); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
//! Automatically generated bindings for the native logger. | ||
#![allow(non_upper_case_globals)] | ||
#![allow(non_camel_case_types)] | ||
#![allow(non_snake_case)] | ||
|
||
include!(concat!(env!("OUT_DIR"), "/log_bindings.rs")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.