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

log: short circuit trace logging on the hot path #66

Merged
merged 1 commit into from
Mar 12, 2018
Merged

log: short circuit trace logging on the hot path #66

merged 1 commit into from
Mar 12, 2018

Conversation

jmank88
Copy link
Contributor

@jmank88 jmank88 commented Mar 12, 2018

This PR extends the log API with support for checking the log level directly. This enables short circuiting before calling log.Trace, avoiding wasting CPU and memory formatting a message and doing internal log handler synchronization. The biggest affect should be in the per-tx sections.

The pre-existing log.Lazy already addresses the problem somewhat, but requires passing a closure and still goes through the internal synchronization.

@@ -70,6 +70,10 @@ func (h *GlogHandler) Verbosity(level Lvl) {
atomic.StoreUint32(&h.level, uint32(level))
}

func (h *GlogHandler) IsLogging(level Lvl) bool {
return atomic.LoadUint32(&h.level) >= uint32(level)
}
Copy link
Contributor Author

@jmank88 jmank88 Mar 12, 2018

Choose a reason for hiding this comment

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

Note that it only checks the global verbosity level. glog supports per-module verbosity, which would be more difficult to look up.

@jmank88 jmank88 requested a review from treeder March 12, 2018 20:35
@treeder treeder merged commit 05723b2 into master Mar 12, 2018
@treeder treeder deleted the trace branch March 12, 2018 21:40
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