diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index 13f95db..cef1ce1 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -24,5 +24,6 @@ jobs: - name: Checking style run: | echo "Checking source and test formatting..." - .build-tools/style/check-style.sh check src + .build-tools/style/check-style.sh check include + .build-tools/style/check-style.sh check tests .build-tools/style/check-style.sh check examples \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ca64af2..aa71440 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -39,7 +39,8 @@ docs: - tiny script: - echo "Checking TraCR source and test formatting..." - - .build-tools/style/check-style.sh check src + - .build-tools/style/check-style.sh check include + - .build-tools/style/check-style.sh check tests - .build-tools/style/check-style.sh check examples only: - main diff --git a/README.md b/README.md index f4d26ba..7a9d9d1 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ - **Examples** provided in the `examples/` folder. - **Post-processing scripts** for trace visualization in `python_scripts/`. - **PyTraCR** for TraCR in python. +- **env flag** use `export DISABLE_TRACR=1` to disable the traces. ## Instrumentation Control diff --git a/examples/README.md b/examples/README.md index 7f195fe..fb20763 100644 --- a/examples/README.md +++ b/examples/README.md @@ -2,14 +2,14 @@ The following examples are provided: -- `thread_markers.cpp`: This is the most commonly used example. The so-called thread markers are stored on the main thread. -If your application uses multiple threads (e.g., with Pthreads), see `pthread_example.cpp`. +- `thread_markers.*`: This is the most commonly used example. The so-called thread markers are stored on the main thread. +If your application uses multiple threads (e.g., with Pthreads), see `pthread_example.*`. -- `pthread_example.cpp`: Similar to `thread_markers.cpp`, but runs across multiple threads using Pthreads. +- `pthread_example.*`: Similar to `thread_markers.*`, but runs across multiple threads using Pthreads. In this case, threads must be explicitly initialized. -- `vmarkers_push_pop.cpp`: Equivalent to `thread_markers.cpp`, but uses VMARKERS (short for vanilla markers). +- `vmarkers_push_pop.*`: Equivalent to `thread_markers.*`, but uses VMARKS (short for vanilla markers). These are lightweight markers that are pushed using a color ID instead of a marker ID. Useful when working with many different markers. -- `vmarkers_set.cpp`: Another VMARKERS example, this time using the SET method instead of PUSH/POP. +- `vmarkers_set.*`: Another VMARKS example, this time using the SET method instead of PUSH/POP. The PUSH/POP method relies on each marker being explicitly pushed and later popped, whereas the SET method simply sets the marker without requiring an end point (i.e. a pop). \ No newline at end of file diff --git a/examples/meson.build b/examples/meson.build index ecfc894..8da6ccc 100644 --- a/examples/meson.build +++ b/examples/meson.build @@ -23,7 +23,7 @@ foreach args : cpp_args_list foreach test_type : test_types test_name = test_type + '_' + flag_name - exe = executable(test_name, test_type + '.cpp', dependencies: InstrumentationBuildDep, cpp_args : args) + exe = executable(test_name, 'tracr/' + test_type + '.cpp', dependencies: InstrumentationBuildDep, cpp_args : args) output_dir = exe.path() + '.p' diff --git a/examples/pytracr/pthread_example.py b/examples/pytracr/pthread_example.py index b1c7c7f..cbdc577 100644 --- a/examples/pytracr/pthread_example.py +++ b/examples/pytracr/pthread_example.py @@ -36,7 +36,7 @@ def threadFunction(lock, id, thrd_running_id, thrd_finished_id): # TraCR init thread INSTRUMENTATION_THREAD_INIT() - INSTRUMENTATION_THREAD_MARK_SET(thrd_running_id) + INSTRUMENTATION_MARK_SET(thrd_running_id) # Get the process ID (PID) and thread ID (TID) pid = os.getpid() # Process ID @@ -53,7 +53,7 @@ def threadFunction(lock, id, thrd_running_id, thrd_finished_id): print(f"Thread {id} is running task: {taskid}") - INSTRUMENTATION_THREAD_MARK_SET(thrd_finished_id) + INSTRUMENTATION_MARK_SET(thrd_finished_id) # TraCR free thread INSTRUMENTATION_THREAD_END() @@ -67,14 +67,14 @@ def main(): INSTRUMENTATION_START() # 0 == Set and 1 == Push/Pop - INSTRUMENTATION_THREAD_MARK_INIT(0) + INSTRUMENTATION_MARK_INIT(0) # Each Label creation costs around (~3us) # Should be done at the beginning or at the ending of the code - thrd_running_id = INSTRUMENTATION_THREAD_MARK_ADD(mark_color.MARK_COLOR_MINT, "thread running") - thrd_finished_id = INSTRUMENTATION_THREAD_MARK_ADD(mark_color.MARK_COLOR_GREEN, "thread finished") - thrd_join_id = INSTRUMENTATION_THREAD_MARK_ADD(mark_color.MARK_COLOR_BROWN, "join threads") - thrds_end_id = INSTRUMENTATION_THREAD_MARK_ADD(mark_color.MARK_COLOR_RED, "threads end") + thrd_running_id = INSTRUMENTATION_MARK_ADD(mark_color.MARK_COLOR_MINT, "thread running") + thrd_finished_id = INSTRUMENTATION_MARK_ADD(mark_color.MARK_COLOR_GREEN, "thread finished") + thrd_join_id = INSTRUMENTATION_MARK_ADD(mark_color.MARK_COLOR_BROWN, "join threads") + thrds_end_id = INSTRUMENTATION_MARK_ADD(mark_color.MARK_COLOR_RED, "threads end") threads = [None] * NRANKS # Vector to hold pthreads threadIds = [None] * NRANKS # Vector to hold thread IDs @@ -90,13 +90,13 @@ def main(): threads[i].start() - INSTRUMENTATION_THREAD_MARK_SET(thrd_join_id) + INSTRUMENTATION_MARK_SET(thrd_join_id) # Wait for all threads to finish for thread in threads: thread.join() - INSTRUMENTATION_THREAD_MARK_SET(thrds_end_id) + INSTRUMENTATION_MARK_SET(thrds_end_id) print("All threads have finished.") diff --git a/examples/pytracr/thread_markers.py b/examples/pytracr/thread_markers.py index 3fe9eff..eace005 100644 --- a/examples/pytracr/thread_markers.py +++ b/examples/pytracr/thread_markers.py @@ -30,49 +30,49 @@ def main(): INSTRUMENTATION_START() # 0 == Set and 1 == Push/Pop - INSTRUMENTATION_THREAD_MARK_INIT(1) + INSTRUMENTATION_MARK_INIT(1) - # Each INSTRUMENTATION_THREAD_MARK_ADD costs around (~3us) + # Each INSTRUMENTATION_MARK_ADD costs around (~3us) # Should be done at the beginning or at the ending of the code - alloc_mem_label_id = INSTRUMENTATION_THREAD_MARK_ADD(mark_color.MARK_COLOR_TEAL, "Allocate Memory") - fill_mat_label_id = INSTRUMENTATION_THREAD_MARK_ADD(mark_color.MARK_COLOR_LAVENDER, "Fill matrices with values") - prt_mat_label_id = INSTRUMENTATION_THREAD_MARK_ADD(mark_color.MARK_COLOR_RED, "Print all matrices") - mmm_label_id = INSTRUMENTATION_THREAD_MARK_ADD(mark_color.MARK_COLOR_PEACH, "MMM") - prt_A_label_id = INSTRUMENTATION_THREAD_MARK_ADD(mark_color.MARK_COLOR_LIGHT_GRAY, "Print solution of matrix A") + alloc_mem_label_id = INSTRUMENTATION_MARK_ADD(mark_color.MARK_COLOR_TEAL, "Allocate Memory") + fill_mat_label_id = INSTRUMENTATION_MARK_ADD(mark_color.MARK_COLOR_LAVENDER, "Fill matrices with values") + prt_mat_label_id = INSTRUMENTATION_MARK_ADD(mark_color.MARK_COLOR_RED, "Print all matrices") + mmm_label_id = INSTRUMENTATION_MARK_ADD(mark_color.MARK_COLOR_PEACH, "MMM") + prt_A_label_id = INSTRUMENTATION_MARK_ADD(mark_color.MARK_COLOR_LIGHT_GRAY, "Print solution of matrix A") t_after_label_set = time.time() # allocate memory - INSTRUMENTATION_THREAD_MARK_PUSH(alloc_mem_label_id) + INSTRUMENTATION_MARK_PUSH(alloc_mem_label_id) A = np.empty((N,N)) B = np.empty((N,N)) C = np.empty((N,N)) # fill matrices - INSTRUMENTATION_THREAD_MARK_PUSH(fill_mat_label_id) + INSTRUMENTATION_MARK_PUSH(fill_mat_label_id) for i in range(N): for j in range(N): B[i,j] = i C[i,j] = j - INSTRUMENTATION_THREAD_MARK_POP(fill_mat_label_id) - INSTRUMENTATION_THREAD_MARK_POP(alloc_mem_label_id) + INSTRUMENTATION_MARK_POP(fill_mat_label_id) + INSTRUMENTATION_MARK_POP(alloc_mem_label_id) # print matrices - INSTRUMENTATION_THREAD_MARK_PUSH(prt_mat_label_id) + INSTRUMENTATION_MARK_PUSH(prt_mat_label_id) print(f"A: {A}") print(f"B: {B}") print(f"C: {C}") - INSTRUMENTATION_THREAD_MARK_POP(prt_mat_label_id) + INSTRUMENTATION_MARK_POP(prt_mat_label_id) # mmm - INSTRUMENTATION_THREAD_MARK_PUSH(mmm_label_id) + INSTRUMENTATION_MARK_PUSH(mmm_label_id) A = B @ C - INSTRUMENTATION_THREAD_MARK_POP(mmm_label_id) + INSTRUMENTATION_MARK_POP(mmm_label_id) # last print - INSTRUMENTATION_THREAD_MARK_PUSH(prt_A_label_id) + INSTRUMENTATION_MARK_PUSH(prt_A_label_id) print(f"A: {A}") - INSTRUMENTATION_THREAD_MARK_POP(prt_A_label_id) + INSTRUMENTATION_MARK_POP(prt_A_label_id) # TraCR finished INSTRUMENTATION_END() diff --git a/examples/pytracr/vmarkers_push_pop.py b/examples/pytracr/vmarkers_push_pop.py index 9f8601d..b1b9e3d 100644 --- a/examples/pytracr/vmarkers_push_pop.py +++ b/examples/pytracr/vmarkers_push_pop.py @@ -23,11 +23,11 @@ VMakers (Vanilla Markers) are the type of markers pushing the color ID directly. - This example is the same as the thread_markers.cpp but with VMARKERS + This example is the same as the thread_markers.cpp but with VMARKS They are useful if you don't wanna have labels and wanna keep track the number. - Still, one can use INSTRUMENTATION_VMARKER_LABEL() if labels are of need. + Still, one can use INSTRUMENTATION_VMARK_LABEL() if labels are of need. But then you need to remember which color id corresponds to which label. """ def main(): @@ -40,50 +40,50 @@ def main(): # 0 == Set and 1 == Push/Pop flag = 1 - INSTRUMENTATION_VMARKER_TYPE(flag, "Simple Marker Example") + INSTRUMENTATION_VMARK_TYPE(flag, "Simple Marker Example") - # Each INSTRUMENTATION_THREAD_MARK_ADD costs around (~3us) + # Each INSTRUMENTATION_MARK_ADD costs around (~3us) # Should be done at the beginning or at the ending of the code - INSTRUMENTATION_VMARKER_LABEL(MARK_COLOR_LIGHT_GREEN, "Allocate Memory") - INSTRUMENTATION_VMARKER_LABEL(MARK_COLOR_LAVENDER, + INSTRUMENTATION_VMARK_LABEL(MARK_COLOR_LIGHT_GREEN, "Allocate Memory") + INSTRUMENTATION_VMARK_LABEL(MARK_COLOR_LAVENDER, "Fill matrices with values") - INSTRUMENTATION_VMARKER_LABEL(MARK_COLOR_MAROON, "Print all matrices") - INSTRUMENTATION_VMARKER_LABEL(MARK_COLOR_OLIVE, "MMM") - INSTRUMENTATION_VMARKER_LABEL(MARK_COLOR_NAVY, "Print solution of matrix A") + INSTRUMENTATION_VMARK_LABEL(MARK_COLOR_MAROON, "Print all matrices") + INSTRUMENTATION_VMARK_LABEL(MARK_COLOR_OLIVE, "MMM") + INSTRUMENTATION_VMARK_LABEL(MARK_COLOR_NAVY, "Print solution of matrix A") t_after_label_set = time.time() # allocate memory - INSTRUMENTATION_VMARKER_PUSH(MARK_COLOR_LIGHT_GREEN) + INSTRUMENTATION_VMARK_PUSH(MARK_COLOR_LIGHT_GREEN) A = np.empty((N,N)) B = np.empty((N,N)) C = np.empty((N,N)) # fill matrices - INSTRUMENTATION_VMARKER_PUSH(MARK_COLOR_LAVENDER) + INSTRUMENTATION_VMARK_PUSH(MARK_COLOR_LAVENDER) for i in range(N): for j in range(N): B[i, j] = i C[i, j] = j - INSTRUMENTATION_VMARKER_POP(MARK_COLOR_LAVENDER) - INSTRUMENTATION_VMARKER_POP(MARK_COLOR_LIGHT_GREEN) + INSTRUMENTATION_VMARK_POP(MARK_COLOR_LAVENDER) + INSTRUMENTATION_VMARK_POP(MARK_COLOR_LIGHT_GREEN) # print matrices - INSTRUMENTATION_VMARKER_PUSH(MARK_COLOR_MAROON) + INSTRUMENTATION_VMARK_PUSH(MARK_COLOR_MAROON) print(f"A: {A}") print(f"B: {B}") print(f"C: {C}") - INSTRUMENTATION_VMARKER_POP(MARK_COLOR_MAROON) + INSTRUMENTATION_VMARK_POP(MARK_COLOR_MAROON) # mmm - INSTRUMENTATION_VMARKER_PUSH(MARK_COLOR_OLIVE) + INSTRUMENTATION_VMARK_PUSH(MARK_COLOR_OLIVE) A = B @ C - INSTRUMENTATION_VMARKER_POP(MARK_COLOR_OLIVE) + INSTRUMENTATION_VMARK_POP(MARK_COLOR_OLIVE) # last print - INSTRUMENTATION_VMARKER_PUSH(MARK_COLOR_NAVY) + INSTRUMENTATION_VMARK_PUSH(MARK_COLOR_NAVY) print(f"A: {A}") - INSTRUMENTATION_VMARKER_POP(MARK_COLOR_NAVY) + INSTRUMENTATION_VMARK_POP(MARK_COLOR_NAVY) # TraCR finished INSTRUMENTATION_END() diff --git a/examples/pytracr/vmarkers_set.py b/examples/pytracr/vmarkers_set.py index 0c2f3fd..ac39c66 100644 --- a/examples/pytracr/vmarkers_set.py +++ b/examples/pytracr/vmarkers_set.py @@ -18,7 +18,7 @@ """ Basic c code to demonstrate TraCR's VMAKERS - This example uses the VMARKER SET method + This example uses the VMARK SET method you can create a nice gradient plot in Paraver with it """ def main(): @@ -27,11 +27,11 @@ def main(): # use flag == 1 for push/pop and flag == 0 for the set method flag = 0 - INSTRUMENTATION_VMARKER_TYPE(flag, "Simple VMarker Example") + INSTRUMENTATION_VMARK_TYPE(flag, "Simple VMarker Example") n = 150 for i in range(1, n+1): - INSTRUMENTATION_VMARKER_SET(i) + INSTRUMENTATION_VMARK_SET(i) print(i, end=' ') # TraCR finished diff --git a/examples/pthread_example.cpp b/examples/tracr/pthread_example.cpp similarity index 83% rename from examples/pthread_example.cpp rename to examples/tracr/pthread_example.cpp index 8331701..ce439c6 100644 --- a/examples/pthread_example.cpp +++ b/examples/tracr/pthread_example.cpp @@ -20,7 +20,7 @@ #include // For getpid() #include -#include +#include #define NRANKS 4 // number of threads #define NTASKS 3 // number of tasks per thread @@ -40,7 +40,7 @@ void *threadFunction(void *arg) { // TraCR init thread INSTRUMENTATION_THREAD_INIT(); - INSTRUMENTATION_THREAD_MARK_SET(thrd_running_id); + INSTRUMENTATION_MARK_SET(thrd_running_id); // Get the process ID (PID) and thread ID (TID) pid_t pid = getpid(); // Process ID @@ -60,11 +60,11 @@ void *threadFunction(void *arg) { std::cout << "Thread " << id << " is running task: " << taskid << std::endl; } - INSTRUMENTATION_THREAD_MARK_SET(thrd_finished_id); + INSTRUMENTATION_MARK_SET(thrd_finished_id); // Optional: This marker pushes the int64_t max value. Can be used to indicate // the ending. - INSTRUMENTATION_VMARKER_RESET(); + INSTRUMENTATION_MARK_RESET(); // TraCR free thread INSTRUMENTATION_THREAD_END(); @@ -83,18 +83,17 @@ int main() { INSTRUMENTATION_START(externally_init); // 0 == Set and 1 == Push/Pop - INSTRUMENTATION_THREAD_MARK_INIT(0); + INSTRUMENTATION_MARK_INIT(0); // Each Label creation costs around (~3us) // Should be done at the beginning or at the ending of the code - thrd_running_id = - INSTRUMENTATION_THREAD_MARK_ADD(MARK_COLOR_MINT, "thread running"); + thrd_running_id = INSTRUMENTATION_MARK_ADD(MARK_COLOR_MINT, "thread running"); thrd_finished_id = - INSTRUMENTATION_THREAD_MARK_ADD(MARK_COLOR_GREEN, "thread finished"); + INSTRUMENTATION_MARK_ADD(MARK_COLOR_GREEN, "thread finished"); const size_t thrd_join_id = - INSTRUMENTATION_THREAD_MARK_ADD(MARK_COLOR_BROWN, "join threads"); + INSTRUMENTATION_MARK_ADD(MARK_COLOR_BROWN, "join threads"); const size_t thrds_end_id = - INSTRUMENTATION_THREAD_MARK_ADD(MARK_COLOR_RED, "threads end"); + INSTRUMENTATION_MARK_ADD(MARK_COLOR_RED, "threads end"); std::vector threads(NRANKS); // Vector to hold pthreads std::vector threadIds(NRANKS); // Vector to hold thread IDs @@ -108,14 +107,14 @@ int main() { pthread_create(&threads[i], nullptr, threadFunction, &threadIds[i]); } - INSTRUMENTATION_THREAD_MARK_SET(thrd_join_id); + INSTRUMENTATION_MARK_SET(thrd_join_id); // Wait for all threads to finish for (int i = 0; i < NRANKS; ++i) { pthread_join(threads[i], nullptr); } - INSTRUMENTATION_THREAD_MARK_SET(thrds_end_id); + INSTRUMENTATION_MARK_SET(thrds_end_id); std::cout << "All threads have finished." << std::endl; diff --git a/examples/thread_markers.cpp b/examples/tracr/thread_markers.cpp similarity index 71% rename from examples/thread_markers.cpp rename to examples/tracr/thread_markers.cpp index c849d32..aac2257 100644 --- a/examples/thread_markers.cpp +++ b/examples/tracr/thread_markers.cpp @@ -15,7 +15,7 @@ */ #include -#include +#include #define mytype float @@ -50,44 +50,43 @@ int main(void) { INSTRUMENTATION_START(externally_init); // 0 == Set and 1 == Push/Pop - INSTRUMENTATION_THREAD_MARK_INIT(1); + INSTRUMENTATION_MARK_INIT(1); - // Each INSTRUMENTATION_THREAD_MARK_ADD costs around (~3us) + // Each INSTRUMENTATION_MARK_ADD costs around (~3us) // Should be done at the beginning or at the ending of the code const size_t alloc_mem_label_id = - INSTRUMENTATION_THREAD_MARK_ADD(MARK_COLOR_TEAL, "Allocate Memory"); - const size_t fill_mat_label_id = INSTRUMENTATION_THREAD_MARK_ADD( + INSTRUMENTATION_MARK_ADD(MARK_COLOR_TEAL, "Allocate Memory"); + const size_t fill_mat_label_id = INSTRUMENTATION_MARK_ADD( MARK_COLOR_LAVENDER, "Fill matrices with values"); const size_t prt_mat_label_id = - INSTRUMENTATION_THREAD_MARK_ADD(MARK_COLOR_RED, "Print all matrices"); - const size_t mmm_label_id = - INSTRUMENTATION_THREAD_MARK_ADD(MARK_COLOR_PEACH, "MMM"); - const size_t prt_A_label_id = INSTRUMENTATION_THREAD_MARK_ADD( + INSTRUMENTATION_MARK_ADD(MARK_COLOR_RED, "Print all matrices"); + const size_t mmm_label_id = INSTRUMENTATION_MARK_ADD(MARK_COLOR_PEACH, "MMM"); + const size_t prt_A_label_id = INSTRUMENTATION_MARK_ADD( MARK_COLOR_LIGHT_GRAY, "Print solution of matrix A"); const size_t free_mem_label_id = - INSTRUMENTATION_THREAD_MARK_ADD(MARK_COLOR_MINT, "Free memory"); + INSTRUMENTATION_MARK_ADD(MARK_COLOR_MINT, "Free memory"); after_label_set = std::chrono::system_clock::now(); // allocate memory - INSTRUMENTATION_THREAD_MARK_PUSH(alloc_mem_label_id); + INSTRUMENTATION_MARK_PUSH(alloc_mem_label_id); mytype *A = (mytype *)calloc(1, N * N * sizeof(mytype)); mytype *B = (mytype *)malloc(N * N * sizeof(mytype)); mytype *C = (mytype *)malloc(N * N * sizeof(mytype)); // fill matrices - INSTRUMENTATION_THREAD_MARK_PUSH(fill_mat_label_id); + INSTRUMENTATION_MARK_PUSH(fill_mat_label_id); for (size_t i = 0; i < N; ++i) { for (size_t j = 0; j < N; ++j) { B[i * N + j] = (mytype)i; C[i * N + j] = (mytype)j; } } - INSTRUMENTATION_THREAD_MARK_POP(fill_mat_label_id); - INSTRUMENTATION_THREAD_MARK_POP(alloc_mem_label_id); + INSTRUMENTATION_MARK_POP(fill_mat_label_id); + INSTRUMENTATION_MARK_POP(alloc_mem_label_id); // print matrices - INSTRUMENTATION_THREAD_MARK_PUSH(prt_mat_label_id); + INSTRUMENTATION_MARK_PUSH(prt_mat_label_id); printf("A:\n"); print_matrix(A, N); @@ -96,10 +95,10 @@ int main(void) { printf("C:\n"); print_matrix(C, N); - INSTRUMENTATION_THREAD_MARK_POP(prt_mat_label_id); + INSTRUMENTATION_MARK_POP(prt_mat_label_id); // mmm - INSTRUMENTATION_THREAD_MARK_PUSH(mmm_label_id); + INSTRUMENTATION_MARK_PUSH(mmm_label_id); for (size_t i = 0; i < N; ++i) { for (size_t j = 0; j < N; ++j) { for (size_t k = 0; k < N; ++k) { @@ -107,20 +106,20 @@ int main(void) { } } } - INSTRUMENTATION_THREAD_MARK_POP(mmm_label_id); + INSTRUMENTATION_MARK_POP(mmm_label_id); // last print - INSTRUMENTATION_THREAD_MARK_PUSH(prt_A_label_id); + INSTRUMENTATION_MARK_PUSH(prt_A_label_id); printf("A (after mmm):\n"); print_matrix(A, N); - INSTRUMENTATION_THREAD_MARK_POP(prt_A_label_id); + INSTRUMENTATION_MARK_POP(prt_A_label_id); // free memory - INSTRUMENTATION_THREAD_MARK_PUSH(free_mem_label_id); + INSTRUMENTATION_MARK_PUSH(free_mem_label_id); free(A); free(B); free(C); - INSTRUMENTATION_THREAD_MARK_POP(free_mem_label_id); + INSTRUMENTATION_MARK_POP(free_mem_label_id); // TraCR finished INSTRUMENTATION_END(); diff --git a/examples/vmarkers_push_pop.cpp b/examples/tracr/vmarkers_push_pop.cpp similarity index 72% rename from examples/vmarkers_push_pop.cpp rename to examples/tracr/vmarkers_push_pop.cpp index ba78205..fedf8c4 100644 --- a/examples/vmarkers_push_pop.cpp +++ b/examples/tracr/vmarkers_push_pop.cpp @@ -15,7 +15,7 @@ */ #include -#include +#include #define mytype float @@ -37,12 +37,12 @@ static void print_matrix(mytype *matrix, const size_t N) { * VMakers (Vanilla Markers) are the type of markers pushing the color ID * directly. * - * This example is the same as the thread_markers.cpp but with VMARKERS + * This example is the same as the thread_markers.cpp but with VMARKS * * They are useful if you don't wanna have labels and wanna keep track the * number. * - * Still, one can use INSTRUMENTATION_VMARKER_LABEL() if labels are of need. + * Still, one can use INSTRUMENTATION_VMARK_LABEL() if labels are of need. * But then you need to remember which color id corresponds to which label. */ int main(void) { @@ -61,39 +61,38 @@ int main(void) { // use flag == 1 for push/pop and flag == 0 for the set method bool flag = 1; - INSTRUMENTATION_VMARKER_TYPE(flag, "Simple Marker Example"); + INSTRUMENTATION_VMARK_TYPE(flag, "Simple Marker Example"); // Each Label creation costs around (~3us) // Should be done at the beginning or at the ending of the code - INSTRUMENTATION_VMARKER_LABEL(MARK_COLOR_LIGHT_GREEN, "Allocate Memory"); - INSTRUMENTATION_VMARKER_LABEL(MARK_COLOR_LAVENDER, - "Fill matrices with values"); - INSTRUMENTATION_VMARKER_LABEL(MARK_COLOR_MAROON, "Print all matrices"); - INSTRUMENTATION_VMARKER_LABEL(MARK_COLOR_OLIVE, "MMM"); - INSTRUMENTATION_VMARKER_LABEL(MARK_COLOR_NAVY, "Print solution of matrix A"); - INSTRUMENTATION_VMARKER_LABEL(MARK_COLOR_PINK, "Free memory"); + INSTRUMENTATION_VMARK_LABEL(MARK_COLOR_LIGHT_GREEN, "Allocate Memory"); + INSTRUMENTATION_VMARK_LABEL(MARK_COLOR_LAVENDER, "Fill matrices with values"); + INSTRUMENTATION_VMARK_LABEL(MARK_COLOR_MAROON, "Print all matrices"); + INSTRUMENTATION_VMARK_LABEL(MARK_COLOR_OLIVE, "MMM"); + INSTRUMENTATION_VMARK_LABEL(MARK_COLOR_NAVY, "Print solution of matrix A"); + INSTRUMENTATION_VMARK_LABEL(MARK_COLOR_PINK, "Free memory"); after_label_set = std::chrono::system_clock::now(); // allocate memory - INSTRUMENTATION_VMARKER_PUSH(MARK_COLOR_LIGHT_GREEN); + INSTRUMENTATION_VMARK_PUSH(MARK_COLOR_LIGHT_GREEN); mytype *A = (mytype *)calloc(1, N * N * sizeof(mytype)); mytype *B = (mytype *)malloc(N * N * sizeof(mytype)); mytype *C = (mytype *)malloc(N * N * sizeof(mytype)); // fill matrices - INSTRUMENTATION_VMARKER_PUSH(MARK_COLOR_LAVENDER); + INSTRUMENTATION_VMARK_PUSH(MARK_COLOR_LAVENDER); for (size_t i = 0; i < N; ++i) { for (size_t j = 0; j < N; ++j) { B[i * N + j] = (mytype)i; C[i * N + j] = (mytype)j; } } - INSTRUMENTATION_VMARKER_POP(MARK_COLOR_LAVENDER); - INSTRUMENTATION_VMARKER_POP(MARK_COLOR_LIGHT_GREEN); + INSTRUMENTATION_VMARK_POP(MARK_COLOR_LAVENDER); + INSTRUMENTATION_VMARK_POP(MARK_COLOR_LIGHT_GREEN); // print matrices - INSTRUMENTATION_VMARKER_PUSH(MARK_COLOR_MAROON); + INSTRUMENTATION_VMARK_PUSH(MARK_COLOR_MAROON); printf("A:\n"); print_matrix(A, N); @@ -102,10 +101,10 @@ int main(void) { printf("C:\n"); print_matrix(C, N); - INSTRUMENTATION_VMARKER_POP(MARK_COLOR_MAROON); + INSTRUMENTATION_VMARK_POP(MARK_COLOR_MAROON); // mmm - INSTRUMENTATION_VMARKER_PUSH(MARK_COLOR_OLIVE); + INSTRUMENTATION_VMARK_PUSH(MARK_COLOR_OLIVE); for (size_t i = 0; i < N; ++i) { for (size_t j = 0; j < N; ++j) { for (size_t k = 0; k < N; ++k) { @@ -113,20 +112,20 @@ int main(void) { } } } - INSTRUMENTATION_VMARKER_POP(MARK_COLOR_OLIVE); + INSTRUMENTATION_VMARK_POP(MARK_COLOR_OLIVE); // last print - INSTRUMENTATION_VMARKER_PUSH(MARK_COLOR_NAVY); + INSTRUMENTATION_VMARK_PUSH(MARK_COLOR_NAVY); printf("A (after mmm):\n"); print_matrix(A, N); - INSTRUMENTATION_VMARKER_POP(MARK_COLOR_NAVY); + INSTRUMENTATION_VMARK_POP(MARK_COLOR_NAVY); // free memory - INSTRUMENTATION_VMARKER_PUSH(MARK_COLOR_PINK); + INSTRUMENTATION_VMARK_PUSH(MARK_COLOR_PINK); free(A); free(B); free(C); - INSTRUMENTATION_VMARKER_POP(MARK_COLOR_PINK); + INSTRUMENTATION_VMARK_POP(MARK_COLOR_PINK); // TraCR finished INSTRUMENTATION_END(); diff --git a/examples/vmarkers_set.cpp b/examples/tracr/vmarkers_set.cpp similarity index 87% rename from examples/vmarkers_set.cpp rename to examples/tracr/vmarkers_set.cpp index 89b71b7..b0ad155 100644 --- a/examples/vmarkers_set.cpp +++ b/examples/tracr/vmarkers_set.cpp @@ -14,11 +14,11 @@ * limitations under the License. */ -#include +#include /** * Basic c code to demonstrate TraCR's VMAKERS - * This example uses the VMARKER SET method + * This example uses the VMARK SET method * you can create a nice gradient plot in Paraver with it */ int main(void) { @@ -30,11 +30,11 @@ int main(void) { // use flag == 1 for push/pop and flag == 0 for the set method bool flag = 0; - INSTRUMENTATION_VMARKER_TYPE(flag, "Simple Marker Example"); + INSTRUMENTATION_VMARK_TYPE(flag, "Simple Marker Example"); const int n = 150; for (int i = 1; i <= n; ++i) { - INSTRUMENTATION_VMARKER_SET(i); + INSTRUMENTATION_VMARK_SET(i); printf("%d ", i); } diff --git a/include/pytracr/README.md b/include/pytracr/README.md index af007c9..742bba3 100644 --- a/include/pytracr/README.md +++ b/include/pytracr/README.md @@ -14,12 +14,12 @@ Be sure all the tests are passing! Now, inside the `build` folder it will create another folder called `mock_install/share/pkgconfig` and this pkg-config file `pybind11.pc` type this: ``` -prefix=/tracr/extern/pybind11/ +prefix=/tracr/extern/pybind11 includedir=${prefix}/include Name: pybind11 Description: Seamless operability between C++11 and Python -Version: 2.13.6 +Version: Cflags: -I${includedir} ``` diff --git a/include/pytracr/pytracr.cpp b/include/pytracr/pytracr.cpp index 6eb53e2..f2fe609 100644 --- a/include/pytracr/pytracr.cpp +++ b/include/pytracr/pytracr.cpp @@ -16,7 +16,7 @@ #include -#include +#include namespace py = pybind11; @@ -41,49 +41,49 @@ static void instrumentation_thread_end_() { INSTRUMENTATION_THREAD_END(); } /** * ovni thread marker methods */ -static void instrumentation_thread_mark_init(size_t flag) { - INSTRUMENTATION_THREAD_MARK_INIT(flag); +static void instrumentation_mark_init(size_t flag) { + INSTRUMENTATION_MARK_INIT(flag); } -static size_t instrumentation_thread_mark_add(size_t value, const char *label) { - return INSTRUMENTATION_THREAD_MARK_ADD(value, label); +static size_t instrumentation_mark_add(size_t value, const char *label) { + return INSTRUMENTATION_MARK_ADD(value, label); } -static void instrumentation_thread_mark_set(size_t idx) { - INSTRUMENTATION_THREAD_MARK_SET(idx); +static void instrumentation_mark_set(size_t idx) { + INSTRUMENTATION_MARK_SET(idx); } -static void instrumentation_thread_mark_push(size_t idx) { - INSTRUMENTATION_THREAD_MARK_PUSH(idx); +static void instrumentation_mark_push(size_t idx) { + INSTRUMENTATION_MARK_PUSH(idx); } -static void instrumentation_thread_mark_pop(size_t idx) { - INSTRUMENTATION_THREAD_MARK_POP(idx); +static void instrumentation_mark_pop(size_t idx) { + INSTRUMENTATION_MARK_POP(idx); } +static void instrumentation_mark_reset() { INSTRUMENTATION_MARK_RESET(); } + /** * ovni marker methods (vanilla) */ -static void instrumentation_vmarker_type(size_t flag, const char *title) { - INSTRUMENTATION_VMARKER_TYPE(flag, title); +static void instrumentation_vmark_type(size_t flag, const char *title) { + INSTRUMENTATION_VMARK_TYPE(flag, title); } -static void instrumentation_vmarker_label(size_t value, const char *label) { - INSTRUMENTATION_VMARKER_LABEL(value, label); +static void instrumentation_vmark_label(size_t value, const char *label) { + INSTRUMENTATION_VMARK_LABEL(value, label); } -static void instrumentation_vmarker_set(size_t value) { - INSTRUMENTATION_VMARKER_SET(value); +static void instrumentation_vmark_set(size_t value) { + INSTRUMENTATION_VMARK_SET(value); } -static void instrumentation_vmarker_reset() { INSTRUMENTATION_VMARKER_RESET(); } - -static void instrumentation_vmarker_push(size_t value) { - INSTRUMENTATION_VMARKER_PUSH(value); +static void instrumentation_vmark_push(size_t value) { + INSTRUMENTATION_VMARK_PUSH(value); } -static void instrumentation_vmarker_pop(size_t value) { - INSTRUMENTATION_VMARKER_POP(value); +static void instrumentation_vmark_pop(size_t value) { + INSTRUMENTATION_VMARK_POP(value); } PYBIND11_MODULE(tracr, m) { @@ -107,26 +107,21 @@ PYBIND11_MODULE(tracr, m) { /** * ovni thread marker methods */ - m.def("INSTRUMENTATION_THREAD_MARK_INIT", &instrumentation_thread_mark_init, - ""); - m.def("INSTRUMENTATION_THREAD_MARK_ADD", &instrumentation_thread_mark_add, - ""); - m.def("INSTRUMENTATION_THREAD_MARK_SET", &instrumentation_thread_mark_set, - ""); - m.def("INSTRUMENTATION_THREAD_MARK_PUSH", &instrumentation_thread_mark_push, - ""); - m.def("INSTRUMENTATION_THREAD_MARK_POP", &instrumentation_thread_mark_pop, - ""); + m.def("INSTRUMENTATION_MARK_INIT", &instrumentation_mark_init, ""); + m.def("INSTRUMENTATION_MARK_ADD", &instrumentation_mark_add, ""); + m.def("INSTRUMENTATION_MARK_SET", &instrumentation_mark_set, ""); + m.def("INSTRUMENTATION_MARK_PUSH", &instrumentation_mark_push, ""); + m.def("INSTRUMENTATION_MARK_POP", &instrumentation_mark_pop, ""); + m.def("INSTRUMENTATION_MARK_RESET", &instrumentation_mark_reset, ""); /** * ovni marker methods (vanilla) */ - m.def("INSTRUMENTATION_VMARKER_TYPE", &instrumentation_vmarker_type, ""); - m.def("INSTRUMENTATION_VMARKER_LABEL", &instrumentation_vmarker_label, ""); - m.def("INSTRUMENTATION_VMARKER_SET", &instrumentation_vmarker_set, ""); - m.def("INSTRUMENTATION_VMARKER_RESET", &instrumentation_vmarker_reset, ""); - m.def("INSTRUMENTATION_VMARKER_PUSH", &instrumentation_vmarker_push, ""); - m.def("INSTRUMENTATION_VMARKER_POP", &instrumentation_vmarker_pop, ""); + m.def("INSTRUMENTATION_VMARK_TYPE", &instrumentation_vmark_type, ""); + m.def("INSTRUMENTATION_VMARK_LABEL", &instrumentation_vmark_label, ""); + m.def("INSTRUMENTATION_VMARK_SET", &instrumentation_vmark_set, ""); + m.def("INSTRUMENTATION_VMARK_PUSH", &instrumentation_vmark_push, ""); + m.def("INSTRUMENTATION_VMARK_POP", &instrumentation_vmark_pop, ""); py::enum_(m, "mark_color", py::arithmetic()) .value("MARK_COLOR_BLUE", MARK_COLOR_BLUE) diff --git a/src/base_instr.hpp b/include/tracr/base_instr.hpp similarity index 100% rename from src/base_instr.hpp rename to include/tracr/base_instr.hpp diff --git a/src/meson.build b/include/tracr/meson.build similarity index 100% rename from src/meson.build rename to include/tracr/meson.build diff --git a/src/tracr.cpp b/include/tracr/tracr.cpp similarity index 65% rename from src/tracr.cpp rename to include/tracr/tracr.cpp index 3d12027..2cfa8b6 100644 --- a/src/tracr.cpp +++ b/include/tracr/tracr.cpp @@ -21,7 +21,7 @@ * @date 17/12/2024 */ -#include "tracr.hpp" +#include /** * Using this flag will enable all the instrumentations of TraCR. Otherwise pure @@ -41,8 +41,33 @@ pid_t main_TID; */ bool external_init; +/** + * An env variable to disable the traces + */ +bool disable_tracr = false; + +/** + * automatic label ID assigning, i.e. doesn't matter which color the label is + * assigned to + */ +std::atomic auto_label{23L}; + +/** + * A function to check if the env flag DISABLE_TRACR is active or not + */ +bool get_env_flag() { + const char *val = std::getenv("DISABLE_TRACR"); + if (!val) + return false; // not set -> treat as false + + std::string s(val); + // accept "1", "true", "TRUE", etc. + return (s == "1" || s == "true" || s == "TRUE" || s == "on" || s == "ON"); +} + /** * ovni thread marker methods */ ThreadMarkerMap thread_marker_map; -#endif + +#endif /* ENABLE_INSTRUMENTATION */ diff --git a/include/tracr/tracr.hpp b/include/tracr/tracr.hpp new file mode 100644 index 0000000..2d9655f --- /dev/null +++ b/include/tracr/tracr.hpp @@ -0,0 +1,287 @@ +/* + * Copyright 2025 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file tracr.hpp + * @brief instrumentation calls inside #define functionalities + * @author Noah Baumann + * @date 17/12/2024 + */ + +#pragma once + +#include +#include // std::getenv +#include // get_nprocs() + +#include "base_instr.hpp" +#include + +/** + * Marker colors values of the default Paraver color palette + * NOTE: Black would be 0 but in ovni it is illegal! + */ +enum mark_color : int64_t { + MARK_COLOR_BLUE = 1, + MARK_COLOR_LIGHT_GRAY, + MARK_COLOR_RED, + MARK_COLOR_GREEN, + MARK_COLOR_YELLOW, + MARK_COLOR_ORANGE, + MARK_COLOR_PURPLE, + MARK_COLOR_CYAN, + MARK_COLOR_MAGENTA, + MARK_COLOR_LIGHT_GREEN, + MARK_COLOR_PINK, + MARK_COLOR_TEAL, + MARK_COLOR_GRAY, + MARK_COLOR_LAVENDER, + MARK_COLOR_BROWN, + MARK_COLOR_LIGHT_YELLOW, + MARK_COLOR_MAROON, + MARK_COLOR_MINT, + MARK_COLOR_OLIVE, + MARK_COLOR_PEACH, + MARK_COLOR_NAVY, + MARK_COLOR_BRIGHT_BLUE +}; + +/** + * Using this flag will enable all the instrumentations of TraCR. Otherwise pure + * void functions. + */ +#ifdef ENABLE_INSTRUMENTATION + +/** + * Debug printing method. Can be enabled with the ENABLE_DEBUG flag included. + */ +#ifdef ENABLE_DEBUG +#define debug_print(fmt, ...) printf("[DEBUG] " fmt "\n", ##__VA_ARGS__) +#else +#define debug_print(fmt, ...) +#endif + +/** + * Keep track of the main thread as this one has to be free'd when instr_end is + * called + */ +extern pid_t main_TID; + +/** + * A flag to check if something else has initialized ovni (like nOS-V). If so, + * TraCR with not init/end proc. + */ +extern bool external_init; + +/** + * An env variable disable the traces + */ +extern bool disable_tracr; + +/** + * automatic label ID assigning, i.e. doesn't matter which color the label is + * assigned to + */ +extern std::atomic auto_label; + +/** + * A function to check if the env flag is active or not + */ +extern bool get_env_flag(); + +/** + * This boolean is needed if something other than TraCR has to be called. + */ +#define INSTRUMENTATION_ACTIVE true + +/** + * ovni proc methods + */ +#define INSTRUMENTATION_START(external_init_) \ + disable_tracr = get_env_flag(); \ + if (!disable_tracr) { \ + main_TID = get_tid(); \ + external_init = external_init_; \ + debug_print("instr_start (external_init: %d) (TID: %d)", external_init, \ + get_tid()); \ + if (!external_init) { \ + instrumentation_init_proc(sched_getcpu(), get_nprocs()); \ + } \ + } + +#define INSTRUMENTATION_END() \ + if (!disable_tracr) { \ + debug_print("instr_end (external_init: %d) (TID: %d)", external_init, \ + get_tid()); \ + if (!external_init) { \ + instrumentation_end(); \ + } \ + } + +/** + * ovni thread methods + */ +#define INSTRUMENTATION_THREAD_INIT() \ + if (!disable_tracr) { \ + debug_print("instr_thread_init with isready: %d (TID: %d)", \ + ovni_thread_isready(), get_tid()); \ + if (!ovni_thread_isready()) { \ + instrumentation_init_thread(); \ + } \ + } + +#define INSTRUMENTATION_THREAD_END() \ + if (!disable_tracr) { \ + debug_print( \ + "external_init %d, instr_thread_end with isready: %d (TID: %d)", \ + external_init, ovni_thread_isready(), get_tid()); \ + if (!external_init && ovni_thread_isready() && !(main_TID == get_tid())) { \ + instrumentation_thread_end(); \ + ovni_thread_free(); \ + } \ + } + +/** + * ovni thread marker methods + */ +extern ThreadMarkerMap thread_marker_map; + +#define INSTRUMENTATION_MARK_INIT(flag) \ + if (!disable_tracr) { \ + debug_print("instr_marker_init (TID: %d)", get_tid()); \ + ovni_mark_type(0, flag, "TraCR Thread Markers"); \ + } + +#define INSTRUMENTATION_MARK_ADD(labelid, label) \ + (!disable_tracr ? thread_marker_map.add(labelid, label) : 0) + +#define INSTRUMENTATION_MARK_LAZY_ADD(label) \ + (!disable_tracr ? thread_marker_map.add(auto_label++, label) : 0) + +#define INSTRUMENTATION_MARK_SET(idx) \ + if (!disable_tracr) { \ + debug_print("instr_marker_set idx: %ld (TID: %d)", idx, get_tid()); \ + thread_marker_map.set(idx); \ + } + +#define INSTRUMENTATION_MARK_PUSH(idx) \ + if (!disable_tracr) { \ + debug_print("instr_marker_push (TID: %d)", get_tid()); \ + thread_marker_map.push(idx); \ + } + +#define INSTRUMENTATION_MARK_POP(idx) \ + if (!disable_tracr) { \ + debug_print("instr_marker_pop (TID: %d)", get_tid()); \ + thread_marker_map.pop(idx); \ + } + +// Resets the color to none +#define INSTRUMENTATION_MARK_RESET() \ + if (!disable_tracr) { \ + debug_print("instr_marker_reset (TID: %d)", get_tid()); \ + ovni_mark_set(0, INT64_MAX); \ + } + +/** + * ovni marker methods (vanilla) + */ +#define INSTRUMENTATION_VMARK_TYPE(flag, title) \ + if (!disable_tracr) { \ + ovni_mark_type(0, flag, title); \ + } + +#define INSTRUMENTATION_VMARK_LABEL(value, label) \ + if (!disable_tracr) { \ + ovni_mark_label(0, value, label); \ + } + +#define INSTRUMENTATION_VMARK_SET(value) \ + if (!disable_tracr) { \ + debug_print("instr_marker_set (TID: %d)", get_tid()); \ + ovni_mark_set(0, value); \ + } + +#define INSTRUMENTATION_VMARK_PUSH(value) \ + if (!disable_tracr) { \ + debug_print("instr_marker_push (TID: %d)", get_tid()); \ + ovni_mark_push(0, value); \ + } + +#define INSTRUMENTATION_VMARK_POP(value) \ + if (!disable_tracr) { \ + debug_print("instr_marker_pop (TID: %d)", get_tid()); \ + ovni_mark_pop(0, value); \ + } + +#else /* No instrumentations (void) */ + +#define INSTRUMENTATION_ACTIVE false + +/** + * ovni proc methods + */ +#define INSTRUMENTATION_START(external_init_) (void)(external_init_) + +#define INSTRUMENTATION_END() + +/** + * ovni thread methods + */ +#define INSTRUMENTATION_THREAD_INIT() + +#define INSTRUMENTATION_THREAD_END() + +/** + * ovni thread marker methods + */ +#define INSTRUMENTATION_MARK_INIT(flag) (void)(flag) + +#define INSTRUMENTATION_MARK_ADD(labelid, label) \ + -1; \ + (void)(labelid); \ + (void)(label) + +#define INSTRUMENTATION_MARK_LAZY_ADD(label) \ + -1; \ + (void)(label) + +#define INSTRUMENTATION_MARK_SET(idx) (void)(idx) + +#define INSTRUMENTATION_MARK_PUSH(idx) (void)(idx) + +#define INSTRUMENTATION_MARK_POP(idx) (void)(idx) + +#define INSTRUMENTATION_MARK_RESET() + +/** + * ovni marker methods (vanilla) + */ +#define INSTRUMENTATION_VMARK_TYPE(flag, title) \ + (void)(flag); \ + (void)(title) + +#define INSTRUMENTATION_VMARK_LABEL(value, label) \ + (void)(value); \ + (void)(label) + +#define INSTRUMENTATION_VMARK_SET(value) (void)(value) + +#define INSTRUMENTATION_VMARK_PUSH(value) (void)(value) + +#define INSTRUMENTATION_VMARK_POP(value) (void)(value) + +#endif /* ENABLE_INSTRUMENTATION */ diff --git a/meson.build b/meson.build index 391acf3..5737723 100644 --- a/meson.build +++ b/meson.build @@ -22,20 +22,20 @@ InstrumentationBuildCppArgs = [ ] InstrumentationBuildIncludes = include_directories([ - 'src' + 'include' ]) ####### Build ovni -subdir('src') +subdir('include/tracr') ####### Collect the dependencies InstrumentationBuildDep = declare_dependency( compile_args: InstrumentationBuildCppArgs, include_directories: InstrumentationBuildIncludes, - sources: ['src/tracr.cpp'], + sources: ['include/tracr/tracr.cpp'], dependencies: ovniDep ) diff --git a/src/tracr.hpp b/src/tracr.hpp deleted file mode 100644 index 55ae803..0000000 --- a/src/tracr.hpp +++ /dev/null @@ -1,230 +0,0 @@ -/* - * Copyright 2025 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @file tracr.hpp - * @brief instrumentation calls inside #define functionalities - * @author Noah Baumann - * @date 17/12/2024 - */ - -#pragma once - -#include "base_instr.hpp" -#include -#include -#include // get_nprocs() - -/** - * Marker colors values of the default Paraver color palette - * NOTE: Black would be 0 but in ovni it is illegal! - */ -enum mark_color : int64_t { - MARK_COLOR_BLUE = 1, - MARK_COLOR_LIGHT_GRAY, - MARK_COLOR_RED, - MARK_COLOR_GREEN, - MARK_COLOR_YELLOW, - MARK_COLOR_ORANGE, - MARK_COLOR_PURPLE, - MARK_COLOR_CYAN, - MARK_COLOR_MAGENTA, - MARK_COLOR_LIGHT_GREEN, - MARK_COLOR_PINK, - MARK_COLOR_TEAL, - MARK_COLOR_GRAY, - MARK_COLOR_LAVENDER, - MARK_COLOR_BROWN, - MARK_COLOR_LIGHT_YELLOW, - MARK_COLOR_MAROON, - MARK_COLOR_MINT, - MARK_COLOR_OLIVE, - MARK_COLOR_PEACH, - MARK_COLOR_NAVY, - MARK_COLOR_BRIGHT_BLUE -}; - -/** - * Using this flag will enable all the instrumentations of TraCR. Otherwise pure - * void functions. - */ -#ifdef ENABLE_INSTRUMENTATION - -/** - * Debug printing method. Can be enabled with the ENABLE_DEBUG flag included. - */ -#ifdef ENABLE_DEBUG -#define debug_print(fmt, ...) printf("[DEBUG] " fmt "\n", ##__VA_ARGS__) -#else -#define debug_print(fmt, ...) -#endif - -/** - * Keep track of the main thread as this one has to be free'd when instr_end is - * called - */ -extern pid_t main_TID; - -/** - * A flag to check if something else has initialized ovni (like nOS-V). If so, - * TraCR with not init/end proc. - */ -extern bool external_init; - -/** - * This boolean is needed if something other than TraCR has to be called. - */ -#define INSTRUMENTATION_ACTIVE true - -/** - * ovni proc methods - */ -#define INSTRUMENTATION_START(external_init_) \ - main_TID = get_tid(); \ - external_init = external_init_; \ - debug_print("instr_start (external_init: %d) (TID: %d)", external_init, \ - get_tid()); \ - if (!external_init) { \ - instrumentation_init_proc(sched_getcpu(), get_nprocs()); \ - } - -#define INSTRUMENTATION_END() \ - debug_print("instr_end (external_init: %d) (TID: %d)", external_init, \ - get_tid()); \ - if (!external_init) { \ - instrumentation_end(); \ - } - -/** - * ovni thread methods - */ -#define INSTRUMENTATION_THREAD_INIT() \ - debug_print("instr_thread_init with isready: %d (TID: %d)", \ - ovni_thread_isready(), get_tid()); \ - if (!ovni_thread_isready()) { \ - instrumentation_init_thread(); \ - } - -#define INSTRUMENTATION_THREAD_END() \ - debug_print("external_init %d, instr_thread_end with isready: %d (TID: %d)", \ - external_init, ovni_thread_isready(), get_tid()); \ - if (!external_init && ovni_thread_isready() && !(main_TID == get_tid())) { \ - instrumentation_thread_end(); \ - ovni_thread_free(); \ - } - -/** - * ovni thread marker methods - */ -extern ThreadMarkerMap thread_marker_map; - -#define INSTRUMENTATION_THREAD_MARK_INIT(flag) \ - debug_print("instr_marker_init (TID: %d)", get_tid()); \ - ovni_mark_type(0, flag, "TraCR Thread Markers") - -#define INSTRUMENTATION_THREAD_MARK_ADD(labelid, label) \ - thread_marker_map.add(labelid, label); \ - debug_print("instr_marker_add (TID: %d)", get_tid()) - -#define INSTRUMENTATION_THREAD_MARK_SET(idx) \ - debug_print("instr_marker_set idx: %ld (TID: %d)", idx, get_tid()); \ - thread_marker_map.set(idx); - -#define INSTRUMENTATION_THREAD_MARK_PUSH(idx) \ - debug_print("instr_marker_push (TID: %d)", get_tid()); \ - thread_marker_map.push(idx); - -#define INSTRUMENTATION_THREAD_MARK_POP(idx) \ - debug_print("instr_marker_pop (TID: %d)", get_tid()); \ - thread_marker_map.pop(idx); - -/** - * ovni marker methods (vanilla) - */ -#define INSTRUMENTATION_VMARKER_TYPE(flag, title) ovni_mark_type(0, flag, title) - -#define INSTRUMENTATION_VMARKER_LABEL(value, label) \ - ovni_mark_label(0, value, label) - -#define INSTRUMENTATION_VMARKER_SET(value) \ - debug_print("instr_marker_set (TID: %d)", get_tid()); \ - ovni_mark_set(0, value) - -#define INSTRUMENTATION_VMARKER_RESET() \ - debug_print("instr_marker_reset (TID: %d)", get_tid()); \ - ovni_mark_set(0, INT64_MAX) - -#define INSTRUMENTATION_VMARKER_PUSH(value) \ - debug_print("instr_marker_push (TID: %d)", get_tid()); \ - ovni_mark_push(0, value) - -#define INSTRUMENTATION_VMARKER_POP(value) \ - debug_print("instr_marker_pop (TID: %d)", get_tid()); \ - ovni_mark_pop(0, value) - -#else /* No instrumentations (void) */ - -#define INSTRUMENTATION_ACTIVE false - -/** - * ovni proc methods - */ -#define INSTRUMENTATION_START(external_init_) (void)(external_init_) - -#define INSTRUMENTATION_END() - -/** - * ovni thread methods - */ -#define INSTRUMENTATION_THREAD_INIT() - -#define INSTRUMENTATION_THREAD_END() - -/** - * ovni thread marker methods - */ -#define INSTRUMENTATION_THREAD_MARK_INIT(flag) (void)(flag) - -#define INSTRUMENTATION_THREAD_MARK_ADD(value, label) \ - -1; \ - (void)(value); \ - (void)(label) - -#define INSTRUMENTATION_THREAD_MARK_SET(idx) (void)(idx) - -#define INSTRUMENTATION_THREAD_MARK_PUSH(idx) (void)(idx) - -#define INSTRUMENTATION_THREAD_MARK_POP(idx) (void)(idx) - -/** - * ovni marker methods (vanilla) (only used for performance comparisons) - */ -#define INSTRUMENTATION_VMARKER_TYPE(flag, title) \ - (void)(flag); \ - (void)(title) - -#define INSTRUMENTATION_VMARKER_LABEL(value, label) \ - (void)(value); \ - (void)(label) - -#define INSTRUMENTATION_VMARKER_SET(value) (void)(value) - -#define INSTRUMENTATION_VMARKER_RESET() - -#define INSTRUMENTATION_VMARKER_PUSH(value) (void)(value) - -#define INSTRUMENTATION_VMARKER_POP(value) (void)(value) -#endif diff --git a/tests/basic_check.cpp b/tests/basic_check.cpp index 17b9f5c..a04935b 100644 --- a/tests/basic_check.cpp +++ b/tests/basic_check.cpp @@ -15,7 +15,7 @@ */ #include -#include +#include /* * Basic test to see if TraCR (and ovni) is installed correctly