Exemplo n.º 1
0
        public async Task DiagnosticAsync(
            [Summary("If set, wait until the next performance service tick, collect unused memory and show diagnostic info. Requires bot ownership")]
            bool forceCollect = false)
        {
            EmbedBuilder embed;
            IUserMessage msg = null;

            if (forceCollect)
            {
                var ownerId = (await discord.GetApplicationInfoAsync()).Owner.Id;
                if (Context.User.Id != ownerId)
                {
                    return;
                }

                embed = new EmbedBuilder()
                        .WithColor(100, 149, 237)
                        .WithDescription("Waiting for next performance service tick...");
                msg = await ReplyAsync("", embed : embed.Build());

                await perf.WaitNextTick(true);
            }

            embed = new EmbedBuilder()
                    .WithColor(100, 149, 237)
                    .AddInlineField("Gateway latency", $"{perf.AverageLatency:.##} ms")
                    .AddInlineField("Memory", $"Heap: {perf.AverageHeapMemory / 1_000_000f:.##}MB\nProcess: {perf.AverageProcessMemory / 1_000_000f:.##}MB")
                    .AddInlineField("Cache", $"{cache.Queries} queries\n{cache.Articles} articles\n{cache.FileSize / 1_000_000f:.##}MB file")
                    .AddInlineField("GC", $"{GC.MaxGeneration} generations\nGen-0 collections: {GC.CollectionCount(0)}")
                    .WithTimestamp(DateTimeOffset.UtcNow);

            if (msg != null)
            {
                await msg.ModifyAsync(f => f.Embed = embed.Build());
            }
            else
            {
                await ReplyAsync("", embed : embed.Build());
            }
        }