Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

Parsing Output of strace Command

Does anyone have experience or working code that parses the output of strace command?

Copilot can up with this but is does not work ...

 

let
// Function to parse a single line of strace output
ParseStraceLine = (line as text) as record =>
let
// Find the position of the first parenthesis
openParen = List.First(Text.PositionOf(line, "(", Occurrence.First)),
// Find the position of the last parenthesis
closeParen = List.First(Text.PositionOf(line, ")", Occurrence.First, openParen)),
// Extract the syscall name
syscall = if openParen > 0 then Text.Start(line, openParen) else null,
// Extract the arguments
args = if openParen > 0 and closeParen > openParen then Text.Middle(line, openParen + 1, closeParen - openParen - 1) else null,
// Extract the result
resultStart = List.First(Text.PositionOf(line, "=", Occurrence.First, closeParen)) + 2,
result = if resultStart > 1 then Text.Middle(line, resultStart) else null,
// Create a record with the parsed data
parsedRecord = if syscall <> null and args <> null and result <> null then
[Syscall = syscall, Args = args, Result = result]
else
null
in
parsedRecord,

// Load the strace output from a text file
Source = Text.FromBinary(File.Contents("strace_output.txt")),
Lines = Text.Split(Source, "#(lf)"),

// Parse each line and filter out null values
ParsedLines = List.Transform(Lines, each ParseStraceLine(_)),
FilteredLines = List.Select(ParsedLines, each _ <> null),

// Convert the list of records to a table
Table = Table.FromRecords(FilteredLines)
in
Table

 

1 Reply