1 // Copyright 2009 Google Inc. All Rights Reserved.
2 // Author: fikes@google.com (Andrew Fikes)
4 #include "config_for_unittests.h"
7 #include "base/logging.h"
12 static void CheckStats(const tcmalloc::PageHeap
* ph
,
13 uint64_t system_pages
,
15 uint64_t unmapped_pages
) {
16 tcmalloc::PageHeap::Stats stats
= ph
->stats();
17 EXPECT_EQ(system_pages
, stats
.system_bytes
>> kPageShift
);
18 EXPECT_EQ(free_pages
, stats
.free_bytes
>> kPageShift
);
19 EXPECT_EQ(unmapped_pages
, stats
.unmapped_bytes
>> kPageShift
);
22 static void TestPageHeap_Stats() {
23 tcmalloc::PageHeap
* ph
= new tcmalloc::PageHeap();
26 CheckStats(ph
, 0, 0, 0);
28 // Allocate a span 's1'
29 tcmalloc::Span
* s1
= ph
->New(256);
30 CheckStats(ph
, 256, 0, 0);
32 // Split span 's1' into 's1', 's2'. Delete 's2'
33 tcmalloc::Span
* s2
= ph
->Split(s1
, 128);
34 Length s2_len
= s2
->length
;
36 CheckStats(ph
, 256, 128, 0);
38 // Unmap deleted span 's2'
39 EXPECT_EQ(s2_len
, ph
->ReleaseAtLeastNPages(1));
40 CheckStats(ph
, 256, 0, 128);
44 CheckStats(ph
, 256, 128, 128);
51 int main(int argc
, char **argv
) {