From patchwork Fri May 14 04:11:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 12257053 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BDBD8C433B4 for ; Fri, 14 May 2021 04:11:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 955B261355 for ; Fri, 14 May 2021 04:11:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232062AbhENEM5 (ORCPT ); Fri, 14 May 2021 00:12:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231171AbhENEM5 (ORCPT ); Fri, 14 May 2021 00:12:57 -0400 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D219C061574 for ; Thu, 13 May 2021 21:11:45 -0700 (PDT) Received: by mail-ed1-x534.google.com with SMTP id a25so9117506edr.12 for ; Thu, 13 May 2021 21:11:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=IX0KKZglghbbf8vkSv88hhEs38ClBJYgzakn+vbrzbA=; b=cjwrnPKhAZN+86CNpXxa4LoPF3gNQhgdfRLOGJxUzWq7xobhAXF1tsjkzkeTOPOBgP DkELMWALdFt7+w1Bx+v/AFIxzd+4vRkJt0Fc0Q8DVJBldhRdAzz6x0nS78CgrOhzqNm8 m6OuJgaJepDaPCFwbu09uj+F7IIcNbd4V4dMPBcW2EAXEJ0Q30rhqfOOtrSdCMlPS89f dgLKIcF1jmZT6Bnhz32IeLFLdk9RIEaXxaoUbPlAeNI1F2gaISmX32pEpSm+7F3YTC/V ZBAbppRhSzjxwpMDXX7Apr6ZYP1dXn8gd03BjTZb9FPSIojLbVTPoQkDdF6ELtxzt6sr 3zlw== 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:mime-version :content-transfer-encoding; bh=IX0KKZglghbbf8vkSv88hhEs38ClBJYgzakn+vbrzbA=; b=BBw1cQEAXFr/8mysm0P9Hdi/KlhlR3+KI1SQL9aKwbqOctb+UVVxX+yLS+94AgRNBY obwieg75BrKsnmaCN41DrYo0v1JQuQ5iM2DFxox3SalUCLaqhHzo/qFVCBbwonTJM7Nk LlFU9QNA7KUorDp7sBSKfHkFgP5Z94F4HdAxYZRjOinGrIDDUqOj5tPbAjEd50qrIzBE i4Fgu8wuygn5olzf5pNrMbZGNjg8551fckVbOLsfnsgdPBjfC4UUqmvRxfNtv+5SSWWL dmzgrw8H0vD1Qwz6o2hg4UMEPzf4Q7Z9jYridi4AYaQu/I1qbaS3OsfBskLHgqx9oSTN QAHg== X-Gm-Message-State: AOAM532yFExphmrqNgrGianXsBX1yFNunnDI4QlDbkaZmM9qjNZR9nep y0ZykQK21ptEOTZ5GfRlMsDAMrde6gFGmA== X-Google-Smtp-Source: ABdhPJznp3QA3CEvbp0PKcGkgrAZS7nVUYHbmkHVXxSoSBa+Q+Gp0x5z4kyCgzj0lozPDfayox5/qg== X-Received: by 2002:a05:6402:883:: with SMTP id e3mr1080727edy.1.1620965503118; Thu, 13 May 2021 21:11:43 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id n25sm3638839edb.26.2021.05.13.21.11.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 May 2021 21:11:42 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v2] trace-cmd: Auto discover running KVM VMs using virsh Date: Fri, 14 May 2021 07:11:41 +0300 Message-Id: <20210514041141.11319-1-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org The "trace-cmd record -A " option, used for guest tracing, accepts VM name as parameter. But trace-cmd needs cid of that VM, in order to perform the tracing. The old logic searches for a process with name "qemu-system-" and parses its command line, to get guest name to cid relation. Using a hardcoded process name and relying on specific process command line arguments is not reliable way. There is no API to get VM name to cid relation, but virsh can be used instead of the old logic. As virsh is the official user interface to libvirt, it should be more reliable than the old approach. Signed-off-by: Tzvetomir Stoyanov (VMware) --- This patch depends on patch set: "[PATCH v3 0/2] trace-cmd: Use vsock tracing to find cids and threads" https://lore.kernel.org/linux-trace-devel/20210513204315.1206204-1-rostedt@goodmis.org/ v2 changes: - Remove the die() in case virsh is not available. tracecmd/trace-vm.c | 177 ++++++++++---------------------------------- 1 file changed, 41 insertions(+), 136 deletions(-) diff --git a/tracecmd/trace-vm.c b/tracecmd/trace-vm.c index 163536ca..d204411c 100644 --- a/tracecmd/trace-vm.c +++ b/tracecmd/trace-vm.c @@ -10,6 +10,7 @@ #include #include #include +#include #include "trace-local.h" #include "trace-msg.h" @@ -17,25 +18,6 @@ static struct trace_guest *guests; static size_t guests_len; -static int set_vcpu_pid_mapping(struct trace_guest *guest, int cpu, int pid) -{ - int *cpu_pid; - int i; - - if (cpu >= guest->cpu_max) { - cpu_pid = realloc(guest->cpu_pid, (cpu + 1) * sizeof(int)); - if (!cpu_pid) - return -1; - /* Handle sparse CPU numbers */ - for (i = guest->cpu_max; i < cpu; i++) - cpu_pid[i] = -1; - guest->cpu_max = cpu + 1; - guest->cpu_pid = cpu_pid; - } - guest->cpu_pid[cpu] = pid; - return 0; -} - static struct trace_guest *get_guest_by_cid(unsigned int guest_cid) { int i; @@ -330,140 +312,63 @@ struct trace_guest *trace_get_guest(unsigned int cid, const char *name) return guest; } -static char *get_qemu_guest_name(char *arg) -{ - char *tok, *end = arg; - - while ((tok = strsep(&end, ","))) { - if (strncmp(tok, "guest=", 6) == 0) - return tok + 6; - } - - return arg; -} - -static int read_qemu_guests_pids(char *guest_task, struct trace_guest *guest) +#define VM_CID_CMD "virsh dumpxml" +#define VM_CID_LINE "