Skip to content

Commit

Permalink
Refactor verbosity code - try to avoid log calls if verbosity is not
Browse files Browse the repository at this point in the history
set
  • Loading branch information
inactive123 committed Jan 17, 2018
1 parent 78adf0c commit 11f26ed
Show file tree
Hide file tree
Showing 12 changed files with 151 additions and 116 deletions.
33 changes: 18 additions & 15 deletions audio/audio_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -618,20 +618,20 @@ static void audio_driver_flush(const int16_t *data, size_t samples)
double direction = (double)delta_mid / half_size;
double adjust = 1.0 + audio_driver_rate_control_delta * direction;

#if 0
RARCH_LOG_OUTPUT("[Audio]: Audio buffer is %u%% full\n",
(unsigned)(100 - (avail * 100) / audio_driver_buffer_size));
#endif

audio_driver_free_samples_buf
[write_idx] = avail;
audio_source_ratio_current =
audio_source_ratio_original * adjust;

#if 0
RARCH_LOG_OUTPUT("[Audio]: New rate: %lf, Orig rate: %lf\n",
audio_source_ratio_current,
audio_source_ratio_original);
if (verbosity_is_enabled())
{
RARCH_LOG_OUTPUT("[Audio]: Audio buffer is %u%% full\n",
(unsigned)(100 - (avail * 100) / audio_driver_buffer_size));
RARCH_LOG_OUTPUT("[Audio]: New rate: %lf, Orig rate: %lf\n",
audio_source_ratio_current,
audio_source_ratio_original);
}
#endif
}

Expand Down Expand Up @@ -862,13 +862,16 @@ bool audio_driver_find_driver(void)
current_audio = (const audio_driver_t*)audio_driver_find_handle(i);
else
{
unsigned d;
RARCH_ERR("Couldn't find any audio driver named \"%s\"\n",
settings->arrays.audio_driver);
RARCH_LOG_OUTPUT("Available audio drivers are:\n");
for (d = 0; audio_driver_find_handle(d); d++)
RARCH_LOG_OUTPUT("\t%s\n", audio_driver_find_ident(d));
RARCH_WARN("Going to default to first audio driver...\n");
if (verbosity_is_enabled())
{
unsigned d;
RARCH_ERR("Couldn't find any audio driver named \"%s\"\n",
settings->arrays.audio_driver);
RARCH_LOG_OUTPUT("Available audio drivers are:\n");
for (d = 0; audio_driver_find_handle(d); d++)
RARCH_LOG_OUTPUT("\t%s\n", audio_driver_find_ident(d));
RARCH_WARN("Going to default to first audio driver...\n");
}

current_audio = (const audio_driver_t*)audio_driver_find_handle(0);

Expand Down
19 changes: 11 additions & 8 deletions camera/camera_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,17 @@ bool camera_driver_ctl(enum rarch_camera_ctl_state state, void *data)
camera_driver = (const camera_driver_t*)camera_driver_find_handle(i);
else
{
unsigned d;
RARCH_ERR("Couldn't find any camera driver named \"%s\"\n",
settings->arrays.camera_driver);
RARCH_LOG_OUTPUT("Available camera drivers are:\n");
for (d = 0; camera_driver_find_handle(d); d++)
RARCH_LOG_OUTPUT("\t%s\n", camera_driver_find_ident(d));

RARCH_WARN("Going to default to first camera driver...\n");
if (verbosity_is_enabled())
{
unsigned d;
RARCH_ERR("Couldn't find any camera driver named \"%s\"\n",
settings->arrays.camera_driver);
RARCH_LOG_OUTPUT("Available camera drivers are:\n");
for (d = 0; camera_driver_find_handle(d); d++)
RARCH_LOG_OUTPUT("\t%s\n", camera_driver_find_ident(d));

RARCH_WARN("Going to default to first camera driver...\n");
}

camera_driver = (const camera_driver_t*)camera_driver_find_handle(0);

Expand Down
3 changes: 3 additions & 0 deletions dynamic.c
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,9 @@ static void rarch_log_libretro(enum retro_log_level level,
if ((unsigned)level < settings->uints.libretro_log_level)
return;

if (!verbosity_is_enabled())
return;

va_start(vp, fmt);

switch (level)
Expand Down
17 changes: 10 additions & 7 deletions gfx/video_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -1843,13 +1843,16 @@ bool video_driver_find_driver(void)
current_video = (video_driver_t*)video_driver_find_handle(i);
else
{
unsigned d;
RARCH_ERR("Couldn't find any video driver named \"%s\"\n",
settings->arrays.video_driver);
RARCH_LOG_OUTPUT("Available video drivers are:\n");
for (d = 0; video_driver_find_handle(d); d++)
RARCH_LOG_OUTPUT("\t%s\n", video_driver_find_ident(d));
RARCH_WARN("Going to default to first video driver...\n");
if (verbosity_is_enabled())
{
unsigned d;
RARCH_ERR("Couldn't find any video driver named \"%s\"\n",
settings->arrays.video_driver);
RARCH_LOG_OUTPUT("Available video drivers are:\n");
for (d = 0; video_driver_find_handle(d); d++)
RARCH_LOG_OUTPUT("\t%s\n", video_driver_find_ident(d));
RARCH_WARN("Going to default to first video driver...\n");
}

current_video = (video_driver_t*)video_driver_find_handle(0);

Expand Down
3 changes: 0 additions & 3 deletions libretro-common/file/archive_file_7z.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,6 @@ static int sevenzip_file_read(
{
size_t output_size = 0;

/*RARCH_LOG_OUTPUT("Opened archive %s. Now trying to extract %s\n",
path, needle);*/

/* C LZMA SDK does not support chunked extraction - see here:
* sourceforge.net/p/sevenzip/discussion/45798/thread/6fb59aaf/
* */
Expand Down
20 changes: 12 additions & 8 deletions location/location_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,18 @@ void find_location_driver(void)
location_driver = (const location_driver_t*)location_driver_find_handle(i);
else
{
unsigned d;
RARCH_ERR("Couldn't find any location driver named \"%s\"\n",
settings->arrays.location_driver);
RARCH_LOG_OUTPUT("Available location drivers are:\n");
for (d = 0; location_driver_find_handle(d); d++)
RARCH_LOG_OUTPUT("\t%s\n", location_driver_find_ident(d));

RARCH_WARN("Going to default to first location driver...\n");

if (verbosity_is_enabled())
{
unsigned d;
RARCH_ERR("Couldn't find any location driver named \"%s\"\n",
settings->arrays.location_driver);
RARCH_LOG_OUTPUT("Available location drivers are:\n");
for (d = 0; location_driver_find_handle(d); d++)
RARCH_LOG_OUTPUT("\t%s\n", location_driver_find_ident(d));

RARCH_WARN("Going to default to first location driver...\n");
}

location_driver = (const location_driver_t*)location_driver_find_handle(0);

Expand Down
17 changes: 10 additions & 7 deletions menu/menu_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -1847,13 +1847,16 @@ bool menu_driver_ctl(enum rarch_menu_ctl_state state, void *data)
menu_driver_find_handle(i);
else
{
unsigned d;
RARCH_WARN("Couldn't find any menu driver named \"%s\"\n",
settings->arrays.menu_driver);
RARCH_LOG_OUTPUT("Available menu drivers are:\n");
for (d = 0; menu_driver_find_handle(d); d++)
RARCH_LOG_OUTPUT("\t%s\n", menu_driver_find_ident(d));
RARCH_WARN("Going to default to first menu driver...\n");
if (verbosity_is_enabled())
{
unsigned d;
RARCH_WARN("Couldn't find any menu driver named \"%s\"\n",
settings->arrays.menu_driver);
RARCH_LOG_OUTPUT("Available menu drivers are:\n");
for (d = 0; menu_driver_find_handle(d); d++)
RARCH_LOG_OUTPUT("\t%s\n", menu_driver_find_ident(d));
RARCH_WARN("Going to default to first menu driver...\n");
}

menu_driver_ctx = (const menu_ctx_driver_t*)
menu_driver_find_handle(0);
Expand Down
1 change: 1 addition & 0 deletions qb/config.params.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ HAVE_MINIUPNPC=auto # Mini UPnP client library (for NAT traversal)
HAVE_BUILTINMINIUPNPC=yes # Bake in Mini UPnP client library (for NAT traversal)
C89_BUILTINMINIUPNPC=no
HAVE_D3D9=yes # Direct3D 9 support
HAVE_D3DX=yes # Direct3DX support
HAVE_OPENGL=auto # OpenGL support
HAVE_MALI_FBDEV=no # Mali fbdev context support
HAVE_VIVANTE_FBDEV=no # Vivante fbdev context support
Expand Down
19 changes: 11 additions & 8 deletions record/record_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,17 @@ void find_record_driver(void)
recording_driver = (const record_driver_t*)record_driver_find_handle(i);
else
{
unsigned d;

RARCH_ERR("Couldn't find any record driver named \"%s\"\n",
settings->arrays.record_driver);
RARCH_LOG_OUTPUT("Available record drivers are:\n");
for (d = 0; record_driver_find_handle(d); d++)
RARCH_LOG_OUTPUT("\t%s\n", record_driver_find_ident(d));
RARCH_WARN("Going to default to first record driver...\n");
if (verbosity_is_enabled())
{
unsigned d;

RARCH_ERR("Couldn't find any record driver named \"%s\"\n",
settings->arrays.record_driver);
RARCH_LOG_OUTPUT("Available record drivers are:\n");
for (d = 0; record_driver_find_handle(d); d++)
RARCH_LOG_OUTPUT("\t%s\n", record_driver_find_ident(d));
RARCH_WARN("Going to default to first record driver...\n");
}

recording_driver = (const record_driver_t*)record_driver_find_handle(0);

Expand Down
94 changes: 45 additions & 49 deletions verbosity.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,22 +124,20 @@ void RARCH_LOG_V(const char *tag, const char *fmt, va_list ap)
#if TARGET_OS_IPHONE
static int asl_initialized = 0;
#if !TARGET_IPHONE_SIMULATOR
static aslclient asl_client;
static aslclient asl_client;
#endif
#else
FILE *fp = NULL;
(void)fp;
#endif

if (!verbosity_is_enabled())
return;
#if TARGET_OS_IPHONE
#if TARGET_IPHONE_SIMULATOR
vprintf(fmt, ap);
#else
if (!asl_initialized)
{
asl_client = asl_open(file_path_str(FILE_PATH_PROGRAM_NAME), "com.apple.console", ASL_OPT_STDERR | ASL_OPT_NO_DELAY);
asl_client = asl_open(
file_path_str(FILE_PATH_PROGRAM_NAME),
"com.apple.console",
ASL_OPT_STDERR | ASL_OPT_NO_DELAY);
asl_initialized = 1;
}
aslmsg msg = asl_new(ASL_TYPE_MSG);
Expand All @@ -151,42 +149,47 @@ static aslclient asl_client;
#endif
#elif defined(_XBOX1)
{
/* FIXME: Using arbitrary string as fmt argument is unsafe. */
char msg_new[1024];
char buffer[1024];

msg_new[0] = buffer[0] = '\0';
snprintf(msg_new, sizeof(msg_new), "%s: %s %s",
file_path_str(FILE_PATH_PROGRAM_NAME),
tag ? tag : "",
fmt);
wvsprintf(buffer, msg_new, ap);
OutputDebugStringA(buffer);
/* FIXME: Using arbitrary string as fmt argument is unsafe. */
char msg_new[1024];
char buffer[1024];

msg_new[0] = buffer[0] = '\0';
snprintf(msg_new, sizeof(msg_new), "%s: %s %s",
file_path_str(FILE_PATH_PROGRAM_NAME),
tag ? tag : "",
fmt);
wvsprintf(buffer, msg_new, ap);
OutputDebugStringA(buffer);
}
#elif defined(ANDROID)
int prio = ANDROID_LOG_INFO;
if (tag)
{
if (string_is_equal(file_path_str(FILE_PATH_LOG_WARN), tag))
prio = ANDROID_LOG_WARN;
else if (string_is_equal(file_path_str(FILE_PATH_LOG_ERROR), tag))
prio = ANDROID_LOG_ERROR;
int prio = ANDROID_LOG_INFO;
if (tag)
{
if (string_is_equal(file_path_str(FILE_PATH_LOG_WARN), tag))
prio = ANDROID_LOG_WARN;
else if (string_is_equal(file_path_str(FILE_PATH_LOG_ERROR), tag))
prio = ANDROID_LOG_ERROR;
}
__android_log_vprint(prio,
file_path_str(FILE_PATH_PROGRAM_NAME),
fmt,
ap);
}
__android_log_vprint(prio,
file_path_str(FILE_PATH_PROGRAM_NAME),
fmt,
ap);
#else

{
#ifdef HAVE_FILE_LOGGER
fp = (FILE*)retro_main_log_file();
FILE *fp = (FILE*)retro_main_log_file();
#else
fp = stderr;
FILE *fp = stderr;
#endif
fprintf(fp, "%s ",
tag ? tag : file_path_str(FILE_PATH_LOG_INFO));
vfprintf(fp, fmt, ap);
fflush(fp);

fprintf(fp, "%s ",
tag ? tag : file_path_str(FILE_PATH_LOG_INFO));
vfprintf(fp, fmt, ap);
fflush(fp);
}
#endif
}

Expand All @@ -202,11 +205,6 @@ void RARCH_LOG(const char *fmt, ...)
va_end(ap);
}

void RARCH_LOG_OUTPUT_V(const char *tag, const char *msg, va_list ap)
{
RARCH_LOG_V(tag, msg, ap);
}

void RARCH_LOG_OUTPUT(const char *msg, ...)
{
va_list ap;
Expand All @@ -215,28 +213,26 @@ void RARCH_LOG_OUTPUT(const char *msg, ...)
va_end(ap);
}

void RARCH_WARN_V(const char *tag, const char *fmt, va_list ap)
{
RARCH_LOG_V(tag, fmt, ap);
}

void RARCH_WARN(const char *fmt, ...)
{
va_list ap;

if (!verbosity_is_enabled())
return;

va_start(ap, fmt);
RARCH_WARN_V(file_path_str(FILE_PATH_LOG_WARN), fmt, ap);
va_end(ap);
}

void RARCH_ERR_V(const char *tag, const char *fmt, va_list ap)
{
RARCH_LOG_V(tag, fmt, ap);
}

void RARCH_ERR(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);

if (!verbosity_is_enabled())
return;

RARCH_ERR_V(file_path_str(FILE_PATH_LOG_ERROR), fmt, ap);
va_end(ap);
}
Expand Down
22 changes: 19 additions & 3 deletions verbosity.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <boolean.h>
#include <retro_common_api.h>
#include <retro_inline.h>

#ifdef HAVE_CONFIG_H
#include "config.h"
Expand Down Expand Up @@ -128,12 +129,27 @@ void logger_send_v(const char *__format, va_list args);
#else
void RARCH_LOG_V(const char *tag, const char *fmt, va_list ap);
void RARCH_LOG(const char *fmt, ...);
void RARCH_LOG_OUTPUT_V(const char *tag, const char *msg, va_list ap);
void RARCH_LOG_OUTPUT(const char *msg, ...);
void RARCH_WARN_V(const char *tag, const char *fmt, va_list ap);
void RARCH_WARN(const char *fmt, ...);
void RARCH_ERR_V(const char *tag, const char *fmt, va_list ap);
void RARCH_ERR(const char *fmt, ...);

static INLINE void RARCH_LOG_OUTPUT_V(const char *tag,
const char *msg, va_list ap)
{
RARCH_LOG_V(tag, msg, ap);
}

static INLINE void RARCH_WARN_V(const char *tag,
const char *fmt, va_list ap)
{
RARCH_LOG_V(tag, fmt, ap);
}

static INLINE void RARCH_ERR_V(const char *tag,
const char *fmt, va_list ap)
{
RARCH_LOG_V(tag, fmt, ap);
}
#endif

RETRO_END_DECLS
Expand Down
Loading

0 comments on commit 11f26ed

Please sign in to comment.