Stefan Schuermans commited on 2020-05-17 18:09:10
Showing 23 changed files, with 83 additions and 81 deletions.
| ... | ... |
@@ -3,18 +3,18 @@ add_custom_command( |
| 3 | 3 |
${CMAKE_CURRENT_BINARY_DIR}/src/lwproctrace.pb-c.c
|
| 4 | 4 |
${CMAKE_CURRENT_BINARY_DIR}/src/lwproctrace.pb-c.h
|
| 5 | 5 |
DEPENDS |
| 6 |
- ${CMAKE_CURRENT_SOURCE_DIR}/lwproctrace.proto
|
|
| 6 |
+ ${CMAKE_SOURCE_DIR}/lwproctrace.proto
|
|
| 7 | 7 |
COMMAND |
| 8 |
- protoc-c --proto_path ${CMAKE_CURRENT_SOURCE_DIR}
|
|
| 8 |
+ protoc-c --proto_path ${CMAKE_SOURCE_DIR}
|
|
| 9 | 9 |
--c_out ${CMAKE_CURRENT_BINARY_DIR}/src
|
| 10 | 10 |
lwproctrace.proto |
| 11 | 11 |
) |
| 12 | 12 |
|
| 13 | 13 |
add_library( |
| 14 |
- lwpttr |
|
| 14 |
+ lwptev |
|
| 15 | 15 |
STATIC |
| 16 |
- include/liblwpttr/proc_begin.h |
|
| 17 |
- include/liblwpttr/proc_end.h |
|
| 16 |
+ include/liblwptev/proc_begin.h |
|
| 17 |
+ include/liblwptev/proc_end.h |
|
| 18 | 18 |
src/cleaner.c |
| 19 | 19 |
src/cleaner.h |
| 20 | 20 |
src/event.c |
| ... | ... |
@@ -33,7 +33,7 @@ add_library( |
| 33 | 33 |
) |
| 34 | 34 |
|
| 35 | 35 |
target_include_directories( |
| 36 |
- lwpttr |
|
| 36 |
+ lwptev |
|
| 37 | 37 |
PUBLIC |
| 38 | 38 |
include |
| 39 | 39 |
PRIVATE |
| ... | ... |
@@ -41,7 +41,7 @@ target_include_directories( |
| 41 | 41 |
) |
| 42 | 42 |
|
| 43 | 43 |
target_link_libraries( |
| 44 |
- lwpttr |
|
| 44 |
+ lwptev |
|
| 45 | 45 |
PUBLIC |
| 46 | 46 |
-lprotobuf-c |
| 47 | 47 |
) |
| ... | ... |
@@ -3,14 +3,14 @@ |
| 3 | 3 |
|
| 4 | 4 |
#include <stdlib.h> |
| 5 | 5 |
|
| 6 |
-struct lwpttr_cleaner_s {
|
|
| 6 |
+struct lwptev_cleaner_s {
|
|
| 7 | 7 |
unsigned int free_ptr_cnt; /**< number of pointer to be freed */ |
| 8 | 8 |
void * free_ptrs[64]; /**< pointers to be freed */ |
| 9 |
- lwpttr_cleaner_t *next; /**< next cleaner object, linked list */ |
|
| 9 |
+ lwptev_cleaner_t *next; /**< next cleaner object, linked list */ |
|
| 10 | 10 |
}; |
| 11 | 11 |
|
| 12 |
-lwpttr_cleaner_t * lwpttr_cleaner_new(void) {
|
|
| 13 |
- lwpttr_cleaner_t *cleaner = malloc(sizeof(lwpttr_cleaner_t)); |
|
| 12 |
+lwptev_cleaner_t * lwptev_cleaner_new(void) {
|
|
| 13 |
+ lwptev_cleaner_t *cleaner = malloc(sizeof(lwptev_cleaner_t)); |
|
| 14 | 14 |
if (! cleaner) {
|
| 15 | 15 |
return NULL; |
| 16 | 16 |
} |
| ... | ... |
@@ -19,20 +19,20 @@ lwpttr_cleaner_t * lwpttr_cleaner_new(void) {
|
| 19 | 19 |
return cleaner; |
| 20 | 20 |
} |
| 21 | 21 |
|
| 22 |
-int lwpttr_cleaner_add_ptr(lwpttr_cleaner_t *cleaner, void *ptr) {
|
|
| 22 |
+int lwptev_cleaner_add_ptr(lwptev_cleaner_t *cleaner, void *ptr) {
|
|
| 23 | 23 |
/* find last cleaner in chain */ |
| 24 |
- lwpttr_cleaner_t *cl = cleaner; |
|
| 24 |
+ lwptev_cleaner_t *cl = cleaner; |
|
| 25 | 25 |
while (cl->next != NULL) {
|
| 26 | 26 |
cl = cl->next; |
| 27 | 27 |
} |
| 28 | 28 |
/* last cleaner full? */ |
| 29 | 29 |
if (cl->free_ptr_cnt >= countof(cl->free_ptrs)) {
|
| 30 | 30 |
/* create new one */ |
| 31 |
- cl->next = lwpttr_cleaner_new(); |
|
| 31 |
+ cl->next = lwptev_cleaner_new(); |
|
| 32 | 32 |
/* error ? */ |
| 33 | 33 |
if (! cl->next) {
|
| 34 | 34 |
/* cleanup everything and reutrn error */ |
| 35 |
- lwpttr_cleaner_cleanup(cleaner); |
|
| 35 |
+ lwptev_cleaner_cleanup(cleaner); |
|
| 36 | 36 |
return -1; |
| 37 | 37 |
} |
| 38 | 38 |
/* go to new cleaner */ |
| ... | ... |
@@ -43,8 +43,8 @@ int lwpttr_cleaner_add_ptr(lwpttr_cleaner_t *cleaner, void *ptr) {
|
| 43 | 43 |
return 0; |
| 44 | 44 |
} |
| 45 | 45 |
|
| 46 |
-void lwpttr_cleaner_cleanup(lwpttr_cleaner_t *cleaner) {
|
|
| 47 |
- lwpttr_cleaner_t *cl = cleaner; |
|
| 46 |
+void lwptev_cleaner_cleanup(lwptev_cleaner_t *cleaner) {
|
|
| 47 |
+ lwptev_cleaner_t *cl = cleaner; |
|
| 48 | 48 |
while (cl) {
|
| 49 | 49 |
/* free all pointers in cleaner */ |
| 50 | 50 |
for (unsigned int i = 0; i < cl->free_ptr_cnt; ++i) {
|
| ... | ... |
@@ -6,13 +6,13 @@ |
| 6 | 6 |
* |
| 7 | 7 |
* collects pointers to be freed and frees them on request |
| 8 | 8 |
*/ |
| 9 |
-typedef struct lwpttr_cleaner_s lwpttr_cleaner_t; |
|
| 9 |
+typedef struct lwptev_cleaner_s lwptev_cleaner_t; |
|
| 10 | 10 |
|
| 11 | 11 |
/** |
| 12 | 12 |
* @brief creater cleaner object |
| 13 | 13 |
* @return pointer to cleaner object or NULL on error |
| 14 | 14 |
*/ |
| 15 |
-lwpttr_cleaner_t * lwpttr_cleaner_new(void); |
|
| 15 |
+lwptev_cleaner_t * lwptev_cleaner_new(void); |
|
| 16 | 16 |
|
| 17 | 17 |
/** |
| 18 | 18 |
* @brief add pointer to be freed to cleaner object |
| ... | ... |
@@ -21,12 +21,12 @@ lwpttr_cleaner_t * lwpttr_cleaner_new(void); |
| 21 | 21 |
* @return 0 on success, -1 on error |
| 22 | 22 |
* (on error, cleanup is done and cleaner is deallocated) |
| 23 | 23 |
*/ |
| 24 |
-int lwpttr_cleaner_add_ptr(lwpttr_cleaner_t *cleaner, void *ptr); |
|
| 24 |
+int lwptev_cleaner_add_ptr(lwptev_cleaner_t *cleaner, void *ptr); |
|
| 25 | 25 |
|
| 26 | 26 |
/** |
| 27 | 27 |
* @brief cleanup all pointers in cleaner and free cleaner itself |
| 28 | 28 |
* @param[in] cleaner cleaner object |
| 29 | 29 |
*/ |
| 30 |
-void lwpttr_cleaner_cleanup(lwpttr_cleaner_t *cleaner); |
|
| 30 |
+void lwptev_cleaner_cleanup(lwptev_cleaner_t *cleaner); |
|
| 31 | 31 |
|
| 32 | 32 |
#endif /* #ifndef LWPTTR_CLEANER_H */ |
| ... | ... |
@@ -14,17 +14,17 @@ |
| 14 | 14 |
* @return 0 on success (*data, *size set), |
| 15 | 15 |
* -1 on error (*data = NULL, *size = 0) |
| 16 | 16 |
*/ |
| 17 |
-int lwpttr_event_pack(struct _Lwproctrace__Event *event, |
|
| 17 |
+int lwptev_event_pack(struct _Lwproctrace__Event *event, |
|
| 18 | 18 |
void **data, size_t *size, |
| 19 |
- lwpttr_cleaner_t *cleaner) {
|
|
| 19 |
+ lwptev_cleaner_t *cleaner) {
|
|
| 20 | 20 |
*size = lwproctrace__event__get_packed_size(event); |
| 21 | 21 |
*data = malloc(*size); |
| 22 | 22 |
if (! data) {
|
| 23 |
- lwpttr_cleaner_cleanup(cleaner); |
|
| 23 |
+ lwptev_cleaner_cleanup(cleaner); |
|
| 24 | 24 |
*size = 0; |
| 25 | 25 |
return -1; |
| 26 | 26 |
} |
| 27 | 27 |
*size = lwproctrace__event__pack(event, *data); |
| 28 |
- lwpttr_cleaner_cleanup(cleaner); |
|
| 28 |
+ lwptev_cleaner_cleanup(cleaner); |
|
| 29 | 29 |
return 0; |
| 30 | 30 |
} |
| ... | ... |
@@ -16,8 +16,8 @@ |
| 16 | 16 |
* @return 0 on success (*data, *size set), |
| 17 | 17 |
* -1 on error (*data = NULL, *size = 0) |
| 18 | 18 |
*/ |
| 19 |
-int lwpttr_event_pack(struct _Lwproctrace__Event *event, |
|
| 19 |
+int lwptev_event_pack(struct _Lwproctrace__Event *event, |
|
| 20 | 20 |
void **data, size_t *size, |
| 21 |
- lwpttr_cleaner_t *cleaner); |
|
| 21 |
+ lwptev_cleaner_t *cleaner); |
|
| 22 | 22 |
|
| 23 | 23 |
#endif /* #ifndef LWPTTR_EVENT_H */ |
| ... | ... |
@@ -1,4 +1,4 @@ |
| 1 |
-#include <liblwpttr/proc_begin.h> |
|
| 1 |
+#include <liblwptev/proc_begin.h> |
|
| 2 | 2 |
#include "cleaner.h" |
| 3 | 3 |
#include "event.h" |
| 4 | 4 |
#include "stringlist.h" |
| ... | ... |
@@ -11,17 +11,17 @@ |
| 11 | 11 |
#include <sys/types.h> |
| 12 | 12 |
#include <unistd.h> |
| 13 | 13 |
|
| 14 |
-int lwpttr_proc_begin(void **data, size_t *size) {
|
|
| 14 |
+int lwptev_proc_begin(void **data, size_t *size) {
|
|
| 15 | 15 |
*data = NULL; |
| 16 | 16 |
*size = 0; |
| 17 | 17 |
|
| 18 |
- lwpttr_cleaner_t *cleaner = lwpttr_cleaner_new(); |
|
| 18 |
+ lwptev_cleaner_t *cleaner = lwptev_cleaner_new(); |
|
| 19 | 19 |
if (! cleaner) {
|
| 20 | 20 |
return -1; |
| 21 | 21 |
} |
| 22 | 22 |
|
| 23 | 23 |
struct _Lwproctrace__Timespec timestamp = LWPROCTRACE__TIMESPEC__INIT; |
| 24 |
- timing_get_timestamp(×tamp); |
|
| 24 |
+ lwptev_timing_get_timestamp(×tamp); |
|
| 25 | 25 |
|
| 26 | 26 |
struct _Lwproctrace__ProcBegin proc_begin = LWPROCTRACE__PROC_BEGIN__INIT; |
| 27 | 27 |
proc_begin.pid = getpid(); |
| ... | ... |
@@ -46,5 +46,5 @@ int lwpttr_proc_begin(void **data, size_t *size) {
|
| 46 | 46 |
event.timestamp = ×tamp; |
| 47 | 47 |
event.proc_begin = &proc_begin; |
| 48 | 48 |
|
| 49 |
- return lwpttr_event_pack(&event, data, size, cleaner); |
|
| 49 |
+ return lwptev_event_pack(&event, data, size, cleaner); |
|
| 50 | 50 |
} |
| ... | ... |
@@ -1,4 +1,4 @@ |
| 1 |
-#include <liblwpttr/proc_end.h> |
|
| 1 |
+#include <liblwptev/proc_end.h> |
|
| 2 | 2 |
#include "cleaner.h" |
| 3 | 3 |
#include "event.h" |
| 4 | 4 |
#include "timing.h" |
| ... | ... |
@@ -9,20 +9,20 @@ |
| 9 | 9 |
#include <sys/types.h> |
| 10 | 10 |
#include <unistd.h> |
| 11 | 11 |
|
| 12 |
-int lwpttr_proc_end(void **data, size_t *size) {
|
|
| 12 |
+int lwptev_proc_end(void **data, size_t *size) {
|
|
| 13 | 13 |
*data = NULL; |
| 14 | 14 |
*size = 0; |
| 15 | 15 |
|
| 16 |
- lwpttr_cleaner_t *cleaner = lwpttr_cleaner_new(); |
|
| 16 |
+ lwptev_cleaner_t *cleaner = lwptev_cleaner_new(); |
|
| 17 | 17 |
if (! cleaner) {
|
| 18 | 18 |
return -1; |
| 19 | 19 |
} |
| 20 | 20 |
|
| 21 | 21 |
struct _Lwproctrace__Timespec timestamp = LWPROCTRACE__TIMESPEC__INIT; |
| 22 |
- timing_get_timestamp(×tamp); |
|
| 22 |
+ lwptev_timing_get_timestamp(×tamp); |
|
| 23 | 23 |
|
| 24 | 24 |
struct _Lwproctrace__Timespec proc_cpu_time = LWPROCTRACE__TIMESPEC__INIT; |
| 25 |
- timing_get_proc_cpu_time(&proc_cpu_time); |
|
| 25 |
+ lwptev_timing_get_proc_cpu_time(&proc_cpu_time); |
|
| 26 | 26 |
|
| 27 | 27 |
struct _Lwproctrace__ProcEnd proc_end = LWPROCTRACE__PROC_END__INIT; |
| 28 | 28 |
proc_end.pid = getpid(); |
| ... | ... |
@@ -32,5 +32,5 @@ int lwpttr_proc_end(void **data, size_t *size) {
|
| 32 | 32 |
event.timestamp = ×tamp; |
| 33 | 33 |
event.proc_end = &proc_end; |
| 34 | 34 |
|
| 35 |
- return lwpttr_event_pack(&event, data, size, cleaner); |
|
| 35 |
+ return lwptev_event_pack(&event, data, size, cleaner); |
|
| 36 | 36 |
} |
| ... | ... |
@@ -95,25 +95,25 @@ static char ** stringlist_make_ptrs(char *data, size_t sz, size_t *cnt) {
|
| 95 | 95 |
} |
| 96 | 96 |
|
| 97 | 97 |
int stringlist_read(char const *pathname, size_t *n, char ***strs, |
| 98 |
- lwpttr_cleaner_t *cleaner) {
|
|
| 98 |
+ lwptev_cleaner_t *cleaner) {
|
|
| 99 | 99 |
*n = 0; |
| 100 | 100 |
*strs = NULL; |
| 101 | 101 |
/* read file contents */ |
| 102 | 102 |
size_t sz; |
| 103 | 103 |
char *data = stringlist_read_file(pathname, &sz); |
| 104 | 104 |
if (! data) {
|
| 105 |
- lwpttr_cleaner_cleanup(cleaner); |
|
| 105 |
+ lwptev_cleaner_cleanup(cleaner); |
|
| 106 | 106 |
return -1; |
| 107 | 107 |
} |
| 108 |
- lwpttr_cleaner_add_ptr(cleaner, data); |
|
| 108 |
+ lwptev_cleaner_add_ptr(cleaner, data); |
|
| 109 | 109 |
/* create pointer array */ |
| 110 | 110 |
size_t cnt; |
| 111 | 111 |
char **ptrs = stringlist_make_ptrs(data, sz, &cnt); |
| 112 | 112 |
if (! ptrs) {
|
| 113 |
- lwpttr_cleaner_cleanup(cleaner); |
|
| 113 |
+ lwptev_cleaner_cleanup(cleaner); |
|
| 114 | 114 |
return -1; |
| 115 | 115 |
} |
| 116 |
- lwpttr_cleaner_add_ptr(cleaner, ptrs); |
|
| 116 |
+ lwptev_cleaner_add_ptr(cleaner, ptrs); |
|
| 117 | 117 |
*n = cnt; |
| 118 | 118 |
*strs = ptrs; |
| 119 | 119 |
return 0; |
| ... | ... |
@@ -36,12 +36,12 @@ static char * symlink_read_target(char const *pathname) {
|
| 36 | 36 |
} |
| 37 | 37 |
|
| 38 | 38 |
int symlink_read(char const *pathname, char **target, |
| 39 |
- lwpttr_cleaner_t *cleaner) {
|
|
| 39 |
+ lwptev_cleaner_t *cleaner) {
|
|
| 40 | 40 |
*target = symlink_read_target(pathname); |
| 41 | 41 |
if (! *target) {
|
| 42 |
- lwpttr_cleaner_cleanup(cleaner); |
|
| 42 |
+ lwptev_cleaner_cleanup(cleaner); |
|
| 43 | 43 |
return -1; |
| 44 | 44 |
} |
| 45 |
- lwpttr_cleaner_add_ptr(cleaner, *target); |
|
| 45 |
+ lwptev_cleaner_add_ptr(cleaner, *target); |
|
| 46 | 46 |
return 0; |
| 47 | 47 |
} |
| ... | ... |
@@ -0,0 +1,23 @@ |
| 1 |
+#include "timing.h" |
|
| 2 |
+ |
|
| 3 |
+#include <lwproctrace.pb-c.h> |
|
| 4 |
+ |
|
| 5 |
+#include <time.h> |
|
| 6 |
+ |
|
| 7 |
+static void lwptev_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 lwptev_timing_get_timestamp(struct _Lwproctrace__Timespec *timestamp) {
|
|
| 17 |
+ lwptev_timing_clock_gettime(CLOCK_REALTIME, timestamp); |
|
| 18 |
+} |
|
| 19 |
+ |
|
| 20 |
+void lwptev_timing_get_proc_cpu_time(struct _Lwproctrace__Timespec |
|
| 21 |
+ *proc_cpu_time) {
|
|
| 22 |
+ lwptev_timing_clock_gettime(CLOCK_PROCESS_CPUTIME_ID, proc_cpu_time); |
|
| 23 |
+} |
| ... | ... |
@@ -7,12 +7,13 @@ |
| 7 | 7 |
* @brief fill timestamp with current time |
| 8 | 8 |
* @param[in,out] timestamp initialized structure to set to current time |
| 9 | 9 |
*/ |
| 10 |
-void timing_get_timestamp(struct _Lwproctrace__Timespec *timestamp); |
|
| 10 |
+void lwptev_timing_get_timestamp(struct _Lwproctrace__Timespec *timestamp); |
|
| 11 | 11 |
|
| 12 | 12 |
/** |
| 13 | 13 |
* @brief fill timestamp with total CPU time used by process |
| 14 | 14 |
* @param[in,out] timestamp initialized structure to set to proccess CPU time |
| 15 | 15 |
*/ |
| 16 |
-void timing_get_proc_cpu_time(struct _Lwproctrace__Timespec *proc_cpu_time); |
|
| 16 |
+void lwptev_timing_get_proc_cpu_time(struct _Lwproctrace__Timespec |
|
| 17 |
+ *proc_cpu_time); |
|
| 17 | 18 |
|
| 18 | 19 |
#endif /* #ifndef LWPTTR_TIMING_H */ |
| ... | ... |
@@ -1,4 +1,4 @@ |
| 1 |
-#include <liblwpttr/proc_begin.h> |
|
| 1 |
+#include <liblwptev/proc_begin.h> |
|
| 2 | 2 |
|
| 3 | 3 |
#include "write.h" |
| 4 | 4 |
|
| ... | ... |
@@ -7,6 +7,6 @@ |
| 7 | 7 |
__attribute__((constructor)) static void constructor(void) {
|
| 8 | 8 |
void *data = NULL; |
| 9 | 9 |
size_t size = 0; |
| 10 |
- lwpttr_proc_begin(&data, &size); |
|
| 10 |
+ lwptev_proc_begin(&data, &size); |
|
| 11 | 11 |
lwptpl_write(data, size); |
| 12 | 12 |
} |
| ... | ... |
@@ -1,4 +1,4 @@ |
| 1 |
-#include <liblwpttr/proc_end.h> |
|
| 1 |
+#include <liblwptev/proc_end.h> |
|
| 2 | 2 |
|
| 3 | 3 |
#include "write.h" |
| 4 | 4 |
|
| ... | ... |
@@ -7,6 +7,6 @@ |
| 7 | 7 |
__attribute__((destructor)) static void destructor(void) {
|
| 8 | 8 |
void *data = NULL; |
| 9 | 9 |
size_t size = 0; |
| 10 |
- lwpttr_proc_end(&data, &size); |
|
| 10 |
+ lwptev_proc_end(&data, &size); |
|
| 11 | 11 |
lwptpl_write(data, size); |
| 12 | 12 |
} |
| ... | ... |
@@ -1,22 +0,0 @@ |
| 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 |
-} |