2018-10-24 21:42:33 +08:00
|
|
|
'use strict';
|
|
|
|
|
2018-02-19 22:13:36 +08:00
|
|
|
module.exports.initializeProfilerMiddleware = function initializeProfiler (label) {
|
|
|
|
return function initializeProfilerMiddleware (req, res, next) {
|
|
|
|
if (req.profiler) {
|
|
|
|
req.profiler.start(`sqlapi.${label}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
next();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports.finishProfilerMiddleware = function finishProfiler () {
|
|
|
|
return function finishProfilerMiddleware (req, res, next) {
|
|
|
|
if (req.profiler) {
|
|
|
|
req.profiler.end();
|
|
|
|
req.profiler.sendStats();
|
|
|
|
|
|
|
|
res.header('X-SQLAPI-Profiler', req.profiler.toJSONString());
|
|
|
|
}
|
|
|
|
|
|
|
|
next();
|
|
|
|
};
|
|
|
|
};
|