-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
log: refine log function for Android #2071
Open
zhouwg
wants to merge
2
commits into
ggerganov:master
Choose a base branch
from
zhouwg:refine-log-subsystem
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
|
@@ -108,6 +108,9 @@ static void byteswap_tensor(ggml_tensor * tensor) { | |
#define BYTESWAP_TENSOR(t) do {} while (0) | ||
#endif | ||
|
||
#if (defined __ANDROID__) || (defined ANDROID) | ||
#define WHISPER_ATTRIBUTE_FORMAT(...) | ||
#else | ||
#ifdef __GNUC__ | ||
#ifdef __MINGW32__ | ||
#define WHISPER_ATTRIBUTE_FORMAT(...) __attribute__((format(gnu_printf, __VA_ARGS__))) | ||
|
@@ -117,24 +120,29 @@ static void byteswap_tensor(ggml_tensor * tensor) { | |
#else | ||
#define WHISPER_ATTRIBUTE_FORMAT(...) | ||
#endif | ||
#endif | ||
|
||
// | ||
// logging | ||
// | ||
#if (defined __ANDROID__) || (defined ANDROID) | ||
extern "C" int __android_log_print(int prio, const char * tag, const char * fmt, ...) | ||
__attribute__((__format__(printf, 3, 4))); | ||
#endif | ||
|
||
WHISPER_ATTRIBUTE_FORMAT(2, 3) | ||
static void whisper_log_internal (ggml_log_level level, const char * format, ...); | ||
WHISPER_ATTRIBUTE_FORMAT(5, 6) | ||
static void whisper_log_internal (ggml_log_level level, const char * file, const char * func, int line, const char * format, ...); | ||
static void whisper_log_callback_default(ggml_log_level level, const char * text, void * user_data); | ||
|
||
#define WHISPER_LOG_ERROR(...) whisper_log_internal(GGML_LOG_LEVEL_ERROR, __VA_ARGS__) | ||
#define WHISPER_LOG_WARN(...) whisper_log_internal(GGML_LOG_LEVEL_WARN , __VA_ARGS__) | ||
#define WHISPER_LOG_INFO(...) whisper_log_internal(GGML_LOG_LEVEL_INFO , __VA_ARGS__) | ||
#define WHISPER_LOG_ERROR(...) whisper_log_internal(GGML_LOG_LEVEL_ERROR, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__) | ||
#define WHISPER_LOG_WARN(...) whisper_log_internal(GGML_LOG_LEVEL_WARN , __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__) | ||
#define WHISPER_LOG_INFO(...) whisper_log_internal(GGML_LOG_LEVEL_INFO , __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__) | ||
|
||
// define this to enable verbose trace logging - useful for debugging purposes | ||
//#define WHISPER_DEBUG | ||
|
||
#if defined(WHISPER_DEBUG) | ||
#define WHISPER_LOG_DEBUG(...) whisper_log_internal(GGML_LOG_LEVEL_DEBUG, __VA_ARGS__) | ||
#define WHISPER_LOG_DEBUG(...) whisper_log_internal(GGML_LOG_LEVEL_DEBUG, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__) | ||
#else | ||
#define WHISPER_LOG_DEBUG(...) | ||
#endif | ||
|
@@ -7196,14 +7204,19 @@ void whisper_log_set(ggml_log_callback log_callback, void * user_data) { | |
g_state.log_callback_user_data = user_data; | ||
} | ||
|
||
GGML_ATTRIBUTE_FORMAT(2, 3) | ||
static void whisper_log_internal(ggml_log_level level, const char * format, ...) { | ||
GGML_ATTRIBUTE_FORMAT(5, 6) | ||
static void whisper_log_internal(ggml_log_level level, const char * file, const char * func, int line, const char * format, ...) { | ||
va_list args; | ||
va_start(args, format); | ||
char buffer[1024]; | ||
int len = vsnprintf(buffer, 1024, format, args); | ||
if (len < 1024) { | ||
int len_prefix = snprintf(buffer, 1024, "[%s, %d]: ", func, line); // param file not used in this file | ||
int len = vsnprintf(buffer + len_prefix, 1024 - len_prefix, format, args); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if |
||
if (len < (1024 - len_prefix)) { | ||
#if (defined __ANDROID__) || (defined ANDROID) | ||
__android_log_print(level, "whisper.cpp", "%s", buffer); | ||
#else | ||
g_state.log_callback(level, buffer, g_state.log_callback_user_data); | ||
#endif | ||
} else { | ||
char* buffer2 = new char[len+1]; | ||
vsnprintf(buffer2, len+1, format, args); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why add these three parameters at such a low level?