perf: 优化session_ctx减少内存占用; 优化global metrics的结构

This commit is contained in:
luwenpeng
2023-11-24 15:17:18 +08:00
parent bda50d79af
commit eedd18183e
12 changed files with 331 additions and 439 deletions

View File

@@ -52,49 +52,6 @@ int mutable_array_count_elem(struct mutable_array *array);
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
******************************************************************************/

View File

@@ -98,29 +98,6 @@ int mutable_array_index_elem(struct mutable_array *array, int index)
return array->elems[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
******************************************************************************/

View File

@@ -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";