|
|
|
@ -8,13 +8,14 @@ |
|
|
|
|
#include <string.h> |
|
|
|
|
#include <unistd.h> |
|
|
|
|
#include <signal.h> |
|
|
|
|
#include <time.h> |
|
|
|
|
|
|
|
|
|
const char *bat_base_path = "/sys/class/power_supply/"; |
|
|
|
|
int dead = 0; |
|
|
|
|
|
|
|
|
|
void usage (void) |
|
|
|
|
{ |
|
|
|
|
printf("usage: bmon [-h] [-w] [-f file] [-t interval]\n"); |
|
|
|
|
printf("usage: bmon [-wuh] [-f file] [-t interval]\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void int_handler (int signum) |
|
|
|
@ -34,10 +35,11 @@ int main (int argc, char *argv[]) |
|
|
|
|
int wflag = 0; |
|
|
|
|
int wait_time = 10; |
|
|
|
|
int fflag = 0; |
|
|
|
|
int uflag = 0; |
|
|
|
|
char ofile_path[256]; |
|
|
|
|
|
|
|
|
|
int opc; |
|
|
|
|
while ((opc = getopt(argc, argv, "hwf:t:")) != -1) { |
|
|
|
|
while ((opc = getopt(argc, argv, "uhwf:t:")) != -1) { |
|
|
|
|
switch (opc) { |
|
|
|
|
case 'w': |
|
|
|
|
wflag = 1; |
|
|
|
@ -48,11 +50,14 @@ int main (int argc, char *argv[]) |
|
|
|
|
break; |
|
|
|
|
case 't': |
|
|
|
|
wait_time = atoi(optarg); |
|
|
|
|
if (wait_time < 0) { |
|
|
|
|
if (wait_time < 1) { |
|
|
|
|
usage(); |
|
|
|
|
exit(1); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case 'u': |
|
|
|
|
uflag = 1; |
|
|
|
|
break; |
|
|
|
|
case 'h': |
|
|
|
|
default: /* '?' */ |
|
|
|
|
usage(); |
|
|
|
@ -129,7 +134,7 @@ int main (int argc, char *argv[]) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
long long elapsed_time = 0; |
|
|
|
|
long int elapsed_time = 0; |
|
|
|
|
char buf[64]; |
|
|
|
|
for (; !dead ; sleep(wait_time)) { |
|
|
|
|
for (int i = 0; i < fp_num; i++) { |
|
|
|
@ -146,13 +151,13 @@ int main (int argc, char *argv[]) |
|
|
|
|
printf("%s\t", buf); |
|
|
|
|
} |
|
|
|
|
if (fflag) { |
|
|
|
|
fprintf(ofile_ptr, "%lld\n", elapsed_time); |
|
|
|
|
fprintf(ofile_ptr, "%ld\n", uflag ? time(NULL) : elapsed_time); |
|
|
|
|
if (fflush(ofile_ptr)) { |
|
|
|
|
perror("error writing to file"); |
|
|
|
|
dead = 1; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
printf("%lld\n", elapsed_time); |
|
|
|
|
printf("%ld\n", uflag ? time(NULL) : elapsed_time); |
|
|
|
|
} |
|
|
|
|
elapsed_time += wait_time; |
|
|
|
|
} |
|
|
|
|