From 8d9e187cc9320666848463cb89d3fc5cfda90ab3 Mon Sep 17 00:00:00 2001 From: Mark Kim Date: Mon, 24 Sep 2018 23:00:04 -0400 Subject: [PATCH] More debugging features, performance and macOS update. Added function name to the output of verbose logging. Verbose logging is the feature introduced in the previous git commit where a call to printf() automatically adds the source filename and line from where the printf() is called, and the runtime timestamp at which the call was made. Now this feature adds the functio name from which the printf() is called. This feature is enabled if and only if both DEBUG and VERBOSE are defined in debug.h and the source is compiled with GCC. Added a new macro DEBUG_PRINTF() that expands to printf() if and only if DEBUG is defined in debug.h. This feature works with verbose logging if VERBOSE is also defined and the source is compiled with GCC. Reduced the launch time. A user reported an issue with Tux Paint taking 7 minutes to launch; an investigation showed that launching Tux Paint with all stamps and the screen width set wide (~1500 pixels) can cause the slowdown during the progress bar drawing sequence because progress bar takes a long time to draw on screens with a wide screen, and it is called ~10 thousand times during the stamp loading process. The issue has been addressed by calling the progress bar less frequently. Updated the macOS build version and date, under which these features were tested. --- macos/Info.plist | 6 +++--- src/debug.h | 29 ++++++++++++++++++++++++++++- src/tuxpaint.c | 9 ++++++--- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/macos/Info.plist b/macos/Info.plist index c6b496330..dcff783b5 100644 --- a/macos/Info.plist +++ b/macos/Info.plist @@ -7,7 +7,7 @@ CFBundleExecutable tuxpaint CFBundleGetInfoString - 0.9.23, Copyright 2009-2018, Tux Paint Development Team + 0.9.23a, Copyright 2009-2018, Tux Paint Development Team CFBundleIconFile tuxpaint.icns CFBundleIdentifier @@ -19,10 +19,10 @@ CFBundlePackageType APPL CFBundleShortVersionString - 0.9.23 + 0.9.23a CFBundleSignature TXPT CFBundleVersion - 2018-09-01 + 2018-09-24 diff --git a/src/debug.h b/src/debug.h index 5d5f62a5b..6b90f5637 100644 --- a/src/debug.h +++ b/src/debug.h @@ -13,7 +13,34 @@ #define printf(args...) do { \ time_t now = time(NULL); \ - printf("\n### %s, %d @ %s", __FILE__, __LINE__, ctime(&now)); \ + printf("\n### %s, line %d in %s() @ %s", __FILE__, __LINE__, __FUNCTION__, ctime(&now)); \ printf(args); \ } while(0) #endif + + +/* +* Define a convenience macro DEBUG_PRINTF(). This macro resolves to printf() +* if and only if DEBUG is enabled, otherwise resolves to nothing. In other +* words, +* +* DEBUG_PRINTF("Hello, world!\n"); +* +* ... is equivalent to: +* +* #if defined(DEBUG) +* printf("Hello, world!\n"); +* #endif +* +* (To be precise, the semicolon falls outside of the #if test, but an empty +* semicolon resolves to nothing in standard C.) +* +* If VERBOSE logging is enabled, DEBUG_PRINTF should resolve to the verbose +* version of printf() defined earlier in this file. +*/ +#if defined(DEBUG) +#define DEBUG_PRINTF(...) printf(__VA_ARGS__) +#else +#define DEBUG_PRINTF(...) +#endif + diff --git a/src/tuxpaint.c b/src/tuxpaint.c index fd64d88ba..d0129e1a8 100644 --- a/src/tuxpaint.c +++ b/src/tuxpaint.c @@ -7419,7 +7419,7 @@ static void loadstamp_callback(SDL_Surface * screen, (void)locale; #ifdef DEBUG /* FIXME: Stderr instead of stdout? */ - printf("loadstamp_callback: %s\n", dir); + printf("loadstamp_callback (%d): %s\n", i, dir); #endif if (num_stamps[stamp_group] > 0) @@ -7459,7 +7459,6 @@ static void loadstamp_callback(SDL_Surface * screen, /* Sort and iterate the file list: */ - qsort(files, i, sizeof *files, compare_ftw_str); while (i--) { @@ -7505,7 +7504,11 @@ static void loadstamp_callback(SDL_Surface * screen, } #endif - show_progress_bar(screen); + /* + * Showing the progress bar across the screen can be CPU-intensive, so + * update infrequently. + */ + if((i % 32) == 0) show_progress_bar(screen); if (dotext > files[i].str && !strcasecmp(dotext, ext) && (dotext - files[i].str + 1 + dirlen < (int) (sizeof fname))