Commit Graph

99 Commits

Author SHA1 Message Date
Aliaksey Kandratsenka 9dfab2cdce cmake: refactor CMakeLists.txt
It is still somewhat broken and somewhat of a mess, but it is much
lesser mess now.

As part of this change I also amputated a number of unnecessary or too
complicated bits. Like attempt to build both static and shared
versions of tcmalloc libraries at the same time. We stick to cmake's
"common" (seemingly) behavior of defaulting to something (in our case
shared library) and letting users override BUILD_SHARED_LIBS.

All the "install" bits are amputated as well, they're not ready.
2024-02-27 17:00:35 -05:00
Aliaksey Kandratsenka 2940450c7a gtestify profiledata_unittest 2024-02-27 16:50:07 -05:00
Aliaksey Kandratsenka bbae941492 gtestify profile-handler_unittest 2024-02-27 16:50:07 -05:00
Aliaksey Kandratsenka a4d9540d8b unbreak cmake for packed-cache_test 2024-02-27 16:50:07 -05:00
Aliaksey Kandratsenka f8da159013 add function_ref_test 2024-02-21 21:57:37 -05:00
Aliaksey Kandratsenka bfbfa333eb add cleanup_test
This also let us spot and fix missing include in the header.
2024-02-21 21:37:47 -05:00
Aliaksey Kandratsenka 0906dacc48 gtestify more tests
Those are malloc_hook_test, mmap_hook_test, page_heap_test,
sampler_test, stack_trace_table_test.
2024-02-20 14:34:28 -05:00
Aliaksey Kandratsenka bfa30bf7df gtestify 3 simpler tests
Those are packed-cache_test, pagemap_unittest, safe_strerror_test
2024-02-20 14:34:23 -05:00
Aliaksey Kandratsenka ff2dce5e67 gtestify addressmap_unittest 2024-02-20 14:34:23 -05:00
Aliaksey Kandratsenka c1799405ae gtestify check_address_test 2024-02-20 14:34:23 -05:00
Aliaksey Kandratsenka a46a391b14 gtestify low_level_alloc_unittest 2024-02-20 14:34:20 -05:00
Aliaksey Kandratsenka 6c24a59682 introduce vendor copy of googletest 2024-02-20 14:30:24 -05:00
Aliaksey Kandratsenka c52c321bdd replace raw printer with usage of generic writer facility 2024-02-07 15:46:54 -05:00
Aliaksey Kandratsenka 771a01ed28 rework and simplify emergency malloc integration
We now wrap StackTraceScope thingy in tcmalloc-specific parts, instead
of automagically inside every stacktrace.cc function. TCMalloc bits
all need to grab stacktraces via newly introduced
tcmalloc::GrabBacktrace (which handles emergency malloc wrapping).

New approach eliminates the need for doing fake stacktrace scope. CPU
profiler, being distinct .so library couldn't take advantage of
emergency malloc anyways.

This simplifies the build further and eliminates another potential
point of runtime divergence when stacktrace is linked to both
libprofiler and libtcmalloc.
2024-02-05 14:27:02 -05:00
Aliaksey Kandratsenka 1331c0e0d1 drop long deprecated google/ headers 2024-02-04 21:54:46 -05:00
Aliaksey Kandratsenka 2e5ecb4de6 amputate src/base/simple_mutex.h
Use standard mutex instead
2024-02-04 16:38:21 -05:00
Aliaksey Kandratsenka 6691226953 split and rewrite TLS access for thread caches
Logic was removed from thread_cache.{h,cc} into
thread_cache_ptr.{h,cc}.

Separation will help possible future evolution, and we already changed
the logic quite a bit:

* early access (when TLS isn't initialized yet) now uses global
ThreadCache instance. We therefore have ThreadCachePtr instances
managing required locking. This eliminates unnecessary complication of
PTHREADS_CRASHES_IF_RUN_TOO_EARLY logic, and any other danger of
touching TLS too early. BTW previous implementation actually leaked
initial early-initialized ThreadCache instance(!)

* old configure-time HAVE_TLS logic is amputated. Config-time part of
it made little sense as C++ 17 guarantees availability of
thread_local, but we have manually curated deny-list of "bad" OSes,
that we tested (via compile checks!) at configure time. Now this
is all compile time. There is now compile-time kHaveGoodTLS variable
and we're using it mostly via if constexpr.

* kHaveGoodTLS case of creating thread cache is simplified and made
more straightforward (no need to have in_setspecific logic).

* !kHaveGoodTLS case if fixed and improved too. We avoid
std:🧵:get_id, as it deadlocks on mingw. We use errno address as
a portable and (usually) async-signal safe 'my thread' identifier. We
also eliminate linear searching of thread's cache and replace it with
straightforward hash table lookup.
2024-02-03 15:57:14 -05:00
Aliaksey Kandratsenka 51d3340b39 avoid -Wunused-results warnings from read/write
glibc with _FORTIFY_SOURCE sets those up to give warnings on unused
results. We used to disable this warning globally, but lets do better.
2024-01-30 17:08:29 -05:00
Aliaksey Kandratsenka 82a36a6fcd bump required c++ standard to c++-17 2024-01-30 15:54:24 -05:00
Aliaksey Kandratsenka 5db2adc4e7 drop stale workaround for ancient solaris issue 2024-01-29 21:02:17 -05:00
Aliaksey Kandratsenka 5ce342e1c8 fix generic_writer_test and proc_maps_iterator_test on cmake+msvc 2024-01-29 21:02:17 -05:00
Aliaksey Kandratsenka a3080fa8d6 extract proc-maps iteration into own file and cover it by tests
This allows us, later, to avoid building this stuff in configurations
that don't use it. I have also reduced API and ABI surface to enable
further refactorings.
2024-01-29 21:02:17 -05:00
lennoxho 9a6848de8a A number of cleanups
* Remove build dependency on HAVE_PTHREAD
* Remove build dependency on HAVE_STD_ALIGNED_VAL_T and ENABLE_ALIGNED_NEW_DELETE
* Remove redundant tcmalloc.h files & ensure there are no cross-build-tool references
* Adopt automake commit 26927d1 in the CMake build
2024-01-29 17:15:53 -08:00
lennoxho 96f34120fe Several build fixes and cleanups
- Fix CMake builds for MinGW and MSVC
- Ensure the Autotools, CMake and VSProj builds do not reference each others' config.h
- Use std:🧵:id instead of our own thread ID wrappers
- Moved explicit TLS wrapper functions into the tcmalloc:: namespace and change their visibility to hidden
Resolves #1486
2024-01-26 16:56:17 -05:00
Aliaksey Kandratsenka 79b6ad2ab5 amputate HAVE_FORK checking
Pretty much everything has fork, except windows. Which is much simpler
to test at compile time, then duplicating and complicating the test at
configure time.
2024-01-25 16:10:30 -05:00
lennoxho 5cab8f3f77 Convert MinGW builds to always use WinAPI based threading facilities. See ##1483 2024-01-24 21:47:06 -05:00
Aliaksey Kandratsenka 24774ebb38 introduce generic_writer facility 2024-01-24 17:30:18 -05:00
Aliaksey Kandratsenka 365060c421 bump version to 2.15 2024-01-05 12:23:30 -05:00
Aliaksey Kandratsenka d5c1edf4f5 [cmake] explicitly link more libraries for threading
See discussion on https://github.com/gperftools/gperftools/pull/1473
2024-01-03 16:07:16 -05:00
Aliaksey Kandratsenka e49b36f7d6 bump version to 2.14 2023-12-31 23:17:03 -05:00
Mateusz Jakub Fila bbc03edc4d added missing aggressive decommit option in cmake 2023-12-27 01:58:46 +01:00
Mateusz Jakub Fila 9c2028ae50 added missing large alloc report option in cmake 2023-12-27 01:58:34 +01:00
Mateusz Jakub Fila eeb25dd2a5 added missing finding asm/ptrace.h in cmake 2023-12-27 01:58:25 +01:00
Mateusz Jakub Fila 4e9fd729d2 added missing finding `HAVE___ATTRIBUTE__ALIGNED_FN` in cmake 2023-12-27 01:58:11 +01:00
Mateusz Jakub Fila ad4a6ff8de added missing gcc unwinder preference option in cmake 2023-12-27 01:57:46 +01:00
Mateusz Jakub Fila 8987d08f79 fixed setting pagesize and pageshift in cmake 2023-12-24 01:51:00 +01:00
Mateusz Jakub Fila b8e75ae6fe Add mallinfo2 function 2023-12-07 14:10:51 +01:00
Aliaksey Kandratsenka a9b734e3fa perform ucontext->pc variants testing in compile-time
As part of cpu profiler we're extracting current PC (program counter)
of out signal's ucontext. Different OS and hardware combinations have
different ways for that. We had a list of variants that we tested at
compile time and populated PC_FROM_UCONTEXT macro into config.h. It
caused duplication and occasional mismatches between our autoconf and
cmake bits.

So this commit changes testing to be compile-time. We remove
complexity from build system and add some to C++ source.

We use SFINAE to find which of those variants compile (and we silently
assume that 'compiles' implies 'works'; this is what config-time
testing did too). Occasionally we'll face situations where several
variants compile. And we couldn't handle this case in pure C++. So we
have a small Ruby program that generates chain of inheritance among
SFINAE-specialized class templates. This handles prioritization among
variants.

List of ucontext->pc extraction variants is mostly same. We dropped
super-obsolete (circa Linux kernel 2.0) arm variant. And NetBSD case
is now improved. We now use their nice architecture-independent macro
instead of x86-specific access.
2023-12-02 18:58:45 -05:00
Sergey Fedorov c815c760da CMakeLists.txt: disable libunwind for ppc 2023-11-25 15:58:24 +08:00
Aliaksey Kandratsenka 4d1a9e9226 stacktrace_unittest: test all stacktrace capturing methods 2023-10-27 19:06:15 -04:00
Aliaksey Kandratsenka 4dc313870c add cmake warning that our support is incomplete 2023-10-27 19:00:17 -04:00
Lennox Ho 64d64bee40 Fix C++ aligned allocation detected in the CMake build 2023-09-22 13:00:25 -04:00
Lennox Ho 589d416977 Add a more performant SpinLockDelay implementation for Windows based on WaitOnAddress and friends 2023-09-19 14:53:16 +08:00
Lennox Ho fd0fabe183 Fix Windows CMake build by linking page_heap_test and mmap_hook_test to the entire library 2023-09-19 14:47:46 +08:00
Lennox Ho d3602c0672 Account for Windows while performing implicit TLS detection in CMakeLists.txt 2023-09-17 07:49:38 +08:00
Aliaksey Kandratsenka dffb4a2f28 bump version to 2.13 2023-09-11 16:23:40 -04:00
Aliaksey Kandratsenka 2748dd5680 unbreak address access "probing" for generic_fp backtracing
We used msync to verify that address is readable. But msync gives
false positives for PROT_NONE mappings. And we recently got bug report
from user hitting this exact condition.

For correct access check, we steal idea from Abseil and do sigprocmask
with address used as new signal mask and with invalid HOW
argument. This works in today's Linux kernels and is among fastest
methods available. But is brittle w.r.t. possible kernel changes. So
we supply fallback method that does 2 syscalls.

For non-Linux systems we implement usual "write to pipe" trick. Which
also has decent performance, but requires occasional pipe draining and
uses fds which could occasionally be damaged by some forking codes.

We also finally cover all new code with unit test.

Fixes github issue #1426
2023-09-10 17:24:32 -04:00
Aliaksey Kandratsenka 539ed9ca40 bump version 2.12 2023-08-24 15:03:47 -04:00
Aliaksey Kandratsenka 0a3ca5b43d bump version to 2.11 2023-08-14 22:47:56 -04:00
Aliaksey Kandratsenka 51c5e2bec7 massage latest GetUniquePathFromEnv changes
This fixes a number of minor bits (like build details) as well as
making overall code style similar to what we're doing elsewhere.
2023-08-09 16:29:13 -04:00