summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchenzizhan <[email protected]>2023-08-22 10:41:24 +0800
committerchenzizhan <[email protected]>2023-08-22 10:41:24 +0800
commit888ae31c70499d14cabedbeb78a37d1f59bb27dd (patch)
tree6a6752c6a2e7b968631078066052e6d884cbb561
parent586c89010bce3c21e522d0c0cc6556d642d5bad4 (diff)
revert merge and reset. Try fix coredump TSG-16625: delete `const` on id_tag_array, some assert , disable optimization flag
-rw-r--r--src/logging/log.c281
-rw-r--r--src/logging/log.h45
-rw-r--r--src/logging/logger_manage.c0
-rw-r--r--src/logging/logger_manage.h0
-rw-r--r--src/metrics/metric.c24
-rw-r--r--src/tags/cell_manager.c5
-rw-r--r--src/tags/heavy_keeper.c12
-rw-r--r--src/tags/my_ut_hash.c4
-rw-r--r--src/tags/sorted_set.c1
-rw-r--r--test/CMakeLists.txt2
-rw-r--r--test/test_metric_counter.cpp2
-rw-r--r--tmp/leetcode.cpp32
12 files changed, 18 insertions, 390 deletions
diff --git a/src/logging/log.c b/src/logging/log.c
deleted file mode 100644
index 37038e6..0000000
--- a/src/logging/log.c
+++ /dev/null
@@ -1,281 +0,0 @@
-/*
- * Copyright (c) 2020 rxi
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to
- * deal in the Software without restriction, including without limitation the
- * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- * sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- * IN THE SOFTWARE.
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <pthread.h>
-#include <sys/stat.h>
-
-#include "log.h"
-
-#define ALLOC(type, number) ((type *)calloc(sizeof(type), number))
-
-typedef enum {
- LOG_OP_IFACE_CONSOLE,
- LOG_OP_IFACE_FILE,
- RT_LOG_OP_IFACE_MAX,
-}log_op_iface;
-
-struct log_handle
-{
- int level;
- int enable;
- FILE *fp;
- va_list ap;
- char defined_log_fn[1024];
- char runtime_log_fn[1024];
- pthread_mutex_t mutex;
- log_op_iface iface;
-};
-
-static unsigned char weekday_str[7][4] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
-
-static unsigned char month_str[12][4] = {"Jan", "Feb", "Mar", "Apr","May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
-
-static int log_create_dir(const char *dir_path, int path_len)
-{
- if(dir_path == NULL)
- return -1;
-
- char *buf = (char *)calloc(path_len+1, 1);
- int ret = -1;
-
- memcpy(buf, dir_path, path_len);
- if(access(buf, R_OK) != 0)
- {
- if(mkdir(buf, 0755)!= 0)
- ret = -1;
- else
- ret = 0;
- }
- else
- ret = 1;
- free(buf);
- buf = NULL;
- return ret;
-}
-
-static void log_close_file(struct log_handle *handle)
-{
- pthread_mutex_lock(&handle->mutex);
- if(handle->fp != NULL)
- {
- fclose(handle->fp);
- handle->fp = NULL;
- }
- pthread_mutex_unlock(&handle->mutex);
- return;
-}
-
-int log_open_file(char *file_name, struct log_handle *handle)
-{
- FILE *fp = NULL;
- log_close_file(handle);
- if(NULL == (fp = fopen(file_name, "a")))
- {
- return -1;
- }
- memcpy(handle->runtime_log_fn, file_name, strlen(file_name));
- handle->fp = fp;
- return 0;
-}
-
-static int log_create_path(const char *file_path)
-{
- FILE *fp = NULL;
-
- if(file_path == NULL)
- return 0;
-
- char *p_path = rindex(file_path, '/');
- if(p_path==0)
- {
- return 0;
- }
-
- const char *p_cur = file_path;
- int path_len = p_path - file_path;
- int i = 0;
-
- if(log_create_dir(file_path, path_len) >= 0)
- return 0;
-
- for(;i<=path_len;i++,p_cur++)
- {
- if(*p_cur == '/')
- {
- if(log_create_dir(file_path, i+1) < 0)
- return -1;
- }
- }
- if(NULL == (fp = fopen(file_path, "w")))
- {
- return 0;
- }
- fclose(fp);
- return 1;
-}
-
-int log_create_log_file(struct log_handle *handle)
-{
- time_t t;
- struct tm local_time;
- char tmp_log_file_name[1024+128];
-
- time(&t);
- if(NULL == (localtime_r(&t, &local_time)))
- {
- return 0;
- }
- snprintf(tmp_log_file_name, sizeof(tmp_log_file_name), "%s.%04d-%02d-%02d", handle->defined_log_fn, local_time.tm_year + 1900, local_time.tm_mon + 1, local_time.tm_mday);
-
- if(handle->fp == NULL)
- {
- if(0 != log_open_file(tmp_log_file_name, handle)) return 0;
- }
- else
- {
- if (0 != memcmp(tmp_log_file_name, handle->runtime_log_fn, strlen(tmp_log_file_name)))
- {
- if(0 != log_open_file(tmp_log_file_name, handle))return 0;
- }
- }
-
- return 1;
-}
-
-static void log_print_file(struct log_handle *handle, int level, const char *module, va_list ap, const char *fmt)
-{
- char buf[64]={0};
- time_t t;
- struct tm local_time;
- const char *level_str_map[]= {"TRACE", "DEBUG", "INFO", "WARN", "ERROR", "FATAL"};
-
- time(&t);
- if(NULL == (localtime_r(&t, &local_time))) return;
- snprintf(buf, sizeof(buf), "%s %s %d %02d:%02d:%02d %d", weekday_str[local_time.tm_wday],
- month_str[local_time.tm_mon], local_time.tm_mday, local_time.tm_hour, local_time.tm_min, local_time.tm_sec, local_time.tm_year+1900);
-
- log_create_log_file(handle);
- fprintf(handle->fp, "%s, %s, %s, ", buf, level_str_map[level], module);
-
- vfprintf(handle->fp, fmt, ap);
- fprintf(handle->fp, "\n");
- fflush(handle->fp);
-}
-
-static void log_print_console(struct log_handle *handle, int level, const char *module, va_list ap, const char *fmt)
-{
- char buf[64]={0};
- time_t t;
- struct tm local_time;
- const char *level_str_map[]= {"TRACE", "DEBUG", "INFO", "WARN", "ERROR", "FATAL"};
-
- time(&t);
- if(NULL == (localtime_r(&t, &local_time))) return;
- snprintf(buf, sizeof(buf), "%s %s %d %02d:%02d:%02d %d", weekday_str[local_time.tm_wday],
- month_str[local_time.tm_mon], local_time.tm_mday, local_time.tm_hour, local_time.tm_min, local_time.tm_sec, local_time.tm_year+1900);
- fprintf(handle->fp, "%s, %s, %s, ", buf, level_str_map[level], module);
-
- vfprintf(handle->fp, fmt, ap);
- fprintf(handle->fp, "\n");
- fflush(handle->fp);
-}
-
-void log_options_set_level(struct log_handle * handle, int level)
-{
- if(handle != NULL)
- {
- handle->level = level;
- }
-}
-
-void log_options_set_enable(struct log_handle * handle, int enable)
-{
- if(handle != NULL)
- {
- handle->enable = enable;
- }
-}
-
-struct log_handle *log_handle_create(const char *file_path, int level)
-{
- struct log_handle *handle = ALLOC(struct log_handle, 1);
- if(!handle)
- {
- return NULL;
- }
- handle->enable=1;
- handle->level = level;
- strncpy(handle->defined_log_fn, file_path, 1024);
- pthread_mutex_init(&handle->mutex,NULL);
-
- if(handle->enable)
- {
- log_create_path(handle->defined_log_fn);
- }
-
- return handle;
-}
-
-void log_handle_destroy(struct log_handle * handle)
-{
- if(!handle)
- {
- return;
- }
-
- if(handle->iface == LOG_OP_IFACE_FILE && handle->fp != NULL)
- {
- fclose(handle->fp);
- handle->fp=NULL;
- }
-
- pthread_mutex_destroy(&(handle->mutex));
- free(handle);
- handle = NULL;
- return;
-}
-
-void log_print(struct log_handle *handle, int level, const char *module, const char *fmt, ...)
-{
- va_list ap;
-
- if(handle->enable != 1 && level >= handle->level)
- {
- handle->fp = stdout;
- handle->iface = LOG_OP_IFACE_CONSOLE;
- va_start(handle->ap, fmt);
- log_print_console(handle, level, module, ap, fmt);
- va_end(handle->ap);
- }
- if (handle->enable == 1 && level >= handle->level)
- {
- handle->iface = LOG_OP_IFACE_FILE;
- va_start(ap, fmt);
- log_print_file(handle, level, module, ap, fmt);
- va_end(ap);
- }
-}
-
diff --git a/src/logging/log.h b/src/logging/log.h
deleted file mode 100644
index 285cf5a..0000000
--- a/src/logging/log.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/**
- * Copyright (c) 2020 rxi
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the MIT license. See `log.c` for details.
- */
-
-#ifndef LOG_H
-#define LOG_H
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-#include <stdio.h>
-#include <stdarg.h>
-#include <stdbool.h>
-#include <time.h>
-
-#define LOG_VERSION "0.1.0"
-
-struct log_handle;
-
-enum { LOG_TRACE, LOG_DEBUG, LOG_INFO, LOG_WARN, LOG_ERROR, LOG_FATAL };
-
-#define log_debug(handle, module, fmt, ...) log_print(handle, LOG_DEBUG, module, fmt, ##__VA_ARGS__)
-#define log_trace(handle, module, fmt, ...) log_print(handle, LOG_TRACE, module, fmt, ##__VA_ARGS__)
-#define log_info(handle, module, fmt, ...) log_print(handle, LOG_INFO, module, fmt, ##__VA_ARGS__)
-#define log_warn(handle, module, fmt, ...) log_print(handle, LOG_WARN, module, fmt, ##__VA_ARGS__)
-#define log_error(handle, module, fmt, ...) log_print(handle, LOG_ERROR, module, fmt, ##__VA_ARGS__)
-#define log_fatal(handle, module, fmt, ...) log_print(handle, LOG_FATAL, module, fmt, ##__VA_ARGS__)
-
-void log_print(struct log_handle *, int level, const char *module, const char *fmt, ...);
-void log_options_set_enable(struct log_handle *, int enable);
-void log_options_set_level(struct log_handle *, int level);
-
-struct log_handle * log_handle_create(const char *file_path, int level);
-void log_handle_destroy(struct log_handle *);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/src/logging/logger_manage.c b/src/logging/logger_manage.c
deleted file mode 100644
index e69de29..0000000
--- a/src/logging/logger_manage.c
+++ /dev/null
diff --git a/src/logging/logger_manage.h b/src/logging/logger_manage.h
deleted file mode 100644
index e69de29..0000000
--- a/src/logging/logger_manage.h
+++ /dev/null
diff --git a/src/metrics/metric.c b/src/metrics/metric.c
index e5bdbf2..d66fafe 100644
--- a/src/metrics/metric.c
+++ b/src/metrics/metric.c
@@ -101,10 +101,7 @@ void metric_add_one_cell(struct metric *pthis, int id, struct metric_measure_dat
pthis->data_array = (struct metric_measure_data **)realloc(pthis->data_array, pthis->max_n_array_item * sizeof(struct metric_measure_data *));
memset(pthis->data_array + pthis->n_array_item, 0, (pthis->max_n_array_item - pthis->n_array_item) * sizeof(struct metric_measure_data *));
}
- if (pthis->data_array[id] != NULL) {
- // todo: log
- // printf("err, metric_add_one_cell, id: %d, data_array[id] is not NULL\n", id);
- }
+ assert(pthis->data_array[id] == NULL);
pthis->data_array[id] = data;
if (id + 1 > pthis->n_array_item) {
@@ -155,7 +152,7 @@ static void metric_scheme_counter_serialize(const struct metric_measure_data *da
mpack_complete_map(&writer);
if (mpack_writer_destroy(&writer) != mpack_ok) {
- // todo: log
+ assert(0);
}
}
@@ -165,7 +162,6 @@ static int metric_scheme_counter_merge(struct metric_measure_data *pthis, const
struct metric_counter_or_gauge *from_counter = from->counter;
if (counter->mode != from_counter->mode) {
- //todo: log
return -1;
}
switch (counter->mode) {
@@ -179,8 +175,7 @@ static int metric_scheme_counter_merge(struct metric_measure_data *pthis, const
counter->value = counter->value < from_counter->value ? counter->value : from_counter->value;
break;
default:
- // todo: log
- // printf("ERR: unknown counter type\n");
+ assert(0);
return -1;
}
@@ -211,8 +206,7 @@ struct metric_measure_data *metric_scheme_counter_deserialize(const char *blob,
counter->mode = mpack_node_i8(mpack_node_map_cstr(content_root, "mode"));
if (mpack_tree_destroy(&content_tree) != mpack_ok) {
- // todo: log
- // printf("ERR: An error occurred in counter_metric_deserialize!\n");
+ assert(0);
}
return ret;
}
@@ -265,8 +259,6 @@ struct metric_measure_data *metric_scheme_histogram_new(const struct metric_para
struct hdr_histogram* tmp_p_hdr = NULL;
int ret = hdr_init((int64_t)para->hdr.lowest_trackable_value, (int64_t)para->hdr.highest_trackable_value, para->hdr.significant_figures, &tmp_p_hdr);
if (ret != 0) {
- // printf("ERR: hdr_init failed!\n");
- // todo: log
return NULL;
}
struct metric_measure_data *data = (struct metric_measure_data *)malloc(sizeof(struct metric_measure_data));
@@ -304,7 +296,7 @@ struct metric_measure_data *metric_scheme_histogram_deserialize(const char *blob
{
struct hdr_histogram *hdr = NULL;
int ret = hdr_log_decode(&hdr, (char *)blob, blob_size);
- if (ret != 0 || hdr == NULL) {// todo: log
+ if (ret != 0 || hdr == NULL) {
return NULL;
}
struct metric_measure_data *data = (struct metric_measure_data *)malloc(sizeof(struct metric_measure_data));
@@ -360,7 +352,7 @@ struct metric_parameter *construct_parameters(enum metric_type type, ...)
paras->hdr.highest_trackable_value = va_arg(ap, long long);
paras->hdr.significant_figures = va_arg(ap, int);
break;
- default:// todo: log
+ default:
assert(0);
}
va_end(ap);
@@ -700,7 +692,7 @@ int metric_merge_or_copy_cell(struct metric *dest, const struct metric *src, int
dest_data = src->scheme->new(src->info->paras);
int ret = dest->scheme->copy(dest_data, src_data);
if (ret == -1) {
- dest->scheme->del(dest_data);// todo: log
+ dest->scheme->del(dest_data);
return -1;
}
metric_add_one_cell(dest, dest_cell_id, dest_data);
@@ -825,7 +817,7 @@ int metric_histogram_record(struct metric *pthis, int cell_id, long long value)
struct metric_measure_data *data = metric_find_or_new_cell(pthis, cell_id);
bool ret = hdr_record_value(data->hdr, value);
- if (!ret) {// todo: log
+ if (!ret) {
return -1;
}
return 0;
diff --git a/src/tags/cell_manager.c b/src/tags/cell_manager.c
index 78155f7..39e12f2 100644
--- a/src/tags/cell_manager.c
+++ b/src/tags/cell_manager.c
@@ -191,8 +191,6 @@ Even though there is a small possibility of not counting certain flows due to th
The number 8 was determined through experiment, where multiple tests were conducted, randomly generating flows by which cells are determined.
The observed stable cell ID count did not exceed 3 times the value of K. Therefore, a conservative value of 8 was chosen.*/
if (pthis->next_cell_id >= pthis->max_cell_num * 8) { // max int is much larger, no risk of overflow
- // todo: log
- // printf("ERR: the number of cells exceeds the limit when topk get bad flows\n");
return -1;
}
@@ -256,8 +254,7 @@ int cell_manager_serialize(const struct cell_manager *pthis, char **blob, size_t
mpack_complete_map(&writer);
if (mpack_writer_destroy(&writer) != mpack_ok) {
- // todo: log
- // printf("ERR: An error occurred in cell_manager_serialize\n");
+ assert(0);
}
return 0;
diff --git a/src/tags/heavy_keeper.c b/src/tags/heavy_keeper.c
index f1601ae..19c9ebe 100644
--- a/src/tags/heavy_keeper.c
+++ b/src/tags/heavy_keeper.c
@@ -8,6 +8,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <assert.h>
#include "minheap/heap.h"
#include "mpack/mpack.h"
@@ -479,8 +480,6 @@ int heavy_keeper_merge_recording_id_details(struct heavy_keeper *dest, const str
if (dest->params.array_num != src->params.array_num ||
dest->params.max_bucket_num != src->params.max_bucket_num ||
dest->K != src->K) {
- // todo: log
- // printf("ERR: parameters of two merged heavy keeper must be the same\n");
return -1;
}
@@ -544,7 +543,7 @@ int heavy_keeper_sorted_set_member_serialization(const struct tag_hash_key *tag,
mpack_complete_map(&writer);
if (mpack_writer_destroy(&writer) != mpack_ok) {
- // printf("ERR: An error occurred in heavy_keeper_sorted_set_member_serialization!\n");
+ assert(0);
return -1;
}
return 0;
@@ -561,7 +560,7 @@ int heavy_keeper_bucket_serialization(const struct Bucket *b, char **blob, size_
mpack_write_u32(&writer, b->finger_print);
mpack_complete_map(&writer);
if (mpack_writer_destroy(&writer) != mpack_ok) {
- // printf("ERR: An error occurred in heavy_keeper_bucket_serialization!\n");
+ assert(0);
return -1;
}
return 0;
@@ -615,7 +614,7 @@ void heavy_keeper_serialization(const struct heavy_keeper *hk, char **blob, size
mpack_complete_map(&writer);
if (mpack_writer_destroy(&writer) != mpack_ok) {
- // printf("ERR: An error occurred in heavy_keeper_serialization\n");
+ assert(0);
}
}
@@ -660,8 +659,7 @@ struct heavy_keeper *heavy_keeper_deserialization(const char *blob, size_t size)
heavy_keeper_sorted_set_deserialization(&root, hk->top_K_heap);
if (mpack_tree_destroy(&tree) != mpack_ok) {
- // printf("ERR: An error occurred in heavy_keeper_deserialization\n");
- return NULL;
+ assert(0);
}
return hk;
}
diff --git a/src/tags/my_ut_hash.c b/src/tags/my_ut_hash.c
index 24b5e0f..0a6052a 100644
--- a/src/tags/my_ut_hash.c
+++ b/src/tags/my_ut_hash.c
@@ -208,7 +208,7 @@ void fieldtag_list_serialize(const struct fieldstat_tag *tag_list, size_t tag_nu
mpack_finish_array(&writer);
if (mpack_writer_destroy(&writer) != mpack_ok) {
- // printf("ERR mpack writer fieldtag_list_serialize destroy failed\n");
+ assert(0);
}
fieldtag_list_free(tag_list_sorted, tag_num);
@@ -364,7 +364,7 @@ void tag_hash_key_serialize(const struct tag_hash_key *tag, char **blob, size_t
mpack_complete_map(&writer);
if (mpack_writer_destroy(&writer) != mpack_ok) {
- // printf("ERR: An error occurred in tag_hash_key_serialize!\n");
+ assert(0);
}
}
diff --git a/src/tags/sorted_set.c b/src/tags/sorted_set.c
index 9c90819..1a72707 100644
--- a/src/tags/sorted_set.c
+++ b/src/tags/sorted_set.c
@@ -277,7 +277,6 @@ void sorted_set_incrby(struct sorted_set *ss, const struct tag_hash_key *tag, un
{
heap_entry *entry = sorted_set_find_entry(ss, tag);
if (entry == NULL) {
- // printf("ERR: sorted_set_incrby: tag not found. The program will new an entry and continue, but it is not expected.\n");
sorted_set_insert(ss, (struct tag_hash_key *)tag, count);
return;
}
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index d6a2bcf..b86bfa1 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -42,7 +42,7 @@ SET(TEST_UTILS_SRC
function (add_unit_test file_name)
add_executable(${file_name} ${SRC} ${TEST_UTILS_SRC} ${file_name}.cpp)
- target_link_libraries(${file_name} gtest-static ${ZLIB_LIBRARIES} ${LFLAGS}) #MESA_handle_logger
+ target_link_libraries(${file_name} gtest-static ${ZLIB_LIBRARIES} ${LFLAGS})
set_property(TARGET ${file_name} PROPERTY CXX_STANDARD 17)
endfunction()
diff --git a/test/test_metric_counter.cpp b/test/test_metric_counter.cpp
index 9b63e13..77b4991 100644
--- a/test/test_metric_counter.cpp
+++ b/test/test_metric_counter.cpp
@@ -238,7 +238,7 @@ TEST(metric_test_counter, topk_add_and_test_accuracy)
error += abs(fieldstat_counter_get(instance, 0, 0, ret_cell_ids[i]) - flow_cnt[key + value]);
}
- printf("error: %lld\n", error);
+ printf("topk_add_and_test_accuracy Mean ratio e: %lld\n", error);
EXPECT_LT(error, tag_list_num * 0.005);
free(ret_cell_ids);
diff --git a/tmp/leetcode.cpp b/tmp/leetcode.cpp
deleted file mode 100644
index 1b7b8d4..0000000
--- a/tmp/leetcode.cpp
+++ /dev/null
@@ -1,32 +0,0 @@
-// 1289. 下降路径最小和 II
-
-
-// 给你一个 n x n 整数矩阵 grid ,请你返回 非零偏移下降路径 数字和的最小值。
-
-// 非零偏移下降路径 定义为:从 grid 数组中的每一行选择一个数字,且按顺序选出来的数字中,相邻数字不在原数组的同一列。
-
-// https://leetcode.cn/problems/minimum-falling-path-sum-ii/description/
-
-// 百分之一百动态规划
-/*
-注意到:一行选哪个不会影响下面第二行选哪个。对于每个位置,记录下来最小的和第二小的就行
-选最小的,如果上方的最小和下方的最小都不在同一行。或者选第二小的。
-额,总之分支成两种情况。
-
-s[i, j] = s[i - 1, p] + v[i, j] or
- = s[i - 1, j] + v[i, p]
-
-算是想出来了,但是灵感是copilot给的
-*/
-
-
-
-#include <vector>
-#include <iostream>
-
-using namespace std;
-
-class Solution {
-public:
-
-}; \ No newline at end of file