Home / Alt manpages / dbilogstrip(1p)

  • dbilogstrip(1p)
  • POSIX command
  • linux

Normalise DBI Trace Logs for Reliable Diffs with dbilogstrip

You will turn two noisy DBI trace runs into comparable text by replacing changing memory addresses and process or thread numbers with stable markers. The examples use dbilogstrip from libdbi-perl version 1.643-4ubuntu0.1 on this machine. Allow about fifteen minutes if the two runs are ready; the command itself does not need elevated privileges.

This is a read-and-write pipeline. It reads trace data and writes the redirected output file, but it does not alter the input trace or your Perl program. Work in a scratch directory if the trace contains credentials, query parameters or other sensitive values.

1. Check the installed filter

Confirm that the command is available and see which package supplied it:

$ command -v dbilogstrip
/usr/bin/dbilogstrip
$ dpkg-query -W -f='${Package} ${Version}\n' libdbi-perl
libdbi-perl 1.643-4ubuntu0.1

The program is a Perl filter rather than a command with a separate help or version interface. Passing --help makes it try to open a file with that name, so use its manual page for the interface:

$ man dbilogstrip

Checkpoint: you should have a command path and a package version. If command -v prints nothing, install the package through your normal system administration process before continuing. Do not run package commands as root unless that is how software installation is managed on this host.

2. Normalise an existing trace file

Give the trace filename as the input argument and redirect standard output to a new file:

$ dbilogstrip dbitrace.log > dbitrace_stripped.log

The filter replaces hexadecimal values beginning with 0x, such as memory addresses, with 0xN. It also replaces numeric process and thread markers. The installed script recognises pid, tid and thr, with an optional non-word separator before the number.

$ printf '%s\n' "DBI::st=HASH(0x19162a0) pid#6254 tid:6255 thr#1800400" | dbilogstrip
DBI::st=HASH(0xN) pidN tidN thrN

The input file is not changed. The output file is changed or created by your shell redirection, so do not point it at the original trace unless overwriting that trace is genuinely acceptable.

3. Verify the normalisation

Check that the result exists and contains the markers you expect:

$ test -s dbitrace_stripped.log && grep -nE '0xN|pidN|tidN|thrN' dbitrace_stripped.log | head
1:  -> STORE for DBD::DBM::st (DBI::st=HASH(0xN)~0xN 'f_params' ARRAY(0xN)) thrN

The exact line number and trace content depend on your run. A zero exit status from test -s means the output is non-empty; the grep result shows that at least one unstable value was replaced. If there are no matches, the trace may simply contain no recognised addresses or identifiers. That is not proof that the filter failed.

Checkpoint: compare a known sample before moving on. If the output is empty, inspect the input with wc -l dbitrace.log and check the redirection target. If the input cannot be opened, correct its path or permissions rather than using sudo automatically.

4. Capture two comparable DBI runs

Run the same program twice with different arguments, send standard error into the pipeline, and write one normalised file per run:

$ DBI_TRACE=2 perl yourscript.pl --mode first 2>&1 | dbilogstrip > dbitrace1.log
$ DBI_TRACE=2 perl yourscript.pl --mode second 2>&1 | dbilogstrip > dbitrace2.log
$ diff -u dbitrace1.log dbitrace2.log

DBI_TRACE=2 is an environment setting consumed by DBI. The manpage uses it as the example trace setting; choose the trace level appropriate for your diagnostic task. 2>&1 matters because trace output is commonly written to standard error. Without it, the filter may receive only ordinary program output and the trace will be missing from the files.

Do not treat a clean diff as proof that the programs behaved identically. This filter removes only the changing hexadecimal and process or thread values. SQL text, bind values, errors, ordering and other trace differences remain visible. Review whether those values contain secrets before sharing either file.

5. Handle failures without losing evidence

Shell pipelines can hide an upstream failure because the pipeline status is normally the status of the last command. Capture the output in a new file, then check the file and the program separately when the run matters:

$ set -o pipefail
$ DBI_TRACE=2 perl yourscript.pl --mode first 2>&1 | dbilogstrip > dbitrace1.log
$ printf 'pipeline status: %s\n' "$?"
pipeline status: 0

dbilogstrip normally copies every input line and dies only if it cannot write its destination. A non-zero pipeline status can therefore indicate a failed Perl program or a failed output write. Preserve the output file and inspect the diagnostic before rerunning. If you accidentally redirected to the wrong new file, remove only that disposable file after checking its path; do not delete the original trace.

If a command reports that an input file cannot be opened, use ls -l and file to inspect the named path. If the destination is not writable, choose a directory you own. Elevated privileges are not part of the normal workflow and can create root-owned output that is harder to clean up.

Done means

  • dbilogstrip resolves to the expected installed command.
  • Each output file is new or deliberately disposable, while the original traces remain intact.
  • Changing addresses and recognised pid, tid or thr numbers appear as 0xN and the corresponding *N markers.
  • diff -u shows only meaningful differences that survived normalisation.
  • You have checked the traces for credentials and other sensitive values before sharing them.