Created
December 20, 2016 19:23
-
-
Save ilyaevseev/a2a80f00d8954a10de7b68c14e6b1e96 to your computer and use it in GitHub Desktop.
Increase performance of atop utility on the systems with many threads.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- atop-2.1.1/atop.c.orig 2014-09-06 17:12:52.000000000 +0400 | |
+++ atop-2.1.1/atop.c 2016-12-20 18:57:25.733100314 +0300 | |
@@ -299,7 +299,6 @@ | |
#include "parseable.h" | |
#define allflags "ab:cde:fghijklmnopqrstuvwxyz1ABCDEFGHIJKL:MNOP:QRSTUVWXYZ" | |
-#define PROCCHUNK 100 /* process-entries for future expansion */ | |
#define MAXFL 64 /* maximum number of command-line flags */ | |
/* | |
@@ -733,7 +732,7 @@ | |
presstat = calloc(1, sizeof(struct sstat)); | |
devsstat = calloc(1, sizeof(struct sstat)); | |
- curtlen = countprocs() * 3 / 2; /* add 50% for threads */ | |
+ curtlen = countprocs() * 2; /* increase twice for threads */ | |
curtpres = calloc(curtlen, sizeof(struct tstat)); | |
ptrverify(cursstat, "Malloc failed for current sysstats\n"); | |
@@ -839,7 +838,7 @@ | |
while ( (ntaskpres = photoproc(curtpres, curtlen)) == curtlen) | |
{ | |
- curtlen += PROCCHUNK; | |
+ curtlen *= 2; | |
curtpres = realloc(curtpres, | |
curtlen * sizeof(struct tstat)); | |
--- atop-2.1.1/photoproc.c.orig 2014-09-06 17:12:52.000000000 +0400 | |
+++ atop-2.1.1/photoproc.c 2016-12-20 21:53:30.890806203 +0300 | |
@@ -373,7 +373,40 @@ | |
} | |
/* | |
-** count number of processes currently running | |
+** count number of threads for given process | |
+*/ | |
+unsigned int | |
+counttasks(const char *pid) | |
+{ | |
+ unsigned int nr = 0; | |
+ DIR *dirp; | |
+ struct dirent *entp; | |
+ char origdir[1024]; | |
+ | |
+ if ( getcwd(origdir, sizeof origdir) == NULL) | |
+ cleanstop(53); | |
+ | |
+ if ( chdir("/proc") == -1 || chdir(pid) == -1 || chdir("task") == -1) | |
+ cleanstop(53); | |
+ | |
+ dirp = opendir("."); | |
+ | |
+ while ( (entp = readdir(dirp)) ) | |
+ { | |
+ if (isdigit(entp->d_name[0])) | |
+ nr++; | |
+ } | |
+ | |
+ closedir(dirp); | |
+ | |
+ if ( chdir(origdir) == -1) | |
+ cleanstop(53); | |
+ | |
+ return nr ? nr : 1; | |
+} | |
+ | |
+/* | |
+** count number of processes and threads currently running | |
*/ | |
unsigned int | |
countprocs(void) | |
@@ -397,7 +430,7 @@ | |
** count subdirectory-names starting with a digit | |
*/ | |
if (isdigit(entp->d_name[0])) | |
- nr++; | |
+ nr += counttasks(entp->d_name); | |
} | |
closedir(dirp); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment