Skip to content
Open
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
63 changes: 63 additions & 0 deletions bpftrace.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# bpftrace: Per-block device read/write byte totals

```bash
sudo bpftrace -e '
tracepoint:block:block_rq_complete
{
$bytes = args->nr_sector * 512;
/* Cast the string to a char pointer and dereference to get the first byte */
$c = *(uint8 *)args->rwbs;
$dev = args->dev;

@read[$dev] += ($c == 82 ? $bytes : 0); /* 82 is "R" */
@write[$dev] += ($c == 87 ? $bytes : 0); /* 87 is "W" */
@total[$dev] += $bytes;
@seen[$dev] = 1;
}
'
```

# bpftrace: Block IO bandwidth tracking at 10ms intervals

```bash
sudo bpftrace -e '
tracepoint:block:block_rq_complete
{
$bytes = args->nr_sector * 512;
/* Cast the string to a char pointer and dereference to get the first byte */
$c = *(uint8 *)args->rwbs;

/* Accumulate bytes for reads and writes */
@read_bytes += ($c == 82 ? $bytes : 0);
@write_bytes += ($c == 87 ? $bytes : 0);
}

interval:ms:10
{
/* Calculate bandwidth in MB/s using integer arithmetic */
/* bytes in 10ms -> bytes_per_second = bytes * 100 */
/* MB_per_second = (bytes * 100) / 1048576 */
$read_bps = @read_bytes * 100; /* bytes per second */
$write_bps = @write_bytes * 100;
$read_mbps = $read_bps / 1048576; /* MB per second (integer division) */
$write_mbps = $write_bps / 1048576;

/* Time in seconds (elapsed is in nanoseconds) */
$time_sec = elapsed / 1000000000;
$time_ms_remainder = elapsed % 1000000000;
$time_ms = $time_ms_remainder / 1000000;

printf("%d.%03d: Read: %d MB/s, Write: %d MB/s\n",
$time_sec, $time_ms, $read_mbps, $write_mbps);

/* Reset counters for next interval */
@read_bytes = 0;
@write_bytes = 0;
}

END
{
printf("\nTracing complete.\n");
}
'
```
9 changes: 9 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ PROFILE_OUTPUT="perf.data"
FLAMEGRAPH_OUTPUT="flamegraph.svg"
SEPARATE_VALUES=false
ENABLE_MEMORY_PROFILING=false
USE_ASYNC_IO=false
PCM_MEMORY="/users/proteet/pcm/build/bin/pcm-memory"

# Function to show usage
Expand Down Expand Up @@ -88,6 +89,10 @@ while [[ $# -gt 0 ]]; do
FLAMEGRAPH_OUTPUT="$2"
shift 2
;;
--use-async)
USE_ASYNC_IO=true
shift
;;
--help|-h)
show_usage
exit 0
Expand Down Expand Up @@ -151,6 +156,10 @@ if [ "$SEPARATE_VALUES" = true ]; then
CMD_ARGS="$CMD_ARGS --separate-values"
fi

if [ "$USE_ASYNC_IO" = true ]; then
CMD_ARGS="$CMD_ARGS --use-async"
fi

echo "Running sorter with parameters:"
echo " File size: $FILE_SIZE"
echo " Key size: $KEY_SIZE"
Expand Down
6 changes: 6 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,18 @@ endif()

find_package(OpenMP REQUIRED)

find_library(LIBURING_LIBRARIES uring)
find_path(LIBURING_INCLUDE_DIRS liburing.h)

# Add executable
add_executable(sorter main.cpp)

# target_compile_options(sorter PRIVATE -fopenmp)
target_link_libraries(sorter PUBLIC OpenMP::OpenMP_CXX)

target_include_directories(sorter PRIVATE ${LIBURING_INCLUDE_DIRS})
target_link_libraries(sorter PRIVATE ${LIBURING_LIBRARIES})

# Enable additional optimizations
# target_compile_options(sorter PRIVATE -march=native -mtune=native)
target_compile_options(sorter PRIVATE -mavx512f -mavx512vl)
Expand Down
Loading