-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathStats.h
More file actions
88 lines (63 loc) · 2.01 KB
/
Stats.h
File metadata and controls
88 lines (63 loc) · 2.01 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
86
87
88
//
// Created by Kosho Owa on 2016/08/19.
//
#ifndef ESPERF_STATS_H
#define ESPERF_STATS_H
#include <iostream>
#include <sstream>
#ifdef __linux__
#include <mutex>
#include <atomic>
#endif
#include "Options.h"
using namespace std;
class Stats {
public:
Stats(Options *options_, mutex *mtx_for_cout_);
bool IsFinished() const;
u_long CountRequest();
void CountResult(const int success, const int error_curl, const int error_http,
const u_long size_upload, const u_long size_download, const double time_transfer);
void ShowProgressHeader();
void ShowProgress();
void ShowResult();
private:
Options *options_;
mutex *mtx_for_cout_;
// Keep start and stop time
chrono::steady_clock::time_point clock_start_ = chrono::steady_clock::now();
chrono::steady_clock::time_point clock_stop_;
// Finished processing
bool finished_ = false;
// Counters from 0 sec
atomic_ulong requests_;
atomic_ulong success_;
atomic_ulong error_curl_;
atomic_ulong error_http_;
atomic_ulong size_upload_;
atomic_ulong size_download_;
atomic<double> time_transfer_{0.0};
// Counters after warm-up seconds
atomic_ulong wu_success_;
atomic_ulong wu_error_curl_;
atomic_ulong wu_error_http_;
atomic_ulong wu_size_upload_;
atomic_ulong wu_size_download_;
atomic<double> wu_time_transfer_;
u_long prev_success_ = 0;
u_long prev_error_curl_ = 0;
u_long prev_error_http_ = 0;
u_long prev_size_upload_ = 0;
u_long prev_size_download_ = 0;
double prev_time_transfer_ = 0;
// Function to add value to atomic double
void add_to_atomic_double(atomic<double> *var, double val) {
auto current = var->load();
while (!var->compare_exchange_weak(current, current + val));
}
void PrintLine(const string option, const u_int value);
void PrintLine(const string option, double value);
void safe_cout(const string msg);
void safe_cerr(const string msg);
};
#endif //ESPERF_STATS_H