Skip to content

If try tracing inside lambdas, compiler runs for infinite time #7591

Description

@diriki

Problem

If I put TRACE_EVENT or TRACE_EVENT_BEGIN macros inside a lambda, the MSVC compiler runs for infinite time without finish.

To reproduce

Try to compile this simple code with perfetto v52.0-6942f195e and toolchain: VS 2026 18.10.1, MSVC 14.51.36231, v145, Release x64.
I noticed the same problem also with older versions of MSVC.

#include <perfetto.h>
#include <iostream>

PERFETTO_DEFINE_CATEGORIES(perfetto::Category("lambda_test"));
PERFETTO_TRACK_EVENT_STATIC_STORAGE();

int main() {
	perfetto::TracingInitArgs args;
	args.backends = perfetto::kInProcessBackend;
	perfetto::Tracing::Initialize(args);
	perfetto::TrackEvent::Register();

	auto traced_lambda = [] {
		TRACE_EVENT("lambda_test", "LambdaTraceEvent");
		std::cout << "Lambda called\n";
		};

	perfetto::TraceConfig config;
	config.add_buffers()->set_size_kb(1024);
	auto session = perfetto::Tracing::NewTrace();
	session->Setup(config);
	session->StartBlocking();
	traced_lambda();
	perfetto::TrackEvent::Flush();
	session->StopBlocking();
	return 0;
}

The same issue happens also if you don't create tracing session and don't call the lambda: you can comment all lines from perfetto::TraceConfig config; to return (excluded) and the issue remains.

Activity

  1. changed the title [-]If try tracing inside with lambdas, compiler runs for infinite time[/-] [+]If try tracing inside lambdas, compiler runs for infinite time[/+] on Sep 23, 2026
  2. primiano commented on Sep 23, 2026

    @primiano
    Member

    it's a bit surprising, but if it happens only with MSVC might likely be some MSVC bug worth filing there.

    Otherwise can you (ask AI help to) to narrow it down to what's causing it?

    We are unlikely to look at some issue that affects only MSVC

  3. diriki commented on Sep 28, 2026

    @diriki
    Author

    Problem solved: there is an issue with the default options of MSVC. It compiles correcty if I set language standard ≥C++20 (flag /std:c++20 or higher). With older standard or the default, the compilation flag /Zc:lambda is needed in order to use TRACE_EVENT inside lambdas. Probably it's related with this MSVC remark.

  4. primiano commented on Sep 28, 2026

    @primiano
    Member

    Oh thanks a lot for finding this. I truly appreciate it.

    We should definitely add this to our documentation.
    I'll reopen the bug to keep track of the doc additions

  5. added theissue type on Oct 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions