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 #if HAVE_THREAD_INFO | KERNEL_LINUX
155 static const char *config_keys[] =
160 static int config_keys_num = 1;
163 typedef struct procstat_entry_s
168 unsigned long num_proc;
169 unsigned long num_lwp;
170 unsigned long vmem_rss;
172 unsigned long vmem_minflt;
173 unsigned long vmem_majflt;
174 unsigned long vmem_minflt_counter;
175 unsigned long vmem_majflt_counter;
177 unsigned long cpu_user;
178 unsigned long cpu_system;
179 unsigned long cpu_user_counter;
180 unsigned long cpu_system_counter;
182 struct procstat_entry_s *next;
185 #define PROCSTAT_NAME_LEN 256
186 typedef struct procstat
188 char name[PROCSTAT_NAME_LEN];
190 unsigned long num_proc;
191 unsigned long num_lwp;
192 unsigned long vmem_rss;
194 unsigned long vmem_minflt_counter;
195 unsigned long vmem_majflt_counter;
197 unsigned long cpu_user_counter;
198 unsigned long cpu_system_counter;
200 struct procstat *next;
201 struct procstat_entry_s *instances;
204 #if HAVE_THREAD_INFO | KERNEL_LINUX
205 static procstat_t *list_head_g = NULL;
209 static mach_port_t port_host_self;
210 static mach_port_t port_task_self;
212 static processor_set_name_array_t pset_list;
213 static mach_msg_type_number_t pset_list_len;
214 /* #endif HAVE_THREAD_INFO */
217 static long pagesize_g;
218 #endif /* KERNEL_LINUX */
220 #if HAVE_THREAD_INFO | KERNEL_LINUX
221 static void ps_list_register (const char *name)
226 if ((new = (procstat_t *) malloc (sizeof (procstat_t))) == NULL)
228 memset (new, 0, sizeof (procstat_t));
229 strncpy (new->name, name, PROCSTAT_NAME_LEN);
231 for (ptr = list_head_g; ptr != NULL; ptr = ptr->next)
233 if (strcmp (ptr->name, name) == 0)
235 if (ptr->next == NULL)
245 static procstat_t *ps_list_search (const char *name)
249 for (ptr = list_head_g; ptr != NULL; ptr = ptr->next)
250 if (strcmp (ptr->name, name) == 0)
256 static void ps_list_add (const char *name, procstat_entry_t *entry)
259 procstat_entry_t *pse;
264 if ((ps = ps_list_search (name)) == NULL)
267 for (pse = ps->instances; pse != NULL; pse = pse->next)
268 if ((pse->id == entry->id) || (pse->next == NULL))
271 if ((pse == NULL) || (pse->id != entry->id))
273 procstat_entry_t *new;
275 new = (procstat_entry_t *) malloc (sizeof (procstat_entry_t));
278 memset (new, 0, sizeof (procstat_entry_t));
290 pse->num_proc = entry->num_proc;
291 pse->num_lwp = entry->num_lwp;
292 pse->vmem_rss = entry->vmem_rss;
294 ps->num_proc += pse->num_proc;
295 ps->num_lwp += pse->num_lwp;
296 ps->vmem_rss += pse->vmem_rss;
298 if ((entry->vmem_minflt_counter == 0)
299 && (entry->vmem_majflt_counter == 0))
301 pse->vmem_minflt_counter += entry->vmem_minflt;
302 pse->vmem_minflt = entry->vmem_minflt;
304 pse->vmem_majflt_counter += entry->vmem_majflt;
305 pse->vmem_majflt = entry->vmem_majflt;
309 if (entry->vmem_minflt_counter < pse->vmem_minflt_counter)
311 pse->vmem_minflt = entry->vmem_minflt_counter
312 + (ULONG_MAX - pse->vmem_minflt_counter);
316 pse->vmem_minflt = entry->vmem_minflt_counter - pse->vmem_minflt_counter;
318 pse->vmem_minflt_counter = entry->vmem_minflt_counter;
320 if (entry->vmem_majflt_counter < pse->vmem_majflt_counter)
322 pse->vmem_majflt = entry->vmem_majflt_counter
323 + (ULONG_MAX - pse->vmem_majflt_counter);
327 pse->vmem_majflt = entry->vmem_majflt_counter - pse->vmem_majflt_counter;
329 pse->vmem_majflt_counter = entry->vmem_majflt_counter;
332 ps->vmem_minflt_counter += pse->vmem_minflt;
333 ps->vmem_majflt_counter += pse->vmem_majflt;
335 if ((entry->cpu_user_counter == 0)
336 && (entry->cpu_system_counter == 0))
338 pse->cpu_user_counter += entry->cpu_user;
339 pse->cpu_user = entry->cpu_user;
341 pse->cpu_system_counter += entry->cpu_system;
342 pse->cpu_system = entry->cpu_system;
346 if (entry->cpu_user_counter < pse->cpu_user_counter)
348 pse->cpu_user = entry->cpu_user_counter
349 + (ULONG_MAX - pse->cpu_user_counter);
353 pse->cpu_user = entry->cpu_user_counter - pse->cpu_user_counter;
355 pse->cpu_user_counter = entry->cpu_user_counter;
357 if (entry->cpu_system_counter < pse->cpu_system_counter)
359 pse->cpu_system = entry->cpu_system_counter
360 + (ULONG_MAX - pse->cpu_system_counter);
364 pse->cpu_system = entry->cpu_system_counter - pse->cpu_system_counter;
366 pse->cpu_system_counter = entry->cpu_system_counter;
369 ps->cpu_user_counter += pse->cpu_user;
370 ps->cpu_system_counter += pse->cpu_system;
373 static void ps_list_reset (void)
376 procstat_entry_t *pse;
377 procstat_entry_t *pse_prev;
379 for (ps = list_head_g; ps != NULL; ps = ps->next)
391 DBG ("Removing this procstat entry cause it's too old: "
392 "id = %lu; name = %s;",
395 if (pse_prev == NULL)
397 ps->instances = pse->next;
403 pse_prev->next = pse->next;
405 pse = pse_prev->next;
414 } /* while (pse != NULL) */
415 } /* for (ps = list_head_g; ps != NULL; ps = ps->next) */
418 static int ps_config (const char *key, const char *value)
420 if (strcasecmp (key, "Process") == 0)
422 ps_list_register (value);
431 #endif /* HAVE_THREAD_INFO | KERNEL_LINUX */
433 static int ps_init (void)
436 kern_return_t status;
438 port_host_self = mach_host_self ();
439 port_task_self = mach_task_self ();
441 if (pset_list != NULL)
443 vm_deallocate (port_task_self,
444 (vm_address_t) pset_list,
445 pset_list_len * sizeof (processor_set_t));
450 if ((status = host_processor_sets (port_host_self,
452 &pset_list_len)) != KERN_SUCCESS)
454 syslog (LOG_ERR, "host_processor_sets failed: %s\n",
455 mach_error_string (status));
460 /* #endif HAVE_THREAD_INFO */
463 pagesize_g = sysconf(_SC_PAGESIZE);
464 DBG ("pagesize_g = %li; CONFIG_HZ = %i;",
465 pagesize_g, CONFIG_HZ);
466 #endif /* KERNEL_LINUX */
471 static void ps_submit_state (const char *state, double value)
474 value_list_t vl = VALUE_LIST_INIT;
476 values[0].gauge = value;
480 vl.time = time (NULL);
481 strcpy (vl.host, hostname_g);
482 strcpy (vl.plugin, "processes");
483 strcpy (vl.plugin_instance, "");
484 strncpy (vl.type_instance, state, sizeof (vl.type_instance));
486 plugin_dispatch_values ("ps_state", &vl);
489 static void ps_submit_proc_list (procstat_t *ps)
492 value_list_t vl = VALUE_LIST_INIT;
496 vl.time = time (NULL);
497 strcpy (vl.host, hostname_g);
498 strcpy (vl.plugin, "processes");
499 strncpy (vl.plugin_instance, ps->name, sizeof (vl.plugin_instance));
501 vl.values[0].gauge = ps->vmem_rss;
503 plugin_dispatch_values ("ps_rss", &vl);
505 vl.values[0].counter = ps->cpu_user_counter;
506 vl.values[1].counter = ps->cpu_system_counter;
508 plugin_dispatch_values ("ps_cputime", &vl);
510 vl.values[0].gauge = ps->num_proc;
511 vl.values[1].gauge = ps->num_lwp;
513 plugin_dispatch_values ("ps_count", &vl);
515 vl.values[0].counter = ps->vmem_minflt_counter;
516 vl.values[1].counter = ps->vmem_majflt_counter;
518 plugin_dispatch_values ("ps_pagefaults", &vl);
520 DBG ("name = %s; num_proc = %lu; num_lwp = %lu; vmem_rss = %lu; "
521 "vmem_minflt_counter = %lu; vmem_majflt_counter = %lu; "
522 "cpu_user_counter = %lu; cpu_system_counter = %lu;",
523 ps->name, ps->num_proc, ps->num_lwp, ps->vmem_rss,
524 ps->vmem_minflt_counter, ps->vmem_majflt_counter,
525 ps->cpu_user_counter, ps->cpu_system_counter);
526 } /* void ps_submit_proc_list */
529 static int *ps_read_tasks (int pid)
532 int list_size = 1; /* size of allocated space, in elements */
533 int list_len = 0; /* number of currently used elements */
539 snprintf (dirname, 64, "/proc/%i/task", pid);
542 if ((dh = opendir (dirname)) == NULL)
544 DBG ("Failed to open directory `%s'", dirname);
548 while ((ent = readdir (dh)) != NULL)
550 if (!isdigit (ent->d_name[0]))
553 if ((list_len + 1) >= list_size)
556 int new_size = 2 * list_size;
557 /* Comes in sizes: 2, 4, 8, 16, ... */
559 new_ptr = (int *) realloc (list, (size_t) (sizeof (int) * new_size));
564 syslog (LOG_ERR, "processes plugin: "
565 "Failed to allocate more memory.");
570 list_size = new_size;
572 memset (list + list_len, 0, sizeof (int) * (list_size - list_len));
575 list[list_len] = atoi (ent->d_name);
576 if (list[list_len] != 0)
582 assert (list_len < list_size);
583 assert (list[list_len] == 0);
588 int ps_read_process (int pid, procstat_t *ps, char *state)
603 long long unsigned cpu_user_counter;
604 long long unsigned cpu_system_counter;
605 long long unsigned vmem_rss;
607 memset (ps, 0, sizeof (procstat_t));
609 snprintf (filename, 64, "/proc/%i/stat", pid);
612 if ((fh = fopen (filename, "r")) == NULL)
615 if (fgets (buffer, 1024, fh) == NULL)
623 fields_len = strsplit (buffer, fields, 64);
626 DBG ("`%s' has only %i fields..",
627 filename, fields_len);
630 else if (fields_len != 41)
632 DBG ("WARNING: (fields_len = %i) != 41", fields_len);
635 /* copy the name, strip brackets in the process */
636 name_len = strlen (fields[1]) - 2;
637 if ((fields[1][0] != '(') || (fields[1][name_len + 1] != ')'))
639 DBG ("No brackets found in process name: `%s'", fields[1]);
642 fields[1] = fields[1] + 1;
643 fields[1][name_len] = '\0';
644 strncpy (ps->name, fields[1], PROCSTAT_NAME_LEN);
646 ppid = atoi (fields[3]);
648 if ((tasks = ps_read_tasks (pid)) == NULL)
650 /* This happends for zombied, e.g. */
651 DBG ("ps_read_tasks (%i) failed.", pid);
661 for (i = 0; tasks[i] != 0; i++)
668 /* Leave the rest at zero if this is only an LWP */
669 if (ps->num_proc == 0)
671 DBG ("This is only an LWP: pid = %i; name = %s;",
676 cpu_user_counter = atoll (fields[13]);
677 cpu_system_counter = atoll (fields[14]);
678 vmem_rss = atoll (fields[23]);
679 ps->vmem_minflt_counter = atol (fields[9]);
680 ps->vmem_majflt_counter = atol (fields[11]);
682 /* Convert jiffies to useconds */
683 cpu_user_counter = cpu_user_counter * 1000000 / CONFIG_HZ;
684 cpu_system_counter = cpu_system_counter * 1000000 / CONFIG_HZ;
685 vmem_rss = vmem_rss * pagesize_g;
687 ps->cpu_user_counter = (unsigned long) cpu_user_counter;
688 ps->cpu_system_counter = (unsigned long) cpu_system_counter;
689 ps->vmem_rss = (unsigned long) vmem_rss;
691 *state = fields[2][0];
695 } /* int ps_read_process (...) */
696 #endif /* KERNEL_LINUX */
699 static int mach_get_task_name (task_t t, int *pid, char *name, size_t name_max_len)
703 struct kinfo_proc kp;
708 mib[2] = KERN_PROC_PID;
710 if (pid_for_task (t, pid) != KERN_SUCCESS)
714 kp_size = sizeof (kp);
715 if (sysctl (mib, 4, &kp, &kp_size, NULL, 0) != 0)
718 if (name_max_len > (MAXCOMLEN + 1))
719 name_max_len = MAXCOMLEN + 1;
721 strncpy (name, kp.kp_proc.p_comm, name_max_len - 1);
722 name[name_max_len - 1] = '\0';
724 DBG ("pid = %i; name = %s;", *pid, name);
726 /* We don't do the special handling for `p_comm == "LaunchCFMApp"' as
727 * `top' does it, because it is a lot of work and only used when
728 * debugging. -octo */
732 #endif /* HAVE_THREAD_INFO */
734 static int ps_read (void)
737 kern_return_t status;
740 processor_set_t port_pset_priv;
743 task_array_t task_list;
744 mach_msg_type_number_t task_list_len;
747 char task_name[MAXCOMLEN + 1];
750 thread_act_array_t thread_list;
751 mach_msg_type_number_t thread_list_len;
752 thread_basic_info_data_t thread_data;
753 mach_msg_type_number_t thread_data_len;
762 procstat_entry_t pse;
767 * The Mach-concept is a little different from the traditional UNIX
768 * concept: All the work is done in threads. Threads are contained in
769 * `tasks'. Therefore, `task status' doesn't make much sense, since
770 * it's actually a `thread status'.
771 * Tasks are assigned to sets of processors, so that's where you go to
774 for (pset = 0; pset < pset_list_len; pset++)
776 if ((status = host_processor_set_priv (port_host_self,
778 &port_pset_priv)) != KERN_SUCCESS)
780 syslog (LOG_ERR, "host_processor_set_priv failed: %s\n",
781 mach_error_string (status));
785 if ((status = processor_set_tasks (port_pset_priv,
787 &task_list_len)) != KERN_SUCCESS)
789 syslog (LOG_ERR, "processor_set_tasks failed: %s\n",
790 mach_error_string (status));
791 mach_port_deallocate (port_task_self, port_pset_priv);
795 for (task = 0; task < task_list_len; task++)
798 if (mach_get_task_name (task_list[task],
800 task_name, PROCSTAT_NAME_LEN) == 0)
801 ps = ps_list_search (task_name);
803 /* Collect more detailed statistics for this process */
806 task_basic_info_data_t task_basic_info;
807 mach_msg_type_number_t task_basic_info_len;
808 task_events_info_data_t task_events_info;
809 mach_msg_type_number_t task_events_info_len;
810 task_absolutetime_info_data_t task_absolutetime_info;
811 mach_msg_type_number_t task_absolutetime_info_len;
813 memset (&pse, '\0', sizeof (pse));
816 task_basic_info_len = TASK_BASIC_INFO_COUNT;
817 status = task_info (task_list[task],
819 (task_info_t) &task_basic_info,
820 &task_basic_info_len);
821 if (status != KERN_SUCCESS)
823 syslog (LOG_ERR, "task_info failed: %s",
824 mach_error_string (status));
825 continue; /* with next thread_list */
828 task_events_info_len = TASK_EVENTS_INFO_COUNT;
829 status = task_info (task_list[task],
831 (task_info_t) &task_events_info,
832 &task_events_info_len);
833 if (status != KERN_SUCCESS)
835 syslog (LOG_ERR, "task_info failed: %s",
836 mach_error_string (status));
837 continue; /* with next thread_list */
840 task_absolutetime_info_len = TASK_ABSOLUTETIME_INFO_COUNT;
841 status = task_info (task_list[task],
842 TASK_ABSOLUTETIME_INFO,
843 (task_info_t) &task_absolutetime_info,
844 &task_absolutetime_info_len);
845 if (status != KERN_SUCCESS)
847 syslog (LOG_ERR, "task_info failed: %s",
848 mach_error_string (status));
849 continue; /* with next thread_list */
853 pse.vmem_rss = task_basic_info.resident_size;
855 pse.vmem_minflt_counter = task_events_info.cow_faults;
856 pse.vmem_majflt_counter = task_events_info.faults;
858 pse.cpu_user_counter = task_absolutetime_info.total_user;
859 pse.cpu_system_counter = task_absolutetime_info.total_system;
862 status = task_threads (task_list[task], &thread_list,
864 if (status != KERN_SUCCESS)
866 /* Apple's `top' treats this case a zombie. It
867 * makes sense to some extend: A `zombie'
868 * thread is nonsense, since the task/process
871 DBG ("task_threads failed: %s",
872 mach_error_string (status));
873 if (task_list[task] != port_task_self)
874 mach_port_deallocate (port_task_self,
876 continue; /* with next task_list */
879 for (thread = 0; thread < thread_list_len; thread++)
881 thread_data_len = THREAD_BASIC_INFO_COUNT;
882 status = thread_info (thread_list[thread],
884 (thread_info_t) &thread_data,
886 if (status != KERN_SUCCESS)
888 syslog (LOG_ERR, "thread_info failed: %s",
889 mach_error_string (status));
890 if (task_list[task] != port_task_self)
891 mach_port_deallocate (port_task_self,
892 thread_list[thread]);
893 continue; /* with next thread_list */
899 switch (thread_data.run_state)
901 case TH_STATE_RUNNING:
904 case TH_STATE_STOPPED:
905 /* What exactly is `halted'? */
906 case TH_STATE_HALTED:
909 case TH_STATE_WAITING:
912 case TH_STATE_UNINTERRUPTIBLE:
915 /* There is no `zombie' case here,
916 * since there are no zombie-threads.
917 * There's only zombie tasks, which are
921 "Unknown thread status: %s",
922 thread_data.run_state);
924 } /* switch (thread_data.run_state) */
926 if (task_list[task] != port_task_self)
928 status = mach_port_deallocate (port_task_self,
929 thread_list[thread]);
930 if (status != KERN_SUCCESS)
931 syslog (LOG_ERR, "mach_port_deallocate failed: %s",
932 mach_error_string (status));
934 } /* for (thread_list) */
936 if ((status = vm_deallocate (port_task_self,
937 (vm_address_t) thread_list,
938 thread_list_len * sizeof (thread_act_t)))
941 syslog (LOG_ERR, "vm_deallocate failed: %s",
942 mach_error_string (status));
947 /* Only deallocate the task port, if it isn't our own.
948 * Don't know what would happen in that case, but this
949 * is what Apple's top does.. ;) */
950 if (task_list[task] != port_task_self)
952 status = mach_port_deallocate (port_task_self,
954 if (status != KERN_SUCCESS)
955 syslog (LOG_ERR, "mach_port_deallocate failed: %s",
956 mach_error_string (status));
960 ps_list_add (task_name, &pse);
961 } /* for (task_list) */
963 if ((status = vm_deallocate (port_task_self,
964 (vm_address_t) task_list,
965 task_list_len * sizeof (task_t))) != KERN_SUCCESS)
967 syslog (LOG_ERR, "vm_deallocate failed: %s",
968 mach_error_string (status));
973 if ((status = mach_port_deallocate (port_task_self, port_pset_priv))
976 syslog (LOG_ERR, "mach_port_deallocate failed: %s",
977 mach_error_string (status));
979 } /* for (pset_list) */
981 ps_submit_state ("running", running);
982 ps_submit_state ("sleeping", sleeping);
983 ps_submit_state ("zombies", zombies);
984 ps_submit_state ("stopped", stopped);
985 ps_submit_state ("blocked", blocked);
987 for (ps = list_head_g; ps != NULL; ps = ps->next)
988 ps_submit_proc_list (ps);
989 /* #endif HAVE_THREAD_INFO */
1005 procstat_entry_t pse;
1010 running = sleeping = zombies = stopped = paging = blocked = 0;
1013 if ((proc = opendir ("/proc")) == NULL)
1015 syslog (LOG_ERR, "Cannot open `/proc': %s", strerror (errno));
1019 while ((ent = readdir (proc)) != NULL)
1021 if (!isdigit (ent->d_name[0]))
1024 if ((pid = atoi (ent->d_name)) < 1)
1027 status = ps_read_process (pid, &ps, &state);
1030 DBG ("ps_read_process failed: %i", status);
1037 pse.num_proc = ps.num_proc;
1038 pse.num_lwp = ps.num_lwp;
1039 pse.vmem_rss = ps.vmem_rss;
1041 pse.vmem_minflt = 0;
1042 pse.vmem_minflt_counter = ps.vmem_minflt_counter;
1043 pse.vmem_majflt = 0;
1044 pse.vmem_majflt_counter = ps.vmem_majflt_counter;
1047 pse.cpu_user_counter = ps.cpu_user_counter;
1049 pse.cpu_system_counter = ps.cpu_system_counter;
1053 case 'R': running++; break;
1054 case 'S': sleeping++; break;
1055 case 'D': blocked++; break;
1056 case 'Z': zombies++; break;
1057 case 'T': stopped++; break;
1058 case 'W': paging++; break;
1061 ps_list_add (ps.name, &pse);
1066 ps_submit_state ("running", running);
1067 ps_submit_state ("sleeping", sleeping);
1068 ps_submit_state ("zombies", zombies);
1069 ps_submit_state ("stopped", stopped);
1070 ps_submit_state ("paging", paging);
1071 ps_submit_state ("blocked", blocked);
1073 for (ps_ptr = list_head_g; ps_ptr != NULL; ps_ptr = ps_ptr->next)
1074 ps_submit_proc_list (ps_ptr);
1075 #endif /* KERNEL_LINUX */
1079 #endif /* PROCESSES_HAVE_READ */
1081 void module_register (void)
1083 plugin_register_data_set (&state_ds);
1084 plugin_register_data_set (&rss_ds);
1085 plugin_register_data_set (&time_ds);
1086 plugin_register_data_set (&count_ds );
1087 plugin_register_data_set (&pagefaults_ds );
1089 #if PROCESSES_HAVE_READ
1090 #if HAVE_THREAD_INFO | KERNEL_LINUX
1091 plugin_register_config ("processes", ps_config,
1092 config_keys, config_keys_num);
1094 plugin_register_init ("processes", ps_init);
1095 plugin_register_read ("processes", ps_read);
1096 #endif /* PROCESSES_HAVE_READ */