From 77d8caa332cd4d0aba009420ff585657c8a94432 Mon Sep 17 00:00:00 2001 From: Geoff Langdale Date: Mon, 7 May 2018 21:33:23 +1000 Subject: [PATCH] Allow a -DSQUASH_COUNTERS to suppress counters at build time (e.g. for using other tools like toplev) --- main.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/main.cpp b/main.cpp index 4939664df..9ccb2149d 100644 --- a/main.cpp +++ b/main.cpp @@ -736,7 +736,11 @@ int main(int argc, char * argv[]) { vector res; res.resize(iterations); -#ifdef __linux__ +#if !defined(__linux__) +#define SQUASH_COUNTERS +#endif + +#ifndef SQUASH_COUNTERS LinuxEvents cycles(PERF_COUNT_HW_CPU_CYCLES); LinuxEvents instructions(PERF_COUNT_HW_INSTRUCTIONS); unsigned long cy1 = 0, cy2 = 0, cy3 = 0, cy4 = 0; @@ -744,33 +748,33 @@ int main(int argc, char * argv[]) { #endif for (u32 i = 0; i < iterations; i++) { auto start = std::chrono::steady_clock::now(); -#ifdef __linux__ +#ifndef SQUASH_COUNTERS cycles.start(); instructions.start(); #endif find_structural_bits(p.first, p.second, pj); -#ifdef __linux__ +#ifndef SQUASH_COUNTERS cl1 += instructions.end(); cy1 += cycles.end(); cycles.start(); instructions.start(); #endif flatten_indexes(p.second, pj); -#ifdef __linux__ +#ifndef SQUASH_COUNTERS cl2 += instructions.end(); cy2 += cycles.end(); cycles.start(); instructions.start(); #endif ape_machine(p.first, p.second, pj); -#ifdef __linux__ +#ifndef SQUASH_COUNTERS cl3 += instructions.end(); cy3 += cycles.end(); cycles.start(); instructions.start(); #endif shovel_machine(p.first, p.second, pj); -#ifdef __linux__ +#ifndef SQUASH_COUNTERS cl4 += instructions.end(); cy4 += cycles.end(); #endif auto end = std::chrono::steady_clock::now(); std::chrono::duration secs = end - start; res[i] = secs.count(); } -#ifdef __linux__ +#ifndef SQUASH_COUNTERS printf("number of bytes %ld number of structural chars %d ratio %.3f\n", p.second, pj.n_structural_indexes, (double) pj.n_structural_indexes / p.second); unsigned long total = cy1 + cy2 + cy3 + cy4;