8000 Profiling output respects loglevel. by krk · Pull Request #986 · async-profiler/async-profiler · GitHub
[go: up one dir, main page]

Skip to content

Conversation

krk
Copy link
Contributor
@krk krk commented Sep 4, 2024

Description

"Profiling started" and other messages are now INFO loglevel and will respect the current loglevel.

Related issues

#960

Motivation and context

All messages should respect loglevel, "Profiling started" etc. messages did not.

How has this been tested?

With different loglevel parameters:

java ... -agentpath: ...,loglevel=info ...
Profiling started
java ... -agentpath: ...,loglevel=warn ...

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@apangin
Copy link
Member
apangin commented Sep 4, 2024

I'd argue that Profiler output should not respect loglevel.
Output and logs are two different streams. The former is where profiling results go to; results must be dumped regardless of the log level.

I think a better approach to the problem is to make "Profiler started" a log message, which it essentially is, with an exception of Java API, where this message is a valid response returned from execute method.

@apangin
Copy link
Member
apangin commented Sep 4, 2024

When testing, please verify all 3 ways to run profiler:

  1. as an agent;
  2. using asprof;
  3. via Java API.

@krk krk force-pushed the profiling-started branch 2 times, most recently from 5cb4148 to 7b448d7 Compare September 9, 2024 10:55
@krk
Copy link
Contributor Author
krk commented Sep 9, 2024

Simplified the approach, introduced a new LogWriter class to be used instead of FileWriter out(STDOUT_FILENO).

Tested as an agent, asprof and Java API.

❯ asprof start jps
Profiling started

❯ asprof start -L info jps
Profiling started

❯ asprof start -L warn jps

@krk krk force-pushed the profiling-started branch from 9203db6 to 3cd9fc8 Compare September 9, 2024 14:44
@krk
Copy link
Contributor Author
krk commented Sep 9, 2024

(rebased)

@krk krk force-pushed the profiling-started branch from 3cd9fc8 to 6bdcbbd Compare September 10, 2024 12:57
src/log.cpp Outdated
LogLevel Log::_level = LOG_INFO;

int Log::fd() {
return _file ? fileno(_file) : 0;
Copy link
Member

Choose a reason for hiding this comment

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

_file must not be NULL, I think.

src/writer.h Outdated
int _fd;
char* _buf;
size_t _size;
bool _keepOpen = false;
Copy link
Member

Choose a reason for hiding this comment

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

This will issue a compiler warning with older gcc.
We should migrate to a newer C++ standard first, but that's a separate story.

src/writer.h Outdated
class LogWriter : public FileWriter {
LogLevel _logLevel;
public:
LogWriter(LogLevel logLevel = LOG_INFO) : FileWriter(Log::fd(), true) {
Copy link
Member

Choose a reason for hiding this comment

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

This creates an implicit coupling with Log::_file, which lives its own life.
Currently, it's not a problem, since Log is always closed after the output file, but this dependency is fragile.
Alternatively, LogWriter could call Log::writeRaw or something.

"Profiling started" and other messages are now INFO loglevel and will respect the current loglevel.
@krk krk force-pushed the profiling-started branch from 6bdcbbd to 7583ccc Compare September 16, 2024 14:22
@apangin apangin merged commit 6d7f73a into async-profiler:master Sep 17, 2024
1 check passed
@apangin
Copy link
Member
apangin commented Sep 17, 2024

After this change, "Profiling started" message goes to asprof output. This is intended, but does not look perfect, given that asprof prints its own start/stop messages:

Profiling started
Profiling for 5 seconds
Done

I'm more are more inclined to believe this message is redundant and can be removed entirely except for the Java API call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0