Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
<PackageReference Include="Microsoft.Diagnostics.Runtime" Version="0.9.180305.1" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This version number should be added to build\targets\PackageVersions.props under the other packages heading and placed in alphabetical order:

<MicrosoftDiagnosticsRuntimePackageVersion>0.9.180305.1</MicrosoftDiagnosticsRuntimePackageVersion>

And replaced in this file with $(MicrosoftDiagnosticsRuntimePackageVersion).

</ItemGroup>

</Project>
52 changes: 52 additions & 0 deletions vsintegration/src/FSharp.Editor/Commands/DumpCommandService.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information.

namespace Microsoft.VisualStudio.FSharp.Editor

open System
open System.ComponentModel.Composition
open System.Diagnostics
open Microsoft.VisualStudio
open Microsoft.VisualStudio.Text.Editor
open Microsoft.VisualStudio.Utilities
open Microsoft.VisualStudio.Shell
open Microsoft.VisualStudio.Shell.Interop
open Microsoft.VisualStudio.FSharp.Interactive
open System.ComponentModel.Design
open Microsoft.Diagnostics.Runtime


[<Export(typeof<IWpfTextViewCreationListener>)>]
[<ContentType(FSharpConstants.FSharpContentTypeName)>]
[<TextViewRole(PredefinedTextViewRoles.PrimaryDocument)>]
type internal DumpCommandFilterProvider
[<ImportingConstructor>]
(checkerProvider: FSharpCheckerProvider,
[<Import(typeof<SVsServiceProvider>)>] serviceProvider: System.IServiceProvider) =

let projectSystemPackage =
lazy(
let shell = serviceProvider.GetService(typeof<SVsShell>) :?> IVsShell
let packageToBeLoadedGuid = ref (Guid "{91a04a73-4f2c-4e7c-ad38-c1a68e7da05c}") // FSharp ProjectSystem guid
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the constant defined ProjectPrelude.fs as GuidList.guidFSharpProjectPkgString.

match shell.LoadPackage packageToBeLoadedGuid with
| VSConstants.S_OK, pkg ->
pkg :?> Package
| _ -> null)

let FSharpDump (_this:Package) (_sender:obj) (_e:EventArgs) =
checkerProvider.Checker.ClearLanguageServiceRootCachesAndCollectAndFinalizeAllTransients()
use target = DataTarget.CreateSnapshotAndAttach(Process.GetCurrentProcess().Id)
let runtime = target.ClrVersions.[0].CreateRuntime();
let outputPane = projectSystemPackage.Value.GetOutputPane(VSConstants.OutputWindowPaneGuid.BuildOutputPane_guid, "FSharp Dump")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with this API. Does "FSharp Dump" need to be localized/translated? If so it'll have to be added to a .resx file and consumed that way.

runtime.Heap.EnumerateObjects()
|> Seq.groupBy (fun x -> x.Type.Name)
|> Seq.map (fun (ty, os) -> ty, os |> Seq.sumBy (fun x -> x.Size), os |> Seq.length)
|> Seq.sortBy (fun (_, size, _) -> -int64 size)
|> Seq.take 100
|> Seq.iter (fun (ty, size, count) -> outputPane.OutputString (sprintf "Type: %s, Total size: %d, Instance count: %d\r\n" ty size count) |> ignore)

interface IWpfTextViewCreationListener with
member __.TextViewCreated(_textView) =
let commandService = (projectSystemPackage.Value :> System.IServiceProvider).GetService(typeof<IMenuCommandService>) :?> OleMenuCommandService
let id = new CommandID(Guids.guidFSharpProjectCmdSet,int32 Guids.cmdIDFSharpDump)
let cmd = new MenuCommand(new EventHandler(FSharpDump projectSystemPackage.Value), id)
commandService.AddCommand(cmd)
3 changes: 3 additions & 0 deletions vsintegration/src/FSharp.Editor/FSharp.Editor.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
<Compile Include="Structure\BlockStructureService.fs" />
<Compile Include="Commands\HelpContextService.fs" />
<Compile Include="Commands\FsiCommandService.fs" />
<Compile Include="Commands\DumpCommandService.fs" />
<Compile Include="Commands\XmlDocCommandService.fs" />
<Compile Include="CodeFix\AddNewKeywordToDisposableConstructorInvocation.fs" />
<Compile Include="CodeFix\AddOpenCodeFixProvider.fs" />
Expand Down Expand Up @@ -106,6 +107,7 @@
<Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Design" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xaml" />
Expand Down Expand Up @@ -139,6 +141,7 @@
<PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
<PackageReference Include="System.Collections.Immutable" Version="$(SystemCollectionsImmutablePackageVersion)" />
<PackageReference Include="VSSDK.VSLangProj" Version="$(VSSDKVSLangProjPackageVersion)" />
<PackageReference Include="Microsoft.Diagnostics.Runtime" Version="0.9.180305.1" />
Copy link
Member

@brettfo brettfo Mar 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same build\targets\PackageVersions.props comment as above.

</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,15 @@
<ButtonText>F# Interactive</ButtonText>
</Strings>
</Button>

<Button guid="FSharpProjectCmdSet" id="cmdidFsDump" priority="0x8000" type="Button">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This addition should have (but obviously didn't) update all of the MenusAndCommands.vsct.*.xlf files. Can you try running this to force regeneration?

msbuild vsintegration\src\FSharp.ProjectSystem.FSharp\ProjectSystem.fsproj /t:UpxateXlf

<!-- low priority -->
<Parent guid="guidSHLMainMenu" id="IDG_VS_WNDO_OTRWNDWS1"/>
<Strings>
<CommandName>FSharp.Dump</CommandName>
<ButtonText>F# Dump</ButtonText>
</Strings>
</Button>

<!-- In Dev11+, shell now has
<Button guid ="guidVSStd11" id ="cmdidInteractiveSessionInterrupt" priority ="0x100" type ="Button">
Expand Down Expand Up @@ -420,6 +429,8 @@
<IDSymbol name = "FSharpSendThisReferenceToInteractiveCmd" value ="0x5004"/>
<IDSymbol name = "FSharpSendReferencesToInteractiveCmd" value ="0x5005"/>
<IDSymbol name = "FSharpSendProjectOutputToInteractiveCmd" value ="0x5006"/>

<IDSymbol name="cmdidFsDump" value="0x0100" />
</GuidSymbol>
<GuidSymbol name="FSharpMoveUpBmp" value="{6C2FAD07-753D-45ab-BEE9-5D12D207991B}" >
<IDSymbol name="moveUp" value="1" />
Expand Down
3 changes: 3 additions & 0 deletions vsintegration/src/FSharp.VS.FSI/fsiBasis.fs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ module internal Guids =
// FSI Package command set
let guidFsiPackageCmdSet = Guid("0be3b0d7-4fc2-45bf-a168-957e8a8834d0")
let cmdIDLaunchFsiToolWindow = 0x101

let guidFSharpProjectCmdSet = new Guid("75AC5611-A912-4195-8A65-457AE17416FB");
let cmdIDFSharpDump = 0x100

let nameFsiLanguageService = "FSharpInteractive" // see Package registration attribute

Expand Down