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

Subscribers

People subscribed via source and target branches