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 "configfile.h"
30 /* Include header files for the mach system, if they exist.. */
32 # if HAVE_MACH_MACH_INIT_H
33 # include <mach/mach_init.h>
35 # if HAVE_MACH_HOST_PRIV_H
36 # include <mach/host_priv.h>
38 # if HAVE_MACH_MACH_ERROR_H
39 # include <mach/mach_error.h>
41 # if HAVE_MACH_MACH_HOST_H
42 # include <mach/mach_host.h>
44 # if HAVE_MACH_MACH_PORT_H
45 # include <mach/mach_port.h>
47 # if HAVE_MACH_MACH_TYPES_H
48 # include <mach/mach_types.h>
50 # if HAVE_MACH_MESSAGE_H
51 # include <mach/message.h>
53 # if HAVE_MACH_PROCESSOR_SET_H
54 # include <mach/processor_set.h>
57 # include <mach/task.h>
59 # if HAVE_MACH_THREAD_ACT_H
60 # include <mach/thread_act.h>
62 # if HAVE_MACH_VM_REGION_H
63 # include <mach/vm_region.h>
65 # if HAVE_MACH_VM_MAP_H
66 # include <mach/vm_map.h>
68 # if HAVE_MACH_VM_PROT_H
69 # include <mach/vm_prot.h>
71 # if HAVE_SYS_SYSCTL_H
72 # include <sys/sysctl.h>
74 /* #endif HAVE_THREAD_INFO */
77 # if HAVE_LINUX_CONFIG_H
78 # include <linux/config.h>
81 # define CONFIG_HZ 100
83 #endif /* KERNEL_LINUX */
85 #define MODULE_NAME "processes"
87 #if HAVE_THREAD_INFO || KERNEL_LINUX
88 # define PROCESSES_HAVE_READ 1
90 # define PROCESSES_HAVE_READ 0
95 static data_source_t state_dsrc[1] =
97 {"value", DS_TYPE_GAUGE, 0.0, 65535.0}
100 static data_set_t state_ds =
102 "ps_state", 1, state_dsrc
105 static data_source_t rss_dsrc[1] =
108 {"value", DS_TYPE_GAUGE, 0.0, 9223372036854775807.0}
111 static data_set_t rss_ds =
113 "ps_rss", 1, rss_dsrc
116 static data_source_t time_dsrc[2] =
118 /* 1 second in user-mode per second ought to be enough.. */
119 {"user", DS_TYPE_COUNTER, 0.0, 1000000.0},
120 {"syst", DS_TYPE_COUNTER, 0.0, 1000000.0}
123 static data_set_t time_ds =
125 "ps_cputime", 2, time_dsrc
128 static data_source_t count_dsrc[2] =
130 /* 1 second in user-mode per second ought to be enough.. */
131 {"processes", DS_TYPE_GAUGE, 0.0, 1000000.0},
132 {"threads", DS_TYPE_GAUGE, 0.0, 1000000.0}
135 static data_set_t count_ds =
137 "ps_count", 2, count_dsrc
140 static data_source_t pagefaults_dsrc[2] =
143 {"minflt", DS_TYPE_COUNTER, 0.0, 9223372036854775807.0},
144 {"majflt", DS_TYPE_COUNTER, 0.0, 9223372036854775807.0}
147 static data_set_t pagefaults_ds =
149 "ps_pagefaults", 2, pagefaults_dsrc
152 #if PROCESSES_HAVE_READ
153 #if HAVE_THREAD_INFO | KERNEL_LINUX
154 static const char *config_keys[] =
159 static int config_keys_num = 1;
162 typedef struct procstat_entry_s
167 unsigned long num_proc;
168 unsigned long num_lwp;
169 unsigned long vmem_rss;
171 unsigned long vmem_minflt;
172 unsigned long vmem_majflt;
173 unsigned long vmem_minflt_counter;
174 unsigned long vmem_majflt_counter;
176 unsigned long cpu_user;
177 unsigned long cpu_system;
178 unsigned long cpu_user_counter;
179 unsigned long cpu_system_counter;
181 struct procstat_entry_s *next;
184 #define PROCSTAT_NAME_LEN 256
185 typedef struct procstat
187 char name[PROCSTAT_NAME_LEN];
189 unsigned long num_proc;
190 unsigned long num_lwp;
191 unsigned long vmem_rss;
193 unsigned long vmem_minflt_counter;
194 unsigned long vmem_majflt_counter;
196 unsigned long cpu_user_counter;
197 unsigned long cpu_system_counter;
199 struct procstat *next;
200 struct procstat_entry_s *instances;
203 #if HAVE_THREAD_INFO | KERNEL_LINUX
204 static procstat_t *list_head_g = NULL;
208 static mach_port_t port_host_self;
209 static mach_port_t port_task_self;
211 static processor_set_name_array_t pset_list;
212 static mach_msg_type_number_t pset_list_len;
213 /* #endif HAVE_THREAD_INFO */
216 static long pagesize_g;
217 #endif /* KERNEL_LINUX */
219 #if HAVE_THREAD_INFO | KERNEL_LINUX
220 static void ps_list_register (const char *name)
225 if ((new = (procstat_t *) malloc (sizeof (procstat_t))) == NULL)
227 memset (new, 0, sizeof (procstat_t));
228 strncpy (new->name, name, PROCSTAT_NAME_LEN);
230 for (ptr = list_head_g; ptr != NULL; ptr = ptr->next)
232 if (strcmp (ptr->name, name) == 0)
234 if (ptr->next == NULL)
244 static procstat_t *ps_list_search (const char *name)
248 for (ptr = list_head_g; ptr != NULL; ptr = ptr->next)
249 if (strcmp (ptr->name, name) == 0)
255 static void ps_list_add (const char *name, procstat_entry_t *entry)
258 procstat_entry_t *pse;
263 if ((ps = ps_list_search (name)) == NULL)
266 for (pse = ps->instances; pse != NULL; pse = pse->next)
267 if ((pse->id == entry->id) || (pse->next == NULL))
270 if ((pse == NULL) || (pse->id != entry->id))
272 procstat_entry_t *new;
274 new = (procstat_entry_t *) malloc (sizeof (procstat_entry_t));
277 memset (new, 0, sizeof (procstat_entry_t));
289 pse->num_proc = entry->num_proc;
290 pse->num_lwp = entry->num_lwp;
291 pse->vmem_rss = entry->vmem_rss;
293 ps->num_proc += pse->num_proc;
294 ps->num_lwp += pse->num_lwp;
295 ps->vmem_rss += pse->vmem_rss;
297 if ((entry->vmem_minflt_counter == 0)
298 && (entry->vmem_majflt_counter == 0))
300 pse->vmem_minflt_counter += entry->vmem_minflt;
301 pse->vmem_minflt = entry->vmem_minflt;
303 pse->vmem_majflt_counter += entry->vmem_majflt;
304 pse->vmem_majflt = entry->vmem_majflt;
308 if (entry->vmem_minflt_counter < pse->vmem_minflt_counter)
310 pse->vmem_minflt = entry->vmem_minflt_counter
311 + (ULONG_MAX - pse->vmem_minflt_counter);
315 pse->vmem_minflt = entry->vmem_minflt_counter - pse->vmem_minflt_counter;
317 pse->vmem_minflt_counter = entry->vmem_minflt_counter;
319 if (entry->vmem_majflt_counter < pse->vmem_majflt_counter)
321 pse->vmem_majflt = entry->vmem_majflt_counter
322 + (ULONG_MAX - pse->vmem_majflt_counter);
326 pse->vmem_majflt = entry->vmem_majflt_counter - pse->vmem_majflt_counter;
328 pse->vmem_majflt_counter = entry->vmem_majflt_counter;
331 ps->vmem_minflt_counter += pse->vmem_minflt;
332 ps->vmem_majflt_counter += pse->vmem_majflt;
334 if ((entry->cpu_user_counter == 0)
335 && (entry->cpu_system_counter == 0))
337 pse->cpu_user_counter += entry->cpu_user;
338 pse->cpu_user = entry->cpu_user;
340 pse->cpu_system_counter += entry->cpu_system;
341 pse->cpu_system = entry->cpu_system;
345 if (entry->cpu_user_counter < pse->cpu_user_counter)
347 pse->cpu_user = entry->cpu_user_counter
348 + (ULONG_MAX - pse->cpu_user_counter);
352 pse->cpu_user = entry->cpu_user_counter - pse->cpu_user_counter;
354 pse->cpu_user_counter = entry->cpu_user_counter;
356 if (entry->cpu_system_counter < pse->cpu_system_counter)
358 pse->cpu_system = entry->cpu_system_counter
359 + (ULONG_MAX - pse->cpu_system_counter);
363 pse->cpu_system = entry->cpu_system_counter - pse->cpu_system_counter;
365 pse->cpu_system_counter = entry->cpu_system_counter;
368 ps->cpu_user_counter += pse->cpu_user;
369 ps->cpu_system_counter += pse->cpu_system;
372 static void ps_list_reset (void)
375 procstat_entry_t *pse;
376 procstat_entry_t *pse_prev;
378 for (ps = list_head_g; ps != NULL; ps = ps->next)
390 DEBUG ("Removing this procstat entry cause it's too old: "
391 "id = %lu; name = %s;",
394 if (pse_prev == NULL)
396 ps->instances = pse->next;
402 pse_prev->next = pse->next;
404 pse = pse_prev->next;
413 } /* while (pse != NULL) */
414 } /* for (ps = list_head_g; ps != NULL; ps = ps->next) */
417 static int ps_config (const char *key, const char *value)
419 if (strcasecmp (key, "Process") == 0)
421 ps_list_register (value);
430 #endif /* HAVE_THREAD_INFO | KERNEL_LINUX */
432 static int ps_init (void)
435 kern_return_t status;
437 port_host_self = mach_host_self ();
438 port_task_self = mach_task_self ();
440 if (pset_list != NULL)
442 vm_deallocate (port_task_self,
443 (vm_address_t) pset_list,
444 pset_list_len * sizeof (processor_set_t));
449 if ((status = host_processor_sets (port_host_self,
451 &pset_list_len)) != KERN_SUCCESS)
453 ERROR ("host_processor_sets failed: %s\n",
454 mach_error_string (status));
459 /* #endif HAVE_THREAD_INFO */
462 pagesize_g = sysconf(_SC_PAGESIZE);
463 DEBUG ("pagesize_g = %li; CONFIG_HZ = %i;",
464 pagesize_g, CONFIG_HZ);
465 #endif /* KERNEL_LINUX */
470 static void ps_submit_state (const char *state, double value)
473 value_list_t vl = VALUE_LIST_INIT;
475 values[0].gauge = value;
479 vl.time = time (NULL);
480 strcpy (vl.host, hostname_g);
481 strcpy (vl.plugin, "processes");
482 strcpy (vl.plugin_instance, "");
483 strncpy (vl.type_instance, state, sizeof (vl.type_instance));
485 plugin_dispatch_values ("ps_state", &vl);
488 static void ps_submit_proc_list (procstat_t *ps)
491 value_list_t vl = VALUE_LIST_INIT;
495 vl.time = time (NULL);
496 strcpy (vl.host, hostname_g);
497 strcpy (vl.plugin, "processes");
498 strncpy (vl.plugin_instance, ps->name, sizeof (vl.plugin_instance));
500 vl.values[0].gauge = ps->vmem_rss;
502 plugin_dispatch_values ("ps_rss", &vl);
504 vl.values[0].counter = ps->cpu_user_counter;
505 vl.values[1].counter = ps->cpu_system_counter;
507 plugin_dispatch_values ("ps_cputime", &vl);
509 vl.values[0].gauge = ps->num_proc;
510 vl.values[1].gauge = ps->num_lwp;
512 plugin_dispatch_values ("ps_count", &vl);
514 vl.values[0].counter = ps->vmem_minflt_counter;
515 vl.values[1].counter = ps->vmem_majflt_counter;
517 plugin_dispatch_values ("ps_pagefaults", &vl);
519 DEBUG ("name = %s; num_proc = %lu; num_lwp = %lu; vmem_rss = %lu; "
520 "vmem_minflt_counter = %lu; vmem_majflt_counter = %lu; "
521 "cpu_user_counter = %lu; cpu_system_counter = %lu;",
522 ps->name, ps->num_proc, ps->num_lwp, ps->vmem_rss,
523 ps->vmem_minflt_counter, ps->vmem_majflt_counter,
524 ps->cpu_user_counter, ps->cpu_system_counter);
525 } /* void ps_submit_proc_list */
528 static int *ps_read_tasks (int pid)
531 int list_size = 1; /* size of allocated space, in elements */
532 int list_len = 0; /* number of currently used elements */
538 snprintf (dirname, 64, "/proc/%i/task", pid);
541 if ((dh = opendir (dirname)) == NULL)
543 DEBUG ("Failed to open directory `%s'", dirname);
547 while ((ent = readdir (dh)) != NULL)
549 if (!isdigit (ent->d_name[0]))
552 if ((list_len + 1) >= list_size)
555 int new_size = 2 * list_size;
556 /* Comes in sizes: 2, 4, 8, 16, ... */
558 new_ptr = (int *) realloc (list, (size_t) (sizeof (int) * new_size));
563 ERROR ("processes plugin: "
564 "Failed to allocate more memory.");
569 list_size = new_size;
571 memset (list + list_len, 0, sizeof (int) * (list_size - list_len));
574 list[list_len] = atoi (ent->d_name);
575 if (list[list_len] != 0)
581 assert (list_len < list_size);
582 assert (list[list_len] == 0);
587 int ps_read_process (int pid, procstat_t *ps, char *state)
602 long long unsigned cpu_user_counter;
603 long long unsigned cpu_system_counter;
604 long long unsigned vmem_rss;
606 memset (ps, 0, sizeof (procstat_t));
608 snprintf (filename, 64, "/proc/%i/stat", pid);
611 if ((fh = fopen (filename, "r")) == NULL)
614 if (fgets (buffer, 1024, fh) == NULL)
622 fields_len = strsplit (buffer, fields, 64);
625 DEBUG ("processes plugin: ps_read_process (pid = %i):"
626 " `%s' has only %i fields..",
627 (int) pid, filename, 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 DEBUG ("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 DEBUG ("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 DEBUG ("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 DEBUG ("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 ERROR ("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 ERROR ("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 ERROR ("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 ERROR ("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 ERROR ("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 DEBUG ("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 ERROR ("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
916 WARNING ("Unknown thread status: %s",
917 thread_data.run_state);
919 } /* switch (thread_data.run_state) */
921 if (task_list[task] != port_task_self)
923 status = mach_port_deallocate (port_task_self,
924 thread_list[thread]);
925 if (status != KERN_SUCCESS)
926 ERROR ("mach_port_deallocate failed: %s",
927 mach_error_string (status));
929 } /* for (thread_list) */
931 if ((status = vm_deallocate (port_task_self,
932 (vm_address_t) thread_list,
933 thread_list_len * sizeof (thread_act_t)))
936 ERROR ("vm_deallocate failed: %s",
937 mach_error_string (status));
942 /* Only deallocate the task port, if it isn't our own.
943 * Don't know what would happen in that case, but this
944 * is what Apple's top does.. ;) */
945 if (task_list[task] != port_task_self)
947 status = mach_port_deallocate (port_task_self,
949 if (status != KERN_SUCCESS)
950 ERROR ("mach_port_deallocate failed: %s",
951 mach_error_string (status));
955 ps_list_add (task_name, &pse);
956 } /* for (task_list) */
958 if ((status = vm_deallocate (port_task_self,
959 (vm_address_t) task_list,
960 task_list_len * sizeof (task_t))) != KERN_SUCCESS)
962 ERROR ("vm_deallocate failed: %s",
963 mach_error_string (status));
968 if ((status = mach_port_deallocate (port_task_self, port_pset_priv))
971 ERROR ("mach_port_deallocate failed: %s",
972 mach_error_string (status));
974 } /* for (pset_list) */
976 ps_submit_state ("running", running);
977 ps_submit_state ("sleeping", sleeping);
978 ps_submit_state ("zombies", zombies);
979 ps_submit_state ("stopped", stopped);
980 ps_submit_state ("blocked", blocked);
982 for (ps = list_head_g; ps != NULL; ps = ps->next)
983 ps_submit_proc_list (ps);
984 /* #endif HAVE_THREAD_INFO */
1000 procstat_entry_t pse;
1005 running = sleeping = zombies = stopped = paging = blocked = 0;
1008 if ((proc = opendir ("/proc")) == NULL)
1011 ERROR ("Cannot open `/proc': %s",
1012 sstrerror (errno, errbuf, sizeof (errbuf)));
1016 while ((ent = readdir (proc)) != NULL)
1018 if (!isdigit (ent->d_name[0]))
1021 if ((pid = atoi (ent->d_name)) < 1)
1024 status = ps_read_process (pid, &ps, &state);
1027 DEBUG ("ps_read_process failed: %i", status);
1034 pse.num_proc = ps.num_proc;
1035 pse.num_lwp = ps.num_lwp;
1036 pse.vmem_rss = ps.vmem_rss;
1038 pse.vmem_minflt = 0;
1039 pse.vmem_minflt_counter = ps.vmem_minflt_counter;
1040 pse.vmem_majflt = 0;
1041 pse.vmem_majflt_counter = ps.vmem_majflt_counter;
1044 pse.cpu_user_counter = ps.cpu_user_counter;
1046 pse.cpu_system_counter = ps.cpu_system_counter;
1050 case 'R': running++; break;
1051 case 'S': sleeping++; break;
1052 case 'D': blocked++; break;
1053 case 'Z': zombies++; break;
1054 case 'T': stopped++; break;
1055 case 'W': paging++; break;
1058 ps_list_add (ps.name, &pse);
1063 ps_submit_state ("running", running);
1064 ps_submit_state ("sleeping", sleeping);
1065 ps_submit_state ("zombies", zombies);
1066 ps_submit_state ("stopped", stopped);
1067 ps_submit_state ("paging", paging);
1068 ps_submit_state ("blocked", blocked);
1070 for (ps_ptr = list_head_g; ps_ptr != NULL; ps_ptr = ps_ptr->next)
1071 ps_submit_proc_list (ps_ptr);
1072 #endif /* KERNEL_LINUX */
1076 #endif /* PROCESSES_HAVE_READ */
1078 void module_register (modreg_e load)
1080 if (load & MR_DATASETS)
1082 plugin_register_data_set (&state_ds);
1083 plugin_register_data_set (&rss_ds);
1084 plugin_register_data_set (&time_ds);
1085 plugin_register_data_set (&count_ds);
1086 plugin_register_data_set (&pagefaults_ds);
1089 #if PROCESSES_HAVE_READ
1092 #if HAVE_THREAD_INFO | KERNEL_LINUX
1093 plugin_register_config ("processes", ps_config,
1094 config_keys, config_keys_num);
1096 plugin_register_init ("processes", ps_init);
1097 plugin_register_read ("processes", ps_read);
1099 #endif /* PROCESSES_HAVE_READ */
1100 } /* void module_register */