Stefan Schuermans commited on 2020-05-17 17:26:39
Showing 8 changed files, with 51 additions and 31 deletions.
| ... | ... |
@@ -26,8 +26,8 @@ add_library( |
| 26 | 26 |
src/stringlist.h |
| 27 | 27 |
src/symlink.c |
| 28 | 28 |
src/symlink.h |
| 29 |
- src/timestamp.c |
|
| 30 |
- src/timestamp.h |
|
| 29 |
+ src/timing.c |
|
| 30 |
+ src/timing.h |
|
| 31 | 31 |
${CMAKE_CURRENT_BINARY_DIR}/src/lwproctrace.pb-c.c
|
| 32 | 32 |
${CMAKE_CURRENT_BINARY_DIR}/src/lwproctrace.pb-c.h
|
| 33 | 33 |
) |
| ... | ... |
@@ -3,7 +3,7 @@ |
| 3 | 3 |
#include "event.h" |
| 4 | 4 |
#include "stringlist.h" |
| 5 | 5 |
#include "symlink.h" |
| 6 |
-#include "timestamp.h" |
|
| 6 |
+#include "timing.h" |
|
| 7 | 7 |
|
| 8 | 8 |
#include <lwproctrace.pb-c.h> |
| 9 | 9 |
|
| ... | ... |
@@ -21,7 +21,7 @@ int lwpttr_proc_begin(void **data, size_t *size) {
|
| 21 | 21 |
} |
| 22 | 22 |
|
| 23 | 23 |
struct _Lwproctrace__Timespec timestamp = LWPROCTRACE__TIMESPEC__INIT; |
| 24 |
- lwpttr_event_get_timestamp(×tamp); |
|
| 24 |
+ timing_get_timestamp(×tamp); |
|
| 25 | 25 |
|
| 26 | 26 |
struct _Lwproctrace__ProcBegin proc_begin = LWPROCTRACE__PROC_BEGIN__INIT; |
| 27 | 27 |
proc_begin.pid = getpid(); |
| ... | ... |
@@ -1,7 +1,7 @@ |
| 1 | 1 |
#include <liblwpttr/proc_end.h> |
| 2 | 2 |
#include "cleaner.h" |
| 3 | 3 |
#include "event.h" |
| 4 |
-#include "timestamp.h" |
|
| 4 |
+#include "timing.h" |
|
| 5 | 5 |
|
| 6 | 6 |
#include <lwproctrace.pb-c.h> |
| 7 | 7 |
|
| ... | ... |
@@ -19,10 +19,14 @@ int lwpttr_proc_end(void **data, size_t *size) {
|
| 19 | 19 |
} |
| 20 | 20 |
|
| 21 | 21 |
struct _Lwproctrace__Timespec timestamp = LWPROCTRACE__TIMESPEC__INIT; |
| 22 |
- lwpttr_event_get_timestamp(×tamp); |
|
| 22 |
+ timing_get_timestamp(×tamp); |
|
| 23 |
+ |
|
| 24 |
+ struct _Lwproctrace__Timespec proc_cpu_time = LWPROCTRACE__TIMESPEC__INIT; |
|
| 25 |
+ timing_get_proc_cpu_time(&proc_cpu_time); |
|
| 23 | 26 |
|
| 24 | 27 |
struct _Lwproctrace__ProcEnd proc_end = LWPROCTRACE__PROC_END__INIT; |
| 25 | 28 |
proc_end.pid = getpid(); |
| 29 |
+ proc_end.proc_cpu_time = &proc_cpu_time; |
|
| 26 | 30 |
|
| 27 | 31 |
struct _Lwproctrace__Event event = LWPROCTRACE__EVENT__INIT; |
| 28 | 32 |
event.timestamp = ×tamp; |
| ... | ... |
@@ -1,13 +0,0 @@ |
| 1 |
-#include "timestamp.h" |
|
| 2 |
- |
|
| 3 |
-#include <lwproctrace.pb-c.h> |
|
| 4 |
- |
|
| 5 |
-#include <time.h> |
|
| 6 |
- |
|
| 7 |
-void lwpttr_event_get_timestamp(struct _Lwproctrace__Timespec *timestamp) {
|
|
| 8 |
- struct timespec now; |
|
| 9 |
- clock_gettime(CLOCK_REALTIME, &now); |
|
| 10 |
- timestamp->sec = now.tv_sec; |
|
| 11 |
- timestamp->has_nsec = 1; |
|
| 12 |
- timestamp->nsec = now.tv_nsec; |
|
| 13 |
-} |
| ... | ... |
@@ -1,12 +0,0 @@ |
| 1 |
-#ifndef LWPTTR_TIMESTAMP_H |
|
| 2 |
-#define LWPTTR_TIMESTAMP_H |
|
| 3 |
- |
|
| 4 |
-#include <lwproctrace.pb-c.h> |
|
| 5 |
- |
|
| 6 |
-/** |
|
| 7 |
- * @brief fill timestamp with current time |
|
| 8 |
- * @param[in,out] timestamp initialized structure to set to current time |
|
| 9 |
- */ |
|
| 10 |
-void lwpttr_event_get_timestamp(struct _Lwproctrace__Timespec *timestamp); |
|
| 11 |
- |
|
| 12 |
-#endif /* #ifndef LWPTTR_TIMESTAMP_H */ |
| ... | ... |
@@ -0,0 +1,22 @@ |
| 1 |
+#include "timing.h" |
|
| 2 |
+ |
|
| 3 |
+#include <lwproctrace.pb-c.h> |
|
| 4 |
+ |
|
| 5 |
+#include <time.h> |
|
| 6 |
+ |
|
| 7 |
+static void timing_clock_gettime(clockid_t clockid, |
|
| 8 |
+ struct _Lwproctrace__Timespec *tsp) {
|
|
| 9 |
+ struct timespec ts; |
|
| 10 |
+ clock_gettime(clockid, &ts); |
|
| 11 |
+ tsp->sec = ts.tv_sec; |
|
| 12 |
+ tsp->has_nsec = 1; |
|
| 13 |
+ tsp->nsec = ts.tv_nsec; |
|
| 14 |
+} |
|
| 15 |
+ |
|
| 16 |
+void timing_get_timestamp(struct _Lwproctrace__Timespec *timestamp) {
|
|
| 17 |
+ timing_clock_gettime(CLOCK_REALTIME, timestamp); |
|
| 18 |
+} |
|
| 19 |
+ |
|
| 20 |
+void timing_get_proc_cpu_time(struct _Lwproctrace__Timespec *proc_cpu_time) {
|
|
| 21 |
+ timing_clock_gettime(CLOCK_PROCESS_CPUTIME_ID, proc_cpu_time); |
|
| 22 |
+} |
| ... | ... |
@@ -0,0 +1,18 @@ |
| 1 |
+#ifndef LWPTTR_TIMING_H |
|
| 2 |
+#define LWPTTR_TIMING_H |
|
| 3 |
+ |
|
| 4 |
+#include <lwproctrace.pb-c.h> |
|
| 5 |
+ |
|
| 6 |
+/** |
|
| 7 |
+ * @brief fill timestamp with current time |
|
| 8 |
+ * @param[in,out] timestamp initialized structure to set to current time |
|
| 9 |
+ */ |
|
| 10 |
+void timing_get_timestamp(struct _Lwproctrace__Timespec *timestamp); |
|
| 11 |
+ |
|
| 12 |
+/** |
|
| 13 |
+ * @brief fill timestamp with total CPU time used by process |
|
| 14 |
+ * @param[in,out] timestamp initialized structure to set to proccess CPU time |
|
| 15 |
+ */ |
|
| 16 |
+void timing_get_proc_cpu_time(struct _Lwproctrace__Timespec *proc_cpu_time); |
|
| 17 |
+ |
|
| 18 |
+#endif /* #ifndef LWPTTR_TIMING_H */ |
|
| 0 | 19 |