dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.23k stars 1.58k forks source link

Dart binary on windows should set it's process name to include the entry point? #37412

Open eseidelGoogle opened 5 years ago

eseidelGoogle commented 5 years ago

When we get reports of dart taking up too much memory, it would be nice to know which dart: image

https://github.com/flutter/flutter/issues/33862#issuecomment-507174340

Maybe there are other, better ways than changing the process name? FYI @devoncarew

julemand101 commented 5 years ago

I can recommend Process Explorer where you can get a lot more details about each process (e.g. command line parameters): https://docs.microsoft.com/en-us/sysinternals/downloads/process-explorer

image

eseidel commented 1 year ago

I ran into this again today while doing some local server development. If you ever leak a dart process, you just have to kill all your Dart processes, because you can't tell which is which. :/ It seems we do support this on Mac at least, there I see "dart:flutter.snapshot" as the name in Activity Monitor, which is helpful. FYI @kevmoo @clarkezone

eseidel commented 1 year ago

To be clear, I'm not at all sure this is possible on windows. Other things I found while investigating: https://stackoverflow.com/questions/23783985/set-child-process-name-in-windows https://github.com/dvarrazzo/py-setproctitle

devoncarew commented 1 year ago

One thing we may do here is ship a dart bug command - a tool to help gather some SDK setup and diagnostic info; that would likely include stats on Dart process (though may not include process IDs). Here's some potential output:


General info

Project info

Process info

Memory CPU Elapsed time Command line
75 MB 0.0% 00:04 dart devtools --machine --try-ports 10 --allow-embedding
792 MB 0.0% 17:52:09 dart language-server --protocol=lsp --client-id=VS-Code --client-version=3.52.1
588 MB 207.9% 00:04 dart language-server --protocol=lsp --client-id=VS-Code --client-version=3.52.1
eseidel commented 1 year ago

A tool that could tell me what the dart processes were on my machine would be awesome (even if I couldn't used the OS ones, although that OS ones would be preferred where possible). Maybe someone has already written a dartps package or similar, that does sound possible to do...

slightfoot commented 1 year ago

Windows executables can have a file section for application resources and that contains the version information for the program, including its display name and info. This information is used by Task Manager and the Properties panel when displaying information on a executable file.

I compiled @timsneath tetris example as a win32 app with dart compile exe and added a resource section with the following version info.

1 VERSIONINFO

FILEVERSION 1,0,0,0
PRODUCTVERSION 1,0,0,0
FILEOS 0x40004
FILETYPE 0x1
{
BLOCK "StringFileInfo"
{
    BLOCK "000004B0"
    {
        VALUE "FileVersion", "1.0.0.0"
        VALUE "ProductVersion", "1.0.0.0"
        VALUE "OriginalFilename", "tetris.exe"
        VALUE "InternalName", "tetris.exe"
        VALUE "FileDescription", "My Awesome Tetris App"
        VALUE "CompanyName", " "
        VALUE "LegalCopyright", "Copyright (c) 2022"
        VALUE "ProductName", " "
    }
}

BLOCK "VarFileInfo"
{
    VALUE "Translation", 0x0000 0x04B0
}
}

And Task Manager shows this: image

You can use the the BeginUpdateResource/UpdateResource/EndUpdateResource APIs to make these changes. The data used in UpdateResource is the compiled script from the above. Microsoft Resource Compiler takes the script and outputs the data with a little header. The format of the raw resource data is spec'd but I forget where.

Ref:

slightfoot commented 1 year ago

Additionally from my understanding there is no runtime way of altering the displayed titles, as, Task Manager opens and memory maps in the executable files into memory to process them and read their resources.

However there is a trick 🤔 If your application has a window it will show its title. You might be able to create an off-screen window or something. Quite hacky 😢