From 66b517b60a32ea5c620aaa7dfeba2ecc1416f880 Mon Sep 17 00:00:00 2001 From: Fred Tingaud <95592999+frederic-tingaud-sonarsource@users.noreply.github.com> Date: Thu, 7 Jul 2022 19:28:54 +0200 Subject: [PATCH] Get statistics on tools usage per language / compiler (#3851) --- lib/tooling/base-tool.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/tooling/base-tool.js b/lib/tooling/base-tool.js index 96d21fe70..b9509cdd3 100755 --- a/lib/tooling/base-tool.js +++ b/lib/tooling/base-tool.js @@ -24,12 +24,15 @@ import path from 'path'; +import PromClient from 'prom-client'; import _ from 'underscore'; import * as exec from '../exec'; import {logger} from '../logger'; import * as utils from '../utils'; +const countersPerTool = {}; + export class BaseTool { constructor(toolInfo, env) { this.tool = toolInfo; @@ -37,6 +40,15 @@ export class BaseTool { this.tool.exclude = this.tool.exclude ? this.tool.exclude.split(':') : []; this.addOptionsToToolArgs = true; this.parseOutput = utils.parseOutput; + + const toolName = this.tool.name; + if (toolName && !(toolName in countersPerTool)) { + countersPerTool[toolName] = new PromClient.Counter({ + name: `${toolName.replaceAll(/\W/g, '_').toLowerCase()}_compilation_total`, + help: `Number of compilations with ${toolName} active`, + labelNames: ['language', 'compiler'], + }); + } } getId() { @@ -121,6 +133,12 @@ export class BaseTool { } async runTool(compilationInfo, inputFilepath, args, stdin /*, supportedLibraries*/) { + if (this.tool.name) { + countersPerTool[this.tool.name].inc({ + language: compilationInfo.compiler.lang, + compiler: compilationInfo.compiler.name, + }); + } let execOptions = this.getDefaultExecOptions(); if (inputFilepath) execOptions.customCwd = path.dirname(inputFilepath); execOptions.input = stdin;