-
Notifications
You must be signed in to change notification settings - Fork 4
/
util.h
executable file
·99 lines (84 loc) · 3.55 KB
/
util.h
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
/*<copyright notice="lm-source" pids="" years="2017">*/
/*******************************************************************************
* Copyright (c) 2017 IBM Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Contributors:
* Paul Harris - Initial implementation
*******************************************************************************/
/*</copyright>*/
/*******************************************************************************/
/* */
/* IBM MQ Log Disk Tester */
/* */
/*******************************************************************************/
#ifndef _UTIL_H
#define _UTIL_H
#include <sys/time.h>
#include <time.h>
#define tStart(X) clock_gettime(CLOCK_MONOTONIC, X.check_time1);
#define ONE_SEC_IN_NS 1000000000
#define HALF_SEC_IN_NS 500000000
extern FILE *csvFile;
extern pthread_mutex_t mutex;
extern pthread_cond_t condition;
extern volatile int started;
struct timer {
struct timespec *start_time; /*Make these pointers so we can flip them easily in tCheck*/
struct timespec *check_time1;
struct timespec *check_time2;
int check_count;
long min_time;
int min_time_instance;
long avg_time;
long max_time;
int max_time_instance;
};
//Calculates time difference between the current time and the last time this method was called, updates min/max/avg time values
static inline long tCheck(struct timer *timerIn) {
long duration;
struct timespec *temp;
clock_gettime(CLOCK_MONOTONIC, timerIn->check_time2);
timerIn->check_count++;
if (timerIn->check_time2->tv_nsec > timerIn->check_time1->tv_nsec) {
duration = ((timerIn->check_time2->tv_sec - timerIn->check_time1->tv_sec) * ONE_SEC_IN_NS - (timerIn->check_time1->tv_nsec - timerIn->check_time2->tv_nsec));
} else {
duration = ((timerIn->check_time2->tv_sec - timerIn->check_time1->tv_sec) * ONE_SEC_IN_NS + (timerIn->check_time2->tv_nsec - timerIn->check_time1->tv_nsec));
}
if (duration > timerIn->max_time) {
timerIn->max_time = duration;
timerIn->max_time_instance = timerIn->check_count;
}
if (duration < timerIn->min_time) {
timerIn->min_time = duration;
timerIn->min_time_instance = timerIn->check_count;
}
timerIn->avg_time = ((timerIn->avg_time * (timerIn->check_count - 1)) + duration) / (timerIn->check_count);
/*flip the timespecs*/
temp = timerIn->check_time1;
timerIn->check_time1 = timerIn->check_time2;
timerIn->check_time2 = temp;
return duration;
}
void tInit(struct timer *timerIn);
void tReset(struct timer *timerIn);
void printTimerStats(struct timer *timerIn, int blockSize);
void csvTimerStatsTitles(FILE *csvFile);
void csvTimerStats(struct timer *timerIn, FILE *csvFile, int blockSize);
long file_GetPhysicalBlockSize(char *path);
char *UtilMakeBigString(int size, long alignment);
void *runTest(void *arg);
void openCSVFile();
#endif