return 0;
}
-void read_pageframe(int pid, int tid, struct pageframe *pageframe,
- struct process **process_list, struct parse_opts *opts)
+static int read_pageframe(int pid, int tid, struct pageframe *pageframe,
+ struct process **process_list, struct parse_opts *opts)
{
struct maps *maps;
struct process *process;
file = fopen(path, "rb");
if (!file)
- return;
+ return 0;
maps = parse_maps(file, pid, tid);
fclose(file);
file = fopen(path, "rb");
if (!file)
- return;
+ return 0;
parse_pageframe(file, pageframe, maps, opts);
fclose(file);
if (read_cmdline(pid, tid, process->name, sizeof(process->name)))
- return;
+ return 1;
if (maps == NULL)
- return;
+ return 1;
list_for_each_entry(maps, &process->maps->list, list) {
process->pages_present += maps->pages_present;
process->pages_swapped += maps->pages_swapped;
}
- return;
+ return 1;
}
static int parse_pid(DIR **dir)
return 0;
}
-static void read_pageframe_with_threads(int pid,
- struct pageframe *pageframe,
- struct process **process_list,
- struct parse_opts *opts)
+static int read_pageframe_with_threads(int pid,
+ struct pageframe *pageframe,
+ struct process **process_list,
+ struct parse_opts *opts)
{
DIR *dir = NULL;
int tid;
+ int count = 0;
while (1) {
if (opts->with_threads)
tid = pid;
if (tid <= 0)
- return;
+ return count;
- read_pageframe(pid, tid, pageframe, process_list, opts);
+ count += read_pageframe(pid, tid, pageframe, process_list,
+ opts);
if (!opts->with_threads)
break;
}
+
+ return count;
}
-void scan_all_pids(struct pageframe *pf, struct process **process_list,
+int scan_all_pids(struct pageframe *pf, struct process **process_list,
struct parse_opts *opts)
{
DIR *dir = NULL;
int pid;
+ int count = 0;
if (opts->parse_mask & PARSE_PROCESS_NAME) {
while ((pid = get_next_pid_by_name(&dir, opts->name))) {
- read_pageframe_with_threads(pid, pf, process_list,
- opts);
+ count += read_pageframe_with_threads(pid, pf,
+ process_list,
+ opts);
}
dir = NULL;
}
if (opts->parse_mask & PARSE_PID)
- read_pageframe_with_threads(opts->pid, pf, process_list, opts);
+ count = read_pageframe_with_threads(opts->pid, pf, process_list,
+ opts);
+
+ if ((count == 0) && !(opts->parse_mask & PARSE_MAP_NAME)) {
+ printf("Failed to find any matching processes "
+ "with given arguments\n");
+ return -1;
+ }
while (1) {
pid = get_next_pid(&dir);
break;
read_pageframe_with_threads(pid, pf, process_list, opts);
}
+
+ return 0;
}