GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/ingestion/item_mem.cc
Date: 2026-03-08 02:37:57
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 23023917 void ItemAllocator::Free(void *ptr) {
17 23023917 const MutexLockGuard guard(lock_);
18
19 23087093 MallocArena *M = MallocArena::GetMallocArena(ptr, kArenaSize);
20
1/2
✓ Branch 1 taken 23087093 times.
✗ Branch 2 not taken.
23087093 M->Free(ptr);
21 23087093 const unsigned N = malloc_arenas_.size();
22
6/6
✓ Branch 0 taken 4500248 times.
✓ Branch 1 taken 18586845 times.
✓ Branch 3 taken 122 times.
✓ Branch 4 taken 4500126 times.
✓ Branch 5 taken 122 times.
✓ Branch 6 taken 23086971 times.
23087093 if ((N > 1) && M->IsEmpty()) {
23
1/2
✓ Branch 0 taken 178 times.
✗ Branch 1 not taken.
178 for (unsigned i = 0; i < N; ++i) {
24
2/2
✓ Branch 1 taken 122 times.
✓ Branch 2 taken 56 times.
178 if (malloc_arenas_[i] == M) {
25
1/2
✓ Branch 1 taken 122 times.
✗ Branch 2 not taken.
122 delete malloc_arenas_[i];
26 122 atomic_xadd64(&total_allocated_, -static_cast<int>(kArenaSize));
27
1/2
✓ Branch 4 taken 122 times.
✗ Branch 5 not taken.
122 malloc_arenas_.erase(malloc_arenas_.begin() + i);
28 122 idx_last_arena_ = 0;
29 122 return;
30 }
31 }
32 PANIC(NULL);
33 }
34
2/2
✓ Branch 1 taken 23071555 times.
✓ Branch 2 taken 1364 times.
23087093 }
35
36
37 1708 ItemAllocator::ItemAllocator() : idx_last_arena_(0) {
38 1708 const int retval = pthread_mutex_init(&lock_, NULL);
39
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1708 times.
1708 assert(retval == 0);
40
41
3/6
✓ Branch 1 taken 1708 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1708 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1708 times.
✗ Branch 8 not taken.
1708 malloc_arenas_.push_back(new MallocArena(kArenaSize));
42 1708 atomic_xadd64(&total_allocated_, kArenaSize);
43 1708 }
44
45
46 1707 ItemAllocator::~ItemAllocator() {
47
2/2
✓ Branch 1 taken 1707 times.
✓ Branch 2 taken 1707 times.
3414 for (unsigned i = 0; i < malloc_arenas_.size(); ++i) {
48 1707 atomic_xadd64(&total_allocated_, -static_cast<int>(kArenaSize));
49
1/2
✓ Branch 1 taken 1707 times.
✗ Branch 2 not taken.
1707 delete malloc_arenas_[i];
50 }
51 1707 pthread_mutex_destroy(&lock_);
52 1707 }
53
54
55 22992305 void *ItemAllocator::Malloc(unsigned size) {
56 22992305 const MutexLockGuard guard(lock_);
57
58
1/2
✓ Branch 2 taken 23087093 times.
✗ Branch 3 not taken.
23087093 void *p = malloc_arenas_[idx_last_arena_]->Malloc(size);
59
2/2
✓ Branch 0 taken 23086859 times.
✓ Branch 1 taken 234 times.
23087093 if (p != NULL)
60 23086859 return p;
61 234 const unsigned N = malloc_arenas_.size();
62
2/2
✓ Branch 0 taken 290 times.
✓ Branch 1 taken 122 times.
412 for (unsigned i = 0; i < N; ++i) {
63
1/2
✓ Branch 2 taken 290 times.
✗ Branch 3 not taken.
290 p = malloc_arenas_[i]->Malloc(size);
64
2/2
✓ Branch 0 taken 112 times.
✓ Branch 1 taken 178 times.
290 if (p != NULL) {
65 112 idx_last_arena_ = i;
66 112 return p;
67 }
68 }
69 122 idx_last_arena_ = N;
70
2/4
✓ Branch 1 taken 122 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 122 times.
✗ Branch 5 not taken.
122 MallocArena *M = new MallocArena(kArenaSize);
71 122 atomic_xadd64(&total_allocated_, kArenaSize);
72
1/2
✓ Branch 1 taken 122 times.
✗ Branch 2 not taken.
122 malloc_arenas_.push_back(M);
73
1/2
✓ Branch 1 taken 122 times.
✗ Branch 2 not taken.
122 p = M->Malloc(size);
74
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 122 times.
122 assert(p != NULL);
75 122 return p;
76 23087093 }
77