File: cache.stp

package info (click to toggle)
db5.3 5.3.28%2Bdfsg2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 158,500 kB
  • sloc: ansic: 448,411; java: 111,824; tcl: 80,544; sh: 44,264; cs: 33,697; cpp: 21,604; perl: 14,557; xml: 10,799; makefile: 4,077; javascript: 1,998; yacc: 1,003; awk: 965; sql: 801; erlang: 342; python: 216; php: 24; asm: 14
file content (104 lines) | stat: -rwxr-xr-x 2,549 bytes parent folder | download | duplicates (8)
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/stap
/*
 * Copyright (c) 2011, 2013 Oracle and/or its affiliates.  All rights reserved.
 *
 * cache.stp - Display DB cache activity groups by file.
 *
 * The path to the DB library is required to be the first argument.
 *
 * usage:
 *	cache <library-path> [<stap options, e.g. -x <pid>>] \
 *		[interval [#iterations [warmup period]]]
 *
 *	The defaults are
 *		interval - 1 second
 *		iterations - 0: unlimited)
 *		warmup - 0: start measuring right away)
 *
 *	For each 'interval' seconds display overall and per-file cache stats:
 *		hits
 *		misses
 *		evictions
 *	Empty lines are displayed when where was no cache activity for that
 *	file & counter during that interval
 */
global interval, current, iterations;
global warmup, hits, misses, evictions, secs, tick;

probe begin
{
	interval = 10;
	iterations = 60;
	warmup = 0;
	%( $# >= 2 %? interval = $2 %)
	%( $# >= 3 %? iterations = $3 %)
	%( $# >= 4 %? warmup = $4 %)
	secs = interval;

	tick = 0;
	current = 0;
}

function printstats()
{
	foreach ([file+] in hits)
		printf("Hits for %s %d\n", file, @count(hits[file]));
	foreach ([file+] in misses)
		printf("Misses for %s %d\n", file, @count(misses[file]));
	foreach ([file+] in evictions)
		printf("Evictions for %s %d\n", file, @count(evictions[file]));
	delete hits;
	delete misses;
	delete evictions;
}

/* mpool-miss(unsigned misses, char *file, unsigned pgno)
 */

probe process(@1).mark("mpool__miss")
{
	if (tick >= warmup)
		misses[$arg2 == 0 ? "<null>" : user_string($arg2)] <<< 1;
}

/* mpool-hit(unsigned hits, char *file, unsigned pgno) */
probe process(@1).mark("mpool__hit")
{
	if (tick >= warmup)
		hits[$arg2 == 0 ? "<null>" : user_string($arg2)] <<< 1;
}

/* mpool-evict(char *file, unsigned pgno, BH *buf */
probe process(@1).mark("mpool__evict")
{
	if (tick >= warmup)
		evictions[$arg1 == 0 ? "<null>" : user_string($arg1)] <<< 1;
}

probe timer.sec(1)
{
	/* Print a banner when starting the first measurement interval. */
	if (tick == warmup) {
		printf("Cache info: %8s %8s %8s %sstarting @ %s\n", "hits",
		    "misses", "evictions",
		    iterations == 0 ? "" : sprintf("%d iterations ", iterations),
		    ctime(gettimeofday_s()));
		secs = interval;
	}
	tick++;
	secs--;
	/* Display and erase statistics when ending an interval */
	if (secs == 0 && tick >= warmup) {
		printf(" %6d  %8d %8d %8d\n", tick, hits, misses, evictions);
		hits = misses = evictions = 0;
		printstats();
		secs = interval;
		if (++current == iterations)
			exit();
	}
}

probe end
{
	printf("\ncache.stp completed\n");
}