File: mutex.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 (112 lines) | stat: -rwxr-xr-x 3,063 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
105
106
107
108
109
110
111
112
#!/usr/bin/stap
/*
 * Copyright (c) 2011, 2013 Oracle and/or its affiliates.  All rights reserved.
 *
 * mutex.stp - Display DB mutex wait times.
 *
 * Specify one particular process with -x <pid> or -c "<program> [<args>..]"
 *
 * Probes: mutex suspend and resume
 *   suspend(unsigned mutex, unsigned exclusive, unsigned alloc_id);
 *   resume(unsigned mutex, unsigned exclusive, unsigned alloc_id);
 *
 *	mutex:
 *		is the integer mutex id returned by mutex_alloc()
 *	exclusive:
 *		is set to 1 except when obtaining a read-write latch with
 *		shared access (allocated with DB_MUTEX_SHARED), then it is 0.
 *	alloc_id:
 *		is one of dbinc/mutex.h's MTX_XXX definitions (i.e., the class)
 */

global idnames;
global suspend;
global mutexwaits;
global classwaits;

function getns()
{
	t = gettimeofday_ns();
	/*
	 * On some virtual machine monitors gettimeofday_ns() returns 0. When
	 * that happens approximate it as if this has a 2 Ghz processor.
	 */
	if (t == 0)
		t = get_cycles() / 2;
	return (t);
}

probe begin
{
	idnames[1] = "APPLICATION";
	idnames[2] = "ATOMIC_EMULATION";
	idnames[3] = "DB_HANDLE";
	idnames[4] = "ENV_DBLIST";
	idnames[5] = "ENV_HANDLE";
	idnames[6] = "ENV_REGION";
	idnames[7] = "LOCK_REGION";
	idnames[8] = "LOGICAL_LOCK";
	idnames[9] = "LOG_FILENAME";
	idnames[10] = "LOG_FLUSH";
	idnames[11] = "LOG_HANDLE";
	idnames[12] = "LOG_REGION";
	idnames[13] = "MPOOLFILE_HANDLE";
	idnames[14] = "MPOOL_BH";
	idnames[15] = "MPOOL_FH";
	idnames[16] = "MPOOL_FILE_BUCKET";
	idnames[17] = "MPOOL_HANDLE";
	idnames[18] = "MPOOL_HASH_BUCKET";
	idnames[19] = "MPOOL_REGION";
	idnames[20] = "MUTEX_REGION";
	idnames[21] = "MUTEX_TEST";
	idnames[22] = "REP_CHKPT";
	idnames[23] = "REP_DATABASE";
	idnames[24] = "REP_DIAG";
	idnames[25] = "REP_EVENT";
	idnames[26] = "REP_REGION";
	idnames[27] = "REP_START";
	idnames[28] = "REP_WAITER";
	idnames[29] = "REPMGR";
	idnames[30] = "SEQUENCE";
	idnames[31] = "TWISTER";
	idnames[32] = "TCL_EVENTS";
	idnames[33] = "TXN_ACTIVE";
	idnames[34] = "TXN_CHKPT";
	idnames[35] = "TXN_COMMIT";
	idnames[36] = "TXN_MVCC";
	idnames[37] = "TXN_REGION";
}

probe process(@1).mark("mutex__suspend")
{
	suspend[tid()] = getns();

}

/* mutex-resume(unsigned mutex, boolean exclusive, unsigned alloc_id, struct __db_mutex_t *mutexp) */
probe process(@1).mark("mutex__resume")
{
	start = suspend[tid()];
	class = idnames[$arg3];
	if (start != 0) {
		duration = getns() - start;
		mutexwaits[$arg1, $arg2, class, tid()] <<< duration;
		classwaits[class, $arg2] <<< duration;
		suspend[tid()] = 0;
	}
}

probe end
{
	foreach ([mutex, excl, alloc_id, tid] in mutexwaits) {
	printf("Mutex %d %s %s thread %d wait times in nanoseconds\n",
	    mutex, excl ? "exclusive" : "shared", alloc_id, tid);
	print(@hist_log(mutexwaits[mutex, excl, alloc_id, tid]))
	}
	print("Aggregate mutex wait times grouped by (alloc_id, mode)\n");
	foreach ([class, excl] in classwaits) {
		printf("Mutex class %s %s wait times in nanoseconds\n", class,
		    excl ? "exclusive" : "shared");
		print(@hist_log(classwaits[class, excl]));
	}
}