-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatistics.cpp
More file actions
32 lines (28 loc) · 865 Bytes
/
statistics.cpp
File metadata and controls
32 lines (28 loc) · 865 Bytes
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
#include "http_server.h"
void write_statistics(std::string ip, std::string ext) {
pthread_mutex_lock(&content_mutex);
if (content_map.find(ip) == content_map.end()) {
content_map[ip][ext] = 1;
}
else {
content_map[ip][ext]++;
}
pthread_mutex_unlock(&content_mutex);
}
void save_statistics(void) {
auto now = std::chrono::system_clock::now();
std::time_t end_time = std::chrono::system_clock::to_time_t(now);
std::string file = "statistics/";
file += std::ctime(&end_time);
file[file.length()-1] = '.';
file += "txt";
std::ofstream fout(file);
for (const auto& ip : content_map) {
fout << ip.first << " {\n";
for (const auto& fmt : ip.second) {
fout << "\t" << fmt.first << ": " << fmt.second << ",\n";
}
fout << "}\n";
}
fout.close();
}