int64_t soft_irq;
};
+struct proc_map_info {
+ uint32_t rss;
+ uint32_t pss;
+ uint32_t swap;
+ uint32_t swap_pss;
+};
+
enum {
PROCESS_STAT_FIELD_PID,
PROCESS_STAT_FIELD_COMM,
char *stat_fields[PROCESS_STAT_FIELD_MAX]);
int kernel_get_process_taskstats(struct taskstats *stats, int cmd_type, pid_t pid);
int kernel_get_thread_group_taskstats(struct taskstats *stats, pid_t tgid, bool get_proc_info);
+int kernel_get_thread_group_map_info(struct proc_map_info *map_info, pid_t tgid);
#endif
#include <util/log.h>
#include <util/kernel.h>
+static int have_smaps_rollup;
+
static int __get_cpu_num(char *path)
{
FILE *fp;
return 0;
}
+
+int kernel_get_thread_group_map_info(struct proc_map_info *map_info, pid_t tgid)
+{
+ char smap_file_path[BUFF_MAX];
+ char buffer[BUFF_MAX];
+ FILE *smaps_file;
+
+ sprintf(smap_file_path, "/proc/%d/%s", tgid, have_smaps_rollup ? "smaps_rollup" : "smaps");
+
+ smaps_file = fopen(smap_file_path, "r");
+ if (!smaps_file)
+ return -EIO;
+
+ map_info->rss = 0;
+ map_info->pss = 0;
+ map_info->swap = 0;
+ map_info->swap_pss = 0;
+
+ while (fgets(buffer, sizeof(buffer), smaps_file)) {
+ if (strchr(buffer, '\n') == 0)
+ continue;
+
+ if (strstr(buffer, "Rss:"))
+ map_info->rss += strtol(buffer + 4, NULL, 10);
+ else if (strstr(buffer, "Pss:"))
+ map_info->pss += strtol(buffer + 4, NULL, 10);
+ else if (strstr(buffer, "Swap:"))
+ map_info->swap += strtol(buffer + 5, NULL, 10);
+ else if (strstr(buffer, "SwapPss:"))
+ map_info->swap_pss += strtol(buffer + 8, NULL, 10);
+ }
+
+ fclose(smaps_file);
+
+ return 0;
+}
+
+static void __CONSTRUCTOR__ kernel_init(void)
+{
+ have_smaps_rollup = !access("/proc/self/smaps_rollup", R_OK);
+}