Changeset cc36562b in mainline for uspace/lib/c/generic/time.c
- Timestamp:
- 2018-08-25T19:06:27Z (7 years ago)
- Children:
- 72df613
- Parents:
- 02f547f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/time.c
r02f547f rcc36562b 50 50 #include <loc.h> 51 51 #include <device/clock_dev.h> 52 #include <stats.h> 52 53 53 54 #define ASCTIME_BUF_LEN 26 … … 70 71 static async_sess_t *clock_conn = NULL; 71 72 72 /** Return processor time used by the program. 73 * 74 * @return -1 The processor time used is not available in this implementation. 73 /** 74 * Get CPU time used since the process invocation. 75 * 76 * @return Consumed microseconds by this process or -1 if not available. 75 77 */ 76 78 clock_t clock(void) 77 79 { 78 return (clock_t) -1; 80 static_assert(CLOCKS_PER_SEC == 1000000); 81 82 size_t count; 83 stats_cpu_t *cpu_stats = stats_get_cpus(&count); 84 if (!cpu_stats) 85 return (clock_t) -1; 86 87 clock_t total_usecs = -1; 88 if (cpu_stats) { 89 stats_task_t *task_stats = stats_get_task(task_get_id()); 90 if (task_stats) { 91 total_usecs = (clock_t) (task_stats->kcycles + 92 task_stats->ucycles) / cpu_stats->frequency_mhz; 93 free(task_stats); 94 } 95 free(cpu_stats); 96 } 97 98 return total_usecs; 79 99 } 80 100
Note:
See TracChangeset
for help on using the changeset viewer.