Detailed build document for windows for in_process trace purpose.
I am searching documents for windows builds, even I can get the library built from bazel without IPC part for windows , but it's still very hard for me to fix the include files for my windows project (for in-process trace purpose only). also I am wondering if there is a simplified SDK for in_process trace purpose which I can build for all platfroms including linux/androind/mac/windows.
Heya, I am making some work recently to clean up and port perfetto to Windows (clang and MSVC 2019). You can follow my patches that mention "Bug: 174454879" (which is the windows port). I have not tested the SDK yet. I suppose that given it refers to the IPC code, it won't JustWork. I see two options going forward:
- Release a "lite" version of the SDK that has only the in-tracing parts.
- Wait for the port of the IPC/Socket part.
2 is getting closer. At this point the main thing missing is a port of base::UnixSocket for Windows which I am going to look next.
Thanks primiano for quick response :) I will follow your patches. For some applications like mobile apps, the size of sdk might be another factor requires attention, a lite version for in-tracing parts only could help to reduce app's size.
@primiano , I followed the patches, however, bazel build for libperfetto_client_experimental still compile ipc related codes on windows, and it's still impossible to get windows version of SDK without IPC... From docs, "Windows builds are not currently supported when using the standalone checkout and GN. Windows is supported only for a subset of the targets (mainly trace_processor and the in-process version of the Tracing SDK) in two ways: (1) when building through Bazel; (2) when building as part of Chromium.", it will be great if we can explained steps to tell how to build with Bazel.
@dionysus1016 yes, patches are still in flight. It will take some month still.
For some applications like mobile apps, the size of sdk might be another factor requires attention,
Just to clarify, mobile here has nothing to do with Windows, right? You are talking about two independent things? Or is there something I'm missing?
@primiano , yes, I am talking two things.. I am trying to use perfetto for all platfroms products. For windows, I am blocked by build issue, espcially the SDK stuff, it's very hard for me to clean to SDK head files... For IOS/Android, I am seeking for a lite version of SDK, e.g. we can remove IPC side if we just use perfetto for in-process tracing only, or maybe remove some cpp templates to safe size...
As a workaround, until we get there, you can try setting enable_perfetto_ipc=false and re-run gen_bazel or gen_amalgamated. Not sure it will "JustWork", might require tweaking the GN files a bit more in order to get that, but most of the logic is there. Let's revisit a proper solution to this in the new year. Most of the team is out at this point
Sure, looking forward the team to onboard SDK for windows.
Just wanted to how this was coming along?
FYI, This is how far I got trying to follow along and at least get trace_processor to build. Any tips for getting further?
cd c:\src\perfetto python tools\install-build-deps set PATH=%PATH%;C:\src\perfetto\buildtools\win Download bazel.exe to C:\src\perfetto\buildtools\win // Any reason why bazel couldn't be installed as part of install-build-deps?
// Fix bash to not point to WSL2 because by default bash with WSL2 (C:\WINDOWS\System32\bash.exe) will launch Linux VM and build will fail. Using Git Bash instead which seems to work
SET PATH=C:\Program Files\Git\usr\bin;%PATH% bazel build trace_processor
// Ultimately failed but it compiled a lot further than when last time I tried to build on Windows and hack things to build! C:\src\perfetto>bazel build trace_processor WARNING: Running Bazel server needs to be killed, because the startup options are different. Starting local Bazel server and connecting to it... INFO: Analyzed target //:trace_processor (24 packages loaded, 1457 targets configured). INFO: Found 1 target... ERROR: C:/src/perfetto/BUILD:588:20: Compiling src/base/logging.cc [for host] failed: (Exit 2): cl.exe failed: error executing command C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Tools/MSVC/14.28.29910/bin/HostX64/x64/cl.exe /nologo /DCOMPILER_MSVC /DNOMINMAX /D_WIN32_WINNT=0x0601 /D_CRT_SECURE_NO_DEPRECATE ... (remaining 29 argument(s) skipped) cl : Command line error D8021 : invalid numeric argument '/Wno-pragma-system-header-outside-header' Target //:trace_processor failed to build Use --verbose_failures to see the command lines of failed build steps. INFO: Elapsed time: 272.607s, Critical Path: 29.21s INFO: 386 processes: 17 internal, 369 local. FAILED: Build did NOT complete successfully
// Not sure if it's true but somewhere might have read this doesn't work if you have VS2019 Installed, and need build tools instead. However, I tried installing and using them and it didn't seem to make a difference // Install VS Builld Tools VS Build Tools - https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2019
// For the workaround with gen_bazel and enable_perfetto_ipc=false
Not sure how to use gen_bazel but it seems to fail
C:\src\perfetto>python tools\gen_bazel
Traceback (most recent call last):
File "C:\src\perfetto\tools\gen_bazel", line 587, in
So I am one CL away for being able to build on Windows. TBH there is a point where this worked (1c5c317076a85d2a9c57b18902e1b8eff7f58520) but I had to revert that CL the day after (in r.android.com/1608095) because it broke on win32 and worked only on win64 (Which then broke chromium).
If you checkout 1c5c317076a8 you can use tools/gn and tools/ninja, e.g.:
git checkout 1c5c317076a85d2a9c57b18902e1b8eff7f58520
python3 tools/install-build-deps
set PATH=%PATH%;C:\src\perfetto\buildtools\win
gn args out/xxx
ninja -C out/xxx trace_processor_shell
That's great to hear @primiano. Sounds very close and I see all the work (commits) you put into this! Definitely having this build even trace_processor would unblock us.
Do you happen to know how the build is picking up the VS lib path? I get this error-mid way through build
Are there certain pre-reqs required? A certain Win10SDK or build tool? I have VS2019 Ent IDE /w the "Desktop development with C++" option installed (among other options also installed).
// Left args.gn blank
gn args out/IvanTraceProcessorWin
C:\src\perfetto>ninja -C out/IvanTraceProcessorWin trace_processor_shell ninja: Entering directory `out/IvanTraceProcessorWin' [350/762] link protozero_plugin.exe FAILED: protozero_plugin.exe ../../buildtools/win/clang/bin\lld-link.exe /nologo /OUT:./protozero_plugin.exe /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.18362.0\ucrt\x64" /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.18362.0\um\x64" /LIBPATH:"C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.28.29910\lib\x64" /PDB:./protozero_plugin.exe.pdb @./protozero_plugin.exe.rsp lld-link: error: could not open 'oldnames.lib': no such file or directory [359/762] compile ../../src/trace_processor/db/column.cc ninja: build stopped: subcommand failed.
C:\src\perfetto>ninja -C out/IvanTraceProcessorWin trace_processor_shell ninja: Entering directory `out/IvanTraceProcessorWin' [3/498] link protoc.exe FAILED: protoc.exe ../../buildtools/win/clang/bin\lld-link.exe /nologo /OUT:./protoc.exe /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.18362.0\ucrt\x64" /LIBPATH:"C:\Program Files (x86)\Windows Kits\10\Lib\10.0.18362.0\um\x64" /LIBPATH:"\lib\x64" /PDB:./protoc.exe.pdb @./protoc.exe.rsp lld-link: error: could not open 'libcmt.lib': no such file or directory lld-link: error: could not open 'oldnames.lib': no such file or directory lld-link: error: could not open 'libcpmt.lib': no such file or directory [12/498] compile ../../src/base/unix_task_runner.cc ninja: build stopped: subcommand failed.
Actually, seems to compile much better under a "x64 Native Tools Command Prompt for VS 2019".
Do you happen to know how the build is picking up the VS lib path? I get this error-mid way through build
All the relevant logic is here: https://github.com/google/perfetto/blob/3c985b7832625923d479ff3b8fb404a6d474bb4a/gn/standalone/toolchain/win_find_msvc.py
Yeah right now some of the paths are hardcoded. You need both:
- Windows 10 SDK: no specific build, the script will pick the highest number
- The compiler, either Build Tools for VIsual Studio 2019 or MSVC 2019
- You can also use clang-cl.exe by setting
is_clang = truein the GN args. clang-cl is automatically downloaded bytools/install-build-deps. But it this still requires both the Win 10 SDK and MVCS/Build tools Because of some internal dependencies clang has (I don't recall the full details)
Actually, seems to compile much better under a "x64 Native Tools Command Prompt for VS 2019".
It should work without that environment. Maybe win_find_msvc.py is failing to locate something.
Sorry, dumb question while you are online - how do I build trace_processor as a .dll?
// Generates trace_processor_shell.exe and friends ninja -C out/IvanTraceProcessorWin trace_processor_shell
// Generates trace_processor.lib
ninja -C out/IvanTraceProcessorWin src\trace_processor ninja: Entering directory `out/IvanTraceProcessorWin' [1/1] link trace_processor.lib
gn args out/IvanTraceProcessorWin --list enable_perfetto_trace_processor Current value (from the default) = true From //gn/perfetto.gni:174
enable_perfetto_trace_processor_httpd Current value (from the default) = true From //gn/perfetto.gni:263
enable_perfetto_trace_processor_json Current value (from the default) = true From //gn/perfetto.gni:258
enable_perfetto_trace_processor_linenoise Current value (from the default) = false From //gn/perfetto.gni:252
enable_perfetto_trace_processor_percentile Current value (from the default) = true From //gn/perfetto.gni:248
enable_perfetto_trace_processor_sqlite Current value (from the default) = true From //gn/perfetto.gni:243
how do I build trace_processor as a .dll?
I don't think there is any support for that. I suppose the closest thing would be wrapping the //trace_processor:lib in a shared library. But it's more complicated than that because then we need:
-
to make sure that .dll linking works. There is no usage right now in the build files, so I don't expect it to JustWork but shouldn't be impossible to port
-
mark the API surface of trace_processor.h as dllexport, which would require a dedicated trace_processor_export.h which has something similar to perfetto/base/export.h (in turn it would require the -DTRACE_PROCESSOR_IMPLEMENTATION trick used elsewhere)
Maybe you can contrib with some patches while I sort out the rest and reland that CL
Aside from the dll issue, I supposed I am confused with even the exports right now. TraceProcessor and TraceProcessorStorage already are marked PERFETTO_EXPORT (used in many places).
If I am reading export.h correctly this should already come out to this on Windows builds: #define PERFETTO_EXPORT __declspec(dllexport)
However, it is clear that trace_processor_shell.exe doesn't have these exports (when queried with dumpbin /exports). It clearly can make them (they show up as exports) if I simply replace PERFETTO_EXPORT with __declspec(dllexport) in the TraceProcessor/TraceProcessorStorage.
So it seems the macro logic is not getting activated and probably this one? (#if defined(PERFETTO_IMPLEMENTATION)). Is this what you meant? If so I would like to know more about this trick and why exports are not on by default (they seem to be declared in many places). Also confused why we need a dedicated trace_processor_export.h when TraceProcessor/TraceProcessorStorage already reference export.h via PERFETTO_EXPORT.
Just been a little lost in the code today - stranger in a strange land :)
PERFETTO_EXPORT is only relevant when building as part of chrome in is_component_build=True (a mode where various chrome units get built as individual dll). In the standalone checkout, PERFETTO_EXPORT doesn't do anything, because PERFETTO_BUILDFLAG(PERFETTO_COMPONENT_BUILD) is never defined.
We need a similar mechanism, but only scoped to trace processor API, without PERFETTO_COMPONENT_BUILD.
So what we need here is something like:
- A trace_processor_export.h header, similar to base/export.h but only for the TP API surface.
- copy/paste that export.h make it work both for COMPONENT_BUILD and in the PERFETTO_STANDALONE_BUILD case
- update trace_processor.h
Note: we can't commit to make trace_processor.h a stable API surface. It didn't change much in the past but, just to be clar, we might occasionally break it so if you depend on that on some dll you'll have to catch up.
The other option is that you create a different DLL wrapper and maintain that if you want API stability.
Also potentially relevant for this discussion, we are instead opening a byte-oriented ABI (see r.android.com/1551613 and related CLs) which is based on protobuf. That will be more stable. So perhaps you could rely on that instead rather than doing some dll-based integration. It's based on protobuf over a byte pipe. At some point we should write also some c++ client.
Note: we can't commit to make trace_processor.h a stable API surface. It didn't change much in the past but, just to be clar, we might occasionally break it so if you depend on that on some dll you'll have to catch up.
The other option is that you create a different DLL wrapper and maintain that if you want API stability.
Hey @primiano. Good discussion. I don't think it's necessary to have a completely stable API surface in trace_processor. Its fine if it reasonably breaks from time. API/ABI makes sense in the context of protobuf or simply places where you shipped something and the consumer of the API doesn't/cant change. For tooling/service(s) it's normal for some reasonable API change(s) especially around major "versions". Assuming good versioning (of some kind) we can simply defer to take the latest on our timeline since we would "ship" with the version that is compatible.
We would prefer trace_processor as it exposes common trace processing and the SQL-like tables/queries that you guys have implemented and invested in.
We are still in the exploratory stage waiting on the Windows port to complete, but once it's available; we could work on this more. The goal would be a cross-platform C# .NET Core binary/code that relies on trace_processor. In this sense it would not be that different than Python support, but for C#.
We plan to OSS this code, and the C# wrapper/interop layer could live in the Perfetto code-base or another repo. If it lived in Perfetto it might make it slightly easier to version/update the wrapper/interop to coincide with any trace_processor.h and friend changes. Either way works.
We would plan on OSS the plugin for Microsoft-Performance-Toolkit-SDK likely where some existing plugins live at https://github.com/microsoft/Microsoft-Performance-Tools-Linux. This would mean folks could just use the C# basic wrapper or take advantage of any extra/post processing that we may do in a cross-platform way. Finally the plugin could be loaded into WPA UI as an analysis tool.