static PackedMemorySnapshot LoadFromFile(string filePath) { Debug.LogFormat("Loading..."); System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); PackedMemorySnapshot result; string fileExtension = Path.GetExtension(filePath); if (string.Equals(fileExtension, ".memsnap3", System.StringComparison.OrdinalIgnoreCase)) { Profiler.BeginSample("PackedMemorySnapshotUtility.LoadFromFile(litjson)"); stopwatch.Start(); using (TextReader reader = File.OpenText(filePath)) { var errors = new List <string>(); var serializer = getSerializer(errors); result = (PackedMemorySnapshot)serializer.Deserialize(reader, typeof(PackedMemorySnapshot)); logErrors(errors); } stopwatch.Stop(); Profiler.EndSample(); } else if (string.Equals(fileExtension, ".memsnap2", System.StringComparison.OrdinalIgnoreCase)) { Profiler.BeginSample("PackedMemorySnapshotUtility.LoadFromFile(json)"); stopwatch.Start(); var json = File.ReadAllText(filePath); result = JsonUtility.FromJson <PackedMemorySnapshot>(json); stopwatch.Stop(); Profiler.EndSample(); } else if (string.Equals(fileExtension, ".memsnap", System.StringComparison.OrdinalIgnoreCase)) { Profiler.BeginSample("PackedMemorySnapshotUtility.LoadFromFile(binary)"); stopwatch.Start(); var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); using (Stream stream = File.Open(filePath, FileMode.Open)) { result = binaryFormatter.Deserialize(stream) as PackedMemorySnapshot; } stopwatch.Stop(); Profiler.EndSample(); } else { Debug.LogErrorFormat("MemoryProfiler: Unrecognized memory snapshot format '{0}'.", filePath); result = null; } Debug.LogFormat("Loading took {0}ms", stopwatch.ElapsedMilliseconds); return(result); }
static public int constructor(IntPtr l) { try { UnityEngine.Profiling.Profiler o; o = new UnityEngine.Profiling.Profiler(); pushValue(l, true); pushValue(l, o); return(2); } catch (Exception e) { return(error(l, e)); } }
static void SaveToFile(string filePath, PackedMemorySnapshot snapshot) { // Saving snapshots using JsonUtility, instead of BinaryFormatter, is significantly faster. // I cancelled saving a memory snapshot that is saving using BinaryFormatter after 24 hours. // Saving the same memory snapshot using JsonUtility.ToJson took 20 seconds only. Debug.LogFormat("Saving..."); System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch(); Profiler.BeginSample("PackedMemorySnapshotUtility.SaveToFile"); stopwatch.Start(); string fileExtension = Path.GetExtension(filePath); if (string.Equals(fileExtension, ".memsnap", System.StringComparison.OrdinalIgnoreCase)) { System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); using (Stream stream = File.Open(filePath, FileMode.Create)) { bf.Serialize(stream, snapshot); } } else if (string.Equals(fileExtension, ".memsnap2", System.StringComparison.OrdinalIgnoreCase)) { var json = JsonUtility.ToJson(snapshot); File.WriteAllText(filePath, json); } else // memsnap3 + default // Stream writing -- will not to exhaust memory (for large snapshots) { using (TextWriter writer = File.CreateText(filePath)) { var errors = new List <string>(); var serializer = getSerializer(errors); serializer.Serialize(writer, snapshot); logErrors(errors); } } stopwatch.Stop(); Profiler.EndSample(); Debug.LogFormat("Saving took {0}ms", stopwatch.ElapsedMilliseconds); }
public static uint GetTotalAllocatedMemory() { return((uint)Profiler.GetTotalAllocatedMemoryLong()); }
public static uint GetMonoUsedSize() { return((uint)Profiler.GetMonoUsedSizeLong()); }
public static int GetRuntimeMemorySize(UnityEngine.Object o) { return((int)Profiler.GetRuntimeMemorySizeLong(o)); }
public static void BeginSample(string name, UnityEngine.Object targetObject) { Profiler.ValidateArguments(name); Profiler.BeginSampleImpl(name, targetObject); }
public static void BeginSample(string name) { Profiler.ValidateArguments(name); Profiler.BeginSampleImpl(name, null); }