GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/ingestion/item_mem.cc
Date: 2026-05-03 02:36:16
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 11222507 void ItemAllocator::Free(void *ptr) {
17 11222507 const MutexLockGuard guard(lock_);
18
19 11255967 MallocArena *M = MallocArena::GetMallocArena(ptr, kArenaSize);
20
1/2
✓ Branch 1 taken 11255967 times.
✗ Branch 2 not taken.
11255967 M->Free(ptr);
21 11255967 const unsigned N = malloc_arenas_.size();
22
6/6
✓ Branch 0 taken 1834308 times.
✓ Branch 1 taken 9421659 times.
✓ Branch 3 taken 56 times.
✓ Branch 4 taken 1834252 times.
✓ Branch 5 taken 56 times.
✓ Branch 6 taken 11255911 times.
11255967 if ((N > 1) && M->IsEmpty()) {
23
1/2
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
84 for (unsigned i = 0; i < N; ++i) {
24
2/2
✓ Branch 1 taken 56 times.
✓ Branch 2 taken 28 times.
84 if (malloc_arenas_[i] == M) {
25
1/2
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
56 delete malloc_arenas_[i];
26 56 atomic_xadd64(&total_allocated_, -static_cast<int>(kArenaSize));
27
1/2
✓ Branch 4 taken 56 times.
✗ Branch 5 not taken.
56 malloc_arenas_.erase(malloc_arenas_.begin() + i);
28 56 idx_last_arena_ = 0;
29 56 return;
30 }
31 }
32 PANIC(NULL);
33 }
34
2/2
✓ Branch 1 taken 11247217 times.
✓ Branch 2 taken 560 times.
11255967 }
35
36
37 1468 ItemAllocator::ItemAllocator() : idx_last_arena_(0) {
38 1468 const int retval = pthread_mutex_init(&lock_, NULL);
39
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1468 times.
1468 assert(retval == 0);
40
41
3/6
✓ Branch 1 taken 1468 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1468 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1468 times.
✗ Branch 8 not taken.
1468 malloc_arenas_.push_back(new MallocArena(kArenaSize));
42 1468 atomic_xadd64(&total_allocated_, kArenaSize);
43 1468 }
44
45
46 1467 ItemAllocator::~ItemAllocator() {
47
2/2
✓ Branch 1 taken 1467 times.
✓ Branch 2 taken 1467 times.
2934 for (unsigned i = 0; i < malloc_arenas_.size(); ++i) {
48 1467 atomic_xadd64(&total_allocated_, -static_cast<int>(kArenaSize));
49
1/2
✓ Branch 1 taken 1467 times.
✗ Branch 2 not taken.
1467 delete malloc_arenas_[i];
50 }
51 1467 pthread_mutex_destroy(&lock_);
52 1467 }
53
54
55 11200093 void *ItemAllocator::Malloc(unsigned size) {
56 11200093 const MutexLockGuard guard(lock_);
57
58
1/2
✓ Branch 2 taken 11255967 times.
✗ Branch 3 not taken.
11255967 void *p = malloc_arenas_[idx_last_arena_]->Malloc(size);
59
2/2
✓ Branch 0 taken 11255897 times.
✓ Branch 1 taken 70 times.
11255967 if (p != NULL)
60 11255897 return p;
61 70 const unsigned N = malloc_arenas_.size();
62
2/2
✓ Branch 0 taken 84 times.
✓ Branch 1 taken 56 times.
140 for (unsigned i = 0; i < N; ++i) {
63
1/2
✓ Branch 2 taken 84 times.
✗ Branch 3 not taken.
84 p = malloc_arenas_[i]->Malloc(size);
64
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 70 times.
84 if (p != NULL) {
65 14 idx_last_arena_ = i;
66 14 return p;
67 }
68 }
69 56 idx_last_arena_ = N;
70
2/4
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 56 times.
✗ Branch 5 not taken.
56 MallocArena *M = new MallocArena(kArenaSize);
71 56 atomic_xadd64(&total_allocated_, kArenaSize);
72
1/2
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
56 malloc_arenas_.push_back(M);
73
1/2
✓ Branch 1 taken 56 times.
✗ Branch 2 not taken.
56 p = M->Malloc(size);
74
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
56 assert(p != NULL);
75 56 return p;
76 11255967 }
77