processes: change type to contextswitch and types to derive_t
[collectd.git] / src / processes.c
index c1f92a7..519d136 100644 (file)
@@ -223,7 +223,7 @@ typedef struct procstat
 
 static procstat_t *list_head_g = NULL;
 
-static _Bool ps_ctx_switch = 0;
+static _Bool report_ctx_switch = 0;
 
 #if HAVE_THREAD_INFO
 static mach_port_t port_host_self;
@@ -362,7 +362,7 @@ static int ps_list_match (const char *name, const char *cmdline, procstat_t *ps)
 static void ps_list_add (const char *name, const char *cmdline, procstat_entry_t *entry)
 {
        procstat_t *ps;
-        procstat_entry_t *pse;
+       procstat_entry_t *pse;
 
        if (entry->id == 0)
                return;
@@ -498,7 +498,6 @@ static void ps_list_add (const char *name, const char *cmdline, procstat_entry_t
 
                ps->cpu_user_counter   += pse->cpu_user;
                ps->cpu_system_counter += pse->cpu_system;
-
        }
 }
 
@@ -610,14 +609,7 @@ static int ps_config (oconfig_item_t *ci)
                }
                else if (strcasecmp (c->key, "CollectContextSwitch") == 0)
                {
-                       if ((c->values_num != 1) 
-                                       || (c->values[0].type != OCONFIG_TYPE_BOOLEAN))
-                       {
-                               ERROR ("processes plugin: `CollectContextSwitch' needs exactly "
-                                               "one boolean argument.");
-                               continue;
-                       }
-                       ps_ctx_switch = c->values[0].value.boolean ? 1 : 0;
+                       cf_util_get_boolean (c, &report_ctx_switch);
                }
                else
                {
@@ -768,14 +760,16 @@ static void ps_submit_proc_list (procstat_t *ps)
                plugin_dispatch_values (&vl);
        }
 
-       if ( ps_ctx_switch )
+       if ( report_ctx_switch )
        {
-               sstrncpy (vl.type, "ps_cswitch_vol", sizeof (vl.type));
+               sstrncpy (vl.type, "contextswitch", sizeof (vl.type));
+               sstrncpy (vl.type_instance, "voluntary", sizeof (vl.type_instance));
                vl.values[0].derive = ps->cswitch_vol;
                vl.values_len = 1;
                plugin_dispatch_values (&vl);
 
-               sstrncpy (vl.type, "ps_cswitch_invol", sizeof (vl.type));
+               sstrncpy (vl.type, "contextswitch", sizeof (vl.type));
+               sstrncpy (vl.type_instance, "involuntary", sizeof (vl.type_instance));
                vl.values[0].derive = ps->cswitch_invol;
                vl.values_len = 1;
                plugin_dispatch_values (&vl);
@@ -827,8 +821,8 @@ static procstat_t *ps_read_tasks_status (int pid, procstat_t *ps)
        char           filename[64];
        FILE          *fh;
        struct dirent *ent;
-       unsigned long long cswitch_vol = 0;
-       unsigned long long cswitch_invol = 0;
+       derive_t cswitch_vol = 0;
+       derive_t cswitch_invol = 0;
        char buffer[1024];
        char *fields[8];
        int numfields;
@@ -859,7 +853,7 @@ static procstat_t *ps_read_tasks_status (int pid, procstat_t *ps)
 
                while (fgets (buffer, sizeof(buffer), fh) != NULL)
                {
-                       long long tmp;
+                       derive_t tmp;
                        char *endptr;
 
                        if (strncmp (buffer, "voluntary_ctxt_switches", 23) != 0
@@ -874,7 +868,7 @@ static procstat_t *ps_read_tasks_status (int pid, procstat_t *ps)
 
                        errno = 0;
                        endptr = NULL;
-                       tmp = strtoll (fields[1], &endptr, /* base = */ 10);
+                       tmp = (derive_t) strtoll (fields[1], &endptr, /* base = */ 10);
                        if ((errno == 0) && (endptr != fields[1]))
                        {
                                if (strncmp (buffer, "voluntary_ctxt_switches", 23) == 0)
@@ -1193,7 +1187,7 @@ int ps_read_process (int pid, procstat_t *ps, char *state)
                DEBUG("ps_read_process: not get io data for pid %i",pid);
        }
 
-       if ( ps_ctx_switch )
+       if ( report_ctx_switch )
        {
                if ( (ps_read_tasks_status(pid, ps)) == NULL)
                {