clinicjs / node-clinic

Clinic.js diagnoses your Node.js performance issues
https://clinicjs.org
MIT License
5.68k stars 125 forks source link

Clini is not generating html report when process end (Ctrl + C) #336

Open Rosnaldo opened 2 years ago

Rosnaldo commented 2 years ago

Clinic should generate the html file by default when I press Ctrl + C For some reason it is having a random behavior. Sometimes generate, sometimes not. I' am using babel transpiler and runing dist/index.js. Also I suspect that the process.on('SIGINT could be some how been interfering since the trigger is the command Ctrl + C

Runing commands:

To run clinic

npx babel-node ./src/tests/utils/clinic.js -- --doctor

To run cannon

npx babel-node ./src/tests/utils/autocannon.js

versions:

clinic: v11.0.0 autocannon: ^7.0.1

clinic.js

'use strict';

const path = require('path');
const ClinicDoctor = require('@clinic/doctor');
const ClinicBubbleprof = require('@clinic/bubbleprof');
const ClinicFlame = require('@clinic/flame');
const log = require('../logger').default;
const argv = require('./argv');

const command = ['node', path.join(process.cwd(), 'dist', 'index.js')];

const trackers = {
  doctor: ClinicDoctor,
  bubbleprof: ClinicBubbleprof,
  flame: ClinicFlame,
};

const args = argv();
const Tester = Object.entries(trackers).reduce((result, [key, cls]) => {
  return args[String(key).toLowerCase()] ? cls : result;
}, null);
if (!Tester) {
  throw new Error(
    'Please specify a tester between [flame, doctor, bubbleprof]'
  );
}

const doctor = new Tester({
  ...args,
  dest: '.clinic',
});

doctor.collect(command, (err, filepath) => {
  if (err) throw err;
  log.trace('Parsing collected data');
  doctor.visualize(filepath, filepath + '.html', (err2) => {
    if (err2) throw err2;
    log.info('Generated %s', path.join(process.cwd(),filepath, filepath + '.html'));
  });
});

/dist/index.js

'use strict';

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _log4js = _interopRequireDefault(require("log4js"));

var _httpTerminator = require("http-terminator");

var _config = _interopRequireDefault(require("./src/config/config"));

var _express = _interopRequireDefault(require("./src/middleware/express"));

var _cron = _interopRequireDefault(require("./src/middleware/cron"));

var _socketIO = require("./src/middleware/socketIO");

require("./src/middleware/db");

var start = new Date();
global.Promise = require('bluebird');

_log4js["default"].configure(_config["default"].log4js);

if (!process.env.LANG_ENV) {
  process.env.LANG_ENV = 'pt-BR';
}

var log = _log4js["default"].getLogger('startup');

var app = (0, _express["default"])();
var server = app.listen(_config["default"].port);
var httpTerminator = (0, _httpTerminator.createHttpTerminator)({
  server: server
});
process.on('SIGINT', function () {
  log.info('SIGINT signal received.');
  log.log('Closing http server.');
  httpTerminator.terminate();
  log.log('Http server closed.');
});
process.on('SIGTERM', function () {
  log.info('SIGTERM signal received, running graceful shutdown in 15s');
  log.log('Closing http server.');
  setTimeout(function () {
    httpTerminator.terminate();
    log.log('Http server closed.');
  }, 15000);
});
(0, _socketIO.initSocketIO)(server);
var _default = {
  app: app,
  server: server
};
exports["default"] = _default;
(0, _cron["default"])();
log.info('Bootstrap: %dms', new Date() - start);
log.info("RESTful API COODESH running in http://localhost:".concat(_config["default"].port));
RafaelGSS commented 2 years ago

Could you create a minimal reproducible code? Reference: https://stackoverflow.com/help/minimal-reproducible-example.