3 # diskhits - disk access by file offset.
4 # Written using DTrace (Solaris 10 3/05).
6 # $Id: diskhits 3 2007-08-01 10:50:08Z brendan $
8 # This prints how a file was accessed, the locations on a distribution plot.
9 # This is for the cache misses only - the file activity that resulted in
12 # USAGE: diskhits pathname
14 # diskhits /var/adm/messages
17 # Location (KB) The file offset of the disk activity, Kbytes.
18 # Size (KB) Size of the disk activity, Kbytes.
19 # Total RW Total disk activity, reads + writes.
21 # BASED ON: /usr/demo/dtrace/applicat.d
23 # SEE ALSO: DTrace Guide "io Provider" chapter (docs.sun.com)
24 # iosnoop (DTraceToolkit)
26 # PORTIONS: Copyright (c) 2005, 2006 Brendan Gregg.
30 # The contents of this file are subject to the terms of the
31 # Common Development and Distribution License, Version 1.0 only
32 # (the "License"). You may not use this file except in compliance
35 # You can obtain a copy of the license at Docs/cddl1.txt
36 # or http://www.opensolaris.org/os/licensing.
37 # See the License for the specific language governing permissions
38 # and limitations under the License.
42 # 08-Jun-2005 Brendan Gregg Created this.
43 # 20-Apr-2006 " " Last update.
50 USAGE: diskhits pathname
52 diskhits /var/adm/wtmpx
58 if (( $# != 1 )); then
61 if [[ $1 == "-h" ]]; then
65 if [[ ! -e $pathname ]]; then
66 print "ERROR2: file $pathname not found" >&2
70 ### Calculate output scale
72 set -- `ls -l $pathname`
74 (( file_kb_max = filesize / 1024 ))
75 (( scale_kb = filesize / (1024 * report_lines) ))
76 if (( file_kb_max < 20 )); then file_kb_max=20; fi
77 if (( scale_kb < 1 )); then scale_kb=1; fi
83 #pragma D option quiet
85 inline string PATHNAME = "'$pathname'";
86 inline int FILE_KB_MAX = '$file_kb_max';
87 inline int SCALE_KB = '$scale_kb';
91 printf("Tracing... Hit Ctrl-C to end.\n");
95 /args[2]->fi_pathname == PATHNAME/
97 this->kb = args[2]->fi_offset == -1 ? -1 : args[2]->fi_offset / 1024;
98 @Location = lquantize(this->kb, 0, FILE_KB_MAX, SCALE_KB);
99 @Size = quantize(args[0]->b_bcount/1024);
100 @Total = sum(args[0]->b_bcount/1024);
105 printf("Location (KB),");
108 printf("Size (KB),");
111 printa("Total RW: %@d KB\n", @Total);