1
0
mirror of https://github.com/ARM-software/devlib.git synced 2025-01-31 02:00:45 +00:00

Merge pull request #9 from credp/junoenergymeter_instantaneous

JunoEnergyInstrument: Provide INSTANTANEOUS interface
This commit is contained in:
setrofim 2015-12-15 17:52:01 +00:00
commit 4c4d7f177e
3 changed files with 41 additions and 23 deletions

Binary file not shown.

View File

@ -20,7 +20,7 @@ import time
import pexpect import pexpect
from devlib.platform import Platform 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.exception import TargetError, HostError
from devlib.host import PACKAGE_BIN_DIRECTORY from devlib.host import PACKAGE_BIN_DIRECTORY
from devlib.utils.serial_port import open_serial_connection from devlib.utils.serial_port import open_serial_connection
@ -208,7 +208,7 @@ class TC2(VersatileExpressPlatform):
class JunoEnergyInstrument(Instrument): class JunoEnergyInstrument(Instrument):
binname = 'readenergy' binname = 'readenergy'
mode = CONTINUOUS mode = CONTINUOUS | INSTANTANEOUS
_channels = [ _channels = [
InstrumentChannel('sys_curr', 'sys', 'current'), InstrumentChannel('sys_curr', 'sys', 'current'),
@ -238,6 +238,7 @@ class JunoEnergyInstrument(Instrument):
self.channels[chan.name] = chan self.channels[chan.name] = chan
self.on_target_file = self.target.tempfile('energy', '.csv') self.on_target_file = self.target.tempfile('energy', '.csv')
self.command = '{} -o {}'.format(self.binary, self.on_target_file) self.command = '{} -o {}'.format(self.binary, self.on_target_file)
self.command2 = '{}'.format(self.binary)
def setup(self): def setup(self):
self.binary = self.target.install(os.path.join(PACKAGE_BIN_DIRECTORY, 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) 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

View File

@ -141,9 +141,10 @@ int nsleep(const struct timespec *req, struct timespec *rem)
void print_help() 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" "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" "Parameters:\n"
" PERIOD is the counter poll period in milliseconds.\n" " PERIOD is the counter poll period in milliseconds.\n"
" (Defaults to 100 milliseconds.)\n" " (Defaults to 100 milliseconds.)\n"
@ -197,13 +198,6 @@ void config_init(struct config *this, int argc, char *argv[])
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
if (this->output_file == NULL)
{
fprintf(stderr, "ERROR: Mandatory -o option not specified.\n\n");
print_help();
exit(EXIT_FAILURE);
}
} }
// -------------------------------------- /config --------------------------------------------------- // -------------------------------------- /config ---------------------------------------------------
@ -219,13 +213,17 @@ struct emeter
void emeter_init(struct emeter *this, char *outfile) void emeter_init(struct emeter *this, char *outfile)
{ {
this->out = fopen(outfile, "w"); if(outfile)
if (this->out == NULL)
{ {
fprintf(stderr, "ERROR: Could not open output file %s; got %s\n", outfile, strerror(errno)); this->out = fopen(outfile, "w");
exit(EXIT_FAILURE); if (this->out == NULL)
{
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); this->fd = open("/dev/mem", O_RDONLY);
if(this->fd < 0) if(this->fd < 0)
{ {
@ -243,10 +241,12 @@ void emeter_init(struct emeter *this, char *outfile)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
fprintf(this->out, "sys_curr,a57_curr,a53_curr,gpu_curr," if(this->out) {
"sys_volt,a57_volt,a53_volt,gpu_volt," fprintf(this->out, "sys_curr,a57_curr,a53_curr,gpu_curr,"
"sys_pow,a57_pow,a53_pow,gpu_pow," "sys_volt,a57_volt,a53_volt,gpu_volt,"
"sys_cenr,a57_cenr,a53_cenr,gpu_cenr\n"); "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) void emeter_read_measurements(struct emeter *this, struct reading *reading)
@ -333,11 +333,16 @@ int main(int argc, char *argv[])
config_init(&config, argc, argv); config_init(&config, argc, argv);
emeter_init(&emeter, config.output_file); emeter_init(&emeter, config.output_file);
struct timespec remaining; if(config.output_file)
while (!done)
{ {
struct timespec remaining;
while (!done)
{
emeter_take_reading(&emeter);
nsleep(&config.period, &remaining);
}
} else {
emeter_take_reading(&emeter); emeter_take_reading(&emeter);
nsleep(&config.period, &remaining);
} }
emeter_finalize(&emeter); emeter_finalize(&emeter);