GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/ingestion/item_mem.cc
Date: 2026-10-11 02:40:02
Exec Total Coverage
Lines: 41 42 97.6%
Branches: 34 50 68.0%

Line Branch Exec Source
1 /**
2 * This file is part of the CernVM File System.
3 */
4
5 #include "item_mem.h"
6
7 #include <cassert>
8 #include <cstdlib>
9
10 #include "util/concurrency.h"
11 #include "util/exception.h"
12
13 std::atomic<int64_t> ItemAllocator::total_allocated_(0);
14
15
16 15977840 void ItemAllocator::Free(void *ptr) {
17 15977840 const MutexLockGuard guard(lock_);
18
19 15984665 MallocArena *M = MallocArena::GetMallocArena(ptr, kArenaSize);
20
1/2
✓ Branch 1 taken 15984665 times.
✗ Branch 2 not taken.
15984665 M->Free(ptr);
21 15984665 const unsigned N = malloc_arenas_.size();
22
6/6
✓ Branch 0 taken 4164974 times.
✓ Branch 1 taken 11819691 times.
✓ Branch 3 taken 133 times.
✓ Branch 4 taken 4164841 times.
✓ Branch 5 taken 133 times.
✓ Branch 6 taken 15984532 times.
15984665 if ((N > 1) && M->IsEmpty()) {
23
1/2
✓ Branch 0 taken 241 times.
✗ Branch 1 not taken.
241 for (unsigned i = 0; i < N; ++i) {
24
2/2
✓ Branch 1 taken 133 times.
✓ Branch 2 taken 108 times.
241 if (malloc_arenas_[i] == M) {
25
1/2
✓ Branch 1 taken 133 times.
✗ Branch 2 not taken.
133 delete malloc_arenas_[i];
26 total_allocated_.fetch_add(-static_cast<int>(kArenaSize));
27
1/2
✓ Branch 4 taken 133 times.
✗ Branch 5 not taken.
133 malloc_arenas_.erase(malloc_arenas_.begin() + i);
28 133 idx_last_arena_ = 0;
29 133 return;
30 }
31 }
32 ✗ PANIC(NULL);
33 }
34
2/2
✓ Branch 1 taken 15984187 times.
✓ Branch 2 taken 115 times.
15984665 }
35
36
37 1867 ItemAllocator::ItemAllocator() : idx_last_arena_(0) {
38 1867 const int retval = pthread_mutex_init(&lock_, NULL);
39
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1867 times.
1867 assert(retval == 0);
40
41
3/6
✓ Branch 1 taken 1867 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1867 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1867 times.
✗ Branch 8 not taken.
1867 malloc_arenas_.push_back(new MallocArena(kArenaSize));
42 total_allocated_.fetch_add(kArenaSize);
43 1867 }
44
45
46 1866 ItemAllocator::~ItemAllocator() {
47
2/2
✓ Branch 1 taken 1866 times.
✓ Branch 2 taken 1866 times.
3732 for (unsigned i = 0; i < malloc_arenas_.size(); ++i) {
48 total_allocated_.fetch_add(-static_cast<int>(kArenaSize));
49
1/2
✓ Branch 1 taken 1866 times.
✗ Branch 2 not taken.
1866 delete malloc_arenas_[i];
50 }
51 1866 pthread_mutex_destroy(&lock_);
52 1866 }
53
54
55 15968822 void *ItemAllocator::Malloc(unsigned size) {
56 15968822 const MutexLockGuard guard(lock_);
57
58
1/2
✓ Branch 2 taken 15984665 times.
✗ Branch 3 not taken.
15984665 void *p = malloc_arenas_[idx_last_arena_]->Malloc(size);
59
2/2
✓ Branch 0 taken 15984298 times.
✓ Branch 1 taken 367 times.
15984665 if (p != NULL)
60 15984298 return p;
61 367 const unsigned N = malloc_arenas_.size();
62
2/2
✓ Branch 0 taken 493 times.
✓ Branch 1 taken 133 times.
626 for (unsigned i = 0; i < N; ++i) {
63
1/2
✓ Branch 2 taken 493 times.
✗ Branch 3 not taken.
493 p = malloc_arenas_[i]->Malloc(size);
64
2/2
✓ Branch 0 taken 234 times.
✓ Branch 1 taken 259 times.
493 if (p != NULL) {
65 234 idx_last_arena_ = i;
66 234 return p;
67 }
68 }
69 133 idx_last_arena_ = N;
70
2/4
✓ Branch 1 taken 133 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 133 times.
✗ Branch 5 not taken.
133 MallocArena *M = new MallocArena(kArenaSize);
71 total_allocated_.fetch_add(kArenaSize);
72
1/2
✓ Branch 1 taken 133 times.
✗ Branch 2 not taken.
133 malloc_arenas_.push_back(M);
73
1/2
✓ Branch 1 taken 133 times.
✗ Branch 2 not taken.
133 p = M->Malloc(size);
74
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 133 times.
133 assert(p != NULL);
75 133 return p;
76 15984665 }
77
78