/* * Copyright 2011-2014 Formal Methods and Tools, University of Twente * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include // for errno #include // memset #include #include #include #include // for nodes table #if SYLVAN_STATS #ifdef __ELF__ __thread sylvan_stats_t sylvan_stats; #else pthread_key_t sylvan_stats_key; #endif #ifndef USE_HWLOC #define USE_HWLOC 0 #endif #if USE_HWLOC #include static hwloc_topology_t topo; #endif VOID_TASK_0(sylvan_stats_reset_perthread) { #ifdef __ELF__ for (int i=0; icpuset, HWLOC_MEMBIND_BIND, 0); #endif pthread_setspecific(sylvan_stats_key, sylvan_stats); } for (int i=0; icounters[i] = 0; } for (int i=0; itimers[i] = 0; } #endif } VOID_TASK_IMPL_0(sylvan_stats_init) { #ifndef __ELF__ pthread_key_create(&sylvan_stats_key, NULL); #endif #if USE_HWLOC hwloc_topology_init(&topo); hwloc_topology_load(topo); #endif TOGETHER(sylvan_stats_reset_perthread); } /** * Reset all counters (for statistics) */ VOID_TASK_IMPL_0(sylvan_stats_reset) { TOGETHER(sylvan_stats_reset_perthread); } #define BLACK "\33[22;30m" #define GRAY "\33[01;30m" #define RED "\33[22;31m" #define LRED "\33[01;31m" #define GREEN "\33[22;32m" #define LGREEN "\33[01;32m" #define BLUE "\33[22;34m" #define LBLUE "\33[01;34m" #define BROWN "\33[22;33m" #define YELLOW "\33[01;33m" #define CYAN "\33[22;36m" #define LCYAN "\33[22;36m" #define MAGENTA "\33[22;35m" #define LMAGENTA "\33[01;35m" #define NC "\33[0m" #define BOLD "\33[1m" #define ULINE "\33[4m" //underline #define BLINK "\33[5m" #define INVERT "\33[7m" VOID_TASK_1(sylvan_stats_sum, sylvan_stats_t*, target) { #ifdef __ELF__ for (int i=0; icounters[i], sylvan_stats.counters[i]); } for (int i=0; itimers[i], sylvan_stats.timers[i]); } #else sylvan_stats_t *sylvan_stats = pthread_getspecific(sylvan_stats_key); if (sylvan_stats != NULL) { for (int i=0; icounters[i], sylvan_stats->counters[i]); } for (int i=0; itimers[i], sylvan_stats->timers[i]); } } #endif } void sylvan_stats_report(FILE *target, int color) { #if !SYLVAN_STATS (void)target; (void)color; return; #else (void)color; sylvan_stats_t totals; memset(&totals, 0, sizeof(sylvan_stats_t)); LACE_ME; TOGETHER(sylvan_stats_sum, &totals); // fix timers for MACH #ifdef __MACH__ mach_timebase_info_data_t timebase; mach_timebase_info(&timebase); uint64_t c = timebase.numer/timebase.denom; for (int i=0;i