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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
#!/usr/bin/ksh
#
# lastwords - print last few syscalls for dying processes.
# Written using DTrace (Solaris 10 3/05).
#
# $Id: lastwords 3 2007-08-01 10:50:08Z brendan $
#
# This prints the last few system calls for processes matching
# the given name, when they exit. This makes use of a ring buffer
# so that the impact on the system is minimised.
#
# USAGE: lastwords command
# eg,
# lastwords netscape
#
# FIELDS:
# TIME Time of syscall return, ns
# PID Process ID
# EXEC Process name (execname)
# SYSCALL System call
# RETURN Return value for system call
# ERR errno for system call
#
# BASED ON: /usr/demo/dtrace/ring.d
#
# SEE ALSO: DTrace Guide "Buffers and Buffering" chapter (docs.sun.com)
# dtruss (DTraceToolkit)
#
# PORTIONS: Copyright (c) 2005, 2006 Brendan Gregg.
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License, Version 1.0 only
# (the "License"). You may not use this file except in compliance
# with the License.
#
# You can obtain a copy of the license at Docs/cddl1.txt
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# CDDL HEADER END
#
# 09-Jun-2005 Brendan Gregg Created this.
# 20-Apr-2006 " " Last update.
#
### Usage
function usage
{
cat <<-END >&2
USAGE: lastwords command
eg,
lastwords netscape
END
exit 1
}
### Process arguments
if (( $# != 1 )); then
usage
fi
command=$1
print "Tracing... Waiting for $command to exit..."
### Run DTrace
/usr/sbin/dtrace -n '
#pragma D option quiet
#pragma D option bufpolicy=ring
#pragma D option bufsize=16k
syscall:::return
/execname == $$1/
{
/* buffer syscall details */
printf("%-18d %5d %12s %12s %10x %3d\n",
timestamp,pid,execname,probefunc,(int)arg0,errno);
}
proc::proc_exit:exit
/execname == $$1/
{
/* print, erm, footer */
printf("%-18s %5s %12s %12s %10s %3s\n",
"TIME","PID","EXEC","SYSCALL","RETURN","ERR");
exit(0);
}
' "$command"
|