debug: more profiling for Automod
This commit is contained in:
parent
53d7491c1b
commit
f582640e8e
2 changed files with 28 additions and 0 deletions
|
@ -7,6 +7,7 @@ import { availableTriggers } from "../triggers/availableTriggers";
|
||||||
import { AutomodContext, AutomodPluginType } from "../types";
|
import { AutomodContext, AutomodPluginType } from "../types";
|
||||||
import { checkAndUpdateCooldown } from "./checkAndUpdateCooldown";
|
import { checkAndUpdateCooldown } from "./checkAndUpdateCooldown";
|
||||||
import { performance } from "perf_hooks";
|
import { performance } from "perf_hooks";
|
||||||
|
import { calculateBlocking } from "../../../utils/easyProfiler";
|
||||||
|
|
||||||
export async function runAutomod(pluginData: GuildPluginData<AutomodPluginType>, context: AutomodContext) {
|
export async function runAutomod(pluginData: GuildPluginData<AutomodPluginType>, context: AutomodContext) {
|
||||||
const userId = context.user?.id || context.member?.id || context.message?.user_id;
|
const userId = context.user?.id || context.member?.id || context.message?.user_id;
|
||||||
|
@ -53,12 +54,20 @@ export async function runAutomod(pluginData: GuildPluginData<AutomodPluginType>,
|
||||||
const triggerStartTime = performance.now();
|
const triggerStartTime = performance.now();
|
||||||
|
|
||||||
const trigger = availableTriggers[triggerName];
|
const trigger = availableTriggers[triggerName];
|
||||||
|
const getBlockingTime = calculateBlocking();
|
||||||
matchResult = await trigger.match({
|
matchResult = await trigger.match({
|
||||||
ruleName,
|
ruleName,
|
||||||
pluginData,
|
pluginData,
|
||||||
context,
|
context,
|
||||||
triggerConfig,
|
triggerConfig,
|
||||||
});
|
});
|
||||||
|
const blockingTime = getBlockingTime();
|
||||||
|
pluginData
|
||||||
|
.getKnubInstance()
|
||||||
|
.profiler.addDataPoint(
|
||||||
|
`automod:${pluginData.guild.id}:${ruleName}:triggers:${triggerName}:blocking`,
|
||||||
|
blockingTime,
|
||||||
|
);
|
||||||
|
|
||||||
if (matchResult) {
|
if (matchResult) {
|
||||||
contexts = [context, ...(matchResult.extraContexts || [])];
|
contexts = [context, ...(matchResult.extraContexts || [])];
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { Profiler } from "knub/dist/Profiler";
|
import { Profiler } from "knub/dist/Profiler";
|
||||||
import { performance } from "perf_hooks";
|
import { performance } from "perf_hooks";
|
||||||
|
import { SECONDS } from "../utils";
|
||||||
|
|
||||||
export const startProfiling = (profiler: Profiler, key: string) => {
|
export const startProfiling = (profiler: Profiler, key: string) => {
|
||||||
const startTime = performance.now();
|
const startTime = performance.now();
|
||||||
|
@ -7,3 +8,21 @@ export const startProfiling = (profiler: Profiler, key: string) => {
|
||||||
profiler.addDataPoint(key, performance.now() - startTime);
|
profiler.addDataPoint(key, performance.now() - startTime);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const calculateBlocking = (coarseness = 10) => {
|
||||||
|
let last = performance.now();
|
||||||
|
let result = 0;
|
||||||
|
const interval = setInterval(() => {
|
||||||
|
const now = performance.now();
|
||||||
|
const blockedTime = Math.max(0, now - last - coarseness);
|
||||||
|
result += blockedTime;
|
||||||
|
last = now;
|
||||||
|
}, coarseness);
|
||||||
|
|
||||||
|
setTimeout(() => clearInterval(interval), 10 * SECONDS);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
clearInterval(interval);
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue