Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Move logging off the main thread - #16325

Merged
jmalanen merged 3 commits into
masterfrom
jmalanen-log
Apr 1, 2020
Merged

jmalanen merged 3 commits into
masterfrom
jmalanen-log

Conversation

@jmalanen

@jmalanen jmalanen commented Mar 20, 2020 •

Copy link
Copy Markdown
Contributor

Fixes: mapbox/mapbox-gl-native-team/issues/224

Comment thread src/mbgl/util/logging.cpp Resolved
@julianrex

Copy link
Copy Markdown
Contributor

What will this mean for platform SDKs that implement observers? /cc @captainbarbosa

@jmalanen
jmalanen force-pushed the jmalanen-log branch 7 times, most recently from b612466 to e843aff Compare March 23, 2020 20:32
@jmalanen
jmalanen requested a review from pozdnyakov March 24, 2020 07:32
@jmalanen
jmalanen marked this pull request as ready for review March 24, 2020 07:32
@jmalanen
jmalanen requested a review from alexshalamov March 24, 2020 07:32
Comment thread src/mbgl/util/logging.cpp
const optional<std::string>& threadName) {
std::lock_guard<std::mutex> lock(mutex);
if (currentObserver && severity != EventSeverity::Debug &&
currentObserver->onRecord(severity, event, code, msg)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This may be a breaking behavior change. Where thread safety should be implemented? On client side or we need to post currentObserver->onRecord invocation on the thread where setObserver was called?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What was the outcome of this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I like the idea of the developer providing the thread/queue for logging, rather than one being created, but that feels like a possible follow-on?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This question was more directed to Android and iOS, and both have now confirmed that the log observers are thread safe.

Regarding the developer providing the thread/queue, it can be a possible follow-up in case there's a need for it.

@alexshalamov
alexshalamov self-requested a review March 24, 2020 08:40
@alexshalamov

Copy link
Copy Markdown
Contributor

@julianrex @tobrun if you use log observers, are they thread safe?

@tobrun

tobrun commented Mar 24, 2020

Copy link
Copy Markdown
Member

@julianrex @tobrun if you use log observers, are they thread safe?

Android, yes

Comment thread include/mbgl/util/logging.hpp Resolved
Comment thread src/mbgl/util/logging.cpp Resolved
Comment thread src/mbgl/util/logging.cpp Resolved

@alexshalamov alexshalamov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm, maybe worth waiting for feedback from iOS folks

@jmalanen jmalanen self-assigned this Mar 24, 2020
@jmalanen
jmalanen requested a review from julianrex March 24, 2020 15:23
@chloekraw

Copy link
Copy Markdown
Contributor

agreed, cc @mapbox/maps-ios @1ec5 to review

@chloekraw
chloekraw requested a review from knov March 24, 2020 20:02
@jmalanen
jmalanen requested a review from 1ec5 March 25, 2020 07:20
@julianrex

Copy link
Copy Markdown
Contributor

Is the primary use-case for useLogThread == false debugging?

@julianrex

Copy link
Copy Markdown
Contributor

Can we merge this after 1.5.0 please?

@chloekraw chloekraw added the ⚠️ DO NOT MERGE Work in progress, proof of concept, or on hold label Mar 25, 2020
@jmalanen

Copy link
Copy Markdown
Contributor Author

Is the primary use-case for useLogThread == false debugging?

@julianrex It's needed for GL native unit tests. Some tests are counting the number of logs to decide pass/fail so the second commit in this PR disables the logging thread for those tests.

@julianrex

Copy link
Copy Markdown
Contributor

Thanks @jmalanen - it would be a good option to make this configurable, especially to the end developer - does this allow for that?

@jmalanen

Copy link
Copy Markdown
Contributor Author

@julianrex It is already configurable. The developer can call Log::useLogThread(false) in case they don't want to use the logging thread.

@chloekraw chloekraw added needs changelog Indicates PR needs a changelog entry prior to merging. and removed ⚠️ DO NOT MERGE Work in progress, proof of concept, or on hold labels Mar 26, 2020
@jmalanen

Copy link
Copy Markdown
Contributor Author
  • Added changelog entry
  • Release 1.5.0 was made so this is OK to merge now

@jmalanen jmalanen removed the needs changelog Indicates PR needs a changelog entry prior to merging. label Mar 27, 2020
@jmalanen

Copy link
Copy Markdown
Contributor Author

@1ec5 @julianrex Can you please review this from iOS point of view?

Juha Alanen added 3 commits March 31, 2020 11:08
some tests are counting the number of logs to determine pass/fail
so disable separate logging thread for them.

FixtureLog::FixtureLog() : observer(new FixtureLogObserver(this)) {
Log::setObserver(std::unique_ptr<Log::Observer>(observer));
Log::useLogThread(false);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there a test where useThread is true?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

All other tests that don't count the number of log messages have useThread == true

@julianrex

Copy link
Copy Markdown
Contributor

Looks good from an iOS pov - our default logging observer is thread-safe.

A few questions, but shouldn't block this PR:

  • Before this PR, was it possible for logging to occur off the main thread?
  • If useThread == false does that mean that all logs are on the main thread, or just the thread where the log was initiated?
  • Are there any use cases where we should expect multiple Log objects (not just the singleton)?

@jmalanen

jmalanen commented Apr 1, 2020

Copy link
Copy Markdown
Contributor Author

Looks good from an iOS pov - our default logging observer is thread-safe.

@julianrex Thank you for the review! Merging the PR based on this.

A few questions, but shouldn't block this PR:

  • Before this PR, was it possible for logging to occur off the main thread?

No.

  • If useThread == false does that mean that all logs are on the main thread, or just the thread where the log was initiated?

The thread where the log was initiated.

  • Are there any use cases where we should expect multiple Log objects (not just the singleton)?

I am currently not aware of such use cases, but it could be another follow-up feature in case there's a need for that.

@jmalanen
jmalanen merged commit 09a5ee2 into master Apr 1, 2020
@jmalanen
jmalanen deleted the jmalanen-log branch April 1, 2020 08:17
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants