Skip to content

[llvm][lit] fix writing results to --time-trace-output file #130845

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 13, 2025

Conversation

da-viper
Copy link
Contributor

@da-viper da-viper commented Mar 11, 2025

This patch fixes an issue introduced with commit: 8507dba

@llvmbot
Copy link
Member

llvmbot commented Mar 11, 2025

@llvm/pr-subscribers-testing-tools

Author: Ebuka Ezike (da-viper)

Changes

Fix crash when time tracing.


Full diff: https://github.com/llvm/llvm-project/pull/130845.diff

1 Files Affected:

  • (modified) llvm/utils/lit/lit/reports.py (+2-1)
diff --git a/llvm/utils/lit/lit/reports.py b/llvm/utils/lit/lit/reports.py
index 8312dcddc769a..cd32f0396677c 100755
--- a/llvm/utils/lit/lit/reports.py
+++ b/llvm/utils/lit/lit/reports.py
@@ -286,7 +286,8 @@ def _write_results_to_file(self, tests, elapsed, file):
 
         json_data = {"traceEvents": events}
 
-        json.dump(json_data, time_trace_file, indent=2, sort_keys=True)
+        with open(self.output_file, "w") as time_trace_file:
+            json.dump(json_data, time_trace_file, indent=2, sort_keys=True)
 
     def _get_test_event(self, test, first_start_time):
         test_name = test.getFullName()

Copy link
Collaborator

@jh7370 jh7370 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to clarify: is lit unconditionally failing with a python error here, because time_trace_file is an unknown identifier?

If so, LGTM, assuming that self.output_file is a file path and not a file object... (I haven't dug into all the code).

@da-viper
Copy link
Contributor Author

Yes, this is the case. see

class Report(object):
def __init__(self, output_file):
self.output_file = output_file
# Set by the option parser later.

@jh7370
Copy link
Collaborator

jh7370 commented Mar 12, 2025

Yes, this is the case. see

class Report(object):
def __init__(self, output_file):
self.output_file = output_file
# Set by the option parser later.

Okay, thanks. Do you have commit access or do you need me to merge this for you?

@da-viper
Copy link
Contributor Author

Okay, thanks. Do you have commit access or do you need me to merge this for you?
No, not yet.

Copy link
Collaborator

@jh7370 jh7370 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, cancelling my LGTM. I'm not convinced about this change anymore.

I decided to dig into the background of this a bit more and it looks like it's a bug caused by @DavidSpickett's work in 8507dba. As far as I can see, this _write_results_to_file method shouldn't be called, except via the Report.write_results method. That method opens the file itself and then passes it into this function.

I think the correct fix is simply to use the passed-in file. @DavidSpickett should be able to confirm.

Copy link
Collaborator

@jh7370 jh7370 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM again, but I'd like @DavidSpickett to just take a quick look to confirm.

@jh7370 jh7370 requested a review from DavidSpickett March 12, 2025 10:12
Copy link
Collaborator

@DavidSpickett DavidSpickett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this looks correct. file will be the uniquely named file if it's been requested. Thanks for fixing this.

@jh7370
Copy link
Collaborator

jh7370 commented Mar 13, 2025

@da-viper, sorry I didn't raise this before, but I just realised that you've got your email address marked as private in GitHub, which means we can't merge this per LLVM policy. See https://llvm.org/docs/DeveloperPolicy.html#email-addresses.

Also, I forgot to comment on your PR description/title, since those form the final commit message once this is merged. Since this PR is specific to a particular option, I suggest mentioning that in the title, e.g. "fix writing results to --time-trace file" (I can't remember the actual option name, please use the correct one!). In the description, you don't need to repeat what's in the title, but I'd suggest you add a reference to the commit that caused the issue (i.e. something like "This patch fixes an issue introduced with 8507dba.")

Let me know once you've addressed these issues and I'll click the merge button. (NB: if this doesn't happen by about 4pm GMT today, I'll not see your comment and am then off work for 2+ weeks, so you'll need to ask somebody else to merge the PR).

@da-viper da-viper changed the title [llvm][lit] fix writing results to file [llvm][lit] fix writing results to --time-trace-output file Mar 13, 2025
@da-viper
Copy link
Contributor Author

@jh7370 Should be all done.

@jh7370 jh7370 merged commit c26ec7e into llvm:main Mar 13, 2025
11 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Mar 13, 2025

LLVM Buildbot has detected a new failure on builder arc-builder running on arc-worker while building llvm at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/3/builds/13059

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: 1200 seconds without output running [b'ninja', b'check-all'], attempting to kill
1.003 [59/18/1] Linking CXX executable tools/clang/unittests/Basic/BasicTests
1.728 [58/18/2] Linking CXX executable tools/clang/unittests/Format/FormatTests
6.267 [57/18/3] Linking CXX executable tools/clang/unittests/Lex/LexTests
6.388 [56/18/4] Linking CXX executable tools/clang/unittests/Rewrite/RewriteTests
6.606 [55/18/5] Linking CXX executable tools/clang/unittests/CrossTU/CrossTUTests
6.666 [54/18/6] Linking CXX executable tools/clang/unittests/libclang/libclangTests
7.149 [53/18/7] Linking CXX executable tools/clang/unittests/libclang/CrashTests/libclangCrashTests
command timed out: 1200 seconds without output running [b'ninja', b'check-all'], attempting to kill
process killed by signal 9
program finished with exit code -1
elapsedTime=1362.735041

@da-viper da-viper deleted the fix-writing-results-to-file branch March 13, 2025 16:50
frederik-h pushed a commit to frederik-h/llvm-project that referenced this pull request Mar 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants