GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/ingestion/item_mem.cc
Date: 2025-07-27 02:42:09
Exec Total Coverage
Lines: 45 46 97.8%
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 atomic_int64 ItemAllocator::total_allocated_ = 0;
14
15
16 12023561 void ItemAllocator::Free(void *ptr) {
17 12023561 const MutexLockGuard guard(lock_);
18
19 12060754 MallocArena *M = MallocArena::GetMallocArena(ptr, kArenaSize);
20
1/2
✓ Branch 1 taken 12060754 times.
✗ Branch 2 not taken.
12060754 M->Free(ptr);
21 12060754 const unsigned N = malloc_arenas_.size();
22
6/6
✓ Branch 0 taken 2290804 times.
✓ Branch 1 taken 9769950 times.
✓ Branch 3 taken 49 times.
✓ Branch 4 taken 2290755 times.
✓ Branch 5 taken 49 times.
✓ Branch 6 taken 12060705 times.
12060754 if ((N > 1) && M->IsEmpty()) {
23
1/2
✓ Branch 0 taken 81 times.
✗ Branch 1 not taken.
81 for (unsigned i = 0; i < N; ++i) {
24
2/2
✓ Branch 1 taken 49 times.
✓ Branch 2 taken 32 times.
81 if (malloc_arenas_[i] == M) {
25
1/2
✓ Branch 1 taken 49 times.
✗ Branch 2 not taken.
49 delete malloc_arenas_[i];
26 49 atomic_xadd64(&total_allocated_, -static_cast<int>(kArenaSize));
27
1/2
✓ Branch 4 taken 49 times.
✗ Branch 5 not taken.
49 malloc_arenas_.erase(malloc_arenas_.begin() + i);
28 49 idx_last_arena_ = 0;
29 49 return;
30 }
31 }
32 PANIC(NULL);
33 }
34
2/2
✓ Branch 1 taken 12050107 times.
✓ Branch 2 taken 33 times.
12060754 }
35
36
37 964 ItemAllocator::ItemAllocator() : idx_last_arena_(0) {
38 964 const int retval = pthread_mutex_init(&lock_, NULL);
39
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 964 times.
964 assert(retval == 0);
40
41
3/6
✓ Branch 1 taken 964 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 964 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 964 times.
✗ Branch 8 not taken.
964 malloc_arenas_.push_back(new MallocArena(kArenaSize));
42 964 atomic_xadd64(&total_allocated_, kArenaSize);
43 964 }
44
45
46 963 ItemAllocator::~ItemAllocator() {
47
2/2
✓ Branch 1 taken 963 times.
✓ Branch 2 taken 963 times.
1926 for (unsigned i = 0; i < malloc_arenas_.size(); ++i) {
48 963 atomic_xadd64(&total_allocated_, -static_cast<int>(kArenaSize));
49
1/2
✓ Branch 1 taken 963 times.
✗ Branch 2 not taken.
963 delete malloc_arenas_[i];
50 }
51 963 pthread_mutex_destroy(&lock_);
52 963 }
53
54
55 11998201 void *ItemAllocator::Malloc(unsigned size) {
56 11998201 const MutexLockGuard guard(lock_);
57
58
1/2
✓ Branch 2 taken 12060754 times.
✗ Branch 3 not taken.
12060754 void *p = malloc_arenas_[idx_last_arena_]->Malloc(size);
59
2/2
✓ Branch 0 taken 12060657 times.
✓ Branch 1 taken 97 times.
12060754 if (p != NULL)
60 12060657 return p;
61 97 const unsigned N = malloc_arenas_.size();
62
2/2
✓ Branch 0 taken 129 times.
✓ Branch 1 taken 49 times.
178 for (unsigned i = 0; i < N; ++i) {
63
1/2
✓ Branch 2 taken 129 times.
✗ Branch 3 not taken.
129 p = malloc_arenas_[i]->Malloc(size);
64
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 81 times.
129 if (p != NULL) {
65 48 idx_last_arena_ = i;
66 48 return p;
67 }
68 }
69 49 idx_last_arena_ = N;
70
2/4
✓ Branch 1 taken 49 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 49 times.
✗ Branch 5 not taken.
49 MallocArena *M = new MallocArena(kArenaSize);
71 49 atomic_xadd64(&total_allocated_, kArenaSize);
72
1/2
✓ Branch 1 taken 49 times.
✗ Branch 2 not taken.
49 malloc_arenas_.push_back(M);
73
1/2
✓ Branch 1 taken 49 times.
✗ Branch 2 not taken.
49 p = M->Malloc(size);
74
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 49 times.
49 assert(p != NULL);
75 49 return p;
76 12060754 }
77