Skip to content

Commit 5e825d1

Browse files
GlenTikibnoordhuis
authored andcommitted
tracing: add lttng support for tracing on linux
This commit adds the ability to enable userspace tracing with lttng in io.js. It adds tracepoints for all the equivalent dtrace and ETW tracepoints. To use these tracepoints enable --with-lttng on linux. PR-URL: #702 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Ryan Graham <[email protected]> Reviewed-By: Stephen Belanger <[email protected]>
1 parent b677b84 commit 5e825d1

14 files changed

+602
-2
lines changed

Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,9 @@ jslint:
385385

386386
CPPLINT_EXCLUDE ?=
387387
CPPLINT_EXCLUDE += src/node_dtrace.cc
388-
CPPLINT_EXCLUDE += src/node_dtrace.cc
388+
CPPLINT_EXCLUDE += src/node_lttng.cc
389389
CPPLINT_EXCLUDE += src/node_root_certs.h
390+
CPPLINT_EXCLUDE += src/node_lttng_tp.h
390391
CPPLINT_EXCLUDE += src/node_win32_perfctr_provider.cc
391392
CPPLINT_EXCLUDE += src/queue.h
392393
CPPLINT_EXCLUDE += src/tree.h

configure

+14
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,11 @@ parser.add_option('--with-dtrace',
213213
dest='with_dtrace',
214214
help='build with DTrace (default is true on sunos)')
215215

216+
parser.add_option('--with-lttng',
217+
action='store_true',
218+
dest='with_lttng',
219+
help='build with Lttng (Only available to Linux)')
220+
216221
parser.add_option('--with-etw',
217222
action='store_true',
218223
dest='with_etw',
@@ -524,6 +529,15 @@ def configure_node(o):
524529
else:
525530
o['variables']['node_use_dtrace'] = 'false'
526531

532+
# Enable Lttng if --with-lttng was defined. Use logic similar to
533+
# ETW for windows. Lttng is only available on the Linux platform.
534+
if flavor == 'linux':
535+
o['variables']['node_use_lttng'] = b(options.with_lttng)
536+
elif options.with_lttng:
537+
raise Exception('lttng is only supported on Linux.')
538+
else:
539+
o['variables']['node_use_lttng'] = 'false'
540+
527541
# if we're on illumos based systems wrap the helper library into the
528542
# executable
529543
if flavor == 'solaris':

lib/_http_client.js

+2
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ ClientRequest.prototype.aborted = undefined;
155155

156156
ClientRequest.prototype._finish = function() {
157157
DTRACE_HTTP_CLIENT_REQUEST(this, this.connection);
158+
LTTNG_HTTP_CLIENT_REQUEST(this, this.connection);
158159
COUNTER_HTTP_CLIENT_REQUEST();
159160
OutgoingMessage.prototype._finish.call(this);
160161
};
@@ -386,6 +387,7 @@ function parserOnIncomingClient(res, shouldKeepAlive) {
386387

387388

388389
DTRACE_HTTP_CLIENT_RESPONSE(socket, req);
390+
LTTNG_HTTP_CLIENT_RESPONSE(socket, req);
389391
COUNTER_HTTP_CLIENT_RESPONSE();
390392
req.res = res;
391393
res.req = req;

lib/_http_server.js

+2
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ util.inherits(ServerResponse, OutgoingMessage);
9292

9393
ServerResponse.prototype._finish = function() {
9494
DTRACE_HTTP_SERVER_RESPONSE(this.connection);
95+
LTTNG_HTTP_SERVER_RESPONSE(this.connection);
9596
COUNTER_HTTP_SERVER_RESPONSE();
9697
OutgoingMessage.prototype._finish.call(this);
9798
};
@@ -416,6 +417,7 @@ function connectionListener(socket) {
416417

417418
res.shouldKeepAlive = shouldKeepAlive;
418419
DTRACE_HTTP_SERVER_REQUEST(req, socket);
420+
LTTNG_HTTP_SERVER_REQUEST(req, socket);
419421
COUNTER_HTTP_SERVER_REQUEST();
420422

421423
if (socket._httpMessage) {

lib/net.js

+2
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,7 @@ Socket.prototype.end = function(data, encoding) {
387387
stream.Duplex.prototype.end.call(this, data, encoding);
388388
this.writable = false;
389389
DTRACE_NET_STREAM_END(this);
390+
LTTNG_NET_STREAM_END(this);
390391

391392
// just in case we're waiting for an EOF.
392393
if (this.readable && !this._readableState.endEmitted)
@@ -1324,6 +1325,7 @@ function onconnection(err, clientHandle) {
13241325
socket.server = self;
13251326

13261327
DTRACE_NET_SERVER_CONNECTION(socket);
1328+
LTTNG_NET_SERVER_CONNECTION(socket);
13271329
COUNTER_NET_SERVER_CONNECTION(socket);
13281330
self.emit('connection', socket);
13291331
}

node.gyp

+12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
'variables': {
33
'v8_use_snapshot%': 'false',
44
'node_use_dtrace%': 'false',
5+
'node_use_lttng%': 'false',
56
'node_use_etw%': 'false',
67
'node_use_perfctr%': 'false',
78
'node_has_winsdk%': 'false',
@@ -260,6 +261,14 @@
260261
}
261262
] ]
262263
} ],
264+
[ 'node_use_lttng=="true"', {
265+
'defines': [ 'HAVE_LTTNG=1' ],
266+
'include_dirs': [ '<(SHARED_INTERMEDIATE_DIR)' ],
267+
'libraries': [ '-llttng-ust' ],
268+
'sources': [
269+
'src/node_lttng.cc'
270+
],
271+
} ],
263272
[ 'node_use_mdb=="true"', {
264273
'dependencies': [ 'node_mdb' ],
265274
'include_dirs': [ '<(SHARED_INTERMEDIATE_DIR)' ],
@@ -450,6 +459,9 @@
450459
[ 'node_use_dtrace=="false" and node_use_etw=="false"', {
451460
'inputs': [ 'src/notrace_macros.py' ]
452461
}],
462+
['node_use_lttng=="false"', {
463+
'inputs': [ 'src/nolttng_macros.py' ]
464+
}],
453465
[ 'node_use_perfctr=="false"', {
454466
'inputs': [ 'src/perfctr_macros.py' ]
455467
}]

src/node.cc

+8
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
#include "node_dtrace.h"
2424
#endif
2525

26+
#if defined HAVE_LTTNG
27+
#include "node_lttng.h"
28+
#endif
29+
2630
#include "ares.h"
2731
#include "async-wrap.h"
2832
#include "async-wrap-inl.h"
@@ -2871,6 +2875,10 @@ void LoadEnvironment(Environment* env) {
28712875
InitDTrace(env, global);
28722876
#endif
28732877

2878+
#if defined HAVE_LTTNG
2879+
InitLTTNG(env, global);
2880+
#endif
2881+
28742882
#if defined HAVE_PERFCTR
28752883
InitPerfCounters(env, global);
28762884
#endif

0 commit comments

Comments
 (0)