-
Notifications
You must be signed in to change notification settings - Fork 1.5k
mm/dump:add command to support dump memory usage of all pids #18468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -35,6 +35,9 @@ | |||
|
|
||||
| /* Special PID to query the info about alloc, free and mempool */ | ||||
|
|
||||
| #if CONFIG_MM_BACKTRACE >= 0 | ||||
xiaoxiang781216 marked this conversation as resolved.
Show resolved
Hide resolved
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
remove, definition does not require adding macro check |
||||
| #define PID_MM_ALL_PID ((pid_t)-7) | ||||
| #endif | ||||
| #define PID_MM_ORPHAN ((pid_t)-6) | ||||
| #define PID_MM_BIGGEST ((pid_t)-5) | ||||
| #define PID_MM_FREE ((pid_t)-4) | ||||
|
|
||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -223,6 +223,29 @@ static void memdump_handler(FAR struct mm_allocnode_s *node, FAR void *arg) | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| #if CONFIG_MM_BACKTRACE >= 0 | ||||||
| struct memdump_tcb_arg_s | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please put the type definition in section: /****************************************************************************
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move to file begin and add Private Types chapter |
||||||
| { | ||||||
| FAR struct mm_heap_s *heap; | ||||||
| unsigned long seqmin; | ||||||
| unsigned long seqmax; | ||||||
|
Comment on lines
+230
to
+231
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not use uintptr_t instead of "unsigned long"? It should be more adaptable to different architectures and data types.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @acassis ,Thank you for your review and feedback. The parameters of the memdump command are passed down via the memdump_write method, with the relevant code in this method as follows: struct mm_memdump_s dump = struct malltask
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you @xiaoqizhan, so let's keep it for now, but I suggest fixing it later (in another PR) using "uintptr_t" to make it to adapt better for each arch case.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @acassis Thank you for your valuable suggestion. I will try to optimize it in another PR as you recommended. |
||||||
| }; | ||||||
|
|
||||||
| static void memdump_tcb_handler(FAR struct tcb_s *tcb, FAR void *arg) | ||||||
| { | ||||||
| struct mallinfo_task info; | ||||||
| struct malltask task; | ||||||
| FAR struct memdump_tcb_arg_s *tcb_arg = arg; | ||||||
|
|
||||||
| task.pid = tcb ? tcb->pid : PID_MM_LEAK; | ||||||
| task.seqmin = tcb_arg->seqmin; | ||||||
| task.seqmax = tcb_arg->seqmax; | ||||||
| info = mm_mallinfo_task(tcb_arg->heap, &task); | ||||||
| syslog(LOG_INFO, "pid:%5d, used:%10d, nused:%10d\n", | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could we filter out PIDs that don't use any memory? |
||||||
| task.pid, info.uordblks, info.aordblks); | ||||||
| } | ||||||
| #endif | ||||||
|
|
||||||
| /**************************************************************************** | ||||||
| * Public Functions | ||||||
| ****************************************************************************/ | ||||||
|
|
@@ -301,6 +324,18 @@ void mm_memdump(FAR struct mm_heap_s *heap, | |||||
| { | ||||||
| syslog(LOG_INFO, "Dump allocated orphan nodes\n"); | ||||||
| } | ||||||
| #if CONFIG_MM_BACKTRACE >= 0 | ||||||
| else if (pid == PID_MM_ALL_PID) | ||||||
| { | ||||||
| syslog(LOG_INFO, "Dump all pid memory allocated\n"); | ||||||
| struct memdump_tcb_arg_s tcb_arg; | ||||||
| tcb_arg.heap = heap; | ||||||
| tcb_arg.seqmin = dump->seqmin; | ||||||
| tcb_arg.seqmax = dump->seqmax; | ||||||
| nxsched_foreach(memdump_tcb_handler, &tcb_arg); | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not reuse memdump_handler, the current approach has two loop(tcb + mem) which is very slower than one loop.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @xiaoxiang781216
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, but why not pass dump to nxsched_foreach and remove memdump_tcb_arg_s. |
||||||
| return; | ||||||
| } | ||||||
| #endif | ||||||
|
|
||||||
| #if CONFIG_MM_BACKTRACE < 0 | ||||||
| syslog(LOG_INFO, "%12s%9s%*s\n", "Size", "Overhead", | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.