From nobody Wed Feb 11 05:17:51 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1613136371; cv=none; d=zohomail.com; s=zohoarc; b=i6vGyZGIu1vxuWEZLyB9ocM4e8zy+TLdiQFGw/yCjOizA8GvPTGzShzGerY+Mw9g3soKd7L+SH7uja9XipPwRKDSkzPZw7hjSrKg4iO2bBM9hUt4zV1+9C8O4obkcXKMx75BFsuQBOtZ2oG1GMX2/OAfAUebD/BGBSdr8NZghpE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1613136371; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=AldqHdb2LNEUJ1U61eqt20UqPU15rdMAfvqCUyJ1W18=; b=MM0ryqIrCWsxjTkCaVhlpm1OQdInEXowl42NtT0SCNW76ouUK/aCxI7KROAQfth7k3iHXXFZstWEkmkVUDruyqQZTzC4Ja8z9xU1HLDQh/kJzObJEyWM0r8F1H9CAzW2rGj6AxIl9EZT/ZqKC9hOx69ikyufkL+bkYGh7vrrYV8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1613136371026372.4864418301174; Fri, 12 Feb 2021 05:26:11 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-579-U9veB5FGN3qGaj72gedVVw-1; Fri, 12 Feb 2021 08:26:07 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1E9EF1936B70; Fri, 12 Feb 2021 13:26:01 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E893EE2C3; Fri, 12 Feb 2021 13:26:00 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id AE59B57DFF; Fri, 12 Feb 2021 13:26:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 11CDPeFR008602 for ; Fri, 12 Feb 2021 08:25:40 -0500 Received: by smtp.corp.redhat.com (Postfix) id AB35A614EB; Fri, 12 Feb 2021 13:25:40 +0000 (UTC) Received: from work.redhat.com (ovpn-112-223.ams2.redhat.com [10.36.112.223]) by smtp.corp.redhat.com (Postfix) with ESMTP id 000706E405; Fri, 12 Feb 2021 13:25:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1613136369; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=AldqHdb2LNEUJ1U61eqt20UqPU15rdMAfvqCUyJ1W18=; b=I3q39WhO5LfF55JKw50RW2bZU4Oce5qSGU9C7ZffbnvsOCNRYYcKj0G+4M0Gec1K0gu63/ O2yUs/VcMwkZvNPclzrTnnpZCxQtbn00jAGXq5WzTQpJL663Wq2KhS61g+QhS7JOBeGAqn gTEucUKwhRRDfyqFw7sJzhqyojoX9OE= X-MC-Unique: U9veB5FGN3qGaj72gedVVw-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 02/10] clang-tidy: Run in parallel Date: Fri, 12 Feb 2021 14:25:26 +0100 Message-Id: <20210212132534.29066-3-twiederh@redhat.com> In-Reply-To: <20210212132534.29066-1-twiederh@redhat.com> References: <20210212132534.29066-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Similar to the "official" run-clang-tidy script. Defaults to run one thread per core, making the tool more pleasant to use locally. Signed-off-by: Tim Wiederhake --- scripts/run-clang-tidy.py | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/scripts/run-clang-tidy.py b/scripts/run-clang-tidy.py index 10c8b80fe0..79d9fb38b2 100755 --- a/scripts/run-clang-tidy.py +++ b/scripts/run-clang-tidy.py @@ -2,9 +2,12 @@ =20 import argparse import json +import multiprocessing import os +import queue import subprocess import sys +import threading =20 =20 def parse_args(): @@ -14,6 +17,12 @@ def parse_args(): dest=3D"build_dir", default=3D".", help=3D"Path to build directory") + parser.add_argument( + "-j", + dest=3D"thread_num", + default=3Dmultiprocessing.cpu_count(), + type=3Dint, + help=3D"Number of threads to run") =20 return parser.parse_args() =20 @@ -38,28 +47,39 @@ def run_clang_tidy(item): =20 =20 def worker(): - for item in items: + while True: + item =3D items.get() os.chdir(item["directory"]) =20 print(item["file"]) =20 result =3D run_clang_tidy(item) =20 - if result["returncode"] !=3D 0: - findings.append(item["file"]) - if result["stdout"]: - print(result["stdout"]) - if result["stderr"]: - print(result["stderr"]) + with lock: + if result["returncode"] !=3D 0: + findings.append(item["file"]) + if result["stdout"]: + print(result["stdout"]) + if result["stderr"]: + print(result["stderr"]) + + items.task_done() =20 =20 args =3D parse_args() +items =3D queue.Queue() +lock =3D threading.Lock() findings =3D list() =20 +for _ in range(args.thread_num): + threading.Thread(target=3Dworker, daemon=3DTrue).start() + with open(os.path.join(args.build_dir, "compile_commands.json")) as f: - items =3D json.load(f) + compile_commands =3D json.load(f) + for compile_command in compile_commands: + items.put(compile_command) =20 -worker() +items.join() =20 if findings: print("Findings in %s file(s):" % len(findings)) --=20 2.26.2