|
3 | 3 | #include <string.h>
|
4 | 4 | #include <unistd.h>
|
5 | 5 | #include <argp.h>
|
| 6 | +#include <time.h> |
6 | 7 |
|
7 | 8 | const char *argp_program_version = "system_info 0.1.0";
|
8 | 9 | const char *argp_program_bug_address = "michalsledz34@gmail.com";
|
@@ -71,16 +72,21 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
|
71 | 72 | static struct argp argp = {options, parse_opt, 0, doc};
|
72 | 73 |
|
73 | 74 | int main(int argc, char **argv) {
|
| 75 | + unsigned long timestamp = (unsigned long)time(NULL); |
| 76 | + int timestamp_len = snprintf(NULL, 0, "%lu", timestamp); |
| 77 | + char *file_name = (char *)malloc(timestamp_len + 1 + 4); // +1 for NULL byte and +4 for .csv extenstion |
| 78 | + snprintf(file_name, timestamp_len + 1 + 4, "%lu.csv", timestamp); |
| 79 | + |
74 | 80 | struct arguments arguments;
|
75 |
| - arguments.file = "cpu_load.csv"; |
| 81 | + arguments.file = file_name; |
76 | 82 | arguments.interval = 1;
|
77 |
| - arguments.time = 10; |
| 83 | + arguments.time = 60; |
78 | 84 | argp_parse(&argp, argc, argv, 0, 0, &arguments);
|
79 | 85 |
|
80 | 86 | print_args(arguments);
|
81 | 87 |
|
82 | 88 | unsigned int iterations = arguments.time / arguments.interval;
|
83 |
| - printf("Iterations: %d\n", iterations); |
| 89 | + fprintf(stdout, "Iterations: %d\n", iterations); |
84 | 90 | struct cpu_info last_cpu_info;
|
85 | 91 | struct cpu_info current_cpu_info;
|
86 | 92 | FILE *stat;
|
@@ -123,6 +129,7 @@ int main(int argc, char **argv) {
|
123 | 129 |
|
124 | 130 | save_to_csv(arguments.file, cpu_loads, iterations);
|
125 | 131 | free(cpu_loads);
|
| 132 | + free(file_name); |
126 | 133 | return 0;
|
127 | 134 | }
|
128 | 135 |
|
|
0 commit comments