lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAP-5=fWdvhoiKd41PUewR5TaaYOcuUPp5WThoOzt0rDrjTfruQ@mail.gmail.com>
Date: Wed, 2 Apr 2025 08:55:55 -0700
From: Ian Rogers <irogers@...gle.com>
To: "Liang, Kan" <kan.liang@...ux.intel.com>
Cc: Peter Zijlstra <peterz@...radead.org>, Ingo Molnar <mingo@...hat.com>, 
	Arnaldo Carvalho de Melo <acme@...nel.org>, Namhyung Kim <namhyung@...nel.org>, 
	Mark Rutland <mark.rutland@....com>, 
	Alexander Shishkin <alexander.shishkin@...ux.intel.com>, Jiri Olsa <jolsa@...nel.org>, 
	Adrian Hunter <adrian.hunter@...el.com>, Howard Chu <howardchu95@...il.com>, 
	Weilin Wang <weilin.wang@...el.com>, Levi Yun <yeoreum.yun@....com>, 
	"Dr. David Alan Gilbert" <linux@...blig.org>, Andi Kleen <ak@...ux.intel.com>, 
	James Clark <james.clark@...aro.org>, Dominique Martinet <asmadeus@...ewreck.org>, 
	linux-perf-users@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v1 3/5] perf evlist: Refactor evlist__scnprintf_evsels

On Wed, Apr 2, 2025 at 8:26 AM Liang, Kan <kan.liang@...ux.intel.com> wrote:
>
>
>
> On 2025-03-18 12:14 a.m., Ian Rogers wrote:
> > Switch output to using a strbuf so the storage can be resized. Rename
> > as scnprintf is no longer used.
> >
> > Signed-off-by: Ian Rogers <irogers@...gle.com>
> > ---
> >  tools/perf/builtin-record.c |  9 ++++++---
> >  tools/perf/util/evlist.c    | 19 +++++++++----------
> >  tools/perf/util/evlist.h    |  3 ++-
> >  3 files changed, 17 insertions(+), 14 deletions(-)
> >
> > diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
> > index ba20bf7c011d..cea5959adadc 100644
> > --- a/tools/perf/builtin-record.c
> > +++ b/tools/perf/builtin-record.c
> > @@ -51,6 +51,7 @@
> >  #include "util/clockid.h"
> >  #include "util/off_cpu.h"
> >  #include "util/bpf-filter.h"
> > +#include "util/strbuf.h"
> >  #include "asm/bug.h"
> >  #include "perf.h"
> >  #include "cputopo.h"
> > @@ -2784,13 +2785,15 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
> >               record__auxtrace_snapshot_exit(rec);
> >
> >       if (forks && workload_exec_errno) {
> > -             char msg[STRERR_BUFSIZE], strevsels[2048];
> > +             char msg[STRERR_BUFSIZE];
> >               const char *emsg = str_error_r(workload_exec_errno, msg, sizeof(msg));
> > +             struct strbuf sb = STRBUF_INIT;
> >
> > -             evlist__scnprintf_evsels(rec->evlist, sizeof(strevsels), strevsels);
> > +             evlist__format_evsels(rec->evlist, &sb);
> >
> >               pr_err("Failed to collect '%s' for the '%s' workload: %s\n",
> > -                     strevsels, argv[0], emsg);
> > +                     sb.buf, argv[0], emsg);
> > +             strbuf_release(&sb);
> >               err = -1;
> >               goto out_child;
> >       }
> > diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
> > index 49e10d6981ad..96cfc7ed1512 100644
> > --- a/tools/perf/util/evlist.c
> > +++ b/tools/perf/util/evlist.c
> > @@ -35,6 +35,7 @@
> >  #include "util/util.h"
> >  #include "util/env.h"
> >  #include "util/intel-tpebs.h"
> > +#include "util/strbuf.h"
> >  #include <signal.h>
> >  #include <unistd.h>
> >  #include <sched.h>
> > @@ -2468,23 +2469,21 @@ struct evsel *evlist__find_evsel(struct evlist *evlist, int idx)
> >       return NULL;
> >  }
> >
> > -int evlist__scnprintf_evsels(struct evlist *evlist, size_t size, char *bf)
> > +void evlist__format_evsels(struct evlist *evlist, struct strbuf *sb)
> >  {
> >       struct evsel *evsel;
> > -     int printed = 0;
> > +     bool first = true;
> >
> >       evlist__for_each_entry(evlist, evsel) {
> >               if (evsel__is_dummy_event(evsel))
> >                       continue;
> > -             if (size > (strlen(evsel__name(evsel)) + (printed ? 2 : 1))) {
> > -                     printed += scnprintf(bf + printed, size - printed, "%s%s", printed ? "," : "", evsel__name(evsel));
> > -             } else {
> > -                     printed += scnprintf(bf + printed, size - printed, "%s...", printed ? "," : "");
> > -                     break;
> > -             }
> > -     }
> >
> > -     return printed;
> > +             if (!first)
> > +                     strbuf_addch(sb, ',');
> > +> +          strbuf_addstr(sb, evsel__name(evsel));
>
> The evlist may include hundreds of events. The error msg will be too
> huge for the case.

I hear you, lots of uncore PMUs :-) I keep wanting to the PMU with an
evsel to be a list. As you suggest in the next feedback, let's add an
option to have some maximum for the perf record use case.

Thanks,
Ian


> Thanks,
> Kan
>
> > +             first = false;
> > +     }
> >  }
> >
> >  void evlist__check_mem_load_aux(struct evlist *evlist)
> > diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
> > index edcbf1c10e92..5fe5cfbbebb1 100644
> > --- a/tools/perf/util/evlist.h
> > +++ b/tools/perf/util/evlist.h
> > @@ -20,6 +20,7 @@ struct pollfd;
> >  struct thread_map;
> >  struct perf_cpu_map;
> >  struct record_opts;
> > +struct strbuf;
> >  struct target;
> >
> >  /*
> > @@ -430,7 +431,7 @@ int event_enable_timer__process(struct event_enable_timer *eet);
> >
> >  struct evsel *evlist__find_evsel(struct evlist *evlist, int idx);
> >
> > -int evlist__scnprintf_evsels(struct evlist *evlist, size_t size, char *bf);
> > +void evlist__format_evsels(struct evlist *evlist, struct strbuf *sb);
> >  void evlist__check_mem_load_aux(struct evlist *evlist);
> >  void evlist__warn_user_requested_cpus(struct evlist *evlist, const char *cpu_list);
> >  void evlist__uniquify_name(struct evlist *evlist);
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ