From patchwork Wed Aug 28 08:57:38 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: 11118303 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 3A79D18B7 for ; Wed, 28 Aug 2019 08:57:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1A8182339E for ; Wed, 28 Aug 2019 08:57:52 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iWw8HQ7e" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726408AbfH1I5v (ORCPT ); Wed, 28 Aug 2019 04:57:51 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:37561 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726293AbfH1I5v (ORCPT ); Wed, 28 Aug 2019 04:57:51 -0400 Received: by mail-wr1-f68.google.com with SMTP id z11so1647315wrt.4 for ; Wed, 28 Aug 2019 01:57:50 -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=eai9MBbxCuXWSarZzFNMEJ1uUK6ncd5rWyIboivmjk0=; b=iWw8HQ7etg5GU6Om7CuKRAinaiEWHEuHkmQGhTURTLS0eXPR8/Ehkhgveh/PL8HpME J4y6yI35MYLRMz6HbeCMALVCeIOqWfBEIkiVm7pyedYDDVXtkd5ERE/yyChEv2yPWmia s94lQ31X5pffrf5Y7MTN902MUaMu18wME0v5QvLYTF5JedtNwRkadcmq17cUBcpjTadF c/sZo9vCrvX+VJE0tqmepke0GMvu4Nw5s7hiLPO6+gblhhUnNJm9ZZgLQsczNoNXzdDJ 6e73bLr90Eg3nDYN+k1tDkQ7+r6Yk5PRrXDy/ZrxX/MqcHiP4AYG8cSr95XxuzNBTauw ViOg== 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=eai9MBbxCuXWSarZzFNMEJ1uUK6ncd5rWyIboivmjk0=; b=MFkkKO1wNXHO4f37vlDNYHYnZ5aD7AvWH4cYYL9N/nnc/bWTBoB0pJ00i7nnrralaO ro+gpEQIbGBAsMRpl4H3tS0bd6fvoyWlFw79N4IoujeUgki3aJf6+CcUPJovCFDfe7Qw tEZL7Nbfx3+Mxl7Ia2UFAkJTyj3emYV1Myj8nIKDISJeHbL8IzvFrA10oaDDIVEDv4NL I2dRYdW78WNxBkntcR0iL1i1As17AHcfd67hPzxXGrQqbqVyXS7qJT0JsG+m+Y5xd8dB CcdeN4Pa7vEljKs9VkdqW56/eYQL1Xg+o8iMyW+9g5fp2i0akxoHtT7LsUiOu+HYwww2 NFLQ== X-Gm-Message-State: APjAAAX2O/RMvG9S+2Y9rCN1+EOvTc8SYLD9O6byQIaT3zMuefrShifA ivx3taRoihxaHpvgjwtoYrLrWeDU X-Google-Smtp-Source: APXvYqxjZKL0tMiKmTSFmL+NruTybWB124o6vqe3dRuocVtJ4CzbBj0l6WX/QfpSN4WxcE43PHp0sg== X-Received: by 2002:adf:a48f:: with SMTP id g15mr3364386wrb.172.1566982669533; Wed, 28 Aug 2019 01:57:49 -0700 (PDT) Received: from oberon.eng.vmware.com ([146.247.46.5]) by smtp.gmail.com with ESMTPSA id u186sm2579433wmu.26.2019.08.28.01.57.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Aug 2019 01:57:48 -0700 (PDT) From: "Tzvetomir Stoyanov (VMware)" To: rostedt@goodmis.org Cc: linux-trace-devel@vger.kernel.org Subject: [PATCH v12 1/9] trace-cmd: Implemented new lib API: tracecmd_local_events_system() Date: Wed, 28 Aug 2019 11:57:38 +0300 Message-Id: <20190828085746.26231-2-tz.stoyanov@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190828085746.26231-1-tz.stoyanov@gmail.com> References: <20190828085746.26231-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 From: Tzvetomir Stoyanov The new tracecmd lib API tracecmd_local_events_system() creates a tep handler and initializes it with the events of the specified subsystems. Signed-off-by: Tzvetomir Stoyanov --- include/trace-cmd/trace-cmd.h | 2 + lib/trace-cmd/trace-util.c | 98 ++++++++++++++++++++++++----------- 2 files changed, 69 insertions(+), 31 deletions(-) diff --git a/include/trace-cmd/trace-cmd.h b/include/trace-cmd/trace-cmd.h index 9a984c1..da29d53 100644 --- a/include/trace-cmd/trace-cmd.h +++ b/include/trace-cmd/trace-cmd.h @@ -32,6 +32,8 @@ void tracecmd_unload_plugins(struct tep_plugin_list *list, struct tep_handle *pe char **tracecmd_event_systems(const char *tracing_dir); char **tracecmd_system_events(const char *tracing_dir, const char *system); struct tep_handle *tracecmd_local_events(const char *tracing_dir); +struct tep_handle *tracecmd_local_events_system(const char *tracing_dir, + const char * const *sys_names); int tracecmd_fill_local_events(const char *tracing_dir, struct tep_handle *pevent, int *parsing_failures); char **tracecmd_local_plugins(const char *tracing_dir); diff --git a/lib/trace-cmd/trace-util.c b/lib/trace-cmd/trace-util.c index d3bb333..9ccf3b3 100644 --- a/lib/trace-cmd/trace-util.c +++ b/lib/trace-cmd/trace-util.c @@ -1120,39 +1120,20 @@ static int read_header(struct tep_handle *pevent, const char *events_dir) return ret; } -/** - * tracecmd_local_events - create a pevent from the events on system - * @tracing_dir: The directory that contains the events. - * - * Returns a pevent structure that contains the pevents local to - * the system. - */ -struct tep_handle *tracecmd_local_events(const char *tracing_dir) +static bool contains(const char *name, const char * const *names) { - struct tep_handle *pevent = NULL; - - pevent = tep_alloc(); - if (!pevent) - return NULL; - - if (tracecmd_fill_local_events(tracing_dir, pevent, NULL)) { - tep_free(pevent); - pevent = NULL; - } - - return pevent; + if (!names) + return false; + for (; *names; names++) + if (strcmp(name, *names) == 0) + return true; + return false; } -/** - * tracecmd_fill_local_events - Fill a pevent with the events on system - * @tracing_dir: The directory that contains the events. - * @pevent: Allocated pevent which will be filled - * @parsing_failures: return number of failures while parsing the event files - * - * Returns whether the operation succeeded - */ -int tracecmd_fill_local_events(const char *tracing_dir, - struct tep_handle *pevent, int *parsing_failures) +static int tracecmd_fill_local_events_system(const char *tracing_dir, + struct tep_handle *pevent, + const char * const *sys_names, + int *parsing_failures) { struct dirent *dent; char *events_dir; @@ -1194,7 +1175,8 @@ int tracecmd_fill_local_events(const char *tracing_dir, if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0) continue; - + if (!contains(name, sys_names)) + continue; sys = append_file(events_dir, name); ret = stat(sys, &st); if (ret < 0 || !S_ISDIR(st.st_mode)) { @@ -1220,6 +1202,60 @@ int tracecmd_fill_local_events(const char *tracing_dir, return ret; } +/** + * tracecmd_local_events_system - create a tep from the events of the specified subsystem. + * + * @tracing_dir: The directory that contains the events. + * @sys_name: Array of system names, to load the events from. + * The last element from the array must be NULL + * + * Returns a tep structure that contains the tep local to + * the system. + */ +struct tep_handle *tracecmd_local_events_system(const char *tracing_dir, + const char * const *sys_names) +{ + struct tep_handle *tep = NULL; + + tep = tep_alloc(); + if (!tep) + return NULL; + + if (tracecmd_fill_local_events_system(tracing_dir, tep, sys_names, NULL)) { + tep_free(tep); + tep = NULL; + } + + return tep; +} + +/** + * tracecmd_local_events - create a pevent from the events on system + * @tracing_dir: The directory that contains the events. + * + * Returns a pevent structure that contains the pevents local to + * the system. + */ +struct tep_handle *tracecmd_local_events(const char *tracing_dir) +{ + return tracecmd_local_events_system(tracing_dir, NULL); +} + +/** + * tracecmd_fill_local_events - Fill a pevent with the events on system + * @tracing_dir: The directory that contains the events. + * @pevent: Allocated pevent which will be filled + * @parsing_failures: return number of failures while parsing the event files + * + * Returns whether the operation succeeded + */ +int tracecmd_fill_local_events(const char *tracing_dir, + struct tep_handle *pevent, int *parsing_failures) +{ + return tracecmd_fill_local_events_system(tracing_dir, pevent, + NULL, parsing_failures); +} + /** * tracecmd_local_plugins - returns an array of available tracer plugins * @tracing_dir: The directory that contains the tracing directory