Skip to content

Commit 3c4959b

Browse files
committed
[smart] add CPU usage tracing config
This patch introduces following features: - Added CPU usage tracing functionality, enabled by default, for applications like 'top'. Signed-off-by: Shell <[email protected]>
1 parent 78bdf67 commit 3c4959b

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

components/lwp/Kconfig

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ if RT_USING_LWP
1212

1313
if LWP_DEBUG
1414
config LWP_DEBUG_INIT
15-
select RT_USING_HOOKLIST
16-
bool "Enable debug mode of init process"
17-
default n
15+
select RT_USING_HOOKLIST
16+
bool "Enable debug mode of init process"
17+
default n
1818
endif
1919

2020
config RT_LWP_MAX_NR
@@ -33,6 +33,13 @@ if RT_USING_LWP
3333
int "The input buffer size of lwp console device"
3434
default 1024
3535

36+
config LWP_TRACING_CPU_USAGE
37+
select RT_USING_HOOK
38+
bool "Enable cpu usage tracing"
39+
help
40+
Enable cpu usage tracing for application like top.
41+
default y
42+
3643
config LWP_TID_MAX_NR
3744
int "The maximum number of lwp thread id"
3845
default 64

components/lwp/lwp.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ extern char working_directory[];
6767
* It's always recommended to scratch the console from the boot arguments.
6868
* And dont forget to register the device with a higher priority.
6969
*/
70-
static rt_err_t lwp_default_console_setup(void)
70+
static rt_err_t _default_console_setup(void)
7171
{
7272
rt_device_t bakdev = rt_device_find("ttyS0");
7373
rt_err_t rc;
@@ -85,6 +85,15 @@ static rt_err_t lwp_default_console_setup(void)
8585
return rc;
8686
}
8787

88+
void rt_update_process_times(void);
89+
static int _set_usage_hook(void)
90+
{
91+
#ifdef LWP_TRACING_CPU_USAGE
92+
rt_tick_sethook(rt_update_process_times);
93+
#endif /* LWP_TRACING_CPU_USAGE */
94+
return RT_EOK;
95+
}
96+
8897
static int lwp_component_init(void)
8998
{
9099
int rc;
@@ -104,9 +113,13 @@ static int lwp_component_init(void)
104113
{
105114
LOG_E("%s: lwp_futex_init() failed", __func__);
106115
}
107-
else if ((rc = lwp_default_console_setup()) != RT_EOK)
116+
else if ((rc = _set_usage_hook()) != RT_EOK)
117+
{
118+
LOG_E("%s: _set_usage_hook() failed", __func__);
119+
}
120+
else if ((rc = _default_console_setup()) != RT_EOK)
108121
{
109-
LOG_E("%s: lwp_default_console_setup() failed", __func__);
122+
LOG_E("%s: _default_console_setup() failed", __func__);
110123
}
111124
return rc;
112125
}

0 commit comments

Comments
 (0)