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

Difficult to identify specific threads when tracking down issues #6527

Open
dadodasyra opened this issue Nov 20, 2024 · 8 comments
Open

Difficult to identify specific threads when tracking down issues #6527

dadodasyra opened this issue Nov 20, 2024 · 8 comments
Labels
Category: UI Related to the user interface (e.g. commands, terminal output) Status: Blocked Depends on other changes which are yet to be completed Type: Enhancement Contributes features or other improvements to PocketMine-MP

Comments

@dadodasyra
Copy link

Problem description

I'm having trouble debugging who's using 10MBps, I've narrowed down to a SPID (thread pid) but I'm unable to do anything with it because there's no way to know which threads it corresponds in PM.

Proposed solution

As already asked, yes there's issues with the fact that there's no cross platform way (according to Dylan, though @cli_set_process_title may be an answer ?). I think at least there should be a way to get an instance of every threads used in pocketmine through a plugin so we can dump IDs with this. Or even better an in-game Pocketmine command to dump every process ids for admins.

Alternative solutions that don't require API changes

Doesn't require any BC breaks

@dktapps
Copy link
Member

dktapps commented Nov 21, 2024

You can use ThreadManager to inspect threads created directly by the main thread, which include lots of useful functions to do what you want. Assuming that the thread you're looking for was started directly by the main thread, anyway.

@dktapps
Copy link
Member

dktapps commented Nov 21, 2024

though @cli_set_process_title may be an answer

No, this doesn't work on individual threads.

pmmpthread could introduce a method to set thread name, but platforms like MacOS only allow a thread to change its own name, so it's a bit annoying to implement.

@dktapps
Copy link
Member

dktapps commented Nov 21, 2024

Relates to pmmp/ext-pmmpthread#139

@dktapps dktapps changed the title Ways to get threads IDs Difficult to identify specific threads when tracking down issues Nov 21, 2024
@dktapps dktapps added Type: Enhancement Contributes features or other improvements to PocketMine-MP Status: Blocked Depends on other changes which are yet to be completed Category: UI Related to the user interface (e.g. commands, terminal output) labels Nov 21, 2024
@dadodasyra
Copy link
Author

though @cli_set_process_title may be an answer

No, this doesn't work on individual threads.

Isn't @cli_set_process_title already used in PM by Console reader?

@dadodasyra
Copy link
Author

You can use ThreadManager to inspect threads created directly by the main thread, which include lots of useful functions to do what you want. Assuming that the thread you're looking for was started directly by the main thread, anyway.

I've seen it after my issue, it seems like I'm unable to get a PID from it (currentThreadId seems a long 64bit id), and, weirdly the getcurrentthread returns null for each threads in the ThreadManager.

@dktapps
Copy link
Member

dktapps commented Nov 21, 2024

though @cli_set_process_title may be an answer

No, this doesn't work on individual threads.

Isn't @cli_set_process_title already used in PM by Console reader?

ConsoleReader isn't a thread

getcurrentthread returns null for each threads in the ThreadManager.

Thread::getCurrentThreadId() returns the ID of the currently executing thread. It's static for a reason.

You should use this function: https://github.com/pmmp/ext-pmmpthread/blob/71cae13851a2ee9cc8558d6e5d0faf8c5bedb36d/stubs/Thread.stub.php#L159

@dadodasyra
Copy link
Author

Thread::getCurrentThreadId() returns the ID of the currently executing thread. It's static for a reason.

You should use this function: https://github.com/pmmp/ext-pmmpthread/blob/71cae13851a2ee9cc8558d6e5d0faf8c5bedb36d/stubs/Thread.stub.php#L159

Yes that's my bad I didn't saw it was static, but that's what I was saying, it returns very long ID that I don't really know what they stands for:

        foreach (ThreadManager::getInstance()->getAll() as $thread) {
            var_dump($thread->getThreadName());
            var_dump($thread->getThreadId());
        }
        
string(13) "AsyncWorker#0"
int(128002130183936)
string(36) "poggit\libasynql\mysqli connector #0"
int(128002115503872)
string(36) "poggit\libasynql\mysqli connector #1"
int(128001985480448)
string(16) "ProxyChildThread"
int(128001819805440)
string(15) "LogsChildThread"
int(128001807222528)
string(4) "RCON"
int(128001792542464)
string(11) "TebexThread"
int(128001779959552)
string(11) "TebexThread"
int(128001631061760)
string(6) "RakLib"
int(128001618478848)

@dktapps
Copy link
Member

dktapps commented Nov 22, 2024

After doing some digging it looks like pthread_self() isn't the same as the ID shown by htop. Still, this shouldn't be necessary anyway. What's needed is to implement pmmp/ext-pmmpthread#139.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: UI Related to the user interface (e.g. commands, terminal output) Status: Blocked Depends on other changes which are yet to be completed Type: Enhancement Contributes features or other improvements to PocketMine-MP
Projects
None yet
Development

No branches or pull requests

2 participants