diff options
author | jhjaggars <jhjaggars@gmail.com> | 2012-03-02 07:05:09 -0800 |
---|---|---|
committer | jhjaggars <jhjaggars@gmail.com> | 2012-03-02 07:05:09 -0800 |
commit | 2a1d5871619d7228fe8c1e6222f848db05b70dfe (patch) | |
tree | cdbc602c525afd230321e0610c56166904b6b1e7 /tools | |
parent | a0c94dff75fb0ab26e003885379ef6ddd51ca4f0 (diff) | |
parent | 4b9412ce0f18da79b71d3abbce343848dfa3a434 (diff) | |
download | sos-2a1d5871619d7228fe8c1e6222f848db05b70dfe.tar.gz |
Merge pull request #40 from jhjaggars/master
Removing lots of unused files, updating example plugin
Diffstat (limited to 'tools')
-rw-r--r-- | tools/osdetect.py | 87 | ||||
-rwxr-xr-x | tools/profiler/report | 145 | ||||
-rwxr-xr-x | tools/sos-open | 151 |
3 files changed, 0 insertions, 383 deletions
diff --git a/tools/osdetect.py b/tools/osdetect.py deleted file mode 100644 index fea78cc5..00000000 --- a/tools/osdetect.py +++ /dev/null @@ -1,87 +0,0 @@ -''' -Created on Aug 2, 2011 -@author: Keith Robertson -''' - -import pprint -import os -import re - -class OSTypes: - """ - Utility class with enumerations for the various OSes to facilitate - OS detection. - """ - JAVA_OS_NAME_KEY='os.name' - - OS_TYPE_LINUX='Linux' - OS_TYPE_LINUX_PAT=re.compile('^%s$' % OS_TYPE_LINUX, re.I) - OS_TYPE_WIN='Windows' - OS_TYPE_WIN_PAT=re.compile('^%s$' % OS_TYPE_WIN, re.I) - OS_TYPE_AIX='AIX' - OS_TYPE_AIX_PAT=re.compile('^%s$' % OS_TYPE_AIX, re.I) - OS_TYPE_MAC='Mac OS' - OS_TYPE_MAC_PAT=re.compile('^%s$' % OS_TYPE_MAC, re.I) - OS_TYPE_390='OS/390' - OS_TYPE_390_PAT=re.compile('^%s$' % OS_TYPE_390, re.I) - OS_TYPE_HPUX='HP-UX' - OS_TYPE_HPUX_PAT=re.compile('^%s$' % OS_TYPE_HPUX, re.I) - -def printProps(): - try: - from java.lang import System - from java.util import Set - from java.util import Iterator - - set = System.getProperties().entrySet() - it = set.iterator() - while it.hasNext(): - me = it.next(); - print "Key (%s) Value(%s)" % (me.getKey(), me.getValue()) - except Exception, e: - print "ERROR: unable to print Java properties %s" % e - - - -def java_detect_os(): - """ - Try to load Java packages. If successful then we know we are running - in JYthon. Use the JRE to determine what type of OS and return the proper - policy. - """ - try: - from java.lang import System - - ostype = System.getProperty(OSTypes.JAVA_OS_NAME_KEY) - if ostype: - if OSTypes.OS_TYPE_LINUX_PAT.match(ostype): - print "Matched %s" % OSTypes.OS_TYPE_LINUX - # Lots of checks here to determine linux version. - #return proper policy here - elif OSTypes.OS_TYPE_WIN_PAT.match(ostype): - print "Matched %s" % OSTypes.OS_TYPE_WIN - elif OS_TYPE_AIX_PAT.match(ostype): - print "Matched %s" % OSTypes.OS_TYPE_AIX - elif OS_TYPE_MAC_PAT.match(ostype): - print "Matched %s" % OSTypes.OS_TYPE_MAC - elif OS_TYPE_390_PAT.match(ostype): - print "Matched %s" % OSTypes.OS_TYPE_390 - elif OS_TYPE_HPUX_PAT.match(ostype): - print "Matched %s" % OSTypes.OS_TYPE_HPUX - else: - raise Exception("Unsupported OS type of %s." % ostype) - else: - raise Exception("Unable to get %s from JRE's system properties." % OSTypes.JAVA_OS_NAME_KEY) - except Exception, e: - print "WARN: unable to print Java properties %s" % e - -def native_detect_os(): - print "here" - - - -if __name__ == '__main__': - #printProps() - detectOS() - - pass
\ No newline at end of file diff --git a/tools/profiler/report b/tools/profiler/report deleted file mode 100755 index 13577fcc..00000000 --- a/tools/profiler/report +++ /dev/null @@ -1,145 +0,0 @@ -#!/usr/bin/python - -# profile reporter - -import sys, os, operator, string -from optparse import OptionParser -from glob import glob -from subprocess import Popen, PIPE -import tarfile - -class GlobalVars: - def __init__(self): - pass - -class MyWriter: - def __init__(self, stdout, filename): - self.stdout = stdout - self.logfile = file(filename, 'w') - - def write(self, text): - self.stdout.write(text) - self.logfile.write(text) - - def close(self): - self.stdout.close() - self.logfile.close() - -def parse_options(opts): - """ parse cmd line opts """ - - parser = OptionParser() - parser.add_option("-f","--filename", dest="filename", - help="write report to FILENAME") - parser.add_option("-t", "--time", dest="rtime", - help="set minimum RUNTIME to report", action="store", - default=float(0.1), type="float") - parser.add_option("-i", "--input", dest="rpt_dir", - help="define directory of sosreport archives", - action="store", default=False) - - GlobalVars.cmdlineopts, GlobalVars.cmdlineargs = parser.parse_args(opts) - - if not GlobalVars.cmdlineopts.rpt_dir: - raise SystemExit("\nPlease make sure to specify --input FILES\n") - -def uncompress_reports(fname): - """ uncompresses the sosreport """ - p = Popen(["xz","-d", fname], stdout=PIPE, stdin=PIPE) - out, err = p.communicate() - if err: - print "Problem extracting %s" % (fname,) - return - -def read_archive(fname): - """ reads tarfile archive and grabs the sosprofile.log fileobj """ - tar = tarfile.open(os.path.abspath(fname), "r:") - for tarinfo in tar.getmembers(): - if 'sosprofile.log' in tarinfo.name: - fobj = tar.extractfile(tarinfo) - buf = fobj.read() - tar.close() - return buf - -def timeoutput(secs): - if secs > 60: - secs = round(secs) / 60 - return (secs, 'm') - elif secs < 60: - return (secs, 's') - -def sort_profile(): - """ provide reports on sosreport profiling """ - # uncompress reports from input files - for rpt in glob(GlobalVars.cmdlineopts.rpt_dir+"/*.xz"): - uncompress_reports(os.path.abspath(rpt)) - GlobalVars.rpt_count = 0 - GlobalVars.timecount = 0 - GlobalVars.lrc = {} - for rpt in glob(GlobalVars.cmdlineopts.rpt_dir+"/*.tar"): - buf = read_archive(rpt) - time_sorts=[] - if not buf: - continue - for line in buf.split("\n"): - try: - cmd, rtime = line.split("time:") - try: - # cmds that span multiple lines still need time calculated - cmd = cmd.split(":")[1] - except IndexError: - cmd, rtime = line.split("time:") - time_sorts.append((cmd.strip(), rtime.strip())) - except ValueError: - continue - time_count = 0 - b_val_count = 0 - write_stats = open(rpt + ".profile_report", 'w') - write_stats.write(28 * ' ' + 'SOSreport Profile Report' + 27 * ' ' + "\n") - write_stats.write(79 * '.' + "\n") - for a,b in sorted(time_sorts, key=operator.itemgetter(1)): - b_val = float(b) - time_count += b_val - if b_val > float(GlobalVars.cmdlineopts.rtime): - b_val_count += b_val - write_stats.write("%-79s %s\n" % (a[:78], b)) - if GlobalVars.lrc.has_key(a) and \ - GlobalVars.lrc[a] < b_val: - GlobalVars.lrc[a] = b_val - else: - GlobalVars.lrc[a] = b_val - # Keep up with total run time for all reports - GlobalVars.timecount += time_count - # Write out totals per report - write_stats.write(79 * '.' + "\n") - write_stats.write("Totals:\n") - secs, fmt = timeoutput(b_val_count) - write_stats.write("cumulative > %s: \t%f%s\n" % (GlobalVars.cmdlineopts.rtime, secs, fmt)) - secs, fmt = timeoutput(time_count) - write_stats.write("cumulative total:\t%f%s\n" % (secs,fmt)) - write_stats.close() - # increment report count so we can get an average runtime - GlobalVars.rpt_count += 1 - -if __name__ == "__main__": - parse_options(sys.argv[1:]) - if GlobalVars.cmdlineopts.filename: - writer = MyWriter(sys.stdout, GlobalVars.cmdlineopts.filename) - sys.stdout = writer - print "Building reports ..." - sort_profile() - print 79 * "-" - print "Total runtime for %d reports is %fs" % (round(GlobalVars.rpt_count, 2), GlobalVars.timecount) - print "Average total runtime of %d reports is %fs" % (round(GlobalVars.rpt_count, 2), GlobalVars.timecount / GlobalVars.rpt_count) - print 79 * "-" - print - print "Longest running commands > %s:" % (GlobalVars.cmdlineopts.rtime,) - print 79 * "-" - for cmd, rtime in sorted(GlobalVars.lrc.iteritems(), key=operator.itemgetter(1)): - print "%-75s %s" % (cmd[:69], rtime) - - if GlobalVars.cmdlineopts.filename: - print 79 * "-" - print "Report log written to: %s" % (GlobalVars.cmdlineopts.filename,) - writer.close() - diff --git a/tools/sos-open b/tools/sos-open deleted file mode 100755 index ffc9f051..00000000 --- a/tools/sos-open +++ /dev/null @@ -1,151 +0,0 @@ -#!/usr/bin/python - -import os, commands, getopt, sys, tarfile - -# FILES NEEDED BY CHECKSYSREPORT: /etc/redhat-release /etc/sysconfig/rhn/up2date rpm-Va installed-rpms uname lsmod - -CONFIG = {} -report_dirs = [] - -CONFIG["outdir"] = "/tmp/sysreports" -CONFIG["extract_reports"] = [] -CONFIG["spawn_terminal"] = False -if not sys.stdin.isatty(): CONFIG["spawn_terminal"] = True -else: CONFIG["spawn_terminal"] = False - -def cat(fname): - try: - fp = open(fname,"r") - print fp.read() - fp.close() - except: pass - -try: - opts, args = getopt.getopt(sys.argv[1:], "hi:w:vxf", ["help", "input="]) -except getopt.GetoptError: - # print help information and exit: - usage() - sys.exit(2) - -for o, a in opts: - if o == "-v": - verbose = True - if o == "-f": - CONFIG["spawn_terminal"] = False - if o == "-x": - CONFIG["spawn_terminal"] = True - sys.argv[sys.argv.index("-x")] = "-f" - if o in ("-h", "--help"): - usage() - sys.exit() - if o in ("-d"): - CONFIG["outdir"] = a - if o in ("-w"): - a = os.path.abspath(a) - try: os.stat(a) - except: print "ERROR: could not open", a - else: report_dirs.append(a) - - if o in ("-i"): - a = os.path.abspath(a) - try: os.stat(a) - except: print "ERROR: could not open", a - -if CONFIG["spawn_terminal"]: - print "spawning new terminal" - sys.argv[0] = os.path.abspath(sys.argv[0]) - os.system("gnome-terminal -e '%s'" % (' '.join(sys.argv))) - sys.exit() - -CONFIG["extract_reports"] = [os.path.abspath(a) for a in args] - -if not os.path.isdir(CONFIG["outdir"]): - if not os.path.exists(CONFIG["outdir"]): - exit("ERROR: working directory path exists but it's not a directory") - else: - try: os.mkdir(CONFIG["outdir"]) - except: exit("ERROR: could not create working directory") - -try: os.chdir(CONFIG["outdir"]) -except: exit("ERROR: could not chdir into working directory, please check permissions") - -for report in CONFIG["extract_reports"]: - report_ext = report.rsplit(".",1)[-1] - - if report_ext == "gpg": - clear_fname = os.path.join(CONFIG["outdir"],os.path.basename(report.rsplit(".",1)[0])) - status, output = commands.getstatusoutput("gpg --output %s %s" % (clear_fname,report)) - if status: - sys.exit("ERROR: could not decrypt using gpg" + output ) - report = clear_fname - report_ext = clear_fname.rsplit(".",1)[-1] - del clear_fname - - outdir = None - tar = tarfile.open(report, "r") - for tarinfo in tar: - if tarinfo.isdir(): outdir = tarinfo.name ; break - tar.close() - - if not outdir: - print("INFO: archive doesn't appear to be either a sysreport or sosreport") - cddir = os.path.basename(report) - for sout in [ ".tar.gz", ".tgz", ".tar.bz2" ]: - if cddir.endswith(sout): cddir = cddir[:-len(sout)] - cddir = os.path.abspath(os.path.join(CONFIG["outdir"],"extract_" + cddir)) - outdir = cddir - else: - cddir = CONFIG["outdir"] - outdir = os.path.abspath(os.path.join(CONFIG["outdir"], outdir)) - - extract = True - if os.path.isdir(outdir): - extract = False - yorno = False - print "This report already seems to have been extracted in:" - print " " + outdir - print - while yorno not in ['y','n']: yorno = raw_input("Do you want to replace it with a fresh copy ? (y/n) ").lower() - if yorno == 'y': - print "Deleting previous copy..." - os.system("chmod -R u+rw %s" % outdir) - os.system("rm -rf %s" % outdir) - extract = True - - if extract: - print "Extracting..." - if not os.path.isdir(cddir): - os.mkdir(cddir) - if report_ext == "bz2": - status, output = commands.getstatusoutput("tar xCfj %s %s" % (cddir,report)) - elif report_ext == "gz" or report_ext == "tgz" : - status, output = commands.getstatusoutput("tar xCfz %s %s" % (cddir,report)) - - if status: - print("ERROR: there was some problem extracting the report (%s)" % report) - - report_dirs.append(os.path.abspath(outdir)) - -if len(report_dirs) == 1 and os.path.isdir(report_dirs[0]): - os.chdir(report_dirs[0]) - - if os.path.isfile("sos_reports/diagnose.txt"): - print - print "Diagnostics messages available:" - print - fp = open("sos_reports/diagnose.txt","r") - for line in fp.readlines(): - print " " + line.strip("\n") - fp.close() - print - - report_dirs[0] - - print - print "The extracted report is located in: " - print " " + report_dirs[0] - print "Once finished, press exit to return." - print - cat("uname") - os.system("PS1='[SoS \W]\$ ' HOME='%s' /bin/bash -l" % (report_dirs[0]) ) - sys.exit(-1) |