Skip to content
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

Write out newline character after the message in verbose output #5135

Merged
merged 2 commits into from
Jun 25, 2020

Conversation

fjeremic
Copy link
Contributor

The TR_VerboseLog::writeLine* APIs currently write the newline
character before the message being printed which is non-conventional.
Typically the expectation of a user is that any API that outputs
newline characters outputs them at the end, examples from various
languages in [1] [2] [3], and there are numerous other examples.

The reason we are making this change is because other components in OMR
will expect to be writing at the start of a newline, whether that be
stdout, stderr, or a file. The verbose log not adhering to this
expectation yields in messages getting printed one after another which
is not desirable.

[1] https://docs.python.org/3/library/functions.html#print
[2] https://docs.oracle.com/javase/8/docs/api/java/io/PrintStream.html#println-java.lang.String-
[3] https://docs.microsoft.com/en-us/dotnet/api/system.console.writeline?view=netframework-4.8#System_Console_WriteLine_System_String_

Signed-off-by: Filip Jeremic [email protected]

@fjeremic
Copy link
Contributor Author

Suggesting @dsouzai for review.

@fjeremic
Copy link
Contributor Author

@genie-omr build all

@dsouzai
Copy link
Contributor

dsouzai commented Apr 28, 2020

The change looks reasonable to me. However, it is worth pointing out its impact.

I think I know the reason why the newline was put in the beginning of the line. It's not a good one lol, but essentially, in OpenJ9, there's times when the vlog data is written out as

TR_VerboseLog::vlogAcquire();
...
TR_VerboseLog::write();
...
TR_VerboseLog::vlogRelease();

and so to reduce the "overhead" of writing out the newline explicitly, the writeLine and writeLineLocked would "guarantee" that you'd always get a new line.

Searching through the code, I also found this [1]

TR_VerboseLog::vlogAcquire();
TR_VerboseLog::writeLine(..);
...
TR_VerboseLog::write(..);
...
TR_VerboseLog::vlogRelease();

Notice how we do writeLine first and then do a bunch of writes. With your change, we'll have to update all those locations in OpenJ9 and possibly OMR that assume that the newline is printed out at the start.

[1] https://github.com/eclipse/openj9/blob/2054d856333aab1b46166f989e1ee904622b7930/runtime/compiler/control/CompilationThread.cpp#L5486-L5514

@fjeremic
Copy link
Contributor Author

Searching through the code, I also found this [1]

TR_VerboseLog::vlogAcquire();
TR_VerboseLog::writeLine(..);
...
TR_VerboseLog::write(..);
...
TR_VerboseLog::vlogRelease();

Thanks for pointing this out. To fix such a location we would just do:

TR_VerboseLog::vlogAcquire();
TR_VerboseLog::write(..);
...
TR_VerboseLog::write(..);
...
TR_VerboseLog::writeLine(..);
TR_VerboseLog::vlogRelease();

Is this correct? I have no problem going through all the locations and fixing this up so we have conventional printing and not catch users off guard. Do you think this is feasible?

@dsouzai
Copy link
Contributor

dsouzai commented Apr 28, 2020

Is this correct?

Yeah looks correct.

Do you think this is feasible?

Yeah i don't think there's too many locations where we do this. Probably could just grep for TR_VerboseLog::vlogAcquire or TR_VerboseLog::writeLine for these few outliers; the majority of data is written to the vlog via TR_VerboseLog::writeLineLocked.

@fjeremic fjeremic closed this Apr 28, 2020
@fjeremic
Copy link
Contributor Author

Uuuups. Accidentally clicked close button. Meant to say thanks for the feedback and I'll turn this into WIP: until we address this.

@fjeremic fjeremic reopened this Apr 28, 2020
@fjeremic fjeremic changed the title Write out newline character after the message in verbose output WIP: Write out newline character after the message in verbose output Apr 28, 2020
@fjeremic fjeremic marked this pull request as draft April 28, 2020 17:31
@fjeremic fjeremic changed the title WIP: Write out newline character after the message in verbose output Write out newline character after the message in verbose output Apr 28, 2020
@fjeremic fjeremic marked this pull request as ready for review April 28, 2020 20:31
@fjeremic
Copy link
Contributor Author

@dsouzai issues have been addressed. Ready for another review.

@andrewcraik
Copy link
Contributor

@mpirvu perhaps you would take a look since you are probably one of the biggest verbose log users?

compiler/env/VerboseLog.cpp Outdated Show resolved Hide resolved
compiler/env/VerboseLog.cpp Outdated Show resolved Hide resolved
@fjeremic fjeremic force-pushed the verbose-newline branch 3 times, most recently from 7b80420 to 813431b Compare April 29, 2020 16:50
Copy link
Contributor

@dsouzai dsouzai left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Contributor

@mpirvu mpirvu left a comment

Choose a reason for hiding this comment

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

LGTM. Not directly related to this PR, I have an inline question about some write statements without a preceding lock.

compiler/control/CompileMethod.cpp Show resolved Hide resolved
@fjeremic
Copy link
Contributor Author

fjeremic commented May 1, 2020

@genie-omr build all

@andrewcraik
Copy link
Contributor

@fjeremic this looks like it should be close to being ready - do we need to warn/help migrate any downstream consumers like OpenJ9 to avoid breaking the logging?

@fjeremic
Copy link
Contributor Author

fjeremic commented May 7, 2020

do we need to warn/help migrate any downstream consumers like OpenJ9 to avoid breaking the logging?

Yes, this is done in eclipse-openj9/openj9#9391.

The `TR_VerboseLog::writeLine*` APIs currently write the newline
character before the message being printed which is non-conventional.
Typically the expectation of a user is that any API that outputs
newline characters outputs them at the end, examples from various
languages in [1] [2] [3], and there are numerous other examples.

The reason we are making this change is because other components in OMR
will expect to be writing at the start of a newline, whether that be
stdout, stderr, or a file. The verbose log not adhering to this
expectation yields in messages getting printed one after another which
is not desirable.

[1] https://docs.python.org/3/library/functions.html#print
[2] https://docs.oracle.com/javase/8/docs/api/java/io/PrintStream.html#println-java.lang.String-
[3] https://docs.microsoft.com/en-us/dotnet/api/system.console.writeline?view=netframework-4.8#System_Console_WriteLine_System_String_

Signed-off-by: Filip Jeremic <[email protected]>
We perform the following changes:

- Update `write` calls to `writeLine` calls where possible
- Update newline convention to print the new line at the end
- Use the tag when printing where possible
- Add lock acquire and release where it is missed

Signed-off-by: Filip Jeremic <[email protected]>
@fjeremic
Copy link
Contributor Author

fjeremic commented Jun 1, 2020

Rebased on the latest branches and I went ahead and generated builds using this PR and compared how the verbose log looks before and after. I carefully analyzed all output of verbose={*} and could not find a difference in any of the output following this change.

@fjeremic
Copy link
Contributor Author

fjeremic commented Jun 1, 2020

@genie-omr build all

@fjeremic
Copy link
Contributor Author

fjeremic commented Jun 5, 2020

Any committer want to sign up to shepherd this one?

@fjeremic
Copy link
Contributor Author

@0xdaryl @Leonardo2718 any takers for this one perhaps (and the OpenJ9 change)?

@0xdaryl 0xdaryl merged commit beb315e into eclipse-omr:master Jun 25, 2020
@0xdaryl 0xdaryl self-assigned this Jun 25, 2020
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