From patchwork Mon Apr 22 14:55:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Slavomir Kaslev X-Patchwork-Id: 10911123 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 E3C73922 for ; Mon, 22 Apr 2019 14:55:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D69EB28535 for ; Mon, 22 Apr 2019 14:55:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CABDC285A1; Mon, 22 Apr 2019 14:55:30 +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=-7.9 required=2.0 tests=BAYES_00,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 5932428535 for ; Mon, 22 Apr 2019 14:55:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727761AbfDVOza (ORCPT ); Mon, 22 Apr 2019 10:55:30 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:53564 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726132AbfDVOza (ORCPT ); Mon, 22 Apr 2019 10:55:30 -0400 Received: by mail-wm1-f66.google.com with SMTP id q16so14749801wmj.3 for ; Mon, 22 Apr 2019 07:55:28 -0700 (PDT) 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=+jKXiMJVBSmRt4N7Ao5wXmoY5NvvdQTgpjkfP32eMRU=; b=eUJrZ7sM1UAe7qJOBMyvjcp8jojNGb4yTLDixcjWBV2SXBpxizYY3wNBHUtdmh4QTx T+TXQq9b+6XjWP8yGTns4J2g6xtePWS6wnVxlm1Oz9ZQB9WERzrKPguys8ObXXLVKg6U IZ30FNzBr+MdvAB3iPPVJNvYUKxhDYA5OdreB3gMTlfUYkWMi8QIBxUZJhwC60Ml2vL5 BjTGynpZ/TjMPvILg+Pq9RTFWroD9wgBBzzswlJC+j72lBw2NMQeKhKmMAqrWKFMVxOg hFinTVrv3QkQulDVTcylQhEyabjAcuArn/BwGnEl6tqEbWvBhaM7EKxqfsLBfV2ybDHa CbtA== X-Gm-Message-State: APjAAAUad0pBsvX+qMSUMGIk26VTUK5E5SE3L/mzMcULyflKbfNbwy0j n5DW4l8plI3JYG66yC4fw+QItmnIxA== X-Google-Smtp-Source: APXvYqyWAmA23k2LZbFFRMiDuZWnc4KV6Wm1+8qyg6y7nefW1N5bTOw2OaztByLmIjfny9sPDuQ4Tw== X-Received: by 2002:a1c:a7c5:: with SMTP id q188mr12230820wme.126.1555944928157; Mon, 22 Apr 2019 07:55:28 -0700 (PDT) Received: from box.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id f128sm17321087wme.28.2019.04.22.07.55.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Apr 2019 07:55:26 -0700 (PDT) From: Slavomir Kaslev To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v10 03/12] trace-cmd: Add tracecmd_create_recorder_virt() function Date: Mon, 22 Apr 2019 17:55:10 +0300 Message-Id: <20190422145519.16146-4-kaslevs@vmware.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190422145519.16146-1-kaslevs@vmware.com> References: <20190422145519.16146-1-kaslevs@vmware.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 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 --- 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 98d8933..8e760ad 100644 --- a/include/trace-cmd/trace-cmd.h +++ b/include/trace-cmd/trace-cmd.h @@ -279,6 +279,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;