diff options
| author | luwenpeng <[email protected]> | 2023-11-24 15:17:18 +0800 |
|---|---|---|
| committer | luwenpeng <[email protected]> | 2023-11-24 15:40:58 +0800 |
| commit | eedd18183ea5b06947079984de83cd145684cd38 (patch) | |
| tree | a8d6c2ef10391c0602df6532ee6c23f47a2c441d /common | |
| parent | bda50d79af1f7c59f5ab71fdefff06e3e3397be2 (diff) | |
perf: 优化session_ctx减少内存占用; 优化global metrics的结构
Diffstat (limited to 'common')
| -rw-r--r-- | common/include/utils.h | 43 | ||||
| -rw-r--r-- | common/src/utils.cpp | 23 | ||||
| -rw-r--r-- | common/test/gtest_utils.cpp | 28 |
3 files changed, 0 insertions, 94 deletions
diff --git a/common/include/utils.h b/common/include/utils.h index b0dfbf4..c606766 100644 --- a/common/include/utils.h +++ b/common/include/utils.h @@ -53,49 +53,6 @@ int mutable_array_exist_elem(struct mutable_array *array, uint64_t elem); int mutable_array_index_elem(struct mutable_array *array, int index); /****************************************************************************** - * sids - ******************************************************************************/ - -typedef uint16_t sid_t; -#define MR_SID_LIST_MAXLEN 8 - -struct sids -{ - int num; - sid_t elems[MR_SID_LIST_MAXLEN]; -}; - -void sids_copy(struct sids *dst, struct sids *src); - -/****************************************************************************** - * route_ctx - ******************************************************************************/ - -struct route_ctx -{ - char data[64]; - int len; -}; - -void route_ctx_copy(struct route_ctx *dst, struct route_ctx *src); - -/****************************************************************************** - * throughput_metrics - ******************************************************************************/ - -struct throughput_metrics -{ - uint64_t n_pkts; - uint64_t n_bytes; -}; - -static inline void throughput_metrics_inc(struct throughput_metrics *iterm, uint64_t n_pkts, uint64_t n_bytes) -{ - iterm->n_bytes += n_bytes; - iterm->n_pkts += n_pkts; -} - -/****************************************************************************** * device ******************************************************************************/ diff --git a/common/src/utils.cpp b/common/src/utils.cpp index 94d644f..773b1f2 100644 --- a/common/src/utils.cpp +++ b/common/src/utils.cpp @@ -99,29 +99,6 @@ int mutable_array_index_elem(struct mutable_array *array, int index) } /****************************************************************************** - * sids - ******************************************************************************/ - -void sids_copy(struct sids *dst, struct sids *src) -{ - if (dst && src) - { - dst->num = src->num; - memcpy(dst->elems, src->elems, sizeof(dst->elems[0]) * dst->num); - } -} - -/****************************************************************************** - * route_ctx - ******************************************************************************/ - -void route_ctx_copy(struct route_ctx *dst, struct route_ctx *src) -{ - memcpy(dst->data, src->data, src->len); - dst->len = src->len; -} - -/****************************************************************************** * device ******************************************************************************/ diff --git a/common/test/gtest_utils.cpp b/common/test/gtest_utils.cpp index 5b85acd..9b50c62 100644 --- a/common/test/gtest_utils.cpp +++ b/common/test/gtest_utils.cpp @@ -36,34 +36,6 @@ TEST(UTILS, FIXED_NUM_ARRAY) EXPECT_TRUE(mutable_array_count_elem(&array) == 0); } -TEST(UTILS, SIDS) -{ - struct sids src; - struct sids dst; - - for (int i = 0; i < MR_SID_LIST_MAXLEN; i++) - { - src.elems[i] = i; - } - src.num = MR_SID_LIST_MAXLEN; - - sids_copy(&dst, &src); - - EXPECT_TRUE(dst.num == src.num); - for (int i = 0; i < MR_SID_LIST_MAXLEN; i++) - { - EXPECT_TRUE(dst.elems[i] == i); - } -} - -TEST(UTILS, THROUGHPUT_METRICS) -{ - struct throughput_metrics iterm = {.n_pkts = 0, .n_bytes = 0}; - throughput_metrics_inc(&iterm, 1, 2); - EXPECT_TRUE(iterm.n_pkts == 1); - EXPECT_TRUE(iterm.n_bytes == 2); -} - TEST(UTILS, DEVICE) { const char *dev_name = "lo"; |
