Skip to content

Commit

Permalink
servo: Merge #4300 - Update PowerMeasure.py post-cargoify (from servo…
Browse files Browse the repository at this point in the history
…:fix-power); r=Manishearth

Source-Repo: https://github.com/servo/servo
Source-Revision: 25a251e6abf50fe818b9836505b09be8191a86fa
  • Loading branch information
metajack committed Dec 12, 2014
1 parent db5adf6 commit 20992ec
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 38 deletions.
1 change: 1 addition & 0 deletions servo/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*.pyc
*.swp
*.swo
*.csv
.DS_Store
servo-test
Servo.app
Expand Down
85 changes: 47 additions & 38 deletions servo/tests/power/PowerMeasure.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,49 +1,56 @@
#!/usr/bin/env python

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

# !/usr/bin/env python

# ---------Power measurement ------------------------------#
# This script will run the servo with the given benchmark and
# get the power usage using Powermetrics. Results will be put
# in sperate files with that name.
# Do not forget to run the script in servo/src/test/power folder
# Do not forget to run the script in servo/tests/power folder
# --------------------------------------------------------#

from __future__ import print_function, unicode_literals

import os
from os import path
import time
import argparse

# ------------------------PowerCollector----------------------------#
# Collecting all the power data and put them into files


TOP_DIR = path.join("..", "..")


def PowerCollector(OutputDir, Benchmarks, LayoutThreads, Renderer):
print " Running the power collector"
os.mkdir(os.path.join(OutputDir+"power"), 0777)
os.mkdir(os.path.join(OutputDir+"time"), 0777)
os.mkdir(os.path.join(OutputDir+"Addtional"), 0777)
print("Running the power collector")
power_dir = path.join(OutputDir, "power")
time_dir = path.join(OutputDir, "time")
etc_dir = path.join(OutputDir, "etc")
for d in [power_dir, time_dir, etc_dir]:
os.mkdir(d)
SleepTime = 20
GuardTime = 0.5
powerTiming = 1
ExperimentNum = 21
for ExpNum in range(1, ExperimentNum):
for layoutT in range(1, LayoutThreads+1):
PowerFiles = OutputDir + 'power/' + 'power-Layout' + \
str(layoutT) + "-set" + str(ExpNum) + ".csv"
TimeFiles = OutputDir + 'time/' + "time-Layout" + \
str(layoutT) + "-set" + str(ExpNum) + ".csv"
# ServoCmd ="(time ./servo -x -y " + str(layoutT) \
# +" "+ Renderer + " " + Benchmarks + " ) 2> " + TimeFiles
ServoCmd = "(time ../../../build/servo -x -y " + \
str(layoutT) + " " + Renderer + " " + \
Benchmarks + " ) 2> " + TimeFiles
Metrics = OutputDir + 'Addtional/' + "metrics-Layout" + \
str(layoutT) + "-set" + str(ExpNum) + "-css.csv"
cmd = '(sudo powermetrics -i ' + str(powerTiming) + \
' | grep \"energy\\|elapsed\\|servo\" > ' + \
PowerFiles + '& ) 2> ' + Metrics
print(" layoutT=%d ExpNum=%d" % (layoutT, ExpNum))
PowerFiles = path.join(
power_dir, "power-Layout%d-set%d.csv" % (layoutT, ExpNum))
TimeFiles = path.join(
time_dir, "time-Layout%d-set%d.csv" % (layoutT, ExpNum))
ServoCmd = "(time ../../components/servo/target/release/servo -x -y %d %s %s) 2> %s" % \
(layoutT, Renderer, Benchmarks, TimeFiles)
Metrics = path.join(
etc_dir, "metrics-Layout%d-set%d-css.csv" % (layoutT, ExpNum))
cmd = "(sudo powermetrics -i %d | " \
"grep \"energy\\|elapsed\\|servo\" > %s &_) 2> %s" % \
(powerTiming, PowerFiles, Metrics)
time.sleep(SleepTime)
os.system(cmd)
time.sleep(GuardTime)
Expand All @@ -57,7 +64,7 @@ def PowerCollector(OutputDir, Benchmarks, LayoutThreads, Renderer):


def PowerParser(OutputDir, LayoutThreads):
print "Running the PowerParser"
print("Running the PowerParser")
ExperimentNum = 21
ResultTable = OutputDir + "ResultTable.csv"
ResultFile = open(ResultTable, "w")
Expand All @@ -74,14 +81,16 @@ def PowerParser(OutputDir, LayoutThreads):
TimeGen = 0
PowerGen = 0
for ExpNum in range(1, ExperimentNum):
Files = OutputDir + 'power/' + 'power-Layout' + str(layoutT) + \
"-set" + str(ExpNum) + ".csv"
NewFile = OutputDir + 'power/Servo-L' + str(layoutT) + \
"set" + str(ExpNum) + ".csv"
print(" layoutT=%d ExpNum=%d" % (layoutT, ExpNum))
Files = path.join(
OutputDir, "power", "power-Layout%d-set%d.csv" %
(layoutT, ExpNum))
NewFile = path.join(OutputDir, "power", "Servo-Layout%d-set%d.csv" %
(layoutT, ExpNum))
File = open(Files, 'r')
PowerFile = open(NewFile, 'w')
TimeFiles = OutputDir + 'time/' + "time-Layout" + \
str(layoutT) + "-set" + str(ExpNum) + ".csv"
TimeFiles = path.join(OutputDir, "time", "time-Layout%d-set%d.csv" %
(layoutT, ExpNum))
# ----Putting the power the power and its time into a table---- #

for line in File:
Expand Down Expand Up @@ -132,30 +141,30 @@ def PowerParser(OutputDir, LayoutThreads):
ResultFile.close()
Opener = ResultFile = open(ResultTable, "r")
for line in Opener:
print line
print(line)

print "Also you can find all the numbers for Power " \
"and Performance in : ", ResultTable
print("Also you can find all the numbers for Power "
"and Performance in : ", ResultTable)


# ----------------------------------------------------#
def main():
LayoutThreads = 8 # Maximum number of threads considered for Layout
Benchmarks = "../../tests/html/perf-rainbow.html"
OutputDir = "Experiments/"
os.mkdir(os.path.join(OutputDir), 0777)
Renderer = " "
Benchmarks = path.join(TOP_DIR, "tests", "html", "perf-rainbow.html")
OutputDir = "Experiments"
os.mkdir(OutputDir)
Renderer = ""

# Parsing the input of the script
parser = argparse.ArgumentParser(description="Mesuring \
power and performance of your servo runs")
parser = argparse.ArgumentParser(description="Measuring \
power and performance of your Servo runs")
parser.add_argument("-b", "--benchmark", help="Gets the \
benchmark, for example \"-B perf-rainbow.html\"")
parser.add_argument("-c", "--CPU", help="Rendering with \
CPU instead of GPU, for example -C")
parser.add_argument("-l", "--LayoutThreads", help="Specifyes \
parser.add_argument("-l", "--LayoutThreads", help="Specify \
the maximum number of threads for layout, for example \" -L 5\"")
parser.add_argument("-o", "--Output", help=" Specifyes \
parser.add_argument("-o", "--Output", help="Specify \
the output directory")

args = parser.parse_args()
Expand Down

0 comments on commit 20992ec

Please sign in to comment.