From nobody Sat Nov 23 17:34:52 2024 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C7AC4146A62 for ; Tue, 19 Nov 2024 01:17:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731979063; cv=none; b=hIFjJq+6qRvyx9/UaD3WtUK9meG8yrbiwdo/4gVvxOhS6Y66izqgYH9scBk9/ncH3Ldyd4V2bsUTajNWhvz7wFiy1jG7ETk+p+lo2DqCbhH79oNbD5V8Y6S4/eq0PwytyG8CSKCV9qViVunEPR/fIHnHpUYF1t7xPpp7YsKPqtk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731979063; c=relaxed/simple; bh=tNLAJ2pb8obJOYMSxFIC+cjFcupLOrxX//i30q8z1rA=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=m899No7TsfZ3eNdcOskS4LSJnv1Zdrhenn07qhFEt0IGkS4mQFux6eRH5+NuBFH90VMctY11BELcUMkrRIl9tbcCUfs2ESweIaw4LaEE2RLaaQztpBycnNCBNm6Mj/oig07NIrfo3rRS6JBWLn4Og6YanYPYhmkdMwv0JJvmePc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=gXn1bRk4; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="gXn1bRk4" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6eae6aba72fso47282517b3.2 for ; Mon, 18 Nov 2024 17:17:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731979061; x=1732583861; darn=vger.kernel.org; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=zn6zJFygLNqQr5gPeWc0c56TIYgfhddx4cdxbohjhZs=; b=gXn1bRk4T/FJStWsXCnEhvCzvPyMs5LzhveUCYqPdbPS9UoC998mX7OCNGNjgSf9dd U82HyTXtB7P09IvGUPWUF6bzawfqEfIr+KLaTQaZzDPvRU/k0GVQPZK6ljj2NmJ8eoGa hpgAIEY62w1C1zfBalRrnpAfloatBw5Eb64QOp56ffqYz2AeGigPloUfWLykIRZKBxqw 8hG1z3Vg4KNkrLv5G0QCmRrFzAj2MKaK3MyFYKmpi+dlxFT6Nk9+iKUXXqhb5P+/Rf3x vUyAUp0T7OU0xfh3e3Kdy74aiAQCEFz0f2+DOHUYcupQ+kuFbZohOK5YfMudEQ/zQRDb 08PQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731979061; x=1732583861; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=zn6zJFygLNqQr5gPeWc0c56TIYgfhddx4cdxbohjhZs=; b=kf1SqouL8LwnylCHijsMBroEjm6uvQmCgIOqlCTnl7Yl22H+EbZyTZcIquWSGE+n/9 5ZVDVoixYacmN3nSNVujMevkJ6rCKaqRU484Z1ND/WZWIwTBpY2h4bNMlejAL3qrETcM OWa9Q227UYD9/ppTFHCbH/p0rQ37wIYdhQOFDmP1mW25UMisqW+gLyw4EG2iCNwJIkAN Tgt97E/WeIKH6vGkibS+A6jZUpfko2mDobXTKnr/DZc74ja5NQWbPpdse2Ravr9OaniJ utP+slxjS7UapyzwENrt8k+h8kcFxgBUGMjnx+RziOv5YiG4wlH4Q4jkNHm0L40emDfn Qwsg== X-Forwarded-Encrypted: i=1; AJvYcCWY9ja5WW4apcuPK4wCiff26vG6w5gS2o4ohbk+MTM1Cq/RCarAyLhVUx5UjNzHTRHs2S1VaQQrGQTuhv8=@vger.kernel.org X-Gm-Message-State: AOJu0YxZ6pCRG+Y1fbvPcnEpBv48fPm6fCaVvHbTyTGKFsTVuwRNllZR /PVVIh6qWuECbb+2Qzjren46m+Lis/sxrkxjXGf3gl+kpATDDFnRGxS13bO6PvjnmBQKqvZuXsE iBt2QqA== X-Google-Smtp-Source: AGHT+IGSCaZ/uVjD7usDHxw9ALNuw5YvhZD4nY+/OTM4rPAXQXTu362uAegaLMkp3WXzWDceXc5+BMM44IUn X-Received: from irogers.svl.corp.google.com ([2620:15c:2c5:11:22a4:ded5:5c37:fcc7]) (user=irogers job=sendgmr) by 2002:a81:ad0a:0:b0:62c:ea0b:a447 with SMTP id 00721157ae682-6ee55a3b7ebmr1874697b3.2.1731979060734; Mon, 18 Nov 2024 17:17:40 -0800 (PST) Date: Mon, 18 Nov 2024 17:16:31 -0800 In-Reply-To: <20241119011644.971342-1-irogers@google.com> Message-Id: <20241119011644.971342-10-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241119011644.971342-1-irogers@google.com> X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Subject: [PATCH v7 09/22] perf script: Move script_spec code to trace-event-scripting.c From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , Howard Chu , Athira Jajeev , Michael Petlan , Veronika Molnarova , Dapeng Mi , Thomas Richter , Ilya Leoshkevich , Colin Ian King , Weilin Wang , Andi Kleen , Josh Poimboeuf , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Cc: Arnaldo Carvalho de Melo Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The script_spec code is referenced in util/trace-event-scripting but the list was in builtin-script, accessed via a function that required a stub function in python.c. Move all the logic to trace-event-scripting, with lookup and foreach functions exposed for builtin-script's benefit. Signed-off-by: Ian Rogers Acked-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-script.c | 67 +--------------------- tools/perf/util/python.c | 5 -- tools/perf/util/trace-event-scripting.c | 75 +++++++++++++++++++++++++ tools/perf/util/trace-event.h | 3 +- 4 files changed, 80 insertions(+), 70 deletions(-) diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c index 0ba1866dbeef..b4deae110dbe 100644 --- a/tools/perf/builtin-script.c +++ b/tools/perf/builtin-script.c @@ -2956,79 +2956,18 @@ static int __cmd_script(struct perf_script *script) return ret; } =20 -struct script_spec { - struct list_head node; - struct scripting_ops *ops; - char spec[]; -}; - -static LIST_HEAD(script_specs); - -static struct script_spec *script_spec__new(const char *spec, - struct scripting_ops *ops) +static int list_available_languages_cb(struct scripting_ops *ops, const ch= ar *spec) { - struct script_spec *s =3D malloc(sizeof(*s) + strlen(spec) + 1); - - if (s !=3D NULL) { - strcpy(s->spec, spec); - s->ops =3D ops; - } - - return s; -} - -static void script_spec__add(struct script_spec *s) -{ - list_add_tail(&s->node, &script_specs); -} - -static struct script_spec *script_spec__find(const char *spec) -{ - struct script_spec *s; - - list_for_each_entry(s, &script_specs, node) - if (strcasecmp(s->spec, spec) =3D=3D 0) - return s; - return NULL; -} - -int script_spec_register(const char *spec, struct scripting_ops *ops) -{ - struct script_spec *s; - - s =3D script_spec__find(spec); - if (s) - return -1; - - s =3D script_spec__new(spec, ops); - if (!s) - return -1; - else - script_spec__add(s); - + fprintf(stderr, " %-42s [%s]\n", spec, ops->name); return 0; } =20 -static struct scripting_ops *script_spec__lookup(const char *spec) -{ - struct script_spec *s =3D script_spec__find(spec); - if (!s) - return NULL; - - return s->ops; -} - static void list_available_languages(void) { - struct script_spec *s; - fprintf(stderr, "\n"); fprintf(stderr, "Scripting language extensions (used in " "perf script -s [spec:]script.[spec]):\n\n"); - - list_for_each_entry(s, &script_specs, node) - fprintf(stderr, " %-42s [%s]\n", s->spec, s->ops->name); - + script_spec__for_each(&list_available_languages_cb); fprintf(stderr, "\n"); } =20 diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c index 7fc3ec5684c3..d157aaa4bb53 100644 --- a/tools/perf/util/python.c +++ b/tools/perf/util/python.c @@ -1305,11 +1305,6 @@ PyMODINIT_FUNC PyInit_perf(void) /* The following are stubs to avoid dragging in builtin-* objects. */ /* TODO: move the code out of the builtin-* file into util. */ =20 -int script_spec_register(const char *spec __maybe_unused, struct scripting= _ops *ops __maybe_unused) -{ - return -1; -} - arch_syscalls__strerrno_t *arch_syscalls__strerrno_function(const char *ar= ch __maybe_unused) { return NULL; diff --git a/tools/perf/util/trace-event-scripting.c b/tools/perf/util/trac= e-event-scripting.c index d514db1df27f..4b7f0592850b 100644 --- a/tools/perf/util/trace-event-scripting.c +++ b/tools/perf/util/trace-event-scripting.c @@ -24,6 +24,81 @@ unsigned int scripting_max_stack =3D PERF_MAX_STACK_DEPT= H; =20 struct scripting_context *scripting_context; =20 +struct script_spec { + struct list_head node; + struct scripting_ops *ops; + char spec[]; +}; + +static LIST_HEAD(script_specs); + +static struct script_spec *script_spec__new(const char *spec, + struct scripting_ops *ops) +{ + struct script_spec *s =3D malloc(sizeof(*s) + strlen(spec) + 1); + + if (s !=3D NULL) { + strcpy(s->spec, spec); + s->ops =3D ops; + } + + return s; +} + +static void script_spec__add(struct script_spec *s) +{ + list_add_tail(&s->node, &script_specs); +} + +static struct script_spec *script_spec__find(const char *spec) +{ + struct script_spec *s; + + list_for_each_entry(s, &script_specs, node) + if (strcasecmp(s->spec, spec) =3D=3D 0) + return s; + return NULL; +} + +static int script_spec_register(const char *spec, struct scripting_ops *op= s) +{ + struct script_spec *s; + + s =3D script_spec__find(spec); + if (s) + return -1; + + s =3D script_spec__new(spec, ops); + if (!s) + return -1; + + script_spec__add(s); + return 0; +} + +struct scripting_ops *script_spec__lookup(const char *spec) +{ + struct script_spec *s =3D script_spec__find(spec); + + if (!s) + return NULL; + + return s->ops; +} + +int script_spec__for_each(int (*cb)(struct scripting_ops *ops, const char = *spec)) +{ + struct script_spec *s; + int ret =3D 0; + + list_for_each_entry(s, &script_specs, node) { + ret =3D cb(s->ops, s->spec); + if (ret) + break; + } + return ret; +} + void scripting_context__update(struct scripting_context *c, union perf_event *event, struct perf_sample *sample, diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h index 79b939f947dd..29cae98695c9 100644 --- a/tools/perf/util/trace-event.h +++ b/tools/perf/util/trace-event.h @@ -113,7 +113,8 @@ struct scripting_ops { =20 extern unsigned int scripting_max_stack; =20 -int script_spec_register(const char *spec, struct scripting_ops *ops); +struct scripting_ops *script_spec__lookup(const char *spec); +int script_spec__for_each(int (*cb)(struct scripting_ops *ops, const char = *spec)); =20 void script_fetch_insn(struct perf_sample *sample, struct thread *thread, struct machine *machine); --=20 2.47.0.338.g60cca15819-goog