Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 06cb827 in mainline


Ignore:
Timestamp:
2011-07-01T23:34:23Z (11 years ago)
Author:
Petr Koupy <petr.koupy@…>
Branches:
lfn, master
Children:
fb872c1
Parents:
a43fbc95
Message:

Implemented clock().

Location:
uspace/lib/posix
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/posix/time.c

    ra43fbc95 r06cb827  
    3838#include "internal/common.h"
    3939#include "time.h"
     40#include "libc/malloc.h"
     41#include <task.h>
     42#include <stats.h>
    4043
    4144/**
     
    8588        // TODO
    8689        if (maxsize >= 1) {
    87                 *s = 0;
     90                *s = '\0';
    8891        }
    8992        return 0;
     
    9194
    9295/**
    93  *
    94  * @return
     96 * Get CPU time used since the process invocation.
     97 *
     98 * @return Consumed CPU cycles by this process or -1 if not available.
    9599 */
    96100posix_clock_t posix_clock(void)
    97101{
    98         // TODO
    99         return (posix_clock_t) -1;
     102        posix_clock_t total_cycles = -1;
     103        stats_task_t *task_stats = stats_get_task(task_get_id());
     104        if (task_stats) {
     105                total_cycles = (posix_clock_t) (task_stats->kcycles + task_stats->ucycles);
     106        }
     107        free(task_stats);
     108        task_stats = 0;
     109
     110        return total_cycles;
    100111}
    101112
  • uspace/lib/posix/time.h

    ra43fbc95 r06cb827  
    4343#endif
    4444
     45#undef CLOCKS_PER_SEC
     46#define CLOCKS_PER_SEC 1000000L
     47
    4548struct posix_tm {
    4649        int tm_sec;         /* Seconds [0,60]. */
Note: See TracChangeset for help on using the changeset viewer.