Skip to contentSkip to conversation

perf expr: Allow exponents on floating point values

PATCH In review Ian Rogers 3 participants 4 messages May 27, 2022 – Jun 17, 2022 1 message not in the archive perf events

lore
Share & tools
lore

Ian Rogers

author reviewer
#0 lore raw

PATCH 1/1 perf expr: Allow exponents on floating point values

Pass the optional exponent component through to strtod that already supports it. We already have exponents in ScaleUnit and so this adds uniformity.

---
 tools/perf/tests/expr.c | 2 ++
 tools/perf/util/expr.l  | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)
tools/perf/tests/expr.c +2 -0
index d54c5371c6a6..5c0032fe93ae 100644
@@ -97,6 +97,8 @@ static int test__expr(struct test_suite *t __maybe_unused, int subtest __maybe_u
 	ret |= test(ctx, "2.2 > 2.2", 0);
 	ret |= test(ctx, "2.2 < 1.1", 0);
 	ret |= test(ctx, "1.1 > 2.2", 0);
+	ret |= test(ctx, "1.1e10 < 1.1e100", 1);
+	ret |= test(ctx, "1.1e2 > 1.1e-2", 1);
 
 	if (ret) {
 		expr__ctx_free(ctx);
tools/perf/util/expr.l +1 -1
index 0a13eb20c814..4dc8edbfd9ce 100644
@@ -91,7 +91,7 @@ static int literal(yyscan_t scanner)
 }
 %}
 
-number		([0-9]+\.?[0-9]*|[0-9]*\.?[0-9]+)
+number		([0-9]+\.?[0-9]*|[0-9]*\.?[0-9]+)(e-?[0-9]+)?
 
 sch		[-,=]
 spec		\\{sch}
Signature · 1 line
2.36.1.124.g0e6072fb45-goog
author reviewer
#1 lore raw
Quoted 7 lines · Ian Rogers

Pass the optional exponent component through to strtod that already supports it. We already have exponents in ScaleUnit and so this adds uniformity.

Ping. Simple fix with tests, PTAL. Thanks,
Ian

Quoted 34 lines
---
 tools/perf/tests/expr.c | 2 ++
 tools/perf/util/expr.l  | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)
tools/perf/tests/expr.c +2 -0
index d54c5371c6a6..5c0032fe93ae 100644
@@ -97,6 +97,8 @@ static int test__expr(struct test_suite *t __maybe_unused, int subtest __maybe_u
        ret |= test(ctx, "2.2 > 2.2", 0);
        ret |= test(ctx, "2.2 < 1.1", 0);
        ret |= test(ctx, "1.1 > 2.2", 0);
+       ret |= test(ctx, "1.1e10 < 1.1e100", 1);
+       ret |= test(ctx, "1.1e2 > 1.1e-2", 1);
 
        if (ret) {
                expr__ctx_free(ctx);
tools/perf/util/expr.l +1 -2
index 0a13eb20c814..4dc8edbfd9ce 100644
@@ -91,7 +91,7 @@ static int literal(yyscan_t scanner)
 }
 %}
 
-number         ([0-9]+\.?[0-9]*|[0-9]*\.?[0-9]+)
+number         ([0-9]+\.?[0-9]*|[0-9]*\.?[0-9]+)(e-?[0-9]+)?
 
 sch            [-,=]
 spec           \\{sch}
--

2.36.1.124.g0e6072fb45-goog

Reviewed-by on v1 1/1
#2 lore raw
In reply to Ian Rogers

Patch looks fine to me

Quoted 37 lines · Ian Rogers

Pass the optional exponent component through to strtod that already supports it. We already have exponents in ScaleUnit and so this adds uniformity.

---
 tools/perf/tests/expr.c | 2 ++
 tools/perf/util/expr.l  | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)
tools/perf/tests/expr.c +2 -0
index d54c5371c6a6..5c0032fe93ae 100644
@@ -97,6 +97,8 @@ static int test__expr(struct test_suite *t __maybe_unused, int subtest __maybe_u
 	ret |= test(ctx, "2.2 > 2.2", 0);
 	ret |= test(ctx, "2.2 < 1.1", 0);
 	ret |= test(ctx, "1.1 > 2.2", 0);
+	ret |= test(ctx, "1.1e10 < 1.1e100", 1);
+	ret |= test(ctx, "1.1e2 > 1.1e-2", 1);
 
 	if (ret) {
 		expr__ctx_free(ctx);
tools/perf/util/expr.l +1 -1
index 0a13eb20c814..4dc8edbfd9ce 100644
@@ -91,7 +91,7 @@ static int literal(yyscan_t scanner)
 }
 %}
 
-number		([0-9]+\.?[0-9]*|[0-9]*\.?[0-9]+)
+number		([0-9]+\.?[0-9]*|[0-9]*\.?[0-9]+)(e-?[0-9]+)?
 
 sch		[-,=]
 spec		\\{sch}

A message that is not in the archive (sent off-list or not yet received): CAP-5=fVY-tdEzXi8fcPGQdQf+F93OTzA7z6UksQy=c6Vh7uPpA@mail.gmail.com

#4 lore raw

Em Wed, Jun 15, 2022 at 10:16:32PM -0700, Ian Rogers escreveu:

Quoted 8 lines · kajoljain
Quoted 5 lines

Patch looks fine to me

Thanks! Arnaldo, can this one go in?

Sure, applied.

- Arnaldo

Quoted 44 lines

Ian

Quoted 41 lines · Ian Rogers

tools/perf/tests/expr.c static int test__expr(struct test_suite *t

Quoted 16 lines

Pass the optional exponent component through to strtod that already supports it. We already have exponents in ScaleUnit and so this adds uniformity.

---
 tools/perf/tests/expr.c | 2 ++
 tools/perf/util/expr.l  | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)
tools/perf/tests/expr.c +0 -0
index d54c5371c6a6..5c0032fe93ae 100644
@@ -97,6 +97,8 @@ static int test__expr(struct test_suite *t

__maybe_unused, int subtest __maybe_u

Quoted 21 lines
tools/perf/tests/expr.c +2 -0
      ret |= test(ctx, "2.2 > 2.2", 0);
      ret |= test(ctx, "2.2 < 1.1", 0);
      ret |= test(ctx, "1.1 > 2.2", 0);
+     ret |= test(ctx, "1.1e10 < 1.1e100", 1);
+     ret |= test(ctx, "1.1e2 > 1.1e-2", 1);
 
      if (ret) {
              expr__ctx_free(ctx);
tools/perf/util/expr.l +1 -1
index 0a13eb20c814..4dc8edbfd9ce 100644
@@ -91,7 +91,7 @@ static int literal(yyscan_t scanner)
 }
 %}
 
-number               ([0-9]+\.?[0-9]*|[0-9]*\.?[0-9]+)
+number               ([0-9]+\.?[0-9]*|[0-9]*\.?[0-9]+)(e-?[0-9]+)?
 
 sch          [-,=]
 spec         \\{sch}
Signature · 1 line
- Arnaldo