private static JsonTimelineMessage CreateJsonTimelineMessage(JsonAction action, string type)
        {
            JsonTimelineMessage timelineMessage = new JsonTimelineMessage();
            string eventName = action.ToString("G");

            if (type != null)
            {
                eventName += " - " + RemoveAssemblyDetails(type);
            }
            timelineMessage.AsTimelineMessage(eventName, new TimelineCategoryItem(action.ToString("G"), "#B3DF00", "#9BBB59"));
            return(timelineMessage);
        }
    IEnumerator DoBenchmark()
    {
        yield return(null);

        // Attempt to find a wrapper matching the selection name
        IJsonLibrary wrapper = null;

        foreach (var w in m_knownJsonLibraryWrappers)
        {
            System.Type t = w.GetType();
            if (t.ToString() == Lib)
            {
                wrapper = w;
                break;
            }
        }

        if (wrapper != null)
        {
            yield return(null);

            LastLibName.text    = Lib;
            LastActionName.text = Action.ToString();

            long   sum     = 0;
            long   samples = long.Parse(NumSamplesToRun.text);
            string notes   = string.Empty; // Gets overwritten, only last notes are shown
            long   avg     = 0;
#if !UNITY_EDITOR
            long memoryAllocatedDuringAction = 0;
#endif

            if (samples > 0)
            {
                for (int i = 0; i < samples; i++)
                {
                    Stopwatch timer = new Stopwatch();

#if !UNITY_EDITOR
                    System.GC.Collect();
                    UnityEngine.Scripting.GarbageCollector.GCMode = UnityEngine.Scripting.GarbageCollector.Mode.Disabled;
                    long totalGCBeforeAction = System.GC.GetTotalMemory(true);
#endif

                    if (Action == JsonAction.Deserialize)
                    {
                        notes  = string.Format("Json being used is {0} char long", m_jsonText.Length);
                        notes += wrapper.Deserialize(timer);
                    }
                    else if (Action == JsonAction.Serialize)
                    {
                        notes  = string.Format("Class being serialized has {0} complex elements", m_holder.junkList.Length);
                        notes += wrapper.Serialize(timer);
                    }

                    if (!timer.IsRunning)
                    {
                        throw new System.Exception("Stopwatch timer was not started by wrapper");
                    }

                    timer.Stop();

                    sum += timer.ElapsedMilliseconds;

#if !UNITY_EDITOR
                    memoryAllocatedDuringAction += System.GC.GetTotalMemory(true) - totalGCBeforeAction;
                    UnityEngine.Scripting.GarbageCollector.GCMode = UnityEngine.Scripting.GarbageCollector.Mode.Enabled;
#endif

                    //UnityEngine.Debug.Log(string.Format("----> {0} using {1} took {2}", Action, Lib, timer.ElapsedMilliseconds));
                    yield return(null);
                }

                avg = (sum / samples);
            }

            notes += "\n" + samples.ToString() + " samples taken";
#if !UNITY_EDITOR
            notes += "\n" + (memoryAllocatedDuringAction / samples * 1e-6).ToString("F2") + " mb GC allocated";
#endif
            Notes.text         = notes;
            LastTimeValue.text = avg.ToString();
        }
        else
        {
            UnityEngine.Debug.Log(string.Format("Unable to find suitable IJsonWrapper to match selection {0}", Lib));
        }

        Action    = JsonAction.None;
        m_working = -1;
    }
 private static JsonTimelineMessage CreateJsonTimelineMessage(JsonAction action, string type)
 {
   JsonTimelineMessage timelineMessage = new JsonTimelineMessage();
   string eventName = action.ToString("G");
   if (type != null)
     eventName += " - " + RemoveAssemblyDetails(type);
   timelineMessage.AsTimelineMessage(eventName, new TimelineCategoryItem(action.ToString("G"), "#B3DF00", "#9BBB59"));
   return timelineMessage;
 }
Exemple #4
0
        public void Add(HttpRequest httpRequest, HttpResponse httpResponse, object objRequest = null, object objResponse = null)
        {
            lock (View)
            {
                ++Count;
                JsonType   jsonType   = JsonType.Handshake;
                JsonAction jsonAction = JsonAction.Request;
                LogDevice  device     = LogDevice.Client;

                if (objRequest != null && objRequest is JsonPacket)
                {
                    JsonPacket  jsonRequest = (JsonPacket)objRequest;
                    JsonMessage jsonMessage = JsonMessage.Parse(jsonRequest.Message);
                    jsonAction = jsonMessage.Action;
                    jsonType   = jsonMessage.Type;

                    if (!httpRequest.HasSession())
                    {
                        device = LogDevice.Server;
                    }
                }

                StringBuilder sb = new StringBuilder();
                sb.Append("[ ").Append(device.ToString().ToUpper()).Append(" ]").Append(Constant.Newline);
                sb.Append("[ ").Append(jsonType.ToString().ToUpper()).Append(" ").Append(jsonAction.ToString().ToUpper()).Append(" ]");
                Add(sb);

                Add(httpRequest, objRequest, Suffix.EOM);
                Add(httpResponse, objResponse, Suffix.EOL);
            }
        }