• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2#
3# Usage:
4#  scripts/throttle.py trace-dat
5#
6# Shows how often the trace throttles and for how long.
7
8import getopt
9from tracecmd import *
10import sys
11
12requests = {}
13throttle = {}
14prev_throttle = 0;
15
16def read_events(t):
17	for cpu in range(0, t.cpus):
18		e = t.read_event(cpu)
19		while e:
20			if e.name == 'i915_gem_request_complete':
21				seqno = e.num_field('seqno')
22				requests[seqno] = e.ts;
23
24			if e.name == 'i915_gem_request_throttle_begin':
25				seqno = e.num_field('seqno')
26				throttle[seqno] = e.ts
27
28			if e.name == 'i915_gem_request_throttle_end':
29				global prev_throttle
30
31				ts = 0
32				sum_dispatch = 0
33				num_dispatch = 0
34				max_dispatch = 0
35
36				seqno = e.num_field('seqno')
37				s = prev_throttle
38				if s == 0:
39					s = seqno
40				while s <= seqno:
41					if requests.has_key(s):
42						if ts:
43							delta = requests[s] - ts
44							num_dispatch += 1
45							sum_dispatch += delta
46							if delta > max_dispatch:								max_dispatch = delta
47						ts = requests[s]
48					s += 1
49
50				if throttle.has_key(seqno) and throttle.has_key(prev_throttle) and num_dispatch:
51					print "throttle +%d: %dms -- %d dispatch, avg %.3fms, max %dus" % ((throttle[seqno]-throttle[prev_throttle])/1000000, (e.ts - throttle[seqno]) / 1000000, num_dispatch, sum_dispatch / (1000000. * num_dispatch), max_dispatch / 1000)
52					throttle[seqno] = e.ts
53
54				prev_throttle = seqno
55
56			e = t.read_event(cpu)
57
58if __name__ == "__main__":
59    	if len(sys.argv) >=2:
60       		filename = sys.argv[1]
61	else:
62		filename = "trace.dat"
63
64	print "Initializing trace '%s'..." % (filename)
65	trace = Trace(filename)
66	read_events(trace)
67
68