mirror of
https://github.com/ARM-software/devlib.git
synced 2025-02-23 04:57:50 +00:00
readenergy: New flag to specify execution duration
- '-d' flag allow user to specify duration in sec - default is 0, which means run till user termination signal is received
This commit is contained in:
parent
8300344f70
commit
dfc63a1cc0
Binary file not shown.
@ -89,6 +89,9 @@
|
|||||||
// Default counter poll period (in milliseconds).
|
// Default counter poll period (in milliseconds).
|
||||||
#define DEFAULT_PERIOD 100
|
#define DEFAULT_PERIOD 100
|
||||||
|
|
||||||
|
// Default duration for the instrument execution (in seconds); 0 means 'forever'
|
||||||
|
#define DEFAULT_DURATION 0
|
||||||
|
|
||||||
// A single reading from the energy meter. The values are the proper readings converted
|
// A single reading from the energy meter. The values are the proper readings converted
|
||||||
// to appropriate units (e.g. Watts for power); they are *not* raw counter values.
|
// to appropriate units (e.g. Watts for power); they are *not* raw counter values.
|
||||||
struct reading
|
struct reading
|
||||||
@ -143,11 +146,15 @@ 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"
|
"to OUTFILE in CSV format either until SIGTERM is received OR\n"
|
||||||
|
"till the specified duration elapsed.\n"
|
||||||
"If OUTFILE is not specified, stdout will be used.\n\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"
|
||||||
|
" DURATION is the duration before execution terminates.\n"
|
||||||
|
" (Defaults to 0 seconds, meaning run till user\n"
|
||||||
|
" terminates execution.\n"
|
||||||
" OUTFILE is the output file path\n");
|
" OUTFILE is the output file path\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,6 +171,7 @@ struct config
|
|||||||
{
|
{
|
||||||
struct timespec period;
|
struct timespec period;
|
||||||
char *output_file;
|
char *output_file;
|
||||||
|
long duration_in_sec;
|
||||||
};
|
};
|
||||||
|
|
||||||
void config_init_period_from_millis(struct config *this, long millis)
|
void config_init_period_from_millis(struct config *this, long millis)
|
||||||
@ -176,9 +184,10 @@ void config_init(struct config *this, int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
this->output_file = NULL;
|
this->output_file = NULL;
|
||||||
config_init_period_from_millis(this, DEFAULT_PERIOD);
|
config_init_period_from_millis(this, DEFAULT_PERIOD);
|
||||||
|
this->duration_in_sec = DEFAULT_DURATION;
|
||||||
|
|
||||||
int opt;
|
int opt;
|
||||||
while ((opt = getopt(argc, argv, "ht:o:")) != -1)
|
while ((opt = getopt(argc, argv, "ht:o:d:")) != -1)
|
||||||
{
|
{
|
||||||
switch(opt)
|
switch(opt)
|
||||||
{
|
{
|
||||||
@ -188,6 +197,9 @@ void config_init(struct config *this, int argc, char *argv[])
|
|||||||
case 'o':
|
case 'o':
|
||||||
this->output_file = optarg;
|
this->output_file = optarg;
|
||||||
break;
|
break;
|
||||||
|
case 'd':
|
||||||
|
this->duration_in_sec = atol(optarg);
|
||||||
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
print_help();
|
print_help();
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
@ -314,13 +326,19 @@ void emeter_finalize(struct emeter *this)
|
|||||||
|
|
||||||
// -------------------------------------- /emeter ----------------------------------------------------
|
// -------------------------------------- /emeter ----------------------------------------------------
|
||||||
|
|
||||||
int done = 0;
|
volatile int done = 0;
|
||||||
|
|
||||||
void term_handler(int signum)
|
void term_handler(int signum)
|
||||||
{
|
{
|
||||||
done = 1;
|
done = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sigalrm_handler(int signum)
|
||||||
|
{
|
||||||
|
done = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct sigaction action;
|
struct sigaction action;
|
||||||
@ -333,6 +351,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 (0 != config.duration_in_sec)
|
||||||
|
{
|
||||||
|
/*Set the alarm with the duration from use only if a non-zero value is specified
|
||||||
|
else it will run forever until SIGTERM signal received from user*/
|
||||||
|
/*Set the signal handler first*/
|
||||||
|
signal(SIGALRM, sigalrm_handler);
|
||||||
|
/*Now set the alarm for the duration specified by the user*/
|
||||||
|
alarm(config.duration_in_sec);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if(config.output_file)
|
if(config.output_file)
|
||||||
{
|
{
|
||||||
struct timespec remaining;
|
struct timespec remaining;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user