perf jevents: Simplify generation of C-string
Previous implementation wanted variable order and '(null)' string output to match the C implementation. The '(null)' string output was a quirk/bug and so there is no need to carry it forward. Signed-off-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: James Clark <james.clark@arm.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: John Garry <john.garry@huawei.com> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Leo Yan <leo.yan@linaro.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Mike Leach <mike.leach@linaro.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Ravi Bangoria <ravi.bangoria@amd.com> Cc: Stephane Eranian <eranian@google.com> Cc: Will Deacon <will@kernel.org> Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com> Cc: linux-arm-kernel@lists.infradead.org Link: http://lore.kernel.org/lkml/20220804221816.1802790-3-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
e1e19d0545
commit
46acb311c6
@ -203,7 +203,7 @@ class JsonEvent:
|
||||
"""Representation of the event as a C struct initializer."""
|
||||
|
||||
def attr_string(attr: str, value: str) -> str:
|
||||
return '\t.%s = \"%s\",\n' % (attr, value)
|
||||
return f'\t.{attr} = \"{value}\",\n'
|
||||
|
||||
def str_if_present(self, attr: str) -> str:
|
||||
if not getattr(self, attr):
|
||||
@ -211,17 +211,11 @@ class JsonEvent:
|
||||
return attr_string(attr, getattr(self, attr))
|
||||
|
||||
s = '{\n'
|
||||
for attr in ['name', 'event']:
|
||||
s += str_if_present(self, attr)
|
||||
if self.desc is not None:
|
||||
s += attr_string('desc', self.desc)
|
||||
else:
|
||||
s += attr_string('desc', '(null)')
|
||||
s += str_if_present(self, 'compat')
|
||||
s += f'\t.topic = "{topic_local}",\n'
|
||||
for attr in [
|
||||
'long_desc', 'pmu', 'unit', 'perpkg', 'aggr_mode', 'metric_expr',
|
||||
'metric_name', 'metric_group', 'deprecated', 'metric_constraint'
|
||||
'aggr_mode', 'compat', 'deprecated', 'desc', 'event', 'long_desc',
|
||||
'metric_constraint', 'metric_expr', 'metric_group', 'metric_name',
|
||||
'name', 'perpkg', 'pmu', 'unit'
|
||||
]:
|
||||
s += str_if_present(self, attr)
|
||||
s += '},\n'
|
||||
|
Loading…
Reference in New Issue
Block a user