Skip to content
This repository has been archived by the owner on Nov 10, 2023. It is now read-only.

Remove extra work when computing code coverage #1066

Closed
kageiit opened this issue Dec 22, 2016 · 17 comments
Closed

Remove extra work when computing code coverage #1066

kageiit opened this issue Dec 22, 2016 · 17 comments

Comments

@kageiit
Copy link
Contributor

kageiit commented Dec 22, 2016

0cc8d5d introduced a performance degradation for projects that do not use the direct_to_jar spool mode when computing code coverage

Ideally, the classes dir can be used if it already exists to prevent unzipping for projects that output classes to the filesystem already.

kageiit referenced this issue Dec 22, 2016
Summary:
When jar_spool_mode is direct_to_jar, we don't generate a directory of
class files. But the code coverage reporting step needs such a
directory to figure out what classes are being tested.

In this diff, I just extract the jar file to that directory just
before calling the reporting step.

Test Plan:
I ran the `buck test --code-coverage` in an external repo which had the
issue and looked at the generated report and it looked fine.

In the buck repo, added a happy path test to cover the code extraction
paths.

Reviewed By: jkeljo

fbshipit-source-id: 7c7c85e
@tdrhq
Copy link

tdrhq commented Dec 22, 2016

@kageiit This should be easy to do, but how much of a regression are we talking about? The code coverage logic has broken a few times in the past, so having fewer variations on the code path would prevent this from breaking again. If the regression is really significant, then I can put in a few if-elses

@kageiit
Copy link
Contributor Author

kageiit commented Dec 22, 2016

This is about covering all the cases consumers can write to disk for jar'ing. We should ideally avoid work unless its needed. Unzipping every single classes jar to obtain code coverage is a significant performance regression especially if the classes directory is already available. Consumers cannot spool to jar if postprocess_classes_commands are active as well, so this sort of change will break build time slas for them

@tdrhq
Copy link

tdrhq commented Dec 22, 2016

To be clear, it shouldn't be every single jar file, it should only be the ones that have the given test in their tests = [] argument. (So, ideally just 2-3 at most even in a big repository)

@kageiit
Copy link
Contributor Author

kageiit commented Dec 22, 2016

I dont understand what you are saying. The classes directory of a rule was replaced with rule.getPathToOutput(); which is getting unzipped for every rule.

@kageiit
Copy link
Contributor Author

kageiit commented Dec 22, 2016

we have several thousand rules that have associated tests with them. We should not be required to unzip the jars for computing code coverage when the unzipped classes directory is already available. We also dont spool directly to jar

@tdrhq
Copy link

tdrhq commented Dec 22, 2016

@kageiit I see, so your concern is with CI runs where you run all the tests, correct? Local runs probably don't get affected as much because people probably run a few targets at a time. Just understanding the situation right now.

@kageiit
Copy link
Contributor Author

kageiit commented Dec 22, 2016

Yes. That is correct

@kageiit
Copy link
Contributor Author

kageiit commented Jan 3, 2017

@tdrhq any updates on this?

@tdrhq
Copy link

tdrhq commented Jan 3, 2017

will be doing this soon, I would still love some kind of number to get a sense of what percentage increase we're talking about, an approximation would do

@kageiit
Copy link
Contributor Author

kageiit commented Jan 3, 2017

Approximately 15 ~ 30 seconds more when running coverage on several thousands of test rules. Overall test run times are around 8 ~ 10 min. This is because code coverage is purely single threaded and happens at the very end after all test rules are run. The unzip has to happen for every build target that underwent tests. The number of test rules are only increasing and would be great to avoid this extra unzip time since the classes are already available

@kageiit
Copy link
Contributor Author

kageiit commented Jan 13, 2017

@tdrhq any updates?

@tdrhq
Copy link

tdrhq commented Jan 13, 2017

woops sorry, I'll work on this today

@tdrhq
Copy link

tdrhq commented Jan 20, 2017

Fixed in a4cd1b0

Let me know if it works

@kageiit
Copy link
Contributor Author

kageiit commented Jan 25, 2017

Going to pull this in by tomorrow. Will report back

@kageiit
Copy link
Contributor Author

kageiit commented Jan 27, 2017

@tdrhq We are seeing an exception with the latest buck version

TESTS PASSED
Failed on step emma_report with an exception:
buck-out/bin/freight/freight-authentication/lib__src_release__classes does not exist
java.lang.IllegalStateException: buck-out/bin/freight/freight-authentication/lib__src_release__classes does not exist
	at com.google.common.base.Preconditions.checkState(Preconditions.java:444)
	at com.facebook.buck.jvm.java.GenerateCodeCoverageReportStep.populateClassesDir(GenerateCodeCoverageReportStep.java:189)
	at com.facebook.buck.jvm.java.GenerateCodeCoverageReportStep.execute(GenerateCodeCoverageReportStep.java:98)
	at com.facebook.buck.step.DefaultStepRunner.runStepForBuildTarget(DefaultStepRunner.java:47)
	at com.facebook.buck.cli.TestRunning.runTests(TestRunning.java:437)
	at com.facebook.buck.cli.TestCommand.runTestsInternal(TestCommand.java:316)
	at com.facebook.buck.cli.TestCommand.runWithoutHelp(TestCommand.java:580)
	at com.facebook.buck.cli.AbstractCommand.run(AbstractCommand.java:205)
	at com.facebook.buck.cli.BuckCommand.run(BuckCommand.java:91)
	at com.facebook.buck.cli.Main.runMainWithExitCode(Main.java:1287)
	at com.facebook.buck.cli.Main.runMainThenExit(Main.java:706)
	at com.facebook.buck.cli.Main.main(Main.java:1884)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.facebook.buck.cli.bootstrapper.ClassLoaderBootstrapper.main(ClassLoaderBootstrapper.java:62)

@felipecsl
Copy link

We're seeing the exception above too. Are there any workarounds for it?

@felipecsl
Copy link

This seems to be fixed with jar_spool_mode = direct_to_jar in the buckconfig file

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants