c - Calculate execution time of all the function -
this project has many functions of them takes lot of time execute. now task find functions tasks of time.
here steps:
write macro calculate execution time
#ifndef _calculate_exe_time_ #define _calculate_exe_time_ #include <time.h> #include <stdio.h> #define calculate_exe_time static clock_t cet_start_time, cet_end_time; \ static float cet_expend_time, cet_total_expend_time; \ static unsigned int cet_invoked_times = 0; \ cet_start_time = clock(); \ #define cet_before_return cet_end_time = clock(); \ cet_expend_time = (float)(cet_end_time - cet_start_time) / clocks_per_sec; \ cet_total_expend_time += cet_expend_time; \ printf("===%s:%s() invoked_times=%u expend_time=%.4fs total_expend_time=%.4fs\n", \ __file__, __function__, ++cet_invoked_times, cet_expend_time, cet_total_expend_time); #endif // _calculate_exe_time_
2.put macros functions
static void john_register_one(struct fmt_main *format) { calculate_exe_time // cet_before_return } many other functions many other functions static char *john_loaded_counts(void) { calculate_exe_time static char s_loaded_counts[80]; if (database.password_count == 1) { cet_before_return return "1 password hash"; } cet_before_return return s_loaded_counts; }
run
===wordlist.c:mgetl() invoked_times=1893 expend_time=0.0000s total_expend_time=0.0082s ===cracker.c:crk_process_key() invoked_times=1880 expend_time=0.0000s total_expend_time=0.0097s ===cracker.c:crk_process_event() invoked_times=10 expend_time=0.0000s total_expend_time=0.0011s ===cracker.c:crk_password_loop() invoked_times=235 expend_time=0.0000s total_expend_time=208.5752s ===cracker.c:crk_salt_loop() invoked_times=235 expend_time=0.0000s total_expend_time=208.6260s ===cracker.c:crk_done() invoked_times=1 expend_time=0.0000s total_expend_time=0.0000s ===wordlist.c:get_progress() invoked_times=2 expend_time=0.0000s total_expend_time=0.0000s ===wordlist.c:save_state() invoked_times=2 expend_time=0.0000s total_expend_time=0.0000s ===wordlist.c:do_wordlist_crack() invoked_times=1 expend_time=208.9100s total_expend_time=208.9100s ===batch.c:do_wordlist_pass() invoked_times=1 expend_time=208.9100s total_expend_time=208.9100s ===batch.c:do_batch_crack() invoked_times=1 expend_time=208.9109s total_expend_time=208.9109s ===wordlist.c:get_progress() invoked_times=3 expend_time=0.0000s total_expend_time=0.0000s ===cracker.c:crk_get_key2() invoked_times=1 expend_time=0.0000s total_expend_time=0.0000s
here questions:
i have put calculate_exe_time , cet_before_return all functions manually! it's huge work! is there way automatically?
i have thought put cet_before_return destructors can invoked after function returns. gcc not support class destructor.
i suggest using profile tool, vtune vs or instruments xcode don't need add ugly code calculate execution time, can slow down execution , make results less accurate. profiling tools provide more information,such locating performance bottlenecks.
Comments
Post a Comment