From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752742AbcFNQif (ORCPT ); Tue, 14 Jun 2016 12:38:35 -0400 Received: from foss.arm.com ([217.140.101.70]:60077 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751923AbcFNQid (ORCPT ); Tue, 14 Jun 2016 12:38:33 -0400 From: Jeremy Linton To: linux-kernel@vger.kernel.org Cc: acme@redhat.com, rostedt@goodmis.org, namhyung@kernel.org, kapileshwar.singh@arm.com, scottwood@freescale.com, hekuang@huawei.com Subject: [RFC/PATCH] perf: Add sizeof operator support Date: Tue, 14 Jun 2016 11:38:32 -0500 Message-Id: <1465922312-30064-1-git-send-email-jeremy.linton@arm.com> X-Mailer: git-send-email 2.5.5 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There are a fair number of tracepoints in the kernel making use of the sizeof operator. Allow perf to understand some of those cases, and report a more informative error message for the ones it cannot understand. Signed-off-by: Jeremy Linton --- So this is as much a RFC as a patch because the use of sizeof seems to extend to structures, pointers, etc that aren't easy to deduce from userspace. I'm not sure what the correct solution should be in those cases. tools/lib/traceevent/event-parse.c | 46 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c index a8b6357..5813248 100644 --- a/tools/lib/traceevent/event-parse.c +++ b/tools/lib/traceevent/event-parse.c @@ -31,6 +31,8 @@ #include #include #include +#include +#include #include #include "event-parse.h" @@ -2868,6 +2870,46 @@ process_str(struct event_format *event __maybe_unused, struct print_arg *arg, } static enum event_type +process_sizeof(struct event_format *event __maybe_unused, struct print_arg *arg, + char **tok) +{ + char *token; + char *atom; + + if (process_paren(event, arg, &token) < 0) + goto out_free; + + atom = arg->atom.atom; + if (arg->type != PRINT_ATOM) { + do_warning_event(event, "didn't understand %s for sizeof\n", + token); + goto out_free_atom; + } + + if (strcmp(token, "__u64") == 0) { + if (asprintf(&arg->atom.atom, "%zd", sizeof(__u64)) < 0) + goto out_free_atom; + } else if (strcmp(token, "__u32") == 0) { + if (asprintf(&arg->atom.atom, "%zd", sizeof(__u32)) < 0) + goto out_free_atom; + } else { + do_warning_event(event, "unknown sizeof %s\n", token); + goto out_free_atom; + } + + free(atom); + *tok = token; + return EVENT_DELIM; + + out_free_atom: + free_token(atom); + out_free: + free_token(token); + *tok = NULL; + return EVENT_ERROR; +} + +static enum event_type process_bitmask(struct event_format *event __maybe_unused, struct print_arg *arg, char **tok) { @@ -3026,6 +3068,10 @@ process_function(struct event_format *event, struct print_arg *arg, free_token(token); return process_dynamic_array_len(event, arg, tok); } + if (strcmp(token, "sizeof") == 0) { + free_token(token); + return process_sizeof(event, arg, tok); + } func = find_func_handler(event->pevent, token); if (func) { -- 2.5.5