/usr/lib/pwrkap/pwrkap_test.py is in pwrkap 7.30-5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | #!/usr/bin/python
"""pwrkap test routines."""
# (C) Copyright IBM Corp. 2008-2009
# Licensed under the GPLv2.
import discovery
import time
import pwrkap_pickle
import sys
import pwrkap_train
def discover_world():
"""Discovery and assemble power domains."""
print "Probing hardware..."
discovery.load_pwrkap_drivers()
discovery.discover_devices()
discovery.discover_meters()
discovery.discover_power_domains()
discover_world()
print ("devices", discovery.PWRKAP_DEVICES)
print ("pmeters", discovery.PWRKAP_POWER_METERS)
print ("emeters", discovery.PWRKAP_ENERGY_METERS)
print ("devdomains", discovery.PWRKAP_DEVICE_DOMAINS)
print ("pwrdomains", discovery.PWRKAP_POWER_DOMAINS)
# Speed things up if we're using fakedomain
def train():
if "fake_cpudomain" in discovery.PWRKAP_DRIVERS:
pwrkap_train.STABILIZE_TIME = 0
pwrkap_train.MAX_MEASUREMENTS = 10
pwrkap_train.train()
def quick_simulate():
if len(discovery.PWRKAP_POWER_DOMAINS) == 0:
return
for pd in discovery.PWRKAP_POWER_DOMAINS:
print pd.inventory()
while True:
for pd in discovery.PWRKAP_POWER_DOMAINS:
print pd.snapshot()
time.sleep(1)
def pickle_test():
for i in range(0, 500):
for dm in discovery.PWRKAP_POWER_DOMAINS:
dm.process_snapshot()
count = 0
for dm in discovery.PWRKAP_POWER_DOMAINS:
count = count + 1
fname = "/tmp/pdom%d" % count
print "Saving to '%s'..." % fname
fp = open(fname, "w")
dm.save_snapshots(fp)
fp.close()
def pickle2():
for i in range(0, 500):
for dm in discovery.PWRKAP_POWER_DOMAINS:
dm.process_snapshot()
pwrkap_pickle.save_domains(discovery.PWRKAP_POWER_DOMAINS)
fubar = pwrkap_pickle.load_domains(discovery.PWRKAP_POWER_DOMAINS)
if fubar == None:
print "Screw up?!"
return False
print "INVENTORY"
for dm in discovery.PWRKAP_POWER_DOMAINS:
print dm.inventory()
print "INVENTORY PICKLED"
for dm in fubar:
print dm.inventory()
print "SNAPSHOT"
for dm in fubar:
print dm.snapshot()
def pickle3():
pwrkap_pickle.save_domains(discovery.PWRKAP_POWER_DOMAINS)
fubar = pwrkap_pickle.load_domains(discovery.PWRKAP_POWER_DOMAINS)
if fubar == None:
print "Screw up?!"
return False
print "INVENTORY"
for dm in discovery.PWRKAP_POWER_DOMAINS:
print dm.inventory()
print "INVENTORY PICKLED"
for dm in fubar:
print dm.inventory()
print "SNAPSHOT"
for dm in fubar:
print dm.snapshot()
def pickle4():
fubar = pwrkap_pickle.load_domains(discovery.PWRKAP_POWER_DOMAINS)
if fubar == None:
print "Screw up?!"
return False
print "INVENTORY"
for dm in discovery.PWRKAP_POWER_DOMAINS:
print dm.inventory()
print "INVENTORY PICKLED"
for dm in fubar:
print dm.inventory()
print "SNAPSHOT"
for dm in fubar:
print dm.snapshot()
def simulate():
for i in range(0, 300):
for dm in discovery.PWRKAP_POWER_DOMAINS:
dm.process_snapshot()
for dm in discovery.PWRKAP_POWER_DOMAINS:
print dm.trans_store.trans_table
x = dm.get_cap()
x = x * 0.75
while x > 10:
y = dm.set_cap(x)
if y < 0:
print "Missed cap %(cap)dW by %(miss)dW usage %(use)dW" \
% {"miss": y, "cap": x, "use": dm.get_power_use()}
x = dm.get_cap()
x = x * 0.75
tests = []
if len(sys.argv) < 2:
tests = ["train", "pickle3"]
else:
tests = sys.argv[1:]
for test in tests:
print "Executing %s()" % test
exec "%s()" % test
|