Remove hooksApi global; reduce coupling with MemoryTracker 10/68210/6
authorDave Rigby <daver@couchbase.com>
Fri, 12 Aug 2016 13:45:20 +0000 (14:45 +0100)
committerDave Rigby <daver@couchbase.com>
Tue, 11 Oct 2016 08:02:38 +0000 (08:02 +0000)
commitd02d8c21ec96efb5f133f99807671b0f228a2a9e
tree9ac234a518dbc7bfc82204110f2ce3b5ceece269
parent3fb0f02cbed9a7ea90af8b59efcf0983794efd2a
Remove hooksApi global; reduce coupling with MemoryTracker

MemoryTracker is somewhat tightly coupled with ep_engine.cc as it uses
the getHooksApi() function to obtain the memory allocator hooks.

Firstly this makes it hard to test - compile one file and you have to
include the other, and it's also difficult to provide a different
hooks api - either for injecting a mock one for testing, or simply to
use the 'normal' hooks API but without pulling in ep-engine.

Secondly, there is unnecessary indirection in NewHook / DeleteHook -
which are called on every new/delete so performance is relevant
there. By giving the MemoryTracker it's own copy of the alloc_hooks
(instead of calling getHooksApi() on every call) we can reduce the
amount of work in NewHook / DeleteHook by approx. 50% (measured in
terms of x64 instructions).

Change-Id: Ia0f8ebb0a5263567dc08b32fe6ff9b7ea9eefa92
Reviewed-on: http://review.couchbase.org/68210
Reviewed-by: Daniel Owen <owend@couchbase.com>
Tested-by: buildbot <build@couchbase.com>
CMakeLists.txt
src/ep_engine.cc
src/memory_tracker.cc
src/memory_tracker.h
src/utility.h
tests/module_tests/defragmenter_test.cc
tests/module_tests/memory_tracker_test.cc
tests/module_tests/mock_hooks_api.cc
tests/module_tests/mock_hooks_api.h [new file with mode: 0644]