Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 5 additions & 5 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
2 changes: 1 addition & 1 deletion examples/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
18 changes: 9 additions & 9 deletions examples/pytracr/pthread_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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
Expand All @@ -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.")

Expand Down
34 changes: 17 additions & 17 deletions examples/pytracr/thread_markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
38 changes: 19 additions & 19 deletions examples/pytracr/vmarkers_push_pop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions examples/pytracr/vmarkers_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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
Expand Down
23 changes: 11 additions & 12 deletions examples/pthread_example.cpp → examples/tracr/pthread_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <unistd.h> // For getpid()
#include <vector>

#include <tracr.hpp>
#include <tracr/tracr.hpp>

#define NRANKS 4 // number of threads
#define NTASKS 3 // number of tasks per thread
Expand All @@ -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
Expand All @@ -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();
Expand All @@ -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<pthread_t> threads(NRANKS); // Vector to hold pthreads
std::vector<int> threadIds(NRANKS); // Vector to hold thread IDs
Expand All @@ -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;

Expand Down
Loading