Learning Dtrace

2,045 views
1,870 views

Published on

pre

0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,045
On SlideShare
0
From Embeds
0
Number of Embeds
13
Actions
Shares
0
Downloads
48
Comments
0
Likes
5
Embeds 0
No embeds

No notes for slide

Learning Dtrace

  1. 1. LearningDtrace2012.11.20Outsider at
  2. 2. DTrace isa comprehensivedynamic tracingframeworkcreated bySun Microsystemsfor troubleshootingkernel andapplication problemson production systemsin real time. http://dtrace.org/blogs/about/dtracepony/
  3. 3. DTrace isa comprehensivedynamic tracingframeworkcreated bySun Microsystemsfor troubleshootingkernel andapplication problemson production systemsin real time. http://dtrace.org/blogs/about/dtracepony/
  4. 4. DTrace isa comprehensivedynamic tracingframeworkcreated bySun Microsystemsfor troubleshootingkernel andapplication problemson production systemsin real time. http://dtrace.org/blogs/about/dtracepony/
  5. 5. DTrace isa comprehensivedynamic tracingframeworkcreated bySun Microsystemsfor troubleshootingkernel andapplication problemson production systemsin real time. http://dtrace.org/blogs/about/dtracepony/
  6. 6. DTrace isa comprehensivedynamic tracingframeworkcreated bySun Microsystemsfor troubleshootingkernel andapplication problemson production systemsin real time. http://dtrace.org/blogs/about/dtracepony/
  7. 7. Bryan CantrillMike ShapiroAdam Leventhal http://www.flickr.com/photos/ghost_of_kuji/370072145
  8. 8. Originally2003 developed for
  9. 9. Open-sourced in 2005 http://www.flickr.com/photos/tinou/171803338
  10. 10. Ported toUnix-like systems http://www.flickr.com/photos/epu/4299657320
  11. 11. MIT Technology Review 2005“Innovators Under 35” http://www2.technologyreview.com/tr35/profile.aspx?trid=91
  12. 12. TechnologyInnovationAwards 2006Gold Winner http://www.dowjones.com/innovation/ei_winners_2006.html
  13. 13. STUG award 2008 https://www.usenix.org/about/stug
  14. 14. Dive into Dtrace
  15. 15. Probe코드가 실행되는 지점동적으로 생성프로덕션에서 사용가능
  16. 16. Probe List: sudo dtrace -l
  17. 17. Probe의 내부 ID
  18. 18. Probe를 제공하는 곳 (ex: syscall, profile)
  19. 19. Unix 모듈이나Probe의 어플리케이션 라이브러리의 이름
  20. 20. Probe가 존재하는 함수의 이름
  21. 21. Probe의 이름
  22. 22. sudo dtrace -l -n PROBE이름
  23. 23. sudo dtrace -l -f FUNCTION
  24. 24. sudo dtrace -l -P PROVIDER
  25. 25. sudo dtrace -l -m MODULE
  26. 26. DScriptD Programming Language
  27. 27. Features.d 확장자컴파일해서 커널레벨에서 실행안전성을 위한 유효성 검사프로덕션에서 안전하게 실행
  28. 28. DScript Output Dtrace User Kernel DProgram
  29. 29. 01 probe-description02 /optional predicate/03 {04 action statements;05 }
  30. 30. provider:module:function:name (ex: syscall:::entry)01 probe-description02 /optional predicate/03 {04 action statements;05 }
  31. 31. 01 probe-description02 /optional predicate/03 {04 action statements;05 } 시스템의 상태를 수집하는 명령문
  32. 32. 01 probe-description02 /optional predicate/03 { 0이 아니거나 true면 action 수행04 action statements;05 }
  33. 33. begin-end.d01 BEGIN02 {03 trace("begin the beguine");04 exit(0);05 }06 END07 {08 trace("thats all...");09 }
  34. 34. begin-end.d01 BEGIN02 {03 trace("begin the beguine");04 exit(0);05 sudo dtrace -s begin-end.d }06 END07 {08 trace("thats all...");09 }
  35. 35. timer.d01 profile:::tick-5sec02 {03 trace("5sec timer");04 }05 profile:::tick-800msec06 {07 trace("800msec timer");08 }
  36. 36. beer.d01 int bottles;02 BEGIN03 { bottles = 5; }04 profile:::tick-1sec05 /bottles >= 0/06 {07 printf("%d bottles on the walln", bottles);08 printf("%d bottles.n", bottles);09 printf("take one down, pass it aroundn");10 printf("%d bottles on the wallnn", bottles);11 bottles--;12 }13 profile:::tick-1sec14 /bottles < 0/15 { exit(0); }16 END17 { printf("thats all..."); }
  37. 37. No Flow Controlno if-elseno loop?: operator is exist
  38. 38. process.d01 proc:::exec-success02 {03 printf("%s", execname);04 }
  39. 39. Aggregate@name[key] = aggfunc(args)@: aggregation’s prefixname: aggregation’s namekey: D expression list (comma-separated)aggfunc: aggregation function
  40. 40. Aggregate Functioncount() : 호출횟수sum(expr) : 표현식의 전체 값avg(expr) : 표현식의 평균min(expr) : 표현식 중 가장 작은 값max(expr) : 표현식 중 가장 큰 값quantize(expr) : 2제곱의 빈도분포lquantize(expr,lower-bound, upper-bound, step-value) : 선형 빈도분포
  41. 41. aggr-count.d01 syscall::read:entry02 {03 @counts[execname] = count();04 }05 profile:::tick-5s06 {07 exit(0);08 }
  42. 42. aggr-quant.d01 syscall::read:entry02 {03 self->ts = timestamp;04 }05 syscall::read:return06 /self->ts/07 {08 delta = timestamp - self->ts;09 @quanttime[execname] = quantize(delta);10 }11 profile:::tick-5s12 {13 exit(0);14 }
  43. 43. Dtracewith Node.js
  44. 44. OS Requirements -Dtrace -ustack helperhttp://www.flickr.com/photos/abandonedhero/3404826467
  45. 45. User-Level Statically Defined TracingUSDTlanded in node v0.6.7
  46. 46. Full featureswork on OpenSolaris http://www.flickr.com/photos/jepoirrier/2043728206
  47. 47. Mac OS Dtraceustack helper
  48. 48. Linux Dtraceustack helper
  49. 49. Windows Dtraceustack helper
  50. 50. node.js is compiled with--with-dtrace http://www.flickr.com/photos/vectorlyme/206472613
  51. 51. “SunOS에서 활성화되지만 다른 시스템에선 동작하지 않는다”
  52. 52. Dtrace with node.json SmartOS of Joyent Demo
  53. 53. server.js01 var http = require(http);02 http.createServer(function(req, res) {03 res.writeHead(200, {04 Content-Type: text/plain05 });06 res.end(Hello Worldn);07 }).listen(8124);0809 console.log(Server running!);
  54. 54. http-server.d01 BEGIN02 {03 printf("%7s %2s %5s %20s (%5s) %8s %s (%s)n",04 "WHO", "FD", "RPORT", "REMOTE", "BUFFR",05 "METHOD", "URL", "FWDFOR");06 }0708 node*:::http-server-request09 {10 printf("+SERVER %2d %5d %20s (%5d) %8s %s (%s)n",11 args[1]->fd, args[1]->remotePort, args[1]->remoteAddress,12 args[1]->bufferSize,13 args[0]->method, args[0]->url, args[0]->forwardedFor);14 }1516 node*:::http-server-response17 {18 printf("-SERVER %2d %5d %20s (%5d)n",19 args[0]->fd, args[0]->remotePort, args[0]->remoteAddress,20 args[0]->bufferSize);21 }
  55. 55. request-count.d01 http-server-request02 {03 @[args[0]->url]=count()04 }
  56. 56. loop.js01 new Error().stack;0203 function main() { func1(); }04 function func1() { func2(); }0506 function func2() {07 (function () {08 for (;;);09 })();10 }11 main();
  57. 57. profile.d01 profile-9702 /execname == "node" && arg1/03 {04 @[jstack(150, 8000)] = count();05 }06 tick-10sec07 {08 exit(0);09 }
  58. 58. stack trace visualizerFlameGraph
  59. 59. http://dtrace.org/blogs/brendan/files/2011/12/mysql-flame.png
  60. 60. node-stackvis $ npm install -g stackvis
  61. 61. Make FrameGraph$ sudo dtrace -s DSCRIPT > INPUT$ stackvis dtrace flamegraph-svg < INPUT > OUTPUT
  62. 62. Alternativeon non-OpenSolarises
  63. 63. node-dtrace-provider https://github.com/chrisa/node-dtrace-provider $ npm install dtrace-provider
  64. 64. 01 var d = require(dtrace-provider);02 var dtp = d.createDTraceProvider(nodeapp);03 var p1 = dtp.addProbe(probe1, int, int);04 var p2 = dtp.addProbe(probe2, char *);05 dtp.enable();
  65. 65. 01 dtp.fire("probe1", function(p) {02 return [1, 2];03 });04 dtp.fire("probe2", function(p) {05 return ["hello, dtrace via provider", "foo"];06 });
  66. 66. Limitationsdata type : int, charmaximum argument : 32
  67. 67. interval.js01 function interval(msg) {02 console.log(msg);03 }0405 setInterval(function() {06 interval(Hello Dtrace);07 }, 1000);
  68. 68. interval.js01 var d = require(dtrace-provider);interval.js02 var dtp =03 d.createDTraceProvider(nodeapp);04 var p2 = dtp.addProbe(echo, char *);0506 function interval(msg) {07 dtp.fire(echo, function () {08 return [msg];09 });10 console.log(msg);11 }12 setInterval(function() {13 interval(Hello Dtrace);14 }, 1000);15 dtp.enable();
  69. 69. interval.d01 nodeapp*:::echo02 {03 trace(copyinstr(arg0));04 }
  70. 70. Thank you~http://blog.outsider.ne.kroutsideris@gmail.com@outsideris

×