def RunActualGpuTest(self, test_path, *args): ipg_path = ipg_utils.LocateIPG() if not ipg_path: self.fail("Fail to locate Intel Power Gadget") repeat = args[0] outliers = args[1] fullscreen = args[2] ipg_logdir = args[3] ipg_duration = args[4] ipg_delay = args[5] ipg_resolution = args[6] print "" print "Total iterations: ", repeat logfiles = [] for iteration in range(repeat): run_label = "Iteration_%d" % iteration print run_label if test_path: self.tab.action_runner.Navigate(test_path, fullscreen_script) self.tab.WaitForDocumentReadyStateToBeComplete() self.tab.action_runner.ExecuteJavaScript('setupVideoElement()') self.tab.action_runner.WaitForJavaScriptCondition( 'isVideoPlaying()', timeout=10) if fullscreen: # TODO(zmo): Switch to use click instead of tap once Telemetry's click # is implemented through DevTools. self.tab.action_runner.TapElement( element_function=('locateButton("%s")' % test_path)) logfile = None if ipg_logdir: if not os.path.isdir(ipg_logdir): self.fail("Folder " + ipg_logdir + " doesn't exist") logfile = ipg_utils.GenerateIPGLogFilename(log_dir=ipg_logdir, timestamp=True) ipg_utils.RunIPG(ipg_duration + ipg_delay, ipg_resolution, logfile) logfiles.append(logfile) if repeat > 1 and iteration < repeat - 1: self.StopBrowser() self.StartBrowser() if repeat == 1: results = ipg_utils.AnalyzeIPGLogFile(logfiles[0], ipg_delay) print "Results: ", results else: json_path = None if ipg_logdir: json_path = os.path.join(ipg_logdir, "output.json") print "Results saved in ", json_path summary = ipg_utils.ProcessResultsFromMultipleIPGRuns( logfiles, ipg_delay, outliers, json_path) print 'Summary: ', summary
def _RunTest_URL(self, test_path, params): repeat = params['repeat'] outliers = params['outliers'] fullscreen = params['fullscreen'] underlay = params['underlay'] ipg_logdir = params['logdir'] ipg_duration = params['duration'] ipg_delay = params['delay'] ipg_resolution = params['resolution'] bypass_ipg = params['bypass_ipg'] if repeat > 1: logging.info("Total iterations: %d", repeat) logfiles = [] for iteration in range(repeat): if repeat > 1: logging.info("Iteration %d", iteration) self.tab.action_runner.Navigate(test_path, _VIDEO_TEST_SCRIPT) self.tab.WaitForDocumentReadyStateToBeComplete() self._SetupVideo(fullscreen=fullscreen, underlay=underlay) if bypass_ipg: logging.info("Bypassing Intel Power Gadget") time.sleep(ipg_duration + ipg_delay) else: logfile = None if ipg_logdir: if not os.path.isdir(ipg_logdir): self.fail("Folder " + ipg_logdir + " doesn't exist") logfile = ipg_utils.GenerateIPGLogFilename( log_dir=ipg_logdir, timestamp=True) ipg_utils.RunIPG(ipg_duration + ipg_delay, ipg_resolution, logfile) logfiles.append(logfile) if repeat > 1 and iteration < repeat - 1: self.StopBrowser() self.StartBrowser() if bypass_ipg: return if repeat == 1: results = ipg_utils.AnalyzeIPGLogFile(logfiles[0], ipg_delay) logging.info("Results: %s", str(results)) else: json_path = None if ipg_logdir: json_path = os.path.join(ipg_logdir, "output.json") print "Results saved in ", json_path summary = ipg_utils.ProcessResultsFromMultipleIPGRuns( logfiles, ipg_delay, outliers, json_path) logging.info("Summary: %s", str(summary))
def RunActualGpuTest(self, test_path, *args): ipg_path = ipg_utils.LocateIPG() if not ipg_path: self.fail("Fail to locate Intel Power Gadget") repeat = args[0] outliers = args[1] fullscreen = args[2] ipg_logdir = args[3] ipg_duration = args[4] ipg_delay = args[5] ipg_resolution = args[6] print "" print "Total iterations: ", repeat logfiles = [] for iteration in range(repeat): run_label = "Iteration_%d" % iteration print run_label if test_path: self.tab.action_runner.Navigate(test_path) if fullscreen: # TODO(zmo): implement fullscreen mode. pass logfile = None if ipg_logdir: if not os.path.isdir(ipg_logdir): self.fail("Folder " + ipg_logdir + " doesn't exist") logfile = ipg_utils.GenerateIPGLogFilename(log_dir=ipg_logdir, timestamp=True) ipg_utils.RunIPG(ipg_duration + ipg_delay, ipg_resolution, logfile) logfiles.append(logfile) if repeat > 1 and iteration < repeat - 1: self.StopBrowser() self.StartBrowser() if repeat == 1: results = ipg_utils.AnalyzeIPGLogFile(logfiles[0], ipg_delay) print "Results: ", results else: json_path = None if ipg_logdir: json_path = os.path.join(ipg_logdir, "output.json") print "Results saved in ", json_path summary = ipg_utils.ProcessResultsFromMultipleIPGRuns( logfiles, ipg_delay, outliers, json_path) print 'Summary: ', summary
def main(argv): parser = optparse.OptionParser() parser.add_option("--browser", help=("select which browser to run. Options include: " + ", ".join(SUPPORTED_BROWSERS) + ", or a full path to a browser executable. " + "By default, stable is selected.")) parser.add_option("--duration", default=60, type="int", help="specify how many seconds Intel Power Gadget " "measures. By default, 60 seconds is selected.") parser.add_option("--delay", default=10, type="int", help="specify how many seconds we skip in the data " "Intel Power Gadget collects. This time is for starting " "video play, switching to fullscreen mode, etc. " "By default, 10 seconds is selected.") parser.add_option("--resolution", default=100, type="int", help="specify how often Intel Power Gadget samples " "data in milliseconds. By default, 100 ms is selected.") parser.add_option("--logdir", help="specify where Intel Power Gadget stores its log." "By default, it is the current path.") parser.add_option("--logname", help="specify the prefix for Intel Power Gadget log " "filename. By default, it is PowerLog.") parser.add_option("-v", "--verbose", action="store_true", default=False, help="print out debug information.") parser.add_option("--repeat", default=1, type="int", help="specify how many times to run the measurements.") parser.add_option( "--url", help="specify the webpage URL the browser launches with.") parser.add_option( "--extra-browser-args", dest="extra_browser_args", help="specify extra command line switches for the browser " "that are separated by spaces (quoted).") parser.add_option( "--extra-browser-args-filename", dest="extra_browser_args_filename", metavar="FILE", help="specify extra command line switches for the browser " "in a text file that are separated by whitespace.") parser.add_option("--fullscreen", action="store_true", default=False, help="specify whether video should be made fullscreen.") (options, _) = parser.parse_args(args=argv) if options.verbose: logging.basicConfig(level=logging.DEBUG) browser = LocateBrowser(options.browser) if not browser: return # TODO(zmo): Add code to disable a bunch of Windows services that might # affect power consumption. log_prefix = options.logname or 'PowerLog' all_results = [] extra_browser_args = [] if options.extra_browser_args: extra_browser_args = options.extra_browser_args.split() if options.extra_browser_args_filename: if not os.path.isfile(options.extra_browser_args_filename): logging.error("Can't locate file at %s", options.extra_browser_args_filename) else: with open(options.extra_browser_args_filename, 'r') as f: extra_browser_args.extend(f.read().split()) f.close() for run in range(1, options.repeat + 1): logfile = ipg_utils.GenerateIPGLogFilename(log_prefix, options.logdir, run, options.repeat, True) print("Iteration #%d out of %d" % (run, options.repeat)) results = MeasurePowerOnce(browser, logfile, options.duration, options.delay, options.resolution, options.url, options.fullscreen, extra_browser_args) print(results) all_results.append(results) now = datetime.datetime.now() results_filename = '%s_%s_results.csv' % (log_prefix, now.strftime('%Y%m%d%H%M%S')) try: with open(results_filename, 'wb') as results_csv: labels = sorted(all_results[0].keys()) w = csv.DictWriter(results_csv, fieldnames=labels) w.writeheader() w.writerows(all_results) except Exception as err: logging.warning('Failed to write results file ' + results_filename) logging.debug(err)
def _RunTest_URL(self, test_path, params): repeat = params['repeat'] outliers = params['outliers'] fullscreen = params['fullscreen'] underlay = params['underlay'] ipg_logdir = params['logdir'] ipg_duration = params['duration'] ipg_delay = params['delay'] ipg_resolution = params['resolution'] print "" print "Total iterations: ", repeat logfiles = [] for iteration in range(repeat): run_label = "Iteration_%d" % iteration print run_label if test_path: self.tab.action_runner.Navigate(test_path, _FULLSCREEN_SCRIPT) self.tab.WaitForDocumentReadyStateToBeComplete() code = "setupVideoElement(%s)" % ("true" if underlay else "false") if not self.tab.action_runner.EvaluateJavaScript(code): # autoplay doesn't work for vimeo. # action_runner.PlayMedia doesn't work for vimeo. self.tab.action_runner.ClickElement( element_function=('locateElement("video")')) if fullscreen: if self.tab.action_runner.EvaluateJavaScript( 'locateFullscreenButton() == null'): self.fail( "Fullscreen button not located, --fullscreen won't work" ) self.tab.action_runner.ClickElement( element_function=('locateFullscreenButton()')) logfile = None if ipg_logdir: if not os.path.isdir(ipg_logdir): self.fail("Folder " + ipg_logdir + " doesn't exist") logfile = ipg_utils.GenerateIPGLogFilename(log_dir=ipg_logdir, timestamp=True) ipg_utils.RunIPG(ipg_duration + ipg_delay, ipg_resolution, logfile) logfiles.append(logfile) if repeat > 1 and iteration < repeat - 1: self.StopBrowser() self.StartBrowser() if repeat == 1: results = ipg_utils.AnalyzeIPGLogFile(logfiles[0], ipg_delay) print "Results: ", results else: json_path = None if ipg_logdir: json_path = os.path.join(ipg_logdir, "output.json") print "Results saved in ", json_path summary = ipg_utils.ProcessResultsFromMultipleIPGRuns( logfiles, ipg_delay, outliers, json_path) print 'Summary: ', summary
def main(argv): parser = optparse.OptionParser() parser.add_option("--browser", help=("select which browser to run. Options include: " + ", ".join(SUPPORTED_BROWSERS) + ", or a full path to a browser executable. " + "By default, stable is selected.")) parser.add_option("--duration", default=60, type="int", help="specify how many seconds Intel Power Gadget " "measures. By default, 60 seconds is selected.") parser.add_option("--delay", default=10, type="int", help="specify how many seconds we skip in the data " "Intel Power Gadget collects. This time is for starting " "video play, switching to fullscreen mode, etc. " "By default, 10 seconds is selected.") parser.add_option("--resolution", default=100, type="int", help="specify how often Intel Power Gadget samples " "data in milliseconds. By default, 100 ms is selected.") parser.add_option("--logdir", help="specify where Intel Power Gadget stores its log." "By default, it is the current path.") parser.add_option("--logname", help="specify the prefix for Intel Power Gadget log " "filename. By default, it is PowerLog.") parser.add_option("-v", "--verbose", action="store_true", default=False, help="print out debug information.") parser.add_option("--repeat", default=1, type="int", help="specify how many times to run the measurements.") parser.add_option( "--url", help="specify the webpage URL the browser launches with.") parser.add_option( "--extra-browser-args", dest="extra_browser_args", help="specify extra commandline switches for the browser " "that are separated by ' '.") # TODO(zmo): add an option --start-fullscreen (options, _) = parser.parse_args(args=argv) if options.verbose: logging.basicConfig(level=logging.DEBUG) browser = LocateBrowser(options.browser) if not browser: return # TODO(zmo): Add code to disable a bunch of Windows services that might # affect power consumption. log_prefix = options.logname or 'PowerLog' for run in range(0, options.repeat): logfile = ipg_utils.GenerateIPGLogFilename(log_prefix, options.logdir, run, options.repeat, True) logging.info("Iteration #%d out of %d", run, options.repeat) results = MeasurePowerOnce(browser, logfile, options.duration, options.delay, options.resolution, options.url, options.extra_browser_args) logging.info(results)
def RunActualGpuTest(self, test_path, *args): ipg_path = ipg_utils.LocateIPG() if not ipg_path: self.fail("Fail to locate Intel Power Gadget") repeat = args[0] outliers = args[1] fullscreen = args[2] underlay = args[3] ipg_logdir = args[4] ipg_duration = args[5] ipg_delay = args[6] ipg_resolution = args[7] print "" print "Total iterations: ", repeat logfiles = [] for iteration in range(repeat): run_label = "Iteration_%d" % iteration print run_label if test_path: self.tab.action_runner.Navigate(test_path, fullscreen_script) self.tab.WaitForDocumentReadyStateToBeComplete() code = "setupVideoElement(%s)" % ("true" if underlay else "false") if not self.tab.action_runner.EvaluateJavaScript(code): # autoplay doesn't work for vimeo. # action_runner.PlayMedia doesn't work for vimeo. self.tab.action_runner.TapElement( element_function=('locateElement("video")')) self.tab.action_runner.WaitForJavaScriptCondition( 'isVideoPlaying()', timeout=10) if fullscreen: if self.tab.action_runner.EvaluateJavaScript( 'locateFullscreenButton() == null'): self.fail( "Fullscreen button not located, --fullscreen won't work" ) self.tab.action_runner.TapElement( element_function=('locateFullscreenButton()')) logfile = None if ipg_logdir: if not os.path.isdir(ipg_logdir): self.fail("Folder " + ipg_logdir + " doesn't exist") logfile = ipg_utils.GenerateIPGLogFilename(log_dir=ipg_logdir, timestamp=True) ipg_utils.RunIPG(ipg_duration + ipg_delay, ipg_resolution, logfile) logfiles.append(logfile) if repeat > 1 and iteration < repeat - 1: self.StopBrowser() self.StartBrowser() if repeat == 1: results = ipg_utils.AnalyzeIPGLogFile(logfiles[0], ipg_delay) print "Results: ", results else: json_path = None if ipg_logdir: json_path = os.path.join(ipg_logdir, "output.json") print "Results saved in ", json_path summary = ipg_utils.ProcessResultsFromMultipleIPGRuns( logfiles, ipg_delay, outliers, json_path) print 'Summary: ', summary