This file is indexed.

/usr/lib/pwrkap/power_energy_meter.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
147
#!/usr/bin/python

"""Fake energy meter that calculates energy use by integrating power use."""
# (C) Copyright IBM Corp. 2008-2009
# Licensed under the GPLv2.
import pwrkap_data
import thread
import datetime
import time
import traceback

class power_energy_meter(pwrkap_data.energy_meter):
	"""Fake energy meter that uses power meter to estimate energy use."""
	def __init__(self, pmeter, threaded):
		self.power_meter = pmeter
		self.energy_use = None
		self.last_update = None
		self.keep_running = True
		self.threaded = threaded

		# This must run last
		if self.threaded:
			thread.start_new_thread(self.run, ())

	def __del__(self):
		self.keep_running = False

	def __setstate__(self, data):
		self.__dict__ = data
		self.last_update = None
		if self.threaded:
			thread.start_new_thread(self.run, ())

	def run(self):
		"""Periodically update energy use."""
		self.keep_running = True
		while self.keep_running:
			try:
				self.update_energy_use()
			except Exception, e:
				print e
				traceback.print_exc()
			time.sleep(1)

	def update_energy_use(self):
		"""Update the energy use counter."""
		now = datetime.datetime.utcnow()

		if self.last_update == None:
			self.energy_use = 0
			self.last_update = now
			return

		td = now - self.last_update
		time_delta =  td.microseconds + \
			     (td.seconds * 1000000) + \
			     (td.days * 86400000000)
		if time_delta == 0:
			time_delta = 1
		time_delta = float(time_delta) / 1000000

		rate = self.power_meter.read()
		self.energy_use = self.energy_use + (rate * time_delta)
		self.last_update = now

	def read(self):
		if not self.threaded:
			self.update_energy_use()
			time.sleep(2)
			self.update_energy_use()
		return self.energy_use

	def get_latency(self):
		return 0;

	def inventory(self):
		return ("power_energy_meter", {})

class energy_power_meter(pwrkap_data.power_meter):
	"""Fake power meter that uses energy meter to estimate energy use."""
	def __init__(self, emeter, threaded):
		self.energy_meter = emeter
		self.last_energy_use = None
		self.last_update = None
		self.power_use = None
		self.keep_running = True
		self.threaded = threaded

		# This must run last
		if self.threaded:
			thread.start_new_thread(self.run, ())

	def __del__(self):
		self.keep_running = False

	def __setstate__(self, data):
		self.__dict__ = data
		self.last_update = None
		if self.threaded:
			thread.start_new_thread(self.run, ())

	def run(self):
		"""Periodically update energy use."""
		self.keep_running = True
		while self.keep_running:
			try:
				self.update_energy_use()
			except Exception, e:
				print e
				traceback.print_exc()
			time.sleep(1)

	def update_power_use(self):
		"""Update the power use counter."""
		now = datetime.datetime.utcnow()

		if self.last_update == None:
			self.last_energy_use = self.energy_meter.read()
			self.power_use = 0
			self.last_update = now
			return

		td = now - self.last_update
		time_delta =  td.microseconds + \
			     (td.seconds * 1000000) + \
			     (td.days * 86400000000)
		if time_delta == 0:
			time_delta = 1
		time_delta = float(time_delta) / 1000000

		energy_now = self.energy_meter.read()
		self.power_use = float(energy_now - self.last_energy_use) / time_delta
		self.last_energy_use = energy_now
		self.last_update = now

	def read(self):
		if not self.threaded:
			self.update_power_use()
			time.sleep(2)
			self.update_power_use()
		return self.power_use

	def get_latency(self):
		return 0;

	def inventory(self):
		return ("energy_power_meter", {})