Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. # dtrace-provider - Native DTrace providers for Node.js apps.
  2. This extension allows you to create native DTrace providers for your
  3. Node.js applications. That is, to create providers and probes which
  4. expose information specific to your application, rather than
  5. information about the node runtime.
  6. You could use this to expose high-level information about the inner
  7. workings of your application, or to create a specific context in which
  8. to look at information from other runtime or system-level providers.
  9. The provider is not created in the usual way, by declaring it and then
  10. changing the build process to include it, but instead dynamically at
  11. runtime. This is done entirely in-process, and there is no background
  12. compiler or [dtrace(1M)](https://illumos.org/man/1M/dtrace) invocation.
  13. The process creating the provider need not run as root.
  14. ## INSTALL
  15. $ npm install dtrace-provider
  16. ## EXAMPLE
  17. Here's a simple example of creating a provider:
  18. ```javascript
  19. var d = require('dtrace-provider');
  20. var dtp = d.createDTraceProvider("nodeapp");
  21. var p1 = dtp.addProbe("probe1", "int", "int");
  22. var p2 = dtp.addProbe("probe2", "char *");
  23. dtp.enable();
  24. ```
  25. Probes may be fired via the provider object:
  26. ```javascript
  27. dtp.fire("probe1", function() {
  28. return [1, 2];
  29. });
  30. dtp.fire("probe2", function() {
  31. return ["hello, dtrace via provider", "foo"];
  32. });
  33. ```
  34. or via the probe objects themselves:
  35. ```javascript
  36. p1.fire(function() {
  37. return [1, 2, 3, 4, 5, 6];
  38. });
  39. p2.fire(function() {
  40. return ["hello, dtrace via probe", "foo"];
  41. });
  42. ```
  43. Note that `.fire()` takes a callback that returns the arguments to be
  44. provided when the DTrace probe actually fires. This allows you to call
  45. `.fire()` unconditionally when you want to fire the probe, but the
  46. callback will be invoked only when the DTrace probe is actually
  47. enabled. This allows you to create probes whose arguments might be
  48. expensive to construct, and only do any work when the probe is
  49. actually enabled. (Examples might include converting a large object to
  50. a string representation or gathering large amounts of information.)
  51. In some cases, creating a new closure to pass to `.fire()` each time
  52. it's called may introduce unwanted overhead. For extremely
  53. CPU-intensive or memory-conscious workloads, you can avoid this by
  54. lifting the closures for your hot probes into an outer scope. You can
  55. then supply arguments to that function as additional arguments to
  56. `.fire()`. As an example, you can convert the following program:
  57. ```javascript
  58. function manipulateObj(largeObj) {
  59. var count = 0;
  60. var name = null;
  61. ...
  62. p1.fire(function () {
  63. return [count, keyToValue(name), JSON.stringify(largeObj)];
  64. });
  65. }
  66. ```
  67. Into this one:
  68. ```javascript
  69. function f(a, b, c) {
  70. return [a, keyToValue(b), JSON.stringify(c)];
  71. }
  72. function manipulateObj(largeObj) {
  73. var count = 0;
  74. var name = null;
  75. ...
  76. p1.fire(f, count, name, largeObj);
  77. }
  78. ```
  79. Be careful to avoid passing `.fire()` additional arguments that are
  80. themselves expensive to construct, as that undermines the design goal
  81. here: minimizing the effect of disabled probes.
  82. This example creates a provider called "nodeapp", and adds two
  83. probes. It then enables the provider, at which point the provider
  84. becomes visible to DTrace.
  85. The probes are then fired, which produces this output:
  86. $ sudo dtrace -Z -n 'nodeapp*:::probe1{ trace(arg0); trace(arg1) }' \
  87. -n 'nodeapp*:::probe2{ trace(copyinstr(arg0)); }'
  88. dtrace: description 'nodeapp*:::probe1' matched 0 probes
  89. dtrace: description 'nodeapp*:::probe2' matched 0 probes
  90. CPU ID FUNCTION:NAME
  91. 1 123562 func:probe1 1 2
  92. 1 123563 func:probe2 hello, dtrace
  93. Arguments are captured by a callback only executed when the probe is
  94. enabled. This means you can do more expensive work to gather arguments.
  95. The maximum number of arguments supported is 32.
  96. Available argument types are "int", for integer numeric values,
  97. "char *" for strings, and "json" for objects rendered into JSON strings.
  98. Arguments typed as "json" will be created as "char *" probes in
  99. DTrace, but objects passed to these probe arguments will be
  100. automatically serialized to JSON before being passed to DTrace. This
  101. feature is best used in conjunction with the json() D subroutine, but
  102. is available whether or not the platform supports it.
  103. # create a json probe:
  104. var dtp = d.createDTraceProvider("nodeapp");
  105. var p1 = dtp.addProbe("j1", "json");
  106. dtp.enable();
  107. p1.fire(function() { return { "foo": "bar" }; });
  108. # on a platform supporting json():
  109. $ sudo dtrace -Z -n 'nodeapp*:::j1{ this->j = copyinstr(arg0); \
  110. trace(json(this->j, "foo")) }'
  111. dtrace: description 'nodeapp$target:::j1' matched 0 probes
  112. CPU ID FUNCTION:NAME
  113. 0 68712 j1:j1 bar
  114. ## PLATFORM SUPPORT
  115. This libusdt-based Node.JS module supports 64 and 32 bit processes on
  116. Mac OS X and Solaris-like systems such as illumos or SmartOS. As more
  117. platform support is added to libusdt, those platforms will be
  118. supported by this module. See libusdt's status at:
  119. https://github.com/chrisa/libusdt#readme
  120. When using Mac OS X, be aware that as of 10.11 (El Capitan), DTrace use
  121. is restricted, and you'll probably want to
  122. [disable SIP](http://internals.exposed/blog/dtrace-vs-sip.html) to
  123. effectively use DTrace.
  124. FreeBSD 10 and 11 are also supported, but you'll need to make sure that
  125. you have the DTrace headers installed in `/usr/src` otherwise libusdt
  126. won't be able to compile. You can
  127. [clone them using SVN](https://www.freebsd.org/doc/handbook/svn.html),
  128. or find the correct `src.txz`
  129. [here](http://ftp.freebsd.org/pub/FreeBSD/releases/) and extract that.
  130. Also note that FreeBSD 10 is restricted to only 4 working arguments per
  131. probe.
  132. Platforms not supporting DTrace (notably, Linux and Windows) may
  133. install this module without building libusdt, with a stub no-op
  134. implementation provided for compatibility. This allows cross-platform
  135. npm modules to embed probes and include a dependency on this module.
  136. GNU Make is required to build libusdt; the build scripts will look for
  137. gmake in `PATH` first, and then for make.
  138. ### TROUBLESHOOTING BUILD ISSUES
  139. If compilation fails during installation on platforms with DTrace, then
  140. the library will fall back to the stub implementation that does nothing.
  141. To force an installation failure when compiling fails, set the environment
  142. variable `NODE_DTRACE_PROVIDER_REQUIRE` to `hard`:
  143. ```shell
  144. $ NODE_DTRACE_PROVIDER_REQUIRE=hard npm install
  145. ```
  146. This will then show you the output of the build process so you can see at
  147. which point it's having an issue. Common issues are:
  148. - Missing a C/C++ compiler toolchain for your platform.
  149. - `python` is Python 3 instead of Python 2; run `npm config set python python2.7`
  150. (or similar) to set the Python binary npm uses.
  151. - On OS X you may need to agree to the XCode license if that's the compiler
  152. toolchain you're using. This will usually manifest with an error like
  153. `Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo.`
  154. To accept the license, you can run `sudo xcodebuild -license`.
  155. Once you've found and fixed the issue, you can run `npm rebuild` to rerun
  156. the lifecycle scripts.
  157. ## CAVEATS
  158. There is some overhead to probes, even when disabled. Probes are
  159. already using the "is-enabled" feature of DTrace to control execution
  160. of the arguments-gathering callback, but some work still needs to be
  161. done before that's checked. This overhead should not be a problem
  162. unless probes are placed in particularly hot code paths.
  163. ## CONTRIBUTING
  164. To clone the project's source code:
  165. $ git clone --recursive https://github.com/chrisa/node-dtrace-provider.git
  166. For issues, please use the [GitHub issue tracker](https://github.com/chrisa/node-dtrace-provider/issues)
  167. linked to the repository. GitHub pull requests are very welcome.
  168. ## RUNNING THE TESTS
  169. ```shell
  170. $ npm install
  171. $ sudo ./node_modules/.bin/tap --tap test/*.test.js
  172. ```
  173. ## OTHER IMPLEMENTATIONS
  174. This node extension is derived from the ruby-dtrace gem, via the Perl
  175. module Devel::DTrace::Provider, both of which provide the same
  176. functionality to those languages.