-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofiler.c
114 lines (104 loc) · 2.23 KB
/
profiler.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*********************************
Author: Parth Pathak (2020PCS1013)
**********************************/
#include <stdio.h>
#include <malloc.h>
#include <time.h>
#include "parth.h"
void fun1(void)
{
f1 = clock();
int i = 1024, l;
void * p = malloc(i);
free(p);
p = NULL;
for(l = 0; l < 4000000; l++){
}
if(p != NULL){
flag = "NO";
}else
{
flag = "YES";
}
f1 = clock() - f1;
double t1 = time_taken(f1);
printf("Fun 1:\t %d\t %s\t %f\r\n", i, flag, t1);
}
void fun2(void)
{
f2 = clock();
int j = 100, l;
void * p = malloc(j);
//free(p); /* << memory leak added here*/
//p = NULL;
for(l = 0; l < 3000000; l++){
}
if(p != NULL){
flag = "NO";
}else
{
flag = "YES";
}
f2 = clock() - f2;
double t2 = time_taken(f2);
printf("Fun 2:\t %d\t %s\t %f\r\n", j, flag, t2);
}
void fun3(void)
{
f3 = clock();
int k = 10, l;
void * p = malloc(k);
//free(p); /* << memory leak added here*/
//p = NULL;
for(l = 0; l < 2000000; l++){
}
if(p != NULL){
flag = "NO";
}else
{
flag = "YES";
}
f3 = clock() - f3;
double t3 = time_taken(f3);
printf("Fun 3:\t %d\t %s\t %f\r\n", k, flag, t3);
}
void fun4(void)
{
f4 = clock();
int l = 20, m;
void * p = malloc(l);
int i;
free(p);
p = NULL;
for(m = 0; m < 1000000; m++){
}
if(p != NULL){
flag = "NO";
}else
{
flag = "YES";
}
f4 = clock() - f4;
double t4 = time_taken(f4);
printf("Fun 4:\t %d\t %s\t %f\r\n", l, flag, t4);
}
int main(int argc, char *argv[])
{
begin = clock();
printf("\n********************Execution Profiler********************\r\n\n");
printf("--------------------------------------------\n");
printf("Function Bytes Freed? Execution Time\n");
printf("--------------------------------------------\n");
fun1();
fun2();
fun3();
fun4();
printf("--------------------------------------------\n");
show_mem_stat();
begin = clock() - begin;
double time_spent = time_taken(begin);
printf("Total Execution Time: %f", time_spent);
long double util = get_cpu_util();
printf("\nThe current CPU utilization is: %lf\n", util);
return 0;
}