From patchwork Fri Nov 29 10:17:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 11266867 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8B99017E0 for ; Fri, 29 Nov 2019 10:18:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 69EF2217D6 for ; Fri, 29 Nov 2019 10:18:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DB17CteB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726888AbfK2KSB (ORCPT ); Fri, 29 Nov 2019 05:18:01 -0500 Received: from mail-lj1-f178.google.com ([209.85.208.178]:40901 "EHLO mail-lj1-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726903AbfK2KSA (ORCPT ); Fri, 29 Nov 2019 05:18:00 -0500 Received: by mail-lj1-f178.google.com with SMTP id s22so12375705ljs.7 for ; Fri, 29 Nov 2019 02:17:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nY5ircyGmJVBcwcMrvZaPID8lurhvLRNnjjwQUGl8j4=; b=DB17CteBaYfl9Dxdlq75UjSW/aj5Gpn4gXRmSpse3GgWHIyKkxGgBrQMIzSveFSYPp TXS88/QkD/zfELhFxeFUDMt9cJ/8zgvT3B4BuSM/55PGQfS9Knm7BCiXGd02xi1zWmbO +M5XuMvTiuMbsX9ehM7JPznicfj20uNhtRTB+tYZFo56Oa00QRHfllD4z4RyE73M6+X5 8pJFfn33Sf+MJtitmSYtv0eUjz72x0M4eD34RE2A79r8Cqe+Thty/4l8xl4negY8jU4Y IQlLW1ZCme7jRztnQHNIRY+Rkm7ex7/8mDfIunO7glCkPK1419oV4bi6PUL1cZPcaHgp PMTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nY5ircyGmJVBcwcMrvZaPID8lurhvLRNnjjwQUGl8j4=; b=UNFiE7ga2eiGlcknWlsz2PalT2eNfauIYaHm2mmdtnmTILLuSaXKPEgBibCCxiBfbU 54aJJC0Twr/2z4c1AdyIL2KS4kE+kNrxY9x4tS7XoOKL1S0gQMKW1vMAFacJdU1h/8iM NWJ4lmbBQB6K+8K2v6J20nqG2ItmSxqabui1MRqcqfhqrh5NsKP/FMfnzMCUtY6AwJL1 smFiGW83QyHbgZeqlMkEwiwKlc7F9UtrfuuvBfoHMVOLc37ODQFKYlV72D/glI+lp+8r I5RINhoJ+q5Hvd9i7gjGZHiiAB4IBnOg68Gi2NR1P+XRycfyrUXGi97jFyiiEcfvJ00N A7WA== X-Gm-Message-State: APjAAAVbKSO+LiYad7PSdMH2j+WYTpeEAeOIhYqmvjR0venhd2fKy0n7 ji4Oppf6qmgenC/4Ex/C5IaTMxUj0uA= X-Google-Smtp-Source: APXvYqxh4oqc6xR7PwGEhJ42fLeVzK5WijoxE5XxFzbXzMc6s10tO8bKcSIiGVs6gAqMdqj3acAHsw== X-Received: by 2002:a2e:808a:: with SMTP id i10mr21662426ljg.151.1575022677718; Fri, 29 Nov 2019 02:17:57 -0800 (PST) Received: from oberon.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id x29sm11367935lfg.45.2019.11.29.02.17.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Nov 2019 02:17:56 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v16 18/18] trace-cmd: Debug scripts for PTP-like algorithm for host - guest timestamp synchronization Date: Fri, 29 Nov 2019 12:17:33 +0200 Message-Id: <20191129101733.375808-19-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191129101733.375808-1-tz.stoyanov@gmail.com> References: <20191129101733.375808-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Sender: linux-trace-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org These scripts can be used to visualise debug files, written when the PTP-like algorithm is compiled with TSYNC_DEBUG defined. The files are located in the guest machine: s-cid*.txt - For each offset calculation: host and guest clocks and calculated offset. res-cid*.txt - For each tracing session: all calculated clock offsets. tsync_hist.py plots a histogram, using data from a s-cid*.txt file: "python tsync_hist.py s-cid2_1.txt" tsync_res.py plots a line, using data from res-cid*.txt file: "python tsync_res.py res-cid2.txt" Signed-off-by: Tzvetomir Stoyanov (VMware) --- scripts/debug/tsync_hist.py | 57 +++++++++++++++++++++++++++++++++++++ scripts/debug/tsync_readme | 12 ++++++++ scripts/debug/tsync_res.py | 46 ++++++++++++++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 scripts/debug/tsync_hist.py create mode 100644 scripts/debug/tsync_readme create mode 100644 scripts/debug/tsync_res.py diff --git a/scripts/debug/tsync_hist.py b/scripts/debug/tsync_hist.py new file mode 100644 index 0000000..819d1e8 --- /dev/null +++ b/scripts/debug/tsync_hist.py @@ -0,0 +1,57 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (C) 2019, VMware Inc, Tzvetomir Stoyanov +# Copyright (C) 2019, VMware Inc, Yordan Karadzhov + + +import matplotlib.pyplot as plt +import matplotlib.lines as mlines +import numpy as np +import sys + +def newline(p1, p2): + ax = plt.gca() + xmin, xmax = ax.get_xbound() + + if(p2[0] == p1[0]): + xmin = xmax = p1[0] + ymin, ymax = ax.get_ybound() + else: + ymax = p1[1]+(p2[1]-p1[1])/(p2[0]-p1[0])*(xmax-p1[0]) + ymin = p1[1]+(p2[1]-p1[1])/(p2[0]-p1[0])*(xmin-p1[0]) + + l = mlines.Line2D([xmin,xmax], [ymin,ymax], color='red') + ax.add_line(l) + return l + + +data = np.loadtxt(fname = sys.argv[1]) +selected_ts = data[-1, 1] +selected_ofs = data[-1, 0] +data = data[:-1,:] + +x = data[:, 1] - data[:, 0] + +mean = x.mean() +std = x.std() + +num_bins = 500 +min = x.min() #+ .4 * (x.max() - x.min()) +max = x.max() #- .4 * (x.max() - x.min()) +bins = np.linspace(min, max, num_bins, endpoint = False, dtype=int) + +fig, ax = plt.subplots() + +# the histogram of the data +n, bins, patches = ax.hist(x, bins, histtype=u'step'); + +ax.set_xlabel('clock offset [$\mu$s]') +ax.set_ylabel('entries') +ax.set_title("$\sigma$=%i" % std) + +x1, y1 = [selected_ofs, min], [selected_ofs, max] +newline(x1, y1) + +# Tweak spacing to prevent clipping of ylabel +fig.tight_layout() +plt.show() diff --git a/scripts/debug/tsync_readme b/scripts/debug/tsync_readme new file mode 100644 index 0000000..f3ebb25 --- /dev/null +++ b/scripts/debug/tsync_readme @@ -0,0 +1,12 @@ +PTP-like algorithm debug +======================== + +tsync_*.py scripts can be used to visualise debug files, written when the PTP-like algorithm +is compiled with TSYNC_DEBUG defined. The files are located in the guest machine: + s-cid*.txt - For each offset calculation: host and guest clocks and calculated offset. + res-cid*.txt - For each tracing session: all calculated clock offsets. + +tsync_hist.py plots a histogram, using data from a s-cid*.txt file: + "python tsync_hist.py s-cid2_1.txt" +tsync_res.py plots a line, using data from res-cid*.txt file: + "python tsync_res.py res-cid2.txt" diff --git a/scripts/debug/tsync_res.py b/scripts/debug/tsync_res.py new file mode 100644 index 0000000..7d10986 --- /dev/null +++ b/scripts/debug/tsync_res.py @@ -0,0 +1,46 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (C) 2019, VMware Inc, Tzvetomir Stoyanov +# Copyright (C) 2019, VMware Inc, Yordan Karadzhov + + +import matplotlib.pyplot as plt +import matplotlib.lines as mlines +import numpy as np +import sys + +def newline(p1, p2): + ax = plt.gca() + xmin, xmax = ax.get_xbound() + + if(p2[0] == p1[0]): + xmin = xmax = p1[0] + ymin, ymax = ax.get_ybound() + else: + ymax = p1[1]+(p2[1]-p1[1])/(p2[0]-p1[0])*(xmax-p1[0]) + ymin = p1[1]+(p2[1]-p1[1])/(p2[0]-p1[0])*(xmin-p1[0]) + + l = mlines.Line2D([xmin,xmax], [ymin,ymax], color='red') + ax.add_line(l) + return l + +data = np.loadtxt(fname = sys.argv[1]) +x = data[:, 0] +y = data[:, 1] + +fig, ax = plt.subplots() + +ax.set_xlabel('samples (t)') +ax.set_ylabel('clock offset') +ax.set_title("$\delta$=%i ns" % (max(y) - min(y))) + +l = mlines.Line2D(x, y) +ax.add_line(l) +ax.set_xlim(min(x), max(x)) +ax.set_ylim(min(y), max(y) ) + +print(min(y), max(y), max(y) - min(y)) + +# Tweak spacing to prevent clipping of ylabel +fig.tight_layout() +plt.show()