Add job queued, started and finished timestamps to the tko db and
modify the parsing code to find these timestamps in the job keyval
file and insert them into the db.
Signed-off-by: John Admanski <jadmanski@google.com>
git-svn-id: http://test.kernel.org/svn/autotest/trunk@1246 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/tko/db.py b/tko/db.py
index 22d05b8..409d086 100644
--- a/tko/db.py
+++ b/tko/db.py
@@ -218,7 +218,10 @@
self.insert('jobs', {'tag':tag,
'label': job.label,
'username': job.user,
- 'machine_idx':job.machine_idx},
+ 'machine_idx': job.machine_idx,
+ 'queued_time': job.queued_time,
+ 'started_time': job.started_time,
+ 'finished_time': job.finished_time},
commit=commit)
job.index = self.get_last_autonumber_value()
for test in job.tests:
diff --git a/tko/migrations/002_add_job_timestamps.py b/tko/migrations/002_add_job_timestamps.py
new file mode 100644
index 0000000..73a1ccc
--- /dev/null
+++ b/tko/migrations/002_add_job_timestamps.py
@@ -0,0 +1,74 @@
+def migrate_up(manager):
+ manager.execute_script(ADD_COLUMNS_SQL)
+ manager.execute_script(ALTER_VIEWS_SQL)
+
+
+ADD_COLUMNS_SQL = """\
+ALTER TABLE jobs ADD COLUMN queued_time datetime NULL;
+ALTER TABLE jobs ADD COLUMN started_time datetime NULL;
+ALTER TABLE jobs ADD COLUMN finished_time datetime NULL;
+"""
+
+
+ALTER_VIEWS_SQL = """\
+ALTER VIEW test_view AS
+SELECT tests.test_idx,
+ tests.job_idx,
+ tests.test,
+ tests.subdir,
+ tests.kernel_idx,
+ tests.status,
+ tests.reason,
+ tests.machine_idx,
+ jobs.tag AS job_tag,
+ jobs.label AS job_label,
+ jobs.username AS job_username,
+ jobs.queued_time AS job_queued_time,
+ jobs.started_time AS job_started_time,
+ jobs.finished_time AS job_finished_time,
+ machines.hostname AS machine_hostname,
+ machines.machine_group,
+ machines.owner AS machine_owner,
+ kernels.kernel_hash,
+ kernels.base AS kernel_base,
+ kernels.printable AS kernel_printable,
+ status.word AS status_word
+FROM tests
+INNER JOIN jobs ON jobs.job_idx = tests.job_idx
+INNER JOIN machines ON machines.machine_idx = jobs.machine_idx
+INNER JOIN kernels ON kernels.kernel_idx = tests.kernel_idx
+INNER JOIN status ON status.status_idx = tests.status;
+
+-- perf_view (to make life easier for people trying to mine performance data)
+ALTER VIEW perf_view AS
+SELECT tests.test_idx,
+ tests.job_idx,
+ tests.test,
+ tests.subdir,
+ tests.kernel_idx,
+ tests.status,
+ tests.reason,
+ tests.machine_idx,
+ jobs.tag AS job_tag,
+ jobs.label AS job_label,
+ jobs.username AS job_username,
+ jobs.queued_time AS job_queued_time,
+ jobs.started_time AS job_started_time,
+ jobs.finished_time AS job_finished_time,
+ machines.hostname AS machine_hostname,
+ machines.machine_group,
+ machines.owner AS machine_owner,
+ kernels.kernel_hash,
+ kernels.base AS kernel_base,
+ kernels.printable AS kernel_printable,
+ status.word AS status_word,
+ iteration_result.iteration,
+ iteration_result.attribute AS iteration_key,
+ iteration_result.value AS iteration_value
+FROM tests
+INNER JOIN jobs ON jobs.job_idx = tests.job_idx
+INNER JOIN machines ON machines.machine_idx = jobs.machine_idx
+INNER JOIN kernels ON kernels.kernel_idx = tests.kernel_idx
+INNER JOIN status ON status.status_idx = tests.status
+INNER JOIN iteration_result ON iteration_result.test_idx = tests.kernel_idx;
+"""
diff --git a/tko/parse.py b/tko/parse.py
index 8a04f12..08fcb68 100755
--- a/tko/parse.py
+++ b/tko/parse.py
@@ -1,5 +1,5 @@
#!/usr/bin/python
-import os, re, md5, sys, email.Message, smtplib
+import os, re, md5, sys, email.Message, smtplib, datetime
client_bin = os.path.join(os.path.dirname(__file__), '../client/bin')
sys.path.insert(0, os.path.abspath(client_bin))
from autotest_utils import read_keyval
@@ -63,6 +63,13 @@
sys.stderr.write(str(info) + '\n')
+def keyval_timestamp(keyval, field):
+ val = keyval.get(field, None)
+ if val is not None:
+ val = datetime.datetime.fromtimestamp(int(val))
+ return val
+
+
class job:
def __init__(self, dir):
self.dir = dir
@@ -85,6 +92,9 @@
self.machine = keyval.get('hostname', None)
if self.machine:
assert ',' not in self.machine
+ self.queued_time = keyval_timestamp(keyval, 'job_queued')
+ self.started_time = keyval_timestamp(keyval, 'job_started')
+ self.finished_time = keyval_timestamp(keyval, 'job_finished')
self.machine_owner = keyval.get('owner', None)
if not self.machine: