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:
commit
4c4d7f177e
Binary file not shown.
@ -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
|
||||||
|
|
||||||
|
|
||||||
|
@ -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 ---------------------------------------------------
|
||||||
@ -218,6 +212,8 @@ struct emeter
|
|||||||
};
|
};
|
||||||
|
|
||||||
void emeter_init(struct emeter *this, char *outfile)
|
void emeter_init(struct emeter *this, char *outfile)
|
||||||
|
{
|
||||||
|
if(outfile)
|
||||||
{
|
{
|
||||||
this->out = fopen(outfile, "w");
|
this->out = fopen(outfile, "w");
|
||||||
if (this->out == NULL)
|
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));
|
fprintf(stderr, "ERROR: Could not open output file %s; got %s\n", outfile, strerror(errno));
|
||||||
exit(EXIT_FAILURE);
|
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,11 +241,13 @@ void emeter_init(struct emeter *this, char *outfile)
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(this->out) {
|
||||||
fprintf(this->out, "sys_curr,a57_curr,a53_curr,gpu_curr,"
|
fprintf(this->out, "sys_curr,a57_curr,a53_curr,gpu_curr,"
|
||||||
"sys_volt,a57_volt,a53_volt,gpu_volt,"
|
"sys_volt,a57_volt,a53_volt,gpu_volt,"
|
||||||
"sys_pow,a57_pow,a53_pow,gpu_pow,"
|
"sys_pow,a57_pow,a53_pow,gpu_pow,"
|
||||||
"sys_cenr,a57_cenr,a53_cenr,gpu_cenr\n");
|
"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,12 +333,17 @@ 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);
|
||||||
|
|
||||||
|
if(config.output_file)
|
||||||
|
{
|
||||||
struct timespec remaining;
|
struct timespec remaining;
|
||||||
while (!done)
|
while (!done)
|
||||||
{
|
{
|
||||||
emeter_take_reading(&emeter);
|
emeter_take_reading(&emeter);
|
||||||
nsleep(&config.period, &remaining);
|
nsleep(&config.period, &remaining);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
emeter_take_reading(&emeter);
|
||||||
|
}
|
||||||
|
|
||||||
emeter_finalize(&emeter);
|
emeter_finalize(&emeter);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user