summaryrefslogtreecommitdiffstats
path: root/binding
diff options
context:
space:
mode:
authorVitaly Wool <vitaly.wool@konsulko.com>2019-03-03 23:04:24 +0100
committerVitaly Wool <vitaly.wool@konsulko.com>2019-03-07 17:14:21 +0100
commitf457ab6fcf8bd3df530636bfa795a0c0fd18bdba (patch)
tree24eced9b1f46b56bde75f3ead36fd4ebe885ed28 /binding
parent84499d67fb23aa6268fd0fde4c8a040f1b40092e (diff)
Fill out extra info for a process
Per request from the front-end, obtain extended information for the process specified by tid, and compose reply with that info. Change-Id: I514e20581b1a3513f68495b74e1f4c2f839870ad Signed-off-by: Vitaly Wool <vitaly.wool@konsulko.com>
Diffstat (limited to 'binding')
-rw-r--r--binding/task-manager-binding.c55
1 files changed, 54 insertions, 1 deletions
diff --git a/binding/task-manager-binding.c b/binding/task-manager-binding.c
index 16bbf9f..c9946c2 100644
--- a/binding/task-manager-binding.c
+++ b/binding/task-manager-binding.c
@@ -129,6 +129,52 @@ void kill_process(struct afb_req request)
/* we don't signal success, there's no use for it */
}
+void get_extra_info(struct afb_req request)
+{
+ struct json_object *ret_json, *json_obj;
+ json_object *req = afb_req_json(request);
+ int tid = json_object_get_int(req);
+
+ ret_json = json_object_new_object();
+ json_obj = json_object_new_object();
+
+ char path[32];
+ char str_val[256];
+ char param[80];
+
+ sprintf(path, "/proc/%d/sched", tid);
+ FILE *fsched = fopen(path, "r");
+
+ if (fsched == NULL) {
+ afb_req_fail(request, "Failed", "Error processing arguments.");
+ }
+ else {
+ json_object_object_add(json_obj, "tid", json_object_new_int(tid));
+
+ fscanf(fsched, "%255s", str_val);
+ json_object_object_add(json_obj, "cmd", json_object_new_string(str_val));
+
+ fscanf(fsched, "%*s"); // the '-' line
+ while (!feof(fsched)) {
+ fscanf(fsched, "%79s%*s%255s", param, str_val);
+ if (strstr(param, "exec_start"))
+ json_object_object_add(json_obj, "exec_start", json_object_new_string(str_val));
+ else if (strstr(param, "vruntime"))
+ json_object_object_add(json_obj, "vruntime", json_object_new_string(str_val));
+ else if (strstr(param, "sum_exec_runtime"))
+ json_object_object_add(json_obj, "sum_exec_runtime", json_object_new_string(str_val));
+ else if (strstr(param, "prio"))
+ json_object_object_add(json_obj, "prio", json_object_new_string(str_val));
+ }
+ }
+ fclose(fsched);
+
+ json_object_object_add(ret_json, "msgType", json_object_new_string("extraInfo"));
+ json_object_object_add(ret_json, "info", json_obj);
+
+ afb_req_success(request, ret_json, NULL);
+}
+
int fill_pstat(proc_t *proc_info, struct pstat *pstat_values)
{
@@ -196,7 +242,14 @@ static const struct afb_verb_v2 _afb_verbs_v2_taskmanager[] = {
.auth = NULL,
.info = "Kill the process specified by tid",
.session = AFB_SESSION_NONE_V2
- }
+ },
+ {
+ .verb = "get_extra_info",
+ .callback = get_extra_info,
+ .auth = NULL,
+ .info = "Get exta info about current process",
+ .session = AFB_SESSION_NONE_V2
+ },
};