summaryrefslogtreecommitdiffstats
path: root/scripts/instperf
diff options
context:
space:
mode:
authorChris Lumens <clumens@redhat.com>2011-05-10 09:24:26 -0400
committerChris Lumens <clumens@redhat.com>2011-05-16 14:07:48 -0400
commit4e5940ffc640f10d6901f6582db50899d58bc6c2 (patch)
tree10b42eba77625adc5920331df86bfbbd00f14e16 /scripts/instperf
parentf159bd6b1be7e2baef3b20633b38863817d7f410 (diff)
downloadanaconda-4e5940ffc640f10d6901f6582db50899d58bc6c2.tar.gz
anaconda-4e5940ffc640f10d6901f6582db50899d58bc6c2.tar.xz
anaconda-4e5940ffc640f10d6901f6582db50899d58bc6c2.zip
Add a python program to record memory usage during installation.
This program only runs during installation if the "debug" command line option is provided. It writes out a /tmp/memory.dat file which can be copied off the system and processed with the provided gnuplot script to display a graph.
Diffstat (limited to 'scripts/instperf')
-rwxr-xr-xscripts/instperf58
1 files changed, 58 insertions, 0 deletions
diff --git a/scripts/instperf b/scripts/instperf
new file mode 100755
index 000000000..f0f53cc9e
--- /dev/null
+++ b/scripts/instperf
@@ -0,0 +1,58 @@
+#!/usr/bin/python
+
+import logging
+from string import split
+from subprocess import Popen, PIPE
+import time
+
+# grab the top five memory consuming processes, returning them in a string of
+# of the format:
+#
+# name1:kB1,name2:kB2,...,name5:kB5
+def topProcesses():
+ output = Popen(["ps", "-eo", "comm,rss", "--sort", "-rss", "--no-headers"], stdout=PIPE).communicate()[0]
+ top5 = output.split("\n")[:5]
+ return ",".join(map(lambda (a,b): a+":"+b, map(split, top5)))
+
+def logit():
+ buffers = 0
+ cached = 0
+ memTotal = 0
+ memFree = 0
+ swapTotal = 0
+ swapFree = 0
+
+ global mem_logger
+
+ with open("/proc/meminfo") as f:
+ for line in f.readlines():
+ if line.startswith("Buffers:"):
+ buffers = line.split()[1]
+ elif line.startswith("Cached:"):
+ cached = line.split()[1]
+ elif line.startswith("MemTotal:"):
+ memTotal = line.split()[1]
+ elif line.startswith("MemFree:"):
+ memFree = line.split()[1]
+ elif line.startswith("SwapTotal:"):
+ swapTotal = line.split()[1]
+ elif line.startswith("SwapFree:"):
+ swapFree = line.split()[1]
+
+ d = {"memUsed": int(memTotal)-int(memFree)-int(cached)-int(buffers),
+ "swapUsed": int(swapTotal)-int(swapFree),
+ "procs": topProcesses()}
+
+ mem_logger.debug("%(memUsed)d %(swapUsed)d %(procs)s" % d)
+
+mem_logger = logging.getLogger("memLog")
+mem_logger.setLevel(logging.DEBUG)
+
+handler = logging.FileHandler("/tmp/memory.dat")
+handler.setLevel(logging.DEBUG)
+handler.setFormatter(logging.Formatter("%(asctime)s %(message)s", "%H:%M:%S"))
+mem_logger.addHandler(handler)
+
+while True:
+ logit()
+ time.sleep(1)