2 * collectd - src/processes.c
3 * Copyright (C) 2005 Lyonel Vincent
4 * Copyright (C) 2006-2007 Florian Forster (Mach code)
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 * Lyonel Vincent <lyonel at ezix.org>
22 * Florian octo Forster <octo at verplant.org>
28 #include "utils_debug.h"
29 #include "configfile.h"
31 /* Include header files for the mach system, if they exist.. */
33 # if HAVE_MACH_MACH_INIT_H
34 # include <mach/mach_init.h>
36 # if HAVE_MACH_HOST_PRIV_H
37 # include <mach/host_priv.h>
39 # if HAVE_MACH_MACH_ERROR_H
40 # include <mach/mach_error.h>
42 # if HAVE_MACH_MACH_HOST_H
43 # include <mach/mach_host.h>
45 # if HAVE_MACH_MACH_PORT_H
46 # include <mach/mach_port.h>
48 # if HAVE_MACH_MACH_TYPES_H
49 # include <mach/mach_types.h>
51 # if HAVE_MACH_MESSAGE_H
52 # include <mach/message.h>
54 # if HAVE_MACH_PROCESSOR_SET_H
55 # include <mach/processor_set.h>
58 # include <mach/task.h>
60 # if HAVE_MACH_THREAD_ACT_H
61 # include <mach/thread_act.h>
63 # if HAVE_MACH_VM_REGION_H
64 # include <mach/vm_region.h>
66 # if HAVE_MACH_VM_MAP_H
67 # include <mach/vm_map.h>
69 # if HAVE_MACH_VM_PROT_H
70 # include <mach/vm_prot.h>
72 # if HAVE_SYS_SYSCTL_H
73 # include <sys/sysctl.h>
75 /* #endif HAVE_THREAD_INFO */
78 # if HAVE_LINUX_CONFIG_H
79 # include <linux/config.h>
82 # define CONFIG_HZ 100
84 #endif /* KERNEL_LINUX */
86 #define MODULE_NAME "processes"
88 #if HAVE_THREAD_INFO || KERNEL_LINUX
89 # define PROCESSES_HAVE_READ 1
91 # define PROCESSES_HAVE_READ 0
96 static data_source_t state_dsrc[1] =
98 {"value", DS_TYPE_GAUGE, 0.0, 65535.0}
101 static data_set_t state_ds =
103 "ps_state", 1, state_dsrc
106 static data_source_t rss_dsrc[1] =
109 {"value", DS_TYPE_GAUGE, 0.0, 9223372036854775807.0}
112 static data_set_t rss_ds =
114 "ps_rss", 1, rss_dsrc
117 static data_source_t time_dsrc[2] =
119 /* 1 second in user-mode per second ought to be enough.. */
120 {"user", DS_TYPE_COUNTER, 0.0, 1000000.0},
121 {"syst", DS_TYPE_COUNTER, 0.0, 1000000.0}
124 static data_set_t time_ds =
126 "ps_cputime", 2, time_dsrc
129 static data_source_t count_dsrc[2] =
131 /* 1 second in user-mode per second ought to be enough.. */
132 {"processes", DS_TYPE_GAUGE, 0.0, 1000000.0},
133 {"threads", DS_TYPE_GAUGE, 0.0, 1000000.0}
136 static data_set_t count_ds =
138 "ps_count", 2, count_dsrc
141 static data_source_t pagefaults_dsrc[2] =
144 {"minflt", DS_TYPE_COUNTER, 0.0, 9223372036854775807.0},
145 {"majflt", DS_TYPE_COUNTER, 0.0, 9223372036854775807.0}
148 static data_set_t pagefaults_ds =
150 "ps_pagefaults", 2, pagefaults_dsrc
153 #if PROCESSES_HAVE_READ
154 static const char *config_keys[] =
159 static int config_keys_num = 1;
161 typedef struct procstat_entry_s
166 unsigned long num_proc;
167 unsigned long num_lwp;
168 unsigned long vmem_rss;
170 unsigned long vmem_minflt;
171 unsigned long vmem_majflt;
172 unsigned long vmem_minflt_counter;
173 unsigned long vmem_majflt_counter;
175 unsigned long cpu_user;
176 unsigned long cpu_system;
177 unsigned long cpu_user_counter;
178 unsigned long cpu_system_counter;
180 struct procstat_entry_s *next;
183 #define PROCSTAT_NAME_LEN 256
184 typedef struct procstat
186 char name[PROCSTAT_NAME_LEN];
188 unsigned long num_proc;
189 unsigned long num_lwp;
190 unsigned long vmem_rss;
192 unsigned long vmem_minflt_counter;
193 unsigned long vmem_majflt_counter;
195 unsigned long cpu_user_counter;
196 unsigned long cpu_system_counter;
198 struct procstat *next;
199 struct procstat_entry_s *instances;
202 static procstat_t *list_head_g = NULL;
205 static mach_port_t port_host_self;
206 static mach_port_t port_task_self;
208 static processor_set_name_array_t pset_list;
209 static mach_msg_type_number_t pset_list_len;
210 /* #endif HAVE_THREAD_INFO */
213 static long pagesize_g;
214 #endif /* KERNEL_LINUX */
216 #if HAVE_THREAD_INFO | KERNEL_LINUX
217 static void ps_list_register (const char *name)
222 if ((new = (procstat_t *) malloc (sizeof (procstat_t))) == NULL)
224 memset (new, 0, sizeof (procstat_t));
225 strncpy (new->name, name, PROCSTAT_NAME_LEN);
227 for (ptr = list_head_g; ptr != NULL; ptr = ptr->next)
229 if (strcmp (ptr->name, name) == 0)
231 if (ptr->next == NULL)
241 static procstat_t *ps_list_search (const char *name)
245 for (ptr = list_head_g; ptr != NULL; ptr = ptr->next)
246 if (strcmp (ptr->name, name) == 0)
252 static void ps_list_add (const char *name, procstat_entry_t *entry)
255 procstat_entry_t *pse;
260 if ((ps = ps_list_search (name)) == NULL)
263 for (pse = ps->instances; pse != NULL; pse = pse->next)
264 if ((pse->id == entry->id) || (pse->next == NULL))
267 if ((pse == NULL) || (pse->id != entry->id))
269 procstat_entry_t *new;
271 new = (procstat_entry_t *) malloc (sizeof (procstat_entry_t));
274 memset (new, 0, sizeof (procstat_entry_t));
286 pse->num_proc = entry->num_proc;
287 pse->num_lwp = entry->num_lwp;
288 pse->vmem_rss = entry->vmem_rss;
290 ps->num_proc += pse->num_proc;
291 ps->num_lwp += pse->num_lwp;
292 ps->vmem_rss += pse->vmem_rss;
294 if ((entry->vmem_minflt_counter == 0)
295 && (entry->vmem_majflt_counter == 0))
297 pse->vmem_minflt_counter += entry->vmem_minflt;
298 pse->vmem_minflt = entry->vmem_minflt;
300 pse->vmem_majflt_counter += entry->vmem_majflt;
301 pse->vmem_majflt = entry->vmem_majflt;
305 if (entry->vmem_minflt_counter < pse->vmem_minflt_counter)
307 pse->vmem_minflt = entry->vmem_minflt_counter
308 + (ULONG_MAX - pse->vmem_minflt_counter);
312 pse->vmem_minflt = entry->vmem_minflt_counter - pse->vmem_minflt_counter;
314 pse->vmem_minflt_counter = entry->vmem_minflt_counter;
316 if (entry->vmem_majflt_counter < pse->vmem_majflt_counter)
318 pse->vmem_majflt = entry->vmem_majflt_counter
319 + (ULONG_MAX - pse->vmem_majflt_counter);
323 pse->vmem_majflt = entry->vmem_majflt_counter - pse->vmem_majflt_counter;
325 pse->vmem_majflt_counter = entry->vmem_majflt_counter;
328 ps->vmem_minflt_counter += pse->vmem_minflt;
329 ps->vmem_majflt_counter += pse->vmem_majflt;
331 if ((entry->cpu_user_counter == 0)
332 && (entry->cpu_system_counter == 0))
334 pse->cpu_user_counter += entry->cpu_user;
335 pse->cpu_user = entry->cpu_user;
337 pse->cpu_system_counter += entry->cpu_system;
338 pse->cpu_system = entry->cpu_system;
342 if (entry->cpu_user_counter < pse->cpu_user_counter)
344 pse->cpu_user = entry->cpu_user_counter
345 + (ULONG_MAX - pse->cpu_user_counter);
349 pse->cpu_user = entry->cpu_user_counter - pse->cpu_user_counter;
351 pse->cpu_user_counter = entry->cpu_user_counter;
353 if (entry->cpu_system_counter < pse->cpu_system_counter)
355 pse->cpu_system = entry->cpu_system_counter
356 + (ULONG_MAX - pse->cpu_system_counter);
360 pse->cpu_system = entry->cpu_system_counter - pse->cpu_system_counter;
362 pse->cpu_system_counter = entry->cpu_system_counter;
365 ps->cpu_user_counter += pse->cpu_user;
366 ps->cpu_system_counter += pse->cpu_system;
369 static void ps_list_reset (void)
372 procstat_entry_t *pse;
373 procstat_entry_t *pse_prev;
375 for (ps = list_head_g; ps != NULL; ps = ps->next)
387 DBG ("Removing this procstat entry cause it's too old: "
388 "id = %lu; name = %s;",
391 if (pse_prev == NULL)
393 ps->instances = pse->next;
399 pse_prev->next = pse->next;
401 pse = pse_prev->next;
410 } /* while (pse != NULL) */
411 } /* for (ps = list_head_g; ps != NULL; ps = ps->next) */
413 #endif /* HAVE_THREAD_INFO | KERNEL_LINUX */
415 static int ps_config (const char *key, const char *value)
417 if (strcasecmp (key, "Process") == 0)
419 ps_list_register (value);
429 static int ps_init (void)
432 kern_return_t status;
434 port_host_self = mach_host_self ();
435 port_task_self = mach_task_self ();
437 if (pset_list != NULL)
439 vm_deallocate (port_task_self,
440 (vm_address_t) pset_list,
441 pset_list_len * sizeof (processor_set_t));
446 if ((status = host_processor_sets (port_host_self,
448 &pset_list_len)) != KERN_SUCCESS)
450 syslog (LOG_ERR, "host_processor_sets failed: %s\n",
451 mach_error_string (status));
456 /* #endif HAVE_THREAD_INFO */
459 pagesize_g = sysconf(_SC_PAGESIZE);
460 DBG ("pagesize_g = %li; CONFIG_HZ = %i;",
461 pagesize_g, CONFIG_HZ);
462 #endif /* KERNEL_LINUX */
467 static void ps_submit_state (const char *state, double value)
470 value_list_t vl = VALUE_LIST_INIT;
472 values[0].gauge = value;
476 vl.time = time (NULL);
477 strcpy (vl.host, hostname);
478 strcpy (vl.plugin, "processes");
479 strcpy (vl.plugin_instance, "");
480 strncpy (vl.type_instance, state, sizeof (vl.type_instance));
482 plugin_dispatch_values ("ps_state", &vl);
485 static void ps_submit_proc_list (procstat_t *ps)
488 value_list_t vl = VALUE_LIST_INIT;
492 vl.time = time (NULL);
493 strcpy (vl.host, hostname);
494 strcpy (vl.plugin, "processes");
495 strncpy (vl.plugin_instance, ps->name, sizeof (vl.plugin_instance));
497 vl.values[0].gauge = ps->vmem_rss;
499 plugin_dispatch_values ("ps_rss", &vl);
501 vl.values[0].counter = ps->cpu_user_counter;
502 vl.values[1].counter = ps->cpu_system_counter;
504 plugin_dispatch_values ("ps_cputime", &vl);
506 vl.values[0].gauge = ps->num_proc;
507 vl.values[1].gauge = ps->num_lwp;
509 plugin_dispatch_values ("ps_count", &vl);
511 vl.values[0].counter = ps->vmem_minflt_counter;
512 vl.values[1].counter = ps->vmem_majflt_counter;
514 plugin_dispatch_values ("ps_pagefaults", &vl);
516 DBG ("name = %s; num_proc = %lu; num_lwp = %lu; vmem_rss = %lu; "
517 "vmem_minflt_counter = %lu; vmem_majflt_counter = %lu; "
518 "cpu_user_counter = %lu; cpu_system_counter = %lu;",
519 ps->name, ps->num_proc, ps->num_lwp, ps->vmem_rss,
520 ps->vmem_minflt_counter, ps->vmem_majflt_counter,
521 ps->cpu_user_counter, ps->cpu_system_counter);
522 } /* void ps_submit_proc_list */
525 static int *ps_read_tasks (int pid)
528 int list_size = 1; /* size of allocated space, in elements */
529 int list_len = 0; /* number of currently used elements */
535 snprintf (dirname, 64, "/proc/%i/task", pid);
538 if ((dh = opendir (dirname)) == NULL)
540 DBG ("Failed to open directory `%s'", dirname);
544 while ((ent = readdir (dh)) != NULL)
546 if (!isdigit (ent->d_name[0]))
549 if ((list_len + 1) >= list_size)
552 int new_size = 2 * list_size;
553 /* Comes in sizes: 2, 4, 8, 16, ... */
555 new_ptr = (int *) realloc (list, (size_t) (sizeof (int) * new_size));
560 syslog (LOG_ERR, "processes plugin: "
561 "Failed to allocate more memory.");
566 list_size = new_size;
568 memset (list + list_len, 0, sizeof (int) * (list_size - list_len));
571 list[list_len] = atoi (ent->d_name);
572 if (list[list_len] != 0)
578 assert (list_len < list_size);
579 assert (list[list_len] == 0);
584 int ps_read_process (int pid, procstat_t *ps, char *state)
599 long long unsigned cpu_user_counter;
600 long long unsigned cpu_system_counter;
601 long long unsigned vmem_rss;
603 memset (ps, 0, sizeof (procstat_t));
605 snprintf (filename, 64, "/proc/%i/stat", pid);
608 if ((fh = fopen (filename, "r")) == NULL)
611 if (fgets (buffer, 1024, fh) == NULL)
619 fields_len = strsplit (buffer, fields, 64);
622 DBG ("`%s' has only %i fields..",
623 filename, fields_len);
626 else if (fields_len != 41)
628 DBG ("WARNING: (fields_len = %i) != 41", fields_len);
631 /* copy the name, strip brackets in the process */
632 name_len = strlen (fields[1]) - 2;
633 if ((fields[1][0] != '(') || (fields[1][name_len + 1] != ')'))
635 DBG ("No brackets found in process name: `%s'", fields[1]);
638 fields[1] = fields[1] + 1;
639 fields[1][name_len] = '\0';
640 strncpy (ps->name, fields[1], PROCSTAT_NAME_LEN);
642 ppid = atoi (fields[3]);
644 if ((tasks = ps_read_tasks (pid)) == NULL)
646 /* This happends for zombied, e.g. */
647 DBG ("ps_read_tasks (%i) failed.", pid);
657 for (i = 0; tasks[i] != 0; i++)
664 /* Leave the rest at zero if this is only an LWP */
665 if (ps->num_proc == 0)
667 DBG ("This is only an LWP: pid = %i; name = %s;",
672 cpu_user_counter = atoll (fields[13]);
673 cpu_system_counter = atoll (fields[14]);
674 vmem_rss = atoll (fields[23]);
675 ps->vmem_minflt_counter = atol (fields[9]);
676 ps->vmem_majflt_counter = atol (fields[11]);
678 /* Convert jiffies to useconds */
679 cpu_user_counter = cpu_user_counter * 1000000 / CONFIG_HZ;
680 cpu_system_counter = cpu_system_counter * 1000000 / CONFIG_HZ;
681 vmem_rss = vmem_rss * pagesize_g;
683 ps->cpu_user_counter = (unsigned long) cpu_user_counter;
684 ps->cpu_system_counter = (unsigned long) cpu_system_counter;
685 ps->vmem_rss = (unsigned long) vmem_rss;
687 *state = fields[2][0];
691 } /* int ps_read_process (...) */
692 #endif /* KERNEL_LINUX */
695 static int mach_get_task_name (task_t t, int *pid, char *name, size_t name_max_len)
699 struct kinfo_proc kp;
704 mib[2] = KERN_PROC_PID;
706 if (pid_for_task (t, pid) != KERN_SUCCESS)
710 kp_size = sizeof (kp);
711 if (sysctl (mib, 4, &kp, &kp_size, NULL, 0) != 0)
714 if (name_max_len > (MAXCOMLEN + 1))
715 name_max_len = MAXCOMLEN + 1;
717 strncpy (name, kp.kp_proc.p_comm, name_max_len - 1);
718 name[name_max_len - 1] = '\0';
720 DBG ("pid = %i; name = %s;", *pid, name);
722 /* We don't do the special handling for `p_comm == "LaunchCFMApp"' as
723 * `top' does it, because it is a lot of work and only used when
724 * debugging. -octo */
728 #endif /* HAVE_THREAD_INFO */
730 static int ps_read (void)
733 kern_return_t status;
736 processor_set_t port_pset_priv;
739 task_array_t task_list;
740 mach_msg_type_number_t task_list_len;
743 char task_name[MAXCOMLEN + 1];
746 thread_act_array_t thread_list;
747 mach_msg_type_number_t thread_list_len;
748 thread_basic_info_data_t thread_data;
749 mach_msg_type_number_t thread_data_len;
758 procstat_entry_t pse;
763 * The Mach-concept is a little different from the traditional UNIX
764 * concept: All the work is done in threads. Threads are contained in
765 * `tasks'. Therefore, `task status' doesn't make much sense, since
766 * it's actually a `thread status'.
767 * Tasks are assigned to sets of processors, so that's where you go to
770 for (pset = 0; pset < pset_list_len; pset++)
772 if ((status = host_processor_set_priv (port_host_self,
774 &port_pset_priv)) != KERN_SUCCESS)
776 syslog (LOG_ERR, "host_processor_set_priv failed: %s\n",
777 mach_error_string (status));
781 if ((status = processor_set_tasks (port_pset_priv,
783 &task_list_len)) != KERN_SUCCESS)
785 syslog (LOG_ERR, "processor_set_tasks failed: %s\n",
786 mach_error_string (status));
787 mach_port_deallocate (port_task_self, port_pset_priv);
791 for (task = 0; task < task_list_len; task++)
794 if (mach_get_task_name (task_list[task],
796 task_name, PROCSTAT_NAME_LEN) == 0)
797 ps = ps_list_search (task_name);
799 /* Collect more detailed statistics for this process */
802 task_basic_info_data_t task_basic_info;
803 mach_msg_type_number_t task_basic_info_len;
804 task_events_info_data_t task_events_info;
805 mach_msg_type_number_t task_events_info_len;
806 task_absolutetime_info_data_t task_absolutetime_info;
807 mach_msg_type_number_t task_absolutetime_info_len;
809 memset (&pse, '\0', sizeof (pse));
812 task_basic_info_len = TASK_BASIC_INFO_COUNT;
813 status = task_info (task_list[task],
815 (task_info_t) &task_basic_info,
816 &task_basic_info_len);
817 if (status != KERN_SUCCESS)
819 syslog (LOG_ERR, "task_info failed: %s",
820 mach_error_string (status));
821 continue; /* with next thread_list */
824 task_events_info_len = TASK_EVENTS_INFO_COUNT;
825 status = task_info (task_list[task],
827 (task_info_t) &task_events_info,
828 &task_events_info_len);
829 if (status != KERN_SUCCESS)
831 syslog (LOG_ERR, "task_info failed: %s",
832 mach_error_string (status));
833 continue; /* with next thread_list */
836 task_absolutetime_info_len = TASK_ABSOLUTETIME_INFO_COUNT;
837 status = task_info (task_list[task],
838 TASK_ABSOLUTETIME_INFO,
839 (task_info_t) &task_absolutetime_info,
840 &task_absolutetime_info_len);
841 if (status != KERN_SUCCESS)
843 syslog (LOG_ERR, "task_info failed: %s",
844 mach_error_string (status));
845 continue; /* with next thread_list */
849 pse.vmem_rss = task_basic_info.resident_size;
851 pse.vmem_minflt_counter = task_events_info.cow_faults;
852 pse.vmem_majflt_counter = task_events_info.faults;
854 pse.cpu_user_counter = task_absolutetime_info.total_user;
855 pse.cpu_system_counter = task_absolutetime_info.total_system;
858 status = task_threads (task_list[task], &thread_list,
860 if (status != KERN_SUCCESS)
862 /* Apple's `top' treats this case a zombie. It
863 * makes sense to some extend: A `zombie'
864 * thread is nonsense, since the task/process
867 DBG ("task_threads failed: %s",
868 mach_error_string (status));
869 if (task_list[task] != port_task_self)
870 mach_port_deallocate (port_task_self,
872 continue; /* with next task_list */
875 for (thread = 0; thread < thread_list_len; thread++)
877 thread_data_len = THREAD_BASIC_INFO_COUNT;
878 status = thread_info (thread_list[thread],
880 (thread_info_t) &thread_data,
882 if (status != KERN_SUCCESS)
884 syslog (LOG_ERR, "thread_info failed: %s",
885 mach_error_string (status));
886 if (task_list[task] != port_task_self)
887 mach_port_deallocate (port_task_self,
888 thread_list[thread]);
889 continue; /* with next thread_list */
895 switch (thread_data.run_state)
897 case TH_STATE_RUNNING:
900 case TH_STATE_STOPPED:
901 /* What exactly is `halted'? */
902 case TH_STATE_HALTED:
905 case TH_STATE_WAITING:
908 case TH_STATE_UNINTERRUPTIBLE:
911 /* There is no `zombie' case here,
912 * since there are no zombie-threads.
913 * There's only zombie tasks, which are
917 "Unknown thread status: %s",
918 thread_data.run_state);
920 } /* switch (thread_data.run_state) */
922 if (task_list[task] != port_task_self)
924 status = mach_port_deallocate (port_task_self,
925 thread_list[thread]);
926 if (status != KERN_SUCCESS)
927 syslog (LOG_ERR, "mach_port_deallocate failed: %s",
928 mach_error_string (status));
930 } /* for (thread_list) */
932 if ((status = vm_deallocate (port_task_self,
933 (vm_address_t) thread_list,
934 thread_list_len * sizeof (thread_act_t)))
937 syslog (LOG_ERR, "vm_deallocate failed: %s",
938 mach_error_string (status));
943 /* Only deallocate the task port, if it isn't our own.
944 * Don't know what would happen in that case, but this
945 * is what Apple's top does.. ;) */
946 if (task_list[task] != port_task_self)
948 status = mach_port_deallocate (port_task_self,
950 if (status != KERN_SUCCESS)
951 syslog (LOG_ERR, "mach_port_deallocate failed: %s",
952 mach_error_string (status));
956 ps_list_add (task_name, &pse);
957 } /* for (task_list) */
959 if ((status = vm_deallocate (port_task_self,
960 (vm_address_t) task_list,
961 task_list_len * sizeof (task_t))) != KERN_SUCCESS)
963 syslog (LOG_ERR, "vm_deallocate failed: %s",
964 mach_error_string (status));
969 if ((status = mach_port_deallocate (port_task_self, port_pset_priv))
972 syslog (LOG_ERR, "mach_port_deallocate failed: %s",
973 mach_error_string (status));
975 } /* for (pset_list) */
977 ps_submit_state ("running", running);
978 ps_submit_state ("sleeping", sleeping);
979 ps_submit_state ("zombies", zombies);
980 ps_submit_state ("stopped", stopped);
981 ps_submit_state ("blocked", blocked);
983 for (ps = list_head_g; ps != NULL; ps = ps->next)
984 ps_submit_proc_list (ps);
985 /* #endif HAVE_THREAD_INFO */
1001 procstat_entry_t pse;
1006 running = sleeping = zombies = stopped = paging = blocked = 0;
1009 if ((proc = opendir ("/proc")) == NULL)
1011 syslog (LOG_ERR, "Cannot open `/proc': %s", strerror (errno));
1015 while ((ent = readdir (proc)) != NULL)
1017 if (!isdigit (ent->d_name[0]))
1020 if ((pid = atoi (ent->d_name)) < 1)
1023 status = ps_read_process (pid, &ps, &state);
1026 DBG ("ps_read_process failed: %i", status);
1033 pse.num_proc = ps.num_proc;
1034 pse.num_lwp = ps.num_lwp;
1035 pse.vmem_rss = ps.vmem_rss;
1037 pse.vmem_minflt = 0;
1038 pse.vmem_minflt_counter = ps.vmem_minflt_counter;
1039 pse.vmem_majflt = 0;
1040 pse.vmem_majflt_counter = ps.vmem_majflt_counter;
1043 pse.cpu_user_counter = ps.cpu_user_counter;
1045 pse.cpu_system_counter = ps.cpu_system_counter;
1049 case 'R': running++; break;
1050 case 'S': sleeping++; break;
1051 case 'D': blocked++; break;
1052 case 'Z': zombies++; break;
1053 case 'T': stopped++; break;
1054 case 'W': paging++; break;
1057 ps_list_add (ps.name, &pse);
1062 ps_submit_state ("running", running);
1063 ps_submit_state ("sleeping", sleeping);
1064 ps_submit_state ("zombies", zombies);
1065 ps_submit_state ("stopped", stopped);
1066 ps_submit_state ("paging", paging);
1067 ps_submit_state ("blocked", blocked);
1069 for (ps_ptr = list_head_g; ps_ptr != NULL; ps_ptr = ps_ptr->next)
1070 ps_submit_proc_list (ps_ptr);
1071 #endif /* KERNEL_LINUX */
1075 #endif /* PROCESSES_HAVE_READ */
1077 void module_register (void)
1079 plugin_register_data_set (&state_ds);
1080 plugin_register_data_set (&rss_ds);
1081 plugin_register_data_set (&time_ds);
1082 plugin_register_data_set (&count_ds );
1083 plugin_register_data_set (&pagefaults_ds );
1085 #if PROCESSES_HAVE_READ
1086 plugin_register_config ("processes", ps_config,
1087 config_keys, config_keys_num);
1088 plugin_register_init ("processes", ps_init);
1089 plugin_register_read ("processes", ps_read);
1090 #endif /* PROCESSES_HAVE_READ */