Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Easy CPU Profiling
Search
Tom Gallacher
February 27, 2014
Programming
3
16k
Easy CPU Profiling
My LNUG slides from the 26th Feburary 2014, Easy and hardcore CPU profiling in #nodejs
Tom Gallacher
February 27, 2014
Tweet
Share
More Decks by Tom Gallacher
See All by Tom Gallacher
Dis.io
tomgco
3
280
Other Decks in Programming
See All in Programming
[初登壇@jAZUG]アプリ開発者が気になるGoogleCloud/Azure+wasm/wasi
asaringo
0
110
2度もゼロから書き直して、やっとブラウザでぬるぬる動くAIに辿り着いた話
tomoino
0
150
Spring gRPC で始める gRPC 入門 / Introduction to gRPC with Spring gRPC
mackey0225
2
470
ワイがおすすめする新潟の食 / 20250530phpconf-niigata-eve
kasacchiful
0
300
無関心の谷
kanayannet
0
160
Bytecode Manipulation 으로 생산성 높이기
bigstark
1
190
Datadog RUM 本番導入までの道
shinter61
1
210
PT AI без купюр
v0lka
0
220
セキュリティマネジャー廃止とクラウドネイティブ型サンドボックス活用
kazumura
1
160
try-catchを使わないエラーハンドリング!? PHPでResult型の考え方を取り入れてみよう
kajitack
3
480
TypeScript LSP の今までとこれから
quramy
1
480
〜可視化からアクセス制御まで〜 BigQuery×Looker Studioで コスト管理とデータソース認証制御する方法
cuebic9bic
3
320
Featured
See All Featured
VelocityConf: Rendering Performance Case Studies
addyosmani
329
24k
Into the Great Unknown - MozCon
thekraken
39
1.8k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
161
15k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
Intergalactic Javascript Robots from Outer Space
tanoku
271
27k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
Adopting Sorbet at Scale
ufuk
77
9.4k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
123
52k
KATA
mclloyd
29
14k
Automating Front-end Workflow
addyosmani
1370
200k
YesSQL, Process and Tooling at Scale
rocio
172
14k
GraphQLとの向き合い方2022年版
quramy
46
14k
Transcript
Hello!
Tom Gallacher ! Aka: @tomgco
Tom Gallacher ! Aka: @tomgco Me!
image by @substack Easy CPU profiling in node
What to expect
What to expect
What to expect ! function init(cb) { for (var i
= 1e8 - 1; i >= 0; i--) { var a = 16 + 87 a = a - 10 } cb() }
What to expect
var http = require(‘http') ! http.createServer(function (req, res) { !
res.writeHead(200, {'Content-Type': ‘text/plain’}) ! res.end('Hello World\n') ! }).listen(1337, '127.0.0.1') ! console.log('Server running at http://127.0.0.1:1337/')
None
What?
$ dtrace -n 'profile-97/pid == 1337 && arg1/{ @[jstack(150, 8000)]
= count(); } tick-60s { exit(0); }' > stacks.out $ stackvis dtrace flamegraph-svg < stacks.out > stacks.svg $ npm install -g stackvis Flame-graph using stack-vis
None
Illumos-based system required Requires sudo (utilises dtrace) Understanding of libuv
required Downfalls: Well not really, it can help
What about SaaS’s?
StrongOps $ npm install -g strong-cli $ open http://strongloop.com/ops/dashboard $
slc strongops --register $ slc example $ cd sls-sample-app
None
NodeTime $ npm install --save nodetime $ node -e 'require('nodetime').profile(
{ accountKey: your_account_key })' $ open https://nodetime.com/apps
None
Don’t fancy sending data to third parties? $ npm install
-g webkit-devtools-agent $ npm install -g bugger $ npm install -g node-inspector -- Upcoming --
None
PAIN!
v0.11
$ npm install --save-dev cpu-profiler $ npm install --save-dev chrome-cpu-profiler
Roll your own (thats what I did)
CPU-Profiler Originally by Danny Coates - https://github.com/dannycoates Updated by StrongLoop
- https://github.com/strongloop New features by me! - https://github.com/tomgco
CPU-Profiler var profiler = require('cpu-profiler') profiler.startProfiling([name], true) var cpuProfile =
profiler.stopProfiling([name]) // …suspected code bottleneck to profile
CPU-Profiler { samplesCount: 0 , endTime: 1393368793528908 , startTime: 1393368789344919
, topRoot: { scriptId: 0 , hitCount: 0 , childrenCount: 2 , id: 1 , callUid: 2833936552 , lineNumber: 0 , bailoutReason: '' , scriptName: '' , functionName: '(root)' , getChild: [Function: getChild] } , uid: 1 , title: 'a' , delete: [Function: delete] , getSample: [Function: getSample] }
Chrome-CPU-Profiler var profiler = require('chrome-cpu-profiler') profiler.startProfiling('cpu-block') var data = profiler.stopProfiling('cpu-block')
// …suspected code bottleneck to profile profiler.writeFile(data)
None
None
None
None
None
USES
image by @substack Easy CPU profiling in node
V8 Tools $ node --prof app.js $ git clone
[email protected]
:v8/v8.git
$ ./tools/mac-tick-processor ~/v8.log > out.prof $ cat out.prof $ cd v8; git checkout 3.20.14.1 #or relevant v8 version
Statistical profiling result from v8.log, (395 ticks, 1 unaccounted, 0
excluded). ! [JavaScript]: ticks total nonlib name 181 45.8% 61.6% LazyCompile: *init /Users/tomg/Projects/nodejs/chrome-cpu-profiler/ 101 25.6% 34.4% LazyCompile: *initInner /Users/tomg/Projects/nodejs/chrome-cpu-prof 2 0.5% 0.7% RegExp: ^(\\/?|)([\\s\\S]*?)((?:\\.{1\,2}|[^\\/]+?|)(\\.[^.\\/]*|)) 2 0.5% 0.7% LazyCompile: *pre /Users/tomg/Projects/nodejs/chrome-cpu-profiler/e 1 0.3% 0.3% Stub: KeyedStoreElementStub 1 0.3% 0.3% Stub: FunctionPrototypeStub 1 0.3% 0.3% Stub: BinaryOpStub_ADD_ReuseLeft(String*String->String) 1 0.3% 0.3% LazyCompile: ~substr native string.js:748:22 1 0.3% 0.3% LazyCompile: ~Buffer.isEncoding buffer.js:126:29 1 0.3% 0.3% KeyedCallMegamorphic: args_count: 2 1 0.3% 0.3% Builtin: ArgumentsAdaptorTrampoline
! [GC]: ticks total nonlib name 3 0.8% ! [Bottom
up (heavy) profile]: Note: percentage shows a share of a particular caller in the total amount of its parent calls. Callers occupying less than 2.0% are not shown. ! ticks parent name 181 45.8% LazyCompile: *init /Users/tomg/Projects/nodejs/chrome-cpu-profiler/example/cp 91 50.3% LazyCompile: ~preInner /Users/tomg/Projects/nodejs/chrome-cpu-profiler/exam 91 100.0% LazyCompile: *pre /Users/tomg/Projects/nodejs/chrome-cpu-profiler/example 91 100.0% LazyCompile: ~bootstrap /Users/tomg/Projects/nodejs/chrome-cpu-profiler 91 100.0% Function: ~<anonymous> /Users/tomg/Projects/nodejs/chrome-cpu-profile 91 100.0% LazyCompile: ~Module._compile module.js:367:37 90 49.7% LazyCompile: ~preInner /Users/tomg/Projects/nodejs/chrome-cpu-profiler/exam 90 100.0% LazyCompile: *pre /Users/tomg/Projects/nodejs/chrome-cpu-profiler/example 90 100.0% LazyCompile: ~initInner /Users/tomg/Projects/nodejs/chrome-cpu-profiler 90 100.0% LazyCompile: *init /Users/tomg/Projects/nodejs/chrome-cpu-profiler/ex 90 100.0% LazyCompile: ~preInner /Users/tomg/Projects/nodejs/chrome-cpu-profi ! 101 25.6% LazyCompile: *initInner /Users/tomg/Projects/nodejs/chrome-cpu-profiler/examp 101 100.0% LazyCompile: *init /Users/tomg/Projects/nodejs/chrome-cpu-profiler/example/ 101 100.0% LazyCompile: ~preInner /Users/tomg/Projects/nodejs/chrome-cpu-profiler/ex 101 100.0% LazyCompile: *pre /Users/tomg/Projects/nodejs/chrome-cpu-profiler/examp 101 100.0% LazyCompile: ~initInner /Users/tomg/Projects/nodejs/chrome-cpu-profil 101 100.0% LazyCompile: *init /Users/tomg/Projects/nodejs/chrome-cpu-profiler/
" " (compiled) "~" (optimisable) "*" (optimised)
:O
Production
Dtrace $ npm install --save dtrace-provider var d = require('dtrace-provider')
! var dtp = d.createDTraceProvider('nodeapp') var p1 = dtp.addProbe('probe1', 'int', 'int') var p2 = dtp.addProbe('probe2', 'char *') dtp.enable()
Metrics - StatsD - Graphite - Lynx https://github.com/dscape/lynx $ npm
install --save lynx
None
None
Tom Gallacher ! Aka: @tomgco
Q&A
YAY
BYE!