samply icon indicating copy to clipboard operation
samply copied to clipboard

obtaining process args for disambiguation

Open vvuk opened this issue 2 years ago • 2 comments

Unity has a complex process tree including kicking off a bunch of dotnet processes, that are lunched via dotnet exec MyProgram.dll. All of these show up just as dotnet, which is not super useful for figuring out what's what :)

I'm thinking to do a local hack for when a process name is dotnet to grab the pid and use proc_pidinfo to get the command line, but I'm unsure if it's safe to do this during TaskProfiler::new just due to it being unclear how long that operation would take. I'm assuming the risk would be some lost samples on process startup, right?

Also, if I were to generalize this to a PR, it would probably look something like an argument to record that's something like... --use_arg_for_command_name dotnet:2 which means "if the command is dotnet, use argv[2] as the recorded command name". Does that sound reasonable?

vvuk avatar Mar 19 '24 03:03 vvuk

I guess dotnet doesn't do this but if you set /proc/pid/comm of the main thread then samply will rename the process accordingly. We use this pretty extensively when profiling Wine apps.

ishitatsuyuki avatar Mar 20 '24 14:03 ishitatsuyuki

In #274 I added an --include-args (or --include-args=5) argument. We will see if proc_pidinfo on macOS is fast enough.

On Linux, renaming the process will still work as before; it will overwrite the old name including the arguments.

Also, if I were to generalize this to a PR, it would probably look something like an argument to record that's something like... --use_arg_for_command_name dotnet:2 which means "if the command is dotnet, use argv[2] as the recorded command name". Does that sound reasonable?

This sounds reasonable to me.

mstange avatar Jun 29 '24 19:06 mstange