Skip to content

Commit 64551b3

Browse files
1a1a11aCopilot
andauthored
[refactor]: simplify logging (#223)
* refactor logging Refactor logging levels by removing VVERBOSE and adjusting log level definitions. Update logging calls throughout the codebase to use VERBOSE instead of VVERBOSE for consistency and clarity. * allow code-quality to run on other branches (#222) * Refactor CMakeLists.txt to improve logging level handling Updated the logic for setting default log levels based on the build type. Removed redundant checks and streamlined the configuration for log levels, ensuring appropriate defaults are set for both Debug and Release builds. This enhances clarity and maintainability of the build configuration. * fix format and cmake default level * Update libCacheSim/traceReader/sampling/SHARD.c Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update CMakeLists.txt Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix * letter case normalize for build --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 61486d6 commit 64551b3

File tree

16 files changed

+66
-107
lines changed

16 files changed

+66
-107
lines changed

.github/workflows/code-quality.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
name: Code Quality
22

3-
on:
4-
push:
5-
branches: [ main, master, develop ]
6-
pull_request:
7-
branches: [ main, master, develop ]
3+
on: [push, pull_request]
84

95
jobs:
106
code-quality:

CMakeLists.txt

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ option(SUPPORT_TTL "whether support TTL" OFF)
2525
option(OPT_SUPPORT_ZSTD_TRACE "whether support zstd trace" ON)
2626
option(ENABLE_LRB "enable LRB" OFF)
2727
option(ENABLE_3L_CACHE "enable 3LCache" OFF)
28-
set(LOG_LEVEL NONE CACHE STRING "change the logging level")
29-
set_property(CACHE LOG_LEVEL PROPERTY STRINGS INFO WARN ERROR DEBUG VERBOSE VVERBOSE VVVERBOSE)
28+
set(LOG_LEVEL "default" CACHE STRING "change the logging level")
29+
set_property(CACHE LOG_LEVEL PROPERTY STRINGS ERROR WARN INFO DEBUG VERBOSE DEFAULT)
3030

3131
# Platform detection
3232
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
@@ -41,20 +41,6 @@ else()
4141
message(FATAL_ERROR "unsupported operating system ${CMAKE_SYSTEM_NAME}")
4242
endif()
4343

44-
if(NOT CMAKE_BUILD_TYPE)
45-
set(CMAKE_BUILD_TYPE Release)
46-
47-
if(LOG_LEVEL STREQUAL "NONE")
48-
set(LOG_LEVEL INFO)
49-
endif()
50-
elseif(${CMAKE_BUILD_TYPE} MATCHES "Debug")
51-
if(LOG_LEVEL STREQUAL "NONE")
52-
set(LOG_LEVEL DEBUG)
53-
endif()
54-
else()
55-
set(LOG_LEVEL INFO)
56-
endif()
57-
5844
configure_file(libCacheSim/include/config.h.in libCacheSim/include/config.h)
5945

6046
if(SUPPORT_TTL)
@@ -65,12 +51,23 @@ if(USE_HUGEPAGE)
6551
add_compile_definitions(USE_HUGEPAGE=1)
6652
endif()
6753

54+
if(NOT CMAKE_BUILD_TYPE)
55+
# we can also consider RelWithDebInfo, but it will be too slow for release build
56+
set(CMAKE_BUILD_TYPE Release)
57+
endif()
58+
59+
6860
string(TOLOWER "${LOG_LEVEL}" LOG_LEVEL_LOWER)
61+
string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER)
6962

70-
if(LOG_LEVEL_LOWER STREQUAL "vvverbose")
71-
add_compile_definitions(LOGLEVEL=3)
72-
elseif(LOG_LEVEL_LOWER STREQUAL "vverbose")
73-
add_compile_definitions(LOGLEVEL=4)
63+
if(LOG_LEVEL_LOWER STREQUAL "default")
64+
if(CMAKE_BUILD_TYPE_LOWER MATCHES "Debug")
65+
message(STATUS "LOG_LEVEL is not set, use DEBUG as default for debug build")
66+
add_compile_definitions(LOGLEVEL=6)
67+
else()
68+
message(STATUS "LOG_LEVEL is not set, use INFO as default for release build")
69+
add_compile_definitions(LOGLEVEL=7)
70+
endif()
7471
elseif(LOG_LEVEL_LOWER STREQUAL "verbose")
7572
add_compile_definitions(LOGLEVEL=5)
7673
elseif(LOG_LEVEL_LOWER STREQUAL "debug")
@@ -81,15 +78,13 @@ elseif(LOG_LEVEL_LOWER STREQUAL "warn")
8178
add_compile_definitions(LOGLEVEL=8)
8279
elseif(LOG_LEVEL_LOWER STREQUAL "error")
8380
add_compile_definitions(LOGLEVEL=9)
84-
85-
# default none is info
86-
elseif(LOG_LEVEL_LOWER STREQUAL "none")
87-
add_compile_definitions(LOGLEVEL=7)
8881
else()
8982
message(WARNING "unknown log level ${LOG_LEVEL}, use INFO as default")
9083
add_compile_definitions(LOGLEVEL=7)
9184
endif()
9285

86+
87+
9388
# Define shared compiler flags for all targets
9489
set(LIBCACHESIM_C_FLAGS
9590
-Wall -Wextra -Werror

libCacheSim/cache/admission/adaptsize/adaptsize.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ void Adaptsize::reconfigure() {
188188
total_obj_size += it->second.obj_size;
189189
++it;
190190
}
191-
VVERBOSE(
191+
VERBOSE(
192192
"Reconfiguring over %zu objects - log2 total size %f log2 statsize %f\n",
193193
longterm_metadata.size(), log2(total_obj_size), log2(stat_size));
194194
// END Prepare for reconf
@@ -249,10 +249,10 @@ void Adaptsize::reconfigure() {
249249
WARN("BUG: NaN h1:%f h2:%f\n", h1, h2);
250250
} else if (h1 > h2) {
251251
c_param = pow(2, x1);
252-
VVERBOSE("C = %f (log2: %f )\n", c_param, x1);
252+
VERBOSE("C = %f (log2: %f )\n", c_param, x1);
253253
} else {
254254
c_param = pow(2, x2);
255-
VVERBOSE("C = %f (log2: %f )\n", c_param, x2);
255+
VERBOSE("C = %f (log2: %f )\n", c_param, x2);
256256
}
257257
// END Check for result
258258
}

libCacheSim/cache/cache.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,10 @@ bool cache_get_base(cache_t *cache, const request_t *req) {
243243
}
244244

245245
if (hit) {
246-
VVERBOSE("req %ld, obj %ld --- cache hit\n", cache->n_req, req->obj_id);
246+
VERBOSE("req %ld, obj %ld --- cache hit\n", cache->n_req, req->obj_id);
247247
} else if (!cache->can_insert(cache, req)) {
248-
VVERBOSE("req %ld, obj %ld --- cache miss cannot insert\n", cache->n_req,
249-
req->obj_id);
248+
VERBOSE("req %ld, obj %ld --- cache miss cannot insert\n", cache->n_req,
249+
req->obj_id);
250250
} else {
251251
while (cache->get_occupied_byte(cache) + req->obj_size +
252252
cache->obj_md_size >

libCacheSim/cache/eviction/GLCache/GLCache.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,8 +397,8 @@ static cache_obj_t *GLCache_insert(cache_t *cache, const request_t *req) {
397397

398398
seg = allocate_new_seg(cache, bucket->bucket_id);
399399
append_seg_to_bucket(params, bucket, seg);
400-
VVERBOSE("%lu allocate new seg, %d in use seg\n", cache->n_req,
401-
params->n_in_use_segs);
400+
VERBOSE("%lu allocate new seg, %d in use seg\n", cache->n_req,
401+
params->n_in_use_segs);
402402
}
403403

404404
cache_obj_t *cache_obj = &seg->objs[seg->n_obj];

libCacheSim/cache/eviction/GLCache/eviction.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ void GLCache_merge_segs(cache_t *cache, bucket_t *bucket, segment_t **segs) {
141141
// called when there is no segment can be merged due to fragmentation
142142
// different from clean_one_seg because this function also updates cache state
143143
int evict_one_seg(cache_t *cache, segment_t *seg) {
144-
VVERBOSE("req %lu, evict one seg id %d occupied size %lu/%lu\n", cache->n_req,
145-
seg->seg_id, cache->occupied_byte, cache->cache_size);
144+
VERBOSE("req %lu, evict one seg id %d occupied size %lu/%lu\n", cache->n_req,
145+
seg->seg_id, cache->occupied_byte, cache->cache_size);
146146
GLCache_params_t *params = cache->eviction_params;
147147
bucket_t *bucket = &params->buckets[seg->bucket_id];
148148

libCacheSim/cache/eviction/LFU.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ static cache_obj_t *LFU_find(cache_t *cache, const request_t *req,
192192
memset(new_node, 0, sizeof(freq_node_t));
193193
new_node->freq = cache_obj->lfu.freq;
194194
g_hash_table_insert(params->freq_map, new_key, new_node);
195-
VVVERBOSE("allocate new %ld %d %p %p\n", new_node->freq, new_node->n_obj,
196-
new_node->first_obj, new_node->last_obj);
195+
VERBOSE("allocate new %ld %d %p %p\n", new_node->freq, new_node->n_obj,
196+
new_node->first_obj, new_node->last_obj);
197197
} else {
198198
// it could be new_node is empty
199199
DEBUG_ASSERT(new_node->freq == cache_obj->lfu.freq);

libCacheSim/cache/eviction/LFUDA.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ static cache_obj_t *LFUDA_find(cache_t *cache, const request_t *req,
181181
memset(new_node, 0, sizeof(freq_node_t));
182182
new_node->freq = cache_obj->lfu.freq;
183183
g_hash_table_insert(params->freq_map, new_key, new_node);
184-
VVVERBOSE("allocate new %ld %d %p %p\n", new_node->freq, new_node->n_obj,
185-
new_node->first_obj, new_node->last_obj);
184+
VERBOSE("allocate new %ld %d %p %p\n", new_node->freq, new_node->n_obj,
185+
new_node->first_obj, new_node->last_obj);
186186
} else {
187187
// it could be new_node is empty
188188
DEBUG_ASSERT(new_node->freq == cache_obj->lfu.freq);

libCacheSim/cache/eviction/LeCaR.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ static cache_obj_t *LeCaR_find(cache_t *cache, const request_t *req,
288288
* when remove_obj_from_freq_node */
289289
if (cache_obj->LeCaR.freq < params->min_freq) {
290290
params->min_freq = cache_obj->LeCaR.freq;
291-
VVERBOSE("update min freq to %d\n", (int)params->min_freq);
291+
VERBOSE("update min freq to %d\n", (int)params->min_freq);
292292
}
293293
}
294294

@@ -312,7 +312,7 @@ static cache_obj_t *LeCaR_find(cache_t *cache, const request_t *req,
312312
cache_obj_t *LeCaR_insert(cache_t *cache, const request_t *req) {
313313
LeCaR_params_t *params = (LeCaR_params_t *)(cache->eviction_params);
314314

315-
VVERBOSE("insert object %lu into cache\n", (unsigned long)req->obj_id);
315+
VERBOSE("insert object %lu into cache\n", (unsigned long)req->obj_id);
316316

317317
// LRU and hash table insert
318318
cache_obj_t *cache_obj = cache_insert_base(cache, req);
@@ -652,8 +652,8 @@ static inline void update_LFU_min_freq(LeCaR_params_t *params) {
652652
break;
653653
}
654654
}
655-
VVERBOSE("update LFU min freq from %ld to %ld\n", old_min_freq,
656-
params->min_freq);
655+
VERBOSE("update LFU min freq from %ld to %ld\n", old_min_freq,
656+
params->min_freq);
657657
// if the object is the only object in the cache, we may have min_freq == 1
658658
DEBUG_ASSERT(params->min_freq > old_min_freq ||
659659
params->q_head == params->q_tail);
@@ -682,19 +682,19 @@ static inline void remove_obj_from_freq_node(LeCaR_params_t *params,
682682
DEBUG_ASSERT(freq_node != NULL);
683683
DEBUG_ASSERT(freq_node->freq == cache_obj->LeCaR.freq);
684684
DEBUG_ASSERT(freq_node->n_obj > 0);
685-
VVERBOSE("remove object from freq node %p (freq %ld, %u obj)\n", freq_node,
686-
freq_node->freq, freq_node->n_obj);
685+
VERBOSE("remove object from freq node %p (freq %ld, %u obj)\n", freq_node,
686+
freq_node->freq, freq_node->n_obj);
687687
freq_node->n_obj--;
688688

689689
if (cache_obj == freq_node->first_obj) {
690-
VVVERBOSE("remove object from freq node --- object is the first object\n");
690+
VERBOSE("remove object from freq node --- object is the first object\n");
691691
freq_node->first_obj = cache_obj->LeCaR.lfu_next;
692692
if (cache_obj->LeCaR.lfu_next != NULL)
693693
((cache_obj_t *)(cache_obj->LeCaR.lfu_next))->LeCaR.lfu_prev = NULL;
694694
}
695695

696696
if (cache_obj == freq_node->last_obj) {
697-
VVVERBOSE("remove object from freq node --- object is the last object\n");
697+
VERBOSE("remove object from freq node --- object is the last object\n");
698698
freq_node->last_obj = cache_obj->LeCaR.lfu_prev;
699699
if (cache_obj->LeCaR.lfu_prev != NULL)
700700
((cache_obj_t *)(cache_obj->LeCaR.lfu_prev))->LeCaR.lfu_next = NULL;
@@ -787,7 +787,7 @@ static void verify_ghost_lru_integrity(cache_t *cache, LeCaR_params_t *params) {
787787
cur = cur->queue.next;
788788
}
789789

790-
VVVERBOSE(
790+
VERBOSE(
791791
"ghost entry head %p tail %p, "
792792
"ghost_entry_size from scan = %ld,"
793793
"lru_g_occupied_byte = %ld\n ",

libCacheSim/include/libCacheSim/const.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,11 @@ extern "C" {
3939
#define MAGENTA "\x1B[35m"
4040
#define CYAN "\x1B[36m"
4141

42-
#define VVVERBOSE_LEVEL 3
43-
#define VVERBOSE_LEVEL 4
4442
#define VERBOSE_LEVEL 5
4543
#define DEBUG_LEVEL 6
4644
#define INFO_LEVEL 7
4745
#define WARN_LEVEL 8
48-
#define SEVERE_LEVEL 9
46+
#define ERROR_LEVEL 9
4947

5048
// this is correct, to change to this, need to update test
5149
#define KiB 1024LL

0 commit comments

Comments
 (0)