/
blkio_per_db.stp
107 lines (89 loc) · 2.67 KB
/
blkio_per_db.stp
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
#! /usr/bin/env stap
############################################################
# blkio_per_db.stp
#
# Track Block I/O by database
# Gouped by instance name
# Usage: stap -g ./blkio_per_db.stp <oracle uid> <refresh time ms>
#
# Author : Bertrand Drouvot
# BLOG : https://bdrouvot.wordpress.com
#
# Version blkio_per_db.stp 1.0 BETA
# Note: script is beta, use it at your own risk
############################################################
%{
#include <linux/string.h>
%}
function get_oracle_name_b:string (mystr:string) %{
char *ptr;
int ch = '_';
char *strargs = STAP_ARG_mystr;
ptr = strchr( strchr( strargs , ch) + 1 , ch);
snprintf(STAP_RETVALUE, MAXSTRINGLEN, "%s",ptr + 1);
%}
function get_oracle_name_f:string (mystr:string) %{
char *ptr;
int ch = ' ';
char substr_res[30];
char *strargs = STAP_ARG_mystr;
ptr = strchr( strargs, ch );
strncpy (substr_res,strargs+6, ptr - strargs - 6);
substr_res[ptr - strargs - 6]='\0';
snprintf(STAP_RETVALUE, MAXSTRINGLEN, "%s",substr_res);
%}
global reads, writes, total_io
probe ioblock.request {
if (bio_rw_str(rw) == "W") {
if ( isinstr(cmdline_str() , "ora_" ) == 1 && uid() == $1) {
writes[get_oracle_name_b(cmdline_str())] <<< size
} else if ( isinstr(cmdline_str() , "LOCAL=" ) == 1 && uid() == $1) {
writes[get_oracle_name_f(cmdline_str())] <<< size
} else {
writes["NOT_A_DB"] <<< size
}
} else {
if ( isinstr(cmdline_str() , "ora_" ) == 1 && uid() == $1) {
reads[get_oracle_name_b(cmdline_str())] <<< size
} else if ( isinstr(cmdline_str() , "LOCAL=" ) == 1 && uid() == $1) {
reads[get_oracle_name_f(cmdline_str())] <<< size
} else {
reads["NOT_A_DB"] <<< size
}
}
}
function print_activity()
{
printf("\n------------------------------------------------------------------------\n")
printf("%-12s: %-9s %-9s %-9s %-9s %-9s %-9s\n","DBNAME","NB_READ","READ_KB","NB_WRITE","WRITE_KB","NB_TOTAL","TOTAL_KB")
printf("------------------------------------------------------------------------\n")
foreach ([dbname] in reads) {
total_io[dbname] += @count(reads[dbname]);
}
foreach ([dbname] in writes) {
total_io[dbname] += @count(writes[dbname]);
}
foreach ([dbname] in total_io-) {
n_reads = @count(reads[dbname])
n_writes = @count(writes[dbname])
kb_reads = n_reads ? @sum(reads[dbname])/1024 : 0
kb_writes = n_writes ? @sum(writes[dbname])/1024 : 0
printf("%-12s: %-9d %-9d %-9d %-9d %-9d %-9d\n",
dbname,
n_reads,
kb_reads,
n_writes,
kb_writes,
n_reads + n_writes,
kb_reads + kb_writes
)
}
print("\n")
delete reads
delete writes
delete total_io
}
probe timer.ms($2), end, error
{
print_activity()
}