Conversation
Adds a new profiling backend that uses the CaptureStackBackTrace function for backtraces. The backend does not currently give the library mapping, but is otherwise functional.
Under windows, on the MSVC runtime, the creat function will raise an assertion if it is called with any flag than S_IREAD and S_IWRITE. To avoid crashing when writing the profiling data, we will mask out any unsupported flags from the provided mode.
|
Is there a sample output when the config is enabled?
I think it's because the part of dump mapping is not supported for windows. Ideally, we should have the full flow implemented as a whole if we want to enabled profiling on windows. |
I'll be able to provide one in a couple weeks (currently traveling).
Yes. I left it unimplemented because I didn't personally need it ( Implementing it shouldn't be too hard though - it's mostly calling |
Here's a sample output: Here's the program source: https://github.com/roblabla/jemalloc-windows-example And the .exe/pdb can be found here: rust-jemalloc-pprof-example.zip
I'll start work on the Windows backend to get the mapping. |
|
@roblabla Thank you for the PRs and pushing for the improvements on Windows! |
LONG is the name of a type in the Windows SDK, so the macro would conflict with that.
|
Pushed an implementation using CreateToolhelp32Snapshot/Module32First/Module32Next, which has the advantage of not requiring allocations (all the allocations are done internally by the API, using the system allocator instead of jemalloc). Here's an example output I also had to rename the LONG macro to SIZEOF_LONG, since LONG is a common datatype typedef in windows, causing conflicts. |
fa17a65 to
1720e4f
Compare
1720e4f to
1c50952
Compare
|
@nullptr0-0 can you help to take another look? |
|
|
||
| static int | ||
| prof_dump_open_file_impl(const char *filename, int mode) { | ||
| #ifdef _MSC_VER |
There was a problem hiding this comment.
What's the difference between _MSC_VER and _WIN32, should we use the latter to be consistent with the codebase?
There was a problem hiding this comment.
_MSC_VERcontains the MSVC compiler version (or, in the case ofclang-cl, the version of MSVC that version ofclang-cltargets)._WIN32is set to 1 when targeting x86/x64/arm32/arm64 with either a MSVC compiler, clang-cl, or MinGW's GCC.
Using _WIN32 is probably more correct here? I'm not sure if MinGW has its own implementation of creat, or if it reuses the broken one from the CRT.
nullptr0-0
left a comment
There was a problem hiding this comment.
Also is the above output consumed properly by jeprof on Windows? I wonder if the jeprof script also needs to be updated in order to fully support the feature?
| } else { | ||
| fd = creat(log_filename, 0644); | ||
| int mode = 0644; | ||
| #ifdef _MSC_VER |
| buf_writer_cb(buf_writer, buffer); | ||
| } while (Module32Next(snapshot, &module) == TRUE); | ||
|
|
||
| label_error: |
There was a problem hiding this comment.
label_done instead of error?
There was a problem hiding this comment.
Not sure how this macro is used internally, @interwq any recommendation?

Adds a new profiling backend, using
CaptureStackBackTraceto grab the stacktrace.The backend doesn't currently grab the memory mapping of libraries, but is otherwise perfectly functional. I'm currently using it in conjunction with
rust-jemalloc-pprof, to great effect.