Austin Schuh | 745610d | 2015-09-06 18:19:50 -0700 | [diff] [blame] | 1 | --- COMPILING
|
| 2 |
|
| 3 | This project has begun being ported to Windows, only tcmalloc_minimal
|
| 4 | is supported at this time. A working solution file exists in this
|
| 5 | directory:
|
| 6 | gperftools.sln
|
| 7 |
|
| 8 | You can load this solution file into VC++ 7.1 (Visual Studio 2003) or
|
| 9 | later -- in the latter case, it will automatically convert the files
|
| 10 | to the latest format for you.
|
| 11 |
|
| 12 | When you build the solution, it will create a number of unittests,
|
| 13 | which you can run by hand (or, more easily, under the Visual Studio
|
| 14 | debugger) to make sure everything is working properly on your system.
|
| 15 | The binaries will end up in a directory called "debug" or "release" in
|
| 16 | the top-level directory (next to the .sln file). It will also create
|
| 17 | two binaries, nm-pdb and addr2line-pdb, which you should install in
|
| 18 | the same directory you install the 'pprof' perl script.
|
| 19 |
|
| 20 | I don't know very much about how to install DLLs on Windows, so you'll
|
| 21 | have to figure out that part for yourself. If you choose to just
|
| 22 | re-use the existing .sln, make sure you set the IncludeDir's
|
| 23 | appropriately! Look at the properties for libtcmalloc_minimal.dll.
|
| 24 |
|
| 25 | Note that these systems are set to build in Debug mode by default.
|
| 26 | You may want to change them to Release mode.
|
| 27 |
|
| 28 | To use tcmalloc_minimal in your own projects, you should only need to
|
| 29 | build the dll and install it someplace, so you can link it into
|
| 30 | further binaries. To use the dll, you need to add the following to
|
| 31 | the linker line of your executable:
|
| 32 | "libtcmalloc_minimal.lib" /INCLUDE:"__tcmalloc"
|
| 33 |
|
| 34 | Here is how to accomplish this in Visual Studio 2005 (VC8):
|
| 35 |
|
| 36 | 1) Have your executable depend on the tcmalloc library by selecting
|
| 37 | "Project Dependencies..." from the "Project" menu. Your executable
|
| 38 | should depend on "libtcmalloc_minimal".
|
| 39 |
|
| 40 | 2) Have your executable depend on a tcmalloc symbol -- this is
|
| 41 | necessary so the linker doesn't "optimize out" the libtcmalloc
|
| 42 | dependency -- by right-clicking on your executable's project (in
|
| 43 | the solution explorer), selecting Properties from the pull-down
|
| 44 | menu, then selecting "Configuration Properties" -> "Linker" ->
|
| 45 | "Input". Then, in the "Force Symbol References" field, enter the
|
| 46 | text "__tcmalloc" (without the quotes). Be sure to do this for both
|
| 47 | debug and release modes!
|
| 48 |
|
| 49 | You can also link tcmalloc code in statically -- see the example
|
| 50 | project tcmalloc_minimal_unittest-static, which does this. For this
|
| 51 | to work, you'll need to add "/D PERFTOOLS_DLL_DECL=" to the compile
|
| 52 | line of every perftools .cc file. You do not need to depend on the
|
| 53 | tcmalloc symbol in this case (that is, you don't need to do either
|
| 54 | step 1 or step 2 from above).
|
| 55 |
|
| 56 | An alternative to all the above is to statically link your application
|
| 57 | with libc, and then replace its malloc with tcmalloc. This allows you
|
| 58 | to just build and link your program normally; the tcmalloc support
|
| 59 | comes in a post-processing step. This is more reliable than the above
|
| 60 | technique (which depends on run-time patching, which is inherently
|
| 61 | fragile), though more work to set up. For details, see
|
| 62 | https://groups.google.com/group/google-perftools/browse_thread/thread/41cd3710af85e57b
|
| 63 |
|
| 64 |
|
| 65 | --- THE HEAP-PROFILER
|
| 66 |
|
| 67 | The heap-profiler has had a preliminary port to Windows but does not
|
| 68 | build on Windows by default. It has not been well tested, and
|
| 69 | probably does not work at all when Frame Pointer Optimization (FPO) is
|
| 70 | enabled -- that is, in release mode. The other features of perftools,
|
| 71 | such as the cpu-profiler and leak-checker, have not yet been ported to
|
| 72 | Windows at all.
|
| 73 |
|
| 74 |
|
| 75 | --- WIN64
|
| 76 |
|
| 77 | The function-patcher has to disassemble code, and is very
|
| 78 | x86-specific. However, the rest of perftools should work fine for
|
| 79 | both x86 and x64. In particular, if you use the 'statically link with
|
| 80 | libc, and replace its malloc with tcmalloc' approach, mentioned above,
|
| 81 | it should be possible to use tcmalloc with 64-bit windows.
|
| 82 |
|
| 83 | As of perftools 1.10, there is some support for disassembling x86_64
|
| 84 | instructions, for work with win64. This work is preliminary, but the
|
| 85 | test file preamble_patcher_test.cc is provided to play around with
|
| 86 | that a bit. preamble_patcher_test will not compile on win32.
|
| 87 |
|
| 88 |
|
| 89 | --- ISSUES
|
| 90 |
|
| 91 | NOTE FOR WIN2K USERS: According to reports
|
| 92 | (http://code.google.com/p/gperftools/issues/detail?id=127)
|
| 93 | the stack-tracing necessary for the heap-profiler does not work on
|
| 94 | Win2K. The best workaround is, if you are building on a Win2k system
|
| 95 | is to add "/D NO_TCMALLOC_SAMPLES=" to your build, to turn off the
|
| 96 | stack-tracing. You will not be able to use the heap-profiler if you
|
| 97 | do this.
|
| 98 |
|
| 99 | NOTE ON _MSIZE and _RECALLOC: The tcmalloc version of _msize returns
|
| 100 | the size of the region tcmalloc allocated for you -- which is at least
|
| 101 | as many bytes you asked for, but may be more. (btw, these *are* bytes
|
| 102 | you own, even if you didn't ask for all of them, so it's correct code
|
| 103 | to access all of them if you want.) Unfortunately, the Windows CRT
|
| 104 | _recalloc() routine assumes that _msize returns exactly as many bytes
|
| 105 | as were requested. As a result, _recalloc() may not zero out new
|
| 106 | bytes correctly. IT'S SAFEST NOT TO USE _RECALLOC WITH TCMALLOC.
|
| 107 | _recalloc() is a tricky routine to use in any case (it's not safe to
|
| 108 | use with realloc, for instance).
|
| 109 |
|
| 110 |
|
| 111 | I have little experience with Windows programming, so there may be
|
| 112 | better ways to set this up than I've done! If you run across any
|
| 113 | problems, please post to the google-perftools Google Group, or report
|
| 114 | them on the gperftools Google Code site:
|
| 115 | http://groups.google.com/group/google-perftools
|
| 116 | http://code.google.com/p/gperftools/issues/list
|
| 117 |
|
| 118 | -- craig
|
| 119 |
|
| 120 | Last modified: 2 February 2012
|