Stefan Schuermans commited on 2020-05-21 09:57:55
Showing 35 changed files, with 272 additions and 278 deletions.
new name: user-space process tracing allow differentiating between no args/envs and not recorded !!! breaking change to protobuf format !!! do not fail if single trace filed cannot be filled
... | ... |
@@ -1,11 +1,11 @@ |
1 | 1 |
cmake_minimum_required(VERSION 3.10) |
2 |
-project(lwproctrace) |
|
2 |
+project(uproctrace) |
|
3 | 3 |
|
4 | 4 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror -fPIC") |
5 | 5 |
|
6 | 6 |
enable_testing() |
7 | 7 |
|
8 | 8 |
add_subdirectory(dump) |
9 |
-add_subdirectory(liblwptev) |
|
10 |
-add_subdirectory(liblwptpl) |
|
9 |
+add_subdirectory(libuptev) |
|
10 |
+add_subdirectory(libuptpl) |
|
11 | 11 |
add_subdirectory(tests) |
... | ... |
@@ -1,12 +1,12 @@ |
1 | 1 |
add_custom_command( |
2 | 2 |
OUTPUT |
3 |
- ${CMAKE_CURRENT_BINARY_DIR}/lwproctrace_pb2.py |
|
3 |
+ ${CMAKE_CURRENT_BINARY_DIR}/uproctrace_pb2.py |
|
4 | 4 |
DEPENDS |
5 |
- ${CMAKE_SOURCE_DIR}/lwproctrace.proto |
|
5 |
+ ${CMAKE_SOURCE_DIR}/uproctrace.proto |
|
6 | 6 |
COMMAND |
7 | 7 |
protoc --proto_path ${CMAKE_SOURCE_DIR} |
8 | 8 |
--python_out ${CMAKE_CURRENT_BINARY_DIR} |
9 |
- lwproctrace.proto |
|
9 |
+ uproctrace.proto |
|
10 | 10 |
) |
11 | 11 |
|
12 | 12 |
add_custom_command( |
... | ... |
@@ -22,6 +22,6 @@ add_custom_target( |
22 | 22 |
dump |
23 | 23 |
ALL |
24 | 24 |
DEPENDS |
25 |
- ${CMAKE_CURRENT_BINARY_DIR}/lwproctrace_pb2.py |
|
25 |
+ ${CMAKE_CURRENT_BINARY_DIR}/uproctrace_pb2.py |
|
26 | 26 |
${CMAKE_CURRENT_BINARY_DIR}/dump.py |
27 | 27 |
) |
... | ... |
@@ -1,12 +1,12 @@ |
1 | 1 |
#! /usr/bin/env python3 |
2 | 2 |
|
3 | 3 |
import argparse |
4 |
-import lwproctrace_pb2 |
|
4 |
+import uproctrace_pb2 |
|
5 | 5 |
import struct |
6 | 6 |
|
7 | 7 |
|
8 | 8 |
def parse_args(): |
9 |
- parser = argparse.ArgumentParser(description='dump lwproctrace trace') |
|
9 |
+ parser = argparse.ArgumentParser(description='dump uproctrace trace') |
|
10 | 10 |
parser.add_argument('trace', help='trace file') |
11 | 11 |
args = parser.parse_args() |
12 | 12 |
return args |
... | ... |
@@ -15,7 +15,7 @@ def parse_args(): |
15 | 15 |
def dump_event(f): |
16 | 16 |
# skip till after magic |
17 | 17 |
magic = f.read(4) |
18 |
- while magic != b'lwpt': |
|
18 |
+ while magic != b'upt0': |
|
19 | 19 |
if len(magic) < 4: |
20 | 20 |
return False # EOF |
21 | 21 |
magic = magic[1:] + f.read(1) # search for magic byte for byte |
... | ... |
@@ -29,7 +29,7 @@ def dump_event(f): |
29 | 29 |
if len(data) < size: |
30 | 30 |
return False # EOF |
31 | 31 |
# unpack event |
32 |
- event = lwproctrace_pb2.event.FromString(data) |
|
32 |
+ event = uproctrace_pb2.event.FromString(data) |
|
33 | 33 |
# dump event |
34 | 34 |
print('event {') |
35 | 35 |
for line in repr(event).split('\n'): |
... | ... |
@@ -1,50 +0,0 @@ |
1 |
-#include <liblwptev/proc_begin.h> |
|
2 |
-#include "cleaner.h" |
|
3 |
-#include "event.h" |
|
4 |
-#include "stringlist.h" |
|
5 |
-#include "symlink.h" |
|
6 |
-#include "timing.h" |
|
7 |
- |
|
8 |
-#include <lwproctrace.pb-c.h> |
|
9 |
- |
|
10 |
-#include <stdlib.h> |
|
11 |
-#include <sys/types.h> |
|
12 |
-#include <unistd.h> |
|
13 |
- |
|
14 |
-int lwptev_proc_begin(void **data, size_t *size) { |
|
15 |
- *data = NULL; |
|
16 |
- *size = 0; |
|
17 |
- |
|
18 |
- lwptev_cleaner_t *cleaner = lwptev_cleaner_new(); |
|
19 |
- if (! cleaner) { |
|
20 |
- return -1; |
|
21 |
- } |
|
22 |
- |
|
23 |
- struct _Lwproctrace__Timespec timestamp = LWPROCTRACE__TIMESPEC__INIT; |
|
24 |
- lwptev_timing_get_timestamp(×tamp); |
|
25 |
- |
|
26 |
- struct _Lwproctrace__ProcBegin proc_begin = LWPROCTRACE__PROC_BEGIN__INIT; |
|
27 |
- proc_begin.pid = getpid(); |
|
28 |
- proc_begin.has_ppid = 1; |
|
29 |
- proc_begin.ppid = getppid(); |
|
30 |
- if (lwptev_symlink_read("/proc/self/exe", &proc_begin.exe, cleaner) != 0) { |
|
31 |
- return -1; |
|
32 |
- } |
|
33 |
- if (lwptev_symlink_read("/proc/self/cwd", &proc_begin.cwd, cleaner) != 0) { |
|
34 |
- return -1; |
|
35 |
- } |
|
36 |
- if (lwptev_stringlist_read("/proc/self/cmdline", &proc_begin.n_cmdline, |
|
37 |
- &proc_begin.cmdline, cleaner) != 0) { |
|
38 |
- return -1; |
|
39 |
- } |
|
40 |
- if (lwptev_stringlist_read("/proc/self/environ", &proc_begin.n_environ, |
|
41 |
- &proc_begin.environ, cleaner) != 0) { |
|
42 |
- return -1; |
|
43 |
- } |
|
44 |
- |
|
45 |
- struct _Lwproctrace__Event event = LWPROCTRACE__EVENT__INIT; |
|
46 |
- event.timestamp = ×tamp; |
|
47 |
- event.proc_begin = &proc_begin; |
|
48 |
- |
|
49 |
- return lwptev_event_pack(&event, data, size, cleaner); |
|
50 |
-} |
... | ... |
@@ -1,36 +0,0 @@ |
1 |
-#include <liblwptev/proc_end.h> |
|
2 |
-#include "cleaner.h" |
|
3 |
-#include "event.h" |
|
4 |
-#include "timing.h" |
|
5 |
- |
|
6 |
-#include <lwproctrace.pb-c.h> |
|
7 |
- |
|
8 |
-#include <stdlib.h> |
|
9 |
-#include <sys/types.h> |
|
10 |
-#include <unistd.h> |
|
11 |
- |
|
12 |
-int lwptev_proc_end(void **data, size_t *size) { |
|
13 |
- *data = NULL; |
|
14 |
- *size = 0; |
|
15 |
- |
|
16 |
- lwptev_cleaner_t *cleaner = lwptev_cleaner_new(); |
|
17 |
- if (! cleaner) { |
|
18 |
- return -1; |
|
19 |
- } |
|
20 |
- |
|
21 |
- struct _Lwproctrace__Timespec timestamp = LWPROCTRACE__TIMESPEC__INIT; |
|
22 |
- lwptev_timing_get_timestamp(×tamp); |
|
23 |
- |
|
24 |
- struct _Lwproctrace__Timespec proc_cpu_time = LWPROCTRACE__TIMESPEC__INIT; |
|
25 |
- lwptev_timing_get_proc_cpu_time(&proc_cpu_time); |
|
26 |
- |
|
27 |
- struct _Lwproctrace__ProcEnd proc_end = LWPROCTRACE__PROC_END__INIT; |
|
28 |
- proc_end.pid = getpid(); |
|
29 |
- proc_end.proc_cpu_time = &proc_cpu_time; |
|
30 |
- |
|
31 |
- struct _Lwproctrace__Event event = LWPROCTRACE__EVENT__INIT; |
|
32 |
- event.timestamp = ×tamp; |
|
33 |
- event.proc_end = &proc_end; |
|
34 |
- |
|
35 |
- return lwptev_event_pack(&event, data, size, cleaner); |
|
36 |
-} |
... | ... |
@@ -1,20 +0,0 @@ |
1 |
-#ifndef LWPTEV_STRINGLIST_H |
|
2 |
-#define LWPTEV_STRINGLIST_H |
|
3 |
- |
|
4 |
-#include "cleaner.h" |
|
5 |
- |
|
6 |
-#include <stdlib.h> |
|
7 |
- |
|
8 |
-/** |
|
9 |
- * @brief read string list file |
|
10 |
- * @param[in] pathname path to file containing zero-terminated string list |
|
11 |
- * @param[out] *n number of strings read |
|
12 |
- * @param[out] *strs strings read |
|
13 |
- * @param[in,out] cleaner object, malloc-ed string is added to it |
|
14 |
- * @return 0 on success, -1 on error |
|
15 |
- * (on error, cleanup is done and cleaner is deallocated) |
|
16 |
- */ |
|
17 |
-int lwptev_stringlist_read(char const *pathname, size_t *n, char ***strs, |
|
18 |
- lwptev_cleaner_t *cleaner); |
|
19 |
- |
|
20 |
-#endif /* #ifndef LWPTEV_STRINGLIST_H */ |
... | ... |
@@ -1,17 +0,0 @@ |
1 |
-#ifndef LWPTEV_SYMLINK_H |
|
2 |
-#define LWPTEV_SYMLINK_H |
|
3 |
- |
|
4 |
-#include "cleaner.h" |
|
5 |
- |
|
6 |
-/** |
|
7 |
- * @brief read symlink |
|
8 |
- * @param[in] pathname path to symbolic link |
|
9 |
- * @param[out] *target malloc-ed string object containing symlink target |
|
10 |
- * @param[in,out] cleaner object, malloc-ed string is added to it |
|
11 |
- * @return 0 on success, -1 on error |
|
12 |
- * (on error, cleanup is done and cleaner is deallocated) |
|
13 |
- */ |
|
14 |
-int lwptev_symlink_read(char const *pathname, char **target, |
|
15 |
- lwptev_cleaner_t *cleaner); |
|
16 |
- |
|
17 |
-#endif /* #ifndef LWPTEV_SYMLINK_H */ |
... | ... |
@@ -1,23 +0,0 @@ |
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 |
-} |
... | ... |
@@ -1,20 +1,20 @@ |
1 | 1 |
add_custom_command( |
2 | 2 |
OUTPUT |
3 |
- ${CMAKE_CURRENT_BINARY_DIR}/src/lwproctrace.pb-c.c |
|
4 |
- ${CMAKE_CURRENT_BINARY_DIR}/src/lwproctrace.pb-c.h |
|
3 |
+ ${CMAKE_CURRENT_BINARY_DIR}/src/uproctrace.pb-c.c |
|
4 |
+ ${CMAKE_CURRENT_BINARY_DIR}/src/uproctrace.pb-c.h |
|
5 | 5 |
DEPENDS |
6 |
- ${CMAKE_SOURCE_DIR}/lwproctrace.proto |
|
6 |
+ ${CMAKE_SOURCE_DIR}/uproctrace.proto |
|
7 | 7 |
COMMAND |
8 | 8 |
protoc-c --proto_path ${CMAKE_SOURCE_DIR} |
9 | 9 |
--c_out ${CMAKE_CURRENT_BINARY_DIR}/src |
10 |
- lwproctrace.proto |
|
10 |
+ uproctrace.proto |
|
11 | 11 |
) |
12 | 12 |
|
13 | 13 |
add_library( |
14 |
- lwptev |
|
14 |
+ uptev |
|
15 | 15 |
STATIC |
16 |
- include/liblwptev/proc_begin.h |
|
17 |
- include/liblwptev/proc_end.h |
|
16 |
+ include/uptev/proc_begin.h |
|
17 |
+ include/uptev/proc_end.h |
|
18 | 18 |
src/cleaner.c |
19 | 19 |
src/cleaner.h |
20 | 20 |
src/event.c |
... | ... |
@@ -30,12 +30,12 @@ add_library( |
30 | 30 |
src/symlink.h |
31 | 31 |
src/timing.c |
32 | 32 |
src/timing.h |
33 |
- ${CMAKE_CURRENT_BINARY_DIR}/src/lwproctrace.pb-c.c |
|
34 |
- ${CMAKE_CURRENT_BINARY_DIR}/src/lwproctrace.pb-c.h |
|
33 |
+ ${CMAKE_CURRENT_BINARY_DIR}/src/uproctrace.pb-c.c |
|
34 |
+ ${CMAKE_CURRENT_BINARY_DIR}/src/uproctrace.pb-c.h |
|
35 | 35 |
) |
36 | 36 |
|
37 | 37 |
target_include_directories( |
38 |
- lwptev |
|
38 |
+ uptev |
|
39 | 39 |
PUBLIC |
40 | 40 |
include |
41 | 41 |
PRIVATE |
... | ... |
@@ -43,7 +43,7 @@ target_include_directories( |
43 | 43 |
) |
44 | 44 |
|
45 | 45 |
target_link_libraries( |
46 |
- lwptev |
|
46 |
+ uptev |
|
47 | 47 |
PUBLIC |
48 | 48 |
-lprotobuf-c |
49 | 49 |
) |
... | ... |
@@ -1,5 +1,5 @@ |
1 |
-#ifndef LWPTEV_PROC_BEGIN_H |
|
2 |
-#define LWPTEV_PROC_BEGIN_H |
|
1 |
+#ifndef UPTEV_PROC_BEGIN_H |
|
2 |
+#define UPTEV_PROC_BEGIN_H |
|
3 | 3 |
|
4 | 4 |
#include <stdlib.h> |
5 | 5 |
|
... | ... |
@@ -10,6 +10,6 @@ |
10 | 10 |
* @return 0 on success (*data, *size set), |
11 | 11 |
* -1 on error (*data = NULL, *size = 0) |
12 | 12 |
*/ |
13 |
-int lwptev_proc_begin(void **data, size_t *size); |
|
13 |
+int uptev_proc_begin(void **data, size_t *size); |
|
14 | 14 |
|
15 |
-#endif /* #ifndef LWPTEV_PROC_BEGIN_H */ |
|
15 |
+#endif /* #ifndef UPTEV_PROC_BEGIN_H */ |
... | ... |
@@ -1,5 +1,5 @@ |
1 |
-#ifndef LWPTEV_PROC_END_H |
|
2 |
-#define LWPTEV_PROC_END_H |
|
1 |
+#ifndef UPTEV_PROC_END_H |
|
2 |
+#define UPTEV_PROC_END_H |
|
3 | 3 |
|
4 | 4 |
#include <stdlib.h> |
5 | 5 |
|
... | ... |
@@ -10,6 +10,6 @@ |
10 | 10 |
* @return 0 on success (*data, *size set), |
11 | 11 |
* -1 on error (*data = NULL, *size = 0) |
12 | 12 |
*/ |
13 |
-int lwptev_proc_end(void **data, size_t *size); |
|
13 |
+int uptev_proc_end(void **data, size_t *size); |
|
14 | 14 |
|
15 |
-#endif /* #ifndef LWPTEV_PROC_END_H */ |
|
15 |
+#endif /* #ifndef UPTEV_PROC_END_H */ |
... | ... |
@@ -3,14 +3,14 @@ |
3 | 3 |
|
4 | 4 |
#include <stdlib.h> |
5 | 5 |
|
6 |
-struct lwptev_cleaner_s { |
|
6 |
+struct uptev_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 |
- lwptev_cleaner_t *next; /**< next cleaner object, linked list */ |
|
9 |
+ uptev_cleaner_t *next; /**< next cleaner object, linked list */ |
|
10 | 10 |
}; |
11 | 11 |
|
12 |
-lwptev_cleaner_t * lwptev_cleaner_new(void) { |
|
13 |
- lwptev_cleaner_t *cleaner = malloc(sizeof(lwptev_cleaner_t)); |
|
12 |
+uptev_cleaner_t * uptev_cleaner_new(void) { |
|
13 |
+ uptev_cleaner_t *cleaner = malloc(sizeof(uptev_cleaner_t)); |
|
14 | 14 |
if (! cleaner) { |
15 | 15 |
return NULL; |
16 | 16 |
} |
... | ... |
@@ -19,20 +19,20 @@ lwptev_cleaner_t * lwptev_cleaner_new(void) { |
19 | 19 |
return cleaner; |
20 | 20 |
} |
21 | 21 |
|
22 |
-int lwptev_cleaner_add_ptr(lwptev_cleaner_t *cleaner, void *ptr) { |
|
22 |
+int uptev_cleaner_add_ptr(uptev_cleaner_t *cleaner, void *ptr) { |
|
23 | 23 |
/* find last cleaner in chain */ |
24 |
- lwptev_cleaner_t *cl = cleaner; |
|
24 |
+ uptev_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 = lwptev_cleaner_new(); |
|
31 |
+ cl->next = uptev_cleaner_new(); |
|
32 | 32 |
/* error ? */ |
33 | 33 |
if (! cl->next) { |
34 | 34 |
/* cleanup everything and reutrn error */ |
35 |
- lwptev_cleaner_cleanup(cleaner); |
|
35 |
+ uptev_cleaner_cleanup(cleaner); |
|
36 | 36 |
return -1; |
37 | 37 |
} |
38 | 38 |
/* go to new cleaner */ |
... | ... |
@@ -43,8 +43,8 @@ int lwptev_cleaner_add_ptr(lwptev_cleaner_t *cleaner, void *ptr) { |
43 | 43 |
return 0; |
44 | 44 |
} |
45 | 45 |
|
46 |
-void lwptev_cleaner_cleanup(lwptev_cleaner_t *cleaner) { |
|
47 |
- lwptev_cleaner_t *cl = cleaner; |
|
46 |
+void uptev_cleaner_cleanup(uptev_cleaner_t *cleaner) { |
|
47 |
+ uptev_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) { |
... | ... |
@@ -1,18 +1,18 @@ |
1 |
-#ifndef LWPTEV_CLEANER_H |
|
2 |
-#define LWPTEV_CLEANER_H |
|
1 |
+#ifndef UPTEV_CLEANER_H |
|
2 |
+#define UPTEV_CLEANER_H |
|
3 | 3 |
|
4 | 4 |
/** |
5 | 5 |
* @brief cleaner object |
6 | 6 |
* |
7 | 7 |
* collects pointers to be freed and frees them on request |
8 | 8 |
*/ |
9 |
-typedef struct lwptev_cleaner_s lwptev_cleaner_t; |
|
9 |
+typedef struct uptev_cleaner_s uptev_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 |
-lwptev_cleaner_t * lwptev_cleaner_new(void); |
|
15 |
+uptev_cleaner_t * uptev_cleaner_new(void); |
|
16 | 16 |
|
17 | 17 |
/** |
18 | 18 |
* @brief add pointer to be freed to cleaner object |
... | ... |
@@ -21,12 +21,12 @@ lwptev_cleaner_t * lwptev_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 lwptev_cleaner_add_ptr(lwptev_cleaner_t *cleaner, void *ptr); |
|
24 |
+int uptev_cleaner_add_ptr(uptev_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 lwptev_cleaner_cleanup(lwptev_cleaner_t *cleaner); |
|
30 |
+void uptev_cleaner_cleanup(uptev_cleaner_t *cleaner); |
|
31 | 31 |
|
32 |
-#endif /* #ifndef LWPTEV_CLEANER_H */ |
|
32 |
+#endif /* #ifndef UPTEV_CLEANER_H */ |
... | ... |
@@ -1,7 +1,7 @@ |
1 | 1 |
#include "event.h" |
2 | 2 |
#include "cleaner.h" |
3 | 3 |
|
4 |
-#include <lwproctrace.pb-c.h> |
|
4 |
+#include <uproctrace.pb-c.h> |
|
5 | 5 |
|
6 | 6 |
#include <stdlib.h> |
7 | 7 |
|
... | ... |
@@ -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 lwptev_event_pack(struct _Lwproctrace__Event *event, |
|
17 |
+int uptev_event_pack(struct _Uproctrace__Event *event, |
|
18 | 18 |
void **data, size_t *size, |
19 |
- lwptev_cleaner_t *cleaner) { |
|
20 |
- *size = lwproctrace__event__get_packed_size(event); |
|
19 |
+ uptev_cleaner_t *cleaner) { |
|
20 |
+ *size = uproctrace__event__get_packed_size(event); |
|
21 | 21 |
*data = malloc(*size); |
22 | 22 |
if (! data) { |
23 |
- lwptev_cleaner_cleanup(cleaner); |
|
23 |
+ uptev_cleaner_cleanup(cleaner); |
|
24 | 24 |
*size = 0; |
25 | 25 |
return -1; |
26 | 26 |
} |
27 |
- *size = lwproctrace__event__pack(event, *data); |
|
28 |
- lwptev_cleaner_cleanup(cleaner); |
|
27 |
+ *size = uproctrace__event__pack(event, *data); |
|
28 |
+ uptev_cleaner_cleanup(cleaner); |
|
29 | 29 |
return 0; |
30 | 30 |
} |
... | ... |
@@ -1,9 +1,9 @@ |
1 |
-#ifndef LWPTEV_EVENT_H |
|
2 |
-#define LWPTEV_EVENT_H |
|
1 |
+#ifndef UPTEV_EVENT_H |
|
2 |
+#define UPTEV_EVENT_H |
|
3 | 3 |
|
4 | 4 |
#include "cleaner.h" |
5 | 5 |
|
6 |
-#include <lwproctrace.pb-c.h> |
|
6 |
+#include <uproctrace.pb-c.h> |
|
7 | 7 |
|
8 | 8 |
#include <stdlib.h> |
9 | 9 |
|
... | ... |
@@ -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 lwptev_event_pack(struct _Lwproctrace__Event *event, |
|
19 |
+int uptev_event_pack(struct _Uproctrace__Event *event, |
|
20 | 20 |
void **data, size_t *size, |
21 |
- lwptev_cleaner_t *cleaner); |
|
21 |
+ uptev_cleaner_t *cleaner); |
|
22 | 22 |
|
23 |
-#endif /* #ifndef LWPTEV_EVENT_H */ |
|
23 |
+#endif /* #ifndef UPTEV_EVENT_H */ |
... | ... |
@@ -0,0 +1,50 @@ |
1 |
+#include <uptev/proc_begin.h> |
|
2 |
+#include "cleaner.h" |
|
3 |
+#include "event.h" |
|
4 |
+#include "stringlist.h" |
|
5 |
+#include "symlink.h" |
|
6 |
+#include "timing.h" |
|
7 |
+ |
|
8 |
+#include <uproctrace.pb-c.h> |
|
9 |
+ |
|
10 |
+#include <stdlib.h> |
|
11 |
+#include <sys/types.h> |
|
12 |
+#include <unistd.h> |
|
13 |
+ |
|
14 |
+int uptev_proc_begin(void **data, size_t *size) { |
|
15 |
+ *data = NULL; |
|
16 |
+ *size = 0; |
|
17 |
+ |
|
18 |
+ uptev_cleaner_t *cleaner = uptev_cleaner_new(); |
|
19 |
+ if (! cleaner) { |
|
20 |
+ return -1; |
|
21 |
+ } |
|
22 |
+ |
|
23 |
+ struct _Uproctrace__Timespec timestamp = UPROCTRACE__TIMESPEC__INIT; |
|
24 |
+ uptev_timing_get_timestamp(×tamp); |
|
25 |
+ |
|
26 |
+ struct _Uproctrace__ProcBegin proc_begin = UPROCTRACE__PROC_BEGIN__INIT; |
|
27 |
+ proc_begin.pid = getpid(); |
|
28 |
+ proc_begin.has_ppid = 1; |
|
29 |
+ proc_begin.ppid = getppid(); |
|
30 |
+ proc_begin.exe = uptev_symlink_read("/proc/self/exe", cleaner); |
|
31 |
+ proc_begin.cwd = uptev_symlink_read("/proc/self/cwd", cleaner); |
|
32 |
+ |
|
33 |
+ struct _Uproctrace__Stringlist cmdline = UPROCTRACE__STRINGLIST__INIT; |
|
34 |
+ if (uptev_stringlist_read("/proc/self/cmdline", &cmdline.n_s, &cmdline.s, |
|
35 |
+ cleaner) == 0) { |
|
36 |
+ proc_begin.cmdline = &cmdline; |
|
37 |
+ } |
|
38 |
+ |
|
39 |
+ struct _Uproctrace__Stringlist environ = UPROCTRACE__STRINGLIST__INIT; |
|
40 |
+ if (uptev_stringlist_read("/proc/self/environ", &environ.n_s, &environ.s, |
|
41 |
+ cleaner) == 0) { |
|
42 |
+ proc_begin.environ = &environ; |
|
43 |
+ } |
|
44 |
+ |
|
45 |
+ struct _Uproctrace__Event event = UPROCTRACE__EVENT__INIT; |
|
46 |
+ event.timestamp = ×tamp; |
|
47 |
+ event.proc_begin = &proc_begin; |
|
48 |
+ |
|
49 |
+ return uptev_event_pack(&event, data, size, cleaner); |
|
50 |
+} |
... | ... |
@@ -0,0 +1,36 @@ |
1 |
+#include <uptev/proc_end.h> |
|
2 |
+#include "cleaner.h" |
|
3 |
+#include "event.h" |
|
4 |
+#include "timing.h" |
|
5 |
+ |
|
6 |
+#include <uproctrace.pb-c.h> |
|
7 |
+ |
|
8 |
+#include <stdlib.h> |
|
9 |
+#include <sys/types.h> |
|
10 |
+#include <unistd.h> |
|
11 |
+ |
|
12 |
+int uptev_proc_end(void **data, size_t *size) { |
|
13 |
+ *data = NULL; |
|
14 |
+ *size = 0; |
|
15 |
+ |
|
16 |
+ uptev_cleaner_t *cleaner = uptev_cleaner_new(); |
|
17 |
+ if (! cleaner) { |
|
18 |
+ return -1; |
|
19 |
+ } |
|
20 |
+ |
|
21 |
+ struct _Uproctrace__Timespec timestamp = UPROCTRACE__TIMESPEC__INIT; |
|
22 |
+ uptev_timing_get_timestamp(×tamp); |
|
23 |
+ |
|
24 |
+ struct _Uproctrace__Timespec proc_cpu_time = UPROCTRACE__TIMESPEC__INIT; |
|
25 |
+ uptev_timing_get_proc_cpu_time(&proc_cpu_time); |
|
26 |
+ |
|
27 |
+ struct _Uproctrace__ProcEnd proc_end = UPROCTRACE__PROC_END__INIT; |
|
28 |
+ proc_end.pid = getpid(); |
|
29 |
+ proc_end.proc_cpu_time = &proc_cpu_time; |
|
30 |
+ |
|
31 |
+ struct _Uproctrace__Event event = UPROCTRACE__EVENT__INIT; |
|
32 |
+ event.timestamp = ×tamp; |
|
33 |
+ event.proc_end = &proc_end; |
|
34 |
+ |
|
35 |
+ return uptev_event_pack(&event, data, size, cleaner); |
|
36 |
+} |
... | ... |
@@ -8,7 +8,7 @@ |
8 | 8 |
#include <sys/stat.h> |
9 | 9 |
#include <unistd.h> |
10 | 10 |
|
11 |
-char * lwptev_read_file(char const *pathname, size_t *size) { |
|
11 |
+char * uptev_read_file(char const *pathname, size_t *size) { |
|
12 | 12 |
/* it is not possible to get file size before, because this yields zero for |
13 | 13 |
files like /proc/self/cmdline */ |
14 | 14 |
*size = 0; |
... | ... |
@@ -1,5 +1,5 @@ |
1 |
-#ifndef LWPTEV_READ_FILE_H |
|
2 |
-#define LWPTEV_READ_FILE_H |
|
1 |
+#ifndef UPTEV_READ_FILE_H |
|
2 |
+#define UPTEV_READ_FILE_H |
|
3 | 3 |
|
4 | 4 |
/** |
5 | 5 |
* @brief read file contents |
... | ... |
@@ -7,6 +7,6 @@ |
7 | 7 |
* @param[out] *size size of file contents |
8 | 8 |
* @return pointer to malloc-ed file contents or NULL |
9 | 9 |
*/ |
10 |
-char * lwptev_read_file(char const *pathname, size_t *size); |
|
10 |
+char * uptev_read_file(char const *pathname, size_t *size); |
|
11 | 11 |
|
12 |
-#endif /* #ifndef LWPTEV_READ_FILE_H */ |
|
12 |
+#endif /* #ifndef UPTEV_READ_FILE_H */ |
... | ... |
@@ -9,14 +9,7 @@ |
9 | 9 |
#include <sys/stat.h> |
10 | 10 |
#include <unistd.h> |
11 | 11 |
|
12 |
-/** |
|
13 |
- * @brief make array with pointers to strings |
|
14 |
- * @param[in] data pointer to string list |
|
15 |
- * @param[in] sz size of string list |
|
16 |
- * @param[out] *cnt number of entries in array |
|
17 |
- * @return pointer to malloc-ed array of NULL |
|
18 |
- */ |
|
19 |
-static char ** lwptev_stringlist_make_ptrs(char *data, size_t sz, |
|
12 |
+static char ** uptev_stringlist_make_ptrs(char *data, size_t sz, |
|
20 | 13 |
size_t *cnt) { |
21 | 14 |
/* count strings */ |
22 | 15 |
size_t pos = 0; |
... | ... |
@@ -40,26 +33,26 @@ static char ** lwptev_stringlist_make_ptrs(char *data, size_t sz, |
40 | 33 |
return ptrs; |
41 | 34 |
} |
42 | 35 |
|
43 |
-int lwptev_stringlist_read(char const *pathname, size_t *n, char ***strs, |
|
44 |
- lwptev_cleaner_t *cleaner) { |
|
36 |
+int uptev_stringlist_read(char const *pathname, size_t *n, char ***strs, |
|
37 |
+ uptev_cleaner_t *cleaner) { |
|
45 | 38 |
*n = 0; |
46 | 39 |
*strs = NULL; |
47 | 40 |
/* read file contents */ |
48 | 41 |
size_t sz; |
49 |
- char *data = lwptev_read_file(pathname, &sz); |
|
42 |
+ char *data = uptev_read_file(pathname, &sz); |
|
50 | 43 |
if (! data) { |
51 |
- lwptev_cleaner_cleanup(cleaner); |
|
52 | 44 |
return -1; |
53 | 45 |
} |
54 |
- lwptev_cleaner_add_ptr(cleaner, data); |
|
55 | 46 |
/* create pointer array */ |
56 | 47 |
size_t cnt; |
57 |
- char **ptrs = lwptev_stringlist_make_ptrs(data, sz, &cnt); |
|
48 |
+ char **ptrs = uptev_stringlist_make_ptrs(data, sz, &cnt); |
|
58 | 49 |
if (! ptrs) { |
59 |
- lwptev_cleaner_cleanup(cleaner); |
|
50 |
+ free(data); |
|
60 | 51 |
return -1; |
61 | 52 |
} |
62 |
- lwptev_cleaner_add_ptr(cleaner, ptrs); |
|
53 |
+ /* success: add malloc-ed object to cleaner and return string array */ |
|
54 |
+ uptev_cleaner_add_ptr(cleaner, data); |
|
55 |
+ uptev_cleaner_add_ptr(cleaner, ptrs); |
|
63 | 56 |
*n = cnt; |
64 | 57 |
*strs = ptrs; |
65 | 58 |
return 0; |
... | ... |
@@ -0,0 +1,19 @@ |
1 |
+#ifndef UPTEV_STRINGLIST_H |
|
2 |
+#define UPTEV_STRINGLIST_H |
|
3 |
+ |
|
4 |
+#include "cleaner.h" |
|
5 |
+ |
|
6 |
+#include <stdlib.h> |
|
7 |
+ |
|
8 |
+/** |
|
9 |
+ * @brief read string list file |
|
10 |
+ * @param[in] pathname path to file containing zero-terminated string list |
|
11 |
+ * @param[out] *n number of strings read or zero on error |
|
12 |
+ * @param[out] *strs malloc-ed array of malloc-ed strings read or NULL on error |
|
13 |
+ * @param[in,out] cleaner object, malloc-ed object are added to it on success |
|
14 |
+ * @return 0 on success, -1 on error |
|
15 |
+ */ |
|
16 |
+int uptev_stringlist_read(char const *pathname, size_t *n, char ***strs, |
|
17 |
+ uptev_cleaner_t *cleaner); |
|
18 |
+ |
|
19 |
+#endif /* #ifndef UPTEV_STRINGLIST_H */ |
... | ... |
@@ -9,7 +9,7 @@ |
9 | 9 |
* @param[in] pathname path to symbolic link |
10 | 10 |
* @return malloc-ed string containting link target or NULL |
11 | 11 |
*/ |
12 |
-static char * lwptev_symlink_read_target(char const *pathname) { |
|
12 |
+static char * uptev_symlink_read_target(char const *pathname) { |
|
13 | 13 |
size_t sz = 256; |
14 | 14 |
char *target = NULL; |
15 | 15 |
while (1) { |
... | ... |
@@ -35,13 +35,12 @@ static char * lwptev_symlink_read_target(char const *pathname) { |
35 | 35 |
} |
36 | 36 |
} |
37 | 37 |
|
38 |
-int lwptev_symlink_read(char const *pathname, char **target, |
|
39 |
- lwptev_cleaner_t *cleaner) { |
|
40 |
- *target = lwptev_symlink_read_target(pathname); |
|
41 |
- if (! *target) { |
|
42 |
- lwptev_cleaner_cleanup(cleaner); |
|
43 |
- return -1; |
|
38 |
+char * uptev_symlink_read(char const *pathname, uptev_cleaner_t *cleaner) { |
|
39 |
+ char *target = uptev_symlink_read_target(pathname); |
|
40 |
+ if (! target) { |
|
41 |
+ return NULL; |
|
44 | 42 |
} |
45 |
- lwptev_cleaner_add_ptr(cleaner, *target); |
|
46 |
- return 0; |
|
43 |
+ /* success: add malloc-ed object to cleaner and return target string */ |
|
44 |
+ uptev_cleaner_add_ptr(cleaner, target); |
|
45 |
+ return target; |
|
47 | 46 |
} |
... | ... |
@@ -0,0 +1,14 @@ |
1 |
+#ifndef UPTEV_SYMLINK_H |
|
2 |
+#define UPTEV_SYMLINK_H |
|
3 |
+ |
|
4 |
+#include "cleaner.h" |
|
5 |
+ |
|
6 |
+/** |
|
7 |
+ * @brief read symlink |
|
8 |
+ * @param[in] pathname path to symbolic link |
|
9 |
+ * @param[in,out] cleaner object, malloc-ed string is added to it on success |
|
10 |
+ * @return malloc-ed string object containing symlink target or NULL on error |
|
11 |
+ */ |
|
12 |
+char * uptev_symlink_read(char const *pathname, uptev_cleaner_t *cleaner); |
|
13 |
+ |
|
14 |
+#endif /* #ifndef UPTEV_SYMLINK_H */ |
... | ... |
@@ -0,0 +1,23 @@ |
1 |
+#include "timing.h" |
|
2 |
+ |
|
3 |
+#include <uproctrace.pb-c.h> |
|
4 |
+ |
|
5 |
+#include <time.h> |
|
6 |
+ |
|
7 |
+static void uptev_timing_clock_gettime(clockid_t clockid, |
|
8 |
+ struct _Uproctrace__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 uptev_timing_get_timestamp(struct _Uproctrace__Timespec *timestamp) { |
|
17 |
+ uptev_timing_clock_gettime(CLOCK_REALTIME, timestamp); |
|
18 |
+} |
|
19 |
+ |
|
20 |
+void uptev_timing_get_proc_cpu_time(struct _Uproctrace__Timespec |
|
21 |
+ *proc_cpu_time) { |
|
22 |
+ uptev_timing_clock_gettime(CLOCK_PROCESS_CPUTIME_ID, proc_cpu_time); |
|
23 |
+} |
... | ... |
@@ -1,19 +1,19 @@ |
1 |
-#ifndef LWPTEV_TIMING_H |
|
2 |
-#define LWPTEV_TIMING_H |
|
1 |
+#ifndef UPTEV_TIMING_H |
|
2 |
+#define UPTEV_TIMING_H |
|
3 | 3 |
|
4 |
-#include <lwproctrace.pb-c.h> |
|
4 |
+#include <uproctrace.pb-c.h> |
|
5 | 5 |
|
6 | 6 |
/** |
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 lwptev_timing_get_timestamp(struct _Lwproctrace__Timespec *timestamp); |
|
10 |
+void uptev_timing_get_timestamp(struct _Uproctrace__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 lwptev_timing_get_proc_cpu_time(struct _Lwproctrace__Timespec |
|
16 |
+void uptev_timing_get_proc_cpu_time(struct _Uproctrace__Timespec |
|
17 | 17 |
*proc_cpu_time); |
18 | 18 |
|
19 |
-#endif /* #ifndef LWPTEV_TIMING_H */ |
|
19 |
+#endif /* #ifndef UPTEV_TIMING_H */ |
... | ... |
@@ -1,4 +1,4 @@ |
1 |
-#include <liblwptev/proc_begin.h> |
|
1 |
+#include <uptev/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 |
- lwptev_proc_begin(&data, &size); |
|
11 |
- lwptpl_write(data, size); |
|
10 |
+ uptev_proc_begin(&data, &size); |
|
11 |
+ uptpl_write(data, size); |
|
12 | 12 |
} |
... | ... |
@@ -1,4 +1,4 @@ |
1 |
-#include <liblwptev/proc_end.h> |
|
1 |
+#include <uptev/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 |
- lwptev_proc_end(&data, &size); |
|
11 |
- lwptpl_write(data, size); |
|
10 |
+ uptev_proc_end(&data, &size); |
|
11 |
+ uptpl_write(data, size); |
|
12 | 12 |
} |
... | ... |
@@ -7,16 +7,16 @@ |
7 | 7 |
#include <sys/file.h> |
8 | 8 |
#include <unistd.h> |
9 | 9 |
|
10 |
-struct lwptpl_event_header_s { |
|
11 |
- uint8_t magic[4]; /**< l w p t */ |
|
10 |
+struct uptpl_event_header_s { |
|
11 |
+ uint8_t magic[4]; /**< u p t 0 */ |
|
12 | 12 |
uint8_t size[4]; /**< size of payload in network byte oder */ |
13 | 13 |
} __attribute__((packed)); |
14 | 14 |
|
15 |
-void lwptpl_write(void const *data, size_t size) { |
|
15 |
+void uptpl_write(void const *data, size_t size) { |
|
16 | 16 |
if (! data || ! size || size > 0xFFFFFFFF) { |
17 | 17 |
return; |
18 | 18 |
} |
19 |
- char const *filename = getenv("LWPTPL_OUTPUT"); |
|
19 |
+ char const *filename = getenv("UPTPL_OUTPUT"); |
|
20 | 20 |
if (! filename) { |
21 | 21 |
return; |
22 | 22 |
} |
... | ... |
@@ -28,8 +28,8 @@ void lwptpl_write(void const *data, size_t size) { |
28 | 28 |
close(fd); |
29 | 29 |
return; |
30 | 30 |
} |
31 |
- struct lwptpl_event_header_s lwptpl_event_header = { |
|
32 |
- .magic = { 'l', 'w', 'p', 't' }, |
|
31 |
+ struct uptpl_event_header_s uptpl_event_header = { |
|
32 |
+ .magic = { 'u', 'p', 't', '0' }, |
|
33 | 33 |
.size = { |
34 | 34 |
(size >> 24) & 0xFF, |
35 | 35 |
(size >> 16) & 0xFF, |
... | ... |
@@ -37,7 +37,7 @@ void lwptpl_write(void const *data, size_t size) { |
37 | 37 |
size & 0xFF, |
38 | 38 |
} |
39 | 39 |
}; |
40 |
- write(fd, &lwptpl_event_header, sizeof(lwptpl_event_header)); |
|
40 |
+ write(fd, &uptpl_event_header, sizeof(uptpl_event_header)); |
|
41 | 41 |
write(fd, data, size); |
42 | 42 |
flock(fd, LOCK_UN); |
43 | 43 |
close(fd); |
... | ... |
@@ -4,14 +4,16 @@ add_test( |
4 | 4 |
COMMAND |
5 | 5 |
bash -c |
6 | 6 |
" |
7 |
+ set -eux -o pipefail |
|
7 | 8 |
> out.proto |
8 | 9 |
( |
9 |
- export LWPTPL_OUTPUT=out.proto |
|
10 |
- export LD_PRELOAD=${CMAKE_BINARY_DIR}/liblwptpl/liblwptpl.so |
|
10 |
+ export UPTPL_OUTPUT=out.proto |
|
11 |
+ export LD_PRELOAD=${CMAKE_BINARY_DIR}/libuptpl/libuptpl.so |
|
11 | 12 |
/bin/true a b 'c d' |
12 |
- /bin/false e f 'g h' |
|
13 |
+ /usr/bin/printf '' e f 'g h' |
|
13 | 14 |
) |
14 | 15 |
ls -l out.proto |
15 |
- ${CMAKE_BINARY_DIR}/dump/dump.py out.proto |
|
16 |
+ ${CMAKE_BINARY_DIR}/dump/dump.py out.proto | tee out.dump |
|
17 |
+ grep '^ *event *{ *$' out.dump | wc -l | grep '^4$' |
|
16 | 18 |
" |
17 | 19 |
) |
... | ... |
@@ -1,19 +1,23 @@ |
1 | 1 |
syntax = "proto2"; |
2 | 2 |
|
3 |
-package lwproctrace; |
|
3 |
+package uproctrace; |
|
4 | 4 |
|
5 | 5 |
message timespec { |
6 | 6 |
required int64 sec = 1; |
7 | 7 |
optional int32 nsec = 2; |
8 | 8 |
} |
9 | 9 |
|
10 |
+message stringlist { |
|
11 |
+ repeated string s = 1; |
|
12 |
+} |
|
13 |
+ |
|
10 | 14 |
message proc_begin { |
11 | 15 |
required int32 pid = 1; |
12 | 16 |
optional int32 ppid = 2; |
13 | 17 |
optional string exe = 3; |
14 | 18 |
optional string cwd = 4; |
15 |
- repeated string cmdline = 5; |
|
16 |
- repeated string environ = 6; |
|
19 |
+ optional stringlist cmdline = 5; |
|
20 |
+ optional stringlist environ = 6; |
|
17 | 21 |
} |
18 | 22 |
|
19 | 23 |
message proc_end { |
20 | 24 |