#define PROCESS_CPU_UTIL BIT(0)
#define PROCESS_MEM_VIRT BIT(1)
#define PROCESS_MEM_RSS BIT(2)
-#define PROCESS_DISK_READ BIT(3)
-#define PROCESS_DISK_WRITE BIT(4)
+#define PROCESS_MEM_PERCENT BIT(3)
+#define PROCESS_DISK_READ BIT(4)
+#define PROCESS_DISK_WRITE BIT(5)
+#define PROCESS_COMM BIT(6)
/**
* @brief Initialize the tizen monitor
struct process_context {
pid_t pid;
+ char comm[TS_COMM_LEN];
struct taskstats prev;
struct taskstats curr;
u_int64_t prev_total_time;
double cpu_period;
int online_cpu;
+ u_int64_t total_memory;
};
static long jiffy;
rss = (double)curr->coremem / (double)curr->ac_stime;
rss *= 1024.0 * 1000.0;
- *data = (void *)(intptr_t)(int)rss;
+ switch (attr->id) {
+ case PROCESS_MEM_RSS:
+ *data = (void *)(intptr_t)(int)rss;
+ break;
+ case PROCESS_MEM_PERCENT:
+ /* percentage value should be divided by 1000 at user-side */
+ *data = (void *)(intptr_t)(int)((rss / ctx->total_memory) * 100000.0);
+ break;
+ default:
+ return -EINVAL;
+ }
return 0;
}
return 0;
}
+static int process_get_comm(const struct resource *res,
+ const struct resource_attribute *attr,
+ void **data)
+{
+ struct process_context *ctx;
+
+ if (!res || !res->priv || !attr || !data)
+ return -EINVAL;
+
+ ctx = res->priv;
+ *data = g_strdup(ctx->comm);
+
+ return 0;
+}
+
static const struct resource_attribute process_attrs[] = {
{
.name = "PROCESS_CPU_UTIL",
},
},
{
+ .name = "PROCESS_MEM_PERCENT",
+ .id = PROCESS_MEM_PERCENT,
+ .type = DATA_TYPE_INT,
+ .ops = {
+ .get = process_get_mem_rss,
+ },
+ },
+ {
.name = "PROCESS_DISK_READ",
.id = PROCESS_DISK_READ,
.type = DATA_TYPE_INT,
.get = process_get_disk_write,
},
},
+ {
+ .name = "PROCESS_COMM",
+ .id = PROCESS_COMM,
+ .type = DATA_TYPE_STRING,
+ .ops = {
+ .get = process_get_comm,
+ },
+ },
};
#define saturatingSub(a, b) (a > b ? a - b : 0)
static int process_init(struct resource *res)
{
+ struct resource *memory;
+ struct taskstats stats;
struct process_context *ctx;
int ret;
return -EINVAL;
}
+ ret = query_taskstats(&stats, TASKSTATS_CMD_ATTR_PID, ctx->pid);
+ if (ret < 0) {
+ free(ctx);
+ return -EINVAL;
+ }
+ memcpy(ctx->comm, stats.ac_comm, TS_COMM_LEN);
+
+ ctx->total_memory = kernel_get_memory_total() * 1024ULL;
+
res->priv = ctx;
return 0;