1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
/*
* Oracle Linux DTrace.
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
* Licensed under the Universal Permissive License v 1.0 as shown at
* http://oss.oracle.com/licenses/upl.
*/
/*
* NAME
* readtrace.d - show the time spent in the read() system call
*
* SYNOPSIS
* sudo dtrace -s readtrace.d
*
* DESCRIPTION
* For each combination of executable name and process id, show the
* total time in microseconds that is spent in the read() system call(s).
*
* NOTES
* - The script needs to be terminated with ctrl-C. In case the
* script is running in the background, get it to run in the
* foreground first by using the fg command and then use ctrl-C
* to terminate the process. Otherwise, typing in ctrl-C will do.
*
* - An aggregation is used to accumulate the timings. An alternative
* is to print the results in the read:return probe and if required,
* post process the output when the script has completed.
*
* - Although the results of an aggregation are automatically
* printed when the tracing terminates, in this case, the results
* are printed in the END probe. The format string is optional,
* but is used to produce a table lay-out.
*/
/*
* Set the base value of the timer. This is used as an offset in the
* read:return probe to calculate the time spent.
*/
syscall::read:entry
{
self->ts_base = timestamp;
}
/*
* The predicate ensures that the base timing has been set.
*/
syscall::read:return
/self->ts_base != 0/
{
/*
* Clause-local variable time_read is used to store the time passed
* since the read:entry probe fired. This time is converted from
* nanoseconds to microseconds.
*
*/
this->time_read = (timestamp - self->ts_base)/1000;
@totals[execname,pid] = sum(this->time_read);
/*
* Free the storage for ts_base.
*/
self->ts_base = 0;
}
/*
* Print the results.
*/
END
{
printa("%15s (pid=%-7d) spent a total of %5@d microseconds in read()\n",
@totals);
}
|