Skip to content

Instantly share code, notes, and snippets.

@bnoordhuis
Created November 15, 2012 14:36
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save bnoordhuis/4078925 to your computer and use it in GitHub Desktop.
Save bnoordhuis/4078925 to your computer and use it in GitHub Desktop.
systemtap script that prints aggregated node.js garbage collector statistics
#!/usr/bin/env stap
global samples
global all_samples
global timestamp
probe process("node").mark("gc__start")
{
timestamp = gettimeofday_us()
}
probe process("node").mark("gc__done")
{
sample = gettimeofday_us() - timestamp
samples <<< sample
all_samples <<< sample
}
probe timer.s(5)
{
print(@hist_log(samples))
printf("min:%d avg:%d max:%d count:%d\n",
@min(samples), @avg(samples),
@max(samples), @count(samples))
delete samples
}
probe end
{
print(@hist_log(all_samples))
printf("min:%d avg:%d max:%d count:%d\n",
@min(all_samples), @avg(all_samples),
@max(all_samples), @count(all_samples))
}
@bnoordhuis
Copy link
Author

Run with sudo stap gc.stp -c 'node script.js'

@bnoordhuis
Copy link
Author

Here is what the output looks like. Times are in microseconds.

value |-------------------------------------------------- count
  128 |                                                    0
  256 |                                                    0
  512 |@@@@@@@@@@@@@@@@                                   16
 1024 |@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@                 34
 2048 |                                                    0
 4096 |@@                                                  2
 8192 |                                                    0
16384 |                                                    0

min:512 avg:1336 max:7919 count:52

@fche
Copy link

fche commented Apr 18, 2013

That "timestamp" global should be indexed with tid(), in case multiple concurrent garbage collection events may be occurring on the machine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment