ze-filter  (ze-filter-0.8.0-develop-180218)
ze-load.c
Go to the documentation of this file.
1 /*
2  *
3  * ze-filter - Mail Server Filter for sendmail
4  *
5  * Copyright (c) 2001-2018 - Jose-Marcio Martins da Cruz
6  *
7  * Auteur : Jose Marcio Martins da Cruz
8  * jose.marcio.mc@gmail.org
9  *
10  * Historique :
11  * Creation : janvier 2002
12  *
13  * This program is free software, but with restricted license :
14  *
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19  *
20  * More details about ze-filter license can be found at ze-filter
21  * web site : http://foss.jose-marcio.org
22  */
23 
24 #include <ze-sys.h>
25 #include <libze.h>
26 #include "ze-filter.h"
27 
28 
29 /* ****************************************************************************
30  * *
31  * *
32  **************************************************************************** */
33 
34 #define OS_OTHER 1
35 
36 #if defined(OS_SOLARIS)
37 #undef OS_OTHER
38 #endif
39 #if defined(OS_TRU64)
40 #undef OS_OTHER
41 #endif
42 #if defined(OS_LINUX)
43 #undef OS_OTHER
44 #endif
45 #if defined(OS_FREEBSD)
46 #undef OS_OTHER
47 #endif
48 #if defined(OS_HPUX)
49 #undef OS_OTHER
50 #endif
51 
52 
53 void *load_measure_thread(void *);
54 
55 /* ****************************************************************************
56  * *
57  * *
58  **************************************************************************** */
59 #if 1
60 typedef int64_t loadtype_T;
61 #else
62 typedef uint32_t loadtype_T;
63 #endif
64 
65 typedef struct cpustats_t cpustats_t;
66 
67 #define JCPU_STATES 5
68 
69 #define JCPU_SLOPE 100
70 
71 #if 0
72 static char *cpustatenames[] =
73  { "idle", "user", "nice", "kernel", "wait", NULL };
74 #endif
75 
76 struct cpustats_t
77 {
78  bool ok;
79  time_t date;
81  int32_t slope;
82 };
83 
84 static bool gather_cpu_load_info();
85 
86 #define CPUSTAT_INITIALIZER {FALSE, (time_t ) 0, {0, 0, 0, 0, 0}}
87 
88 #define HISTLEN 8
89 
90 static cpustats_t cpu_new = CPUSTAT_INITIALIZER;
91 static cpustats_t cpu_old = CPUSTAT_INITIALIZER;
92 static cpustats_t cpu_pct = CPUSTAT_INITIALIZER;
93 static cpustats_t cpu_ary[HISTLEN];
94 static int cpu_ptr = 0;
95 static bool init_ok = FALSE;
96 
97 static pthread_mutex_t cpu_mutex = PTHREAD_MUTEX_INITIALIZER;
98 
99 #define CPU_LOAD_LOCK() MUTEX_LOCK(&cpu_mutex)
100 
101 #define CPU_LOAD_UNLOCK() MUTEX_UNLOCK(&cpu_mutex)
102 
103 static time_t dt_stat = 10;
104 
105 
106 
107 
108 /* ****************************************************************************
109  * *
110  * *
111  **************************************************************************** */
112 static bool
113 cpu_load_init()
114 {
115  if (init_ok)
116  return TRUE;
117 
118  CPU_LOAD_LOCK();
119  if (!init_ok)
120  memset(cpu_ary, 0, sizeof (cpu_ary));
121  cpu_ptr = 0;
122  CPU_LOAD_UNLOCK();
123 
124  return TRUE;
125 }
126 
127 /* ****************************************************************************
128  * *
129  * *
130  **************************************************************************** */
131 int
132 evaluate_load_pct(pct, old, new)
133  cpustats_t *pct;
134  cpustats_t *old;
135  cpustats_t *new;
136 {
137  loadtype_T total, half;
138  int i;
139  loadtype_T oldidle;
140  int oldslope;
141 
142  if ((old == NULL) || (new == NULL) || (pct == NULL))
143  return 0;
144 
145  total = 0;
146  for (i = 0; i < JCPU_STATES; i++)
147  total += new->load[i] - old->load[i];
148 
149  if (total == 0)
150  total = 1;
151  half = total / 2;
152 
153  oldidle = pct->load[JCPU_IDLE];
154  oldslope = pct->slope;
155 
156  pct->date = time(NULL);
157  for (i = 0; i < JCPU_STATES; i++)
158  pct->load[i] = ((new->load[i] - old->load[i]) * 1000 + half) / total;
159 
160  pct->ok = new->ok;
161 
162  if (pct->load[JCPU_IDLE] < oldidle)
163  pct->slope = ++oldslope;
164  else
165  pct->slope = 0;
166 
167  cpu_ary[cpu_ptr++] = *pct;
168  cpu_ptr %= HISTLEN;
169 
170  return 0;
171 }
172 
173 
174 /* ****************************************************************************
175  * *
176  * #### #### # ## ##### # #### *
177  * # # # # # # # # # # *
178  * #### # # # # # # # # #### *
179  * # # # # ###### ##### # # *
180  * # # # # # # # # # # # # *
181  * #### #### ###### # # # # # #### *
182  * *
183  **************************************************************************** */
184 #if OS_SOLARIS
185 
186 static bool
187 gather_cpu_load_info()
188 {
189  static kstat_ctl_t *kc = NULL;
190  static kstat_t *ksp = NULL;
191 
192  static time_t last = 0;
193  time_t now = time(NULL);
194 
195  if (kc == NULL)
196  {
197  if ((kc = kstat_open()) == NULL)
198  {
199  ZE_LogSysError("kstat_open() error");
200  return FALSE;
201  }
202  } else
203  {
204  kid_t kid;
205 
206  if ((kid = kstat_chain_update(kc)) < 0)
207  {
208  ZE_LogSysError("kstat_open() error");
209  return FALSE;
210  }
211  }
212 
213  if (kc == NULL)
214  {
215  ZE_LogMsgError(0, "ks NULL");
216  return FALSE;
217  }
218 
219  if (last + dt_stat > now)
220  return TRUE;
221  last = now;
222 
223  CPU_LOAD_LOCK();
224 
225  cpu_old = cpu_new;
226 
227  memset(&cpu_new, 0, sizeof (cpu_new));
228  cpu_new.date = time(NULL);
229 
230  for (ksp = kc->kc_chain; ksp != NULL; ksp = ksp->ks_next)
231  {
232  if (strncasecmp(ksp->ks_module, "cpu_stat", 8) == 0)
233  {
234  static cpu_stat_t cpu_buf;
235  static cpu_sysinfo_t *cpuinfo = &cpu_buf.cpu_sysinfo;
236 
237  if (kstat_read(kc, ksp, &cpu_buf) < 0)
238  {
239  ZE_LogSysError("kstat_read() error");
240  CPU_LOAD_UNLOCK();
241  return FALSE;
242  }
243  cpu_new.load[JCPU_IDLE] += cpuinfo->cpu[CPU_IDLE];
244  cpu_new.load[JCPU_USER] += cpuinfo->cpu[CPU_USER];
245  cpu_new.load[JCPU_KERNEL] += cpuinfo->cpu[CPU_KERNEL];
246  cpu_new.load[JCPU_WAIT] += cpuinfo->cpu[CPU_WAIT];
247  cpu_new.ok = TRUE;
248  }
249  }
250 
251  (void) evaluate_load_pct(&cpu_pct, &cpu_old, &cpu_new);
252 
253  CPU_LOAD_UNLOCK();
254 
255  return TRUE;
256 }
257 
258 #endif /* OS_SOLARIS */
259 
260 /* ****************************************************************************
261  * *
262  * # # # # # # # # *
263  * # # ## # # # # # *
264  * # # # # # # # ## *
265  * # # # # # # # ## *
266  * # # # ## # # # # *
267  * ###### # # # #### # # *
268  * *
269  **************************************************************************** */
270 
271 #if OS_LINUX
272 
273 #define PROC_STAT_FILE "/proc/stat"
274 
275 static bool
276 gather_cpu_load_info()
277 {
278  int fd;
279  static time_t last = 0;
280  time_t now = time(NULL);
281  static char buf[4096];
282  int nbl = 0;
283 
284  if (last + dt_stat > now)
285  return TRUE;
286  last = now;
287 
288  if ((fd = open(PROC_STAT_FILE, O_RDONLY)) < 0)
289  {
290  ZE_LogSysError("Error opening %s", PROC_STAT_FILE);
291  return FALSE;
292  }
293 
294  CPU_LOAD_LOCK();
295 
296  cpu_old = cpu_new;
297  memset(&cpu_new, 0, sizeof (cpu_new));
298  cpu_new.date = time(NULL);
299 
300  *buf = '\0';
301  if (read(fd, buf, sizeof (buf)) > 0)
302  {
303  char *largv[32];
304  int largc;
305  int iarg;
306 
307  largc = zeStr2Tokens(buf, 32, largv, "\r\n");
308  for (iarg = 0; iarg < largc; iarg++)
309  {
310  loadtype_T u, n, s, i, x, y, z;
311  char *argv[16], **p;
312  int argc;
313 
314  if (!zeStrRegex(largv[iarg], "^cpu ", NULL, NULL, TRUE))
315  continue;
316 
317  u = n = s = i = x = y = z = 0;
318 
319  argc = zeStr2Tokens(largv[iarg], 16, argv, " ");
320 
321  p = argv;
322  if (*p == NULL)
323  continue;
324 
325  if (*++p != NULL)
326  {
327  u = zeStr2ulonglong(*p, NULL, 0);
328  if (errno == ERANGE)
329  continue;
330  }
331  if (*++p != NULL)
332  {
333  n = zeStr2ulonglong(*p, NULL, 0);
334  if (errno == ERANGE)
335  continue;
336  }
337  if (*++p != NULL)
338  {
339  s = zeStr2ulonglong(*p, NULL, 0);
340  if (errno == ERANGE)
341  continue;
342  }
343  if (*++p != NULL)
344  {
345  i = zeStr2ulonglong(*p, NULL, 0);
346  if (errno == ERANGE)
347  continue;
348  }
349  if (*++p != NULL)
350  {
351  x = zeStr2ulonglong(*p, NULL, 0);
352  if (errno == ERANGE)
353  continue;
354  }
355  if (*++p != NULL)
356  {
357  y = zeStr2ulonglong(*p, NULL, 0);
358  if (errno == ERANGE)
359  continue;
360  }
361  if (*++p != NULL)
362  {
363  z = zeStr2ulonglong(*p, NULL, 0);
364  if (errno == ERANGE)
365  continue;
366  }
367 
368  cpu_new.load[JCPU_USER] += u;
369  cpu_new.load[JCPU_NICE] += n;
370  cpu_new.load[JCPU_KERNEL] += (s + x + y + z);
371  cpu_new.load[JCPU_IDLE] += i;
372  cpu_new.ok = TRUE;
373  nbl++;
374 
375  break;
376  }
377  }
378  if (nbl > 1)
379  {
380  cpu_new.load[JCPU_USER] /= nbl;
381  cpu_new.load[JCPU_NICE] /= nbl;
382  cpu_new.load[JCPU_KERNEL] /= nbl;
383  cpu_new.load[JCPU_IDLE] /= nbl;
384  }
385  close(fd);
386 
387  (void) evaluate_load_pct(&cpu_pct, &cpu_old, &cpu_new);
388 
389  CPU_LOAD_UNLOCK();
390 
391  return TRUE;
392 }
393 
394 #endif
395 
396 /* ****************************************************************************
397  * *
398  * ##### # *
399  * ##### ##### # # # # # # *
400  * # # # # # # # # *
401  * # # # # # ###### # # *
402  * # ##### # # # # ####### *
403  * # # # # # # # # *
404  * # # # #### ##### # *
405  * *
406  **************************************************************************** */
407 
408 #if OS_TRU64
409 
410 static bool
411 gather_cpu_load_info()
412 {
413  static time_t last = 0;
414  time_t now = time(NULL);
415 
416  if (last + dt_stat > now)
417  return TRUE;
418  last = now;
419 
420  CPU_LOAD_LOCK();
421 
422  cpu_old = cpu_new;
423 
424  memset(&cpu_new, 0, sizeof (cpu_new));
425  cpu_new.date = time(NULL);
426 
427  cpu_new.load[JCPU_USER] = 0;
428  cpu_new.load[JCPU_NICE] = 0;
429  cpu_new.load[JCPU_KERNEL] = 0;
430  cpu_new.load[JCPU_IDLE] = cpu_old.load[JCPU_IDLE] + 1;
431 
432  (void) evaluate_load_pct(&cpu_pct, &cpu_old, &cpu_new);
433 
434  CPU_LOAD_UNLOCK();
435  return TRUE;
436 }
437 
438 #endif
439 
440 /* ****************************************************************************
441  * *
442  * ###### ##### ###### ###### ##### #### ##### *
443  * # # # # # # # # # # *
444  * ##### # # ##### ##### ##### #### # # *
445  * # ##### # # # # # # # *
446  * # # # # # # # # # # # *
447  * # # # ###### ###### ##### #### ##### *
448  * *
449  **************************************************************************** */
450 #if OS_FREEBSD
451 
452 #ifndef MAX_KVM_ERR
453 #define MAX_KVM_ERR 32
454 #endif
455 
456 static bool
457 gather_cpu_load_info()
458 {
459  static time_t last = 0;
460  time_t now = time(NULL);
461 
462  static int nerr = 0;
463 
464  if ((MAX_KVM_ERR > 0) && (nerr > MAX_KVM_ERR))
465  return TRUE;
466 
467  if (last + dt_stat > now)
468  return TRUE;
469  last = now;
470 
471 
472 #if HAVE_SYSCTLBYNAME
473  CPU_LOAD_LOCK();
474 
475  cpu_old = cpu_new;
476 
477  memset(&cpu_new, 0, sizeof (cpu_new));
478  cpu_new.date = time(NULL);
479 
480  {
481  long cp_time[CPUSTATES];
482  size_t len = sizeof (cp_time);
483 
484  if (sysctlbyname("kern.cp_time", &cp_time, &len, NULL, 0) == 0)
485  {
486  cpu_new.load[JCPU_USER] = cp_time[CP_USER];
487  cpu_new.load[JCPU_NICE] = cp_time[CP_NICE];
488  cpu_new.load[JCPU_KERNEL] = cp_time[CP_SYS] + cp_time[CP_INTR];
489  cpu_new.load[JCPU_IDLE] = cp_time[CP_IDLE];
490 
491  cpu_new.ok = TRUE;
492  } else
493  ZE_LogSysError("sysctlbyname error");
494 
495  (void) evaluate_load_pct(&cpu_pct, &cpu_old, &cpu_new);
496 
497  }
498 
499  CPU_LOAD_UNLOCK();
500 #else
501  {
502  static kvm_t *kd = NULL;
503  static struct nlist namelist[] = { {"_cp_time"}, {""} };
504  static unsigned long nameaddr = 0;
505 
506  if (kd == NULL)
507  {
508  char errbuf[_POSIX2_LINE_MAX];
509 
510  if ((kd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, errbuf)) == NULL)
511  {
512  nerr++;
513  ZE_LogMsgError(0, "kvm_openfiles : %s", errbuf);
514  return FALSE;
515  }
516  if (kvm_nlist(kd, namelist) != 0)
517  {
518  nerr++;
519  kvm_close(kd);
520  kd = NULL;
521  return FALSE;
522  }
523  nameaddr = namelist[0].n_value;
524  }
525  nerr = 0;
526 
527  CPU_LOAD_LOCK();
528 
529  cpu_old = cpu_new;
530 
531  memset(&cpu_new, 0, sizeof (cpu_new));
532  cpu_new.date = time(NULL);
533 
534  {
535  loadtype_T cp_time[CPUSTATES];
536 
537  if (kvm_read(kd, nameaddr, cp_time, sizeof (cp_time)) == sizeof (cp_time))
538  {
539  cpu_new.load[JCPU_USER] = cp_time[CP_USER];
540  cpu_new.load[JCPU_NICE] = cp_time[CP_NICE];
541  cpu_new.load[JCPU_KERNEL] = cp_time[CP_SYS] + cp_time[CP_INTR];
542  cpu_new.load[JCPU_IDLE] = cp_time[CP_IDLE];
543 
544  cpu_new.ok = TRUE;
545  } else
546  ZE_LogMsgError(0, "kvm_read error");
547 
548  (void) evaluate_load_pct(&cpu_pct, &cpu_old, &cpu_new);
549 
550  }
551 
552  CPU_LOAD_UNLOCK();
553 
554  if (kd != NULL)
555  {
556  if (kvm_close(kd) != 0)
557  {
558 
559  }
560  }
561  kd = NULL;
562  }
563 #endif
564 
565  return TRUE;
566 }
567 
568 #endif
569 
570 /* ****************************************************************************
571  * *
572  * # # ##### # # # # *
573  * # # # # # # # # *
574  * ###### # # ##### # # ## *
575  * # # ##### # # ## *
576  * # # # # # # # *
577  * # # # #### # # *
578  * *
579  **************************************************************************** */
580 #if OS_HPUX
581 
582 static bool
583 gather_cpu_load_info()
584 {
585  static time_t last = 0;
586  time_t now = time(NULL);
587 
588  if (last + dt_stat > now)
589  return TRUE;
590  last = now;
591 
592  CPU_LOAD_LOCK();
593 
594  cpu_old = cpu_new;
595 
596  memset(&cpu_new, 0, sizeof (cpu_new));
597  cpu_new.date = time(NULL);
598 
599 #if 0
600  /* WRITE HERE HOW TO GET LOAD UNDER THIS OS */
601 #endif
602  cpu_new.load[JCPU_USER] = 0;
603  cpu_new.load[JCPU_NICE] = 0;
604  cpu_new.load[JCPU_KERNEL] = 0;
605  cpu_new.load[JCPU_IDLE] = cpu_old.load[JCPU_IDLE] + 1;
606 
607  (void) evaluate_load_pct(&cpu_pct, &cpu_old, &cpu_new);
608 
609  CPU_LOAD_UNLOCK();
610  return TRUE;
611 }
612 
613 #endif
614 
615 /* ****************************************************************************
616  * *
617  * #### ##### # # ###### ##### *
618  * # # # # # # # # *
619  * # # # ###### ##### # # *
620  * # # # # # # ##### *
621  * # # # # # # # # *
622  * #### # # # ###### # # *
623  * *
624  **************************************************************************** */
625 #if OS_OTHER
626 
627 static bool
628 gather_cpu_load_info()
629 {
630  static time_t last = 0;
631  time_t now = time(NULL);
632 
633  if (last + dt_stat > now)
634  return TRUE;
635  last = now;
636 
637  CPU_LOAD_LOCK();
638 
639  cpu_old = cpu_new;
640 
641  memset(&cpu_new, 0, sizeof (cpu_new));
642  cpu_new.date = time(NULL);
643 
644 #if 0
645  /* WRITE HERE HOW TO GET LOAD UNDER THIS OS */
646 #endif
647  cpu_new.load[JCPU_USER] = 0;
648  cpu_new.load[JCPU_NICE] = 0;
649  cpu_new.load[JCPU_KERNEL] = 0;
650  cpu_new.load[JCPU_IDLE] = cpu_old.load[JCPU_IDLE] + 1;
651 
652  (void) evaluate_load_pct(&cpu_pct, &cpu_old, &cpu_new);
653 
654  CPU_LOAD_UNLOCK();
655  return TRUE;
656 }
657 
658 #endif
659 
660 /* ****************************************************************************
661  * *
662  * *
663  **************************************************************************** */
664 void
666 {
667  loadtype_T u, n, i, s;
668 
669  if ((cpu_new.date == (time_t) 0) || (cpu_old.date == (time_t) 0))
670  return;
671 
672  u = cpu_new.load[JCPU_USER] - cpu_old.load[JCPU_USER];
673  n = cpu_new.load[JCPU_NICE] - cpu_old.load[JCPU_NICE];
674  s = cpu_new.load[JCPU_KERNEL] - cpu_old.load[JCPU_KERNEL];
675  i = cpu_new.load[JCPU_IDLE] - cpu_old.load[JCPU_IDLE];
676  if (u + n + s + i > 0)
677  {
678  printf("*** %ld", (long) cpu_new.date);
679  printf(" - user : %5.2f", ((double) u) / (u + n + s + i));
680  printf(" - nice : %5.2f", ((double) n) / (u + n + s + i));
681  printf(" - kernel : %5.2f", ((double) s) / (u + n + s + i));
682  printf(" - idle : %5.2f", ((double) i) / (u + n + s + i));
683  printf("\n");
684  }
685 }
686 
687 /* ****************************************************************************
688  * *
689  * *
690  **************************************************************************** */
691 void
693 {
694  char *fmt = NULL;
695 
696  CPU_LOAD_LOCK();
697 
698 #if OS_SOLARIS
699  fmt =
700  "SYSTEM LOAD - idle : %5.1f - user : %5.1f - kernel : %5.1f - wait %5.1f - %3d";
701 
702  ZE_MessageInfo(9, fmt,
707 #endif /* OS_SOLARIS */
708 
709 #if OS_LINUX
710  fmt = "SYSTEM LOAD - idle/kernel/user/nice = %5.1f %5.1f %5.1f %5.1f %3d";
711 
712  ZE_MessageInfo(9, fmt,
717 #endif /* OS_LINUX */
718 
719 #if OS_FREEBSD
720  fmt = "SYSTEM LOAD - idle/kernel/user/nice = %5.1f %5.1f %5.1f %5.1f %3d";
721 
722  ZE_MessageInfo(9, fmt,
727 #endif /* OS_FREEBSD */
728 
729 #if OS_HPUX
730 
731 #endif /* OS_HPUX */
732 
733 #if OS_TRU64
734 
735 #endif /* OS_TRU64 */
736 
737 #if OS_HPUX
738 
739 #endif /* OS_HPUX */
740 
741 #if OS_OTHER
742 
743 #endif /* OS_OTHER */
744 
745  CPU_LOAD_UNLOCK();
746 }
747 
748 /* ****************************************************************************
749  * *
750  * *
751  **************************************************************************** */
752 double
754  int which;
755 {
756  if (which == JCPU_SLOPE)
757  return (double) cpu_pct.slope;
758 
759  if ((which >= JCPU_STATES) || (which < 0))
760  return 0;
761 
762  if (cpu_new.ok)
763  return cpu_pct.load[which] / 10.;
764 
765  if (which == JCPU_IDLE)
766  return 100.;
767  else
768  return 0.;
769 }
770 
771 /* ****************************************************************************
772  * *
773  * *
774  **************************************************************************** */
775 #define DT_SYSLOAD 10
776 
777 static bool cpuloadgo = TRUE;
778 static bool cpuloadok = FALSE;
779 
780 void *
782  void *data;
783 {
784  pthread_t tid;
785  time_t old, now;
786 
787  ZE_MessageInfo(9, "*** cpuload_tread starting...");
788  tid = pthread_self();
789  (void) pthread_detach(tid);
790 
791  if (cpuloadok)
792  return NULL;
793 
794  cpuloadgo = TRUE;
795 
796  old = now = time(NULL);
797 
798  cpu_load_init();
799 
800  while (cpuloadgo)
801  {
802  sleep(dt_stat);
803 
804  now = time(NULL);
805  if (gather_cpu_load_info())
806  {
807  if ((int) get_cpu_load_info(JCPU_SLOPE) > 2)
808  ZE_MessageInfo(9,
809  "System Load increasing for more than %ld sec - Last Idle = %5.1f",
810  (int) get_cpu_load_info(JCPU_SLOPE) * dt_stat,
812 
814  {
815  if (now - old >= 60)
816  {
818  old = now;
819  }
820  }
821  } else
822  ZE_MessageInfo(9, "Can't gather_cpu_load_info...");
823  }
824 
825  cpuloadok = FALSE;
826 
827  return NULL;
828 }
829 
830 
831 /* ****************************************************************************
832  * *
833  * *
834  **************************************************************************** */
835 void
837 {
838  cpuloadgo = FALSE;
839 }
840 
841 /* ****************************************************************************
842  * *
843  * *
844  **************************************************************************** */
845 bool
847 {
848  pthread_t tid;
849  int r;
850 
851  ZE_MessageInfo(10, "*** Starting %s ...", ZE_FUNCTION);
852 
853 #if OS_LINUX
854  if ((r = pthread_create(&tid, NULL, cpuload_thread, (void *) NULL)) != 0)
855  {
856  ZE_LogSysError("Couldn't launch cpuload_thread");
857  return FALSE;
858  }
859 #endif
860 
861 #if OS_SOLARIS
862  if ((r = pthread_create(&tid, NULL, cpuload_thread, (void *) NULL)) != 0)
863  {
864  ZE_LogSysError("Couldn't launch cpuload_thread");
865  return FALSE;
866  }
867 #endif
868 
869 #if OS_FREEBSD
870  if ((r = pthread_create(&tid, NULL, cpuload_thread, (void *) NULL)) != 0)
871  {
872  ZE_LogSysError("Couldn't launch cpuload_thread");
873  return FALSE;
874  }
875 #endif
876 
877 #if OS_TRU64
878  if ((r = pthread_create(&tid, NULL, cpuload_thread, (void *) NULL)) != 0)
879  {
880  ZE_LogSysError("Couldn't launch cpuload_thread");
881  return FALSE;
882  }
883 #endif
884 
885 #if OS_OTHER
886  if ((r = pthread_create(&tid, NULL, cpuload_thread, (void *) NULL)) != 0)
887  {
888  ZE_LogSysError("Couldn't launch cpuload_thread");
889  return FALSE;
890  }
891 #endif
892 
893  return TRUE;
894 }
#define CF_LOG_LOAD
Definition: cfh-defs.h:61
#define JCPU_SLOPE
Definition: ze-load.c:69
#define JCPU_WAIT
Definition: ze-load.h:37
#define ZE_FUNCTION
Definition: ze-sys.h:471
double get_cpu_load_info(int which)
Definition: ze-load.c:753
#define JCPU_USER
Definition: ze-load.h:34
#define JCPU_IDLE
Definition: ze-load.h:33
loadtype_T load[JCPU_STATES]
Definition: ze-load.c:80
void * cpuload_thread(void *data)
Definition: ze-load.c:781
#define FALSE
Definition: macros.h:160
#define ZE_LogMsgError(level,...)
Definition: zeSyslog.h:113
bool zeStrRegex(char *, char *, long *, long *, bool)
Definition: zeStrings.c:544
#define OPT_YES
Definition: ze-cf.h:45
void cpuload_stop()
Definition: ze-load.c:836
int cf_get_int(int id)
Definition: ze-cf.c:803
int zeStr2Tokens(char *, int, char **, char *)
Definition: zeStrings.c:610
#define HISTLEN
Definition: ze-load.c:88
void print_cpu_load_info()
Definition: ze-load.c:665
#define CPU_LOAD_UNLOCK()
Definition: ze-load.c:101
unsigned long long zeStr2ulonglong(char *s, int *error, unsigned long long dval)
Definition: zeStrConvert.c:134
#define JCPU_STATES
Definition: ze-load.c:67
bool cpuload_start()
Definition: ze-load.c:846
#define _POSIX2_LINE_MAX
Definition: ze-sys.h:586
int64_t loadtype_T
Definition: ze-load.c:60
int evaluate_load_pct(cpustats_t *pct, cpustats_t *old, cpustats_t *new)
Definition: ze-load.c:132
void * load_measure_thread(void *)
#define ZE_MessageInfo(level,...)
Definition: zeSyslog.h:90
#define TRUE
Definition: macros.h:157
#define ZE_LogSysError(...)
Definition: zeSyslog.h:129
time_t date
Definition: ze-load.c:79
#define JCPU_KERNEL
Definition: ze-load.h:36
time_t last
Definition: ze-connopen.c:60
int32_t slope
Definition: ze-load.c:81
#define CPUSTAT_INITIALIZER
Definition: ze-load.c:86
#define JCPU_NICE
Definition: ze-load.h:35
bool ok
Definition: ze-load.c:78
long uint32_t
Definition: ze-sys.h:489
void log_cpu_load_info()
Definition: ze-load.c:692
#define CPU_LOAD_LOCK()
Definition: ze-load.c:99