コード例 #1
0
    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);
    }
コード例 #2
0
 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));
     }
 }
コード例 #3
0
    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);
    }
コード例 #4
0
 public static uint GetTotalAllocatedMemory()
 {
     return((uint)Profiler.GetTotalAllocatedMemoryLong());
 }
コード例 #5
0
 public static uint GetMonoUsedSize()
 {
     return((uint)Profiler.GetMonoUsedSizeLong());
 }
コード例 #6
0
 public static int GetRuntimeMemorySize(UnityEngine.Object o)
 {
     return((int)Profiler.GetRuntimeMemorySizeLong(o));
 }
コード例 #7
0
 public static void BeginSample(string name, UnityEngine.Object targetObject)
 {
     Profiler.ValidateArguments(name);
     Profiler.BeginSampleImpl(name, targetObject);
 }
コード例 #8
0
 public static void BeginSample(string name)
 {
     Profiler.ValidateArguments(name);
     Profiler.BeginSampleImpl(name, null);
 }