diff mbox series

[ovs-dev,1/2] process: Extend get_process_info() for additional fields.

Message ID 1510174167-71108-1-git-send-email-bhanuprakash.bodireddy@intel.com
State Accepted
Headers show
Series [ovs-dev,1/2] process: Extend get_process_info() for additional fields. | expand

Commit Message

Bodireddy, Bhanuprakash Nov. 8, 2017, 8:49 p.m. UTC
This commit enables the fields relating to process name and the core
number the process was last scheduled. The fields will be used by keepalive
monitoring framework in future commits.

This commit also fixes the following "sparse" warning:

  lib/process.c:439:16: error: use of assignment suppression and length
  modifier together in gnu_scanf format [-Werror=format=].

Signed-off-by: Bhanuprakash Bodireddy <bhanuprakash.bodireddy@intel.com>
---
 lib/process.c | 43 +++++++++++++++++++++++--------------------
 lib/process.h |  2 ++
 2 files changed, 25 insertions(+), 20 deletions(-)

Comments

Ben Pfaff Nov. 28, 2017, 11:56 p.m. UTC | #1
On Wed, Nov 08, 2017 at 08:49:26PM +0000, Bhanuprakash Bodireddy wrote:
> This commit enables the fields relating to process name and the core
> number the process was last scheduled. The fields will be used by keepalive
> monitoring framework in future commits.
> 
> This commit also fixes the following "sparse" warning:
> 
>   lib/process.c:439:16: error: use of assignment suppression and length
>   modifier together in gnu_scanf format [-Werror=format=].
> 
> Signed-off-by: Bhanuprakash Bodireddy <bhanuprakash.bodireddy@intel.com>

Applied to master, thanks!
diff mbox series

Patch

diff --git a/lib/process.c b/lib/process.c
index dd678cd..78de4b8 100644
--- a/lib/process.c
+++ b/lib/process.c
@@ -64,7 +64,8 @@  struct raw_process_info {
     long long int uptime;       /* ms since started. */
     long long int cputime;      /* ms of CPU used during 'uptime'. */
     pid_t ppid;                 /* Parent. */
-    char name[18];              /* Name (surrounded by parentheses). */
+    int core_id;                /* Core id last executed on. */
+    char name[18];              /* Name. */
 };
 
 /* Pipe used to signal child termination. */
@@ -421,7 +422,7 @@  get_raw_process_info(pid_t pid, struct raw_process_info *raw)
 
     n = fscanf(stream,
                "%*d "           /* (1. pid) */
-               "%17s "          /* 2. process name */
+               "(%17[^)]) "     /* 2. process name */
                "%*c "           /* (3. state) */
                "%lu "           /* 4. ppid */
                "%*d "           /* (5. pgid) */
@@ -444,33 +445,34 @@  get_raw_process_info(pid_t pid, struct raw_process_info *raw)
                "%llu "          /* 22. start_time */
                "%llu "          /* 23. vsize */
                "%llu "          /* 24. rss */
+               "%*u "           /* (25. rsslim) */
+               "%*u "           /* (26. start_code) */
+               "%*u "           /* (27. end_code) */
+               "%*u "           /* (28. start_stack) */
+               "%*u "           /* (29. esp) */
+               "%*u "           /* (30. eip) */
+               "%*u "           /* (31. pending signals) */
+               "%*u "           /* (32. blocked signals) */
+               "%*u "           /* (33. ignored signals) */
+               "%*u "           /* (34. caught signals) */
+               "%*u "           /* (35. whcan) */
+               "%*u "           /* (36. always 0) */
+               "%*u "           /* (37. always 0) */
+               "%*d "           /* (38. exit_signal) */
+               "%d "            /* 39. task_cpu */
 #if 0
                /* These are here for documentation but #if'd out to save
                 * actually parsing them from the stream for no benefit. */
-               "%*lu "          /* (25. rsslim) */
-               "%*lu "          /* (26. start_code) */
-               "%*lu "          /* (27. end_code) */
-               "%*lu "          /* (28. start_stack) */
-               "%*lu "          /* (29. esp) */
-               "%*lu "          /* (30. eip) */
-               "%*lu "          /* (31. pending signals) */
-               "%*lu "          /* (32. blocked signals) */
-               "%*lu "          /* (33. ignored signals) */
-               "%*lu "          /* (34. caught signals) */
-               "%*lu "          /* (35. whcan) */
-               "%*lu "          /* (36. always 0) */
-               "%*lu "          /* (37. always 0) */
-               "%*d "           /* (38. exit_signal) */
-               "%*d "           /* (39. task_cpu) */
                "%*u "           /* (40. rt_priority) */
                "%*u "           /* (41. policy) */
                "%*llu "         /* (42. blkio_ticks) */
                "%*lu "          /* (43. gtime) */
                "%*ld"           /* (44. cgtime) */
 #endif
-               , raw->name, &ppid, &utime, &stime, &start_time, &vsize, &rss);
+               , raw->name, &ppid, &utime, &stime, &start_time,
+                  &vsize, &rss, &raw->core_id);
     fclose(stream);
-    if (n != 7) {
+    if (n != 8) {
         VLOG_ERR_ONCE("%s: fscanf failed", file_name);
         return false;
     }
@@ -496,12 +498,14 @@  get_process_info(pid_t pid, struct process_info *pinfo)
         return false;
     }
 
+    ovs_strlcpy(pinfo->name, child.name, sizeof pinfo->name);
     pinfo->vsz = child.vsz;
     pinfo->rss = child.rss;
     pinfo->booted = child.uptime;
     pinfo->crashes = 0;
     pinfo->uptime = child.uptime;
     pinfo->cputime = child.cputime;
+    pinfo->core_id = child.core_id;
 
     if (child.ppid) {
         struct raw_process_info parent;
@@ -579,7 +583,6 @@  process_run(void)
 #endif
 }
 
-
 /* Causes the next call to poll_block() to wake up when process 'p' has
  * exited. */
 void
diff --git a/lib/process.h b/lib/process.h
index 999ac68..8c52820 100644
--- a/lib/process.h
+++ b/lib/process.h
@@ -29,6 +29,8 @@  struct process_info {
     int crashes;                /* # of crashes (usually 0). */
     long long int uptime;       /* ms since last (re)started by monitor. */
     long long int cputime;      /* ms of CPU used during 'uptime'. */
+    int core_id;
+    char name[18];
 };
 
 /* Starting and monitoring subprocesses.