From nobody Wed Nov 5 21:55:50 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1495032918974813.854746411166; Wed, 17 May 2017 07:55:18 -0700 (PDT) Received: from localhost ([::1]:49381 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dB0M8-0003sf-KL for importer@patchew.org; Wed, 17 May 2017 10:55:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50780) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dB0JB-0001qc-K0 for qemu-devel@nongnu.org; Wed, 17 May 2017 10:52:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dB0JA-0004hH-Cr for qemu-devel@nongnu.org; Wed, 17 May 2017 10:52:13 -0400 Received: from mail-wr0-x22b.google.com ([2a00:1450:400c:c0c::22b]:33987) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dB0JA-0004gT-3T for qemu-devel@nongnu.org; Wed, 17 May 2017 10:52:12 -0400 Received: by mail-wr0-x22b.google.com with SMTP id l9so12462915wre.1 for ; Wed, 17 May 2017 07:52:11 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id n27sm1530670wra.57.2017.05.17.07.52.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 May 2017 07:52:08 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id E7F7F3E08D5; Wed, 17 May 2017 15:52:59 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zr8eaC1w14Cw1tsLDUZYCE/XYLWMKJGYH7RPzbyRiBQ=; b=I/AVSdxStsN51eRIO2vsIOMeQCZeTVLw1kpFwPftxOEg2KFG7V4l6fp46dz86rQl3c fmPtzR4ZGp5DDFt8BBxUCKoOfZoEnfd7YQBGFwA+J5aVuAFDUIegnWQdbjaV44N+zOLs ookJyJVUlo78lQTRbM5aImBFe+pPtxCm5nlMY= 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=zr8eaC1w14Cw1tsLDUZYCE/XYLWMKJGYH7RPzbyRiBQ=; b=uNWcN+Jvi5pBkNK/NxmqqtFhz8ghLa3wk38x3++y8ZFD7sRHj7pl/xGKZkE3609ct2 +dLLnYfCCE0YYWUF/1llxLwph02zx4NkwW5MYwuZ6PMK+wcCbVvTi+Mp1vDg5MntDoQj zfM58DTPEprVRUTdSJUvpefTqgpYj1dd1/wMdR/K/Uj3G3soO4e9NAGfZGwkdHqNuecS 4CWyuRIM+DJAiDXYR9OlqEc71vpNmSHzs7Gycw4KkgMKDOyx7BFdeV3tkYpFjtaE5f96 DV5zRen4Adir1wAJy4k6nPMrGbFvMtGidDmXqjb5/eMstZl+TUznM6QfvBaLHVyVsifO OU9g== X-Gm-Message-State: AODbwcA0Am4Dn5SpGexsPTnLDvDr19UEJpyFeN42GKPXaJ5i/dTQKHxR jDfDFwDwCUeCqGgI X-Received: by 10.223.179.199 with SMTP id x7mr2898073wrd.72.1495032730881; Wed, 17 May 2017 07:52:10 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: pbonzini@redhat.com, stefanha@redhat.com Date: Wed, 17 May 2017 15:52:59 +0100 Message-Id: <20170517145259.28979-7-alex.bennee@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170517145259.28979-1-alex.bennee@linaro.org> References: <20170517145259.28979-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::22b Subject: [Qemu-devel] [PATCH v2 6/6] new script/analyse-tlb-flushes-simpletrace.py X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: cota@braap.org, =?UTF-8?q?Alex=20Benn=C3=A9e?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 This is a simple helper script to extract TLB flush stats from the a simpletrace file and plot the results. Signed-off-by: Alex Benn=C3=A9e --- v2 - re-factored for new trace events - added time and latency graphs --- scripts/analyse-tlb-flushes-simpletrace.py | 144 +++++++++++++++++++++++++= ++++ 1 file changed, 144 insertions(+) create mode 100755 scripts/analyse-tlb-flushes-simpletrace.py diff --git a/scripts/analyse-tlb-flushes-simpletrace.py b/scripts/analyse-t= lb-flushes-simpletrace.py new file mode 100755 index 0000000000..03fab8c86b --- /dev/null +++ b/scripts/analyse-tlb-flushes-simpletrace.py @@ -0,0 +1,144 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Generate a simple graph of flushes over time +# +# Author: Alex Benn=C3=A9e +# +# analyzer =3D CpuTLBFlushAnalyser(4) +# simpletrace.process("../trace-events-all", "../trace-22464", analyzer) + +import os +import simpletrace +import argparse +import numpy as np +import matplotlib +# Force matplotlib to not use any Xwindows backend. +matplotlib.use('Agg') +import matplotlib.pyplot as plt + +class FlushType: + Self, Async, Synced =3D range(3) + +class CpuTLBFlushAnalyser(simpletrace.Analyzer): + "A simpletrace Analyser for extracting flush stats." + + def __init__(self, nvcpus): + self.flush_total =3D 0 + self.flush_all =3D 0 + self.nvcpus =3D nvcpus + self.vcpu_last =3D [[] for _ in range(nvcpus)] + self.flush_self =3D [] + self.flush_self_times =3D [] + self.flush_async =3D [] + self.flush_async_times =3D [] + self.flush_synced =3D [] + self.flush_synced_times =3D [] + self.flush_work =3D [] + + self.unmatched_work =3D [] + + def __save_queue(self, vcpu, record): + self.flush_total +=3D 1 + # FIXME: don't seem to see -1 + if vcpu > 0x7fffffff: + self.flush_all +=3D 1 + for i in range(0, self.nvcpus): + self.vcpu_last[i].append(record) + else: + self.vcpu_last[vcpu].append(record) + + def tlb_flush_self(self, timestamp, fn, vcpu): + self.__save_queue(vcpu, (timestamp[0], FlushType.Self)) + self.flush_self.append((timestamp[0], vcpu)) + + def tlb_flush_async_schedule(self, timestamp, fn, from_vcpu, to_vcpu): + self.__save_queue(to_vcpu, (timestamp[0], FlushType.Async, + to_vcpu, from_vcpu)) + self.flush_async.append((timestamp[0], to_vcpu)) + + def tlb_flush_synced_schedule(self, timestamp, fn, from_vcpu, to_vcpu): + self.__save_queue(to_vcpu, (timestamp[0], FlushType.Synced, + to_vcpu, from_vcpu)) + self.flush_synced.append((timestamp[0], to_vcpu)) + + def tlb_flush_work(self, timestamp, fn, vcpu): + "Check when it was queued and work out how long it took" + + if len(self.vcpu_last[vcpu]): + last =3D self.vcpu_last[vcpu].pop(0) + latency =3D timestamp[0] - last[0] + switcher =3D { + FlushType.Self: lambda a: a.flush_self_times.append(latenc= y), + FlushType.Async: lambda a: a.flush_async_times.append(late= ncy), + FlushType.Synced: lambda a: a.flush_synced_times.append(la= tency), + } + switcher.get(last[1])(self) + + self.flush_work.append((timestamp[0], vcpu)) + else: + self.unmatched_work.append((timestamp[0], vcpu, fn)) + + + + +def get_args(): + "Grab options" + parser =3D argparse.ArgumentParser() + parser.add_argument("--output", "-o", type=3Dstr, help=3D"Render plot = to file") + parser.add_argument("--vcpus", type=3Dint, help=3D"Number of vCPUS") + parser.add_argument("--graph", choices=3D['time', 'latency'], default= =3D'time') + parser.add_argument("events", type=3Dstr, help=3D'trace file read from= ') + parser.add_argument("tracefile", type=3Dstr, help=3D'trace file read f= rom') + return parser.parse_args() + +def plot_time_series(time_data, label): + "Plot one timeseries, return star and end time limits" + counts =3D np.arange(0, len(time_data)) + times =3D [x[0] for x in time_data] + plt.plot(times, counts, label=3Dlabel) + return (times[0],times[-1]) + + +if __name__ =3D=3D '__main__': + args =3D get_args() + + # Gather data from the trace + analyzer =3D CpuTLBFlushAnalyser(args.vcpus) + + simpletrace.process(args.events, args.tracefile, analyzer) + + # Print some summary stats + print ("Flushes: self:%d async:%d synced:%d" % + ( len(analyzer.flush_self), + len(analyzer.flush_async), + len(analyzer.flush_synced))) + + if args.graph =3D=3D 'time': + start_self, end_self =3D plot_time_series(analyzer.flush_self, "Se= lf") + start_async, end_async =3D plot_time_series(analyzer.flush_async, = "Async") + start_synced, end_synced =3D plot_time_series(analyzer.flush_synce= d, "Self") + + # start right at the edge + plt.xlim(xmin=3Dmin(start_self, start_async, start_synced)) + elif args.graph =3D=3D 'latency': + + # Three subplots, the axes array is 1-d + + f, (ax_self, ax_async, ax_synced) =3D plt.subplots(3, sharex=3DTru= e) + ax_self.set_title("Distribution") + + ax_self.hist(analyzer.flush_self_times, 10, normed=3D1, + facecolor=3D'green', alpha=3D0.5) + ax_self.hist(analyzer.flush_async_times, 10, normed=3D1, + facecolor=3D'blue', alpha=3D0.5) + ax_self.hist(analyzer.flush_synced_times, + 10, normed=3D1, + facecolor=3D'red', alpha=3D0.5) + else: + raise ValueError("Bad graph type") + + if args.output: + plt.savefig(args.output) + else: + plt.show() --=20 2.11.0