Skip to content

Commit 4e1139f

Browse files
Copilotnibanks
andcommitted
Support babeltrace2 with fallback to babeltrace in scripts
Co-authored-by: nibanks <[email protected]>
1 parent 08bdac2 commit 4e1139f

File tree

4 files changed

+52
-7
lines changed

4 files changed

+52
-7
lines changed

docs/Diagnostics.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ cmake -D QUIC_ENABLE_LOGGING=ON -D QUIC_LOGGING_TYPE=stdout ...
2424
```
2525

2626
#### LTTng
27-
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:
27+
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:
2828

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

222222
```
223+
# Using babeltrace2 (preferred)
224+
babeltrace2 --names all ./msquic_lttng/* > quic.babel.txt
225+
# OR using babeltrace (fallback)
223226
babeltrace --names all ./msquic_lttng/* > quic.babel.txt
227+
224228
~/.dotnet/tools/clog2text_lttng -i quic.babel.txt -s clog.sidecar -o quic.log --showTimestamp --showCpuInfo
225229
```
226230

scripts/log.ps1

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,17 @@ $Clog2Text_lttng = "$HOME/.dotnet/tools/clog2text_lttng"
134134
$TempDir = $null
135135
$TempLTTngDir = $null
136136
$TempPerfDir = $null
137+
138+
# Helper function to get the appropriate babeltrace command
139+
function Get-BabeltraceCommand {
140+
if (Get-Command babeltrace2 -ErrorAction SilentlyContinue) {
141+
return "babeltrace2"
142+
} elseif (Get-Command babeltrace -ErrorAction SilentlyContinue) {
143+
return "babeltrace"
144+
} else {
145+
throw "Neither babeltrace2 nor babeltrace is available"
146+
}
147+
}
137148
if ($IsLinux) {
138149
$InstanceName = $InstanceName.Replace(".", "_")
139150
$TempDir = Join-Path $HOME "QUICLogs"
@@ -246,10 +257,19 @@ function Log-Start {
246257

247258
if ($Stream) {
248259
lttng list | Write-Debug
249-
babeltrace -i lttng-live net://localhost | Write-Debug
260+
$BabeltraceCmd = Get-BabeltraceCommand
261+
if ($BabeltraceCmd -eq "babeltrace2") {
262+
& $BabeltraceCmd convert -i lttng-live net://localhost | Write-Debug
263+
} else {
264+
& $BabeltraceCmd -i lttng-live net://localhost | Write-Debug
265+
}
250266
$myHostName = hostname
251267
Write-Host "Now decoding LTTng events in realtime on host=$myHostName...`n"
252-
$args = "babeltrace --names all -i lttng-live net://localhost/host/$myHostName/msquiclive | $Clog2Text_lttng -s $SideCar --showTimestamp --showCpuInfo"
268+
if ($BabeltraceCmd -eq "babeltrace2") {
269+
$args = "$BabeltraceCmd convert --names all -i lttng-live net://localhost/host/$myHostName/msquiclive | $Clog2Text_lttng -s $SideCar --showTimestamp --showCpuInfo"
270+
} else {
271+
$args = "$BabeltraceCmd --names all -i lttng-live net://localhost/host/$myHostName/msquiclive | $Clog2Text_lttng -s $SideCar --showTimestamp --showCpuInfo"
272+
}
253273
Write-Host $args
254274
Invoke-Expression $args
255275
}
@@ -315,7 +335,12 @@ function Log-Stop {
315335
if (!$RawLogOnly) {
316336
try {
317337
Write-Debug "Decoding LTTng into BabelTrace format ($BableTraceFile)"
318-
babeltrace --names all $TempLTTngDir/* > $BableTraceFile
338+
$BabeltraceCmd = Get-BabeltraceCommand
339+
if ($BabeltraceCmd -eq "babeltrace2") {
340+
& $BabeltraceCmd convert --names all $TempLTTngDir/* > $BableTraceFile
341+
} else {
342+
& $BabeltraceCmd --names all $TempLTTngDir/* > $BableTraceFile
343+
}
319344
Write-Host "Decoding into human-readable text: $ClogOutputDecodeFile"
320345
$Command = "$Clog2Text_lttng -i $BableTraceFile -s $SideCar -o $ClogOutputDecodeFile --showTimestamp --showCpuInfo"
321346
Write-Host $Command
@@ -358,7 +383,12 @@ function Log-Decode {
358383

359384
try {
360385
Write-Host "Decoding LTTng into BabelTrace format ($BableTraceFile)"
361-
babeltrace --names all $DecompressedLogs/* > $BableTraceFile
386+
$BabeltraceCmd = Get-BabeltraceCommand
387+
if ($BabeltraceCmd -eq "babeltrace2") {
388+
& $BabeltraceCmd convert --names all $DecompressedLogs/* > $BableTraceFile
389+
} else {
390+
& $BabeltraceCmd --names all $DecompressedLogs/* > $BableTraceFile
391+
}
362392
Write-Host "Decoding Babeltrace into human text using CLOG"
363393
$Command = "$Clog2Text_lttng -i $BableTraceFile -s $SideCar -o $ClogOutputDecodeFile"
364394
Write-Host $Command

scripts/log_wrapper.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ fi
1414
if [ $sessionCreated -eq 0 ]; then
1515
lttng destroy msquic
1616

17-
babeltrace --names all $dirname/data > $dirname/quic.babel.txt
17+
# Try babeltrace2 first, then fallback to babeltrace
18+
if command -v babeltrace2 > /dev/null 2>&1; then
19+
babeltrace2 --names all $dirname/data > $dirname/quic.babel.txt
20+
elif command -v babeltrace > /dev/null 2>&1; then
21+
babeltrace --names all $dirname/data > $dirname/quic.babel.txt
22+
else
23+
echo "Error: Neither babeltrace2 nor babeltrace is available"
24+
exit 1
25+
fi
1826
./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
1927
fi

scripts/prepare-machine.ps1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,10 @@ if ($IsLinux) {
537537
sudo apt-get install -y cmake
538538
sudo apt-get install -y build-essential
539539
sudo apt-get install -y liblttng-ust-dev
540-
sudo apt-get install -y babeltrace
540+
# Try to install babeltrace2 first, then fallback to babeltrace
541+
if (!sudo apt-get install -y babeltrace2 2>/dev/null) {
542+
sudo apt-get install -y babeltrace
543+
}
541544
sudo apt-get install -y libssl-dev
542545
sudo apt-get install -y libnuma-dev
543546
if ($InstallArm64Toolchain) {

0 commit comments

Comments
 (0)