@@ -17,17 +17,17 @@ let appAssembly = Assembly.GetEntryAssembly()
1717let appName = appAssembly.GetName()
1818
1919let showCopyright () =
20- printfn " "
21- printfn " %s v%s - collects process or system traces" appName.Name ( appName.Version.ToString())
20+ eprintfn " "
21+ eprintfn " %s v%s - collects process or system traces" appName.Name ( appName.Version.ToString())
2222 let customAttrs = appAssembly.GetCustomAttributes( typeof< AssemblyCompanyAttribute>, true );
2323 assert ( customAttrs.Length > 0 )
24- printfn " Copyright (C) 2022 %s " ( customAttrs.[ 0 ] :?> AssemblyCompanyAttribute) .Company
25- printfn " Visit https://wtrace.net to learn more"
26- printfn " "
24+ eprintfn " Copyright (C) 2022 %s " ( customAttrs.[ 0 ] :?> AssemblyCompanyAttribute) .Company
25+ eprintfn " Visit https://wtrace.net to learn more"
26+ eprintfn " "
2727
2828let showHelp () =
29- printfn " Usage: %s [OPTIONS] [pid|imagename args]" appName.Name
30- printfn @"
29+ eprintfn " Usage: %s [OPTIONS] [pid|imagename args]" appName.Name
30+ eprintfn @"
3131Options:
3232 -f, --filter=FILTER Displays only events which satisfy a given FILTER.
3333 (Does not impact the summary)
@@ -39,6 +39,8 @@ Options:
3939 - shown in the summary.
4040 --symbols=SYMPATH Resolve stacks and RPC method names using the provided symbols path.
4141 --nosummary Prints only ETW events - no summary at the end.
42+ --output Format of the events in the output.
43+ Available options: 'freetext' (default) or 'json'
4244 -v, --verbose Shows wtrace diagnostics logs.
4345 -h, --help Shows this message and exits.
4446
@@ -96,9 +98,9 @@ let parseHandlers args =
9698 |> Set.add " process" // process handler is always on
9799 let handlers = handlerNames |> Set.toArray |> Array.map resolveHandler
98100
99- printfn " HANDLERS"
100- printfn " %s " ( handlerNames |> String.concat " , " )
101- printfn " "
101+ eprintfn " HANDLERS"
102+ eprintfn " %s " ( handlerNames |> String.concat " , " )
103+ eprintfn " "
102104
103105 Ok handlers
104106 with
@@ -120,10 +122,10 @@ let parseFilters args =
120122 try
121123 let filters =
122124 filters |> List.map EventFilter.parseFilter
123- printfn " FILTERS"
124- if filters |> List.isEmpty then printfn " [none]"
125+ eprintfn " FILTERS"
126+ if filters |> List.isEmpty then eprintfn " [none]"
125127 else EventFilter.printFilters filters
126- printfn " "
128+ eprintfn " "
127129 Ok ( EventFilter.buildFilterFunction filters)
128130 with
129131 | EventFilter.ParseError msg -> Error msg
@@ -142,11 +144,11 @@ let checkElevated () =
142144let finishProcessingAndShowSummary tstate counters ( ct : CancellationToken ) =
143145
144146 if RpcResolver.isRunning () then
145- printf " \r Resolving RPC endpoints (press Ctrl + C to stop) "
147+ eprintf " \r Resolving RPC endpoints (press Ctrl + C to stop) "
146148 while not ct.IsCancellationRequested && RpcResolver.isRunning () do
147- printf " ."
149+ eprintf " ."
148150 Async.Sleep( 500 ) |> Async.RunSynchronously
149- printfn " "
151+ eprintfn " "
150152
151153 TraceSummary.dump tstate counters
152154
@@ -160,7 +162,12 @@ let start (supportFilesDirectory : string) (args : Map<string, list<string>>) =
160162
161163 if [| " v" ; " verbose" |] |> isFlagEnabled then
162164 Trace.AutoFlush <- true
163- Logger.initialize( SourceLevels.Verbose, [ new TextWriterTraceListener( Console.Out) ])
165+ Logger.initialize( SourceLevels.Verbose, [ new TextWriterTraceListener( Console.Error) ])
166+
167+ let outputFormat =
168+ match args |> Map.tryFind " output" with
169+ | Some [ " json" ] -> TraceControl.OutputFormat.Json
170+ | _ -> TraceControl.OutputFormat.FreeText
164171
165172 let! filterEvents = parseFilters args
166173 let! handlers = parseHandlers args
@@ -174,17 +181,17 @@ let start (supportFilesDirectory : string) (args : Map<string, list<string>>) =
174181 | None ->
175182 match Environment.GetEnvironmentVariable( " _NT_SYMBOL_PATH" ) with
176183 | v when v <> null ->
177- printfn " Debug symbols path: %s " v
178- printfn " "
184+ eprintfn " Debug symbols path: %s " v
185+ eprintfn " "
179186
180187 UseDbgHelp( dbgHelpPath, v)
181188 | _ -> DebugSymbolSettings.Ignore
182189 | Some paths ->
183190 Debug.Assert( paths.Length > 0 )
184191 let symbolsPath = List.last paths
185192
186- printfn " Debug symbols path: %s " symbolsPath
187- printfn " "
193+ eprintfn " Debug symbols path: %s " symbolsPath
194+ eprintfn " "
188195
189196 UseDbgHelp( dbgHelpPath, symbolsPath)
190197
@@ -199,7 +206,7 @@ let start (supportFilesDirectory : string) (args : Map<string, list<string>>) =
199206 Console.CancelKeyPress.Add(
200207 fun ev ->
201208 if not tracingCts.IsCancellationRequested then
202- printfn " Closing the trace session. Please wait..."
209+ eprintfn " Closing the trace session. Please wait..."
203210 ev.Cancel <- true
204211 tracingCts.Cancel()
205212 elif not processingCts.IsCancellationRequested then
@@ -213,27 +220,29 @@ let start (supportFilesDirectory : string) (args : Map<string, list<string>>) =
213220 match args |> Map.tryFind " " with
214221 | None when isSystemTrace args ->
215222 if not showSummary then
216- printfn " WARNING: --nosummary does not take any effect in the system-only trace."
223+ eprintfn " WARNING: --nosummary does not take any effect in the system-only trace."
217224 TraceControl.traceSystemOnly cancellationTokens
218225
219226 | None ->
220- TraceControl.traceEverything cancellationTokens handlers filterEvents showSummary debugSymbols
227+ TraceControl.traceEverything cancellationTokens handlers filterEvents showSummary debugSymbols outputFormat
221228
222229 | Some args ->
223230 let newConsole = ([| " newconsole" |] |> isFlagEnabled)
224231 let includeChildren = [| " c" ; " children" |] |> isFlagEnabled
225232
226233 match args with
227234 | [ pid ] when isInteger pid ->
228- TraceControl.traceRunningProcess cancellationTokens handlers filterEvents showSummary debugSymbols includeChildren ( Int32.Parse( pid))
235+ TraceControl.traceRunningProcess cancellationTokens handlers filterEvents showSummary
236+ debugSymbols outputFormat includeChildren ( Int32.Parse( pid))
229237 | args ->
230- TraceControl.traceNewProcess cancellationTokens handlers filterEvents showSummary debugSymbols newConsole includeChildren args
238+ TraceControl.traceNewProcess cancellationTokens handlers filterEvents showSummary
239+ debugSymbols outputFormat newConsole includeChildren args
231240
232241 if not ( TraceControl.sessionWaitEvent.WaitOne( TimeSpan.FromSeconds( 3.0 ))) then
233- printfn " WARNING: the session did not finish in the allotted time. Stop it manually: logman stop wtrace-rt -ets"
242+ eprintfn " WARNING: the session did not finish in the allotted time. Stop it manually: logman stop wtrace-rt -ets"
234243
235244 if TraceControl.lostEventsCount > 0 then
236- printfn " WARNING: %d events were lost in the session. Check wtrace help at https://wtrace.net to learn more." TraceControl.lostEventsCount
245+ eprintfn " WARNING: %d events were lost in the session. Check wtrace help at https://wtrace.net to learn more." TraceControl.lostEventsCount
237246
238247 finishProcessingAndShowSummary traceState counters cancellationTokens.ProcessingCancellationToken
239248}
@@ -250,5 +259,5 @@ let main (supportFilesDirectory : string) (argv : array<string>) =
250259 else
251260 match start supportFilesDirectory args with
252261 | Ok _ -> 0
253- | Error msg -> printfn " ERROR: %s " msg; 1
262+ | Error msg -> eprintfn " ERROR: %s " msg; 1
254263
0 commit comments