diff mbox series

[v4,02/17] perf jevents: Simplify generation of C-string

Message ID 20220804221816.1802790-3-irogers@google.com (mailing list archive)
State New, archived
Headers show
Series Compress the pmu_event tables | expand

Commit Message

Ian Rogers Aug. 4, 2022, 10:18 p.m. UTC
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>
---
 tools/perf/pmu-events/jevents.py | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

Comments

Arnaldo Carvalho de Melo Aug. 9, 2022, 7:37 p.m. UTC | #1
Em Thu, Aug 04, 2022 at 03:18:01PM -0700, Ian Rogers escreveu:
> 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.

Thanks, applied.

- Arnaldo

 
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
>  tools/perf/pmu-events/jevents.py | 14 ++++----------
>  1 file changed, 4 insertions(+), 10 deletions(-)
> 
> diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py
> index 5b72048d50da..cdfa4e0e7557 100755
> --- a/tools/perf/pmu-events/jevents.py
> +++ b/tools/perf/pmu-events/jevents.py
> @@ -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'
> -- 
> 2.37.1.559.g78731f0fdb-goog
diff mbox series

Patch

diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py
index 5b72048d50da..cdfa4e0e7557 100755
--- a/tools/perf/pmu-events/jevents.py
+++ b/tools/perf/pmu-events/jevents.py
@@ -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'