Skip to content

Commit

Permalink
Set default file name to unix timestamp. Set default time to 60 seconds.
Browse files Browse the repository at this point in the history
  • Loading branch information
mickel8 committed Aug 8, 2021
1 parent 3613a1d commit 7dcf109
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <string.h>
#include <unistd.h>
#include <argp.h>
#include <time.h>

const char *argp_program_version = "system_info 0.1.0";
const char *argp_program_bug_address = "[email protected]";
Expand Down Expand Up @@ -71,16 +72,21 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
static struct argp argp = {options, parse_opt, 0, doc};

int main(int argc, char **argv) {
unsigned long timestamp = (unsigned long)time(NULL);
int timestamp_len = snprintf(NULL, 0, "%lu", timestamp);
char *file_name = (char *)malloc(timestamp_len + 1 + 4); // +1 for NULL byte and +4 for .csv extenstion
snprintf(file_name, timestamp_len + 1 + 4, "%lu.csv", timestamp);

struct arguments arguments;
arguments.file = "cpu_load.csv";
arguments.file = file_name;
arguments.interval = 1;
arguments.time = 10;
arguments.time = 60;
argp_parse(&argp, argc, argv, 0, 0, &arguments);

print_args(arguments);

unsigned int iterations = arguments.time / arguments.interval;
printf("Iterations: %d\n", iterations);
fprintf(stdout, "Iterations: %d\n", iterations);
struct cpu_info last_cpu_info;
struct cpu_info current_cpu_info;
FILE *stat;
Expand Down Expand Up @@ -123,6 +129,7 @@ int main(int argc, char **argv) {

save_to_csv(arguments.file, cpu_loads, iterations);
free(cpu_loads);
free(file_name);
return 0;
}

Expand Down

0 comments on commit 7dcf109

Please sign in to comment.