Skip to content

Commit dff3164

Browse files
committed
formatting
1 parent a4eabb2 commit dff3164

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

analyzer.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
#include "analyzer.h"
22
#include "cputracker.h"
33

4-
5-
unsigned long average_cpu_usage(struct proc_stat prev, struct proc_stat next){
4+
unsigned long average_cpu_usage(struct proc_stat prev, struct proc_stat next) {
65
unsigned long prev_idle = prev.idle + prev.iowait;
76
unsigned long idle = next.idle + next.iowait;
87

9-
unsigned long prev_non_idle = prev.user + prev.nice + prev.system + prev.irq + prev.softirq + prev.steal;
10-
unsigned long non_idle = next.user + next.nice + next.system + next.irq + next.softirq + next.steal;
8+
unsigned long prev_non_idle = prev.user + prev.nice + prev.system + prev.irq +
9+
prev.softirq + prev.steal;
10+
unsigned long non_idle = next.user + next.nice + next.system + next.irq +
11+
next.softirq + next.steal;
1112

1213
unsigned long prev_total = prev_idle + prev_non_idle;
1314
unsigned long total = idle + non_idle;
1415

1516
total -= prev_total;
1617
idle -= prev_idle;
1718

18-
return (total-idle)*100/total;
19+
return (total - idle) * 100 / total;
1920
}
2021

21-
2222
void *analyzer() {
23-
struct proc_stat *prev = malloc(g_nproc*sizeof(struct proc_stat));
23+
struct proc_stat *prev = malloc(g_nproc * sizeof(struct proc_stat));
2424
struct proc_stat *stats = NULL;
2525
while (1) {
2626
sem_wait(&g_filledSpaceSemaphore);
2727

2828
pthread_mutex_lock(&g_bufferMutex);
2929

3030
stats = get_item_from_buffer();
31-
for(int i = 0; i < g_nproc; i++){
31+
for (int i = 0; i < g_nproc; i++) {
3232
printf("%lu ", average_cpu_usage(prev[i], stats[i]));
3333
prev[i] = stats[i];
3434
}
@@ -38,4 +38,5 @@ void *analyzer() {
3838

3939
sem_post(&g_leftSpaceSemaphore);
4040
}
41+
free(prev);
4142
}

reader.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void *reader() {
3030
pthread_mutex_lock(&g_bufferMutex);
3131

3232
stats = get_item_from_buffer();
33-
33+
3434
if (get_proc_stats(stats) == -1) {
3535
pthread_mutex_unlock(&g_bufferMutex);
3636
continue;

0 commit comments

Comments
 (0)