Skip to content

Instantly share code, notes, and snippets.

@hannes
Created April 14, 2015 12:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hannes/5a19a2bd1dcfb66fc477 to your computer and use it in GitHub Desktop.
Save hannes/5a19a2bd1dcfb66fc477 to your computer and use it in GitHub Desktop.
#include <assert.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <math.h>
#include <stdlib.h>
#if defined(_MSC_VER) || defined(__WIN32__)
#else
#define HAVE_NL_LANGINFO /* not on Windows, probably everywhere else */
#endif
#ifdef HAVE_NL_LANGINFO
#include <langinfo.h>
#endif
// trace output format and columns
#define TRACE_NCOLS 14
#define TRACE_COL_QUERYID 2
#define TRACE_COL_STATEFL 4
#define TRACE_COL_MALSTMT 13
#define TRACE_MAL_MAXPARAMS 3 // we don't need more than 3 params here
// size of the progress bar in characters
#define PROFILER_BARSYMB 60
static SOCKET profiler_socket;
#ifdef _MSC_VER
static HANDLE profiler_pthread;
#else
static pthread_t profiler_pthread;
#endif
static int profiler_needcleanup = 0;
static int profiler_armed = 0;
static char* profiler_symb_query = "X";
static char* profiler_symb_trans = "V";
static char* profiler_symb_bfree = "_";
static char* profiler_symb_bfull = "#";
// clear line and overwrite with spaces
void profiler_clearbar(void) {
int bs;
if (!profiler_needcleanup) return;
for (bs=0; bs < PROFILER_BARSYMB + 3 + 6; bs++) printf("\b \b");
profiler_needcleanup = 0;
}
void profiler_renderbar(size_t state, size_t total, char *symbol) {
int bs;
unsigned short percentage, symbols;
profiler_clearbar();
profiler_needcleanup = 1;
percentage = (unsigned short) ceil((1.0 *
state / total) * 100);
symbols = (unsigned short) (PROFILER_BARSYMB*(percentage/100.0));
printf("%s ", symbol);
for (bs=0; bs < symbols; bs++) printf("%s", profiler_symb_bfull);
for (bs=0; bs < PROFILER_BARSYMB-symbols; bs++) printf("%s", profiler_symb_bfree);
printf(" %3u%% ", (unsigned int) percentage);
fflush(NULL);
}
#ifdef HAVE_NL_LANGINFO
if (strcasecmp(nl_langinfo(CODESET), "utf-8") == 0) {
profiler_symb_query = "\342\237\262"; /* U+27F2 */
profiler_symb_trans = "\342\206\223"; /* U+2193 */
profiler_symb_bfree = "\342\226\221"; /* U+2591 */
profiler_symb_bfull = "\342\226\210"; /* U+2588 */
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment