You are on page 1of 2

Assignment #3

Agenda

Assignment #3

Performance Measurement Techniques

Assignment #3 built-in performance tools

DPRNTF

Stats

Stopwatch

External Tools

Shell time command

Profiling perf

Guidelines
Assignment #3

Consists of your Assignment #1 with some


new code:

Fileops layer
_open(), _read(), _getchar(), _close()

Key index building, storage, and querying


Scan all files, read them, enter words in index

New code is simple, but poorly performing

Your job is to optimize it

Hint: Consider algorithms first!


Understanding the system

Your first step should be to understand the


system

Already know the file system part (assn #1)

Study the indexer and new fileops layer

Tools available:

DPRNTF

Stat counters

Stopwatch
TooI - Debug printf

Example in scan.c
DPRINTF('s', ("Scan_Pathname(%s)\n", pathname));
DPRINTF('s',("Scan_Pathname discard dup (%s)\n", inpathname));

nvoke: ./disksearch -d s .

Use to understand code operation

Trace execution

dentify common code paths

Add your own to help understand program's


execution
TooI - Existing stats framework

Example in scan.c
static long long numfiles, .., numdups, ..;
pathname = Pathstore_path(store,inpathname,discardDups);
if (pathname == NULL) {
numdups++;
return 0;
}
numfiles++;

Scan_dumpstats(FLE *file)

printf() various counters in the Scan module


TooI - Existing stats
framework

Each module dumps stats on program exit:


************ Stats ***************
Disksim: 583 reads, 0 writes
Diskimg: 583 reads, 0 writes
Scan: 3 files, 3 words, 15 characters, 1 directories, 5 dirents, 0 duplicates
Index: 3 stores, 3 allocates, 0 lookups
Pathstore: 3 stores, 0 duplicates
Pathstore2: 3 compares, 3 checksumdiff, 0 comparesuccess, 0 comparefail
Fileops: 4 opens, 6 reads, 99 getchars, 4 isfiles
Usage: 1.784111 usertime, 2.872179 systemtime, 0 voluntary ctxt switches, 396
involuntary ctxt switches
Mallinfo1: arena 135168 ordblks 1 smblks 2 hblks 0 hblkhd 0
Mallinfo2: usmblks 0 fsblks 32 uordblks 1016 fordblks 134152 keepcost 134120
Stats framework

Use stats to identify frequency of paths

Something invoked 0 times isn't a good target for


optimizations

Code is only real documentation for stats

Look where stats counter is modified

Some stats

disksim Number of /Os Metric to optimized

Two system stats. See man pages:

getrusage CPU time (user, system) context switches

mallinfo malloc usage


ManuaI Instrumentation -
Stopwatch
startTime = Debug_GetTimenMicrosecs();
Do some function()
endTime = Debug_GetTimenMicrosecs();
totalTime = endTime startTime;
printf(Function took %d time\n, totalTime);

Easy to do. Just bracket call


10
ExternaI tooI - sheII time cmd

nvocation: time command

Documentation: man time

Quick look at disksearch execution:


% time ./disksearch -f simple.dat simple.img
0.000u 0.000s 0:06.99 0.0% 0+0k 0+0io 0pf+0w
% time ./disksearch -f medium.dat medium.img
nterrupted after about an hour
0.000u 0.000s 55:45.16 0.0% 0+0k 0+0io 0pf+0w

CPU Utilization is close to zero

CPU optimizations won't help

Need to do fewer /O
TooI - perf

A powerful Linux tool.

At regular intervals, takes snapshots of your


program's stack as it is running.

Provides very helpful call graph information

Demo!
Modification guideIines

Any changes to code you want

Both assignment #1 and #3 code

Exceptions:

Can't disable disk latency simulation.

Need to support fast query even if this


assignment doesn't test it.

Means you can't just skip on building the index

The query functionality used in assignment #4

Must bound memory used for caching

See assignment handout for details on what


counts as part of the bounded cache.

You might also like