From patchwork Wed Apr 28 12:28:35 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: 12228667 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=-15.7 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,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 D4244C433ED for ; Wed, 28 Apr 2021 12:28:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 88F9761158 for ; Wed, 28 Apr 2021 12:28:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235956AbhD1M3a (ORCPT ); Wed, 28 Apr 2021 08:29:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233027AbhD1M3a (ORCPT ); Wed, 28 Apr 2021 08:29:30 -0400 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12245C061574 for ; Wed, 28 Apr 2021 05:28:44 -0700 (PDT) Received: by mail-ej1-x631.google.com with SMTP id u17so94454547ejk.2 for ; Wed, 28 Apr 2021 05:28:43 -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=paqJ12TSx/7K5HmjtNb5+XQ9nscLWH8EPsbfy8ABDHA=; b=cYqFKXiItSXMW7EhfF6Lu1/TEWwmCeRGqxbLVZFRk6T0W8ZswArlxWB5AFVQwI3UP2 7rBUPkZehRoYDpXqUBVWq2y4rp4xxVQKQWLWRrYOYN2S7AODjF0VJXbonB2lWo0ASQJb 90za965bQNJkZhUWrQX84QGN/xrN3Ila0APxVCT4kEntmMdKuNEpBqjJlv9JoqHPeL2c fFbaHJCgvlEWeK/6nJo0DcuLrqZvRvCq44eZseXVqdWbB0c9J2mNiDWRlu97JWbVLQ/1 bsEsvIGbyC92AqVQ5jIszmN8ftTLqheo8l3qLFnhfA1RkXUYMbob+AQMmPbU8F8K9U+p MjHA== 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=paqJ12TSx/7K5HmjtNb5+XQ9nscLWH8EPsbfy8ABDHA=; b=udTTsQn5lK26kXKPVXUAyFKgT/JzvtEXnarY4rjodWdmxDJSWpUsWDqbiOttpPxovl bNTd23yjMvnmJ/frdCLsrOAkY698S5KdRJdh2aIWoJp6aFJaRXrTg1asw9M17MQ5Fjs5 QCRF1usu5RVAbcZ/T/Q6KWK1brOBK/7vLrEU1nGko/FuHYRhwXJPCTRSNypJbuTHcIJf n0pb8uBlRn2mUjgUYnidXtJcRhnXYVea8E9FOKiYwRscSYWAs5ZbtgIfZaZicMtEIqUm rwWzfTKZsGVlyzIbdRJ5YcSI7NZR9zFSN7QmIbrzjkWAbJAb9oL2yzDls1/cMI4CWcfv hDow== X-Gm-Message-State: AOAM531uMRyH2r+5v2H4KyJypBDn8ZMzXTtTFbYYjzW3AiEatQMyEPGb H0/q70wsTS6laz+BEuwEYu0= X-Google-Smtp-Source: ABdhPJwhuCTpAHzESFr/mwgm8ZNRauMYpECywiN5uEbc33Y7lqbWViSEenInwiCmhN324Vy2MsaILg== X-Received: by 2002:a17:906:828b:: with SMTP id h11mr20630391ejx.305.1619612922837; Wed, 28 Apr 2021 05:28:42 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id n10sm1846546ejg.124.2021.04.28.05.28.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Apr 2021 05:28:42 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH 1/5] trace-cmd: Remove ts offset from tsc2nsec conversion Date: Wed, 28 Apr 2021 15:28:35 +0300 Message-Id: <20210428122839.805296-2-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210428122839.805296-1-tz.stoyanov@gmail.com> References: <20210428122839.805296-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Do not get, store and use offset when converting TSC to nanoseconds. The logic for automatically detecting the TSC offset is not stable enough and could introduce errors, which leads to problems when reading trace files in some use cases. The offset is not mandatory for tsc2nsec conversion. Signed-off-by: Tzvetomir Stoyanov (VMware) --- lib/trace-cmd/trace-input.c | 1 - tracecmd/trace-record.c | 62 ------------------------------------- 2 files changed, 63 deletions(-) diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index a00fa982..e8a257db 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -1319,7 +1319,6 @@ static unsigned long long timestamp_calc(unsigned long long ts, int cpu, ts *= handle->ts2secs; } else if (handle->tsc_calc.mult) { /* auto calculated TSC clock frequency */ - ts -= handle->tsc_calc.offset; ts = mul_u64_u32_shr(ts, handle->tsc_calc.mult, handle->tsc_calc.shift); } diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index fd03a605..d732b394 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -6483,65 +6483,6 @@ static bool has_local_instances(void) return false; } -/* - * Get the current clock value - */ -#define CLOCK_INST_NAME "_clock_instance_" -static unsigned long long get_clock_now(const char *clock) -{ - struct tracefs_instance *ts_instance = NULL; - unsigned long long ts = 0; - struct tep_handle *tep; - int tfd; - int ret; - - /* Set up a tep to read the raw format */ - tep = get_ftrace_tep(); - if (!tep) - return 0; - ts_instance = tracefs_instance_create(CLOCK_INST_NAME); - if (!ts_instance) - goto out; - if (clock) { - ret = tracefs_instance_file_write(ts_instance, "trace_clock", clock); - if (ret < strlen(clock)) - goto out; - } - tfd = tracefs_instance_file_open(ts_instance, "trace_marker", O_WRONLY); - if (tfd < 0) - goto out; - tracefs_trace_on(ts_instance); - ret = write(tfd, STAMP, 5); - tracefs_trace_off(ts_instance); - ts = find_time_stamp(tep, ts_instance); - close(tfd); - -out: - if (ts_instance) { - if (tracefs_instance_is_new(ts_instance)) - tracefs_instance_destroy(ts_instance); - tracefs_instance_free(ts_instance); - } - tep_free(tep); - - return ts; -} - -static void get_tsc_offset(struct common_record_context *ctx) -{ - struct buffer_instance *instance; - - for_all_instances(instance) { - if (is_guest(instance) || !instance->clock) - continue; - - ctx->tsc2nsec.offset = get_clock_now(instance->clock); - return; - } - - ctx->tsc2nsec.offset = get_clock_now(NULL); -} - static void set_tsync_params(struct common_record_context *ctx) { struct buffer_instance *instance; @@ -6566,7 +6507,6 @@ static void set_tsync_params(struct common_record_context *ctx) die("Cannot not allocate clock"); ctx->tsc2nsec.mult = mult; ctx->tsc2nsec.shift = shift; - ctx->tsc2nsec.offset = get_clock_now(TSC_CLOCK); force_tsc = true; } else { /* Use the current clock of the first host instance */ clock = get_trace_clock(true); @@ -6661,8 +6601,6 @@ static void record_trace(int argc, char **argv, for_all_instances(instance) set_clock(instance); - if (ctx->tsc2nsec.mult) - get_tsc_offset(ctx); /* Record records the date first */ if (ctx->date && From patchwork Wed Apr 28 12:28:36 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: 12228669 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=-15.7 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,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 17B97C433B4 for ; Wed, 28 Apr 2021 12:28:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D91AA61423 for ; Wed, 28 Apr 2021 12:28:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233027AbhD1M3b (ORCPT ); Wed, 28 Apr 2021 08:29:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235833AbhD1M3a (ORCPT ); Wed, 28 Apr 2021 08:29:30 -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 D7B5AC06138A for ; Wed, 28 Apr 2021 05:28:44 -0700 (PDT) Received: by mail-ed1-x534.google.com with SMTP id j28so9960809edy.9 for ; Wed, 28 Apr 2021 05:28:44 -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=RmxnJl/Q/4nxbDmX0g/m7vKjWl0cphQhiKjiNds0feU=; b=jPOdEwT3h7yp1NGCnTjJrxJKXGlihNyCyeeU7Qo+jlxZG5d8CBqr8HOFeyf1t1Q5Nx g+hi+aPKNCPMM6nkTCVLwIPFBeSG2kHR0xWFINSloT0LxEAXyWXrhjPhjs7lidG36LYK fRAaaJAGLDhbg4bX46UilWdtCmauuIRVY65GNJHMYZg1ztMI4Ku5fZxy9Pggw4VLtNKZ 61a7aWzH1V/qJBoYOdvH4rZA2ohzQZi5caLyn8IQC/8UfTED0WNJUDPPfDNJ99//C9Ec /7JO+26rHV2JQ96vjMC36OaGPY4i1eBYNFSEuQrsmLoBl6A+49CyO7PKi54MvJrA/6t1 ECiA== 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=RmxnJl/Q/4nxbDmX0g/m7vKjWl0cphQhiKjiNds0feU=; b=aqNybd0kJTinjio+SmE2yWK2w72lhzDZ5CX10BVeWxDzJ8rBx2dtNwn/OAaJSOO/4M o1JPqQQHGTC1OO2F8nDOR4dbv5JpffGGIBSFxXEoY86MkTS8tMCxubkJjImeGrft9OAj oblXKNM08gGiQjQPiSXLLSi3o6JLvPdUlA1xyskNydxHx/dIL+FQc2sWTCY7eVUb+ONK hFHHoy3wDex7l0PlwmZdz/9vXDWEO+AZYGGrUQRRFAGYnp1xM+yFPau+5GACriIH8ec6 asMw+eWXokOd70vEVDutPTU8ghM8xu0Js3uHEkfxmCrFbJGUmt6yXVi0JlYYuGT6ypwH SlVA== X-Gm-Message-State: AOAM530LWANUNpiKDnzstQ1k3stS2ss6kJjsDGnoE29piwP+aVFINKy3 OcdJgGOenP40TvjLbKKfnlI= X-Google-Smtp-Source: ABdhPJzA+ZMnXdOt2XFUVoaO/QGxIfcQlfQltllpH/BlsDQi5kho/Lq/F6JJT/Genxrip6xuyjnLdA== X-Received: by 2002:aa7:cc98:: with SMTP id p24mr10780507edt.187.1619612923696; Wed, 28 Apr 2021 05:28:43 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id n10sm1846546ejg.124.2021.04.28.05.28.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Apr 2021 05:28:43 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH 2/5] trace-cmd library: Remove useless check before applying ts offset Date: Wed, 28 Apr 2021 15:28:36 +0300 Message-Id: <20210428122839.805296-3-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210428122839.805296-1-tz.stoyanov@gmail.com> References: <20210428122839.805296-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org Checking if offset is non-zero before adding to the timestamp is useless, as adding 0 will not change the timestamp. Signed-off-by: Tzvetomir Stoyanov (VMware) --- lib/trace-cmd/trace-input.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index e8a257db..bacf9ccf 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -1323,8 +1323,7 @@ static unsigned long long timestamp_calc(unsigned long long ts, int cpu, } /* User specified time offset with --ts-offset or --date options */ - if (handle->ts_offset) - ts += handle->ts_offset; + ts += handle->ts_offset; return ts; } From patchwork Wed Apr 28 12:28:37 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: 12228673 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=-15.7 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,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 333E2C43460 for ; Wed, 28 Apr 2021 12:28:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 042C76141E for ; Wed, 28 Apr 2021 12:28:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235833AbhD1M3b (ORCPT ); Wed, 28 Apr 2021 08:29:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236337AbhD1M3a (ORCPT ); Wed, 28 Apr 2021 08:29:30 -0400 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0BD93C061574 for ; Wed, 28 Apr 2021 05:28:46 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id g14so14284307edy.6 for ; Wed, 28 Apr 2021 05:28: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:in-reply-to:references :mime-version:content-transfer-encoding; bh=RoHJW8v1IN+0e0bayeOW7SbjCJ8zaHs6/DcIJkhnGXw=; b=lhNCthXlAhPcJ2n2UdBEGyqJhOeTuVOBT9uBc8zdUKI5wfDsbtsBgz6QpGh4d6KBXJ m2Tn9V294bihpH3XFbwp8z7pH42WDebZvZyfrDcyuYuQBuiG8n9UkZDEbP+ozLPyXtuf JxLD4ek9Pv1D7FhslT/SLpffI+zwi0uaPTW6sFNhmqCBW6yr8bFfSIgpvVTphVLzX1Du XajtjLwhPSRG8/sbxOCe4MN7hhL3iQKAP5njD51zwkUnLKQIXKl+xA+My5ohx5e1eFDj iddMNHcpFuu9ZF8WDQiYkVHzscnIXFhlYa1+8j5fonVCqogdhtlnZzNx7J01F0u9CD4G 5Lxw== 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=RoHJW8v1IN+0e0bayeOW7SbjCJ8zaHs6/DcIJkhnGXw=; b=J84DM76gBlXTXNLwB58qpmOCk6Ab/HSa+/YfD7J28iVBctZBR440iiwNYCugbhgBJI AkWGBxOCLBnmgQZx9s7hpLhlpEP4kepnxsj4wHmLBk4qM46L14PZRf4N4hFhUH1OMtcv Y2xkJKYT7GdtPjq/zhDynsgioTFiKtfyqZbqHD7IxDWzqbrgOiK/JfpPp9SKlcc/J0aE DsizOK+LcR/nB4HBfGT42Rh0tlGcSBZlMlJjFhwNmdj+tWVkUVWANrWrXjCRmvoxlpzs Jvd5oEBDRpVfR3CH4renXu6SI+rc0MNS4neWfF4HxegDIKncvjlyy418XGPD/5ALOe/2 ro2A== X-Gm-Message-State: AOAM532Dts7JGkuPzedAEhFlQ2uXr7Qt3mb5DE7Oe9OL5a3gvrzRZ/GO 76TiQUpTFzt8wMEzMtYD8ftlSJifJY9E3g== X-Google-Smtp-Source: ABdhPJxyr6QVk95AdO5Z3OaG+T3mDpdALismX/R6yvkxem+nPufz+SrEQTb+sqVC/XnNKNdrv1nurQ== X-Received: by 2002:aa7:d543:: with SMTP id u3mr10892043edr.26.1619612924860; Wed, 28 Apr 2021 05:28:44 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id n10sm1846546ejg.124.2021.04.28.05.28.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Apr 2021 05:28:44 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH 3/5] trace-cmd library: Store the timestamp of the first event when reading a trace file Date: Wed, 28 Apr 2021 15:28:37 +0300 Message-Id: <20210428122839.805296-4-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210428122839.805296-1-tz.stoyanov@gmail.com> References: <20210428122839.805296-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org When reading a trace file, detect and store the timestamp of the first recorded event. A new API is introduced to get the first ts from an input handler: tracecmd_get_first_ts() The first ts can be used by the library users to align timestamps of the events, when displaying them. Signed-off-by: Tzvetomir Stoyanov (VMware) --- include/trace-cmd/trace-cmd.h | 1 + lib/trace-cmd/trace-input.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/trace-cmd/trace-cmd.h b/include/trace-cmd/trace-cmd.h index 162cd318..022720b0 100644 --- a/include/trace-cmd/trace-cmd.h +++ b/include/trace-cmd/trace-cmd.h @@ -37,6 +37,7 @@ int tracecmd_get_guest_cpumap(struct tracecmd_input *handle, unsigned long long trace_id, const char **name, int *vcpu_count, const int **cpu_pid); +unsigned long long tracecmd_get_first_ts(struct tracecmd_input *handle); int tracecmd_buffer_instances(struct tracecmd_input *handle); const char *tracecmd_buffer_instance_name(struct tracecmd_input *handle, int indx); struct tracecmd_input *tracecmd_buffer_instance_handle(struct tracecmd_input *handle, int indx); diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index bacf9ccf..284f25e8 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -61,6 +61,7 @@ struct cpu_data { unsigned long long offset; unsigned long long size; unsigned long long timestamp; + unsigned long long first_ts; struct list_head page_maps; struct page_map *page_map; struct page **pages; @@ -2273,6 +2274,7 @@ static int init_cpu(struct tracecmd_input *handle, int cpu) if (update_page_info(handle, cpu)) goto fail; + cpu_data->first_ts = cpu_data->timestamp; return 0; fail: @@ -4072,6 +4074,27 @@ unsigned long long tracecmd_get_traceid(struct tracecmd_input *handle) return handle->trace_id; } +/** + * tracecmd_get_first_ts - get the timestamp of the first recorded event + * @handle: input handle for the trace.dat file + * + * Returns the timestamp of the first recorded event + */ +unsigned long long tracecmd_get_first_ts(struct tracecmd_input *handle) +{ + unsigned long long ts = 0; + bool first = true; + int i; + + for (i = 0; i < handle->cpus; i++) { + if (first || ts > handle->cpu_data[i].first_ts) + ts = handle->cpu_data[i].first_ts; + first = false; + } + + return ts; +} + /** * tracecmd_get_guest_cpumap - get the mapping of guest VCPU to host process * @handle: input handle for the trace.dat file From patchwork Wed Apr 28 12:28:38 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: 12228671 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=-15.7 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,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 2A93FC43461 for ; Wed, 28 Apr 2021 12:28:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E804661158 for ; Wed, 28 Apr 2021 12:28:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236337AbhD1M3c (ORCPT ); Wed, 28 Apr 2021 08:29:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236440AbhD1M3b (ORCPT ); Wed, 28 Apr 2021 08:29:31 -0400 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1ADF3C061574 for ; Wed, 28 Apr 2021 05:28:47 -0700 (PDT) Received: by mail-ej1-x631.google.com with SMTP id ja3so18460211ejc.9 for ; Wed, 28 Apr 2021 05:28:47 -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=gv5y3rqgeuatvJpCMSkmKG3E0fvmuYQPIfLH2BNYFg4=; b=VeHLgxL+eY08mOU+khxlo1dNgXX98KxFbo61NibHztmklfRmK0jE59ZaQvsTBo8YmN O4kXHvCTyecVbm9tNDqcbuUqFEjxHWwzQ6wtYkJlNsZryBoyMg3ObaN9X8yMMA6PQH4P gdX3DgcrhxbCBo4tAf8BRLwyYOMQhm/cXa3AqDq/Jcz4Dfp40InnmeswQ3GlIQUMxvQ+ sw2nXH6jN4qixb7RWoxkgzDBA7JforYqkutwSpMM2HmGASJJEDyOYXVvLz69ukzBMN2H CSDfVcU+mdPi3KsCahSDF7p2sxOdQFIl5980cURL7ps2t2eyR4W10vzz/L06TN5EeQui piAg== 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=gv5y3rqgeuatvJpCMSkmKG3E0fvmuYQPIfLH2BNYFg4=; b=VVnFX88VZG4sTCTVBS1I4O5Mdn4N8eNbnZJehAR4yMmzpXOEgs7+Oz1+EsER+QxwG1 6a3FsvOzEUAQTraKivNIF6lYmFKqxTwOtM4uLqYojXI6QmYY9U2RWbawKuKKdLgrE9KA ifOrrKeNVQ2iDSLFuyUdi/lJjo+SBwgUArzBAFXcm4EuxYRPxLd/H/HapZtSyb8uYUAt A7fF43bq8F1xkZs01MPX0CoDOQ/k3Beh7DbhhfsngbKrGLEN7YRk0aPaTV1m88eSJl0s fxZDbVUx+aOcvTnB6LIwvpLnBJ9QfuWaA65VA8C7NGE7JeHH6QHdEbd9azafIecJZOgF 64AQ== X-Gm-Message-State: AOAM532SYRf2C/DxjVZMBo1w6mKISqtIezTskRUAeafVhG/fBnEzg0m4 nW9/QZEfoxIQ55CLBu+Vue4= X-Google-Smtp-Source: ABdhPJwX6RQbQuE7hGUNMktGnspMeLv5Yi65EvDfDR2u4nPVQMPNQ5qtBIASoVpGM3o4wt+KCJXCwA== X-Received: by 2002:a17:906:f41:: with SMTP id h1mr29126062ejj.399.1619612925911; Wed, 28 Apr 2021 05:28:45 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id n10sm1846546ejg.124.2021.04.28.05.28.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Apr 2021 05:28:45 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH 4/5] trace-cmd library: New API for modifyning the timestamp offset Date: Wed, 28 Apr 2021 15:28:38 +0300 Message-Id: <20210428122839.805296-5-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210428122839.805296-1-tz.stoyanov@gmail.com> References: <20210428122839.805296-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org New API is introduced, it can be used to add value to the offset which will be applied to the timestamps of all events from given trace file: tracecmd_add_ts_offset() Signed-off-by: Tzvetomir Stoyanov (VMware) --- include/trace-cmd/trace-cmd.h | 1 + lib/trace-cmd/trace-input.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/include/trace-cmd/trace-cmd.h b/include/trace-cmd/trace-cmd.h index 022720b0..7305487c 100644 --- a/include/trace-cmd/trace-cmd.h +++ b/include/trace-cmd/trace-cmd.h @@ -38,6 +38,7 @@ int tracecmd_get_guest_cpumap(struct tracecmd_input *handle, const char **name, int *vcpu_count, const int **cpu_pid); unsigned long long tracecmd_get_first_ts(struct tracecmd_input *handle); +void tracecmd_add_ts_offset(struct tracecmd_input *handle, long long offset); int tracecmd_buffer_instances(struct tracecmd_input *handle); const char *tracecmd_buffer_instance_name(struct tracecmd_input *handle, int indx); struct tracecmd_input *tracecmd_buffer_instance_handle(struct tracecmd_input *handle, int indx); diff --git a/lib/trace-cmd/trace-input.c b/lib/trace-cmd/trace-input.c index 284f25e8..6adc8bfa 100644 --- a/lib/trace-cmd/trace-input.c +++ b/lib/trace-cmd/trace-input.c @@ -2291,6 +2291,18 @@ void tracecmd_set_ts_offset(struct tracecmd_input *handle, handle->ts_offset = offset; } +/** + * tracecmd_add_ts_offset - Add value to the offset which will be applied to the timestamps of all + * events from given trace file + * @handle: input handle to the trace.dat file + * @offset: value, that will be added to the offset + */ +void tracecmd_add_ts_offset(struct tracecmd_input *handle, + long long offset) +{ + handle->ts_offset += offset; +} + void tracecmd_set_ts2secs(struct tracecmd_input *handle, unsigned long long hz) { From patchwork Wed Apr 28 12:28:39 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: 12228675 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=-15.7 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,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 A1C0EC433ED for ; Wed, 28 Apr 2021 12:28:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 72D2A61158 for ; Wed, 28 Apr 2021 12:28:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236510AbhD1M3d (ORCPT ); Wed, 28 Apr 2021 08:29:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236440AbhD1M3c (ORCPT ); Wed, 28 Apr 2021 08:29:32 -0400 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28103C061574 for ; Wed, 28 Apr 2021 05:28:48 -0700 (PDT) Received: by mail-ej1-x634.google.com with SMTP id l4so94310226ejc.10 for ; Wed, 28 Apr 2021 05:28:48 -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=E3/GLc9HOJghtk+5bbfMzNmXgDl+RfCWLyXeCvn0fco=; b=ttiKoRP5AYz9Zz53LyyVqj2PmeTIoGMKMSidLoGBmHo5j6coA8H9CdPI6222l8kp8t 0cAIgxmjkntOph6lIfpCgQFC83MqpgU8qqOwCYFffwULgUKZqKE3NuOwT8f0ET6vwAg8 baT0cnA+I/Vr8jZ41N/DVHHZyc4TSDo0IAHt3t5Pwrm9svQ5b5IHm5NYlqexdrbE5yCY 1dHxkN0KF7dTioumEZh6ONg3gHK9R8Pz+dcy9y7dWbkaQFc4c8nm2DzHGjPKE8gyKBZq wlpOW+hXxB6z90rGzbEMQCPYmrCL/5lnjBUf8iZAZOvLdnY8hhaCfTs166P1GNQxzQp8 79wA== 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=E3/GLc9HOJghtk+5bbfMzNmXgDl+RfCWLyXeCvn0fco=; b=KAWmki6jtnrJotiQSB8R0w67NJGIKbVOU/nmHWuALmj4oBTaFCs5nPfbb8SAYyfVBh tTWxesEPtQLpD3J6Yb+YKrin9nAT39r56GuYXilFdFb8MBnBfSmHNj3nm+o6fYQGHscQ Q/9yniSfDDY1VPGbEVM/f3isf9Ics3fllzDOClUoSKW3OJ8vMxnLVcTqvfneNA0Zkz8Z LYde7hHy0kimr09F4Vabnvx6RqjZED1YXzMG55492KgFipCEjfcCuuSddN6kQuiYyv4k LGJZwv4b7XE9XXu7YUVnY+ZrHCFvZKcXZxTUst8JzfghpbDUeMtGKKQOYMbW6zZULUbW xp1Q== X-Gm-Message-State: AOAM531bvbl7Vf1BGcaHFMiRdJLFGNkKopWfQXSFHuHbsE0aCByGi0aJ ZZz6y2/OaCng2+7KyTSBWpU= X-Google-Smtp-Source: ABdhPJxr94SHnneJvdh4DjMqdGmprKRuRnyhAmmcEAuRtgNvSbj5q/acpfB8ankadwex/N8D963yrg== X-Received: by 2002:a17:907:7283:: with SMTP id dt3mr28580973ejc.47.1619612926911; Wed, 28 Apr 2021 05:28:46 -0700 (PDT) Received: from oberon.zico.biz ([83.222.187.186]) by smtp.gmail.com with ESMTPSA id n10sm1846546ejg.124.2021.04.28.05.28.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Apr 2021 05:28:46 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH 5/5] trace-cmd report: New option --align-ts Date: Wed, 28 Apr 2021 15:28:39 +0300 Message-Id: <20210428122839.805296-6-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210428122839.805296-1-tz.stoyanov@gmail.com> References: <20210428122839.805296-1-tz.stoyanov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org A new option is added: trace-cmd report --align-ts It shows timestamps aligned to the first recorded event. Signed-off-by: Tzvetomir Stoyanov (VMware) --- tracecmd/trace-read.c | 25 ++++++++++++++++++++++--- tracecmd/trace-usage.c | 1 + 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/tracecmd/trace-read.c b/tracecmd/trace-read.c index d962b671..4a7bdb9c 100644 --- a/tracecmd/trace-read.c +++ b/tracecmd/trace-read.c @@ -1192,14 +1192,16 @@ enum output_type { }; static void read_data_info(struct list_head *handle_list, enum output_type otype, - int global) + int global, int align_ts) { + unsigned long long ts, first_ts; struct handle_list *handles; struct handle_list *last_handle; struct tep_record *record; struct tep_record *last_record; struct tep_handle *pevent; struct tep_event *event; + int first = 1; int ret; list_for_each_entry(handles, handle_list, list) { @@ -1218,7 +1220,12 @@ static void read_data_info(struct list_head *handle_list, enum output_type otype ret = tracecmd_init_data(handles->handle); if (ret < 0) die("failed to init data"); - + if (align_ts) { + ts = tracecmd_get_first_ts(handles->handle); + if (first || first_ts > ts) + first_ts = ts; + first = 0; + } print_handle_file(handles); printf("cpus=%d\n", cpus); @@ -1286,6 +1293,12 @@ static void read_data_info(struct list_head *handle_list, enum output_type otype if (otype != OUTPUT_NORMAL) return; + if (align_ts) { + list_for_each_entry(handles, handle_list, list) { + tracecmd_add_ts_offset(handles->handle, -first_ts); + } + } + do { last_handle = NULL; last_record = NULL; @@ -1485,6 +1498,7 @@ static void add_hook(const char *arg) } enum { + OPT_align_ts = 235, OPT_raw_ts = 236, OPT_version = 237, OPT_tscheck = 238, @@ -1536,6 +1550,7 @@ void trace_report (int argc, char **argv) int nanosec = 0; int no_date = 0; int raw_ts = 0; + int align_ts = 0; int global = 0; int neg = 0; int ret = 0; @@ -1578,6 +1593,7 @@ void trace_report (int argc, char **argv) {"ts-diff", no_argument, NULL, OPT_tsdiff}, {"ts-check", no_argument, NULL, OPT_tscheck}, {"raw-ts", no_argument, NULL, OPT_raw_ts}, + {"align-ts", no_argument, NULL, OPT_align_ts}, {"help", no_argument, NULL, '?'}, {NULL, 0, NULL, 0} }; @@ -1753,6 +1769,9 @@ void trace_report (int argc, char **argv) case OPT_raw_ts: raw_ts = 1; break; + case OPT_align_ts: + align_ts = 1; + break; default: usage(argv); } @@ -1883,7 +1902,7 @@ void trace_report (int argc, char **argv) /* and version overrides uname! */ if (show_version) otype = OUTPUT_VERSION_ONLY; - read_data_info(&handle_list, otype, global); + read_data_info(&handle_list, otype, global, align_ts); list_for_each_entry(handles, &handle_list, list) { tracecmd_close(handles->handle); diff --git a/tracecmd/trace-usage.c b/tracecmd/trace-usage.c index 98247074..97b3aec0 100644 --- a/tracecmd/trace-usage.c +++ b/tracecmd/trace-usage.c @@ -234,6 +234,7 @@ static struct usage_help usage_help[] = { " --ts-diff Show the delta timestamp between events.\n" " --ts-check Check to make sure no time stamp on any CPU goes backwards.\n" " --raw-ts Display raw timestamps, without any corrections.\n" + " --align-ts Display timestamps aligned to the first event.\n" }, { "stream",