├── tool
├── .gitignore
├── MemTraceTool
│ ├── luna.ico
│ ├── icons
│ │ ├── asset.png
│ │ ├── delta.png
│ │ ├── folder.png
│ │ ├── gear.png
│ │ ├── heap.png
│ │ ├── pacman.png
│ │ ├── symbol.png
│ │ ├── namespace.png
│ │ └── sourcefile.png
│ ├── packages.config
│ ├── Properties
│ │ ├── Settings.settings
│ │ ├── Settings.Designer.cs
│ │ ├── AssemblyInfo.cs
│ │ ├── Resources.Designer.cs
│ │ └── Resources.resx
│ ├── Program.cs
│ ├── App.config
│ ├── WarningWindow.cs
│ ├── TimeControlHelpers.cs
│ ├── TODO.txt
│ ├── FragmentationWidget.Designer.cs
│ ├── TraceListItem.cs
│ ├── TreePerspective.cs
│ ├── WarningWindow.Designer.cs
│ ├── DeltaWindow.cs
│ ├── FragmentationWidget.cs
│ ├── SymbolResolveDialog.Designer.cs
│ ├── SymbolResolveDialog.cs
│ ├── Options.cs
│ ├── RangeQueryWindow.cs
│ ├── FragmentationWidget.resx
│ ├── DeltaWindow.Designer.cs
│ ├── OptionsDialog.cs
│ └── TreeBuilder.cs
├── MemTraceWidgets
│ ├── dots.png
│ ├── Resources
│ │ └── Dots.png
│ ├── packages.config
│ ├── app.config
│ ├── MemBlockView.Designer.cs
│ ├── FragmentationWidget.Designer.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── MemTreeNode.cs
│ ├── HeapTreeList.cs
│ ├── TimeControl.cs
│ ├── WidgetResources.Designer.cs
│ ├── MemBlockView.cs
│ ├── TimeControl.Designer.cs
│ ├── TimeControl.resx
│ ├── FragmentationWidget.resx
│ ├── WidgetResources.resx
│ ├── MemTraceWidgets.csproj
│ └── HeapTreeList.Designer.cs
├── MemTrace
│ ├── packages.config
│ ├── MemTrace.yaml
│ ├── app.config
│ ├── EventCode.cs
│ ├── ISymbolResolver.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── TraceListener.cs
│ ├── DbgHelpSymbolResolver.cs
│ ├── MemTrace.csproj
│ ├── TraceRecorder.cs
│ ├── AsyncStreamPump.cs
│ └── OrbisSymbolResolver.cs
└── MemTraceUI.sln
├── runtime
├── vs2012
│ ├── .gitignore
│ ├── MemTraceDemo.vcxproj.filters
│ ├── MemTrace.sln
│ ├── MemTrace.vcxproj.filters
│ ├── MemTraceDemo.vcxproj
│ └── MemTrace.vcxproj
├── minhook-bin
│ └── MinHook.x64.dll
├── Makefile
├── MemTrace.h
├── DemoMain.cpp
├── MemTraceInit.h
├── MemTraceSys.cpp
└── MemTraceSys.h
├── .gitignore
├── docs
├── addrquery.png
├── deltaview.png
├── heapview.png
├── mainwindow.png
├── opt_files.png
├── opt_network.png
├── fragmentation.png
├── opt_symbolpaths.png
├── opt_symbolremap.png
├── opt_symbolsupp.png
├── symbolresolve.png
└── heapview_perspective.png
├── .gitmodules
├── DefaultOptions.json
└── COPYING
/tool/.gitignore:
--------------------------------------------------------------------------------
1 | packages
2 |
--------------------------------------------------------------------------------
/runtime/vs2012/.gitignore:
--------------------------------------------------------------------------------
1 | Debug
2 | Release
3 | x64
4 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | bin
2 | obj
3 | *.pdb
4 | *.suo
5 | *.user
6 | pingme.txt
7 |
--------------------------------------------------------------------------------
/docs/addrquery.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/deplinenoise/ig-memtrace/HEAD/docs/addrquery.png
--------------------------------------------------------------------------------
/docs/deltaview.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/deplinenoise/ig-memtrace/HEAD/docs/deltaview.png
--------------------------------------------------------------------------------
/docs/heapview.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/deplinenoise/ig-memtrace/HEAD/docs/heapview.png
--------------------------------------------------------------------------------
/docs/mainwindow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/deplinenoise/ig-memtrace/HEAD/docs/mainwindow.png
--------------------------------------------------------------------------------
/docs/opt_files.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/deplinenoise/ig-memtrace/HEAD/docs/opt_files.png
--------------------------------------------------------------------------------
/docs/opt_network.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/deplinenoise/ig-memtrace/HEAD/docs/opt_network.png
--------------------------------------------------------------------------------
/docs/fragmentation.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/deplinenoise/ig-memtrace/HEAD/docs/fragmentation.png
--------------------------------------------------------------------------------
/docs/opt_symbolpaths.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/deplinenoise/ig-memtrace/HEAD/docs/opt_symbolpaths.png
--------------------------------------------------------------------------------
/docs/opt_symbolremap.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/deplinenoise/ig-memtrace/HEAD/docs/opt_symbolremap.png
--------------------------------------------------------------------------------
/docs/opt_symbolsupp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/deplinenoise/ig-memtrace/HEAD/docs/opt_symbolsupp.png
--------------------------------------------------------------------------------
/docs/symbolresolve.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/deplinenoise/ig-memtrace/HEAD/docs/symbolresolve.png
--------------------------------------------------------------------------------
/tool/MemTraceTool/luna.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/deplinenoise/ig-memtrace/HEAD/tool/MemTraceTool/luna.ico
--------------------------------------------------------------------------------
/docs/heapview_perspective.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/deplinenoise/ig-memtrace/HEAD/docs/heapview_perspective.png
--------------------------------------------------------------------------------
/tool/MemTraceWidgets/dots.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/deplinenoise/ig-memtrace/HEAD/tool/MemTraceWidgets/dots.png
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "runtime/minhook"]
2 | path = runtime/minhook
3 | url = https://github.com/TsudaKageyu/minhook.git
4 |
--------------------------------------------------------------------------------
/tool/MemTraceTool/icons/asset.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/deplinenoise/ig-memtrace/HEAD/tool/MemTraceTool/icons/asset.png
--------------------------------------------------------------------------------
/tool/MemTraceTool/icons/delta.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/deplinenoise/ig-memtrace/HEAD/tool/MemTraceTool/icons/delta.png
--------------------------------------------------------------------------------
/tool/MemTraceTool/icons/folder.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/deplinenoise/ig-memtrace/HEAD/tool/MemTraceTool/icons/folder.png
--------------------------------------------------------------------------------
/tool/MemTraceTool/icons/gear.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/deplinenoise/ig-memtrace/HEAD/tool/MemTraceTool/icons/gear.png
--------------------------------------------------------------------------------
/tool/MemTraceTool/icons/heap.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/deplinenoise/ig-memtrace/HEAD/tool/MemTraceTool/icons/heap.png
--------------------------------------------------------------------------------
/tool/MemTraceTool/icons/pacman.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/deplinenoise/ig-memtrace/HEAD/tool/MemTraceTool/icons/pacman.png
--------------------------------------------------------------------------------
/tool/MemTraceTool/icons/symbol.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/deplinenoise/ig-memtrace/HEAD/tool/MemTraceTool/icons/symbol.png
--------------------------------------------------------------------------------
/runtime/minhook-bin/MinHook.x64.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/deplinenoise/ig-memtrace/HEAD/runtime/minhook-bin/MinHook.x64.dll
--------------------------------------------------------------------------------
/tool/MemTraceTool/icons/namespace.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/deplinenoise/ig-memtrace/HEAD/tool/MemTraceTool/icons/namespace.png
--------------------------------------------------------------------------------
/tool/MemTraceTool/icons/sourcefile.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/deplinenoise/ig-memtrace/HEAD/tool/MemTraceTool/icons/sourcefile.png
--------------------------------------------------------------------------------
/tool/MemTraceWidgets/Resources/Dots.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/deplinenoise/ig-memtrace/HEAD/tool/MemTraceWidgets/Resources/Dots.png
--------------------------------------------------------------------------------
/tool/MemTrace/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/tool/MemTraceTool/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/tool/MemTraceWidgets/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/tool/MemTrace/MemTrace.yaml:
--------------------------------------------------------------------------------
1 | Name: MemTrace
2 | Type: CSharpLib
3 | UseDiskSources: true
4 |
5 | NuGetPackages:
6 | - { id: "Netwonsoft.Json", version: "6.0.8", targetFramework: "net45" }
7 | - { id: "ObjectListView", version: "2.7.1", targetFramework: "net45" }
8 |
9 |
--------------------------------------------------------------------------------
/tool/MemTraceTool/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/DefaultOptions.json:
--------------------------------------------------------------------------------
1 | {
2 | "SuppressedSymbols": [
3 | "MemTrace::Encoder::BeginEvent",
4 | "MemTrace::HeapAllocate",
5 | "__tmainCRTStartup",
6 | "RtlUserThreadStart",
7 | "BaseThreadInitThunk",
8 | "wWinMainCRTStartup",
9 | "MemTrace::HeapFree"
10 | ],
11 | "EnableSuppression": true,
12 | "BindAddress": "0.0.0.0",
13 | "BindPort": 9811,
14 | "SymbolPaths": [
15 | ],
16 | "ModulePathRemappings": [
17 | ]
18 | }
19 |
--------------------------------------------------------------------------------
/runtime/Makefile:
--------------------------------------------------------------------------------
1 | all: Demo
2 |
3 | DEFINES += -DMEMTRACE_USE_TEMP_FILE
4 |
5 | .cpp.o:
6 | clang++ -c $(DEFINES) -std=c++11 -Wall -o $@ $<
7 |
8 | MemTrace.o: MemTrace.cpp MemTrace.h MemTraceSys.h MemTraceInit.h
9 |
10 | MemTraceSys.o: MemTraceSys.cpp MemTrace.h MemTraceSys.h
11 |
12 | DemoMain.o: DemoMain.cpp MemTrace.h MemTraceInit.h
13 |
14 | Demo: DemoMain.o MemTrace.o MemTraceSys.o
15 | clang++ -std=c++11 -Wall -o $@ $^
16 |
17 | clean:
18 | rm -f Demo *.o
19 |
--------------------------------------------------------------------------------
/tool/MemTraceTool/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Forms;
3 |
4 | namespace MemTraceTool
5 | {
6 | static class Program
7 | {
8 | ///
9 | /// The main entry point for the application.
10 | ///
11 | [STAThread]
12 | static void Main()
13 | {
14 | Application.EnableVisualStyles();
15 | Application.SetCompatibleTextRenderingDefault(false);
16 | Application.Run(new MainWindow());
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/tool/MemTrace/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/tool/MemTraceWidgets/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/tool/MemTraceTool/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/tool/MemTraceTool/WarningWindow.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Data;
5 | using System.Drawing;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 | using System.Windows.Forms;
10 |
11 | namespace MemTraceTool
12 | {
13 | public partial class WarningWindow : Form
14 | {
15 | public void SetWarnings(ICollection data)
16 | {
17 | m_TextBox.Clear();
18 | m_TextBox.Text = String.Join("\r\n", data);
19 | m_TextBox.Select(0, -1);
20 | }
21 |
22 | public WarningWindow()
23 | {
24 | InitializeComponent();
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/tool/MemTraceWidgets/MemBlockView.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace MemTrace.Widgets
2 | {
3 | partial class MemBlockView
4 | {
5 | ///
6 | /// Required designer variable.
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | #region Component Designer generated code
11 |
12 | ///
13 | /// Required method for Designer support - do not modify
14 | /// the contents of this method with the code editor.
15 | ///
16 | private void InitializeComponent()
17 | {
18 | components = new System.ComponentModel.Container();
19 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
20 | }
21 |
22 | #endregion
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/tool/MemTrace/EventCode.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace MemTrace
8 | {
9 | // Event codes - keep in sync with native code side.
10 | public enum EventCode
11 | {
12 | BeginStream = 1,
13 | EndStream,
14 | ModuleDump,
15 | Mark,
16 |
17 | AddressAllocate = 10,
18 | AddressFree,
19 | VirtualCommit,
20 | VirtualDecommit,
21 |
22 | PhysicalAllocate,
23 | PhysicalFree,
24 | PhysicalMap,
25 | PhysicalUnmap,
26 |
27 | HeapCreate,
28 | HeapDestroy,
29 | HeapAddCore,
30 | HeapRemoveCore,
31 | HeapAllocate,
32 | HeapReallocate,
33 | HeapFree,
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/runtime/vs2012/MemTraceDemo.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
--------------------------------------------------------------------------------
/tool/MemTraceTool/TimeControlHelpers.cs:
--------------------------------------------------------------------------------
1 | using MemTrace;
2 | using MemTrace.Widgets;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace MemTraceTool
10 | {
11 | class TimeControlHelpers
12 | {
13 | public static void CreateTimeControlMarks(TimeControl tc, TraceProcessorBase trace)
14 | {
15 | // Build set of times stamps from marks
16 | {
17 | var m = new List();
18 | m.Add(new TimeControl.Mark { Name = "Start", Time = 0.0 });
19 | var marks = new List();
20 | trace.MetaData.GetTraceMarks(marks);
21 | foreach (var mark in marks)
22 | {
23 | m.Add(new TimeControl.Mark
24 | {
25 | Name = mark.Name,
26 | Time = mark.TimeStamp / (double)trace.MetaData.TimerFrequency
27 | });
28 | }
29 | tc.MinTime = 0;
30 | tc.MaxTime = trace.MetaData.MaxTimeStamp / (double)trace.MetaData.TimerFrequency;
31 | m.Add(new TimeControl.Mark { Name = "End", Time = tc.MaxTime });
32 | tc.SetMarks(m);
33 | }
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/tool/MemTraceTool/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.34014
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace MemTraceTool.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/tool/MemTrace/ISymbolResolver.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace MemTrace
8 | {
9 | public sealed class ModulePathRemapping
10 | {
11 | public string Platform { get; set; }
12 | public string Path { get; set; }
13 | public string ReplacementPath { get; set; }
14 |
15 | public ModulePathRemapping Clone()
16 | {
17 | return new ModulePathRemapping
18 | {
19 | Platform = Platform,
20 | Path = Path,
21 | ReplacementPath = ReplacementPath
22 | };
23 | }
24 | }
25 |
26 | public interface ISymbolProgressListener
27 | {
28 | void UpdateProgress(string status, double pct);
29 | void UpdateMessage(string status, params object[] args);
30 | void Done();
31 | void UpdateError(string p);
32 | }
33 |
34 | public interface ISymbolResolver
35 | {
36 | bool NeedsExePath { get; }
37 | string ExeExtension { get; }
38 |
39 | void BeginResolve(string exePath, ISymbolProgressListener listener, TraceReplayStateful replay, ICollection symbolPaths, ICollection remappings);
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/tool/MemTraceTool/TODO.txt:
--------------------------------------------------------------------------------
1 |
2 | Initial JSON file to live next to checked-in binary.
3 |
4 | Find dialog in heap view.
5 |
6 | Need new delta view now that the time control is in.
7 |
8 | Asset heap not working on PC.
9 |
10 | Clean up File menu/open options. How to get trace files from locutus to your own machine?
11 |
12 | Detect code branch via LunaServer to figure out bin directory?
13 |
14 | Options menu access from heap view.
15 |
16 | Fragmentation view:
17 | - Select one heap/container?
18 | - Colorize allocs based on topic?
19 | - Fade out to white with age?
20 | - How to map? Customizable?
21 |
22 | After stopping a trace buttons should be accessible.
23 |
24 | Better crash proofing againt bad trace files on disk.
25 |
26 | Figure out deployment of Durango wrapped DLLs.
27 |
28 | Figure out if we can hook lower-level stuff like ntdll!NtVirtualAllocate to catch *everything*
29 |
30 | HeapAllocate() and friends should definitely be hooked. Hook HeapCreate() to figure out name?
31 |
32 | Symbol resolution dialog:
33 | - Fix ghetto flickering text box
34 | - Show report at the end with # of symbols resolved and # failed
35 |
36 | Nice to have:
37 | - Rename dump filenames or at least add a comment to dump.
38 | - Mark time recorded and length of recording in h/m/s.
39 |
40 |
41 | [DONE]
42 | Initial setup needs settings in the registry.
43 |
--------------------------------------------------------------------------------
/COPYING:
--------------------------------------------------------------------------------
1 | Copyright (c) 2015, Insomniac Games All rights reserved.
2 |
3 | Redistribution and use in source and binary forms, with or without
4 | modification, are permitted provided that the following conditions are met:
5 |
6 | Redistributions of source code must retain the above copyright notice, this
7 | list of conditions and the following disclaimer.
8 |
9 | Redistributions in binary form must reproduce the above copyright notice, this
10 | list of conditions and the following disclaimer in the documentation and/or
11 | other materials provided with the distribution.
12 |
13 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
14 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
17 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
20 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
21 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 |
--------------------------------------------------------------------------------
/runtime/vs2012/MemTrace.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2012
4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MemTrace", "MemTrace.vcxproj", "{C9F9CA93-3A01-41E8-A601-66C45AA7FEA6}"
5 | EndProject
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MemTraceDemo", "MemTraceDemo.vcxproj", "{635A9485-BB33-4886-BE78-797A2693B987}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Release|x64 = Release|x64
12 | EndGlobalSection
13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 | {C9F9CA93-3A01-41E8-A601-66C45AA7FEA6}.Debug|x64.ActiveCfg = Debug|x64
15 | {C9F9CA93-3A01-41E8-A601-66C45AA7FEA6}.Debug|x64.Build.0 = Debug|x64
16 | {C9F9CA93-3A01-41E8-A601-66C45AA7FEA6}.Release|x64.ActiveCfg = Release|x64
17 | {C9F9CA93-3A01-41E8-A601-66C45AA7FEA6}.Release|x64.Build.0 = Release|x64
18 | {635A9485-BB33-4886-BE78-797A2693B987}.Debug|x64.ActiveCfg = Debug|x64
19 | {635A9485-BB33-4886-BE78-797A2693B987}.Debug|x64.Build.0 = Debug|x64
20 | {635A9485-BB33-4886-BE78-797A2693B987}.Release|x64.ActiveCfg = Release|x64
21 | {635A9485-BB33-4886-BE78-797A2693B987}.Release|x64.Build.0 = Release|x64
22 | EndGlobalSection
23 | GlobalSection(SolutionProperties) = preSolution
24 | HideSolutionNode = FALSE
25 | EndGlobalSection
26 | EndGlobal
27 |
--------------------------------------------------------------------------------
/runtime/vs2012/MemTrace.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 | Source Files
23 |
24 |
25 |
26 |
27 | Header Files
28 |
29 |
30 | Header Files
31 |
32 |
33 |
--------------------------------------------------------------------------------
/tool/MemTraceTool/FragmentationWidget.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace MemTraceTool
2 | {
3 | partial class FragmentationWidget
4 | {
5 | ///
6 | /// Required designer variable.
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// Clean up any resources being used.
12 | ///
13 | /// true if managed resources should be disposed; otherwise, false.
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Component Designer generated code
24 |
25 | ///
26 | /// Required method for Designer support - do not modify
27 | /// the contents of this method with the code editor.
28 | ///
29 | private void InitializeComponent()
30 | {
31 | this.SuspendLayout();
32 | //
33 | // FragmentationWidget
34 | //
35 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
36 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
37 | this.BackColor = System.Drawing.SystemColors.AppWorkspace;
38 | this.Name = "FragmentationWidget";
39 | this.ResumeLayout(false);
40 |
41 | }
42 |
43 | #endregion
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/tool/MemTraceWidgets/FragmentationWidget.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace MemTrace.Widgets
2 | {
3 | partial class FragmentationWidget
4 | {
5 | ///
6 | /// Required designer variable.
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// Clean up any resources being used.
12 | ///
13 | /// true if managed resources should be disposed; otherwise, false.
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Component Designer generated code
24 |
25 | ///
26 | /// Required method for Designer support - do not modify
27 | /// the contents of this method with the code editor.
28 | ///
29 | private void InitializeComponent()
30 | {
31 | this.SuspendLayout();
32 | //
33 | // FragmentationWidget
34 | //
35 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
36 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
37 | this.BackColor = System.Drawing.SystemColors.ControlLight;
38 | this.Name = "FragmentationWidget";
39 | this.ResumeLayout(false);
40 |
41 | }
42 |
43 | #endregion
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/tool/MemTraceTool/TraceListItem.cs:
--------------------------------------------------------------------------------
1 | using MemTrace;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace MemTraceTool
9 | {
10 | class TraceListItem
11 | {
12 | private string m_FileName;
13 | public TraceMeta Meta { get; internal set; }
14 | public TraceRecorder Recorder { get; internal set; }
15 |
16 | public string FileName { get { return m_FileName; } set { m_FileName = value; } }
17 | public string SourceMachine { get { return Meta.SourceMachine; } }
18 | public long EventCount { get { return Meta.EventCount; } }
19 | public long WireSize { get { return Meta.WireSizeBytes; } }
20 | public long OutputSize { get { return Meta.EncodedDataSizeBytes; } }
21 | public string PlatformName { get { return Meta.PlatformName; } }
22 | public string IsResolved { get { return Meta.ResolvedSymbols.Count > 0 ? "Yes" : "No"; } }
23 | public TraceStatus Status { get { return Meta.Status; } }
24 | public string ExecutableName { get { return Meta.ExecutableName; } }
25 | public int WarningCount { get { return Meta.WarningCount; } }
26 |
27 | internal TraceListItem(string fn, TraceMeta meta, TraceRecorder recorder)
28 | {
29 | m_FileName = fn;
30 | Meta = meta;
31 | Recorder = recorder;
32 | }
33 |
34 | public ICollection Warnings { get { return Meta.Warnings; } }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/tool/MemTrace/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("MemTraceDecode")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("MemTraceDecode")]
13 | [assembly: AssemblyCopyright("Copyright © 2014")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("1202b419-3b4b-4ed1-9c7d-5b44aeab1be6")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/tool/MemTraceTool/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("MemTraceTool")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("MemTraceTool")]
13 | [assembly: AssemblyCopyright("Copyright © 2014")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("9c53455f-a919-4a5f-8f48-dbd4b3140580")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/tool/MemTraceWidgets/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("MemTraceWidgets")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("MemTraceWidgets")]
13 | [assembly: AssemblyCopyright("Copyright © 2014")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("dcdffe31-aab6-4842-8651-d853c8db0d6d")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/tool/MemTraceTool/TreePerspective.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace MemTraceTool
4 | {
5 | enum TreeAxis
6 | {
7 | CallStack,
8 | CallStackReverse,
9 | FileName,
10 | Heap,
11 | AssetType,
12 | AssetPath,
13 | ComponentType
14 | }
15 |
16 | sealed class TreePerspective
17 | {
18 | internal static readonly TreePerspective Default = new TreePerspective("Heap/Stack", new TreeAxis[] { TreeAxis.Heap, TreeAxis.CallStack });
19 | internal static readonly TreePerspective Reverse = new TreePerspective("Heap/Stack (Reverse)", new TreeAxis[] { TreeAxis.Heap, TreeAxis.CallStackReverse });
20 | internal static readonly TreePerspective Asset = new TreePerspective("Heap/Asset Type/Asset Path", new TreeAxis[] { TreeAxis.Heap, TreeAxis.AssetType, TreeAxis.AssetPath, TreeAxis.CallStack });
21 | internal static readonly TreePerspective AssetType = new TreePerspective("Asset Type/Heap", new TreeAxis[] { TreeAxis.AssetType, TreeAxis.Heap });
22 | internal static readonly TreePerspective Component = new TreePerspective("Heap/Component Type/Stack", new TreeAxis[] { TreeAxis.Heap, TreeAxis.ComponentType, TreeAxis.CallStack });
23 |
24 | internal static readonly TreePerspective[] AllItems = new TreePerspective[] {
25 | Default,
26 | Reverse,
27 | Asset,
28 | AssetType,
29 | Component
30 | };
31 |
32 | internal string Name { get; private set; }
33 | internal TreeAxis[] Axes { get; private set; }
34 |
35 | private TreePerspective(string name, TreeAxis[] axes)
36 | {
37 | Name = name;
38 | Axes = axes;
39 | }
40 |
41 | public override string ToString()
42 | {
43 | return Name;
44 | }
45 | }
46 | }
--------------------------------------------------------------------------------
/tool/MemTraceWidgets/MemTreeNode.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace MemTraceTool
8 | {
9 | public sealed class MemTreeNode
10 | {
11 | private Dictionary m_Children = new Dictionary();
12 | private MemTreeNode[] m_ChildArray = null;
13 |
14 | public MemTreeNode[] Children { get { return m_ChildArray; } }
15 | public bool HasChildren { get { return m_ChildArray != null; } }
16 |
17 | public MemTreeNode Parent { get; private set; }
18 | public string Key { get; private set; }
19 | public string FileName { get; set; }
20 | public int LineNumber { get; set; }
21 | public string Icon { get; set; }
22 | public long SizeBytes { get; set; }
23 | public ulong Count { get; set; }
24 |
25 | public MemTreeNode(MemTreeNode parent, string key)
26 | {
27 | Parent = parent;
28 | Key = key;
29 | }
30 |
31 | public MemTreeNode GetChild(string key)
32 | {
33 | MemTreeNode child;
34 | if (m_Children.TryGetValue(key, out child))
35 | return child;
36 |
37 | child = new MemTreeNode(this, key);
38 | m_Children.Add(key, child);
39 | return child;
40 | }
41 |
42 | public void Freeze()
43 | {
44 | if (m_Children.Count > 0)
45 | {
46 | m_ChildArray = m_Children.Values.ToArray();
47 | foreach (var child in m_ChildArray)
48 | {
49 | child.Freeze();
50 | }
51 | }
52 | else
53 | {
54 | m_ChildArray = null;
55 | }
56 | m_Children = null;
57 | }
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/tool/MemTraceUI.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2012
4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MemTrace", "MemTrace\MemTrace.csproj", "{2E43CDC0-AC81-4172-85E7-4126EED64656}"
5 | EndProject
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MemTraceTool", "MemTraceTool\MemTraceTool.csproj", "{2FBF023A-ACDB-4526-AEBF-8C72FFC40E9A}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MemTraceWidgets", "MemTraceWidgets\MemTraceWidgets.csproj", "{DE94B6DF-8E75-4623-A12C-BE2A1756A128}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Any CPU = Debug|Any CPU
13 | Release|Any CPU = Release|Any CPU
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {2E43CDC0-AC81-4172-85E7-4126EED64656}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17 | {2E43CDC0-AC81-4172-85E7-4126EED64656}.Debug|Any CPU.Build.0 = Debug|Any CPU
18 | {2E43CDC0-AC81-4172-85E7-4126EED64656}.Release|Any CPU.ActiveCfg = Release|Any CPU
19 | {2E43CDC0-AC81-4172-85E7-4126EED64656}.Release|Any CPU.Build.0 = Release|Any CPU
20 | {2FBF023A-ACDB-4526-AEBF-8C72FFC40E9A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {2FBF023A-ACDB-4526-AEBF-8C72FFC40E9A}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {2FBF023A-ACDB-4526-AEBF-8C72FFC40E9A}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {2FBF023A-ACDB-4526-AEBF-8C72FFC40E9A}.Release|Any CPU.Build.0 = Release|Any CPU
24 | {DE94B6DF-8E75-4623-A12C-BE2A1756A128}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25 | {DE94B6DF-8E75-4623-A12C-BE2A1756A128}.Debug|Any CPU.Build.0 = Debug|Any CPU
26 | {DE94B6DF-8E75-4623-A12C-BE2A1756A128}.Release|Any CPU.ActiveCfg = Release|Any CPU
27 | {DE94B6DF-8E75-4623-A12C-BE2A1756A128}.Release|Any CPU.Build.0 = Release|Any CPU
28 | EndGlobalSection
29 | GlobalSection(SolutionProperties) = preSolution
30 | HideSolutionNode = FALSE
31 | EndGlobalSection
32 | EndGlobal
33 |
--------------------------------------------------------------------------------
/tool/MemTraceWidgets/HeapTreeList.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Drawing;
5 | using System.Data;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 | using System.Windows.Forms;
10 | using MemTraceTool;
11 |
12 | namespace MemTrace.Widgets
13 | {
14 | public partial class HeapTreeList : UserControl
15 | {
16 | public HeapTreeList()
17 | {
18 | InitializeComponent();
19 |
20 | // Hook up treelist view stuff.
21 | m_TreeList.CanExpandGetter = (object o) =>
22 | {
23 | return ((MemTreeNode)o).HasChildren;
24 | };
25 | m_TreeList.ChildrenGetter = (object o) =>
26 | {
27 | return ((MemTreeNode)o).Children;
28 | };
29 | m_KeyColumn.ImageGetter = (object o) =>
30 | {
31 | return ((MemTreeNode)o).Icon;
32 | };
33 | m_LineNumberColumn.AspectGetter = (object o) =>
34 | {
35 | int value = ((MemTreeNode)o).LineNumber;
36 | if (value == 0)
37 | return null;
38 | return value;
39 | };
40 | m_SizeColumn.AspectToStringConverter = (object o) =>
41 | {
42 | long size = (long)o;
43 | long abs = Math.Abs(size);
44 | if ((abs >> 30) > 0)
45 | {
46 | return String.Format("{0:n2} GB", size / (1024.0 * 1024.0 * 1024.0));
47 | }
48 | if ((abs >> 20) > 0)
49 | {
50 | return String.Format("{0:n2} MB", size / (1024.0 * 1024.0));
51 | }
52 | if ((abs >> 10) > 0)
53 | {
54 | return String.Format("{0:n2} KB", size / (1024.0));
55 | }
56 | return String.Format("{0:n0} B", size);
57 | };
58 | }
59 |
60 | public MemTreeNode SelectedNode
61 | {
62 | get { return (MemTreeNode)m_TreeList.SelectedObject; }
63 | }
64 |
65 | public void SetRoot(MemTreeNode root)
66 | {
67 | m_TreeList.Roots = new object[] { root };
68 | m_TreeList.RebuildAll(true);
69 | m_TreeList.Expand(root);
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/tool/MemTraceTool/WarningWindow.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace MemTraceTool
2 | {
3 | partial class WarningWindow
4 | {
5 | ///
6 | /// Required designer variable.
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// Clean up any resources being used.
12 | ///
13 | /// true if managed resources should be disposed; otherwise, false.
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Windows Form Designer generated code
24 |
25 | ///
26 | /// Required method for Designer support - do not modify
27 | /// the contents of this method with the code editor.
28 | ///
29 | private void InitializeComponent()
30 | {
31 | System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(WarningWindow));
32 | this.m_TextBox = new System.Windows.Forms.TextBox();
33 | this.SuspendLayout();
34 | //
35 | // m_TextBox
36 | //
37 | this.m_TextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
38 | | System.Windows.Forms.AnchorStyles.Left)
39 | | System.Windows.Forms.AnchorStyles.Right)));
40 | this.m_TextBox.Location = new System.Drawing.Point(13, 13);
41 | this.m_TextBox.Multiline = true;
42 | this.m_TextBox.Name = "m_TextBox";
43 | this.m_TextBox.ReadOnly = true;
44 | this.m_TextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
45 | this.m_TextBox.Size = new System.Drawing.Size(629, 399);
46 | this.m_TextBox.TabIndex = 0;
47 | //
48 | // WarningWindow
49 | //
50 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
51 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
52 | this.ClientSize = new System.Drawing.Size(654, 424);
53 | this.Controls.Add(this.m_TextBox);
54 | this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
55 | this.Name = "WarningWindow";
56 | this.Text = "Warnings";
57 | this.ResumeLayout(false);
58 | this.PerformLayout();
59 |
60 | }
61 |
62 | #endregion
63 |
64 | private System.Windows.Forms.TextBox m_TextBox;
65 | }
66 | }
--------------------------------------------------------------------------------
/tool/MemTraceTool/DeltaWindow.cs:
--------------------------------------------------------------------------------
1 | using MemTrace;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.ComponentModel;
5 | using System.Data;
6 | using System.Drawing;
7 | using System.Linq;
8 | using System.Text;
9 | using System.Threading.Tasks;
10 | using System.Windows.Forms;
11 |
12 | namespace MemTraceTool
13 | {
14 | public partial class DeltaWindow : Form
15 | {
16 | private TraceReplayStateful m_Trace;
17 | private Options m_Options;
18 |
19 | internal DeltaWindow(string fn, Options options)
20 | {
21 | InitializeComponent();
22 |
23 | m_Trace = new TraceReplayStateful(fn);
24 | m_Options = options;
25 |
26 | TimeControlHelpers.CreateTimeControlMarks(m_StartTimeControl, m_Trace);
27 | TimeControlHelpers.CreateTimeControlMarks(m_EndTimeControl, m_Trace);
28 |
29 | m_Perspective.Items.AddRange(TreePerspective.AllItems);
30 | m_Perspective.SelectedIndex = 0;
31 | }
32 |
33 | protected override void OnClosed(EventArgs e)
34 | {
35 | m_Trace.Dispose();
36 | }
37 |
38 | private void OnRefreshButtonClick(object sender, EventArgs e)
39 | {
40 | m_RefreshButton.Enabled = false;
41 | m_StartTimeControl.Enabled = false;
42 | m_EndTimeControl.Enabled = false;
43 |
44 | var perspective = (TreePerspective) m_Perspective.SelectedItem;
45 | var startTime = m_StartTimeControl.CurrentTime;
46 | var endTime = m_EndTimeControl.CurrentTime;
47 |
48 | Task.Run(() => { this.UpdateDeltaViewAsync(startTime, endTime, perspective); });
49 | }
50 |
51 | private void UpdateDeltaViewAsync(double startTime, double endTime, TreePerspective perspective)
52 | {
53 | this.Invoke((Action)delegate() { m_StripStatus.Text = "Replaying events.."; });
54 |
55 | TraceReplayStateful.StatusDelegate replayCallback = (double ratio) =>
56 | {
57 | this.Invoke((Action)delegate()
58 | {
59 | m_ReplayProgress.Value = (int)Math.Round(1000.0 * ratio);
60 | });
61 | };
62 |
63 | TreeBuilderBase tree_builder;
64 | tree_builder = new DeltaTreeBuilder(m_Trace, startTime, endTime, replayCallback, perspective, m_Options);
65 |
66 | this.Invoke((Action)delegate() { m_StripStatus.Text = "Building report tree.."; });
67 |
68 | var root = tree_builder.BuildReportTree();
69 |
70 | this.Invoke((Action)delegate()
71 | {
72 | OnTreeUpdated(root);
73 | });
74 | }
75 |
76 | private void OnTreeUpdated(MemTreeNode root)
77 | {
78 | m_HeapTree.SetRoot(root);
79 | m_StripStatus.Text = "Ready";
80 | m_ReplayProgress.Value = 0;
81 | m_RefreshButton.Enabled = true;
82 | m_StartTimeControl.Enabled = true;
83 | m_EndTimeControl.Enabled = true;
84 | }
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/tool/MemTraceTool/FragmentationWidget.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Drawing;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using System.Windows.Forms;
8 | using System.Diagnostics;
9 |
10 | namespace MemTraceTool
11 | {
12 | public interface IMemoryInfo
13 | {
14 | ulong MinAddress { get; }
15 | ulong MaxAddress { get; }
16 |
17 | void GetOccupancyMask(uint[] out_bits, ulong addr_lo, ulong addr_hi);
18 |
19 | void GetAllocationInfo(ulong address);
20 | }
21 |
22 | public partial class FragmentationWidget : UserControl, IDisposable
23 | {
24 | public IMemoryInfo MemoryInfo { get; set; }
25 |
26 | public int BytesPerPixelLog2 { get; set; }
27 |
28 | private Brush m_BackgroundBrush;
29 | private uint[] m_Buffer = new uint[1024];
30 |
31 | public FragmentationWidget()
32 | {
33 | m_BackgroundBrush = new SolidBrush(Color.DarkGray);
34 | InitializeComponent();
35 | }
36 |
37 | protected override void OnPaint(PaintEventArgs e)
38 | {
39 | var g = e.Graphics;
40 | Draw(g);
41 | }
42 |
43 | private Point AddressToPoint(ulong address)
44 | {
45 | var mem = MemoryInfo;
46 | if (null == mem)
47 | return new Point(0, 0);
48 |
49 | var sz = this.ClientSize;
50 | ulong w = (ulong) sz.Width;
51 | int bbp = BytesPerPixelLog2;
52 |
53 | ulong offset = (address - mem.MinAddress);
54 | int yoff = (int) ((offset >> bbp) / w);
55 | int xoff = (int) ((offset >> bbp) % w);
56 |
57 | return new Point(xoff, yoff);
58 | }
59 |
60 | private ulong PointToAddress(Point p)
61 | {
62 | var mem = MemoryInfo;
63 | var sz = this.ClientSize;
64 |
65 | if (mem == null || p.X < 0 || p.X >= sz.Width || p.Y <0 || p.Y >= sz.Height)
66 | return 0;
67 |
68 | int bbp = BytesPerPixelLog2;
69 | ulong x = (ulong) p.X;
70 | ulong y = (ulong) p.Y;
71 |
72 | ulong off = (x + y * (ulong)sz.Width) << bbp;
73 |
74 | return mem.MinAddress + off;
75 | }
76 |
77 | private void Draw(Graphics g)
78 | {
79 | var mem = MemoryInfo;
80 | var rect = g.ClipBounds;
81 | g.FillRectangle(m_BackgroundBrush, rect);
82 |
83 | if (null == mem)
84 | return;
85 |
86 | ulong start_addr = PointToAddress(new Point((int)rect.Left, (int)rect.Top));
87 | ulong end_addr = PointToAddress(new Point((int)rect.Right, (int)rect.Bottom));
88 |
89 | // Make sure the buffer is large enough.
90 | int bytes = (int)(end_addr - start_addr);
91 | int count = (bytes + 31) / 32;
92 | if (count > m_Buffer.Length)
93 | m_Buffer = new uint[count + 1024];
94 |
95 | mem.GetOccupancyMask(m_Buffer, start_addr, end_addr);
96 |
97 | for (ulong addr = start_addr; addr < end_addr; ++addr)
98 | {
99 |
100 | }
101 | }
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/tool/MemTraceTool/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.34014
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace MemTraceTool.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// Returns the cached ResourceManager instance used by this class.
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MemTraceTool.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// Overrides the current thread's CurrentUICulture property for all
51 | /// resource lookups using this strongly typed resource class.
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/tool/MemTraceWidgets/TimeControl.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Drawing;
5 | using System.Data;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 | using System.Windows.Forms;
10 |
11 | namespace MemTrace.Widgets
12 | {
13 | public partial class TimeControl : UserControl
14 | {
15 | public double MinTime { get; set; }
16 | public double MaxTime { get; set; }
17 |
18 | public string TimeLabel
19 | {
20 | get { return m_Label.Text; }
21 | set { m_Label.Text = value; }
22 | }
23 |
24 | public double CurrentTime
25 | {
26 | get; private set;
27 | }
28 |
29 | public delegate void TimeChangedDelegate(object sender, TimeChangedEvent e);
30 | public event TimeChangedDelegate TimeChanged;
31 |
32 | public sealed class Mark
33 | {
34 | public string Name;
35 | public double Time;
36 |
37 | public override string ToString()
38 | {
39 | return String.Format("{1:0.000}s ({0})", Name, Time);
40 | }
41 | }
42 |
43 | public void SetMarks(ICollection marks)
44 | {
45 | m_Time.Items.Clear();
46 | m_Time.Items.AddRange(marks.ToArray());
47 | }
48 |
49 | public TimeControl()
50 | {
51 | InitializeComponent();
52 | m_Time.Text = "0.000";
53 | }
54 |
55 | private void OnRev2Button_Click(object sender, EventArgs e)
56 | {
57 | CurrentTime = Math.Max(0, CurrentTime - 1.0);
58 | UpdateTime();
59 | }
60 |
61 | private void OnRev1Button_Click(object sender, EventArgs e)
62 | {
63 | CurrentTime = Math.Max(0, CurrentTime - 0.033);
64 | UpdateTime();
65 | }
66 |
67 | private void OnFwd1Button_Click(object sender, EventArgs e)
68 | {
69 | CurrentTime = Math.Min(MaxTime, CurrentTime + 0.033);
70 | UpdateTime();
71 | }
72 |
73 | private void OnFwd2Button_Click(object sender, EventArgs e)
74 | {
75 | CurrentTime = Math.Min(MaxTime, CurrentTime + 1.0);
76 | UpdateTime();
77 | }
78 |
79 | private void OnComboKeyDown(object sender, KeyEventArgs e)
80 | {
81 | if (e.KeyValue == (int) Keys.Enter || e.KeyValue == (int) Keys.Return)
82 | {
83 | try
84 | {
85 | CurrentTime = Double.Parse(m_Time.Text);
86 | }
87 | catch (Exception)
88 | {
89 | }
90 | UpdateTime();
91 | }
92 | }
93 |
94 | private void OnTimeValueSelected(object sender, EventArgs e)
95 | {
96 | var item = (Mark) m_Time.SelectedItem;
97 | CurrentTime = item.Time;
98 | UpdateTime();
99 | }
100 |
101 | private void UpdateTime()
102 | {
103 | var ev = new TimeChangedEvent { Time = CurrentTime };
104 | if (null != TimeChanged)
105 | {
106 | TimeChanged(this, ev);
107 | }
108 | CurrentTime = ev.Time;
109 | BeginInvoke(new Action(() => m_Time.Text = String.Format("{0:0.000}", CurrentTime)));
110 | }
111 | }
112 |
113 | public sealed class TimeChangedEvent
114 | {
115 | public double Time { get; set; }
116 | }
117 |
118 | }
119 |
--------------------------------------------------------------------------------
/tool/MemTraceWidgets/WidgetResources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.34014
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace MemTrace.Widgets {
12 | using System;
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class WidgetResources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal WidgetResources() {
33 | }
34 |
35 | ///
36 | /// Returns the cached ResourceManager instance used by this class.
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MemTrace.Widgets.WidgetResources", typeof(WidgetResources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// Overrides the current thread's CurrentUICulture property for all
51 | /// resource lookups using this strongly typed resource class.
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 |
63 | ///
64 | /// Looks up a localized resource of type System.Drawing.Bitmap.
65 | ///
66 | internal static System.Drawing.Bitmap dots {
67 | get {
68 | object obj = ResourceManager.GetObject("dots", resourceCulture);
69 | return ((System.Drawing.Bitmap)(obj));
70 | }
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/tool/MemTrace/TraceListener.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using System.Net;
7 | using System.Net.Sockets;
8 | using System.IO;
9 |
10 | namespace MemTrace
11 | {
12 | class TraceSession : IDisposable
13 | {
14 | public TraceRecorder Recorder { get; private set; }
15 | public Socket Socket { get; private set; }
16 |
17 | public TraceSession(ITraceFileHandler handler, Socket socket, string filename)
18 | {
19 | Socket = socket;
20 | Recorder = new TraceRecorder(handler, socket, filename);
21 | }
22 |
23 | ~TraceSession()
24 | {
25 | Dispose(false);
26 | }
27 |
28 | public void Dispose()
29 | {
30 | Dispose(true);
31 | }
32 |
33 | private void Dispose(bool disposing)
34 | {
35 | if (Recorder != null)
36 | {
37 | Recorder.Dispose();
38 | Recorder = null;
39 | }
40 | if (Socket != null)
41 | {
42 | Socket.Dispose();
43 | Socket = null;
44 | }
45 |
46 | if (disposing)
47 | {
48 | GC.SuppressFinalize(this);
49 | }
50 | }
51 | }
52 |
53 | // Sets up a TCP/IP end point for collecting traces.
54 | public class TraceListener : IDisposable
55 | {
56 | public string TraceDirectory { get; set; }
57 | public IPAddress BindAddress { get; set; }
58 | public int BindPort { get; set; }
59 |
60 | public ITraceFileHandler TraceFileHandler { get; private set; }
61 |
62 | private TcpListener m_Socket;
63 | private List m_Sessions = new List();
64 |
65 | public TraceListener(ITraceFileHandler handler)
66 | {
67 | TraceFileHandler = handler;
68 | BindAddress = IPAddress.Loopback;
69 | BindPort = 9811;
70 | }
71 |
72 | ~TraceListener()
73 | {
74 | Dispose(false);
75 | }
76 |
77 | public void Start()
78 | {
79 | if (String.IsNullOrEmpty(TraceDirectory))
80 | throw new ApplicationException("TraceDirectory is not valid");
81 |
82 | if (BindAddress == null)
83 | throw new ApplicationException("BindAddress is not valid");
84 |
85 | if (!Directory.Exists(TraceDirectory))
86 | {
87 | Directory.CreateDirectory(TraceDirectory);
88 | }
89 |
90 | m_Socket = new TcpListener(BindAddress, BindPort);
91 |
92 | m_Socket.Start();
93 |
94 | m_Socket.BeginAcceptSocket(OnIncomingConnection, null);
95 | }
96 |
97 | private void OnIncomingConnection(IAsyncResult ar)
98 | {
99 | if (m_Socket == null)
100 | return;
101 |
102 | Socket client = m_Socket.EndAcceptSocket(ar);
103 |
104 | // Pick a filename for this trace.
105 | string fn = String.Format("trace_{0}.mtrace", DateTime.Now.ToFileTimeUtc());
106 | string path = Path.Combine(TraceDirectory, fn);
107 |
108 | m_Sessions.Add(new TraceSession(TraceFileHandler, client, path));
109 |
110 | // Immediately accept a new client.
111 | m_Socket.BeginAcceptSocket(OnIncomingConnection, null);
112 | }
113 |
114 | public void Dispose()
115 | {
116 | Dispose(true);
117 | }
118 |
119 | private void Dispose(bool disposing)
120 | {
121 | if (m_Socket != null)
122 | {
123 | m_Socket.Stop();
124 | m_Socket = null;
125 | }
126 |
127 | if (disposing)
128 | {
129 | GC.SuppressFinalize(this);
130 | }
131 | }
132 | }
133 | }
134 |
--------------------------------------------------------------------------------
/tool/MemTraceWidgets/MemBlockView.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Drawing;
5 | using System.Data;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 | using System.Windows.Forms;
10 | using System.Drawing.Imaging;
11 |
12 | namespace MemTrace.Widgets
13 | {
14 | public partial class MemBlockView : UserControl
15 | {
16 | private List m_Allocs = null;
17 |
18 | private long m_LoAddress;
19 | private long m_HiAddress;
20 | private int[] m_Pixels = new int[256 * 256];
21 | private bool m_BitmapValid = false;
22 | private Bitmap m_Bitmap = new Bitmap(256, 256);
23 |
24 | public MemBlockView()
25 | {
26 | InitializeComponent();
27 | }
28 |
29 | ///
30 | /// Clean up any resources being used.
31 | ///
32 | /// true if managed resources should be disposed; otherwise, false.
33 | protected override void Dispose(bool disposing)
34 | {
35 | if (disposing && (components != null))
36 | {
37 | components.Dispose();
38 | }
39 | if (disposing && (m_Bitmap != null))
40 | {
41 | m_Bitmap.Dispose();
42 | }
43 | base.Dispose(disposing);
44 | }
45 |
46 |
47 | public void SetBlock(ulong start, ulong end, List allocs)
48 | {
49 | m_Allocs = allocs;
50 | m_LoAddress = (long) start;
51 | m_HiAddress = (long) end;
52 |
53 | m_BitmapValid = false;
54 | Invalidate();
55 | }
56 |
57 | protected override void OnPaintBackground(PaintEventArgs e)
58 | {
59 | if (DesignMode)
60 | {
61 | base.OnPaintBackground(e);
62 | }
63 | }
64 |
65 | protected override void OnPaint(PaintEventArgs ev)
66 | {
67 | base.OnPaint(ev);
68 |
69 | var g = ev.Graphics;
70 |
71 | var w = Width;
72 | var h = Height;
73 | var lo = m_LoAddress;
74 | var hi = m_HiAddress;
75 | var rng = hi - lo;
76 | double bytes_per_row = (double) rng / (double)w;
77 | double bytes_per_pixel = (double)w / bytes_per_row;
78 |
79 | if (m_Allocs == null)
80 | {
81 | g.Clear(BackColor);
82 | return;
83 | }
84 |
85 | if (!m_BitmapValid)
86 | {
87 | UpdateBitmap();
88 | }
89 |
90 | g.DrawImage(m_Bitmap, 0, 0);
91 |
92 | }
93 |
94 | private void UpdateBitmap()
95 | {
96 | var pixels = m_Pixels;
97 | var bg = BackColor.ToArgb();
98 |
99 | for (int i = 0; i < pixels.Length; ++i)
100 | {
101 | pixels[i] = bg;
102 | }
103 |
104 | foreach (var a in m_Allocs)
105 | {
106 | long s = (long) a.Alloc.Address - m_LoAddress;
107 | long e = s + (long) a.Alloc.SizeBytes;
108 |
109 | s = Math.Max(s, 0);
110 | e = Math.Min(e, 256 * 256);
111 |
112 | for (; s < e; ++s)
113 | {
114 | pixels[s] = a.Color.ToArgb();
115 | }
116 | }
117 |
118 | var bm = m_Bitmap;
119 | var rect = new Rectangle(0, 0, 256, 256);
120 |
121 | BitmapData data = null;
122 |
123 | try
124 | {
125 | data = bm.LockBits(rect, ImageLockMode.ReadWrite, bm.PixelFormat);
126 | System.Runtime.InteropServices.Marshal.Copy(pixels, 0, data.Scan0, Math.Abs(data.Stride) * bm.Height / 4);
127 | }
128 | finally
129 | {
130 | if (data != null)
131 | {
132 | bm.UnlockBits(data);
133 | }
134 | }
135 | }
136 | }
137 | }
138 |
--------------------------------------------------------------------------------
/tool/MemTrace/DbgHelpSymbolResolver.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 | using MemTrace;
7 | using System.IO;
8 |
9 | namespace MemTrace
10 | {
11 | public sealed class DbgHelpSymbolResolver : ISymbolResolver
12 | {
13 | public bool NeedsExePath { get { return false; } }
14 |
15 | public string ExeExtension { get { return ".exe"; } }
16 |
17 | public void BeginResolve(string ignored, ISymbolProgressListener listener, TraceReplayStateful replay, ICollection symbolPaths, ICollection remappings)
18 | {
19 | Task.Run(() =>
20 | {
21 | var result = new Dictionary();
22 | var metadata = replay.MetaData;
23 | var platform = metadata.PlatformName;
24 |
25 | using (var dbghelp = new DbgHelp(symbolPaths))
26 | {
27 | for (int i = 0, count = metadata.Modules.Count; i < count; ++i)
28 | {
29 | var mod = metadata.Modules[i];
30 |
31 | listener.UpdateProgress(String.Format("Loading module {0}/{1}..", i + 1, count), (i + 1) / (double)count);
32 |
33 | // TEMP! Ignore empty module from Durango.
34 | if (mod.Name == "")
35 | continue;
36 |
37 | var fn = mod.Name;
38 | foreach (var rm in remappings)
39 | {
40 | if (0 != StringComparer.InvariantCultureIgnoreCase.Compare(rm.Platform, platform))
41 | continue;
42 |
43 | if (fn.ToLower().StartsWith(rm.Path.ToLower()))
44 | {
45 | var oldfn = fn;
46 | fn = rm.ReplacementPath + fn.Substring(rm.Path.Length);
47 | listener.UpdateMessage(String.Format("Remapped {0} -> {1}", oldfn, fn));
48 | }
49 | }
50 |
51 | listener.UpdateMessage(String.Format("Loading {0} at {1:x16}, size={2:n0} bytes", fn, mod.BaseAddress, mod.SizeBytes));
52 | dbghelp.LoadModule(fn, mod.BaseAddress, mod.SizeBytes);
53 | }
54 |
55 | int x = 0;
56 | foreach (ulong address in metadata.Symbols)
57 | {
58 | if (x % 100 == 0)
59 | {
60 | listener.UpdateProgress(String.Format("Resolving symbol {0}/{1}..", x + 1, metadata.Symbols.Count), (x + 1) / (double)metadata.Symbols.Count);
61 | }
62 |
63 | SymbolInfo sym;
64 | if (dbghelp.LookupSymbol(address, out sym))
65 | {
66 | result[address] = sym;
67 | }
68 | else
69 | {
70 | sym.Symbol = "(unknown)";
71 | foreach (var mod in metadata.Modules)
72 | {
73 | if (address >= mod.BaseAddress && address <= mod.BaseAddress + mod.SizeBytes)
74 | {
75 | sym.Symbol = String.Format("{0}!0x{1:x16}", Path.GetFileNameWithoutExtension(mod.Name), address);
76 | result[address] = sym;
77 | break;
78 | }
79 | }
80 | //UpdateMessage(String.Format("Failed to resolve address {0:x}\n", address));
81 | }
82 |
83 | ++x;
84 | }
85 | }
86 |
87 | listener.UpdateProgress("Saving..", 1.0);
88 | listener.UpdateMessage("Writing resolved symbols back to trace file");
89 |
90 | replay.UpdateResolvedSymbols(result);
91 |
92 | listener.UpdateProgress("Done", 1.0);
93 | listener.UpdateMessage("Finished!");
94 |
95 | listener.Done();
96 | });
97 | }
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/runtime/MemTrace.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015, Insomniac Games All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions are met:
6 |
7 | Redistributions of source code must retain the above copyright notice, this
8 | list of conditions and the following disclaimer.
9 |
10 | Redistributions in binary form must reproduce the above copyright notice, this
11 | list of conditions and the following disclaimer in the documentation and/or
12 | other materials provided with the distribution.
13 |
14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 | */
25 |
26 | #pragma once
27 |
28 | #include
29 | #include
30 |
31 | // You can control this with a build macro if desired to compile MemTrace out.
32 | #define MEMTRACE_ENABLE 1
33 |
34 | namespace MemTrace
35 | {
36 | typedef uint32_t HeapId;
37 |
38 | enum ScopeKind
39 | {
40 | kScopeNone,
41 | kScopeAsset,
42 | kScopeComponent
43 | };
44 |
45 | #if MEMTRACE_ENABLE
46 |
47 | // Get connection parameters specified on the command line, if any (returns true)
48 | // Useful to forward memtrace configuration along to spawned child processes.
49 | bool GetSocketData(char (&ip_addr_out)[128], int* port_out);
50 |
51 | void InitFile(const char *trace_temp_file);
52 |
53 | void InitSocket(const char *server_ip_address, int server_port);
54 |
55 | void Shutdown();
56 |
57 | void UserMark(const char* label, ...);
58 |
59 | void Flush();
60 |
61 | void AddressAllocate(const void* base, size_t size_bytes, const char* name);
62 | void AddressFree(const void* base);
63 |
64 | void VirtualCommit(const void* base, size_t size_bytes);
65 | void VirtualDecommit(const void* base, size_t size_bytes);
66 |
67 | HeapId HeapCreate(const char* name);
68 | void HeapDestroy(HeapId heap_id);
69 | void HeapAddCore(HeapId heap_id, const void* base, size_t size_bytes);
70 | void HeapRemoveCore(HeapId heap_id, const void* base, size_t size_bytes);
71 | void HeapAllocate(HeapId heap_id, const void* ptr, size_t size_bytes);
72 | void HeapReallocate(HeapId heap_id, const void* ptr_in, const void* ptr_out, size_t new_size_bytes);
73 | void HeapFree(HeapId heap_id, const void* ptr);
74 |
75 | void PushScope(ScopeKind kind, const char* str, ScopeKind* old_kind, const char** old_str);
76 | void RestoreScope(ScopeKind kind, const char* str);
77 |
78 | class ScopeHelper
79 | {
80 | ScopeKind m_Kind;
81 | const char *m_String;
82 |
83 | public:
84 | ScopeHelper(ScopeKind kind, const char* str)
85 | {
86 | PushScope(kind, str, &m_Kind, &m_String);
87 | }
88 |
89 | ~ScopeHelper()
90 | {
91 | RestoreScope(m_Kind, m_String);
92 | }
93 | private:
94 | ScopeHelper(const ScopeHelper&);
95 | ScopeHelper& operator=(const ScopeHelper&);
96 | };
97 |
98 | void DummyInitFunction(char dummy);
99 |
100 | #define MEMTRACE_SCOPE(kind, text) \
101 | ::MemTrace::ScopeHelper memtrace_scope_(kind, text)
102 |
103 | #else
104 |
105 | #define MEMTRACE_SCOPE(kind, text) \
106 | do {} while(0)
107 |
108 | #endif
109 |
110 | }
111 |
--------------------------------------------------------------------------------
/tool/MemTraceTool/SymbolResolveDialog.Designer.cs:
--------------------------------------------------------------------------------
1 | namespace MemTraceTool
2 | {
3 | partial class SymbolResolveDialog
4 | {
5 | ///
6 | /// Required designer variable.
7 | ///
8 | private System.ComponentModel.IContainer components = null;
9 |
10 | ///
11 | /// Clean up any resources being used.
12 | ///
13 | /// true if managed resources should be disposed; otherwise, false.
14 | protected override void Dispose(bool disposing)
15 | {
16 | if (disposing && (components != null))
17 | {
18 | components.Dispose();
19 | }
20 | base.Dispose(disposing);
21 | }
22 |
23 | #region Windows Form Designer generated code
24 |
25 | ///
26 | /// Required method for Designer support - do not modify
27 | /// the contents of this method with the code editor.
28 | ///
29 | private void InitializeComponent()
30 | {
31 | System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SymbolResolveDialog));
32 | this.m_LogText = new System.Windows.Forms.TextBox();
33 | this.m_ProgressBar = new System.Windows.Forms.ProgressBar();
34 | this.m_StatusLabel = new System.Windows.Forms.Label();
35 | this.SuspendLayout();
36 | //
37 | // m_LogText
38 | //
39 | this.m_LogText.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
40 | | System.Windows.Forms.AnchorStyles.Left)
41 | | System.Windows.Forms.AnchorStyles.Right)));
42 | this.m_LogText.Location = new System.Drawing.Point(10, 58);
43 | this.m_LogText.MaxLength = 128000;
44 | this.m_LogText.Multiline = true;
45 | this.m_LogText.Name = "m_LogText";
46 | this.m_LogText.ReadOnly = true;
47 | this.m_LogText.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
48 | this.m_LogText.Size = new System.Drawing.Size(606, 354);
49 | this.m_LogText.TabIndex = 0;
50 | //
51 | // m_ProgressBar
52 | //
53 | this.m_ProgressBar.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
54 | | System.Windows.Forms.AnchorStyles.Right)));
55 | this.m_ProgressBar.Location = new System.Drawing.Point(10, 29);
56 | this.m_ProgressBar.Maximum = 1000;
57 | this.m_ProgressBar.Name = "m_ProgressBar";
58 | this.m_ProgressBar.Size = new System.Drawing.Size(605, 23);
59 | this.m_ProgressBar.TabIndex = 1;
60 | //
61 | // m_StatusLabel
62 | //
63 | this.m_StatusLabel.AutoSize = true;
64 | this.m_StatusLabel.Location = new System.Drawing.Point(9, 13);
65 | this.m_StatusLabel.Name = "m_StatusLabel";
66 | this.m_StatusLabel.Size = new System.Drawing.Size(37, 13);
67 | this.m_StatusLabel.TabIndex = 2;
68 | this.m_StatusLabel.Text = "Status";
69 | //
70 | // SymbolResolveDialog
71 | //
72 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
73 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
74 | this.ClientSize = new System.Drawing.Size(627, 422);
75 | this.Controls.Add(this.m_StatusLabel);
76 | this.Controls.Add(this.m_ProgressBar);
77 | this.Controls.Add(this.m_LogText);
78 | this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
79 | this.Name = "SymbolResolveDialog";
80 | this.Text = "Resolving Symbols..";
81 | this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.OnFormClosing);
82 | this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.OnFormClosed);
83 | this.Shown += new System.EventHandler(this.OnFormShown);
84 | this.ResumeLayout(false);
85 | this.PerformLayout();
86 |
87 | }
88 |
89 | #endregion
90 |
91 | private System.Windows.Forms.TextBox m_LogText;
92 | private System.Windows.Forms.ProgressBar m_ProgressBar;
93 | private System.Windows.Forms.Label m_StatusLabel;
94 | }
95 | }
--------------------------------------------------------------------------------
/tool/MemTraceTool/SymbolResolveDialog.cs:
--------------------------------------------------------------------------------
1 | using MemTrace;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.ComponentModel;
5 | using System.Diagnostics;
6 | using System.Drawing;
7 | using System.IO;
8 | using System.Linq;
9 | using System.Text;
10 | using System.Threading.Tasks;
11 | using System.Windows.Forms;
12 |
13 | namespace MemTraceTool
14 | {
15 | public partial class SymbolResolveDialog : Form, ISymbolProgressListener
16 | {
17 | private TraceListItem m_Item;
18 | private TraceReplayStateful m_Replay;
19 | private Options m_Options;
20 | private volatile bool m_Done;
21 |
22 | internal SymbolResolveDialog(TraceListItem trace, Options options)
23 | {
24 | InitializeComponent();
25 |
26 | m_Options = options;
27 | m_Item = trace;
28 | m_Replay = new TraceReplayStateful(trace.FileName);
29 |
30 | }
31 |
32 | private ISymbolResolver CreateResolver(TraceReplayStateful m_Replay)
33 | {
34 | var platformName = m_Replay.MetaData.PlatformName;
35 | switch (platformName)
36 | {
37 | case "Windows":
38 | case "Durango":
39 | return new DbgHelpSymbolResolver();
40 |
41 | case "Orbis":
42 | return new OrbisSymbolResolver();
43 |
44 | default:
45 | return null;
46 | }
47 | }
48 |
49 | private List m_LogLines = new List();
50 |
51 | private void OnFormClosed(object sender, FormClosedEventArgs e)
52 | {
53 | m_Replay.Dispose();
54 | }
55 |
56 | private void OnFormClosing(object sender, FormClosingEventArgs e)
57 | {
58 | if (!m_Done)
59 | {
60 | e.Cancel = true;
61 | return;
62 | }
63 | }
64 |
65 | public TraceMeta UpdatedMeta { get { return m_Replay.MetaData; } }
66 |
67 | public void UpdateProgress(string status, double pct)
68 | {
69 | this.Invoke((Action)delegate() {
70 | m_ProgressBar.Value = (int) Math.Round(pct * m_ProgressBar.Maximum);
71 | m_StatusLabel.Text = status;
72 | });
73 | }
74 |
75 | public void UpdateMessage(string status, params object[] args)
76 | {
77 | this.Invoke((Action)delegate() {
78 | m_LogLines.Add(String.Format(status, args));
79 | m_LogText.Lines = m_LogLines.ToArray();
80 | m_LogText.SelectionStart = m_LogText.Text.Length;
81 | m_LogText.ScrollToCaret();
82 | m_LogText.Refresh();
83 | });
84 | }
85 |
86 | public void Done()
87 | {
88 | m_Done = true;
89 | UpdateProgress("Done", 1.0);
90 | }
91 |
92 |
93 | public void UpdateError(string p)
94 | {
95 | UpdateMessage("ERROR: " + p);
96 | Done();
97 | }
98 |
99 | private void OnFormShown(object sender, EventArgs e)
100 | {
101 | ISymbolResolver resolver = CreateResolver(m_Replay);
102 | if (resolver != null)
103 | {
104 | if (resolver.NeedsExePath)
105 | {
106 | using (var fd = new OpenFileDialog())
107 | {
108 | fd.Title = "Select Executable File";
109 | fd.CheckFileExists = true;
110 | var ext = resolver.ExeExtension;
111 | fd.Filter = "Executable Files (*" + ext + ")|*" + ext + "|All files(*.*)|*.*";
112 |
113 | switch (fd.ShowDialog())
114 | {
115 | case DialogResult.OK:
116 | resolver.BeginResolve(fd.FileName, this, m_Replay, m_Options.SymbolPaths, m_Options.ModulePathRemappings);
117 | break;
118 | default:
119 | m_Done = true;
120 | this.Close();
121 | break;
122 | }
123 | }
124 | }
125 | else
126 | {
127 | resolver.BeginResolve(null, this, m_Replay, m_Options.SymbolPaths, m_Options.ModulePathRemappings);
128 | }
129 | }
130 | else
131 | {
132 | MessageBox.Show("Sorry, don't know how to resolve symbols for this platform yet");
133 | m_Done = true;
134 | }
135 | }
136 | }
137 | }
138 |
--------------------------------------------------------------------------------
/tool/MemTrace/MemTrace.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {2E43CDC0-AC81-4172-85E7-4126EED64656}
8 | Library
9 | Properties
10 | MemTrace
11 | MemTrace
12 | v4.5.1
13 | 512
14 |
15 |
16 |
17 | true
18 | bin\x64\Debug\
19 | DEBUG;TRACE
20 | full
21 | x64
22 | prompt
23 | MinimumRecommendedRules.ruleset
24 | false
25 |
26 |
27 | bin\x64\Release\
28 | TRACE
29 | true
30 | pdbonly
31 | x64
32 | prompt
33 | MinimumRecommendedRules.ruleset
34 | false
35 |
36 |
37 | true
38 | bin\Debug\
39 | DEBUG;TRACE
40 | full
41 | AnyCPU
42 | prompt
43 | MinimumRecommendedRules.ruleset
44 | false
45 |
46 |
47 | bin\Release\
48 | TRACE
49 | true
50 | pdbonly
51 | AnyCPU
52 | prompt
53 | MinimumRecommendedRules.ruleset
54 | false
55 |
56 |
57 |
58 | ..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll
59 |
60 |
61 | ..\packages\ObjectListView.2.7.1\lib\ObjectListView.dll
62 |
63 |
64 | ..\packages\ObjectListView.2.7.1\lib\SparkleLibrary.dll
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
94 |
--------------------------------------------------------------------------------
/runtime/DemoMain.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2015, Insomniac Games All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without
5 | modification, are permitted provided that the following conditions are met:
6 |
7 | Redistributions of source code must retain the above copyright notice, this
8 | list of conditions and the following disclaimer.
9 |
10 | Redistributions in binary form must reproduce the above copyright notice, this
11 | list of conditions and the following disclaimer in the documentation and/or
12 | other materials provided with the distribution.
13 |
14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
18 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 | */
25 |
26 | #include "MemTrace.h"
27 | #include "MemTraceInit.h"
28 |
29 | #include
30 | #include
31 | #include