public void Awake() { screenRect = new Rect(0f, 0f, Screen.width, Screen.height); if(instance == null) { instance = this; } else { Destroy(this); } DontDestroyOnLoad(gameObject); // Setup Custom GUI Windows toggleWindow = new ToggleWindow(this); toggleWindow.isVisible = true; profilerWindow = new SummaryWindow(this, listResourceGroups); detailsWindow = new DetailsWindow(this, "Memory Details"); // Setup the resources groups that you want to have in the profiler at run-time listResourceGroups.Add( new ProfilerResourcesGroup<Texture>() ); listResourceGroups.Add( new ProfilerResourcesGroup<AudioClip>() ); listResourceGroups.Add( new ProfilerResourcesGroup<Mesh>() ); listResourceGroups.Add( new ProfilerResourcesGroup<Material>() ); listResourceGroups.Add( new ProfilerResourcesGroup<GameObject>() ); }
/// <summary> /// MemoryProfiler.TakeSnapshotを実行する /// </summary> /// <param name="fname">snapshotのファイル名</param> public void TakeSnapshot(string fname) { isDone = false; var path = string.Format("{0}/{1}.snap", Application.temporaryCachePath, fname); MemoryProfiler.TakeSnapshot(path, FinishCB, ScreenshotCallback); }
public void RunMemoryProfile(bool full = true) { if (runningMemoryProfile || runningProfile) { return; } runningMemoryProfile = true; UpdateManager.Instance.Profile = true; Directory.CreateDirectory("Profiles"); if (full) { MemoryProfiler.TakeSnapshot($"Profiles/FullMemoryProfile{DateTime.Now:yyyy-MM-dd HH-mm-ss}.snap", MemoryProfileEnd, CaptureFlags.ManagedObjects | CaptureFlags.NativeAllocations | CaptureFlags.NativeObjects | CaptureFlags.NativeAllocationSites | CaptureFlags.NativeStackTraces); return; } MemoryProfiler.TakeSnapshot($"Profiles/ManagedMemoryProfile{DateTime.Now:yyyy-MM-dd HH-mm-ss}.snap", MemoryProfileEnd, CaptureFlags.ManagedObjects | CaptureFlags.NativeAllocations | CaptureFlags.NativeAllocationSites | CaptureFlags.NativeStackTraces); }
private Tuple <long, long, long> GpHashTableSize() { // Enable collecting memory allocation data. // Check IsActive only once. Do nothing // (do not throw exceptions, etc.) if IsActive is false if (MemoryProfiler.IsActive && MemoryProfiler.CanControlAllocations) { MemoryProfiler.EnableAllocations(); } // Here goes your code to profile var table = Frame.Gp.ToHashMap(); MemoryProfiler.Dump(); var tableSize = table.SizeInBytes(); var mvCount = table.TargetMultivectorsCount; var termsCount = table.TargetMultivectorTermsCount; return(new Tuple <long, long, long>( tableSize, mvCount, termsCount )); }
public static void native(ConsoleSystem.Arg arg) { string str = MemSnap.NeedProfileFolder(); DateTime now = DateTime.Now; MemoryProfiler.TakeSnapshot(string.Concat(str, "/memdump-", now.ToString("MM-dd-yyyy-h-mm-ss"), ".snap"), null, CaptureFlags.NativeObjects); }
public ToggleWindow(MemoryProfiler _parent) { windowId = this.GetInstanceID(); windowDrawHandler = DrawWindowOverride; screenRect = new Rect(0f, 0f, Screen.width, Screen.height); parent = _parent; }
static async Task Main(string[] args) { MemoryProfiler.CollectAllocations(true); MemoryProfiler.ForceGc(); const int iterationCount = 20; foreach (var kernelName in new [] { "csharp", "fsharp" }) { for (int i = 0; i < iterationCount; i++) { MemoryProfiler.GetSnapshot($"Before {kernelName} Kernel creation at Iteration {i}"); MemoryProfiler.ForceGc(); var kernel = CreateKernel(kernelName); MemoryProfiler.ForceGc(); MemoryProfiler.GetSnapshot($"Before {kernelName} Iteration {i}"); var submitCode = CreateSubmitCode(kernelName); await kernel.SendAsync(submitCode); MemoryProfiler.GetSnapshot($"After {kernelName} Iteration {i}"); kernel.Dispose(); kernel = null; MemoryProfiler.ForceGc(); } } }
public void Awake() { screenRect = new Rect(0f, 0f, Screen.width, Screen.height); if (instance == null) { instance = this; } else { Destroy(this); } DontDestroyOnLoad(gameObject); // Setup Custom GUI Windows toggleWindow = new ToggleWindow(this); toggleWindow.isVisible = true; profilerWindow = new SummaryWindow(this, listResourceGroups); detailsWindow = new DetailsWindow(this, "Memory Details"); // Setup the resources groups that you want to have in the profiler at run-time listResourceGroups.Add(new ProfilerResourcesGroup <Texture>()); listResourceGroups.Add(new ProfilerResourcesGroup <AudioClip>()); listResourceGroups.Add(new ProfilerResourcesGroup <Mesh>()); listResourceGroups.Add(new ProfilerResourcesGroup <Material>()); listResourceGroups.Add(new ProfilerResourcesGroup <GameObject>()); }
private static void SemaphoreGCExtremePressureBlocking() { const int NumberOfAllocations = 50000000; // Variable declarations outside of block scope in case there are compiler optimizations // that will dispose these variables when leaving block scope. CancellationTokenSource tokenSource; SemaphoreSlim semaphore; if (MemoryProfiler.IsActive) { MemoryProfiler.Dump(); } for (int i = 0; i < NumberOfAllocations; ++i) { tokenSource = new CancellationTokenSource(); semaphore = new SemaphoreSlim(1); semaphore.Wait(tokenSource.Token); semaphore.Release(); if (i % 10000 == 0) { Console.WriteLine(i); } } if (MemoryProfiler.IsActive) { MemoryProfiler.Dump(); } Console.WriteLine("Allocated {0} number of Semaphores and CancellationTokenSources", NumberOfAllocations); }
public static void Func() { // System.Type t = Types.GetType("Unity.MemoryProfiler.Editor", "Unity.MemoryProfiler.Editor.dll"); //var assembly = Assembly.Load("Unity.MemoryProfiler.Editor"); //var type = assembly.GetType("Unity.MemoryProfiler.Editor.MemoryProfilerWindow"); #if false var memoryProfilerWindow = type.InvokeMember( null , BindingFlags.CreateInstance , null , null , new object[] { } ); var methodInfo = type.GetMethod("TakeCapture", BindingFlags.NonPublic | BindingFlags.Instance); methodInfo.Invoke(memoryProfilerWindow, null); #endif //var window = EditorWindow.GetWindow(type); //var methodInfo = type.GetMethod("TakeCapture", BindingFlags.NonPublic | BindingFlags.Instance); //var methodInfo = type.GetMethod("DelayedSnapshotRoutine", BindingFlags.NonPublic | BindingFlags.Instance); // methodInfo.Invoke(window, null); // Debug.Log(window); var now = System.DateTime.Now; string fpath = System.IO.Directory.GetCurrentDirectory() + "/Temp/" + now.ToString("yyyyMMddHHmmss") + ".snap"; MemoryProfiler.TakeSnapshot(fpath, FinishCB, ScreenshotCallback); }
public MemoryProfile(string sdkPath, string resultsDirectory) : base(resultsDirectory) { var saveSnapshotProfilingConfig = new SaveSnapshotProfilingConfig { ProfilingControlKind = ProfilingControlKind.Api, TempDir = Path.GetTempPath(), SaveDir = resultsDirectory, RedistDir = sdkPath, ProfilingType = ProfilingType.Memory, ListFile = this.ListFile }; while (SelfAttach.State != SelfApiState.None) { Thread.Sleep(250); } SelfAttach.Attach(saveSnapshotProfilingConfig); this.WaitForProfilerToAttachToProcess(); if (MemoryProfiler.IsActive && MemoryProfiler.CanControlAllocations) { MemoryProfiler.EnableAllocations(); } }
static async Task Main( Operation operation, int iterationCount = 20, string kernelName = "csharp") { MemoryProfiler.CollectAllocations(true); MemoryProfiler.ForceGc(); for (var i = 0; i < iterationCount; i++) { MemoryProfiler.GetSnapshot($"Before {kernelName} Kernel creation at Iteration {i}"); MemoryProfiler.ForceGc(); using var kernel = await CreateKernel( operation, kernelName); MemoryProfiler.ForceGc(); MemoryProfiler.GetSnapshot($"Before {kernelName} Iteration {i}"); await RunProfiledOperation(operation, kernel); MemoryProfiler.GetSnapshot($"After {kernelName} Iteration {i}"); kernel.Dispose(); MemoryProfiler.ForceGc(); } }
public static void GetSnapshot() { #if PROFILE AssertProfilerIsConnected(); MemoryProfiler.Dump(); #endif }
private void TimerOnElapsed(object sender, EventArgs args) { if (MemoryProfiler.IsActive) { if (_numSwitches % DumpEverySwitchCount == 0) { MemoryProfiler.Dump(); } } _numSwitches++; for (int i = 0; i < MaxVideos; ++i) { var indexCell = (_indexCell + i) % _cells.Count; var indexFile = (_indexFile + i) % _files.Length; StopVideo(indexCell, indexFile); } _indexCell = (_indexCell + MaxVideos) % _cells.Count; _indexFile = (_indexFile + MaxVideos) % _files.Length; for (int i = 0; i < MaxVideos; ++i) { var indexCell = (_indexCell + i) % _cells.Count; var indexFile = (_indexFile + i) % _files.Length; PlayVideo(indexCell, indexFile); } }
private static void testRegexMatches(string input, string pattern, RegexOptions options, int times) { Console.WriteLine("Pattern: {0}", pattern.ShowVerbatim()); if (options != RegexOptions.None) { Console.WriteLine("Options: [{0}]", options.ToString()); } MemoryProfiler memoryProfiler; if (useMemoryProfiler) { memoryProfiler = MemoryProfiler.StartNew(); } Stopwatch stopwatch = Stopwatch.StartNew(); MatchCollection2 matches = null; //Msoft.MatchCollection matches = null; for (int i = 0; i < times; i++) { matches = new Regex2(pattern, AlgorithmType.Backtracking, options).Matches(input); } //matches = new Msoft.Regex(pattern, RegexAssert.ToMsoftRegexOptions(options)).Matches(input); if (useMemoryProfiler) { memoryProfiler.Reset(); } Console.WriteLine("Matches: {0:#,##0}", matches.Count); //string v; //foreach (var m in matches.Cast<Match2>()) ////foreach (var m in matches.Cast<Msoft.Match>()) // v = m.Value; decimal elapsed = ((decimal)stopwatch.ElapsedMilliseconds) / 1000; if (useMemoryProfiler) { long deltaBefore = memoryProfiler.DeltaValue; memoryProfiler.CollectGC(); long deltaAfter = memoryProfiler.DeltaValue; if (matches.Count > 0) { Console.WriteLine("Last: {0:#,##0} chars", matches[matches.Count - 1].Value.Length); } Console.WriteLine("Memory: {0,10:#,##0} bytes", deltaBefore); Console.WriteLine("AfterGC: {0,10:#,##0} bytes", deltaAfter); } Console.WriteLine("Time: {0:#0.000} sec.\n", elapsed); }
public SummaryWindow(MemoryProfiler _parent, List<IProfilerResourcesGroup> _listResourceGroups) { windowId = this.GetInstanceID(); windowDrawHandler = DrawWindowOverride; screenRect = new Rect(0f, 0f, Screen.width, Screen.height); parent = _parent; listResourceGroups = _listResourceGroups; }
public DetailsWindow(MemoryProfiler _parent, string windowTitle) { windowId = this.GetInstanceID(); windowDrawHandler = DrawWindowOverride; screenRect = new Rect(0f, 0f, Screen.width, Screen.height); parent = _parent; title = windowTitle; }
public static void MatchCollections() { MemoryProfiler memoryProfiler = MemoryProfiler.StartNew(); int itemCount = 10000000; MatchCollection2 matches1 = Factory.CreateMatchCollection(Enumerable.Range(1, itemCount) .Select(i => Factory.CreateMatch(i, i, "x"))); memoryProfiler.CollectGC(); Console.WriteLine("Matches: {0:#,##0}", matches1.Count); displayMemoryProfiler(memoryProfiler, itemCount); // 41 bytes/match (itemCount = 10,000,000) // 36.9 bytes/match (itemCount = 13,000,000) memoryProfiler.Reset(); Match2[] matches2 = Enumerable.Range(1, itemCount) .Select(i => Factory.CreateMatch(i, i, "x")) .ToArray(); memoryProfiler.CollectGC(); Console.WriteLine("Matches: {0:#,##0}", matches2.Length); displayMemoryProfiler(memoryProfiler, itemCount); // 36 bytes/match (itemCount = 10,000,000) // 36 bytes/match (itemCount = 13,000,000) memoryProfiler.Reset(); List <Match2> matches3 = Enumerable.Range(1, itemCount) .Select(i => Factory.CreateMatch(i, i, "x")) .ToList(); memoryProfiler.CollectGC(); Console.WriteLine("Matches: {0:#,##0}", matches3.Count); displayMemoryProfiler(memoryProfiler, itemCount); // 38.7 bytes/match (itemCount = 10,000,000) // 37.2 bytes/match (itemCount = 13,000,000) memoryProfiler.Reset(); List <int> ints1 = Enumerable.Range(1, itemCount) .ToList(); memoryProfiler.CollectGC(); Console.WriteLine("Ints: {0:#,##0}", ints1.Count); displayMemoryProfiler(memoryProfiler, itemCount); // 6.7 bytes/match (itemCount = 10,000,000) // 5.2 bytes/match (itemCount = 13,000,000) memoryProfiler.Reset(); int[] ints2 = Enumerable.Range(1, itemCount) .ToArray(); memoryProfiler.CollectGC(); Console.WriteLine("Ints: {0:#,##0}", ints2.Length); displayMemoryProfiler(memoryProfiler, itemCount); // 4 bytes/match (itemCount = 10,000,000) // 4 bytes/match (itemCount = 13,000,000) }
// Token: 0x06007EE0 RID: 32480 public MemoryProfiler.ObjectContentInfo GetContentInfo() { if (!this.contentLoaded) { this.contentInfo = MemoryProfiler.buildContentInfo(this.instance); this.contentLoaded = true; } return(this.contentInfo); }
public SummaryWindow(MemoryProfiler _parent, List <IProfilerResourcesGroup> _listResourceGroups) { windowId = this.GetInstanceID(); windowDrawHandler = DrawWindowOverride; screenRect = new Rect(0f, 0f, Screen.width, Screen.height); parent = _parent; listResourceGroups = _listResourceGroups; }
public MainWindow() { InitializeComponent(); _cells.Add(Cell00); _cells.Add(Cell01); _cells.Add(Cell02); _cells.Add(Cell03); _cells.Add(Cell04); _cells.Add(Cell10); _cells.Add(Cell11); _cells.Add(Cell12); _cells.Add(Cell13); _cells.Add(Cell14); _cells.Add(Cell20); _cells.Add(Cell21); _cells.Add(Cell22); _cells.Add(Cell23); _cells.Add(Cell24); _cells.Add(Cell30); _cells.Add(Cell31); _cells.Add(Cell32); _cells.Add(Cell33); _cells.Add(Cell34); _cells.Add(Cell40); _cells.Add(Cell41); _cells.Add(Cell42); _cells.Add(Cell43); _cells.Add(Cell44); _wrappers = new MediaElementWrapper[_cells.Count]; _files = Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\Videos\\IliaSequencer"); _sizes = new long[_files.Length]; for (var i = 0; i < _files.Length; ++i) { var fileInfo = new FileInfo(_files[i]); _sizes[i] = fileInfo.Length; } _timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(SwitchTimeMilliseconds) }; _timer.Tick += TimerOnElapsed; if (MemoryProfiler.IsActive && MemoryProfiler.CanControlAllocations) { MemoryProfiler.EnableAllocations(); } _timer.Start(); TimerOnElapsed(this, EventArgs.Empty); }
private static Session RunConsole(string command, Config config) { Trace.Verbose("DotMemory.RunConsole: Looking for runner..."); var runnerPath = ConsoleRunnerPackage.GetRunnerPath(); var workspaceFile = GetSaveToFilePath(config); var commandLine = new StringBuilder(); if (config.LogLevel != null) { commandLine.Append($"--log-level={config.LogLevel} "); } if (config.LogFile != null) { commandLine.Append($"\"--log-file={config.LogFile}\" "); } commandLine.Append($"{command} {Process.GetCurrentProcess().Id} \"-f={workspaceFile}\""); if (config.IsOverwriteWorkspace) { commandLine.Append(" --overwrite"); } if (config.IsOpenDotMemory) { commandLine.Append(" --open-dotmemory"); } if (command != "get-snapshot") { commandLine.Append(" --use-api"); } if (config.OtherArguments != null) { commandLine.Append(' ').Append(config.OtherArguments); } Trace.Info("DotMemory.RunConsole:\n runner = `{0}`\n arguments = `{1}`", runnerPath, commandLine); var consoleProfiler = new ConsoleProfiler( runnerPath, commandLine.ToString(), MessageServicePrefix, CltPresentableName, () => (MemoryProfiler.GetFeatures() & MemoryFeatures.Ready) == MemoryFeatures.Ready ); Trace.Verbose("DotMemory.RunConsole: Runner started."); return(new Session(consoleProfiler, workspaceFile)); }
public static void DisableAllocations() { #if PROFILE AssertProfilerIsConnected(); if (!MemoryProfiler.CanControlAllocations) { throw new InvalidOperationException(); } MemoryProfiler.DisableAllocations(); #endif }
// Token: 0x06007E13 RID: 32275 private static MemoryProfiler.ObjectContentInfo buildContentInfo(object instance) { if (instance == null) { return(null); } Debug.LogWarning("building contentInfo for object: " + instance.ToString()); List <object> objectHistory = new List <object>(); return(new MemoryProfiler.ObjectContentInfo(instance.GetType().Name, "", instance.ToString()) { contentInfo = MemoryProfiler.buildContentInfoRecursive(instance, 0, objectHistory) }); }
static void Main(string[] args) { MemoryProfiler.CollectAllocations(true); MemoryProfiler.GetSnapshot(); var arrayOfValues = new[] { 10, 20, 30, 40, 50 }; var thing = new SomeClass(arrayOfValues, "FiveValues"); var total = thing.GetTotal(); MemoryProfiler.GetSnapshot(); }
private static async Task SemaphoreGCTricklePressure() { const int AllocationsPerSecond = 1000; const int MinutesToRun = 10; long allocated = 0; // Variable declarations outside of block scope in case there are compiler optimizations // that will dispose these variables when leaving block scope. CancellationTokenSource tokenSource; SemaphoreSlim semaphore; DateTime endTime = DateTime.Now.AddMinutes(MinutesToRun); if (MemoryProfiler.IsActive) { MemoryProfiler.Dump(); } while (true) { tokenSource = new CancellationTokenSource(); semaphore = new SemaphoreSlim(1); await semaphore.WaitAsync(tokenSource.Token); semaphore.Release(); // Delay before creating next sempahore. await Task.Delay(1000 / AllocationsPerSecond, tokenSource.Token); // Do not Dispose CancellationTokenSource or Semaphore. Let this leak and see how many // sempaphores are required to make this crash. allocated++; if (endTime < DateTime.Now) { break; } } if (MemoryProfiler.IsActive) { MemoryProfiler.Dump(); } Console.WriteLine("Allocated {0} number of Semaphores and CancellationTokenSources", allocated); Console.WriteLine("Excuted for {0} minutes", MinutesToRun); }
public override void Dispose() { if (MemoryProfiler.IsActive) { MemoryProfiler.Dump(); } if (MemoryProfiler.CanDetach) { MemoryProfiler.Detach(); } base.Dispose(); }
static void Main(string[] args) { var initialGrid = RandomGridMulti(100); var conway = new Core.ConwayPerformance(100, 100); MemoryProfiler.CollectAllocations(true); MemoryProfiler.GetSnapshot(); for (var i = 0; i < 100; i++) { conway.NextState(initialGrid); } MemoryProfiler.GetSnapshot(); }
private void Start() { MemoryProfiler.TakeSnapshot("Snapshot", ((s, b) => Debug.Log(s + b)), CaptureFlags.ManagedObjects | CaptureFlags.NativeObjects); _transforms = new Transform[Count][]; _positions = new Vector3[Count][]; for (int i = 0; i < Count; i++) { _positions[i] = new Vector3[Count]; for (int j = 0; j < Count; j++) { //_transforms[i, j] = new GameObject("obj" + i).transform; _positions[i][j] = Vector3.one * i; //_transforms[i, j].position = _positions[i, j]; } } }
/// <summary> /// The Unity Start method. /// </summary>` public void Start() { // Ensure only one scene UI. if (FindObjectsOfType <MemoryProfilerApplicationController>().Length > 1) { Destroy(gameObject); } else { DontDestroyOnLoad(this); } // Initialize the UI to the home screen. _SetUIState(Debug.isDebugBuild ? UIScreenStateEnum.HomeScreen : UIScreenStateEnum.DubugBuildErrorScreen); // Initialize the memory profiler, set to inactive until profiling scene load. m_memoryProfiler = MemoryProfiler.Get(); }
static void Main(string[] args) { if (MemoryProfiler.CanControlAllocations) { MemoryProfiler.EnableAllocations(); } Task task1 = SemaphoreGCTricklePressure(); task1.Wait(); Task task2 = SemaphoreGCExtremePressure(); task2.Wait(); SemaphoreGCExtremePressureBlocking(); Console.ReadLine(); }
static void VwSalesByCategoryContainsMem() { var benchmark = new QueryGenerationBenchmark(); benchmark.DataProvider = ProviderName.Access; #if JETBRAINS MemoryProfiler.CollectAllocations(true); #endif for (int c = 0; c < 5; c++) { for (int i = 0; i < 1000; i++) { benchmark.VwSalesByCategoryContains(); } #if JETBRAINS MemoryProfiler.GetSnapshot(); #endif } }