Merge lp:~coreygoldberg/ubuntu-test-cases/touch-trace-export into lp:ubuntu-test-cases/touch

Proposed by Corey Goldberg
Status: Work in progress
Proposed branch: lp:~coreygoldberg/ubuntu-test-cases/touch-trace-export
Merge into: lp:ubuntu-test-cases/touch
Diff against target: 94 lines (+90/-0)
1 file modified
scripts/app-trace-export.py (+90/-0)
To merge this branch: bzr merge lp:~coreygoldberg/ubuntu-test-cases/touch-trace-export
Reviewer Review Type Date Requested Status
Ubuntu Test Case Developers Pending
Review via email: mp+204779@code.launchpad.net

Description of the change

This branch adds a new script: `scripts/app-trace-export.py`, used to parse app traces for benchmarking and export to external MongoDB.

usage: app-trace-export.py [-h] app_id path

Summary:
 * parses binary lttng traces
 * gathers relevant tracepoints and timestamps
 * generates a python dictionary with test run information and gathered tracepoints
 * pretty prints the result dict to console/stdout
 * sends the result to a remote MongoDB

(example with traces stored under ~/lttng-traces/)
run from a branch
  $ bzr branch lp:~coreygoldberg/ubuntu-test-cases/touch-trace-export tracing
  $ cd tracing
  $ ./scripts/app-trace-export.py sudoku-app ~/lttng-traces/sudoku-start-20131217-095828/ust/uid/32011/32-bit/

To post a comment you must log in.
142. By Corey Goldberg

merged trunk

143. By Corey Goldberg

refactor and fix pep8

Unmerged revisions

143. By Corey Goldberg

refactor and fix pep8

142. By Corey Goldberg

merged trunk

141. By Corey Goldberg

added yet more fields to json doc

140. By Corey Goldberg

added more fields to json doc

139. By Corey Goldberg

create json structured doc

138. By Corey Goldberg

fixed import

137. By Corey Goldberg

send results to mongodb

136. By Corey Goldberg

refactor script

135. By Corey Goldberg

import teds initial script

134. By Alex Chiang

Update tests/customizations/setup.sh to handle updated lp:savilerow project

lp:savilerow now includes the formerly separate tests/ branch, co-locating
both code and tests in the same branch.

Update the script here to bzr export the tests from the new location.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'scripts/app-trace-export.py'
2--- scripts/app-trace-export.py 1970-01-01 00:00:00 +0000
3+++ scripts/app-trace-export.py 2014-02-06 20:39:30 +0000
4@@ -0,0 +1,90 @@
5+#!/usr/bin/env python3
6+
7+"""
8+Export application trace events for app startup.
9+"""
10+
11+import argparse
12+import os
13+
14+from datetime import datetime
15+from pprint import pprint
16+
17+from babeltrace import TraceCollection
18+# Install Python bindings for libbabeltrace:
19+# $ sudo add-apt-repository ppa:ted/babeltrace-python
20+# $ sudo apt-get update
21+# $ sudo apt-get install babeltrace python3-libbabeltrace
22+
23+from pymongo import MongoClient
24+# Install Python MongoDB client:
25+# $ sudo apt-get install python3-pymongo
26+
27+
28+def parse_traces(trace_path):
29+ """
30+ Read binary traces and convert to dict of
31+ tracepoint names and timestamps. Timestamp format is:
32+ epoch secs + nanosecs.
33+ """
34+
35+ # Tracepoints to include for app startup
36+ tracepoints = (
37+ 'upstart_app_launch:libual_start_message_sent',
38+ 'upstart_app_launch:libual_start',
39+ 'upstart_app_launch:exec_pre_exec',
40+ 'upstart_app_launch:libual_start_message_callback',
41+ )
42+
43+ # Build up the traces collection
44+ traces = TraceCollection()
45+ ret = traces.add_trace(trace_path, 'ctf')
46+ if ret is None:
47+ raise IOError('Error adding trace')
48+
49+ # Record the timestamps
50+ timestamps = {}
51+ for event in traces.events:
52+ # We only want the event if it's the first occurance to
53+ # handle possibly messy traces.
54+ if event.name not in timestamps:
55+ # Keep only the timestamps we care about by event name
56+ if event.name in tracepoints:
57+ timestamps[event.name] = event.timestamp
58+
59+ return timestamps
60+
61+
62+def generate_doc(tracepoints):
63+ return dict(
64+ app_id=args.app_id,
65+ android_serial=os.environ.get('ANDROID_SERIAL'),
66+ image_type=os.environ.get('IMAGE_TYPE'),
67+ build_num=os.environ.get('BUILD_NUMBER'),
68+ build_id=os.environ.get('BUILD_ID'),
69+ job_name=os.environ.get('JOB_NAME'),
70+ node_name=os.environ.get('NODE_NAME'),
71+ datetime=datetime.utcnow(),
72+ tracepoints=tracepoints,
73+ )
74+
75+
76+def send_to_db(host, port, doc):
77+ db = MongoClient(host, port)
78+ posts = db.posts
79+ post_id = posts.insert(doc)
80+ return post_id
81+
82+
83+if __name__ == '__main__':
84+ parser = argparse.ArgumentParser()
85+ parser.add_argument('app_id', help='application identifier')
86+ parser.add_argument('path', help='path to trace')
87+ args = parser.parse_args()
88+
89+ tracepoints = parse_traces(args.path),
90+ doc = generate_doc(tracepoints)
91+
92+ pprint(doc)
93+
94+ send_to_db('localhost', 27017, doc)

Subscribers

People subscribed via source and target branches