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

Tracy and coroutines #936

Open
Sven-v-Beuningen opened this issue Dec 2, 2024 · 4 comments
Open

Tracy and coroutines #936

Sven-v-Beuningen opened this issue Dec 2, 2024 · 4 comments

Comments

@Sven-v-Beuningen
Copy link

I'm currently working on a c++20 coroutine based JobSystem.
The JobSystem schedules coroutines on multiple threads. Calls to co_await can suspend the current coroutine and the JobSystem schedules another coroutine on the same thread. Later on the scheduler returns to the co_awaited coroutine.
Because of this it can happen that a coroutine is suspended and resumed multiple times.
I tried to use Tracy with this system, but always get "Zone is ended twice" error.
Is there anything I can do about that, or does Tracy just not support using coroutines?

Thank you very much in advance!

@wolfpld
Copy link
Owner

wolfpld commented Dec 2, 2024

Please read about fibers in the manual.

@Sven-v-Beuningen
Copy link
Author

Thank you very much about the hin. I read the part about fibers in the documentation and gave it a try:

This is my main worker function. It graps a Job and executes/resumes it. As described in your documentation, I Added the TracyFiberEnter and TracyFiberLeave macros. I also defined TRACY_FIBERS

auto JobSystemWorker::workerFunction() -> void
{
    TracyFiberEnter(m_workerName.c_str());
    while (m_running)
    {
        auto job = std::move(getJob());
        if (job)
        {
            (*job)();
        }
    }
    TracyFiberLeave;
}

Unfortunately, this didn't change anything. As written in the documentation, I added TracyFiberEnter macros, everytime I resume a coroutine:

auto func() -> Job {
    TracyFiberEnter(JobSystem::GetCurrentWorker()->getName());
    UV_PERF_ZONE(EProfilingSystem::Render_1);
    co_return;
}

auto mainFunc() -> Job
{
    while (true)
    {
        UV_PERF_ZONE(EProfilingSystem::Render_1);
        co_await func();
        TracyFiberEnter(JobSystem::GetCurrentWorker()->getName());
        UV_PERF_FRAMEBREAK();
    }

    JobSystem::Stop();
    co_return;
}

But I still geht the "Zone ended twice" error. Did I miss something else?

@HodBadichi
Copy link

@Sven-v-Beuningen Any progress?

I have the same issue, though when reading the manual I'm not sure if the TracyFiberEnter should be in the coroutine context or the dispatcher/scheduler . It seems you chose to put it inside the coroutine itself.

@Sven-v-Beuningen
Copy link
Author

@HodBadichi We've found a solution which does work in a way, that it doesn't crash and doesn't produce "zone ended twice" errors. But from our current point of view it is not very useful for us.
Everytime before one of our workers resumes a coroutine it calls "TracyFiberEnter" with a unique name for each coroutine. If we do it like that, Tracy can successfully assign the tracked zones to this coroutine, also if it is worked on by different workers.
But since each new job in our system is a new coroutine, we have 10th of thousands coroutines each second. This leads to totally bloated progress lines in the server, because each line is just a tiny coroutine.
From our point of view, we need a line for each worker, instead for each coroutine, but we haven't found a solution to achieve this.

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

No branches or pull requests

3 participants