Changeset 06cb827 in mainline for uspace/lib/posix/time.c


Ignore:
Timestamp:
2011-07-01T23:34:23Z (13 years ago)
Author:
Petr Koupy <petr.koupy@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
fb872c1
Parents:
a43fbc95
Message:

Implemented clock().

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.