aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Preud'homme <thomasp@graphcore.ai>2019-10-06 18:30:31 +0000
committerThomas Preud'homme <thomasp@graphcore.ai>2019-10-06 18:30:31 +0000
commit8e292858c6e3bb244402324a8f4f5e61c5eba129 (patch)
tree59f91cd3a0e03a3bfcaa712b3f12bae684a9d7fb
parent3d1a6d0c391d583f709da96ca92b5c756799fd10 (diff)
[LNT] Python 3 support: stable profile getFunctions output
lnt profile getFunctions output depends on the iteration order of a dictionary, which is an implementation detail up to Python 3.6 (included). The test tests/lnttool/Profile.py is thus unstable accross architectures and Python versions. This commit adds a --sortkeys option to the getFunctions command to sort the keys in the dictionary when dumping it into json, thus allowing stable results of tests/lnttool/Profile.py by using this option. Reviewers: cmatthews, hubert.reinterpretcast, kristof.beyls Reviewed By: hubert.reinterpretcast Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D68221 git-svn-id: https://llvm.org/svn/llvm-project/lnt/trunk@373860 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lnt/lnttool/main.py6
-rw-r--r--tests/lnttool/Profile.py4
2 files changed, 6 insertions, 4 deletions
diff --git a/lnt/lnttool/main.py b/lnt/lnttool/main.py
index 050fb58..e91160e 100644
--- a/lnt/lnttool/main.py
+++ b/lnt/lnttool/main.py
@@ -424,11 +424,13 @@ def command_top_level_counters(input):
@action_profile.command("getFunctions")
@click.argument("input", type=click.Path(exists=True))
-def command_get_functions(input):
+@click.option("--sortkeys", is_flag=True)
+def command_get_functions(input, sortkeys):
"""print the functions in a profile"""
import json
import lnt.testing.profile.profile as profile
- print(json.dumps(profile.Profile.fromFile(input).getFunctions()))
+ print(json.dumps(profile.Profile.fromFile(input).getFunctions(),
+ sort_keys=sortkeys))
@action_profile.command("getCodeForFunction")
diff --git a/tests/lnttool/Profile.py b/tests/lnttool/Profile.py
index f6c3c62..807eb55 100644
--- a/tests/lnttool/Profile.py
+++ b/tests/lnttool/Profile.py
@@ -4,8 +4,8 @@
# RUN: lnt profile getTopLevelCounters %S/Inputs/test.lntprof | FileCheck --check-prefix=CHECK-GETTLC %s
# CHECK-GETTLC: {"cycles": 12345.0, "branch-misses": 200.0}
-# RUN: lnt profile getFunctions %S/Inputs/test.lntprof | FileCheck --check-prefix=CHECK-GETFUNCTIONS %s
-# CHECK-GETFUNCTIONS: {"fn1": {"length": 2, "counters": {"cycles": 45.0, "branch-misses": 10.0}}}
+# RUN: lnt profile getFunctions --sortkeys %S/Inputs/test.lntprof | FileCheck --check-prefix=CHECK-GETFUNCTIONS %s
+# CHECK-GETFUNCTIONS: {"fn1": {"counters": {"branch-misses": 10.0, "cycles": 45.0}, "length": 2}}
# RUN: lnt profile getCodeForFunction %S/Inputs/test.lntprof fn1 | FileCheck --check-prefix=CHECK-GETFN1 %s
# CHECK-GETFN1: [{}, 1048576, "add r0, r0, r0"], [{"cycles": 100.0}, 1048580, "sub r1, r0, r0"]]