1 1.1 christos ************************************************************************** 2 1.1 christos * The following are notes regarding the overheads of running DTrace. 3 1.1 christos * 4 1.1 christos * $Id: ALLoverhead.txt,v 1.1.1.1 2015/09/30 22:01:09 christos Exp $ 5 1.1 christos * 6 1.1 christos * COPYRIGHT: Copyright (c) 2007 Brendan Gregg. 7 1.1 christos ************************************************************************** 8 1.1 christos 9 1.1 christos 10 1.1 christos The following are notes regarding the overheads of running DTrace. 11 1.1 christos 12 1.1 christos * What are the overheads of running DTrace? 13 1.1 christos 14 1.1 christos Often negligible. 15 1.1 christos 16 1.1 christos It depends what the DTrace script does, in particular, the frequency of 17 1.1 christos events that it is tracing. 18 1.1 christos 19 1.1 christos The following tips should explain what the overheads probably are, 20 1.1 christos 21 1.1 christos - if your script traces less than 1000 events per second, then the overhead 22 1.1 christos is probably negligible. ie, less than 0.1% CPU. 23 1.1 christos - if your script traces more than 100,000 events per second, then the 24 1.1 christos overhead will start to be significant. If you are tracing kernel events, 25 1.1 christos then perhaps this could be 10% per CPU. If you are tracing user land 26 1.1 christos application events, then the overhead can be greater than 30% per CPU. 27 1.1 christos - if your script produes pages of output, then the CPU cost of drawing 28 1.1 christos this output to the screen and rendering the fonts is usually far greater 29 1.1 christos than DTrace itself. Redirect the output of DTrace to a file in /tmp 30 1.1 christos ("-o" or ">"). 31 1.1 christos - a ballpark figure for the overhead of a DTrace probe would be 500 ns. 32 1.1 christos This can be much less (kernel only), or much more (many user to kerel 33 1.1 christos copyin()s); I've provided it to give you a very rough idea. Of course, 34 1.1 christos as CPUs become faster, this overhead will become smaller. 35 1.1 christos 36 1.1 christos If overheads are a concern - then perform tests to measure their magnitude 37 1.1 christos for both your workload and the scripts applied, such as benchmarks with 38 1.1 christos and without DTrace running. Also read the scripts you are using, and 39 1.1 christos consider how frequent the probes will fire, and if you can customise the 40 1.1 christos script to reduce the frequency of probes. 41 1.1 christos 42 1.1 christos For example, scripts that trace, 43 1.1 christos 44 1.1 christos pid$target:::entry, 45 1.1 christos pid$target:::return 46 1.1 christos 47 1.1 christos would usually cause significant performance overhead, since they fire two 48 1.1 christos probes for every function called (and can easily reach 100,000 per second). 49 1.1 christos You could reduce this by modifying the script to only trace the libraries 50 1.1 christos you are interested in. For example, if you were only interested in 51 1.1 christos libsocket and libnsl, then change the above lines wherever they appeared to, 52 1.1 christos 53 1.1 christos pid$target:libsocket::entry, 54 1.1 christos pid$target:libsocket::return, 55 1.1 christos pid$target:libnsl::entry, 56 1.1 christos pid$target:libnsl::return 57 1.1 christos 58 1.1 christos and you may notice the overheads are significantly reduced (especially anytime 59 1.1 christos you drop libc and libdl). To go further, only list functions of interest, 60 1.1 christos 61 1.1 christos pid$target:libsocket:connect:entry, 62 1.1 christos pid$target:libsocket:connect:return, 63 1.1 christos pid$target:libsocket:listen:entry, 64 1.1 christos pid$target:libsocket:listen:return, 65 1.1 christos [...] 66 1.1 christos 67 1.1 christos There are additional notes in Docs/Faq about the DTraceToolkit's scripts 68 1.1 christos and performance overhead. 69 1.1 christos 70 1.1 christos 71 1.1 christos * When are the overheads a problem? 72 1.1 christos 73 1.1 christos When they are significant (due to frequent events), and you are tracing 74 1.1 christos in a production environment that is sensitive to additional CPU load. 75 1.1 christos 76 1.1 christos Overheads should be considered if you are measuring times (delta, elapsed, 77 1.1 christos on-CPU, etc) for performance analysis. In practise, overheads aren't 78 1.1 christos that much of a problem -- the script will either identify your issues 79 1.1 christos correctly (great), or not (keep looking). Any it is usually easy to quickly 80 1.1 christos confirm what DTrace does find by using other tools, or by hacking quick 81 1.1 christos code changes. You might be using DTrace output that you know has a 82 1.1 christos significant margin of error - but that becomes moot after you prove that 83 1.1 christos the performance fix works through benchmarking a quick fix. 84 1.1 christos 85 1.1 christos At the end of the day, if DTrace helps find real measurable performance wins 86 1.1 christos (and it should), then it has been successful. 87 1.1 christos 88 1.1 christos 89 1.1 christos * When are overheads not a problem? 90 1.1 christos 91 1.1 christos When the script is not tracing extreamly frequent events. 92 1.1 christos 93 1.1 christos Also, when you are in development and tracing events for troubleshooting 94 1.1 christos purposes (args to functions, for example), DTrace overheads are usually 95 1.1 christos not an issue at all. 96 1.1 christos 97