Skip to content

Support babeltrace2 with fallback to babeltrace #5141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
6 changes: 5 additions & 1 deletion docs/Diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ cmake -D QUIC_ENABLE_LOGGING=ON -D QUIC_LOGGING_TYPE=stdout ...
```

#### LTTng
On Linux, MsQuic leverages [LTTng](https://lttng.org/features/) for its logging. Some dependencies, such as babeltrace, lttng, and clog2text_lttng are required. The simplest way to install all dependencies is by running `./scripts/prepare-machine.ps1 -ForTest`, but if you only want to collect the traces on the machine, the **minimal dependencies** are:
On Linux, MsQuic leverages [LTTng](https://lttng.org/features/) for its logging. Some dependencies, such as babeltrace2 (or babeltrace), lttng, and clog2text_lttng are required. The simplest way to install all dependencies is by running `./scripts/prepare-machine.ps1 -ForTest`, but if you only want to collect the traces on the machine, the **minimal dependencies** are:

```
sudo apt-add-repository ppa:lttng/stable-2.13
Expand Down Expand Up @@ -220,7 +220,11 @@ dotnet build submodules/clog/src/clog2text/clog2text_lttng/ -c Release
To convert the trace, you can use the following commands:

```
# Using babeltrace2 (preferred)
babeltrace2 --names all ./msquic_lttng/* > quic.babel.txt
# OR using babeltrace (fallback)
babeltrace --names all ./msquic_lttng/* > quic.babel.txt

~/.dotnet/tools/clog2text_lttng -i quic.babel.txt -s clog.sidecar -o quic.log --showTimestamp --showCpuInfo
```

Expand Down
38 changes: 34 additions & 4 deletions scripts/log.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,17 @@ $Clog2Text_lttng = "$HOME/.dotnet/tools/clog2text_lttng"
$TempDir = $null
$TempLTTngDir = $null
$TempPerfDir = $null

# Helper function to get the appropriate babeltrace command
function Get-BabeltraceCommand {
if (Get-Command babeltrace2 -ErrorAction SilentlyContinue) {
return "babeltrace2"
} elseif (Get-Command babeltrace -ErrorAction SilentlyContinue) {
return "babeltrace"
} else {
throw "Neither babeltrace2 nor babeltrace is available"
}
}
if ($IsLinux) {
$InstanceName = $InstanceName.Replace(".", "_")
$TempDir = Join-Path $HOME "QUICLogs"
Expand Down Expand Up @@ -246,10 +257,19 @@ function Log-Start {

if ($Stream) {
lttng list | Write-Debug
babeltrace -i lttng-live net://localhost | Write-Debug
$BabeltraceCmd = Get-BabeltraceCommand
if ($BabeltraceCmd -eq "babeltrace2") {
& $BabeltraceCmd convert -i lttng-live net://localhost | Write-Debug
} else {
& $BabeltraceCmd -i lttng-live net://localhost | Write-Debug
}
$myHostName = hostname
Write-Host "Now decoding LTTng events in realtime on host=$myHostName...`n"
$args = "babeltrace --names all -i lttng-live net://localhost/host/$myHostName/msquiclive | $Clog2Text_lttng -s $SideCar --showTimestamp --showCpuInfo"
if ($BabeltraceCmd -eq "babeltrace2") {
$args = "$BabeltraceCmd convert --names all -i lttng-live net://localhost/host/$myHostName/msquiclive | $Clog2Text_lttng -s $SideCar --showTimestamp --showCpuInfo"
} else {
$args = "$BabeltraceCmd --names all -i lttng-live net://localhost/host/$myHostName/msquiclive | $Clog2Text_lttng -s $SideCar --showTimestamp --showCpuInfo"
}
Write-Host $args
Invoke-Expression $args
}
Expand Down Expand Up @@ -315,7 +335,12 @@ function Log-Stop {
if (!$RawLogOnly) {
try {
Write-Debug "Decoding LTTng into BabelTrace format ($BableTraceFile)"
babeltrace --names all $TempLTTngDir/* > $BableTraceFile
$BabeltraceCmd = Get-BabeltraceCommand
if ($BabeltraceCmd -eq "babeltrace2") {
& $BabeltraceCmd convert --names all $TempLTTngDir/* > $BableTraceFile
} else {
& $BabeltraceCmd --names all $TempLTTngDir/* > $BableTraceFile
}
Write-Host "Decoding into human-readable text: $ClogOutputDecodeFile"
$Command = "$Clog2Text_lttng -i $BableTraceFile -s $SideCar -o $ClogOutputDecodeFile --showTimestamp --showCpuInfo"
Write-Host $Command
Expand Down Expand Up @@ -358,7 +383,12 @@ function Log-Decode {

try {
Write-Host "Decoding LTTng into BabelTrace format ($BableTraceFile)"
babeltrace --names all $DecompressedLogs/* > $BableTraceFile
$BabeltraceCmd = Get-BabeltraceCommand
if ($BabeltraceCmd -eq "babeltrace2") {
& $BabeltraceCmd convert --names all $DecompressedLogs/* > $BableTraceFile
} else {
& $BabeltraceCmd --names all $DecompressedLogs/* > $BableTraceFile
}
Write-Host "Decoding Babeltrace into human text using CLOG"
$Command = "$Clog2Text_lttng -i $BableTraceFile -s $SideCar -o $ClogOutputDecodeFile"
Write-Host $Command
Expand Down
10 changes: 9 additions & 1 deletion scripts/log_wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ fi
if [ $sessionCreated -eq 0 ]; then
lttng destroy msquic

babeltrace --names all $dirname/data > $dirname/quic.babel.txt
# Try babeltrace2 first, then fallback to babeltrace
if command -v babeltrace2 > /dev/null 2>&1; then
babeltrace2 --names all $dirname/data > $dirname/quic.babel.txt
elif command -v babeltrace > /dev/null 2>&1; then
babeltrace --names all $dirname/data > $dirname/quic.babel.txt
else
echo "Error: Neither babeltrace2 nor babeltrace is available"
exit 1
fi
./submodules/clog/src/clog2text/clog2text_lttng/bin/Release/net6.0/publish/clog2text_lttng -i $dirname/quic.babel.txt -s ./src/manifest/clog.sidecar -o $dirname/quic.log --showTimestamp --showCpuInfo
fi
7 changes: 6 additions & 1 deletion scripts/prepare-machine.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,12 @@ if ($IsLinux) {
sudo apt-get install -y cmake
sudo apt-get install -y build-essential
sudo apt-get install -y liblttng-ust-dev
sudo apt-get install -y babeltrace
# Try to install babeltrace2 first, then fallback to babeltrace
try {
sudo apt-get install -y babeltrace2 2>&1 | Out-Null
} catch {
sudo apt-get install -y babeltrace
}
sudo apt-get install -y libssl-dev
sudo apt-get install -y libnuma-dev
if ($InstallArm64Toolchain) {
Expand Down
Loading