Keith Haddow | 1e5c701 | 2016-03-09 16:05:37 -0800 | [diff] [blame] | 1 | import json |
lmr | 6f80e7a | 2010-02-04 03:18:28 +0000 | [diff] [blame] | 2 | import os |
jadmanski | cc54917 | 2008-05-21 18:11:51 +0000 | [diff] [blame] | 3 | |
| 4 | from autotest_lib.client.common_lib import utils |
| 5 | from autotest_lib.tko import utils as tko_utils |
jadmanski | 6e8bf75 | 2008-05-14 00:17:48 +0000 | [diff] [blame] | 6 | |
| 7 | |
mbligh | e79ebb0 | 2008-04-17 15:39:22 +0000 | [diff] [blame] | 8 | class job(object): |
Dennis Jeffrey | ccbc9d4 | 2013-07-23 12:16:45 -0700 | [diff] [blame] | 9 | """Represents a job.""" |
| 10 | |
jadmanski | f7fa2cc | 2008-10-01 14:13:23 +0000 | [diff] [blame] | 11 | def __init__(self, dir, user, label, machine, queued_time, started_time, |
showard | 71b9431 | 2009-08-20 23:40:02 +0000 | [diff] [blame] | 12 | finished_time, machine_owner, machine_group, aborted_by, |
showard | c1a98d1 | 2010-01-15 00:22:22 +0000 | [diff] [blame] | 13 | aborted_on, keyval_dict): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 14 | self.dir = dir |
| 15 | self.tests = [] |
| 16 | self.user = user |
| 17 | self.label = label |
| 18 | self.machine = machine |
| 19 | self.queued_time = queued_time |
| 20 | self.started_time = started_time |
| 21 | self.finished_time = finished_time |
| 22 | self.machine_owner = machine_owner |
showard | 71b9431 | 2009-08-20 23:40:02 +0000 | [diff] [blame] | 23 | self.machine_group = machine_group |
jadmanski | f7fa2cc | 2008-10-01 14:13:23 +0000 | [diff] [blame] | 24 | self.aborted_by = aborted_by |
| 25 | self.aborted_on = aborted_on |
showard | c1a98d1 | 2010-01-15 00:22:22 +0000 | [diff] [blame] | 26 | self.keyval_dict = keyval_dict |
Michael Tang | 5f74ffd | 2016-10-31 10:34:53 -0700 | [diff] [blame] | 27 | self.afe_parent_job_id = None |
| 28 | self.build_version = None |
| 29 | self.suite = None |
| 30 | self.board = None |
Prathmesh Prabhu | c2a8a6a | 2018-04-19 16:23:32 -0700 | [diff] [blame] | 31 | self.job_idx = None |
Prathmesh Prabhu | f5030d3 | 2018-04-19 16:08:55 -0700 | [diff] [blame] | 32 | # id of the corresponding tko_task_references entry. |
| 33 | # This table is used to refer to skylab task / afe job corresponding to |
| 34 | # this tko_job. |
| 35 | self.task_reference_id = None |
mbligh | e79ebb0 | 2008-04-17 15:39:22 +0000 | [diff] [blame] | 36 | |
jadmanski | a8e302a | 2008-09-25 19:49:38 +0000 | [diff] [blame] | 37 | @staticmethod |
| 38 | def read_keyval(dir): |
Dennis Jeffrey | ccbc9d4 | 2013-07-23 12:16:45 -0700 | [diff] [blame] | 39 | """ |
| 40 | Read job keyval files. |
| 41 | |
| 42 | @param dir: String name of directory containing job keyval files. |
| 43 | |
| 44 | @return A dictionary containing job keyvals. |
| 45 | |
| 46 | """ |
jadmanski | a8e302a | 2008-09-25 19:49:38 +0000 | [diff] [blame] | 47 | dir = os.path.normpath(dir) |
| 48 | top_dir = tko_utils.find_toplevel_job_dir(dir) |
| 49 | if not top_dir: |
| 50 | top_dir = dir |
| 51 | assert(dir.startswith(top_dir)) |
| 52 | |
Dennis Jeffrey | ccbc9d4 | 2013-07-23 12:16:45 -0700 | [diff] [blame] | 53 | # Pull in and merge all the keyval files, with higher-level |
| 54 | # overriding values in the lower-level ones. |
jadmanski | a8e302a | 2008-09-25 19:49:38 +0000 | [diff] [blame] | 55 | keyval = {} |
| 56 | while True: |
| 57 | try: |
jadmanski | fc4e338 | 2008-10-02 16:19:19 +0000 | [diff] [blame] | 58 | upper_keyval = utils.read_keyval(dir) |
| 59 | # HACK: exclude hostname from the override - this is a special |
Dennis Jeffrey | ccbc9d4 | 2013-07-23 12:16:45 -0700 | [diff] [blame] | 60 | # case where we want lower to override higher. |
| 61 | if 'hostname' in upper_keyval and 'hostname' in keyval: |
| 62 | del upper_keyval['hostname'] |
jadmanski | 8e00afa | 2008-10-02 16:22:04 +0000 | [diff] [blame] | 63 | keyval.update(upper_keyval) |
jadmanski | a8e302a | 2008-09-25 19:49:38 +0000 | [diff] [blame] | 64 | except IOError: |
Dennis Jeffrey | ccbc9d4 | 2013-07-23 12:16:45 -0700 | [diff] [blame] | 65 | pass # If the keyval can't be read just move on to the next. |
jadmanski | a8e302a | 2008-09-25 19:49:38 +0000 | [diff] [blame] | 66 | if dir == top_dir: |
| 67 | break |
| 68 | else: |
Dennis Jeffrey | ccbc9d4 | 2013-07-23 12:16:45 -0700 | [diff] [blame] | 69 | assert(dir != '/') |
jadmanski | a8e302a | 2008-09-25 19:49:38 +0000 | [diff] [blame] | 70 | dir = os.path.dirname(dir) |
| 71 | return keyval |
| 72 | |
| 73 | |
mbligh | e79ebb0 | 2008-04-17 15:39:22 +0000 | [diff] [blame] | 74 | class kernel(object): |
Dennis Jeffrey | ccbc9d4 | 2013-07-23 12:16:45 -0700 | [diff] [blame] | 75 | """Represents a kernel.""" |
| 76 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 77 | def __init__(self, base, patches, kernel_hash): |
| 78 | self.base = base |
| 79 | self.patches = patches |
| 80 | self.kernel_hash = kernel_hash |
mbligh | e79ebb0 | 2008-04-17 15:39:22 +0000 | [diff] [blame] | 81 | |
| 82 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 83 | @staticmethod |
| 84 | def compute_hash(base, hashes): |
Dennis Jeffrey | ccbc9d4 | 2013-07-23 12:16:45 -0700 | [diff] [blame] | 85 | """Compute a hash given the base string and hashes for each patch. |
| 86 | |
| 87 | @param base: A string representing the kernel base. |
| 88 | @param hashes: A list of hashes, where each hash is associated with a |
| 89 | patch of this kernel. |
| 90 | |
| 91 | @return A string representing the computed hash. |
| 92 | |
| 93 | """ |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 94 | key_string = ','.join([base] + hashes) |
lmr | 6f80e7a | 2010-02-04 03:18:28 +0000 | [diff] [blame] | 95 | return utils.hash('md5', key_string).hexdigest() |
jadmanski | 6e8bf75 | 2008-05-14 00:17:48 +0000 | [diff] [blame] | 96 | |
| 97 | |
mbligh | e79ebb0 | 2008-04-17 15:39:22 +0000 | [diff] [blame] | 98 | class test(object): |
Dennis Jeffrey | ccbc9d4 | 2013-07-23 12:16:45 -0700 | [diff] [blame] | 99 | """Represents a test.""" |
| 100 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 101 | def __init__(self, subdir, testname, status, reason, test_kernel, |
| 102 | machine, started_time, finished_time, iterations, |
Dennis Jeffrey | 368c54b | 2013-07-24 11:19:03 -0700 | [diff] [blame] | 103 | attributes, perf_values, labels): |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 104 | self.subdir = subdir |
| 105 | self.testname = testname |
| 106 | self.status = status |
| 107 | self.reason = reason |
| 108 | self.kernel = test_kernel |
| 109 | self.machine = machine |
| 110 | self.started_time = started_time |
| 111 | self.finished_time = finished_time |
| 112 | self.iterations = iterations |
| 113 | self.attributes = attributes |
Dennis Jeffrey | 368c54b | 2013-07-24 11:19:03 -0700 | [diff] [blame] | 114 | self.perf_values = perf_values |
jadmanski | 9b6babf | 2009-04-21 17:57:40 +0000 | [diff] [blame] | 115 | self.labels = labels |
mbligh | e79ebb0 | 2008-04-17 15:39:22 +0000 | [diff] [blame] | 116 | |
| 117 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 118 | @staticmethod |
| 119 | def load_iterations(keyval_path): |
Dennis Jeffrey | ccbc9d4 | 2013-07-23 12:16:45 -0700 | [diff] [blame] | 120 | """Abstract method to load a list of iterations from a keyval file. |
| 121 | |
| 122 | @param keyval_path: String path to a keyval file. |
| 123 | |
| 124 | @return A list of iteration objects. |
| 125 | |
| 126 | """ |
Dennis Jeffrey | 05eb4b1 | 2013-07-17 11:11:52 -0700 | [diff] [blame] | 127 | raise NotImplementedError |
| 128 | |
| 129 | |
| 130 | @staticmethod |
| 131 | def load_perf_values(perf_values_file): |
Dennis Jeffrey | ccbc9d4 | 2013-07-23 12:16:45 -0700 | [diff] [blame] | 132 | """Loads perf values from a perf measurements file. |
| 133 | |
| 134 | @param perf_values_file: The string path to a perf measurements file. |
| 135 | |
| 136 | @return A list of perf_value_iteration objects. |
| 137 | |
| 138 | """ |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 139 | raise NotImplementedError |
jadmanski | cc54917 | 2008-05-21 18:11:51 +0000 | [diff] [blame] | 140 | |
| 141 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 142 | @classmethod |
| 143 | def parse_test(cls, job, subdir, testname, status, reason, test_kernel, |
jadmanski | 74eebf3 | 2008-07-15 20:04:42 +0000 | [diff] [blame] | 144 | started_time, finished_time, existing_instance=None): |
Dennis Jeffrey | 05eb4b1 | 2013-07-17 11:11:52 -0700 | [diff] [blame] | 145 | """ |
| 146 | Parse test result files to construct a complete test instance. |
| 147 | |
| 148 | Given a job and the basic metadata about the test that can be |
| 149 | extracted from the status logs, parse the test result files (keyval |
| 150 | files and perf measurement files) and use them to construct a complete |
| 151 | test instance. |
| 152 | |
| 153 | @param job: A job object. |
| 154 | @param subdir: The string subdirectory name for the given test. |
| 155 | @param testname: The name of the test. |
| 156 | @param status: The status of the test. |
| 157 | @param reason: The reason string for the test. |
| 158 | @param test_kernel: The kernel of the test. |
| 159 | @param started_time: The start time of the test. |
| 160 | @param finished_time: The finish time of the test. |
| 161 | @param existing_instance: An existing test instance. |
| 162 | |
| 163 | @return A test instance that has the complete information. |
| 164 | |
| 165 | """ |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 166 | tko_utils.dprint("parsing test %s %s" % (subdir, testname)) |
jadmanski | cc54917 | 2008-05-21 18:11:51 +0000 | [diff] [blame] | 167 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 168 | if subdir: |
Dennis Jeffrey | ccbc9d4 | 2013-07-23 12:16:45 -0700 | [diff] [blame] | 169 | # Grab iterations from the results keyval. |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 170 | iteration_keyval = os.path.join(job.dir, subdir, |
Dennis Jeffrey | ccbc9d4 | 2013-07-23 12:16:45 -0700 | [diff] [blame] | 171 | 'results', 'keyval') |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 172 | iterations = cls.load_iterations(iteration_keyval) |
jadmanski | cc54917 | 2008-05-21 18:11:51 +0000 | [diff] [blame] | 173 | |
Dennis Jeffrey | 05eb4b1 | 2013-07-17 11:11:52 -0700 | [diff] [blame] | 174 | # Grab perf values from the perf measurements file. |
| 175 | perf_values_file = os.path.join(job.dir, subdir, |
Keith Haddow | 1e5c701 | 2016-03-09 16:05:37 -0800 | [diff] [blame] | 176 | 'results', 'results-chart.json') |
| 177 | perf_values = {} |
| 178 | if os.path.exists(perf_values_file): |
| 179 | with open(perf_values_file, 'r') as fp: |
| 180 | contents = fp.read() |
| 181 | if contents: |
| 182 | perf_values = json.loads(contents) |
Dennis Jeffrey | 05eb4b1 | 2013-07-17 11:11:52 -0700 | [diff] [blame] | 183 | |
Dennis Jeffrey | ccbc9d4 | 2013-07-23 12:16:45 -0700 | [diff] [blame] | 184 | # Grab test attributes from the subdir keyval. |
| 185 | test_keyval = os.path.join(job.dir, subdir, 'keyval') |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 186 | attributes = test.load_attributes(test_keyval) |
| 187 | else: |
| 188 | iterations = [] |
Keith Haddow | 1e5c701 | 2016-03-09 16:05:37 -0800 | [diff] [blame] | 189 | perf_values = {} |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 190 | attributes = {} |
jadmanski | cc54917 | 2008-05-21 18:11:51 +0000 | [diff] [blame] | 191 | |
Dennis Jeffrey | ccbc9d4 | 2013-07-23 12:16:45 -0700 | [diff] [blame] | 192 | # Grab test+host attributes from the host keyval. |
showard | 71b9431 | 2009-08-20 23:40:02 +0000 | [diff] [blame] | 193 | host_keyval = cls.parse_host_keyval(job.dir, job.machine) |
Dennis Jeffrey | ccbc9d4 | 2013-07-23 12:16:45 -0700 | [diff] [blame] | 194 | attributes.update(dict(('host-%s' % k, v) |
showard | 71b9431 | 2009-08-20 23:40:02 +0000 | [diff] [blame] | 195 | for k, v in host_keyval.iteritems())) |
jadmanski | b591fba | 2008-09-10 16:19:22 +0000 | [diff] [blame] | 196 | |
jadmanski | 74eebf3 | 2008-07-15 20:04:42 +0000 | [diff] [blame] | 197 | if existing_instance: |
| 198 | def constructor(*args, **dargs): |
Dennis Jeffrey | ccbc9d4 | 2013-07-23 12:16:45 -0700 | [diff] [blame] | 199 | """Initializes an existing test instance.""" |
jadmanski | 74eebf3 | 2008-07-15 20:04:42 +0000 | [diff] [blame] | 200 | existing_instance.__init__(*args, **dargs) |
| 201 | return existing_instance |
| 202 | else: |
| 203 | constructor = cls |
Dennis Jeffrey | 368c54b | 2013-07-24 11:19:03 -0700 | [diff] [blame] | 204 | |
jadmanski | 74eebf3 | 2008-07-15 20:04:42 +0000 | [diff] [blame] | 205 | return constructor(subdir, testname, status, reason, test_kernel, |
| 206 | job.machine, started_time, finished_time, |
Dennis Jeffrey | 368c54b | 2013-07-24 11:19:03 -0700 | [diff] [blame] | 207 | iterations, attributes, perf_values, []) |
jadmanski | 74eebf3 | 2008-07-15 20:04:42 +0000 | [diff] [blame] | 208 | |
| 209 | |
| 210 | @classmethod |
| 211 | def parse_partial_test(cls, job, subdir, testname, reason, test_kernel, |
| 212 | started_time): |
Dennis Jeffrey | ccbc9d4 | 2013-07-23 12:16:45 -0700 | [diff] [blame] | 213 | """ |
| 214 | Create a test instance representing a partial test result. |
| 215 | |
| 216 | Given a job and the basic metadata available when a test is |
jadmanski | 74eebf3 | 2008-07-15 20:04:42 +0000 | [diff] [blame] | 217 | started, create a test instance representing the partial result. |
| 218 | Assume that since the test is not complete there are no results files |
Dennis Jeffrey | ccbc9d4 | 2013-07-23 12:16:45 -0700 | [diff] [blame] | 219 | actually available for parsing. |
jadmanski | 74eebf3 | 2008-07-15 20:04:42 +0000 | [diff] [blame] | 220 | |
Dennis Jeffrey | ccbc9d4 | 2013-07-23 12:16:45 -0700 | [diff] [blame] | 221 | @param job: A job object. |
| 222 | @param subdir: The string subdirectory name for the given test. |
| 223 | @param testname: The name of the test. |
| 224 | @param reason: The reason string for the test. |
| 225 | @param test_kernel: The kernel of the test. |
| 226 | @param started_time: The start time of the test. |
| 227 | |
| 228 | @return A test instance that has partial test information. |
| 229 | |
| 230 | """ |
| 231 | tko_utils.dprint('parsing partial test %s %s' % (subdir, testname)) |
| 232 | |
| 233 | return cls(subdir, testname, 'RUNNING', reason, test_kernel, |
Dennis Jeffrey | 368c54b | 2013-07-24 11:19:03 -0700 | [diff] [blame] | 234 | job.machine, started_time, None, [], {}, [], []) |
jadmanski | cc54917 | 2008-05-21 18:11:51 +0000 | [diff] [blame] | 235 | |
| 236 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 237 | @staticmethod |
| 238 | def load_attributes(keyval_path): |
Dennis Jeffrey | ccbc9d4 | 2013-07-23 12:16:45 -0700 | [diff] [blame] | 239 | """ |
| 240 | Load test attributes from a test keyval path. |
| 241 | |
| 242 | Load the test attributes into a dictionary from a test |
| 243 | keyval path. Does not assume that the path actually exists. |
| 244 | |
| 245 | @param keyval_path: The string path to a keyval file. |
| 246 | |
| 247 | @return A dictionary representing the test keyvals. |
| 248 | |
| 249 | """ |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 250 | if not os.path.exists(keyval_path): |
| 251 | return {} |
| 252 | return utils.read_keyval(keyval_path) |
jadmanski | cc54917 | 2008-05-21 18:11:51 +0000 | [diff] [blame] | 253 | |
| 254 | |
jadmanski | b591fba | 2008-09-10 16:19:22 +0000 | [diff] [blame] | 255 | @staticmethod |
Dan Shi | ba7b981 | 2016-06-30 10:55:58 -0700 | [diff] [blame] | 256 | def _parse_keyval(job_dir, sub_keyval_path): |
| 257 | """ |
| 258 | Parse a file of keyvals. |
| 259 | |
| 260 | @param job_dir: The string directory name of the associated job. |
| 261 | @param sub_keyval_path: Path to a keyval file relative to job_dir. |
| 262 | |
| 263 | @return A dictionary representing the keyvals. |
| 264 | |
| 265 | """ |
| 266 | # The "real" job dir may be higher up in the directory tree. |
| 267 | job_dir = tko_utils.find_toplevel_job_dir(job_dir) |
| 268 | if not job_dir: |
| 269 | return {} # We can't find a top-level job dir with job keyvals. |
| 270 | |
| 271 | # The keyval is <job_dir>/`sub_keyval_path` if it exists. |
| 272 | keyval_path = os.path.join(job_dir, sub_keyval_path) |
| 273 | if os.path.isfile(keyval_path): |
| 274 | return utils.read_keyval(keyval_path) |
| 275 | else: |
| 276 | return {} |
| 277 | |
| 278 | |
| 279 | @staticmethod |
jadmanski | b591fba | 2008-09-10 16:19:22 +0000 | [diff] [blame] | 280 | def parse_host_keyval(job_dir, hostname): |
Dennis Jeffrey | ccbc9d4 | 2013-07-23 12:16:45 -0700 | [diff] [blame] | 281 | """ |
| 282 | Parse host keyvals. |
| 283 | |
| 284 | @param job_dir: The string directory name of the associated job. |
| 285 | @param hostname: The string hostname. |
| 286 | |
| 287 | @return A dictionary representing the host keyvals. |
| 288 | |
| 289 | """ |
Dan Shi | ba7b981 | 2016-06-30 10:55:58 -0700 | [diff] [blame] | 290 | # The host keyval is <job_dir>/host_keyvals/<hostname> if it exists. |
| 291 | return test._parse_keyval(job_dir, |
| 292 | os.path.join('host_keyvals', hostname)) |
jadmanski | b591fba | 2008-09-10 16:19:22 +0000 | [diff] [blame] | 293 | |
Dan Shi | ba7b981 | 2016-06-30 10:55:58 -0700 | [diff] [blame] | 294 | |
| 295 | @staticmethod |
| 296 | def parse_job_keyval(job_dir): |
| 297 | """ |
| 298 | Parse job keyvals. |
| 299 | |
| 300 | @param job_dir: The string directory name of the associated job. |
| 301 | |
| 302 | @return A dictionary representing the job keyvals. |
| 303 | |
| 304 | """ |
| 305 | # The job keyval is <job_dir>/keyval if it exists. |
| 306 | return test._parse_keyval(job_dir, 'keyval') |
jadmanski | b591fba | 2008-09-10 16:19:22 +0000 | [diff] [blame] | 307 | |
| 308 | |
mbligh | e79ebb0 | 2008-04-17 15:39:22 +0000 | [diff] [blame] | 309 | class patch(object): |
Dennis Jeffrey | ccbc9d4 | 2013-07-23 12:16:45 -0700 | [diff] [blame] | 310 | """Represents a patch.""" |
| 311 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 312 | def __init__(self, spec, reference, hash): |
| 313 | self.spec = spec |
| 314 | self.reference = reference |
| 315 | self.hash = hash |
mbligh | e79ebb0 | 2008-04-17 15:39:22 +0000 | [diff] [blame] | 316 | |
| 317 | |
| 318 | class iteration(object): |
Dennis Jeffrey | ccbc9d4 | 2013-07-23 12:16:45 -0700 | [diff] [blame] | 319 | """Represents an iteration.""" |
| 320 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 321 | def __init__(self, index, attr_keyval, perf_keyval): |
| 322 | self.index = index |
| 323 | self.attr_keyval = attr_keyval |
| 324 | self.perf_keyval = perf_keyval |
jadmanski | cc54917 | 2008-05-21 18:11:51 +0000 | [diff] [blame] | 325 | |
| 326 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 327 | @staticmethod |
| 328 | def parse_line_into_dicts(line, attr_dict, perf_dict): |
Dennis Jeffrey | ccbc9d4 | 2013-07-23 12:16:45 -0700 | [diff] [blame] | 329 | """ |
| 330 | Abstract method to parse a keyval line and insert it into a dictionary. |
| 331 | |
| 332 | @param line: The string line to parse. |
| 333 | @param attr_dict: Dictionary of generic iteration attributes. |
| 334 | @param perf_dict: Dictionary of iteration performance results. |
| 335 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 336 | """ |
| 337 | raise NotImplementedError |
jadmanski | cc54917 | 2008-05-21 18:11:51 +0000 | [diff] [blame] | 338 | |
| 339 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 340 | @classmethod |
| 341 | def load_from_keyval(cls, keyval_path): |
Dennis Jeffrey | ccbc9d4 | 2013-07-23 12:16:45 -0700 | [diff] [blame] | 342 | """ |
| 343 | Load a list of iterations from an iteration keyval file. |
| 344 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 345 | Keyval data from separate iterations is separated by blank |
| 346 | lines. Makes use of the parse_line_into_dicts method to |
Dennis Jeffrey | ccbc9d4 | 2013-07-23 12:16:45 -0700 | [diff] [blame] | 347 | actually parse the individual lines. |
| 348 | |
| 349 | @param keyval_path: The string path to a keyval file. |
| 350 | |
| 351 | @return A list of iteration objects. |
| 352 | |
| 353 | """ |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 354 | if not os.path.exists(keyval_path): |
| 355 | return [] |
jadmanski | cc54917 | 2008-05-21 18:11:51 +0000 | [diff] [blame] | 356 | |
jadmanski | 0afbb63 | 2008-06-06 21:10:57 +0000 | [diff] [blame] | 357 | iterations = [] |
| 358 | index = 1 |
| 359 | attr, perf = {}, {} |
| 360 | for line in file(keyval_path): |
| 361 | line = line.strip() |
| 362 | if line: |
| 363 | cls.parse_line_into_dicts(line, attr, perf) |
| 364 | else: |
| 365 | iterations.append(cls(index, attr, perf)) |
| 366 | index += 1 |
| 367 | attr, perf = {}, {} |
| 368 | if attr or perf: |
| 369 | iterations.append(cls(index, attr, perf)) |
| 370 | return iterations |
Dennis Jeffrey | 05eb4b1 | 2013-07-17 11:11:52 -0700 | [diff] [blame] | 371 | |
| 372 | |
| 373 | class perf_value_iteration(object): |
Dennis Jeffrey | ccbc9d4 | 2013-07-23 12:16:45 -0700 | [diff] [blame] | 374 | """Represents a perf value iteration.""" |
| 375 | |
Dennis Jeffrey | 05eb4b1 | 2013-07-17 11:11:52 -0700 | [diff] [blame] | 376 | def __init__(self, index, perf_measurements): |
| 377 | """ |
| 378 | Initializes the perf values for a particular test iteration. |
| 379 | |
| 380 | @param index: The integer iteration number. |
| 381 | @param perf_measurements: A list of dictionaries, where each dictionary |
| 382 | contains the information for a measured perf metric from the |
| 383 | current iteration. |
| 384 | |
| 385 | """ |
| 386 | self.index = index |
| 387 | self.perf_measurements = perf_measurements |
| 388 | |
| 389 | |
| 390 | def add_measurement(self, measurement): |
| 391 | """ |
| 392 | Appends to the list of perf measurements for this iteration. |
| 393 | |
| 394 | @param measurement: A dictionary containing information for a measured |
| 395 | perf metric. |
| 396 | |
| 397 | """ |
| 398 | self.perf_measurements.append(measurement) |
| 399 | |
| 400 | |
| 401 | @staticmethod |
| 402 | def parse_line_into_dict(line): |
| 403 | """ |
| 404 | Abstract method to parse an individual perf measurement line. |
| 405 | |
| 406 | @param line: A string line from the perf measurement output file. |
| 407 | |
| 408 | @return A dicionary representing the information for a measured perf |
| 409 | metric from one line of the perf measurement output file, or an |
| 410 | empty dictionary if the line cannot be parsed successfully. |
| 411 | |
| 412 | """ |
| 413 | raise NotImplementedError |
| 414 | |