From patchwork Tue Jun 18 14:39:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Slavomir Kaslev X-Patchwork-Id: 11001873 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 189FA1902 for ; Tue, 18 Jun 2019 14:40:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 081A328470 for ; Tue, 18 Jun 2019 14:40:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F0941286DA; Tue, 18 Jun 2019 14:40:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7BF8728470 for ; Tue, 18 Jun 2019 14:40:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729174AbfFROkM (ORCPT ); Tue, 18 Jun 2019 10:40:12 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:52964 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728572AbfFROkM (ORCPT ); Tue, 18 Jun 2019 10:40:12 -0400 Received: by mail-wm1-f67.google.com with SMTP id s3so3599520wms.2 for ; Tue, 18 Jun 2019 07:40:10 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=hk6cusv+uK9Vs9ucOV0chmDxi5bH1nrn5N/xtNmAzhs=; b=YfyPnH9rt0gd44sMxeadDgDTKCtsNlzZeC19BSz8mhT+mQT7SJBm8CKspj1m37Sqv/ QAnBCInSzWV+CR4q5Ij5c5wCjSu6NuOmfsVRJhSFibDinrdRrFk8e7Fw9aavfdwJqiKd RpUkd+Csj7zDC9lc7Qcy13f+9EyYOkmyUlPSnivKpN1FF3CCdNX1ht0dRo1W6Blk3t2y OWGF3/NZJVOwGcRogcBRzbcihUWccwGM4FoAHJdBvXuaVVyMCboLnMaTn27m0/5VZi6H P5O+p9bxO83DdqCn2vjS1o9vgAaoTQo3GGkH04rX9dB4uRDE+vSe/CU2UII4mBg8WRRd agKA== 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=hk6cusv+uK9Vs9ucOV0chmDxi5bH1nrn5N/xtNmAzhs=; b=HHzgr+epY8GyRe6csxixdTykagZ0oVGX711QV3FwBzk2NvV7Q38TeHHtG7fn20F/6P WkO7YymqQlGdWlILFUfw8ZCjLuVPLDYpHE67+LsW4XQCOLQTDnJIG7q8EpxjBdjs3UGR 22RjSDRVpKzjCTE0szHVhI2kTSTiygOIBMn433zW6cxSYJTFEFo0bgecg9XrzDogcMkG RPitcKGCeGM0ZT5icXb+Sdc2ocm3j9NWDNLKWlJ9ornLS4bx2xLukZLHitTXh6u3Ui2V 3YVwj/yx7eLIzMxf2HSn+MfbhcDNmBR8vdjLgeDSPvGG3amCHM+GVZd02Y+0lGzt8ckN IeAg== X-Gm-Message-State: APjAAAX0QXZ+aoEH0StMC/klvN2WMnnRdfnaVR/bKWH8NWob/RWOqjY6 LrVGSVe5HlOADhadPdBXZrrdSHY= X-Google-Smtp-Source: APXvYqydp+YdzX3RshxbLe/59U8sovZuimPmOzGXDz0FPo6yZHqJ/X4774xEJL9gjjsb8dk6WE6eRA== X-Received: by 2002:a1c:3942:: with SMTP id g63mr3605832wma.61.1560868809964; Tue, 18 Jun 2019 07:40:09 -0700 (PDT) Received: from box.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id y1sm2411808wma.32.2019.06.18.07.40.08 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 18 Jun 2019 07:40:09 -0700 (PDT) From: "Slavomir Kaslev (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v11 03/13] trace-cmd: Add tracecmd_create_recorder_virt() function Date: Tue, 18 Jun 2019 17:39:48 +0300 Message-Id: <20190618143958.2865-4-slavomir.kaslev@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190618143958.2865-1-slavomir.kaslev@gmail.com> References: <20190618143958.2865-1-slavomir.kaslev@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 X-Virus-Scanned: ClamAV using ClamSMTP From: Slavomir Kaslev Add tracecmd_create_recorder_virt() which creates tracecmd_recorder recording tracing data from the trace_fd parameter instead of from the local systems tracefs. It will be used for recording tracing data coming from VMs. Signed-off-by: Slavomir Kaslev Signed-off-by: Slavomir Kaslev (VMware) --- include/trace-cmd/trace-cmd.h | 1 + lib/trace-cmd/trace-recorder.c | 61 +++++++++++++++++++++++++--------- 2 files changed, 47 insertions(+), 15 deletions(-) diff --git a/include/trace-cmd/trace-cmd.h b/include/trace-cmd/trace-cmd.h index 923015e..28b5b38 100644 --- a/include/trace-cmd/trace-cmd.h +++ b/include/trace-cmd/trace-cmd.h @@ -281,6 +281,7 @@ enum { void tracecmd_free_recorder(struct tracecmd_recorder *recorder); struct tracecmd_recorder *tracecmd_create_recorder(const char *file, int cpu, unsigned flags); struct tracecmd_recorder *tracecmd_create_recorder_fd(int fd, int cpu, unsigned flags); +struct tracecmd_recorder *tracecmd_create_recorder_virt(const char *file, int cpu, unsigned flags, int trace_fd); struct tracecmd_recorder *tracecmd_create_recorder_maxkb(const char *file, int cpu, unsigned flags, int maxkb); struct tracecmd_recorder *tracecmd_create_buffer_recorder_fd(int fd, int cpu, unsigned flags, const char *buffer); struct tracecmd_recorder *tracecmd_create_buffer_recorder(const char *file, int cpu, unsigned flags, const char *buffer); diff --git a/lib/trace-cmd/trace-recorder.c b/lib/trace-cmd/trace-recorder.c index 0bd0657..0ea7a87 100644 --- a/lib/trace-cmd/trace-recorder.c +++ b/lib/trace-cmd/trace-recorder.c @@ -154,16 +154,22 @@ tracecmd_create_buffer_recorder_fd2(int fd, int fd2, int cpu, unsigned flags, recorder->fd1 = fd; recorder->fd2 = fd2; - if (flags & TRACECMD_RECORD_SNAPSHOT) - ret = asprintf(&path, "%s/per_cpu/cpu%d/snapshot_raw", buffer, cpu); - else - ret = asprintf(&path, "%s/per_cpu/cpu%d/trace_pipe_raw", buffer, cpu); - if (ret < 0) - goto out_free; + if (buffer) { + if (flags & TRACECMD_RECORD_SNAPSHOT) + ret = asprintf(&path, "%s/per_cpu/cpu%d/snapshot_raw", + buffer, cpu); + else + ret = asprintf(&path, "%s/per_cpu/cpu%d/trace_pipe_raw", + buffer, cpu); + if (ret < 0) + goto out_free; + + recorder->trace_fd = open(path, O_RDONLY); + free(path); - recorder->trace_fd = open(path, O_RDONLY); - if (recorder->trace_fd < 0) - goto out_free; + if (recorder->trace_fd < 0) + goto out_free; + } if ((recorder->flags & TRACECMD_RECORD_NOSPLICE) == 0) { ret = pipe(recorder->brass); @@ -183,13 +189,9 @@ tracecmd_create_buffer_recorder_fd2(int fd, int fd2, int cpu, unsigned flags, recorder->pipe_size = pipe_size; } - free(path); - return recorder; out_free: - free(path); - tracecmd_free_recorder(recorder); return NULL; } @@ -200,8 +202,9 @@ tracecmd_create_buffer_recorder_fd(int fd, int cpu, unsigned flags, const char * return tracecmd_create_buffer_recorder_fd2(fd, -1, cpu, flags, buffer, 0); } -struct tracecmd_recorder * -tracecmd_create_buffer_recorder(const char *file, int cpu, unsigned flags, const char *buffer) +static struct tracecmd_recorder * +__tracecmd_create_buffer_recorder(const char *file, int cpu, unsigned flags, + const char *buffer) { struct tracecmd_recorder *recorder; int fd; @@ -264,6 +267,34 @@ tracecmd_create_buffer_recorder_maxkb(const char *file, int cpu, unsigned flags, goto out; } +struct tracecmd_recorder * +tracecmd_create_buffer_recorder(const char *file, int cpu, unsigned flags, + const char *buffer) +{ + return __tracecmd_create_buffer_recorder(file, cpu, flags, buffer); +} + +/** + * tracecmd_create_recorder_virt - Create a recorder reading tracing data + * from the trace_fd file descriptor instead of from the local tracefs + * @file: output filename where tracing data will be written + * @cpu: which CPU is being traced + * @flags: flags configuring the recorder (see TRACECMD_RECORDER_* enums) + * @trace_fd: file descriptor from where tracing data will be read + */ +struct tracecmd_recorder * +tracecmd_create_recorder_virt(const char *file, int cpu, unsigned flags, + int trace_fd) +{ + struct tracecmd_recorder *recorder; + + recorder = __tracecmd_create_buffer_recorder(file, cpu, flags, NULL); + if (recorder) + recorder->trace_fd = trace_fd; + + return recorder; +} + struct tracecmd_recorder *tracecmd_create_recorder_fd(int fd, int cpu, unsigned flags) { const char *tracing;