3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 12:25:02 +00:00

feat: upgrade to Knub v30.0.0-beta.46, add better performance profiling tools

This commit is contained in:
Dragory 2021-10-05 20:49:58 +03:00
parent cb53061256
commit ff8d406e8a
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
6 changed files with 73 additions and 33 deletions

View file

@ -18,7 +18,7 @@ import { ReloadServerCmd } from "./commands/ReloadServerCmd";
import { RemoveDashboardUserCmd } from "./commands/RemoveDashboardUserCmd";
import { ServersCmd } from "./commands/ServersCmd";
import { BotControlPluginType, ConfigSchema } from "./types";
import { PluginPerformanceCmd } from "./commands/PluginPerformanceCmd";
import { ProfilerDataCmd } from "./commands/ProfilerDataCmd";
import { AddServerFromInviteCmd } from "./commands/AddServerFromInviteCmd";
import { ChannelToServerCmd } from "./commands/ChannelToServerCmd";
import { RestPerformanceCmd } from "./commands/RestPerformanceCmd";
@ -53,7 +53,7 @@ export const BotControlPlugin = zeppelinGlobalPlugin<BotControlPluginType>()({
ListDashboardUsersCmd,
ListDashboardPermsCmd,
EligibleCmd,
PluginPerformanceCmd,
ProfilerDataCmd,
RestPerformanceCmd,
RateLimitPerformanceCmd,
AddServerFromInviteCmd,

View file

@ -1,23 +0,0 @@
import { TextChannel } from "discord.js";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { createChunkedMessage, formatNumber, resolveInvite, sorter, verboseUserMention } from "../../../utils";
import { botControlCmd } from "../types";
export const PluginPerformanceCmd = botControlCmd({
trigger: ["plugin_performance"],
permission: "can_performance",
signature: {},
async run({ pluginData, message: msg, args }) {
const stats = pluginData.getKnubInstance().getPluginPerformanceStats();
const averageLoadTimeEntries = Object.entries(stats.averageLoadTimes);
averageLoadTimeEntries.sort(sorter((v) => v[1].time, "DESC"));
const lines = averageLoadTimeEntries.map(
([pluginName, { time }]) => `${pluginName}: **${formatNumber(Math.round(time))}ms**`,
);
const fullStats = `Average plugin load times:\n\n${lines.join("\n")}`;
createChunkedMessage(msg.channel as TextChannel, fullStats);
},
});

View file

@ -0,0 +1,57 @@
import { TextChannel } from "discord.js";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { getBaseUrl, sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { createChunkedMessage, formatNumber, resolveInvite, sorter, verboseUserMention } from "../../../utils";
import { botControlCmd } from "../types";
import { GuildArchives } from "../../../data/GuildArchives";
import moment from "moment-timezone";
const sortProps = {
totalTime: "TOTAL TIME",
averageTime: "AVERAGE TIME",
count: "SAMPLES",
};
export const ProfilerDataCmd = botControlCmd({
trigger: ["profiler_data"],
permission: "can_performance",
signature: {
filter: ct.string({ required: false }),
sort: ct.string({ option: true, required: false }),
},
async run({ pluginData, message: msg, args }) {
if (args.sort === "samples") {
args.sort = "count";
}
const sortProp = args.sort && sortProps[args.sort] ? args.sort : "totalTime";
const headerInfoItems = [`sorted by ${sortProps[sortProp]}`];
const profilerData = pluginData.getKnubInstance().profiler.getData();
let entries = Object.entries(profilerData);
entries.sort(sorter((entry) => entry[1][sortProp], "DESC"));
if (args.filter) {
entries = entries.filter(([key]) => key.includes(args.filter));
headerInfoItems.push(`matching "${args.filter}"`);
}
const formattedEntries = entries.map(([key, data]) => {
const dataLines = [
["Total time", `${Math.round(data.totalTime)} ms`],
["Average time", `${Math.round(data.averageTime)} ms`],
["Samples", data.count],
];
return `${key}\n${dataLines.map((v) => ` ${v[0]}: ${v[1]}`).join("\n")}`;
});
const formatted = `Profiler data, ${headerInfoItems.join(", ")}:\n\n${formattedEntries.join("\n\n")}`;
const archives = GuildArchives.getGuildInstance("0");
const archiveId = await archives.create(formatted, moment().add(1, "hour"));
const archiveUrl = archives.getUrl(getBaseUrl(pluginData), archiveId);
msg.channel.send(`Link: ${archiveUrl}`);
},
});