logger: write thread id as part of log message#6978
logger: write thread id as part of log message#6978carun wants to merge 1 commit intodlang:masterfrom carun:log-threadid
Conversation
|
Thanks for your pull request and interest in making D better, @carun! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub fetch digger
dub run digger -- build "master + phobos#6978" |
|
Ping @burner @thewilsonator |
std/experimental/logger/core.d
Outdated
|
|
||
| import std.experimental.logger.filelogger; | ||
|
|
||
| extern (C) size_t syscall(int number, ...); |
There was a problem hiding this comment.
not sure if using this to get the tid is a good idea.
I think gettid should be placed in druntime.
std/experimental/logger/core.d
Outdated
|
|
||
| import std.experimental.logger.filelogger; | ||
|
|
||
| extern (C) size_t syscall(int number, ...); |
There was a problem hiding this comment.
I think I miss-communicated.
I meant
if(!betterSolutionToPlaceASyscallThanDefiningTheSyscallExternCFunction()) {
makeItPrivate();
} else {
implementBetterSolution();
}I still consider this extern(C) to be a major code smell.
Geod24
left a comment
There was a problem hiding this comment.
This is essentially re-doing what's in core.thread. If accessing the thread ID is expensive, then it should be fixed, rather than worked around.
In addition, using pthread_self (like core.thread) would probably be better than gettid, as it would support POSIX systems, not only Linux. It would also be more correct, as the result of gettid does not match the result of pthread_self, which is most likely what people will get when debugging.
|
@Geod24 Thanks for your comments.
Fixing
If you look closer, you will see that The user can look at the log for some error, check the thread ID entry obtained via |
Yep, I've seen. The point was more about providing platform-specific features. Ideally the feature set should be the same for all platform at the Phobos level. Some place just can't achieve that, but here it looked to me that we could.
Good point, I did not consider the use case of live debugging. It would be nice to add a mention (comment) of why the Also, this needs to be mentioned in the release notes. Some people might be relying on Last but not least, types are a bit messy in the patch: |
|
@carun any updates? |
|
@burner apparently, dlang/druntime#2820 brings in |
Previous implementation had `std.concurrency.Tid`, which is simply a wrapper around `MessageBox` and is not related to Thread ID in anyway. It cannot be used in `@safe` code. Instead this patch uses `core.thread.ThreadID`. Using it requires `this` and it also locks mutex for every call. This patch also caches the result in a TLS to prevent unnecessary synchronization overhead.
|
@carun sounds good, you properly should focus on getting the druntime thing in first though. IMHO that is the more controversial PR. |
|
ping @carun what's the status of this PR? anytime soon to get it in? Thanks. |
|
@mingwugmail the situation is kinda complicated that this PR now depends on the druntime refactoring and anything that huge has the potential for a long wait or rejection. I don't intend to work on this anymore. D runtime is a pity, sadly. |
Previous implementation had
std.concurrency.Tid, which is simply awrapper around MessageBox and is not related to Thread ID in anyway.
It cannot be used in @safe code.
Instead this patch uses
core.thread.ThreadID. It requiresthisandit also locks mutex for every call. This patch caches the result in a
TLS to prevent unnecessary synchronization overhead.