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

Don't need to truncate thread names to 15 chars on Apple platforms. #919

Open
alecazam opened this issue Oct 31, 2024 · 3 comments
Open

Comments

@alecazam
Copy link

The 15 character limit is an archaic limitation of Linux/Android, and not macOS/iOS. So the name here doesn't need truncated in TaskSystem.cpp

#elif (defined _GNU_SOURCE || defined __clang__) && !defined __EMSCRIPTEN__
    {
#if defined __APPLE__
		pthread_setname_np( name );
#else
		// only linux/android have a 15 char name limit
		const auto sz = strlen( name );
        if( sz <= 15 )
        {
            pthread_setname_np( pthread_self(), name );
        }
        else
        {
            char buf[16];
            memcpy( buf, name, 15 );
            buf[15] = '\0';
            pthread_setname_np( pthread_self(), buf );
        }
#endif
    }
@wolfpld
Copy link
Owner

wolfpld commented Oct 31, 2024

Please provide a reference to documentation that supports this claim.

@alecazam
Copy link
Author

alecazam commented Oct 31, 2024

Not sure what docs you expect. This stuff is rarely documented. macOS is 64 chars at least. Also the tracy thread names are > 15 and get truncated always. Seeing "Tracy Compress Wo" is not ideal. These should be shortened.

https://sourceware.org/bugzilla/show_bug.cgi?id=16578

@alecazam
Copy link
Author

alecazam commented Nov 5, 2024

Also the macOS build GetThreadName doesn't return anything but an id. Code would look something like the following. The call needs a pthread ptr, and int (32-bit) won't hold that. I'm hoping that the thread name table returns valid names and so this code isn't needed.

TRACY_API const char* GetThreadName( uint32_t id )
{
#elif defined __APPLE__
       static char nameBuf[63 + 1] = {0};
	if (pthread_getname_np(static_cast<pthread_t*>(id), nameBuf, 63) == 0) {
		return nameBuf;
	};
}

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

2 participants