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

Add tracing with switch and level #397

Closed
wants to merge 3 commits into from

Conversation

oguzcanoguz
Copy link
Contributor

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.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 28, 2023

Dependency Review

✅ No vulnerabilities or license issues found.

Scanned Manifest Files

Copy link
Contributor

@github-actions github-actions bot left a 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!

@github-actions
Copy link
Contributor

github-actions bot commented Aug 28, 2023

🦙 MegaLinter status: ⚠️ WARNING

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
⚠️ MARKDOWN markdownlint 7 1 11 1.46s
⚠️ MARKDOWN markdown-link-check 7 1 51.45s
✅ MARKDOWN markdown-table-formatter 7 1 0 0.33s
⚠️ SPELL lychee 126 1 2.51s
⚠️ YAML prettier 21 0 1 1.08s
✅ YAML v8r 21 0 7.75s
✅ YAML yamllint 21 0 0.39s

See detailed report in MegaLinter reports

MegaLinter is graciously provided by OX Security


static auto GlobalTracingLevel = TracingLevel::DEBUG;

template<class T, TracingLevel L>
Copy link
Collaborator

@richardapeters richardapeters Aug 28, 2023

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;

Copy link
Contributor Author

@oguzcanoguz oguzcanoguz Oct 20, 2023

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 :)

Copy link
Contributor Author

@oguzcanoguz oguzcanoguz Oct 30, 2023

Choose a reason for hiding this comment

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

In fact we extract and use TextOutputStream from tracer at many places.
image

Copy link
Contributor Author

@oguzcanoguz oguzcanoguz Oct 30, 2023

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

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
0.0% 0.0% Duplication

warning 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.
Read more here

@oguzcanoguz oguzcanoguz marked this pull request as ready for review November 17, 2023 13:56
@oguzcanoguz oguzcanoguz requested a review from a team as a code owner November 17, 2023 13:56
@oguzcanoguz oguzcanoguz removed the request for review from daantimmer November 20, 2023 11:17
@oguzcanoguz oguzcanoguz reopened this Nov 20, 2023
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

100.0% 100.0% Coverage
0.0% 0.0% Duplication

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