当前位置:首页 > Web开发 > 正文

() = { console. log( `go to :8080/ to generate traffic`) })

2024-03-31 Web开发

昨天有概略介绍多0x 火焰图,以下是一个简单的试用

环境筹备

项目布局

├── README.md

├── ab.sh

├── app.js

├── package.json

└── yarn.lock

代码说明
flame script 为使用flamebearer 工具,all-in-one 为使用0x
pacakge.json

 

{

 "name": "nodejs-flame-graph",

 "version": "1.0.0",

 "main": "app.js",

 "license": "MIT",

 "scripts": {

   "start": "node --perf-basic-prof-only-functions app.js",

   "pprof": "node --prof app.js",

   "all-in-one":"0x app.js",

   "flame": "node --prof-process --preprocess -j isolate*.log | flamebearer"

},

 "dependencies": {

   "express": "^4.14.1",

   "fast-levenshtein": "^2.0.6"

},

 "devDependencies": {

   "0x": "^4.9.1",

   "flamebearer": "^1.1.3"

}

}

 

app.js 一个express 代码

//app.js

const express = require(‘express‘);

const console = require(‘console‘);

const levenshtein = require(‘fast-levenshtein‘);

var arr=[];

const HOW_OBVIOUS_THE_FLAME_GRAPH_SHOULD_BE_ON_SCALE_1_TO_100 = 10;

?

const someFakeModule = (function someFakeModule () {

return {

 calculateStringDistance (a, b) {

   return levenshtein.get(a, b, {

   useCollator: true

  })

}

}

})()

?

const app = express();

?

app.get(‘/‘, (req, res) => {

 res.send(`

 <h2>Take a look at the network tab in devtools</h2>

 <script>

   function loops(func) {

   return func().then(_ => setTimeout(loops, 20, func))

   }

   loops(_ => fetch(‘api/tick‘))

 </script>\

 `)

});

?

app.get(‘/api/tick‘, (req, res) => {

 arr.push({name:‘Shubham‘});

 Promise.resolve(‘asynchronous flow will make our stacktrace more realistic‘.repeat(HOW_OBVIOUS_THE_FLAME_GRAPH_SHOULD_BE_ON_SCALE_1_TO_100))

.then(text => {

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/32241.html