xref: /aosp_15_r20/external/trace-cmd/scripts/debug/tsync_res.py (revision 58e6ee5f017f6a8912852c892d18457e4bafb554)
1# SPDX-License-Identifier: GPL-2.0
2#
3# Copyright (C) 2019, VMware Inc, Tzvetomir Stoyanov <[email protected]>
4# Copyright (C) 2019, VMware Inc, Yordan Karadzhov <[email protected]>
5
6
7import matplotlib.pyplot as plt
8import matplotlib.lines as mlines
9import numpy as np
10import sys
11
12def newline(p1, p2):
13    ax = plt.gca()
14    xmin, xmax = ax.get_xbound()
15
16    if(p2[0] == p1[0]):
17        xmin = xmax = p1[0]
18        ymin, ymax = ax.get_ybound()
19    else:
20        ymax = p1[1]+(p2[1]-p1[1])/(p2[0]-p1[0])*(xmax-p1[0])
21        ymin = p1[1]+(p2[1]-p1[1])/(p2[0]-p1[0])*(xmin-p1[0])
22
23    l = mlines.Line2D([xmin,xmax], [ymin,ymax], color='red')
24    ax.add_line(l)
25    return l
26
27data = np.loadtxt(fname = sys.argv[1])
28x = data[:, 0]
29y = data[:, 1]
30
31fig, ax = plt.subplots()
32
33ax.set_xlabel('samples (t)')
34ax.set_ylabel('clock offset')
35ax.set_title("$\delta$=%i ns" % (max(y) - min(y)))
36
37l = mlines.Line2D(x, y)
38ax.add_line(l)
39ax.set_xlim(min(x), max(x))
40ax.set_ylim(min(y), max(y) )
41
42print(min(y), max(y), max(y) - min(y))
43
44# Tweak spacing to prevent clipping of ylabel
45fig.tight_layout()
46plt.show()
47