summaryrefslogtreecommitdiffstats
path: root/examples/syscalltimes
blob: 84ca77a9f45bc8c2c062f74dc407c3d201291840 (plain)
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
/*
 * (C) Copyright 2004
 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
 *
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA 02111-1307 USA
 */

#include <config.h>
#ifdef __PPC__
/*
 * At least on G2 PowerPC cores, sequential accesses to non-existent
 * memory must be synchronized.
 */
# include <asm/io.h>	/* for sync() */
#else
# define sync()		/* nothing */
#endif

/*
 * Check memory range for valid RAM. A simple memory test determines
 * the actually available RAM size between addresses `base' and
 * `base + maxsize'.
 */
long get_ram_size(volatile long *base, long maxsize)
{
	volatile long *addr;
	long           save[32];
	long           cnt;
	long           val;
	long           size;
	int            i = 0;

	for (cnt = (maxsize / sizeof (long)) >> 1; cnt > 0; cnt >>= 1) {
		addr = base + cnt;	/* pointer arith! */
		sync ();
		save[i++] = *addr;
		sync ();
		*addr = ~cnt;
	}

	addr = base;
	sync ();
	save[i] = *addr;
	sync ();
	*addr = 0;

	sync ();
	if ((val = *addr) != 0) {
		/* Restore the original data before leaving the function.
		 */
		sync ();
		*addr = save[i];
		for (cnt = 1; cnt < maxsize / sizeof(long); cnt <<= 1) {
			addr  = base + cnt;
			sync ();
			*addr = save[--i];
		}
		return (0);
	}

	for (cnt = 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
		addr = base + cnt;	/* pointer arith! */
		val = *addr;
		*addr = save[--i];
		if (val != ~cnt) {
			size = cnt * sizeof (long);
			/* Restore the original data before leaving the function.
			 */
			for (cnt <<= 1; cnt < maxsize / sizeof (long); cnt <<= 1) {
				addr  = base + cnt;
				*addr = save[--i];
			}
			return (size);
		}
	}

	return (maxsize);
}
delim) } } # User IDs if ('$F_UID') { uid = tokenize(f_uid_str, delim) while (uid != "") { f_uid[strtol(uid, 10)] = 1 uid = tokenize("", delim) } } } probe syscall.* { start[name, tid()] = gettimeofday_ns() } probe syscall.*.return { # Skip if we have not seen this before if (!([name, tid()] in start)) next delta = gettimeofday_ns() - start[name, tid()] # Check filters if ('$FILTER') { target = 0 if (pid() in f_pid) { timebypid[name, pid()] <<< delta target = 1 } if (uid() in f_uid) { timebyuid[name, uid()] <<< delta target = 1 } if (execname() in f_exec) { timebyexec[name, execname()] <<< delta target = 1 } } else target = 1 # Totals if (target && prt_totals) timebycall[name] <<< delta delete start[name, tid()] } function print_header() { printf("%22s %10s %12s %12s %12s %12s\n", "System Call", "Count", "Total ns", "Avg ns", "Min ns", "Max ns") } probe end { if (prt_totals) { printf("\nTimes for all processes%s:\n\n", filter_str) print_header() foreach (call in timebycall) printf("%22s %10d %12d %12d %12d %12d\n", call, @count(timebycall[call]), @sum(timebycall[call]), @avg(timebycall[call]), @min(timebycall[call]), @max(timebycall[call])) } if ('$F_PID') { curpid = -1 foreach ([call, pid-] in timebypid) { if (curpid != pid) { curpid = pid printf("\nTimes for process ID %d:\n\n", curpid) print_header() } printf("%22s %10d %12d %12d %12d %12d\n", call, @count(timebypid[call, pid]), @sum(timebypid[call, pid]), @avg(timebypid[call, pid]), @min(timebypid[call, pid]), @max(timebypid[call, pid])) } printf("\n") } if ('$F_EXEC') { curexec = "" foreach ([call, exec-] in timebyexec) { if (curexec != exec) { curexec = exec printf("\nTimes for process name %s:\n\n", curexec) print_header() } printf("%22s %10d %12d %12d %12d %12d\n", call, @count(timebyexec[call, exec]), @sum(timebyexec[call, exec]), @avg(timebyexec[call, exec]), @min(timebyexec[call, exec]), @max(timebyexec[call, exec])) } printf("\n") } if ('$F_UID') { curuid = -1 foreach ([call, uid-] in timebyuid) { if (curuid != uid) { curuid = uid printf("\nTimes for user ID %d:\n\n", curuid) print_header() } printf("%22s %10d %12d %12d %12d %12d\n", call, @count(timebyuid[call, uid]), @sum(timebyuid[call, uid]), @avg(timebyuid[call, uid]), @min(timebyuid[call, uid]), @max(timebyuid[call, uid])) } printf("\n") } delete timebycall delete timebypid delete timebyuid delete timebyexec }'