blob: 81cfbab4aa56da70a8e096ba7f8b8d35d677d887 [file] [log] [blame]
Florian Mayer1cdb85e2018-05-08 17:54:26 +01001#!/usr/bin/python
2
3# Copyright (C) 2018 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17import os
18import sys
19
20import numpy as np
21from matplotlib import pyplot as plt
22
23from absl import app
24from absl import flags
25
26FLAGS = flags.FLAGS
27
28flags.DEFINE_integer('window', 100, 'Size of rolling average window')
29
30COLORS = ['b', 'g', 'r', 'c', 'm', 'y', 'k', 'indigo']
31
32
33def max_default(seq, default):
34 try:
35 return np.max(seq)
36 except ValueError:
37 return default
38
39
40def main(argv):
41 max_val = 0
42 max_key = ""
43
44 n = 0
45 for fn in argv[1:]:
46 name = os.path.basename(fn)
47 xs = np.loadtxt(fn, dtype=np.int)
48 ys = np.arange(len(xs))
49
50 delta = ys - np.array([max_default(ys[xs < x - FLAGS.window], np.NaN)
51 for x in xs])
52
53 max_delta = np.nanmax(delta)
54 if max_delta > max_val:
55 max_val = max_delta
56 max_key = name
57
58 plt.plot(xs, delta, color=COLORS[n % len(COLORS)], label=name)
59 print xs, delta
60 n += 1
61 print "Max delta %d in %s" % (max_val, max_key)
62 print "Buffer size: %d KB" % (max_val * 4)
63 plt.legend()
64 plt.show()
65
66
67if __name__ == '__main__':
68 app.run(main)