From patchwork Tue May 17 13:10:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 12852472 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 68C2AC433FE for ; Tue, 17 May 2022 13:10:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346207AbiEQNKn (ORCPT ); Tue, 17 May 2022 09:10:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51008 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347243AbiEQNKe (ORCPT ); Tue, 17 May 2022 09:10:34 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 758843526C; Tue, 17 May 2022 06:10:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1652793033; x=1684329033; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CLsBVlIOB1svkFU1pGIbk69WpliItNCCGs4gSAnCKVw=; b=FxJK/rEHk1Ecclv48dly46DX53Rq9zqqcm2foyWiyNe+sSliu7AkMVw+ z5wzzB/qyypRmXI/5tklLWl2glOtPGCB7Fbb4ijXMzEytbm5KMzS8KUu1 xJZK0QwkgtEAAOKt+nBM0iK6ZhqhJLaSYEMvUh6w31E/LSM2WGkn/nveb b/k6XcU/bacCu7Tv0u6PZByIFwdFer7VqjljFsqJWZG50BKpdTYZR7ppR Q/ztcZVuHa7eV9QQPJTaA7SEHVRb9tDsz04i34/fKVe6Wpd0sB8aciI6k mFnuKi+S8Y+cgRwULK9aA00QFbzy1FwrcjcoR9ud7zyasv8vWdB67X4NO g==; X-IronPort-AV: E=McAfee;i="6400,9594,10349"; a="271300111" X-IronPort-AV: E=Sophos;i="5.91,232,1647327600"; d="scan'208";a="271300111" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 May 2022 06:10:33 -0700 X-IronPort-AV: E=Sophos;i="5.91,232,1647327600"; d="scan'208";a="713844280" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.252.52.217]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 May 2022 06:10:30 -0700 From: Adrian Hunter To: Arnaldo Carvalho de Melo Cc: Jiri Olsa , Namhyung Kim , Ian Rogers , Leo Yan , Andi Kleen , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, kvm@vger.kernel.org Subject: [PATCH V2 2/6] perf tools: Factor out thread__set_guest_comm() Date: Tue, 17 May 2022 16:10:07 +0300 Message-Id: <20220517131011.6117-3-adrian.hunter@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220517131011.6117-1-adrian.hunter@intel.com> References: <20220517131011.6117-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Factor out thread__set_guest_comm() so it can be reused. Signed-off-by: Adrian Hunter --- tools/perf/util/machine.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index e96f6ea4fd82..e67b5a7670f3 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c @@ -84,6 +84,14 @@ static int machine__set_mmap_name(struct machine *machine) return machine->mmap_name ? 0 : -ENOMEM; } +static void thread__set_guest_comm(struct thread *thread, pid_t pid) +{ + char comm[64]; + + snprintf(comm, sizeof(comm), "[guest/%d]", pid); + thread__set_comm(thread, comm, 0); +} + int machine__init(struct machine *machine, const char *root_dir, pid_t pid) { int err = -ENOMEM; @@ -119,13 +127,11 @@ int machine__init(struct machine *machine, const char *root_dir, pid_t pid) if (pid != HOST_KERNEL_ID) { struct thread *thread = machine__findnew_thread(machine, -1, pid); - char comm[64]; if (thread == NULL) goto out; - snprintf(comm, sizeof(comm), "[guest/%d]", pid); - thread__set_comm(thread, comm, 0); + thread__set_guest_comm(thread, pid); thread__put(thread); }