-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Add bazel query --output_file
option, which writes query results directly to a file
#24298
Add bazel query --output_file
option, which writes query results directly to a file
#24298
Conversation
…rectly to a file
src/main/java/com/google/devtools/build/lib/runtime/QueryRuntimeHelper.java
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/runtime/QueryRuntimeHelper.java
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/buildtool/CqueryProcessor.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/query2/common/CommonQueryOptions.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/query2/common/CommonQueryOptions.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/query2/common/CommonQueryOptions.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/runtime/QueryRuntimeHelper.java
Outdated
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/runtime/QueryRuntimeHelper.java
Outdated
Show resolved
Hide resolved
if (outputFile == null) { | ||
return createInternal(env.getReporter().getOutErr().getOutputStream()); | ||
} | ||
Path fullPath = env.getWorkspace().getRelative(outputFile); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be CommandEnvironment#getWorkspace
or CommandEnvironment#getWorkingDirectory
? The latter should let you store the file beneath the workspace root?
src/main/java/com/google/devtools/build/lib/runtime/QueryRuntimeHelper.java
Show resolved
Hide resolved
src/main/java/com/google/devtools/build/lib/runtime/QueryRuntimeHelper.java
Show resolved
Hide resolved
We're working on channeling anything (via flags) that writes to the local filesystem outside of the output tree to the InstrumentationOutput abstraction? Could you see if that could be used without too much hardship? We're still working out the ergonomics, so I apologize if it might not be straightforward (yet). |
I'm OK with trying this, but from the name and docs, |
Agreed the name isn't ideal, but it's the same thing in spirit. I think this just might be the ~first1 time we've had something like this, or the first we've encountered it since taking inventory and naming this concept Footnotes
|
I just tried using
|
Update: I fixed 1 and 2 myself, and @jin said I don't need 3. |
switch (destinationRelativeTo) { | ||
case OUTPUT_BASE -> env.getOutputBase().getRelative(destination); | ||
case WORKSPACE_OR_HOME -> env.getWorkspace().getRelative(destination); | ||
case WORKING_DIR -> env.getWorkingDirectory().getRelative(destination); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As the author of InstrumentationOutput
, I want to sincerely thank you for adopting InstrumentationOutput
.
However, please note that env.getWorkingDirectory()
is not "getting the directory from which the user ran Bazel". From its implementation and JavaDoc, this method returns "working directory of the server", which could be identical to workspace, in most cases I think. I apologize for this confusion. And this is painful for us as well, which makes us making the initial assumption to conflate workspace and working directory.
As of now, we are researching about fixing this flawed assumption. So it is totally fine to opt out of adopting InstrumentationOutput
in this change. I think we can do the switch after we know how to sort out this ball of mud.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, thanks for the explanation! Note: you linked to BlazeDirectories.getWorkingDirectory
, which you described accurately; but I was not calling that; I was calling CommandEnvironment.getWorkingDirectory()
, which is the client working directory :)
bazel/src/main/java/com/google/devtools/build/lib/runtime/CommandEnvironment.java
Lines 653 to 662 in 72a9d49
/** | |
* Returns the working directory of the {@code blaze} client process. | |
* | |
* <p>This may be equal to {@code BlazeRuntime#getWorkspace()}, or beneath it. | |
* | |
* @see #getWorkspace() | |
*/ | |
public Path getWorkingDirectory() { | |
return workingDirectory; | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I misread on this. Then this looks good to me.
return new FileQueryRuntimeHelper(instrumentationOutput); | ||
} catch (IOException e) { | ||
throw new QueryRuntimeHelperException( | ||
"Could not open query output file " + instrumentationOutput.getHumanReadableName(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think you alluded to this in my other comment - is this the absolute path? a perhaps not-well-documented thing we like to try to do is avoid absolute paths in user-visible messaging as much as possible, this way if the local filesystem (CI etc) doesn't match the end-user's filesystem there's less confusion. also, as you may have deduced from the instrumentation-output abstraction, this path might not reflect the actual file we were operating on.
that said, logging absolute paths to info logging should be fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, okay. Personally when Bazel outputs a path, it can be difficult to understand which of Bazel's many directories it is relative to. So I would prefer Bazel only print absolute paths :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM modulo tests.
src/main/java/com/google/devtools/build/lib/query2/common/CommonQueryOptions.java
Show resolved
Hide resolved
Co-authored-by: Timothy Gu <[email protected]>
Your added test is failing internally. I'll attempt to fix it, but apologies if there's a delay. |
Thank you so much for the update! Hope they are not too onerous to fix. |
…rectly to a file This is a proposed fix for bazelbuild#24293 This speeds up a fully warm `bazel query ...` by 23.7%, reducing wall time from 1m49s to 1m23s ``` $ time bazel query '...' --output=streamed_proto > queryoutput4.streamedproto real 1m48.768s user 0m27.410s sys 0m19.646s $ time bazel query '...' --output=streamed_proto --output_file=queryoutput5.streamedproto real 1m22.920s user 0m0.045s sys 0m0.016s ``` _💁♂️ Note: when combined with bazelbuild#24305, total wall time is 37s, an overall reduction of 66%._ Closes bazelbuild#24298. PiperOrigin-RevId: 700583890 Change-Id: Ic13f0611aca60c2ce8641e72a0fcfc330f13c803
This is a proposed fix for #24293
This speeds up a fully warm
bazel query ...
by 23.7%, reducing wall time from 1m49s to 1m23s💁♂️ Note: when combined with #24305, total wall time is 37s, an overall reduction of 66%.