> Has anyone every called dtrace in a perl script? I don't care about
> instrumenting perl at all. What I want to do is make a script that calls a
> dtrace script, does a bunch of things, kills dtrace and returns. Right now
> I'm trying to fork and call dtrace. However, when I try to send SIGINT to the
> child it doesn't kill dtrace... Any ideas? I think dtrace may not even be
> fully started before SIGINT is called, but I'm not sure how to coordinate the
> two.
Here is an example that worked for me
sub get_dtrace_data
{
local *DTRACE;
# Collect some DTrace data.
my $collect_time = DCOLLECTTIME . 's';
my $time_ns = DCOLLECTTIME * NANOSEC;
######################################################################
# DTrace Blob
#
# The profile provider tick probe is used to time the script. The tick probe may
# fire before the specified interval if someone else had it enable, so make sure
# that the required interval have actually passed. If the tick probe fires too
# early, use a backup 1-sec tick probe to check whether it is time to bail out.
#
my $dtrace = <<END_OF_DTRACE;
/usr/sbin/dtrace -n '
#pragma D option quiet
/* record the script start time */
dtrace:::BEGIN { start = timestamp; }
... your script here
/* Exit when collection time expires */
profile:::tick-$collect_time, profile:::tick-1s
/timestamp - start >= $time_ns/
{ exit(0); }
END { print something }
'
END_OF_DTRACE
#
# End of DTrace blob
######################################################################
#
# Now run the DTrace script above and get the last line of the output.
# Convert it to the { pid, tid, count } triplet.
#
open(DTRACE,"$dtrace |") || warn(-1, "can not start dtrace: $!\n");
my $migration_data = ();
# Collect data generated by DTrace
while (<DTRACE>) {
chomp; # Trim end of line
next unless $_; # Skip empty lines
# Extract device name, device instance and CPU ID.
# We are done with DTrace
close(DTRACE) or
warn(-1, "can not complete dtrace: $!\n");
return $_;
}
_______________________________________________
dtrace-discuss mailing list
[email protected]