1
0
mirror of https://github.com/ARM-software/devlib.git synced 2025-07-09 23:32:41 +01:00

Merge pull request from credp/junoenergymeter_instantaneous

JunoEnergyInstrument: Provide INSTANTANEOUS interface
This commit is contained in:
setrofim
2015-12-15 17:52:01 +00:00
3 changed files with 41 additions and 23 deletions
devlib
bin
platform
src/readenergy

Binary file not shown.

@ -20,7 +20,7 @@ import time
import pexpect
from devlib.platform import Platform
from devlib.instrument import Instrument, InstrumentChannel, MeasurementsCsv, CONTINUOUS
from devlib.instrument import Instrument, InstrumentChannel, MeasurementsCsv, Measurement, CONTINUOUS, INSTANTANEOUS
from devlib.exception import TargetError, HostError
from devlib.host import PACKAGE_BIN_DIRECTORY
from devlib.utils.serial_port import open_serial_connection
@ -208,7 +208,7 @@ class TC2(VersatileExpressPlatform):
class JunoEnergyInstrument(Instrument):
binname = 'readenergy'
mode = CONTINUOUS
mode = CONTINUOUS | INSTANTANEOUS
_channels = [
InstrumentChannel('sys_curr', 'sys', 'current'),
@ -238,6 +238,7 @@ class JunoEnergyInstrument(Instrument):
self.channels[chan.name] = chan
self.on_target_file = self.target.tempfile('energy', '.csv')
self.command = '{} -o {}'.format(self.binary, self.on_target_file)
self.command2 = '{}'.format(self.binary)
def setup(self):
self.binary = self.target.install(os.path.join(PACKAGE_BIN_DIRECTORY,
@ -281,4 +282,16 @@ class JunoEnergyInstrument(Instrument):
return MeasurementsCsv(output_file, self.active_channels)
def take_measurement(self):
result = []
output = self.target.execute(self.command2).split()
reader=csv.reader(output)
headings=reader.next()
values = reader.next()
for chan in self.active_channels:
value = values[headings.index(chan.name)]
result.append(Measurement(value, chan))
print result
return result

@ -141,9 +141,10 @@ int nsleep(const struct timespec *req, struct timespec *rem)
void print_help()
{
fprintf(stderr, "Usage: readenergy [-t PERIOD] -o OUTFILE\n\n"
fprintf(stderr, "Usage: readenergy [-t PERIOD] [-o OUTFILE]\n\n"
"Read Juno energy counters every PERIOD milliseconds, writing them\n"
"to OUTFILE in CSV format until SIGTERM is received.\n\n"
"to OUTFILE in CSV format until SIGTERM is received.\n"
"If OUTFILE is not specified, stdout will be used.\n\n"
"Parameters:\n"
" PERIOD is the counter poll period in milliseconds.\n"
" (Defaults to 100 milliseconds.)\n"
@ -197,13 +198,6 @@ void config_init(struct config *this, int argc, char *argv[])
exit(EXIT_FAILURE);
}
}
if (this->output_file == NULL)
{
fprintf(stderr, "ERROR: Mandatory -o option not specified.\n\n");
print_help();
exit(EXIT_FAILURE);
}
}
// -------------------------------------- /config ---------------------------------------------------
@ -218,6 +212,8 @@ struct emeter
};
void emeter_init(struct emeter *this, char *outfile)
{
if(outfile)
{
this->out = fopen(outfile, "w");
if (this->out == NULL)
@ -225,7 +221,9 @@ void emeter_init(struct emeter *this, char *outfile)
fprintf(stderr, "ERROR: Could not open output file %s; got %s\n", outfile, strerror(errno));
exit(EXIT_FAILURE);
}
} else {
this->out = stdout;
}
this->fd = open("/dev/mem", O_RDONLY);
if(this->fd < 0)
{
@ -243,11 +241,13 @@ void emeter_init(struct emeter *this, char *outfile)
exit(EXIT_FAILURE);
}
if(this->out) {
fprintf(this->out, "sys_curr,a57_curr,a53_curr,gpu_curr,"
"sys_volt,a57_volt,a53_volt,gpu_volt,"
"sys_pow,a57_pow,a53_pow,gpu_pow,"
"sys_cenr,a57_cenr,a53_cenr,gpu_cenr\n");
}
}
void emeter_read_measurements(struct emeter *this, struct reading *reading)
{
@ -333,12 +333,17 @@ int main(int argc, char *argv[])
config_init(&config, argc, argv);
emeter_init(&emeter, config.output_file);
if(config.output_file)
{
struct timespec remaining;
while (!done)
{
emeter_take_reading(&emeter);
nsleep(&config.period, &remaining);
}
} else {
emeter_take_reading(&emeter);
}
emeter_finalize(&emeter);
return EXIT_SUCCESS;