840c0b18e9990fe15416283f869bc8532c1bbf3a
Stefan Schuermans add copyright headers and l...

Stefan Schuermans authored 4 years ago

1) /**
2)  * UProcTrace: User-space Process Tracing
3)  * Copyright 2020: Stefan Schuermans, Aachen, Germany <stefan@schuermans.info>
4)  * Copyleft: GNU LESSER GENERAL PUBLIC LICENSE version 3 (see LICENSE)
5)  */
6) 
Stefan Schuermans rename: lwproctrace -> upro...

Stefan Schuermans authored 4 years ago

7) #include "timing.h"
8) 
9) #include <uproctrace.pb-c.h>
10) 
Stefan Schuermans implement user/sys time + m...

Stefan Schuermans authored 4 years ago

11) #include <sys/time.h>
Stefan Schuermans rename: lwproctrace -> upro...

Stefan Schuermans authored 4 years ago

12) #include <time.h>
13) 
Stefan Schuermans implement user/sys time + m...

Stefan Schuermans authored 4 years ago

14) void uptev_timing_timeval_to_pb(struct timeval const *tv,
15)                                 struct _Uproctrace__Timespec *tsp) {
16)   tsp->sec = tv->tv_sec;
17)   tsp->has_nsec = 1;
18)   tsp->nsec = tv->tv_usec * 1000;
19) }
20) 
21) void uptev_timing_timespec_to_pb(struct timespec const *ts,
22)                                  struct _Uproctrace__Timespec *tsp) {
23)   tsp->sec = ts->tv_sec;
Stefan Schuermans rename: lwproctrace -> upro...

Stefan Schuermans authored 4 years ago

24)   tsp->has_nsec = 1;
Stefan Schuermans implement user/sys time + m...

Stefan Schuermans authored 4 years ago

25)   tsp->nsec = ts->tv_nsec;
Stefan Schuermans rename: lwproctrace -> upro...

Stefan Schuermans authored 4 years ago

26) }
27) 
28) void uptev_timing_get_timestamp(struct _Uproctrace__Timespec *timestamp) {
Stefan Schuermans implement user/sys time + m...

Stefan Schuermans authored 4 years ago

29)   struct timespec ts;
30)   clock_gettime(CLOCK_REALTIME, &ts);
31)   uptev_timing_timespec_to_pb(&ts, timestamp);
Stefan Schuermans rename: lwproctrace -> upro...

Stefan Schuermans authored 4 years ago

32) }
33) 
Stefan Schuermans formatting

Stefan Schuermans authored 4 years ago

34) void uptev_timing_get_proc_cpu_time(
35)     struct _Uproctrace__Timespec *proc_cpu_time) {
Stefan Schuermans implement user/sys time + m...

Stefan Schuermans authored 4 years ago

36)   struct timespec ts;
37)   clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts);
38)   uptev_timing_timespec_to_pb(&ts, proc_cpu_time);