Blame SOURCES/sysstat-10.1.5-pids-prealloc.patch

9a8d55
diff -upr sysstat-10.1.5.orig/common.h sysstat-10.1.5/common.h
9a8d55
--- sysstat-10.1.5.orig/common.h	2013-03-23 17:31:46.000000000 +0100
9a8d55
+++ sysstat-10.1.5/common.h	2016-04-29 12:47:09.285214132 +0200
9a8d55
@@ -106,9 +106,12 @@
9a8d55
  *
9a8d55
  * NB: Define SP_VALUE() to normalize to %;
9a8d55
  * HZ is 1024 on IA64 and % should be normalized to 100.
9a8d55
+ * SP_VALUE_100() will not output value bigger than 100; this is needed for some
9a8d55
+ *     corner cases, should be used with care.
9a8d55
  */
9a8d55
 #define S_VALUE(m,n,p)	(((double) ((n) - (m))) / (p) * HZ)
9a8d55
 #define SP_VALUE(m,n,p)	(((double) ((n) - (m))) / (p) * 100)
9a8d55
+#define SP_VALUE_100(m,n,p)	MINIMUM((((double) ((n) - (m))) / (p) * 100),100)
9a8d55
 
9a8d55
 /*
9a8d55
  * Under very special circumstances, STDOUT may become unavailable.
9a8d55
diff -upr sysstat-10.1.5.orig/pidstat.c sysstat-10.1.5/pidstat.c
9a8d55
--- sysstat-10.1.5.orig/pidstat.c	2013-03-23 17:31:46.000000000 +0100
9a8d55
+++ sysstat-10.1.5/pidstat.c	2016-04-29 13:04:02.672402150 +0200
9a8d55
@@ -152,15 +152,35 @@ void salloc_pid_array(unsigned int len)
9a8d55
  */
9a8d55
 void salloc_pid(unsigned int len)
9a8d55
 {
9a8d55
-	int i;
9a8d55
+	short i;
9a8d55
+
9a8d55
+	for (i = 0; i < 3; i++) {
9a8d55
+		if ((st_pid_list[i] = (struct pid_stats *) calloc(len, PID_STATS_SIZE)) == NULL) {
9a8d55
+			perror("calloc");
9a8d55
+			exit(4);
9a8d55
+		}
9a8d55
+	}
9a8d55
+}
9a8d55
+
9a8d55
+/*
9a8d55
+ ***************************************************************************
9a8d55
+ * Reallocate structures for PIDs to read.
9a8d55
+ ***************************************************************************
9a8d55
+ */
9a8d55
+void realloc_pid(void)
9a8d55
+{
9a8d55
+	short i;
9a8d55
+	unsigned int new_size = 2 * pid_nr;
9a8d55
 
9a8d55
 	for (i = 0; i < 3; i++) {
9a8d55
-		if ((st_pid_list[i] = (struct pid_stats *) malloc(PID_STATS_SIZE * len)) == NULL) {
9a8d55
-			perror("malloc");
9a8d55
+		if ((st_pid_list[i] = (struct pid_stats *) realloc(st_pid_list[i], PID_STATS_SIZE * new_size)) == NULL) {
9a8d55
+			perror("realloc");
9a8d55
 			exit(4);
9a8d55
 		}
9a8d55
-		memset(st_pid_list[i], 0, PID_STATS_SIZE * len);
9a8d55
+		memset(st_pid_list[i] + pid_nr, 0, PID_STATS_SIZE * (new_size - pid_nr));
9a8d55
 	}
9a8d55
+
9a8d55
+	pid_nr = new_size;
9a8d55
 }
9a8d55
 
9a8d55
 /*
9a8d55
@@ -774,23 +794,22 @@ void read_task_stats(int curr, unsigned
9a8d55
 	if ((dir = opendir(filename)) == NULL)
9a8d55
 		return;
9a8d55
 
9a8d55
-	while (*index < pid_nr) {
9a8d55
+	while ((drp = readdir(dir)) != NULL) {
9a8d55
+		if (!isdigit(drp->d_name[0])) {
9a8d55
+			continue;
9a8d55
+		}
9a8d55
 
9a8d55
-		while ((drp = readdir(dir)) != NULL) {
9a8d55
-			if (isdigit(drp->d_name[0]))
9a8d55
-				break;
9a8d55
+		pst = st_pid_list[curr] + (*index)++;
9a8d55
+		if (read_pid_stats(atoi(drp->d_name), pst, &thr_nr, pid)) {
9a8d55
+			/* Thread no longer exists */
9a8d55
+			pst->pid = 0;
9a8d55
 		}
9a8d55
 
9a8d55
-		if (drp) {
9a8d55
-			pst = st_pid_list[curr] + (*index)++;
9a8d55
-			if (read_pid_stats(atoi(drp->d_name), pst, &thr_nr, pid)) {
9a8d55
-				/* Thread no longer exists */
9a8d55
-				pst->pid = 0;
9a8d55
-			}
9a8d55
+		if (*index >= pid_nr) {
9a8d55
+			realloc_pid();
9a8d55
 		}
9a8d55
-		else
9a8d55
-			break;
9a8d55
 	}
9a8d55
+
9a8d55
 	closedir(dir);
9a8d55
 }
9a8d55
 
9a8d55
@@ -830,36 +849,34 @@ void read_stats(int curr)
9a8d55
 			exit(4);
9a8d55
 		}
9a8d55
 
9a8d55
-		while (p < pid_nr) {
9a8d55
+		/* Get directory entries */
9a8d55
+                while ((drp = readdir(dir)) != NULL) {
9a8d55
+                        if (!isdigit(drp->d_name[0])) {
9a8d55
+                                continue;
9a8d55
+                        }
9a8d55
+
9a8d55
+                        pst = st_pid_list[curr] + p++;
9a8d55
+                        pid = atoi(drp->d_name);
9a8d55
+
9a8d55
+                        if (read_pid_stats(pid, pst, &thr_nr, 0)) {
9a8d55
+                            /* Process has terminated */
9a8d55
+                            pst->pid = 0;
9a8d55
+                        } else if (DISPLAY_TID(pidflag)) {
9a8d55
+                            /* Read stats for threads in task subdirectory */
9a8d55
+                            read_task_stats(curr, pid, &p);
9a8d55
 
9a8d55
-			/* Get directory entries */
9a8d55
-			while ((drp = readdir(dir)) != NULL) {
9a8d55
-				if (isdigit(drp->d_name[0]))
9a8d55
-					break;
9a8d55
-			}
9a8d55
-			if (drp) {
9a8d55
-				pst = st_pid_list[curr] + p++;
9a8d55
-				pid = atoi(drp->d_name);
9a8d55
-	
9a8d55
-				if (read_pid_stats(pid, pst, &thr_nr, 0)) {
9a8d55
-					/* Process has terminated */
9a8d55
-					pst->pid = 0;
9a8d55
-				}
9a8d55
-	
9a8d55
-				else if (DISPLAY_TID(pidflag)) {
9a8d55
-					/* Read stats for threads in task subdirectory */
9a8d55
-					read_task_stats(curr, pid, &p);
9a8d55
-				}
9a8d55
-			}
9a8d55
-			else {
9a8d55
-				for (q = p; q < pid_nr; q++) {
9a8d55
-					pst = st_pid_list[curr] + q;
9a8d55
-					pst->pid = 0;
9a8d55
-				}
9a8d55
-				break;
9a8d55
 			}
9a8d55
+
9a8d55
+			if (p >= pid_nr) {
9a8d55
+                            realloc_pid();
9a8d55
+                        }
9a8d55
 		}
9a8d55
 
9a8d55
+                for (q = p; q < pid_nr; q++) {
9a8d55
+                    pst = st_pid_list[curr] + q;
9a8d55
+                    pst->pid = 0;
9a8d55
+                }
9a8d55
+
9a8d55
 		/* Close /proc directory */
9a8d55
 		closedir(dir);
9a8d55
 	}
9a8d55
@@ -1174,15 +1191,15 @@ int write_pid_task_all_stats(int prev, i
9a8d55
 			printf(" %7.2f %7.2f %7.2f %7.2f",
9a8d55
 			       (pstc->utime - pstc->gtime) < (pstp->utime - pstp->gtime) ?
9a8d55
 			       0.0 :
9a8d55
-			       SP_VALUE(pstp->utime - pstp->gtime,
9a8d55
+			       SP_VALUE_100(pstp->utime - pstp->gtime,
9a8d55
 					pstc->utime - pstc->gtime, itv),
9a8d55
-			       SP_VALUE(pstp->stime,  pstc->stime, itv),
9a8d55
-			       SP_VALUE(pstp->gtime,  pstc->gtime, itv),
9a8d55
+			       SP_VALUE_100(pstp->stime,  pstc->stime, itv),
9a8d55
+			       SP_VALUE_100(pstp->gtime,  pstc->gtime, itv),
9a8d55
 			       /* User time already includes guest time */
9a8d55
 			       IRIX_MODE_OFF(pidflag) ?
9a8d55
-			       SP_VALUE(pstp->utime + pstp->stime,
9a8d55
+			       SP_VALUE_100(pstp->utime + pstp->stime,
9a8d55
 					pstc->utime + pstc->stime, g_itv) :
9a8d55
-			       SP_VALUE(pstp->utime + pstp->stime,
9a8d55
+			       SP_VALUE_100(pstp->utime + pstp->stime,
9a8d55
 					pstc->utime + pstc->stime, itv));
9a8d55
 
9a8d55
 			printf("   %3d", pstc->processor);
9a8d55
@@ -1351,15 +1368,15 @@ int write_pid_task_cpu_stats(int prev, i
9a8d55
 		printf(" %7.2f %7.2f %7.2f %7.2f",
9a8d55
 		       (pstc->utime - pstc->gtime) < (pstp->utime - pstp->gtime) ?
9a8d55
 		       0.0 :
9a8d55
-		       SP_VALUE(pstp->utime - pstp->gtime,
9a8d55
+		       SP_VALUE_100(pstp->utime - pstp->gtime,
9a8d55
 				pstc->utime - pstc->gtime, itv),
9a8d55
-		       SP_VALUE(pstp->stime,  pstc->stime, itv),
9a8d55
-		       SP_VALUE(pstp->gtime,  pstc->gtime, itv),
9a8d55
+		       SP_VALUE_100(pstp->stime,  pstc->stime, itv),
9a8d55
+		       SP_VALUE_100(pstp->gtime,  pstc->gtime, itv),
9a8d55
 		       /* User time already includes guest time */
9a8d55
 		       IRIX_MODE_OFF(pidflag) ?
9a8d55
-		       SP_VALUE(pstp->utime + pstp->stime,
9a8d55
+		       SP_VALUE_100(pstp->utime + pstp->stime,
9a8d55
 				pstc->utime + pstc->stime, g_itv) :
9a8d55
-		       SP_VALUE(pstp->utime + pstp->stime,
9a8d55
+		       SP_VALUE_100(pstp->utime + pstp->stime,
9a8d55
 				pstc->utime + pstc->stime, itv));
9a8d55
 
9a8d55
 		if (!disp_avg) {
9a8d55
diff -upr sysstat-10.1.5.orig/pidstat.h sysstat-10.1.5/pidstat.h
9a8d55
--- sysstat-10.1.5.orig/pidstat.h	2013-03-23 17:31:46.000000000 +0100
9a8d55
+++ sysstat-10.1.5/pidstat.h	2016-04-28 18:24:37.700124018 +0200
9a8d55
@@ -13,7 +13,7 @@
9a8d55
 #define K_P_CHILD	"CHILD"
9a8d55
 #define K_P_ALL		"ALL"
9a8d55
 
9a8d55
-#define NR_PID_PREALLOC	10
9a8d55
+#define NR_PID_PREALLOC	100
9a8d55
 
9a8d55
 #define MAX_COMM_LEN	128
9a8d55
 #define MAX_CMDLINE_LEN	128