public void Send(uint seconds = 15)
        {
            //validate
            if (seconds == 0)
            {
                Context.Respond("seconds must greater than zero");
                return;
            }

            async void ProfileAndCatch()
            {
                try
                {
                    var mask = new GameEntityMask();
                    using (var profiler = new GridProfiler(mask))
                        using (ProfilerResultQueue.Profile(profiler))
                        {
                            Context.Respond($"Started profiling grids, result in {seconds}s");

                            var startTick = MySandboxGame.Static.SimulationFrameCounter;
                            profiler.MarkStart();
                            await Task.Delay(TimeSpan.FromSeconds(seconds));

                            var result  = profiler.GetResult();
                            var endTick = MySandboxGame.Static.SimulationFrameCounter;
                            var ticks   = endTick - startTick;
                            Context.Respond($"Profiling finish in {ticks}ticks");
                            CleanGps();
                            OnProfilerRequestFinished(result, ticks);
                        }
                }
                catch (Exception e)
                {
                    Log.Error(e);
                    Context.Respond($"Error occured: {e.Message}");
                }
            }

            ProfileAndCatch();
        }
Exemplo n.º 2
0
        async Task Profile(CancellationToken canceller)
        {
            // auto profile
            var mask = new GameEntityMask(null, null, null);

            using (var gridProfiler = new GridProfiler(mask))
                using (var playerProfiler = new PlayerProfiler(mask))
                    using (ProfilerResultQueue.Profile(gridProfiler))
                        using (ProfilerResultQueue.Profile(playerProfiler))
                        {
                            Log.Trace("auto-profile started");
                            gridProfiler.MarkStart();
                            playerProfiler.MarkStart();
                            await Task.Delay(_config.IntervalFrequency.Seconds(), canceller);

                            Log.Trace("auto-profile done");

                            _grids.Update(gridProfiler.GetResult());
                            _players.Update(playerProfiler.GetResult());
                        }

            Log.Trace("profile done");
        }