Skip to content

Commit

Permalink
Merging to top of mozilla repo
Browse files Browse the repository at this point in the history
  • Loading branch information
Clint Talbert committed Mar 7, 2013
2 parents 0d24d57 + 2b8c388 commit 10cffed
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 55 deletions.
83 changes: 53 additions & 30 deletions b2gperf/b2gperf.py
Expand Up @@ -12,7 +12,7 @@
import time
from urlparse import urlparse
import xml.dom.minidom
from zipfile import ZipFile
import zipfile

from progressbar import Counter
from progressbar import ProgressBar
Expand All @@ -28,7 +28,7 @@

class DatazillaPerfPoster(object):

def __init__(self, marionette, datazilla_config=None):
def __init__(self, marionette, datazilla_config=None, sources=None):
self.marionette = marionette

settings = gaiatest.GaiaData(self.marionette).all_settings # get all settings
Expand All @@ -38,19 +38,28 @@ def __init__(self, marionette, datazilla_config=None):
self.ancillary_data = {}

if gaiatest.GaiaDevice(self.marionette).is_android_build:
# get gaia revision
device_manager = mozdevice.DeviceManagerADB()
app_zip = device_manager.pullFile('/data/local/webapps/settings.gaiamobile.org/application.zip')
with ZipFile(StringIO(app_zip)).open('resources/gaia_commit.txt') as f:
self.ancillary_data['gaia_revision'] = f.read().splitlines()[0]

# get gecko and build revisions
sources_xml = xml.dom.minidom.parseString(device_manager.catFile('system/sources.xml'))
for element in sources_xml.getElementsByTagName('project'):
path = element.getAttribute('path')
revision = element.getAttribute('revision')
if path in ['gecko', 'build']:
self.ancillary_data['_'.join([path, 'revision'])] = revision
# get gaia, gecko and build revisions
try:
device_manager = mozdevice.DeviceManagerADB()
app_zip = device_manager.pullFile('/data/local/webapps/settings.gaiamobile.org/application.zip')
with zipfile.ZipFile(StringIO(app_zip)).open('resources/gaia_commit.txt') as f:
self.ancillary_data['gaia_revision'] = f.read().splitlines()[0]
except zipfile.BadZipfile:
# the zip file will not exist if Gaia has not been flashed to
# the device, so we fall back to the sources file
pass

try:
sources_xml = sources and xml.dom.minidom.parse(sources) or xml.dom.minidom.parseString(device_manager.catFile('system/sources.xml'))
for element in sources_xml.getElementsByTagName('project'):
path = element.getAttribute('path')
revision = element.getAttribute('revision')
if not self.ancillary_data.get('gaia_revision') and path in 'gaia':
self.ancillary_data['gaia_revision'] = revision
if path in ['gecko', 'build']:
self.ancillary_data['_'.join([path, 'revision'])] = revision
except:
pass

self.required = {
'gaia revision': self.ancillary_data.get('gaia_revision'),
Expand All @@ -77,9 +86,9 @@ def __init__(self, marionette, datazilla_config=None):
def post_to_datazilla(self, results, app_name):
# Prepare DataZilla results
res = dzclient.DatazillaResult()
test_suite = app_name.replace(' ', '_').lower()
res.add_testsuite(test_suite)
for metric in results.keys():
test_suite = app_name.replace(' ', '_').lower()
res.add_testsuite(test_suite)
res.add_test_results(test_suite, metric, results[metric])
req = dzclient.DatazillaRequest(
protocol=self.required.get('protocol'),
Expand Down Expand Up @@ -211,7 +220,6 @@ def test_scrollfps(self):
gaiatest.LockScreen(self.marionette).unlock() # unlock
apps.kill_all() # kill all running apps
self.marionette.execute_script('window.wrappedJSObject.dispatchEvent(new Event("home"));') # return to home screen
self.marionette.import_script(pkg_resources.resource_filename(__name__, 'launchapp.js'))
self.marionette.import_script(pkg_resources.resource_filename(__name__, 'scrollapp.js'))
for app_name in self.app_names:
try:
Expand All @@ -231,23 +239,22 @@ def test_scrollfps(self):
sample_hz = 100
self.marionette.set_script_timeout(period + 1000)
# Launch the app
if app_name != 'Homescreen':
result = self.marionette.execute_async_script('launch_app("%s")' % app_name)
if not result:
raise Exception('Error launching app')
app = apps.launch(app_name, switch_to_frame=False)

# Turn on FPS
result = self.marionette.execute_async_script('window.wrappedJSObject.fps = new fps_meter("%s", %d, %d); window.wrappedJSObject.fps.start_fps();' % (app_name, period, sample_hz))
if not result:
raise Exception('Error turning on fps measurement')

# Do scroll
self.marionette.switch_to_frame(app.frame)
self.scroll_app(app_name)
self.marionette.switch_to_frame()

fps = self.marionette.execute_async_script('window.wrappedJSObject.fps.stop_fps()', new_sandbox=False)
if fps:
print 'FPS: %f' % (fps.get('fps'))

if fps:
gaiatest.GaiaApps(self.marionette).kill(gaiatest.GaiaApp(origin=fps.get('origin'))) # kill application
success_counter += 1
Expand All @@ -257,11 +264,14 @@ def test_scrollfps(self):
if fail_counter > fail_threshold:
raise Exception('Exceeded failure threshold for gathering results!')

finally:
self.marionette.set_context(self.marionette.CONTEXT_CHROME)
self.marionette.execute_script('Services.prefs.setBoolPref("layers.acceleration.draw-fps", false);')
self.marionette.set_context(self.marionette.CONTEXT_CONTENT)

# TODO: This is where you submit to datazilla
print "This is the FPS object: %s" % fps
self.marionette.set_context(self.marionette.CONTEXT_CHROME)
self.marionette.execute_script('Services.prefs.setBoolPref("layers.acceleration.draw-fps", false);')
self.marionette.set_context(self.marionette.CONTEXT_CONTENT)

except Exception, e:
print e
caught_exception = True
Expand All @@ -270,11 +280,12 @@ def test_scrollfps(self):

def scroll_app(self, app_name):
print "Here is where I scroll the app"
touch_duration=float(200)

touch_duration = float(200)
self.marionette.__class__ = type('Marionette', (Marionette, MarionetteTouchMixin), {})

self.marionette.setup_touch()

if app_name == 'Homescreen':
self.marionette.flick(self.marionette.find_element('id', 'landing-page'), '90%', '50%', '10%', '50%', touch_duration)
time.sleep(touch_duration / 1000)
Expand All @@ -283,6 +294,7 @@ def scroll_app(self, app_name):
print "SCROLL ME NOW"
time.sleep(25)


class dzOptionParser(OptionParser):
def __init__(self, **kwargs):
OptionParser.__init__(self, **kwargs)
Expand Down Expand Up @@ -312,8 +324,17 @@ def __init__(self, **kwargs):
dest='datazilla_secret',
metavar='str',
help='oauth secret for datazilla server')
self.add_option('--sources',
action='store',
dest='sources',
metavar='str',
help='path to sources.xml containing project revisions')

def datazilla_config(self, options):
if options.sources:
if not os.path.exists(options.sources):
raise Exception('--sources file does not exist')

datazilla_url = urlparse(options.datazilla_url)
datazilla_config = {
'protocol': datazilla_url.scheme,
Expand Down Expand Up @@ -394,7 +415,9 @@ def cli():

marionette = Marionette(host='localhost', port=2828) # TODO command line option for address
marionette.start_session()
b2gperf = B2GPerfRunner(marionette, datazilla_config=datazilla_config)
b2gperf = B2GPerfRunner(marionette,
datazilla_config=datazilla_config,
sources=options.sources)
b2gperf.measure_app_perf(
app_names=args,
delay=options.delay,
Expand Down
4 changes: 3 additions & 1 deletion b2gperf/mozperf.py
Expand Up @@ -45,5 +45,7 @@ def process_results(self, filename):

marionette = Marionette(host='localhost', port=2828)
marionette.start_session()
handler = MozPerfHandler(marionette, datazilla_config=datazilla_config)
handler = MozPerfHandler(marionette,
datazilla_config=datazilla_config,
sources=options.sources)
handler.process_results(args[0])
28 changes: 5 additions & 23 deletions b2gperf/scrollapp.js
Expand Up @@ -24,47 +24,37 @@ fps_meter.prototype = {
if (app) {
self._app_origin = GaiaApps.getRunningAppOrigin(name);
console.log("DBG: got app origin: " + self._app_origin + "\n");

let utils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).getInterface(Components.interfaces.nsIDOMWindowUtils);
let cf = {}, cfps = {}, tf = {}, tfps = {};
let showFPS = function showFPS() {
try {
//utils.getFPSInfo(cf, cfps, tf, tfps);
//self._data.push([performance.now(), cf.value, cfps.value, tf.value, tfps.value]);
console.log("DBG: showFPS called");

self._data.push(performance.now());
self._animation_handle = window.mozRequestAnimationFrame(showFPS);
} catch (e) {
console.log("DBG: Threw inside startfps: " + e + "\n");
//clearInterval(self._interval);
window.mozCancelAnimationFrame(self._animation_handle);

marionetteScriptFinished(false);
}
};
// Now we start measuring fps
console.log("DBG::Starting the interval for showfps\n");
window.mozRequestAnimationFrame(showFPS);
//self._startstamp = performance.now();
//self._interval = setInterval(showFPS, 1000 / self.sample_hz);
//self._interval = setInterval(animate, 1000 / self.sample_hz);
marionetteScriptFinished(true);
}
});
},

stop_fps: function() {
console.log("DBG: stop_fps called\n");

//window.clearInterval(this._interval);
window.mozCancelAnimationFrame(this._animation_handle);
// Calculate FPS over the entire period, but also provide the
// entire list of instantaneous FPS estimates.
/*let cp_fps_all = [x[2] for each (x in this._data)];
let txn_fps_all = [x[4] for each (x in this._data)];
let last = this._data.pop();
let time_elapsed = last[0] - this._data[0][0];
let total_cp_frames = last[1] - this._data[0][1];
let total_txn_frames = last[3] - this._data[0][3];
let cp_fps = (total_cp_frames - 1) / (time_elapsed / 1000);
let txn_fps = (total_txn_frames - 1) / (time_elapsed / 1000);*/

let time_elapsed = this._data[this._data.length -1] - this._data[0];
let num_frames = this._data.length;
Expand All @@ -73,19 +63,11 @@ fps_meter.prototype = {
console.log("DBG: Total time elapsed was " + time_elapsed);
console.log("DBG: num_frames: " + num_frames);
console.log("DBG: fps: " + framepersec);
//console.log("DBG: num cp frames: " + total_cp_frames);
//console.log("DBG: cp_fps: " + cp_fps);
//console.log("DBG: origin: " + this._app_origin);

marionetteScriptFinished({origin: this._app_origin,
time_elapsed: time_elapsed,
number_frames: num_frames,
fps: framepersec});
//composition_fps: cp_fps,
//transaction_fps: txn_fps,
//composition_frames: total_cp_frames,
//transaction_frames: total_txn_frames,
//composition_fps_all: cp_fps_all,
//transaction_fps_all: txn_fps_all});
}
};

2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -5,7 +5,7 @@
import os
from setuptools import setup, find_packages

version = '0.2'
version = '0.2.1'

# get documentation from the README
try:
Expand Down

0 comments on commit 10cffed

Please sign in to comment.