加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0084-mod-unix-time-stamp-to-local-time.patch 2.98 KB
一键复制 编辑 原始数据 按行查看 历史
yinbin6 提交于 2023-12-16 15:16 . sync fix EPOLLIN event error
From 95784bb047ae30ebff9d224ef178430fda91027e Mon Sep 17 00:00:00 2001
From: hantwofish <hankangkang5@huawei.com>
Date: Fri, 15 Dec 2023 03:34:46 +0800
Subject: [PATCH] mod unix time stamp to local time
---
src/ltran/ltran_dfx.c | 26 +++++++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)
diff --git a/src/ltran/ltran_dfx.c b/src/ltran/ltran_dfx.c
index 2a84cb8..25d4f35 100644
--- a/src/ltran/ltran_dfx.c
+++ b/src/ltran/ltran_dfx.c
@@ -53,6 +53,7 @@
#define GAZELLE_DECIMAL 10
#define GAZELLE_KEEPALIVE_STR_LEN 35
+#define GAZELLE_TIME_STR_LEN 25
static int32_t g_unix_fd = -1;
static int32_t g_ltran_rate_show_flag = GAZELLE_OFF; // not show when first get total statistics
@@ -1001,13 +1002,27 @@ static void gazelle_keepalive_string(char* str, int buff_len, struct gazelle_sta
if (conn_info->keepalive == 0) {
return;
}
- int ret = sprintf_s(str, buff_len - 1, "(%u,%u,%u)", conn_info->keep_idle, conn_info->keep_intvl,
+ int ret = sprintf_s(str, buff_len, "(%u,%u,%u)", conn_info->keep_idle, conn_info->keep_intvl,
conn_info->keep_cnt);
if (ret < 0) {
printf("gazelle_keepalive_string sprintf_s fail ret=%d\n", ret);
return;
}
- str[strlen(str)] = '\0';
+}
+
+static void gazelle_localtime_string(char* str, int buff_len)
+{
+ struct timeval time = {0};
+ gettimeofday(&time, NULL);
+ struct tm* tm;
+ time_t t = time.tv_sec;
+ tm = localtime(&t);
+ int ret = sprintf_s(str, buff_len, "%d-%d-%d %d:%d:%d",
+ tm->tm_yday + 1900, tm->tm_mon + 1, tm->tm_yday, tm->tm_hour, tm->tm_min, tm->tm_sec);
+ if (ret < 0) {
+ printf("gazelle_localtime_string sprintf_s fail ret=%d\n", ret);
+ return;
+ }
}
static void gazelle_print_lstack_stat_conn(void *buf, const struct gazelle_stat_msg_request *req_msg)
@@ -1020,13 +1035,14 @@ static void gazelle_print_lstack_stat_conn(void *buf, const struct gazelle_stat_
char str_raddr[INET6_ADDRSTRLEN + 6] = {0};
struct gazelle_stack_dfx_data *stat = (struct gazelle_stack_dfx_data *)buf;
struct gazelle_stat_lstack_conn *conn = &stat->data.conn;
- struct timeval time = {0};
- gettimeofday(&time, NULL);
+
char keepalive_info_str[GAZELLE_KEEPALIVE_STR_LEN] = {0};
+ char sys_local_time_str[GAZELLE_TIME_STR_LEN] = {0};
+ gazelle_localtime_string(sys_local_time_str, GAZELLE_TIME_STR_LEN);
printf("Active Internet connections (servers and established)\n");
do {
- printf("\n------ stack tid: %6u ------time=%lu\n", stat->tid, time.tv_sec * 1000000 + time.tv_usec);
+ printf("\n------ stack tid: %6u ------time=%s\n", stat->tid, sys_local_time_str);
printf("No. Proto lwip_recv recv_ring in_send send_ring cwn rcv_wnd snd_wnd snd_buf snd_nxt"
" lastack rcv_nxt events epoll_ev evlist fd Local Address"
" Foreign Address State"
--
2.27.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化