Skip to content

Commit af26dea

Browse files
author
Thomas Preud'homme
committed
[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 llvm-svn: 373860
1 parent 9f4e778 commit af26dea

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

lnt/lnttool/main.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,11 +424,13 @@ def command_top_level_counters(input):
424424

425425
@action_profile.command("getFunctions")
426426
@click.argument("input", type=click.Path(exists=True))
427-
def command_get_functions(input):
427+
@click.option("--sortkeys", is_flag=True)
428+
def command_get_functions(input, sortkeys):
428429
"""print the functions in a profile"""
429430
import json
430431
import lnt.testing.profile.profile as profile
431-
print(json.dumps(profile.Profile.fromFile(input).getFunctions()))
432+
print(json.dumps(profile.Profile.fromFile(input).getFunctions(),
433+
sort_keys=sortkeys))
432434

433435

434436
@action_profile.command("getCodeForFunction")

tests/lnttool/Profile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
# RUN: lnt profile getTopLevelCounters %S/Inputs/test.lntprof | FileCheck --check-prefix=CHECK-GETTLC %s
55
# CHECK-GETTLC: {"cycles": 12345.0, "branch-misses": 200.0}
66

7-
# RUN: lnt profile getFunctions %S/Inputs/test.lntprof | FileCheck --check-prefix=CHECK-GETFUNCTIONS %s
8-
# CHECK-GETFUNCTIONS: {"fn1": {"length": 2, "counters": {"cycles": 45.0, "branch-misses": 10.0}}}
7+
# RUN: lnt profile getFunctions --sortkeys %S/Inputs/test.lntprof | FileCheck --check-prefix=CHECK-GETFUNCTIONS %s
8+
# CHECK-GETFUNCTIONS: {"fn1": {"counters": {"branch-misses": 10.0, "cycles": 45.0}, "length": 2}}
99

1010
# RUN: lnt profile getCodeForFunction %S/Inputs/test.lntprof fn1 | FileCheck --check-prefix=CHECK-GETFN1 %s
1111
# CHECK-GETFN1: [{}, 1048576, "add r0, r0, r0"], [{"cycles": 100.0}, 1048580, "sub r1, r0, r0"]]

0 commit comments

Comments
 (0)