Florian Mayer | 1cdb85e | 2018-05-08 17:54:26 +0100 | [diff] [blame] | 1 | #!/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 | |
| 17 | import os |
| 18 | import sys |
| 19 | |
| 20 | import numpy as np |
| 21 | from matplotlib import pyplot as plt |
| 22 | |
| 23 | from absl import app |
| 24 | from absl import flags |
| 25 | |
| 26 | FLAGS = flags.FLAGS |
| 27 | |
| 28 | flags.DEFINE_integer('window', 100, 'Size of rolling average window') |
| 29 | |
| 30 | COLORS = ['b', 'g', 'r', 'c', 'm', 'y', 'k', 'indigo'] |
| 31 | |
| 32 | |
| 33 | def max_default(seq, default): |
| 34 | try: |
| 35 | return np.max(seq) |
| 36 | except ValueError: |
| 37 | return default |
| 38 | |
| 39 | |
| 40 | def 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 | |
| 67 | if __name__ == '__main__': |
| 68 | app.run(main) |