Пример #1
0
    public static byte[] CustomLoader(ref string filename)
    {
        TextAsset luaCfg;

        if (filename.Split('/')[0].Equals("Lua"))
        {
            luaCfg = CoreEntry.gResLoader.LoadTextAsset(filename + ".lua", SenLib.AssetType.Txt);
        }
        else
        {
            luaCfg = Resources.Load(filename + ".lua", typeof(TextAsset)) as TextAsset;
        }

        if (luaCfg != null)
        {
            ProfilerData.AddLuaFile(filename, luaCfg);
        }

        byte[] ret = null;
        if (luaCfg != null)
        {
            ret = luaCfg.bytes;
        }

        Resources.UnloadAsset(luaCfg);
        luaCfg = null;

        return(ret);
    }
Пример #2
0
        static Profiler()
        {
            profilerData = new ProfilerData();
            Thread t = new Thread(PushProfilerMetricsToLogServer);

            t.Start();
        }
Пример #3
0
 public Profiler()
 {
     visualizers  = new List <ProfilerVisualizer>();
     recorders    = new List <Recorder>();
     profilerData = new ProfilerData();
     isCustom     = new List <bool>();
     profilerData.samplingSize = 120;
 }
Пример #4
0
        private void OnProfilerRequestComplete(WorkData data)
        {
            ProfilerData data2 = data as ProfilerData;

            base.SyncLayer.TransportLayer.SendFlush(data2.Sender.Value);
            Vector3D?position = null;

            MyMultiplayer.RaiseStaticEvent <byte[]>(s => new Action <byte[]>(MyMultiplayerClientBase.ReceiveProfiler), data2.Buffer, new EndpointId(data2.Sender.Value), position);
        }
Пример #5
0
        public void Save(ProfilerData data)
        {
            var key = String.Format("profiler:{0}:{1:yyyyMMdd}", SettingProvider.SiteIdentity, data.RequestTime);

            using (var client = CreateRedisClient())
            {
                var json = JsonSerializer.SerializeToString(data);
                client.PushItemToList(key, json);
            }
        }
Пример #6
0
 public LoadPlugins(ProfilerData profilerData,
                    GuiModel guiModelData,
                    IDialogManager dialogManager,
                    ICommonDialogsService commonDialogsService)
 {
     _profilerData         = profilerData;
     _guiModelData         = guiModelData;
     _dialogManager        = dialogManager;
     _commonDialogsService = commonDialogsService;
 }
Пример #7
0
        private static void UpdateProfilerForEntering(EneterTrace trace)
        {
            int aThreadId = Thread.CurrentThread.ManagedThreadId;

            Action aProfilerJob = () =>
            {
                MethodBase aMethod = trace.myCallStack.GetMethod();

                lock (myProfilerData)
                {
                    ProfilerData aProfileData;
                    myProfilerData.TryGetValue(aMethod, out aProfileData);
                    if (aProfileData == null)
                    {
                        aProfileData                    = new ProfilerData();
                        aProfileData.Calls              = 1;
                        aProfileData.MaxConcurency      = 1;
                        aProfileData.MaxRecursion       = 1;
                        aProfileData.Threads[aThreadId] = 1;

                        myProfilerData[aMethod] = aProfileData;
                    }
                    else
                    {
                        ++aProfileData.Calls;

                        // If this thread is already inside then it is a recursion.
                        if (aProfileData.Threads.ContainsKey(aThreadId))
                        {
                            int aRecursion = ++aProfileData.Threads[aThreadId];
                            if (aRecursion > aProfileData.MaxRecursion)
                            {
                                aProfileData.MaxRecursion = aRecursion;
                            }
                        }
                        // ... else it is another thread wich is parallel inside.
                        else
                        {
                            aProfileData.Threads[aThreadId] = 1;
                            if (aProfileData.Threads.Count > aProfileData.MaxConcurency)
                            {
                                aProfileData.MaxConcurency = aProfileData.Threads.Count;
                            }
                        }
                    }

                    trace.myBufferedProfileData = aProfileData;
                }
            };

            EnqueueJob(aProfilerJob);
        }
Пример #8
0
 public static void PushProfilerMetricsToLogServer()
 {
     RuntimePlatformUtils.SetupCurrentThreadCulture();
     while (true)
     {
         try {
             ProfilerData oldProfilerData = profilerData;
             profilerData = new ProfilerData();
             ServerLog.PushProfilerMetricsToLogServer(oldProfilerData);
         } catch (System.Net.Sockets.SocketException) { }
         Thread.Sleep(Settings.GetInt(Settings.Configs.Profiler_PushMetricsToLogServerIntervalMs));
     }
 }
 public MinimizingPreProcessor(ICache cache, IRunResultCache resultCache, IConfiguration configuration, IOptimizeBuildConfiguration buildOptimizer, IMessageBus bus, ITestRunner[] runners)
 {
     _cache                      = cache;
     _resultCache                = resultCache;
     _configuration              = configuration;
     _buildOptimizer             = buildOptimizer;
     _bus                        = bus;
     _runner                     = (AutoTestTestRunner)runners.First(x => x.GetType().Name.Equals("AutoTestTestRunner"));
     _minimizer                  = new TestMinimizer(configuration.AllSettings("mm-MinimizerDebug") == "true", 1);
     _profilerData               = new ProfilerData(GetDBName(), new BinaryFileProfilerDataParser(), new ForEveryFixtureConstructorOrFixtureChangeContextChangeFinder());
     _profilerData.DebugMessage += _profilerData_DebugMessage;
     Logger.WriteDebug("Minimizing PreProc Created");
 }
Пример #10
0
        private void ProfilerRequestAsync(WorkData data)
        {
            ProfilerData data2 = data as ProfilerData;

            try
            {
                VRage.Profiler.MyRenderProfiler.AddPause(false);
                MemoryStream writeTo = new MemoryStream();
                MyObjectBuilderSerializer.SerializeXML(writeTo, MyObjectBuilder_ProfilerSnapshot.GetObjectBuilder(MyRenderProxy.GetRenderProfiler()), MyObjectBuilderSerializer.XmlCompression.Gzip, null);
                data2.Buffer = writeTo.ToArray();
                MyLog.Default.WriteLine("Profiler for " + MySession.Static.Players.TryGetIdentityNameFromSteamId(data2.Sender.Value) + " serialized");
            }
            catch
            {
                MyLog.Default.WriteLine("Profiler serialization for " + MySession.Static.Players.TryGetIdentityNameFromSteamId(data2.Sender.Value) + " crashed");
            }
        }
Пример #11
0
 private void OnProfilerRequest(EndpointId sender)
 {
     if (!base.IsServer)
     {
         MyLog.Default.WriteLine("Profiler request received from " + MySession.Static.Players.TryGetIdentityNameFromSteamId(sender.Value) + ", but ignored");
     }
     else
     {
         MyLog.Default.WriteLine("Profiler request received from " + MySession.Static.Players.TryGetIdentityNameFromSteamId(sender.Value));
         ProfilerData data1 = new ProfilerData();
         data1.Sender   = sender;
         data1.Priority = WorkPriority.Low;
         ProfilerData workData = data1;
         VRage.Profiler.MyRenderProfiler.AddPause(true);
         Parallel.Start(new Action <WorkData>(this.ProfilerRequestAsync), new Action <WorkData>(this.OnProfilerRequestComplete), workData);
     }
 }
Пример #12
0
        private static void UpdateProfilerForLeaving(EneterTrace trace, long ticks)
        {
            int aThreadId = Thread.CurrentThread.ManagedThreadId;

            Action aProfilerJob = () =>
            {
                lock (myProfilerData)
                {
                    trace.myBufferedProfileData.Ticks += ticks;
                    int aRecursion = --trace.myBufferedProfileData.Threads[aThreadId];

                    if (aRecursion < 1)
                    {
                        MethodBase   aMethod      = trace.myCallStack.GetMethod();
                        ProfilerData aProfileData = myProfilerData[aMethod];
                        aProfileData.Threads.Remove(aThreadId);
                    }
                }
            };

            EnqueueJob(aProfilerJob);
        }
Пример #13
0
        private static void UpdateProfilerForLeaving(Trace trace, long ticks)
        {
            Action aProfilerJob = () =>
            {
                //lock (myProfilerData)
                {
                    trace.myBufferedProfileData.Ticks += ticks;
                    int aRecursion = --trace.myBufferedProfileData.Threads[trace.myThreadId];

                    if (aRecursion < 1)
                    {
                        MethodBase   aMethod      = trace.myCallStack.GetMethod();
                        ProfilerData aProfileData = myProfilerData[aMethod];
                        aProfileData.Threads.Remove(trace.myThreadId);
                    }

                    myActiveStacks.TryGetValue(trace.myThreadId, out Stack <ProfilerData> aStack);
                    if (aStack != null)
                    {
                        aStack.Pop();

                        if (aStack.Count > 0)
                        {
                            ProfilerData aCallerProfilerData = aStack.Peek();
                            aCallerProfilerData.SubcallsTicks += ticks;
                        }
                        else
                        {
                            // note: do not remove the empty stack from the dictionary so that it can be reused if needed.
                            //       the dictionary is cleared at the very end of profilling.
                        }
                    }
                }
            };

            EnqueueJob(aProfilerJob);
        }
Пример #14
0
        private void UpdateDebugData()
        {
            ProfilerData data = Drone.DebugProfilerData;

            StringBuilder profilerString = new StringBuilder();

            profilerString.AppendFormat("Free heap: {0}", Formatting.FormatDataSize(data.FreeHeapBytes));
            profilerString.AppendLine();

            if (data.Entries != null)
            {
                for (int i = 0; i < data.Entries.Length; i++)
                {
                    ProfilerData.Entry entry = data.Entries[i];
                    profilerString.AppendFormat("{0} {1}ms ({2}ms)",
                                                entry.Name.PadLeft(25),
                                                Formatting.FormatDecimal(entry.Time.TotalMilliseconds, 1, 8),
                                                Formatting.FormatDecimal(entry.TimeMax.TotalMilliseconds, 1, 8));
                    profilerString.AppendLine();
                }

                profilerData.Text = profilerString.ToString();
            }
        }
Пример #15
0
        private static void UpdateProfilerForEntering(Trace trace)
        {
            int aThreadId = Thread.CurrentThread.ManagedThreadId;

            Action aProfilerJob = () =>
            {
                trace.myThreadId = aThreadId;
                MethodBase aMethod = trace.myCallStack.GetMethod();

                //lock (myProfilerData)
                {
                    if (myStartProfilingTicks == 0)
                    {
                        myStartProfilingTicks = GetTimeTicks();
                    }
                    ++myProfilerCounter;

                    ProfilerData aProfileData;
                    myProfilerData.TryGetValue(aMethod, out aProfileData);
                    if (aProfileData == null)
                    {
                        aProfileData                    = new ProfilerData();
                        aProfileData.Calls              = 1;
                        aProfileData.MaxConcurency      = 1;
                        aProfileData.MaxRecursion       = 1;
                        aProfileData.Threads[aThreadId] = 1;

                        myProfilerData[aMethod] = aProfileData;
                    }
                    else
                    {
                        ++aProfileData.Calls;

                        // If this thread is already inside then it is a recursion.
                        if (aProfileData.Threads.ContainsKey(aThreadId))
                        {
                            int aRecursion = ++aProfileData.Threads[aThreadId];
                            if (aRecursion > aProfileData.MaxRecursion)
                            {
                                aProfileData.MaxRecursion = aRecursion;
                            }
                        }
                        // ... else it is another thread wich is parallel inside.
                        else
                        {
                            aProfileData.Threads[aThreadId] = 1;
                            if (aProfileData.Threads.Count > aProfileData.MaxConcurency)
                            {
                                aProfileData.MaxConcurency = aProfileData.Threads.Count;
                            }
                        }
                    }


                    myActiveStacks.TryGetValue(aThreadId, out Stack <ProfilerData> aStack);
                    if (aStack == null)
                    {
                        aStack = new Stack <ProfilerData>();
                        myActiveStacks[aThreadId] = aStack;
                    }
                    aStack.Push(aProfileData);

                    trace.myBufferedProfileData = aProfileData;
                }
            };

            EnqueueJob(aProfilerJob);
        }
Пример #16
0
 private List<ProfilerData> ParseProfilerDataString(string data)
 {
     List<ProfilerData> profilerData = new List<ProfilerData>();
     var tokens = data.Split(' ');
     for (int i = 0; i < tokens.Length; i += 5)
     {
         ProfilerData newData = new ProfilerData()
         {
             name = tokens[i + 0],
             pointId = tokens[i + 1],
             parentId = tokens[i + 2],
             count = tokens[i + 3],
             interval = tokens[i + 4]
         };
         profilerData.Add(newData);
     }
     return profilerData;
 }
Пример #17
0
        private void Handle(ProfilerRequestType type)
        {
            var          ticks       = SampleTicks;
            var          top         = Top;
            long?        factionMask = null;
            long?        playerMask  = null;
            long?        entityMask  = null;
            MyModContext modFilter   = null;
            long?        reportGPS   = null;

            foreach (var arg in Context.Args)
            {
                if (arg.StartsWith("--ticks="))
                {
                    ticks = ulong.Parse(arg.Substring("--ticks=".Length));
                }
                else if (arg.StartsWith("--top="))
                {
                    top = int.Parse(arg.Substring("--top=".Length));
                }
                else if (arg.StartsWith("--faction="))
                {
                    var name = arg.Substring("--faction=".Length);
                    if (!ResolveFaction(name, out var id))
                    {
                        Context.Respond($"Failed to find faction {name}");
                        return;
                    }

                    factionMask = id?.FactionId ?? 0;
                }
                else if (arg.StartsWith("--player="))
                {
                    var name = arg.Substring("--player=".Length);
                    if (!ResolveIdentity(name, out var id))
                    {
                        Context.Respond($"Failed to find player {name}");
                        return;
                    }

                    playerMask = id?.IdentityId ?? 0;
                }
                else if (arg.StartsWith("--entity="))
                {
                    var id  = long.Parse(arg.Substring("--entity=".Length));
                    var ent = MyEntities.GetEntityById(id);
                    if (ent == null)
                    {
                        Context.Respond($"Failed to find entity with ID={id}");
                        return;
                    }

                    entityMask = ent.EntityId;
                }
                else if (arg == "--this")
                {
                    var controlled = Context.Player?.Controller?.ControlledEntity?.Entity;
                    if (controlled == null)
                    {
                        Context.Respond($"You must have a controlled entity to use the --this argument");
                        return;
                    }

                    MyCubeGrid grid;
                    var        tmp = controlled;
                    do
                    {
                        grid = tmp as MyCubeGrid;
                        if (grid != null)
                        {
                            break;
                        }
                        tmp = tmp.Parent;
                    } while (tmp != null);

                    if (grid == null)
                    {
                        Context.Respond($"You must be controlling a grid to use the --this argument");
                        return;
                    }

                    entityMask = grid.EntityId;
                }
                else if (arg == "--gps")
                {
                    var controlled = Context.Player;
                    if (controlled == null)
                    {
                        Context.Respond($"GPS return can only be used by players");
                        return;
                    }

                    reportGPS = controlled.IdentityId;
                    CleanGPS(reportGPS.Value);
                }
                else if (arg.StartsWith("--mod="))
                {
                    var nam = arg.Substring("--mod=".Length);
                    foreach (var mod in MySession.Static.Mods)
                    {
                        var ctx = new MyModContext();
                        ctx.Init(mod);
                        if (ctx.ModId.Equals(nam, StringComparison.OrdinalIgnoreCase) || ctx.ModId.Equals(nam + ".sbm", StringComparison.OrdinalIgnoreCase) || ctx.ModName.Equals(nam, StringComparison.OrdinalIgnoreCase))
                        {
                            modFilter = ctx;
                            break;
                        }
                    }
                    if (nam.Equals("base", StringComparison.OrdinalIgnoreCase) || nam.Equals("keen", StringComparison.OrdinalIgnoreCase))
                    {
                        modFilter = MyModContext.BaseGame;
                    }

                    // ReSharper disable once InvertIf
                    if (modFilter == null)
                    {
                        Context.Respond($"Failed to find mod {nam}");
                        return;
                    }
                }
            }

            if (!ProfilerData.ChangeMask(playerMask, factionMask, entityMask, modFilter))
            {
                Context.Respond($"Failed to change profiling mask.  There can only be one.");
                return;
            }

            var req     = new ProfilerRequest(type, ticks);
            var context = Context;

            req.OnFinished += (printByPassCount, results) =>
            {
                for (var i = 0; i < Math.Min(top, results.Length); i++)
                {
                    var r             = results[i];
                    var formattedTime = FormatTime(r.MsPerTick);
                    var hits          = results[i].HitsPerTick;
                    var hitsUnit      = results[i].HitsUnit;
                    var formattedName = string.Format(r.Name ?? "unknown", i, formattedTime, hits, hitsUnit);
                    var formattedDesc = string.Format(r.Description ?? "", i, formattedTime, hits, hitsUnit);
                    if (reportGPS.HasValue || !r.Position.HasValue)
                    {
                        context.Respond(printByPassCount
                            ? $"{formattedName} {formattedDesc} took {hits:F1} {hitsUnit}"
                            : $"{formattedName} {formattedDesc} took {formattedTime} ({hits:F1} {hitsUnit})");
                        if (!reportGPS.HasValue || !r.Position.HasValue)
                        {
                            continue;
                        }
                        var gpsDisplay = printByPassCount ? $"{hits:F1} {hitsUnit} {formattedName}" : $"{formattedTime} {formattedName}";
                        var gpsDesc    = formattedDesc + $" {hits:F1} {hitsUnit}";
                        var gps        = new MyGps(new MyObjectBuilder_Gps.Entry
                        {
                            name        = gpsDisplay,
                            DisplayName = gpsDisplay,
                            coords      = r.Position.Value,
                            showOnHud   = true,
                            color       = VRageMath.Color.Purple,
                            description = gpsDesc,
                            entityId    = 0,
                            isFinal     = false
                        });
                        MyAPIGateway.Session?.GPS.AddGps(reportGPS.Value, gps);
                        var set = GpsForIdentity.GetOrAdd(reportGPS.Value, (x) => new HashSet <int>());
                        lock (set)
                            set.Add(gps.Hash);
                        continue;
                    }

                    var posData =
                        $"{r.Position.Value.X.ToString(ProfilerRequest.DistanceFormat)},{r.Position.Value.Y.ToString(ProfilerRequest.DistanceFormat)},{r.Position.Value.Z.ToString(ProfilerRequest.DistanceFormat)}";
                    context.Respond(
                        printByPassCount
                            ? $"{formattedName} {formattedDesc} took ({hits:F1} {hitsUnit})  @ {posData}"
                            : $"{formattedName} {formattedDesc} took {formattedTime} ({hits:F1} {hitsUnit})  @ {posData}");
                }

                {
                    var    totalUpdates = 0d;
                    var    totalTime    = 0d;
                    string hitsUnit     = null;
                    for (var i = Math.Min(top, results.Length) + 1; i < results.Length; i++)
                    {
                        var r = results[i];
                        totalUpdates += r.HitsPerTick;
                        totalTime    += r.MsPerTick;
                        hitsUnit      = r.HitsUnit;
                    }

                    if (totalUpdates > 0)
                    {
                        context.Respond(printByPassCount
                            ? $"Others took {totalUpdates:F1} {hitsUnit}"
                            : $"Others took {FormatTime(totalTime)} ({totalUpdates:F1} {hitsUnit})");
                    }
                }
            };
            var timeEstMs = ticks * MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS * 1000f / (MyMultiplayer.Static?.ServerSimulationRatio ?? 1);

            context.Respond($"Profiling for {type} started, results in {ticks} ticks (about {FormatTime(timeEstMs)})");
            ProfilerData.Submit(req);
        }
Пример #18
0
        private void HandleDataPacket(byte[] packet)
        {
            using (MemoryStream stream = new MemoryStream(packet))
            {
                PacketBuffer buffer = new PacketBuffer(stream);
                if (buffer.Size < 3 || buffer.ReadByte() != 'F' || buffer.ReadByte() != 'L' || buffer.ReadByte() != 'Y')
                {
                    return;
                }

                int            revision = buffer.ReadInt();
                DataPacketType type     = (DataPacketType)buffer.ReadByte();

                lastDataTime = Environment.TickCount;

                switch (type)
                {
                case DataPacketType.Drone:
                    if (!CheckRevision(lastDataDroneRevision, revision))
                    {
                        return;
                    }

                    DroneState      state       = (DroneState)buffer.ReadByte();
                    QuadMotorValues motorValues = new QuadMotorValues(buffer);
                    SensorData      sensor      = new SensorData(buffer);

                    float batteryVoltage = buffer.ReadFloat();
                    int   wifiRssi       = buffer.ReadInt();

                    Data = new DroneData(state, motorValues, sensor, batteryVoltage, wifiRssi);

                    lastDataDroneRevision = revision;
                    break;

                case DataPacketType.Log:
                    if (!CheckRevision(lastDataLogRevision, revision))
                    {
                        return;
                    }

                    int lines = buffer.ReadInt();

                    for (int i = 0; i < lines; i++)
                    {
                        string msg = buffer.ReadString();

                        DroneLog.AddLine(msg);
                    }

                    lastDataLogRevision = revision;
                    break;

                case DataPacketType.DebugOutput:
                    if (!CheckRevision(lastDataOutputRevision, revision))
                    {
                        return;
                    }

                    DebugOutputData        = new OutputData(buffer);
                    lastDataOutputRevision = revision;

                    NotifyDebugDataChanged();
                    break;

                case DataPacketType.DebugProfiler:
                    if (!CheckRevision(lastDataProfilerRevision, revision))
                    {
                        return;
                    }

                    DebugProfilerData        = new ProfilerData(buffer);
                    lastDataProfilerRevision = revision;

                    NotifyDebugDataChanged();
                    break;
                }
            }
        }