Add time_in_seconds function
This commit is contained in:
		@@ -61,6 +61,8 @@ u64 read_cpu_timer(void);
 | 
				
			|||||||
// CPU frequency in hz/sec
 | 
					// CPU frequency in hz/sec
 | 
				
			||||||
u64 get_cpu_freq(u64 milliseconds);
 | 
					u64 get_cpu_freq(u64 milliseconds);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					f64 time_in_seconds(u64 cpu_time, u64 cpu_freq);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void profile_start(u64 count);
 | 
					void profile_start(u64 count);
 | 
				
			||||||
void profile_end();
 | 
					void profile_end();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -38,12 +38,13 @@ u64 read_cpu_timer(void) { return __rdtsc(); }
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
u64 get_cpu_freq(u64 milliseconds) {
 | 
					u64 get_cpu_freq(u64 milliseconds) {
 | 
				
			||||||
  u64 os_freq = get_os_frequency();
 | 
					  u64 os_freq = get_os_frequency();
 | 
				
			||||||
  u64 os_start = get_os_time();
 | 
					 | 
				
			||||||
  u64 cpu_start = read_cpu_timer();
 | 
					 | 
				
			||||||
  u64 os_end = 0;
 | 
					  u64 os_end = 0;
 | 
				
			||||||
  u64 os_elapsed = 0;
 | 
					  u64 os_elapsed = 0;
 | 
				
			||||||
  u64 os_wait_time = os_freq * milliseconds / 1000;
 | 
					  u64 os_wait_time = os_freq * milliseconds / 1000;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  u64 os_start = get_os_time();
 | 
				
			||||||
 | 
					  u64 cpu_start = read_cpu_timer();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  while (os_elapsed < os_wait_time) {
 | 
					  while (os_elapsed < os_wait_time) {
 | 
				
			||||||
    os_end = get_os_time();
 | 
					    os_end = get_os_time();
 | 
				
			||||||
    os_elapsed = os_end - os_start;
 | 
					    os_elapsed = os_end - os_start;
 | 
				
			||||||
@@ -61,6 +62,10 @@ u64 get_cpu_freq(u64 milliseconds) {
 | 
				
			|||||||
  return cpu_freq;
 | 
					  return cpu_freq;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					f64 time_in_seconds(u64 cpu_time, u64 cpu_freq) {
 | 
				
			||||||
 | 
					  return (f64)cpu_time / cpu_freq;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void profile_start(u64 count) {
 | 
					void profile_start(u64 count) {
 | 
				
			||||||
  profiler.cpu_freq = get_cpu_freq(1000);
 | 
					  profiler.cpu_freq = get_cpu_freq(1000);
 | 
				
			||||||
  profiler.start = read_cpu_timer();
 | 
					  profiler.start = read_cpu_timer();
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user