Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(236)

Side by Side Diff: client/bin/base_sysinfo.py

Issue 6246035: Merge remote branch 'cros/upstream' into master (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/autotest.git@master
Patch Set: patch Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 import os, shutil, re, glob, subprocess, logging 1 import os, shutil, re, glob, subprocess, logging
2 2
3 from autotest_lib.client.common_lib import log 3 from autotest_lib.client.common_lib import log
4 from autotest_lib.client.bin import utils, package 4 from autotest_lib.client.bin import utils, package
5 5
6 6
7 _DEFAULT_COMMANDS_TO_LOG_PER_TEST = [] 7 _DEFAULT_COMMANDS_TO_LOG_PER_TEST = []
8 _DEFAULT_COMMANDS_TO_LOG_PER_BOOT = [ 8 _DEFAULT_COMMANDS_TO_LOG_PER_BOOT = [
9 "lspci -vvn", "mount", "uptime", 9 "lspci -vvn", "mount", "uptime",
10 ] 10 ]
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 def __hash__(self): 71 def __hash__(self):
72 return hash((self.path, self.logf)) 72 return hash((self.path, self.logf))
73 73
74 74
75 def run(self, logdir): 75 def run(self, logdir):
76 if os.path.exists(self.path): 76 if os.path.exists(self.path):
77 shutil.copyfile(self.path, os.path.join(logdir, self.logf)) 77 shutil.copyfile(self.path, os.path.join(logdir, self.logf))
78 78
79 79
80 class command(loggable): 80 class command(loggable):
81 def __init__(self, cmd, logf=None, log_in_keyval=False): 81 def __init__(self, cmd, logf=None, log_in_keyval=False, compress_log=False):
82 if not logf: 82 if not logf:
83 logf = cmd.replace(" ", "_") 83 logf = cmd.replace(" ", "_")
84 super(command, self).__init__(logf, log_in_keyval) 84 super(command, self).__init__(logf, log_in_keyval)
85 self.cmd = cmd 85 self.cmd = cmd
86 self._compress_log = compress_log
86 87
87 88
88 def __repr__(self): 89 def __repr__(self):
89 r = "sysinfo.command(%r, %r, %r)" 90 r = "sysinfo.command(%r, %r, %r)"
90 r %= (self.cmd, self.logf, self.log_in_keyval) 91 r %= (self.cmd, self.logf, self.log_in_keyval)
91 return r 92 return r
92 93
93 94
94 def __eq__(self, other): 95 def __eq__(self, other):
95 if isinstance(other, command): 96 if isinstance(other, command):
96 return (self.cmd, self.logf) == (other.cmd, other.logf) 97 return (self.cmd, self.logf) == (other.cmd, other.logf)
97 elif isinstance(other, loggable): 98 elif isinstance(other, loggable):
98 return False 99 return False
99 return NotImplemented 100 return NotImplemented
100 101
101 102
102 def __ne__(self, other): 103 def __ne__(self, other):
103 result = self.__eq__(other) 104 result = self.__eq__(other)
104 if result is NotImplemented: 105 if result is NotImplemented:
105 return result 106 return result
106 return not result 107 return not result
107 108
108 109
109 def __hash__(self): 110 def __hash__(self):
110 return hash((self.cmd, self.logf)) 111 return hash((self.cmd, self.logf))
111 112
112 113
113 def run(self, logdir): 114 def run(self, logdir):
114 stdin = open(os.devnull, "r")
115 stdout = open(os.path.join(logdir, self.logf), "w")
116 stderr = open(os.devnull, "w")
117 env = os.environ.copy() 115 env = os.environ.copy()
118 if "PATH" not in env: 116 if "PATH" not in env:
119 env["PATH"] = "/usr/bin:/bin" 117 env["PATH"] = "/usr/bin:/bin"
120 subprocess.call(self.cmd, stdin=stdin, stdout=stdout, stderr=stderr, 118 logf_path = os.path.join(logdir, self.logf)
121 shell=True, env=env) 119 stdin = open(os.devnull, "r")
122 for f in (stdin, stdout, stderr): 120 stderr = open(os.devnull, "w")
123 f.close() 121 stdout = open(logf_path, "w")
122 try:
123 subprocess.call(self.cmd, stdin=stdin, stdout=stdout, stderr=stderr,
124 shell=True, env=env)
125 finally:
126 for f in (stdin, stdout, stderr):
127 f.close()
128 if self._compress_log and os.path.exists(logf_path):
129 utils.system('gzip -9 "%s"' % logf_path, ignore_status=True)
124 130
125 131
126 class base_sysinfo(object): 132 class base_sysinfo(object):
127 def __init__(self, job_resultsdir): 133 def __init__(self, job_resultsdir):
128 self.sysinfodir = self._get_sysinfodir(job_resultsdir) 134 self.sysinfodir = self._get_sysinfodir(job_resultsdir)
129 135
130 # pull in the post-test logs to collect 136 # pull in the post-test logs to collect
131 self.test_loggables = set() 137 self.test_loggables = set()
132 for cmd in _DEFAULT_COMMANDS_TO_LOG_PER_TEST: 138 for cmd in _DEFAULT_COMMANDS_TO_LOG_PER_TEST:
133 self.test_loggables.add(command(cmd)) 139 self.test_loggables.add(command(cmd))
(...skipping 20 matching lines...) Expand all
154 self.after_iteration_loggables = set() 160 self.after_iteration_loggables = set()
155 for cmd in _DEFAULT_COMMANDS_TO_LOG_AFTER_ITERATION: 161 for cmd in _DEFAULT_COMMANDS_TO_LOG_AFTER_ITERATION:
156 self.after_iteration_loggables.add( 162 self.after_iteration_loggables.add(
157 command(cmd, logf=cmd.replace(" ", "_") + '.after')) 163 command(cmd, logf=cmd.replace(" ", "_") + '.after'))
158 for fname in _DEFAULT_FILES_TO_LOG_AFTER_ITERATION: 164 for fname in _DEFAULT_FILES_TO_LOG_AFTER_ITERATION:
159 self.after_iteration_loggables.add( 165 self.after_iteration_loggables.add(
160 logfile(fname, logf=os.path.basename(fname) + '.after')) 166 logfile(fname, logf=os.path.basename(fname) + '.after'))
161 167
162 # add in a couple of extra files and commands we want to grab 168 # add in a couple of extra files and commands we want to grab
163 self.test_loggables.add(command("df -mP", logf="df")) 169 self.test_loggables.add(command("df -mP", logf="df"))
164 self.test_loggables.add(command("dmesg -c", logf="dmesg")) 170 # We compress the dmesg because it can get large when kernels are
171 # configured with a large buffer and some tests trigger OOMs or
172 # other large "spam" that fill it up...
173 self.test_loggables.add(command("dmesg -c", logf="dmesg",
174 compress_log=True))
165 self.boot_loggables.add(logfile("/proc/cmdline", 175 self.boot_loggables.add(logfile("/proc/cmdline",
166 log_in_keyval=True)) 176 log_in_keyval=True))
167 # log /proc/mounts but with custom filename since we already 177 # log /proc/mounts but with custom filename since we already
168 # log the output of the "mount" command as the filename "mount" 178 # log the output of the "mount" command as the filename "mount"
169 self.boot_loggables.add(logfile('/proc/mounts', logf='proc_mounts')) 179 self.boot_loggables.add(logfile('/proc/mounts', logf='proc_mounts'))
170 self.boot_loggables.add(command("uname -a", logf="uname", 180 self.boot_loggables.add(command("uname -a", logf="uname",
171 log_in_keyval=True)) 181 log_in_keyval=True))
172 182
173 183
174 def serialize(self): 184 def serialize(self):
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 match = re.search(r"^MemTotal:\s+(\d+) kB$", mem_data, 366 match = re.search(r"^MemTotal:\s+(\d+) kB$", mem_data,
357 re.MULTILINE) 367 re.MULTILINE)
358 if match: 368 if match:
359 keyval["sysinfo-memtotal-in-kb"] = match.group(1) 369 keyval["sysinfo-memtotal-in-kb"] = match.group(1)
360 370
361 # guess the system's total physical memory, including sys tables 371 # guess the system's total physical memory, including sys tables
362 keyval["sysinfo-phys-mbytes"] = utils.rounded_memtotal()//1024 372 keyval["sysinfo-phys-mbytes"] = utils.rounded_memtotal()//1024
363 373
364 # return what we collected 374 # return what we collected
365 return keyval 375 return keyval
OLDNEW
« cli/job.py ('K') | « client/bin/autotest ('k') | client/bin/harness.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698