-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimplebench.c
More file actions
85 lines (70 loc) · 2.36 KB
/
simplebench.c
File metadata and controls
85 lines (70 loc) · 2.36 KB
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
// Name: Hou, Binbing
// Project: PA-1 (Simplebench)
// Instructor: Feng Chen
// Class: cs7700-sp18
// LogonID: cs770094
#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <pthread.h>
#include <unistd.h>
#include <sys/time.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "simplebench.h"
/* The main function controls the flow of testing */
int main(int argc, char ** argv)
{
int i, err;
float real_duration;
Parameters paras;
Result res;
// parse the parameters
if (parmeters_parsing_and_checking(argv, argc, ¶s) != 0){
printf("Please refer to the README file for parameter settings.\n");
return 0;
}
// check the access permission for the file or device to be tested
if (permission_check(paras.file, paras.type) != 0){
printf("Make sure that you have the permission to test the file or device\n");
return 0;
}
// check the permission to create and open the trace file
if (init_trace_file(paras.output) != 0){
printf("Failed to create or open the trace file %s \n", paras.output);
printf("Make sure that you have the permission \n");
return 0;
}
// init related data structures
threads = (pthread_t*)malloc(paras.thread_num * sizeof(pthread_t));
// allocate the State data structure per thread
paras.stat = (Stat *)malloc(paras.thread_num * sizeof(Stat));
// init the Result data structure
init_result(&res);
// record the start time
gettimeofday(&(start_time), NULL);
// create and start the threads
for (i = 0; i < paras.thread_num; i++){
err = pthread_create(&(threads[i]), NULL, &worker, (void*)¶s);
if (err != 0){
printf("Thread creation failed :[%s]", strerror(err));
return 0;
}
}
// wait until all the threads are completed
for (i = 0; i< paras.thread_num; i++)
pthread_join(threads[i], NULL);
// record the end time
gettimeofday(&(end_time), NULL);
// calculate thr real duration
real_duration = time_diff(end_time,start_time) /1000000.0;
// calcluate the metrics
result_stat(paras.stat, &res, paras.thread_num, paras.size, paras.type, real_duration);
// print the results
result_print(res);
return 0;
}