From patchwork Fri Nov 29 10:17:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Tzvetomir Stoyanov (VMware)" X-Patchwork-Id: 11266849 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C26F0109A for ; Fri, 29 Nov 2019 10:17:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9FCC020833 for ; Fri, 29 Nov 2019 10:17:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AUrTXRc9" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726881AbfK2KRt (ORCPT ); Fri, 29 Nov 2019 05:17:49 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:35356 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726871AbfK2KRt (ORCPT ); Fri, 29 Nov 2019 05:17:49 -0500 Received: by mail-lj1-f194.google.com with SMTP id j6so22380754lja.2 for ; Fri, 29 Nov 2019 02:17:48 -0800 (PST) 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=K8ZZRaXB75jmADvYv/7v8U9DJpWLr4FMA5xXySBgHmY=; b=AUrTXRc9cHOIxCgKyEWe9zn3keZ+YLs2Kk7NsF314qNdus8VxHek0myaRBYR1lkr0R iLZ8e8uGiixTdwz855QR7Ru2QRZSI/dgAcm5xHzIyWDkeOdUpUFjJLigdNIoaSUoB27A rFEjjX4C2Vpb9kewuSBLILqXHriI9mVj9NpDvAW46SDjhvGp2ytxowliUyphvEEQoikI 4R/54G5hNxyK/xla6Mm7vDQd5lNnGREPbWJL9C6itkxqfjRkDEXzTIsOoo749VWLeSH7 sVgbcrsDsy0W1yqXaO57t7GLe27qq5Gwiw7gIdtN7+uTPYfNCihWvamtK8WKH9CjcoJo S+FQ== 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=K8ZZRaXB75jmADvYv/7v8U9DJpWLr4FMA5xXySBgHmY=; b=UARKoznNg9S2k/kxAktci3idPS4uLAk4eo3BzrOcDCA8x/7J2f50JhcRh3DVS4KH1P NtPy9qfjlqYripzxrk+wejETLwz8R7B7AOCQt6UBdnABFaM3QO5D4kzd3cakcplS1JyJ Lm+qe4TS16tW5cpGBSbLYEA7mONEUq4HB19P8I2zSpuHlOhZ9GAyg2h6cDdy56MlhZ/S hNxkktojVtnXde2EOnu128/Q9gkGcyDbq3x++ksN0pJoy91QGVHNgp1d1VqiwhfOuUso 6E9zDNYrLIiEnrHDrZqKVGKyzpdpMVDTHNxzIpklRNhbcNBNc+liz09L4hOp120bIPre oifg== X-Gm-Message-State: APjAAAVE/5W5YqHAiYimg/G8aEgWEUNYBonUMJNEQI/enCQNwnd75KdS fdJntZfhQMDuMlVYHVJt9aU= X-Google-Smtp-Source: APXvYqwSGyOIImOvVdiB9Rz4GQmrbwYIP5C1GMdsRxQVdeTujWOqlrSCqwuopMgcni7hMwIwXyptdQ== X-Received: by 2002:a05:651c:285:: with SMTP id b5mr11434715ljo.14.1575022667275; Fri, 29 Nov 2019 02:17:47 -0800 (PST) Received: from oberon.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id x29sm11367935lfg.45.2019.11.29.02.17.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Nov 2019 02:17:46 -0800 (PST) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v16 09/18] trace-cmd: Add new API to generate a unique ID of the tracing session Date: Fri, 29 Nov 2019 12:17:24 +0200 Message-Id: <20191129101733.375808-10-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191129101733.375808-1-tz.stoyanov@gmail.com> References: <20191129101733.375808-1-tz.stoyanov@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 A new libtracecmd API is implemented: unsigned long long tracecmd_generate_traceid(void); At trace-cmd init phase a unique ID, used for the current tracing session. Signed-off-by: Tzvetomir Stoyanov (VMware) --- include/trace-cmd/trace-cmd.h | 1 + lib/trace-cmd/trace-util.c | 31 +++++++++++++++++++++++++++++++ tracecmd/include/trace-local.h | 1 + tracecmd/trace-record.c | 1 + 4 files changed, 34 insertions(+) diff --git a/include/trace-cmd/trace-cmd.h b/include/trace-cmd/trace-cmd.h index 47fa463..6d50b08 100644 --- a/include/trace-cmd/trace-cmd.h +++ b/include/trace-cmd/trace-cmd.h @@ -441,6 +441,7 @@ void tracecmd_plog_error(const char *fmt, ...); int tracecmd_set_logfile(char *logfile); /* --- System --- */ +unsigned long long tracecmd_generate_traceid(void); int tracecmd_count_cpus(void); /* --- Hack! --- */ diff --git a/lib/trace-cmd/trace-util.c b/lib/trace-cmd/trace-util.c index a54a905..2231eb8 100644 --- a/lib/trace-cmd/trace-util.c +++ b/lib/trace-cmd/trace-util.c @@ -18,6 +18,8 @@ #include #include #include +#include +#include #include "trace-cmd.h" #include "event-utils.h" @@ -1299,3 +1301,32 @@ error: tracecmd_put_tracing_file(path); return ret; } + +#define FNV_64_PRIME 0x100000001b3ULL +unsigned long long tracecmd_generate_traceid(void) +{ + unsigned long long hash = 0; + unsigned char *ustr; + struct sysinfo sinfo; + struct timespec ts; + char *str = NULL; + + clock_gettime(CLOCK_MONOTONIC_RAW, &ts); + sysinfo(&sinfo); + asprintf(&str, "%ld %ld %ld %ld %ld %ld %ld %ld %d", + ts.tv_sec, ts.tv_nsec, + sinfo.loads[0], sinfo.loads[1], sinfo.loads[2], + sinfo.freeram, sinfo.sharedram, sinfo.freeswap, + sinfo.procs); + if (!str) + return 0; + ustr = (unsigned char *)str; + hash = 0; + while (*ustr) { + hash ^= (unsigned long long)*ustr++; + hash *= FNV_64_PRIME; + } + + free(str); + return hash; +} diff --git a/tracecmd/include/trace-local.h b/tracecmd/include/trace-local.h index 51abef1..6203e0d 100644 --- a/tracecmd/include/trace-local.h +++ b/tracecmd/include/trace-local.h @@ -182,6 +182,7 @@ struct pid_addr_maps { struct buffer_instance { struct buffer_instance *next; struct tracecmd_instance *ftrace; + unsigned long long trace_id; char *cpumask; struct event_list *events; struct event_list **event_next; diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index fd7ca82..1583c53 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -5062,6 +5062,7 @@ void init_top_instance(void) top_instance.ftrace = tracecmd_create_instance(NULL); top_instance.cpu_count = tracecmd_count_cpus(); top_instance.flags = BUFFER_FL_KEEP; + top_instance.trace_id = tracecmd_generate_traceid(); tracecmd_init_instance(&top_instance); }