1 .\" $NetBSD: 2.t,v 1.4 2003/08/07 10:30:47 agc Exp $
3 .\" Copyright (c) 1985 The Regents of the University of California.
4 .\" All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. Neither the name of the University nor the names of its contributors
15 .\" may be used to endorse or promote products derived from this software
16 .\" without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" @(#)2.t 5.1 (Berkeley) 4/17/91
32 .ds RH Observation techniques
34 Observation techniques
36 There are many tools available for monitoring the performance
38 Those that we found most useful are described below.
40 System maintenance tools
42 Several standard maintenance programs are invaluable in
43 observing the basic actions of the system.
45 program is designed to be an aid to monitoring
46 systemwide activity. Together with the
48 command (as in ``ps av''), it can be used to investigate systemwide
49 virtual memory activity.
50 By running \fIvmstat\fP
51 when the system is active you can judge the system activity in several
52 dimensions: job distribution, virtual memory load, paging and swapping
53 activity, disk and CPU utilization.
54 Ideally, to have a balanced system in activity,
55 there should be few blocked (b) jobs,
56 there should be little paging or swapping activity, there should
57 be available bandwidth on the disk devices (most single arms peak
58 out at 25-35 tps in practice), and the user CPU utilization (us) should
61 If the system is busy, then the count of active jobs may be large,
62 and several of these jobs may often be blocked (b). If the virtual
63 memory is active, then the paging demon will be running (sr will
64 be non-zero). It is healthy for the paging demon to free pages when
65 the virtual memory gets active; it is triggered by the amount of free
66 memory dropping below a threshold and increases its pace as free memory
69 If you run \fIvmstat\fP
70 when the system is busy (a ``vmstat 5'' gives all the
71 numbers computed by the system), you can find
72 imbalances by noting abnormal job distributions. If many
73 processes are blocked (b), then the disk subsystem
74 is overloaded or imbalanced. If you have several non-DMA
75 devices or open teletype lines that are ``ringing'', or user programs
76 that are doing high-speed non-buffered input/output, then the system
77 time may go high (60-80% or higher).
78 It is often possible to pin down the cause of high system time by
79 looking to see if there is excessive context switching (cs), interrupt
80 activity (in) or system call activity (sy). Long term measurements
82 our large machines show
83 an average of 60 context switches and interrupts
84 per second and an average of 90 system calls per second.
86 If the system is heavily loaded, or if you have little memory
87 for your load (1 megabyte is little in our environment), then the system
88 may be forced to swap. This is likely to be accompanied by a noticeable
89 reduction in the system responsiveness and long pauses when interactive
90 jobs such as editors swap out.
92 A second important program is \fIiostat\fP\|(1).
94 iteratively reports the number of characters read and written to terminals,
95 and, for each disk, the number of transfers per second, kilobytes
96 transferred per second,
97 and the milliseconds per average seek.
98 It also gives the percentage of time the system has
99 spent in user mode, in user mode running low priority (niced) processes,
100 in system mode, and idling.
102 To compute this information, for each disk, seeks and data transfer completions
103 and the number of words transferred are counted;
104 for terminals collectively, the number
105 of input and output characters are counted.
107 the state of each disk is examined
108 and a tally is made if the disk is active.
109 From these numbers and the transfer rates
110 of the devices it is possible to determine
111 average seek times for each device.
113 When filesystems are poorly placed on the available
114 disks, figures reported by \fIiostat\fP can be used
115 to pinpoint bottlenecks. Under heavy system load, disk
116 traffic should be spread out among the drives with
117 higher traffic expected to the devices where the root, swap, and
118 /tmp filesystems are located. When multiple disk drives are
119 attached to the same controller, the system will
120 attempt to overlap seek operations with I/O transfers. When
121 seeks are performed, \fIiostat\fP will show
122 non-zero average seek times. Most modern disk drives should
123 exhibit an average seek time of 25-35 ms.
125 Terminal traffic reported by \fIiostat\fP should be heavily
126 output oriented unless terminal lines are being used for
127 data transfer by programs such as \fIuucp\fP. Input and
128 output rates are system specific. Screen editors
129 such as \fIvi\fP and \fIemacs\fP tend to exhibit output/input
130 ratios of anywhere from 5/1 to 8/1. On one of our largest
131 systems, 88 terminal lines plus 32 pseudo terminals, we observed
132 an average of 180 characters/second input and 450 characters/second
133 output over 4 days of operation.
137 It is simple to build a 4.2BSD kernel that will automatically
138 collect profiling information as it operates simply by specifying the
140 option to \fIconfig\fP\|(8) when configuring a kernel.
141 The program counter sampling can be driven by the system clock,
142 or by an alternate real time clock.
143 The latter is highly recommended as use of the system clock results
144 in statistical anomalies in accounting for
145 the time spent in the kernel clock routine.
147 Once a profiling system has been booted statistic gathering is
148 handled by \fIkgmon\fP\|(8).
149 \fIKgmon\fP allows profiling to be started and stopped
150 and the internal state of the profiling buffers to be dumped.
151 \fIKgmon\fP can also be used to reset the state of the internal
152 buffers to allow multiple experiments to be run without
153 rebooting the machine.
155 The profiling data is processed with \fIgprof\fP\|(1)
156 to obtain information regarding the system's operation.
157 Profiled systems maintain histograms of the kernel program counter,
158 the number of invocations of each routine,
159 and a dynamic call graph of the executing system.
160 The postprocessing propagates the time spent in each
161 routine along the arcs of the call graph.
162 \fIGprof\fP then generates a listing for each routine in the kernel,
163 sorted according to the time it uses
164 including the time of its call graph descendents.
165 Below each routine entry is shown its (direct) call graph children,
166 and how their times are propagated to this routine.
167 A similar display above the routine shows how this routine's time and the
168 time of its descendents is propagated to its (direct) call graph parents.
170 A profiled system is about 5-10% larger in its text space because of
171 the calls to count the subroutine invocations.
172 When the system executes,
173 the profiling data is stored in a buffer that is 1.2
174 times the size of the text space.
175 All the information is summarized in memory,
176 it is not necessary to have a trace file
177 being continuously dumped to disk.
178 The overhead for running a profiled system varies;
179 under normal load we see anywhere from 5-25%
180 of the system time spent in the profiling code.
181 Thus the system is noticeably slower than an unprofiled system,
182 yet is not so bad that it cannot be used in a production environment.
183 This is important since it allows us to gather data
184 in a real environment rather than trying to
185 devise synthetic work loads.
189 The kernel can be configured to trace certain operations by
190 specifying ``options TRACE'' in the configuration file. This
191 forces the inclusion of code that records the occurrence of
192 events in \fItrace records\fP in a circular buffer in kernel
193 memory. Events may be enabled/disabled selectively while the
194 system is operating. Each trace record contains a time stamp
195 (taken from the VAX hardware time of day clock register), an
196 event identifier, and additional information that is interpreted
197 according to the event type. Buffer cache operations, such as
198 initiating a read, include
199 the disk drive, block number, and transfer size in the trace record.
200 Virtual memory operations, such as a pagein completing, include
201 the virtual address and process id in the trace record. The circular
202 buffer is normally configured to hold 256 16-byte trace records.\**
204 \** The standard trace facilities distributed with 4.2
205 differ slightly from those described here. The time stamp in the
206 distributed system is calculated from the kernel's time of day
207 variable instead of the VAX hardware register, and the buffer cache
208 trace points do not record the transfer size.
211 Several user programs were written to sample and interpret the
212 tracing information. One program runs in the background and
213 periodically reads the circular buffer of trace records. The
214 trace information is compressed, in some instances interpreted
215 to generate additional information, and a summary is written to a
216 file. In addition, the sampling program can also record
217 information from other kernel data structures, such as those
218 interpreted by the \fIvmstat\fP program. Data written out to
219 a file is further buffered to minimize I/O load.
221 Once a trace log has been created, programs that compress
222 and interpret the data may be run to generate graphs showing the
223 data and relationships between traced events and
226 The trace package was used mainly to investigate the operation of
227 the file system buffer cache. The sampling program maintained a
228 history of read-ahead blocks and used the trace information to
229 calculate, for example, percentage of read-ahead blocks used.
233 Benchmark programs were used in two ways. First, a suite of
234 programs was constructed to calculate the cost of certain basic
235 system operations. Operations such as system call overhead and
236 context switching time are critically important in evaluating the
237 overall performance of a system. Because of the drastic changes in
238 the system between 4.1BSD and 4.2BSD, it was important to verify
239 the overhead of these low level operations had not changed appreciably.
241 The second use of benchmarks was in exercising
242 suspected bottlenecks.
243 When we suspected a specific problem with the system,
244 a small benchmark program was written to repeatedly use
246 While these benchmarks are not useful as a general tool
247 they can give quick feedback on whether a hypothesized
248 improvement is really having an effect.
249 It is important to realize that the only real assurance
250 that a change has a beneficial effect is through
251 long term measurements of general timesharing.
252 We have numerous examples where a benchmark program
253 suggests vast improvements while the change
254 in the long term system performance is negligible,
255 and conversely examples in which the benchmark program run more slowly,
256 but the long term system performance improves significantly.