From: Dongwoo Lee Date: Thu, 31 Mar 2022 04:16:49 +0000 (+0900) Subject: resource: process: Get initial stats of target process with taskstats X-Git-Tag: accepted/tizen/unified/20220412.100309~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F55%2F273455%2F1;p=platform%2Fcore%2Fsystem%2Fpass.git resource: process: Get initial stats of target process with taskstats Since open and read procfs task stat often cause performance degradation in the case that many process drivers are frequentyl set control. To reduce this overhead, now initial stats are retrieved by taskstats and 'pgid' which cannot be retrieved by taskstats is get lazily once at the first reading. Change-Id: I9bae9965a17192fbc0ab5789df45a782ab97ca9d Signed-off-by: Dongwoo Lee --- diff --git a/src/resource/resource-process.c b/src/resource/resource-process.c index 00fb14c..01ef3f9 100644 --- a/src/resource/resource-process.c +++ b/src/resource/resource-process.c @@ -199,6 +199,19 @@ static int process_get_context_data(const struct resource *res, strncpy((char *)data, ctx->comm, TS_COMM_LEN); break; case PROCESS_ATTR_PGID: + if (ctx->pgid < 0) { + char *stat_fields[PROCESS_STAT_FIELD_MAX]; + char buffer[BUFF_MAX]; + int ret; + + ret = kernel_get_process_stat_fields(ctx->tgid, buffer, + BUFF_MAX, stat_fields); + if (ret < 0) + break; + + ctx->pgid = atoi(stat_fields[PROCESS_STAT_FIELD_PGID]); + } + *((int *)data) = ctx->pgid; break; case PROCESS_ATTR_PPID: @@ -309,8 +322,6 @@ static int process_setup_tgid(const struct resource *res, const struct resource_control *ctrl, const void *data) { - char buf[BUFF_MAX]; - char *stat_fields[PROCESS_STAT_FIELD_MAX]; struct process_context *ctx; u_int64_t total_memory; int ret; @@ -328,20 +339,14 @@ static int process_setup_tgid(const struct resource *res, ctx->prev_total_time = get_total_cpu_time(); /* update initial status */ - ret = kernel_get_process_taskstats(&ctx->curr, ctx->tgid, false); - if (ret < 0) - return ret; - - ret = kernel_get_process_stat_fields(ctx->tgid, buf, BUFF_MAX, stat_fields); + ret = kernel_get_thread_group_taskstats(&ctx->curr, ctx->tgid, true); if (ret < 0) return ret; - /* save comm with removing parentheses */ - strncpy(ctx->comm, stat_fields[PROCESS_STAT_FIELD_COMM] + 1, - strlen(stat_fields[PROCESS_STAT_FIELD_COMM]) - 2 /* '(', ')' */); + memcpy(ctx->comm, ctx->curr.ac_comm, strlen(ctx->curr.ac_comm) + 1); - ctx->pgid = atoi(stat_fields[PROCESS_STAT_FIELD_PGID]); - ctx->ppid = atoi(stat_fields[PROCESS_STAT_FIELD_PPID]); + ctx->pgid = -1; + ctx->ppid = ctx->curr.ac_ppid; return 0; }