WEAK void sampling_profiler_thread(void *) { halide_profiler_state *s = halide_profiler_get_state(); // grab the lock halide_mutex_lock(&s->lock); while (s->current_func != halide_profiler_please_stop) { uint64_t t1 = halide_current_time_ns(NULL); uint64_t t = t1; while (1) { uint64_t t_now = halide_current_time_ns(NULL); int func = s->current_func; if (func == halide_profiler_please_stop) { break; } else if (func >= 0) { // Assume all time since I was last awake is due to // the currently running func. bill_func(s, func, t_now - t); } t = t_now; // Release the lock, sleep, reacquire. int sleep_ms = s->sleep_time; halide_mutex_unlock(&s->lock); halide_sleep_ms(NULL, sleep_ms); halide_mutex_lock(&s->lock); } } s->started = false; halide_mutex_unlock(&s->lock); }
WEAK void sampling_profiler_thread(void *) { halide_profiler_state *s = halide_profiler_get_state(); // grab the lock halide_mutex_lock(&s->lock); while (s->current_func != halide_profiler_please_stop) { uint64_t t1 = halide_current_time_ns(NULL); uint64_t t = t1; while (1) { int func, active_threads; if (s->get_remote_profiler_state) { // Execution has disappeared into remote code running // on an accelerator (e.g. Hexagon DSP) s->get_remote_profiler_state(&func, &active_threads); } else { func = s->current_func; active_threads = s->active_threads; } uint64_t t_now = halide_current_time_ns(NULL); if (func == halide_profiler_please_stop) { break; } else if (func >= 0) { // Assume all time since I was last awake is due to // the currently running func. bill_func(s, func, t_now - t, active_threads); } t = t_now; // Release the lock, sleep, reacquire. int sleep_ms = s->sleep_time; halide_mutex_unlock(&s->lock); halide_sleep_ms(NULL, sleep_ms); halide_mutex_lock(&s->lock); } } s->started = false; halide_mutex_unlock(&s->lock); }