linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michael Petlan <mpetlan@redhat.com>
To: Ian Rogers <irogers@google.com>
Cc: Namhyung Kim <namhyung@kernel.org>,
	linux-perf-users@vger.kernel.org, acme@kernel.org,
	acme@redhat.com, qzhao@redhat.com, cjense@google.com
Subject: Re: [PATCH 0/2] perf test: Fix JSON linter
Date: Tue, 24 Jan 2023 18:39:04 +0100 (CET)	[thread overview]
Message-ID: <alpine.LRH.2.20.2301241751180.5281@Diego> (raw)
In-Reply-To: <CAP-5=fXuNW2XYomrxViwzQThVQpwF5Cvo+UuQ_da3QiUESwAmw@mail.gmail.com>

On Fri, 20 Jan 2023, Ian Rogers wrote:
> On Fri, Jan 20, 2023 at 5:41 AM Michael Petlan <mpetlan@redhat.com> wrote:
> >
> > Hello all.
> >
> > We have observed issues with the 'perf stat JSON output linter' testcase
> > on systems that allow topdown metrics.
> >
> > =========================
> >
[...]
> > 2) Since the JSON printing engine thinks that one and only one metric
> > is printed, it always closes the line by adding '}'. This is not true,
> > so I have fixed the comma printing and adjusted the engine to be
> > capable of printing 1-N metrics and then close the line.
> 
> So the current printing code is messy. For example, there is a newline
> callback function, but that has little meaning for json where
> everything is on a newline. For CSV mode, adding a summary used to
> cause a column to suddenly appear on the left for the row containing
> the summary. I believe the right thing to do is a refactor and
> recently I did a similar refactor for 'perf list':
> https://lore.kernel.org/lkml/20221114210723.2749751-11-irogers@google.com/
> So it is strange that metrics are "shadows" of events, but whatever
> the point is to think about the printing API. In the change linked
> above you can see that everytime something is printed the print
> handling code is given all the information and the print handling code
> has state. Based on the state and callback's information, the print
> handling code can do nothing, properly format for CSV, json, etc. This
> gets completely away from the kind of madness of branches and
> whac-a-mole the code currently has.
> 
> I'm happy to look at doing the refactor to be similar to 'perf
> list'/builtin-list.c. Namhyung I thought might have gotten to it with
> his recent work on improving aggregation. If I hear silence then I'll
> assume that is a request I do it :-)
> 
> Pragmatically in the short term we could land your changes, but I
> worry they are more of the whac-a-mole and something somewhere else
> will break. Which is why we have a test, and so I'm not overly
> worried. I can download and test too.
> 
> Anyway, sorry for the issue and let me know what you think. Thanks,
> Ian

Hello.

I think that applying the patchset won't make things worse, eventhough
we know it would deserve a better solution for the whole print engine.

Yes, we have a test, but maybe that's what should be improved first,
since it does not actually verify the format correctness. I have hit
the problem because of failing test, but the fail cause was that there
were too many commas, but strings like

  "Heavy Operations"}"metric-value"

are still OK according to the linter.

Proper JSON linter might be in some library, but we don't want to add
too many dependencies I guess.

Maybe some simple JSON linter I used when preparing the patchset would
be enough for our perf-stat output... I'll convert it to Python and
post it to see.

=============================

Finally, speaking of tests, I think that thinking of integrating the
external perf testsuite [1] might be a better approach than adding
new shell-based tests such as "perf stat tests", etc. Tests like that
have been already written, see [1].

Some years ago, I was trying to add it to perf-test, however it was
unsuccessful, but since then, many shell-based tests were added
instead and I think they slightly duplicate the work already done.

Thoughts?
Michael

[1] https://github.com/rfmvh/perftool-testsuite

> 
> 
> > =========================
> >
> > On machines that don't support topdown, the problem can be shown by
> > doubling the following line in util/stat-shadow.c, so that the simple
> > 'insn per cycle' metric is printed twice:
> >
> >   print_metric(config, ctxp, NULL, "%7.2f ", "insn per cycle", ratio);
> >
> > The worst problem is that the JSON line is broken, such as:
> >
> > ... "pcnt-running" : 100.00, "metric-value" : 3.501931, "metric-unit"
> >     : "Heavy Operations"}"metric-value" : 14.007787, "metric-unit" : ...
> >                   here ^^^^^
> >
> > =========================
> >
> > The first patch solves the JSON output correctness, the second tries
> > to adjust the testcase to some extent, so that it should work on the
> > topdown-capable machines.
> >
> > However, it's highly possible that the testcase will have to be fixed
> > or maybe rewritten in future. First, it has quite naive evaluation of
> > what's expected/correct/etc. Second, it does no JSON format validation
> > at all. As a linter it should do so though.
> >
> >  ***
> >
> > For further discussion: What about removing the check for number of
> > expected elements in the line and just check for the keywords, such
> > as "metric-value", "counter-value", "event", etc. and for some values
> > that should be numeric. And, do proper JSON format sanity check?
> >
> >
> > Thank you for inputs!
> >
> > Michael
> >
> >
> >
> >
> > Michael Petlan (2):
> >   perf stat: Fix JSON metric printout for multiple metrics per line
> >   perf test: Fix JSON format linter test checks
> >
> >  .../tests/shell/lib/perf_json_output_lint.py  | 16 +++++------
> >  tools/perf/util/stat-display.c                | 28 +++++++++++--------
> >  2 files changed, 24 insertions(+), 20 deletions(-)
> >
> > --
> > 2.18.4
> >
> 
> 


  parent reply	other threads:[~2023-01-24 17:40 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-20 13:40 [PATCH 0/2] perf test: Fix JSON linter Michael Petlan
2023-01-20 13:40 ` [PATCH 1/2] perf stat: Fix JSON metric printout for multiple metrics per line Michael Petlan
2023-01-23  6:31   ` Namhyung Kim
2023-05-22 12:11   ` Michael Petlan
2023-06-06 11:16     ` Michael Petlan
2023-01-20 13:40 ` [PATCH 2/2] perf test: Fix JSON format linter test checks Michael Petlan
2023-01-23  6:36   ` Namhyung Kim
2023-01-24 16:49     ` Michael Petlan
2023-01-24 17:26       ` Namhyung Kim
2023-01-27 12:26   ` Arnaldo Carvalho de Melo
2023-01-27 12:30     ` Arnaldo Carvalho de Melo
2023-01-31 17:14       ` Michael Petlan
2023-02-02  1:18         ` Arnaldo Carvalho de Melo
2023-01-20 17:37 ` [PATCH 0/2] perf test: Fix JSON linter Ian Rogers
2023-01-23  6:48   ` Namhyung Kim
2023-01-23 13:38   ` Arnaldo Carvalho de Melo
2023-01-24 17:39   ` Michael Petlan [this message]
2023-01-25  0:37     ` Ian Rogers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LRH.2.20.2301241751180.5281@Diego \
    --to=mpetlan@redhat.com \
    --cc=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=cjense@google.com \
    --cc=irogers@google.com \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=namhyung@kernel.org \
    --cc=qzhao@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).