UNPKG

express-profiler

Version:
34 lines (26 loc) 885 B
/** * Created by lv on 2017/6/6. */ 'use strict'; var profiler = require('v8-profiler'); var fs=require('fs'); var moment=require('moment'); exports.profile=function (app,option) { app.use('/cpuProfiler',function (req,res,next) { var filePath=option.filepath; var fileName=moment(new Date()).format("YYYYMMDDHHmmss")+"profile.json"; var fullPath=filePath+"/"+fileName; profiler.startProfiling(option.name, true); setTimeout(function () { var profile1 = profiler.stopProfiling(); profile1.export(function(error, result) { fs.writeFileSync(fullPath, result); profile1.delete(); }); },option.timeout); res.status(200).send({ 'timeout':option.timeout, 'filePath':fullPath }); }); };