Skip to content

Commit 2ce1825

Browse files
authored
VS: log activities to output pane in debug (#15028)
* dump activities to output pane
1 parent 1515f5e commit 2ce1825

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

vsintegration/src/FSharp.Editor/Common/Logging.fs

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,19 @@ type Logger [<ImportingConstructor>] ([<Import(typeof<SVsServiceProvider>)>] ser
7171
match self.FSharpLoggingPane, msgType with
7272
| None, _ -> ()
7373
| Some pane, LogType.Message ->
74-
String.Format("[F#][{0}{1}] {2}{3}", "", time, msg, Environment.NewLine)
74+
String.Format("[{0}{1}] {2}{3}", "", time, msg, Environment.NewLine)
7575
|> pane.OutputString
7676
|> ignore
7777
| Some pane, LogType.Info ->
78-
String.Format("[F#][{0}{1}] {2}{3}", "INFO ", time, msg, Environment.NewLine)
78+
String.Format("[{0}{1}] {2}{3}", "INFO ", time, msg, Environment.NewLine)
7979
|> pane.OutputString
8080
|> ignore
8181
| Some pane, LogType.Warn ->
82-
String.Format("[F#][{0}{1}] {2}{3}", "WARN ", time, msg, Environment.NewLine)
82+
String.Format("[{0}{1}] {2}{3}", "WARN ", time, msg, Environment.NewLine)
8383
|> pane.OutputString
8484
|> ignore
8585
| Some pane, LogType.Error ->
86-
String.Format("[F#][{0}{1}] {2}{3}", "ERROR ", time, msg, Environment.NewLine)
86+
String.Format("[{0}{1}] {2}{3}", "ERROR ", time, msg, Environment.NewLine)
8787
|> pane.OutputString
8888
|> ignore
8989

@@ -112,3 +112,34 @@ module Logging =
112112

113113
let logExceptionWithContext (ex: Exception, context) =
114114
logErrorf "Context: %s\nException Message: %s\nStack Trace: %s" context ex.Message ex.StackTrace
115+
116+
module Activity =
117+
let listen filter =
118+
let indent (activity: Activity) =
119+
let rec loop (activity: Activity) n =
120+
if activity.Parent <> null then
121+
loop (activity.Parent) (n + 1)
122+
else
123+
n
124+
125+
String.replicate (loop activity 0) " "
126+
127+
let collectTags (activity: Activity) =
128+
[ for tag in activity.Tags -> $"{tag.Key}: %A{tag.Value}" ]
129+
|> String.concat ", "
130+
131+
let listener =
132+
new ActivityListener(
133+
ShouldListenTo = (fun source -> source.Name = FSharp.Compiler.Diagnostics.ActivityNames.FscSourceName),
134+
Sample =
135+
(fun context ->
136+
if context.Name.Contains(filter) then
137+
ActivitySamplingResult.AllDataAndRecorded
138+
else
139+
ActivitySamplingResult.None),
140+
ActivityStarted = (fun a -> logMsg $"{indent a}{a.OperationName} {collectTags a}")
141+
)
142+
143+
ActivitySource.AddActivityListener(listener)
144+
145+
let listenToAll () = listen ""

vsintegration/src/FSharp.Editor/LanguageService/LanguageService.fs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,11 @@ type internal FSharpPackage() as this =
321321

322322
let mutable solutionEventsOpt = None
323323

324+
#if DEBUG
325+
let _logger = Logging.Activity.listenToAll ()
326+
// Logging.Activity.listen "IncrementalBuild"
327+
#endif
328+
324329
// FSI-LINKAGE-POINT: unsited init
325330
do Microsoft.VisualStudio.FSharp.Interactive.Hooks.fsiConsoleWindowPackageCtorUnsited (this :> Package)
326331

0 commit comments

Comments
 (0)