File: perf.sh

package info (click to toggle)
systemtap 3.1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 32,860 kB
  • ctags: 12,513
  • sloc: cpp: 58,610; ansic: 58,189; exp: 37,322; sh: 10,633; xml: 7,771; perl: 2,252; python: 2,066; tcl: 1,305; makefile: 969; lisp: 105; java: 100; awk: 94; asm: 91; sed: 16
file content (63 lines) | stat: -rwxr-xr-x 1,758 bytes parent folder | download | duplicates (2)
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
#!/bin/sh

# The declaration order should be irrelevant.  Run the script twice, each with
# a different counter declaration order, counting the insns and cycles.  For
# each run get the difference between cycles and insns and find the the largest
# term, e.g. 53874->50000.  Check that this term is equal for both runs.
# Caveat: possible false negative, if one run yields e.g. 59975->50000 and the
# other yields 600200>600000

STAP=$1

declare -A perfresult
for i in "first" "second"; do
perfresult[$i]=$($STAP -g -c "/bin/cat $0 >/dev/null" -e '
global insn

%( @1 == "first" %?
probe perf.hw.instructions.process("/bin/cat").counter("find_insns") {}
probe perf.hw.cpu_cycles.process("/bin/cat").counter("find_cycles") {}
%:
probe perf.hw.cpu_cycles.process("/bin/cat").counter("find_cycles") {}
probe perf.hw.instructions.process("/bin/cat").counter("find_insns") {}
%)

function poly (val) %{ /* unprivileged */
  int i;
  int root = 1;
  int j = STAP_ARG_val;
  if (j < 0)
     j = -j;
  for (root = 1; root < __LONG_MAX__; root *= 10)
     if (root > j)
	{
	  STAP_RETURN ((root/10) * (j / (root/10)));
	}
  STAP_RETURN(0);
  %}

probe process("/bin/cat").function("main")
{
  insn["find_insns"] = @perf("find_insns")
  insn["find_cycles"] = @perf("find_cycles")
}

# in lieu of .return
probe process("/bin/cat").function("main").return
{
  insn["find_cycles"] = (@perf("find_cycles") - insn["find_cycles"])
  insn["find_insns"] =  (@perf("find_insns") - insn["find_insns"])
}

probe end
{
  printf ("%d\n", poly(insn["find_cycles"]-insn["find_insns"]))
}' $i )
done


if [ "${perfresult['first']}" == "${perfresult['second']}" ] ; then
    echo PASS: ${perfresult["first"]}
else
    echo UNRESOLVED: ${perfresult["first"]} ${perfresult["second"]}
fi