import { Request, Response } from "express"; import { config } from "../utils/config"; import Inspector from "inspector-api"; import { BaseController } from "./BaseController"; import logger from "../utils/logger"; export class ProfilerController extends BaseController { private inspector: Inspector; constructor() { super(); this.get("/profile", this.startProfiling); this.inspector = new Inspector({ storage: { type: "s3", bucket: config.PROFILER_S3_BUCKET, dir: "inspector", }, }); } async startProfiling(req: Request, res: Response) { if (req.get("authorization") !== "static Kdfuo902FDSMMnsipam") { res.status(401).send(); return; } try { await this.inspector.profiler.enable(); await this.inspector.profiler.start(); logger.info("profiler started"); setTimeout(async () => { try { logger.info("stopping profiler"); await this.inspector.profiler.stop(); this.inspector.profiler.disable(); } catch (e: any) { logger.error(e, "error stopping profiler " + e.name + " " + e.message); } }, 300000); res.status(200).send("profiler started"); } catch (err: any) { logger.error(err); res.status(500).send(); } } }