public ResourceTracker()
    {
        try
        {
            DateTime dt = DateTime.Now;

            string logFile = string.Format("{0}_{1}_alloc.txt", SysUtil.FormatDateAsFileNameString(dt), SysUtil.FormatTimeAsFileNameString(dt));
            string logPath = Path.Combine(Application.persistentDataPath, logFile);

            _logWriter           = new FileInfo(logPath).CreateText();
            _logWriter.AutoFlush = true;
            _logPath             = logPath;
        }
        catch (Exception ex)
        {
            UnityEngine.Debug.LogErrorFormat("[ResourceTracker.ctor] error: {0} ", ex.Message);

            if (_logWriter != null)
            {
                _logWriter.Close();
                _logWriter = null;
            }

            _logPath = "";
        }
    }
Example #2
0
        void OnSnapshotBeginComparing(PackedMemorySnapshot snapshot)
        {
            string filename = string.Format("{0}/{1}-{2}.memsnap",
                                            Application.persistentDataPath,
                                            SysUtil.FormatDateAsFileNameString(DateTime.Now),
                                            SysUtil.FormatTimeAsFileNameString(DateTime.Now));

            System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
            using (Stream stream = File.Open(filename, FileMode.Create))
            {
                bf.Serialize(stream, snapshot);
            }

            _compBeginFilename     = filename;
            _isRequestingCompBegin = false;
        }
Example #3
0
 public void Open()
 {
     if (this._enableTracking)
     {
         Debug.LogFormat("[ResourceTracker] info: {0} ", new object[1]
         {
             (object)"already enabled, ignored."
         });
     }
     else
     {
         try
         {
             string str = Path.Combine(Application.get_persistentDataPath(), "mem_logs");
             if (!Directory.Exists(str))
             {
                 Directory.CreateDirectory(str);
             }
             DateTime now      = DateTime.Now;
             string   path2    = string.Format("{0}_{1}_alloc.txt", (object)SysUtil.FormatDateAsFileNameString(now), (object)SysUtil.FormatTimeAsFileNameString(now));
             string   fileName = Path.Combine(str, path2);
             this._logWriter           = new System.IO.FileInfo(fileName).CreateText();
             this._logWriter.AutoFlush = true;
             this._enableTracking      = true;
             Debug.LogFormat("[ResourceTracker] tracking enabled: {0} ", new object[1]
             {
                 (object)fileName
             });
         }
         catch (Exception ex)
         {
             Debug.LogErrorFormat("[ResourceTracker] Open() failed, error: {0} ", new object[1]
             {
                 (object)ex.Message
             });
             if (this._logWriter != null)
             {
                 this._logWriter.Close();
                 this._logWriter = (StreamWriter)null;
             }
             this._enableTracking = false;
         }
     }
 }
Example #4
0
    public void Open()
    {
        if (_enableTracking)
        {
            UnityEngine.Debug.LogFormat("[ResourceTracker] info: {0} ", "already enabled, ignored.");
            return;
        }

        try
        {
            string logDir = Path.Combine(Application.persistentDataPath, "mem_logs");
            if (!Directory.Exists(logDir))
            {
                Directory.CreateDirectory(logDir);
            }

            DateTime dt = DateTime.Now;

            string logFile = string.Format("{0}_{1}_alloc.txt", SysUtil.FormatDateAsFileNameString(dt), SysUtil.FormatTimeAsFileNameString(dt));
            string logPath = Path.Combine(logDir, logFile);

            _logWriter           = new FileInfo(logPath).CreateText();
            _logWriter.AutoFlush = true;
            _logPath             = logPath;

            _enableTracking = true;
            UnityEngine.Debug.LogFormat("[ResourceTracker] tracking enabled: {0} ", logPath);
        }
        catch (Exception ex)
        {
            UnityEngine.Debug.LogErrorFormat("[ResourceTracker] Open() failed, error: {0} ", ex.Message);

            if (_logWriter != null)
            {
                _logWriter.Close();
                _logWriter = null;
            }

            _enableTracking = false;
            _logPath        = "";
        }
    }
Example #5
0
    public static string Save(PackedMemorySnapshot snapshot)
    {
        try
        {
            string filename = GetFullpath(string.Format("{0}-{1}.memsnap",
                                                        SysUtil.FormatDateAsFileNameString(DateTime.Now),
                                                        SysUtil.FormatTimeAsFileNameString(DateTime.Now)));

            System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
            using (Stream stream = File.Open(filename, FileMode.Create))
            {
                bf.Serialize(stream, snapshot);
            }
            return(filename);
        }
        catch (Exception ex)
        {
            Debug.LogException(ex);
            return("");
        }
    }
    public void StopStats()
    {
        if (!((Behaviour)this).get_enabled())
        {
            return;
        }
        ((Behaviour)this).set_enabled(false);
        float         num1       = Time.get_time() - this.m_startTime;
        List <string> stringList = new List <string>();
        int           num2       = Time.get_frameCount() - this.m_startFrame;

        stringList.Add(string.Format("name \ttotalMS \tperFrameMS \trebuildCount \tupdateCount \tdrawcallCount/updateCount \t --- {0} frames ---", (object)num2));
        List <KeyValuePair <int, UIPanelData> > list1 = this.m_accumulatedPanels.ToList <KeyValuePair <int, UIPanelData> >();

        list1.Sort((Comparison <KeyValuePair <int, UIPanelData> >)((pair1, pair2) => pair2.Value.mElapsedTicks.CompareTo(pair1.Value.mElapsedTicks)));
        foreach (KeyValuePair <int, UIPanelData> keyValuePair in list1)
        {
            string      name        = UIDebugCache.GetName(keyValuePair.Key);
            UIPanelData uiPanelData = keyValuePair.Value;
            stringList.Add(string.Format("{0}\t{1:0.00}\t{2:0.00}\t{3}\t{4}\t{5}", (object)name, (object)uiPanelData.mElapsedTicks, (object)(uiPanelData.mElapsedTicks / (double)num2), (object)(int)((double)uiPanelData.mRebuildCount / (double)num1), (object)(int)((double)uiPanelData.mCalls / (double)num1), (object)(uiPanelData.mDrawCallNum / uiPanelData.mCalls)));
        }
        List <KeyValuePair <int, double> > list2 = this.m_accumulated.ToList <KeyValuePair <int, double> >();

        list2.Sort((Comparison <KeyValuePair <int, double> >)((pair1, pair2) => pair2.Value.CompareTo(pair1.Value)));
        foreach (KeyValuePair <int, double> keyValuePair in list2)
        {
            string str        = UIDebugCache.GetName(keyValuePair.Key);
            string parentName = UIDebugCache.GetParentName(keyValuePair.Key);
            if (!string.IsNullOrEmpty(parentName))
            {
                str = string.Format("{0}:{1}", (object)parentName, (object)str);
            }
            stringList.Add(string.Format("{0}\t{1:0.00}\t{2:0.00}", (object)str, (object)keyValuePair.Value, (object)(keyValuePair.Value / (double)num2)));
        }
        File.WriteAllLines(Path.Combine(Application.get_persistentDataPath(), string.Format("TestTools/ui_stats_panels_{0}_{1}.log", (object)SysUtil.FormatDateAsFileNameString(DateTime.Now), (object)SysUtil.FormatTimeAsFileNameString(DateTime.Now))), stringList.ToArray());
    }
Example #7
0
    public bool PrepareWriter()
    {
        if (!_enableTracking)
        {
            return(false);
        }

        DateTime dt = DateTime.Now;

        if (_logWriter != null)
        {
            if (dt.Hour == _lastWriteTime.Hour && dt.Minute / 10 == _lastWriteTime.Minute / 10)
            {
                return(true); // nothing to do, keep writing
            }
            else
            {
                LogInfo("Switching file at: " + dt.ToString());
                CloseWriter();
            }
        }

        // create a new text to write
        try
        {
            string baseInfo    = Application.isEditor ? "editor" : Network.player.ipAddress.ToString();
            string svnVersion  = "000";
            string buildInfoID = "000";

#if JX3M
            if (!Application.isEditor)
            {
                svnVersion = Lua2CS.GetVersion();
            }
            if (!Application.isEditor)
            {
                buildInfoID = Lua2CS.BuildInfoID();
            }
#endif

            string logFile = string.Format("{0}_{1}-{2}_{3}_{4}.txt", baseInfo,
                                           SysUtil.FormatDateAsFileNameString(dt),
                                           SysUtil.FormatTimeAsFileNameString(dt), svnVersion, buildInfoID);
            string filePath = Path.Combine(_logDir, logFile);

            if (!File.Exists(filePath))
            {
                File.Create(filePath).Dispose();
                LogInfo("Creating new text successfully at: " + filePath);
            }

            if (_logWriter == null)
            {
                _logWriter           = new StreamWriter(filePath, true);
                _logWriter.AutoFlush = true;   // TODO: buffering for better performance
            }
            return(true);
        }
        catch (Exception ex)
        {
            _enableTracking = false;
            LogError("Creating new text failed: " + ex.Message);
            CloseWriter();
            return(false);
        }
    }
Example #8
0
    public void StopStats()
    {
        if (!enabled)
        {
            return;
        }

        enabled = false;

        float seconds = Time.time - m_startTime;

        List <string> content       = new List <string>();
        int           frameRecorded = Time.frameCount - m_startFrame;

        content.Add(string.Format("name \ttotalMS \tperFrameMS \trebuildCount \tupdateCount \tdrawcallCount/updateCount \t --- {0} frames ---", frameRecorded));

        {
            List <KeyValuePair <int, UIPanelData> > panelData = m_accumulatedPanels.ToList();
            panelData.Sort(
                delegate(KeyValuePair <int, UIPanelData> pair1,
                         KeyValuePair <int, UIPanelData> pair2)
            {
                return(pair2.Value.mElapsedTicks.CompareTo(pair1.Value.mElapsedTicks));
            }
                );

            foreach (var p in panelData)
            {
                string      name = UIDebugCache.GetName(p.Key);
                UIPanelData data = p.Value;
                content.Add(string.Format("{0}\t{1:0.00}\t{2:0.00}\t{3}\t{4}\t{5}",
                                          name, data.mElapsedTicks, data.mElapsedTicks / (double)frameRecorded,
                                          (int)(data.mRebuildCount / seconds), (int)(data.mCalls / seconds), data.mDrawCallNum / data.mCalls));
            }
        }

        List <KeyValuePair <int, double> > sortBuf = m_accumulated.ToList();

        sortBuf.Sort(
            delegate(KeyValuePair <int, double> pair1,
                     KeyValuePair <int, double> pair2)
        {
            return(pair2.Value.CompareTo(pair1.Value));
        }
            );

        foreach (var p in sortBuf)
        {
            string name       = UIDebugCache.GetName(p.Key);
            string parentName = UIDebugCache.GetParentName(p.Key);
            if (!string.IsNullOrEmpty(parentName))
            {
                name = string.Format("{0}:{1}", parentName, name);
            }
            content.Add(string.Format("{0}\t{1:0.00}\t{2:0.00}", name, p.Value, p.Value / (double)frameRecorded));
        }
        string file = Path.Combine(Application.persistentDataPath, string.Format("TestTools/ui_stats_panels_{0}_{1}.log", SysUtil.FormatDateAsFileNameString(DateTime.Now), SysUtil.FormatTimeAsFileNameString(DateTime.Now)));

        System.IO.File.WriteAllLines(file, content.ToArray());
    }
Example #9
0
    public void StopStats()
    {
        if (!((Behaviour)this).get_enabled())
        {
            return;
        }
        ((Behaviour)this).set_enabled(false);
        List <KeyValuePair <string, int> > list = this.m_widgetHighlightCount.ToList <KeyValuePair <string, int> >();

        list.Sort((Comparison <KeyValuePair <string, int> >)((pair1, pair2) => pair2.Value.CompareTo(pair1.Value)));
        List <string> stringList = new List <string>();

        foreach (KeyValuePair <string, int> keyValuePair in list)
        {
            stringList.Add(string.Format("{0} {1}", (object)keyValuePair.Key, (object)keyValuePair.Value));
        }
        File.WriteAllLines(Path.Combine(Application.get_persistentDataPath(), string.Format("TestTools/ui_stats_{0}_{1}.log", (object)SysUtil.FormatDateAsFileNameString(DateTime.Now), (object)SysUtil.FormatTimeAsFileNameString(DateTime.Now))), stringList.ToArray());
    }
    public bool PrepareWriter()
    {
        if (!this._enableTracking)
        {
            return(false);
        }
        DateTime now = DateTime.Now;

        if (this._logWriter != null)
        {
            if (now.Hour == this._lastWriteTime.Hour && now.Minute / 10 == this._lastWriteTime.Minute / 10)
            {
                return(true);
            }
            this.LogInfo("Switching file at: " + now.ToString());
            this.CloseWriter();
        }
        try
        {
            string str1 = !Application.get_isEditor() ? IPManager.GetIP(ADDRESSFAM.IPv4) : "editor";
            string str2 = "000";
            string str3 = "000";
            string path = Path.Combine(this._logDir, string.Format("{0}_{1}-{2}_{3}_{4}.txt", (object)str1, (object)SysUtil.FormatDateAsFileNameString(now), (object)SysUtil.FormatTimeAsFileNameString(now), (object)str2, (object)str3));
            if (!File.Exists(path))
            {
                File.Create(path).Dispose();
                this.LogInfo("Creating new text successfully at: " + path);
            }
            if (this._logWriter == null)
            {
                this._logWriter           = new StreamWriter(path, true);
                this._logWriter.AutoFlush = true;
            }
            return(true);
        }
        catch (Exception ex)
        {
            this._enableTracking = false;
            this.LogError("Creating new text failed: " + ex.Message);
            this.CloseWriter();
            return(false);
        }
    }
Example #11
0
    public void StopStats()
    {
        if (!enabled)
        {
            return;
        }

        enabled = false;
        List <KeyValuePair <string, int> > sortBuf = m_widgetHighlightCount.ToList();

        sortBuf.Sort(
            delegate(KeyValuePair <string, int> pair1,
                     KeyValuePair <string, int> pair2)
        {
            return(pair2.Value.CompareTo(pair1.Value));
        }
            );

        List <string> content = new List <string>();

        foreach (var p in sortBuf)
        {
            content.Add(string.Format("{0} {1}", p.Key, p.Value));
        }
        string file = Path.Combine(Application.persistentDataPath, string.Format("TestTools/ui_stats_{0}_{1}.log", SysUtil.FormatDateAsFileNameString(DateTime.Now), SysUtil.FormatTimeAsFileNameString(DateTime.Now)));

        System.IO.File.WriteAllLines(file, content.ToArray());
    }