1#!/bin/bash
2#
3# Analyze a given results directory for rcuperf performance measurements,
4# looking for ftrace data.  Exits with 0 if data was found, analyzed, and
5# printed.  Intended to be invoked from kvm-recheck-rcuperf.sh after
6# argument checking.
7#
8# Usage: kvm-recheck-rcuperf-ftrace.sh resdir
9#
10# This program is free software; you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation; either version 2 of the License, or
13# (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with this program; if not, you can access it online at
22# http://www.gnu.org/licenses/gpl-2.0.html.
23#
24# Copyright (C) IBM Corporation, 2016
25#
26# Authors: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
27
28i="$1"
29. tools/testing/selftests/rcutorture/bin/functions.sh
30
31if test "`grep -c 'rcu_exp_grace_period.*start' < $i/console.log`" -lt 100
32then
33	exit 10
34fi
35
36sed -e 's/^\[[^]]*]//' < $i/console.log |
37grep 'us : rcu_exp_grace_period' |
38sed -e 's/us : / : /' |
39tr -d '\015' |
40awk '
41$8 == "start" {
42	if (starttask != "")
43		nlost++;
44	starttask = $1;
45	starttime = $3;
46	startseq = $7;
47}
48
49$8 == "end" {
50	if (starttask == $1 && startseq == $7) {
51		curgpdur = $3 - starttime;
52		gptimes[++n] = curgpdur;
53		gptaskcnt[starttask]++;
54		sum += curgpdur;
55		if (curgpdur > 1000)
56			print "Long GP " starttime "us to " $3 "us (" curgpdur "us)";
57		starttask = "";
58	} else {
59		# Lost a message or some such, reset.
60		starttask = "";
61		nlost++;
62	}
63}
64
65$8 == "done" {
66	piggybackcnt[$1]++;
67}
68
69END {
70	newNR = asort(gptimes);
71	if (newNR <= 0) {
72		print "No ftrace records found???"
73		exit 10;
74	}
75	pct50 = int(newNR * 50 / 100);
76	if (pct50 < 1)
77		pct50 = 1;
78	pct90 = int(newNR * 90 / 100);
79	if (pct90 < 1)
80		pct90 = 1;
81	pct99 = int(newNR * 99 / 100);
82	if (pct99 < 1)
83		pct99 = 1;
84	div = 10 ** int(log(gptimes[pct90]) / log(10) + .5) / 100;
85	print "Histogram bucket size: " div;
86	last = gptimes[1] - 10;
87	count = 0;
88	for (i = 1; i <= newNR; i++) {
89		current = div * int(gptimes[i] / div);
90		if (last == current) {
91			count++;
92		} else {
93			if (count > 0)
94				print last, count;
95			count = 1;
96			last = current;
97		}
98	}
99	if (count > 0)
100		print last, count;
101	print "Distribution of grace periods across tasks:";
102	for (i in gptaskcnt) {
103		print "\t" i, gptaskcnt[i];
104		nbatches += gptaskcnt[i];
105	}
106	ngps = nbatches;
107	print "Distribution of piggybacking across tasks:";
108	for (i in piggybackcnt) {
109		print "\t" i, piggybackcnt[i];
110		ngps += piggybackcnt[i];
111	}
112	print "Average grace-period duration: " sum / newNR " microseconds";
113	print "Minimum grace-period duration: " gptimes[1];
114	print "50th percentile grace-period duration: " gptimes[pct50];
115	print "90th percentile grace-period duration: " gptimes[pct90];
116	print "99th percentile grace-period duration: " gptimes[pct99];
117	print "Maximum grace-period duration: " gptimes[newNR];
118	print "Grace periods: " ngps + 0 " Batches: " nbatches + 0 " Ratio: " ngps / nbatches " Lost: " nlost + 0;
119	print "Computed from ftrace data.";
120}'
121exit 0
122