-
Notifications
You must be signed in to change notification settings - Fork 31
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
Add tracing with switch and level #397
Conversation
Dependency Review✅ No vulnerabilities or license issues found.Scanned Manifest Files |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your first PR. We really appreciate it!
🦙 MegaLinter status:
|
Descriptor | Linter | Files | Fixed | Errors | Elapsed time |
---|---|---|---|---|---|
✅ ACTION | actionlint | 12 | 0 | 0.06s | |
✅ DOCKERFILE | hadolint | 2 | 0 | 0.11s | |
✅ JSON | eslint-plugin-jsonc | 8 | 0 | 0 | 4.11s |
✅ JSON | prettier | 8 | 0 | 0 | 0.48s |
markdownlint | 7 | 1 | 11 | 1.46s | |
markdown-link-check | 7 | 1 | 51.45s | ||
✅ MARKDOWN | markdown-table-formatter | 7 | 1 | 0 | 0.33s |
lychee | 126 | 1 | 2.51s | ||
prettier | 21 | 0 | 1 | 1.08s | |
✅ YAML | v8r | 21 | 0 | 7.75s | |
✅ YAML | yamllint | 21 | 0 | 0.39s |
See detailed report in MegaLinter reports
services/tracer/Tracer.hpp
Outdated
|
||
static auto GlobalTracingLevel = TracingLevel::DEBUG; | ||
|
||
template<class T, TracingLevel L> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about adding a LevelTracer like this:
class LevelTracer
: public Tracer
{
public:
using Tracer::Trace;
#ifdef EMIL_ENABLE_GLOBAL_TRACING
infra::TextOutputStream Trace(int level);
#else
class EmptyTracing
{
template<class T>
EmptyTracing operator<<(T x) { return *this; }
};
EmptyTracing Trace(int level);
#endif
void SetCurrentLevel(int level);
};
tracer.Trace(Level::debug) << "something " << 6;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried this and it nicely discards everything that comes after "<<".
Then it is indeed nicer. However, there are places that access OutputStream such as
Observer().FillTopic(tracer.Continue().Writer());
which fails. That can be solved by adding OutputStream members to EmptyTracing but where do we stop :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can decide to stop exposing TextOutputStream altogether and adapt the code that rely on this.
What do you think?
#ifdef EMIL_ENABLE_GLOBAL_TRACING
class Tracing
{
public:
template<class T>
Tracing operator<<(T x)
{
stream << x;
return *this;
}
};
Tracing Trace()
{
stream << "\r\n";
InsertHeader();
return Tracing{};
}
Tracing Continue()
{
return Tracing{};
}
#else
class EmptyTracing
{
public:
template<class T>
EmptyTracing operator<<(T x)
{
return *this;
}
};
EmptyTracing Trace()
{
return EmptyTracing{};
}
EmptyTracing Continue()
{
return EmptyTracing{};
}
#endif
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information The version of Java (11.0.14.1) you have used to run this analysis is deprecated and we will stop accepting it soon. Please update to at least Java 17. |
Kudos, SonarCloud Quality Gate passed! |
Adding switchable tracing to embedded infra lib.
Global on and off switch removes the tracing code at compile/link time which has size benefits.
Tracing level turns it on and off at runtime which has significant performance effects. Since even when we use a dummy tracer, we process lots of strings and for example binary pipe performance suffers a lot with tracing per packet.