Permalink
Browse files

Bug 789597 - Turn on frame numbering when profiling enabled

This also involves ignoring the area covered by the frame counter when doing
analysis, which I think is done ok here.
  • Loading branch information...
wlach committed Sep 7, 2012
1 parent 465b46c commit a317331be929234ac58e3346dfada412785239a0
View
@@ -205,6 +205,12 @@ def main(args=sys.argv[1:]):
'device': device.model,
'startupTest': options.startup_test
}
+
+ # something of a hack. if profiling is enabled, carve off an area to
+ # ignore in the capture
+ if options.profile_file:
+ capture_metadata['ignoreAreas'] = [ [ 0, 0, 3*64, 3 ] ]
+
capture_server = CaptureServer(capture_metadata,
capture_file,
options.checkerboard_log_file,
@@ -206,16 +206,21 @@ def start(self, profile_file=None):
# for fennec only, we create and use a profile
if self.appname.startswith('org.mozilla'):
args = []
- profile = None
- profile = mozprofile.Profile(preferences = { 'gfx.show_checkerboard_pattern': False,
- 'browser.firstrun.show.uidiscovery': False,
- 'toolkit.telemetry.prompted': 2 })
+ self.is_profiling = profile_file != None
+ preferences = { 'gfx.show_checkerboard_pattern': False,
+ 'browser.firstrun.show.uidiscovery': False,
+ 'toolkit.telemetry.prompted': 2 }
+
+ # Add frame counter to correlate video capture with profile
+ if self.is_profiling:
+ preferences['layers.acceleration.frame-counter'] = True
+
+ profile = mozprofile.Profile(preferences = preferences)
self.remote_profile_dir = "/".join([self.dm.getDeviceRoot(),
os.path.basename(profile.profile)])
if not self.dm.pushDir(profile.profile, self.remote_profile_dir):
raise Exception("Failed to copy profile to device")
- self.is_profiling = profile_file != None
if self.is_profiling:
self.profile_file = profile_file
mozEnv = { "MOZ_PROFILER_STARTUP": "true" }
@@ -12,17 +12,34 @@
PIXEL_DIFF_THRESHOLD = 5.0
def get_framediff_image(capture, framenum1, framenum2, cropped=False):
+ if capture.metadata.get('ignoreAreas'):
+ ignored_areas = capture.metadata['ignoreAreas']
+ else:
+ ignored_areas = []
+
frame1 = capture.get_frame(framenum1, cropped)
frame2 = capture.get_frame(framenum2, cropped)
framediff = numpy.abs(frame1.astype('float') - frame2.astype('float'))
thresh = 5.0
- for row in framediff:
- for px in row:
- if px[0] >= PIXEL_DIFF_THRESHOLD or px[1] >= PIXEL_DIFF_THRESHOLD \
- or px[2] >= PIXEL_DIFF_THRESHOLD:
+ for (y, row) in enumerate(framediff):
+ for (x, px) in enumerate(row):
+ skip = False
+ for ignored_area in ignored_areas:
+ if y >= ignored_area[1] and y < ignored_area[3] and \
+ x >= ignored_area[0] and x < ignored_area[2]:
+ print ignored_area
+ print "Skipped: %s %s" % (x, y)
+ skip = True
+ break
+
+ if not skip and (px[0] >= PIXEL_DIFF_THRESHOLD or \
+ px[1] >= PIXEL_DIFF_THRESHOLD or \
+ px[2] >= PIXEL_DIFF_THRESHOLD):
px[0] = 255.0
px[1] = 0.0
px[2] = 0.0
+ else:
+ px[0] = px[1] = px[2] = 0.0
return Image.fromarray(framediff.astype(numpy.uint8))
@@ -32,6 +49,11 @@ def get_framediff_sums(capture):
except:
cache = {}
+ if capture.metadata.get('ignoreAreas'):
+ ignored_areas = capture.metadata['ignoreAreas']
+ else:
+ ignored_areas = []
+
try:
diffsums = cache['diffsums']
except:
@@ -43,6 +65,10 @@ def get_framediff_sums(capture):
frame = capture.get_frame(i, True).astype('float')
if prevframe != None:
framediff = (frame - prevframe)
+ for ignored_area in ignored_areas:
+ for x in range(ignored_area[0], ignored_area[2]):
+ for y in range(ignored_area[1], ignored_area[3]):
+ framediff[x][y] = 0.0
framediff = framediff[framediff >= PIXEL_DIFF_THRESHOLD]
diffsums.append(len(framediff))
prevframe = frame
@@ -4,6 +4,11 @@
import numpy
+# how far outside the bounds of the square a scanline can be and still be
+# considered part of the frame
+X_TOLERANCE_MIN = 192 + 1 # ignore frame counter on left for fennec
+X_TOLERANCE_MAX = 1
+
def get_squares(rgb, imgarray):
''' Get contiguous square regions within a certain threshold of an RGB
color inside an image '''
@@ -26,9 +31,16 @@ def get_squares(rgb, imgarray):
if scanline:
found_existing = False
for square in squares:
- if abs(square[0] - scanline[0]) < 1 and abs(square[2] - scanline[1]) < 1:
+ if abs(square[0] - scanline[0]) < X_TOLERANCE_MIN and \
+ abs(square[2] - scanline[1]) < X_TOLERANCE_MAX:
square[3] = y
found_existing = True
+ # expand the square if the scanline is bigger
+ if square[0] > scanline[0]:
+ square[0] = scanline[0]
+ if square[2] < scanline[1]:
+ square[2] = scanline[1]
+
if not found_existing:
squares.append([int(scanline[0]), y, int(scanline[1]), y])

0 comments on commit a317331

Please sign in to comment.