Skip to content

Commit ffa9693

Browse files
committed
Add task cmdline feature for procrank
Signed-off-by: quic_chahuan <[email protected]>
1 parent 57dc7fb commit ffa9693

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

procrank/procrank.cpp

+34-1
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,14 @@ void Procrank::cmd_main(void) {
2727
int flags;
2828
std::string cppString;
2929
if (argcnt < 2) cmd_usage(pc->curcmd, SYNOPSIS);
30-
while ((c = getopt(argcnt, args, "a")) != EOF) {
30+
while ((c = getopt(argcnt, args, "ac")) != EOF) {
3131
switch(c) {
3232
case 'a':
3333
parser_process_memory();
3434
break;
35+
case 'c':
36+
parser_process_name();
37+
break;
3538
default:
3639
argerrs++;
3740
break;
@@ -58,6 +61,8 @@ void Procrank::init_command(){
5861
"dump process memory information", /* short description */
5962
"-a \n"
6063
" This command dumps the process info. sorted by rss",
64+
"-c \n"
65+
" This command dumps the process cmdline.",
6166
"\n",
6267
"EXAMPLES",
6368
" Display process memory info:",
@@ -66,6 +71,12 @@ void Procrank::init_command(){
6671
" 975 1.97Gb 51.09Mb 13.71Mb 3.54Mb 1.99Mb Binder:975_3",
6772
" 465 1.69Gb 4.53Mb 286.01Kb 36.00Kb 26.01Mb main",
6873
"\n",
74+
"EXAMPLES",
75+
" Display process cmdline:",
76+
" %s> procrank -c",
77+
" PID Comm Cmdline",
78+
" 1 init /system/bin/init",
79+
"\n",
6980
};
7081
initialize();
7182
//print_table();
@@ -147,6 +158,7 @@ std::shared_ptr<procrank> Procrank::parser_vma(ulong& vma_addr, ulong& task_addr
147158
ulong vm_end = ULONG(vma_struct + field_offset(vm_area_struct, vm_end));
148159
struct task_context *tc = task_to_context(task_addr);
149160
if(tc == nullptr){
161+
FREEBUF(vma_struct);
150162
return nullptr;
151163
}
152164
for(ulong vaddr = vm_start; vaddr < vm_end; vaddr+= page_size){
@@ -181,4 +193,25 @@ std::shared_ptr<procrank> Procrank::parser_vma(ulong& vma_addr, ulong& task_addr
181193
return procrank_ptr;
182194
}
183195

196+
void Procrank::parser_process_name() {
197+
std::ostringstream oss_hd;
198+
oss_hd << std::left << std::setw(8) << "PID" << " "
199+
<< std::left << std::setw(20) << "Comm" << " "
200+
<< std::left << std::setw(10) << "Cmdline" << "\n";
201+
for(ulong task_addr: for_each_process()){
202+
std::string cmdline;
203+
struct task_context *tc = task_to_context(task_addr);
204+
if (!swap_ptr->is_zram_enable()){
205+
cmdline = tc->comm;
206+
} else {
207+
cmdline = swap_ptr->read_start_args(task_addr);
208+
}
209+
oss_hd << std::left << std::setw(8) << tc->pid << " "
210+
<< std::left << std::setw(20) << tc->comm << " "
211+
<< std::left << std::setw(10) << cmdline << "\n";
212+
}
213+
214+
fprintf(fp, "%s \n", oss_hd.str().c_str());
215+
}
216+
184217
#pragma GCC diagnostic pop

procrank/procrank.h

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class Procrank : public PaserPlugin {
3636
void init_command();
3737
void cmd_main(void) override;
3838
void parser_process_memory();
39+
void parser_process_name();
3940
std::shared_ptr<procrank> parser_vma(ulong& vma_addr, ulong& task_addr);
4041
DEFINE_PLUGIN_INSTANCE(Procrank)
4142

0 commit comments

Comments
 (0)