Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2301_76519099
rt-thread
提交
2ea39b4f
R
rt-thread
项目概览
2301_76519099
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
3
Star
1
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2ea39b4f
编写于
4月 15, 2021
作者:
armink_ztl
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[ulog] Using gettimeofday for timestamp get.
上级
6eb67523
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
30 addition
and
11 deletion
+30
-11
components/utilities/ulog/ulog.c
components/utilities/ulog/ulog.c
+30
-11
未找到文件。
components/utilities/ulog/ulog.c
浏览文件 @
2ea39b4f
...
...
@@ -260,19 +260,36 @@ RT_WEAK rt_size_t ulog_formater(char *log_buf, rt_uint32_t level, const char *ta
/* add time info */
{
#ifdef ULOG_TIME_USING_TIMESTAMP
static
time_t
now
;
static
struct
timeval
now
;
static
struct
tm
*
tm
,
tm_tmp
;
static
rt_bool_t
check_usec_support
=
RT_FALSE
,
usec_is_support
=
RT_FALSE
;
now
=
time
(
NULL
);
tm
=
gmtime_r
(
&
now
,
&
tm_tmp
);
#ifdef RT_USING_SOFT_RTC
rt_snprintf
(
log_buf
+
log_len
,
ULOG_LINE_BUF_SIZE
-
log_len
,
"%02d-%02d %02d:%02d:%02d.%03d"
,
tm
->
tm_mon
+
1
,
tm
->
tm_mday
,
tm
->
tm_hour
,
tm
->
tm_min
,
tm
->
tm_sec
,
rt_tick_get
()
%
1000
);
#else
rt_snprintf
(
log_buf
+
log_len
,
ULOG_LINE_BUF_SIZE
-
log_len
,
"%02d-%02d %02d:%02d:%02d"
,
tm
->
tm_mon
+
1
,
tm
->
tm_mday
,
tm
->
tm_hour
,
tm
->
tm_min
,
tm
->
tm_sec
);
#endif
/* RT_USING_SOFT_RTC */
if
(
gettimeofday
(
&
now
,
NULL
)
>=
0
)
{
time_t
t
=
now
.
tv_sec
;
tm
=
localtime_r
(
&
t
,
&
tm_tmp
);
/* show the time format MM-DD HH:MM:SS */
rt_snprintf
(
log_buf
+
log_len
,
ULOG_LINE_BUF_SIZE
-
log_len
,
"%02d-%02d %02d:%02d:%02d"
,
tm
->
tm_mon
+
1
,
tm
->
tm_mday
,
tm
->
tm_hour
,
tm
->
tm_min
,
tm
->
tm_sec
);
/* check the microseconds support when kernel is startup */
if
(
!
check_usec_support
&&
rt_thread_self
()
!=
RT_NULL
)
{
long
old_usec
=
now
.
tv_usec
;
/* delay some time for wait microseconds changed */
rt_thread_delay
(
2
);
gettimeofday
(
&
now
,
NULL
);
check_usec_support
=
RT_TRUE
;
/* the microseconds is not equal between two gettimeofday calls */
if
(
now
.
tv_usec
!=
old_usec
)
usec_is_support
=
RT_TRUE
;
}
if
(
usec_is_support
)
{
/* show the millisecond */
log_len
+=
rt_strlen
(
log_buf
+
log_len
);
rt_snprintf
(
log_buf
+
log_len
,
ULOG_LINE_BUF_SIZE
-
log_len
,
".%03d"
,
now
.
tv_usec
/
1000
);
}
}
#else
static
rt_size_t
tick_len
=
0
;
...
...
@@ -321,7 +338,9 @@ RT_WEAK rt_size_t ulog_formater(char *log_buf, rt_uint32_t level, const char *ta
rt_size_t
name_len
=
0
;
const
char
*
thread_name
=
"N/A"
;
if
(
rt_thread_self
()
->
name
)
{
thread_name
=
rt_thread_self
()
->
name
;
}
name_len
=
rt_strnlen
(
thread_name
,
RT_NAME_MAX
);
rt_strncpy
(
log_buf
+
log_len
,
thread_name
,
name_len
);
log_len
+=
name_len
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录