#include <stdlib.h>
#include <unistd.h>
#include <Profiler.h>

void usage(void);

std::string samplefile("/tmp/samples.out");

// this global (sorry) indicates that the process should exit upon certain
// errors.  Initially it is being used to exit if a .so file cannot be
// mapped
bool g_quitOnError = false;

int
main(int argc, char *argv[])
{
    int ch;
    bool showlines = false;
    g_quitOnError = false;
    while ((ch = getopt(argc, argv, "qlf:")) != -1)
    {
        switch (ch)
        {
        case 'f':
            samplefile = optarg;
            break;
        case 'l':
            showlines = true;
            break;
        case 'q':
            g_quitOnError = true;
            break;
        case '?':
        default:
            usage();
            break;
        }
    }
    argc -= optind;
    argv += optind;

    Profiler profiler(samplefile, showlines);
    profiler.createProfile();
    return 0;
}

void
usage()
{
    fprintf(stderr,
            "usage: profiler [-lq] [-f samplefile]\n"
            "    l - show line numbers\n"
            "    q - quit on error\n"
            "    default samplefile is /tmp/samples.out\n");
    exit(1);
}

