This repository has been archived by the owner on Jan 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Stats.c
52 lines (47 loc) · 1.55 KB
/
Stats.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
#include "Stats.h"
#include "Global.h"
#include "Config.h"
#include "ProxyLists.h"
#include "Logger.h"
#ifdef __linux__
#include <unistd.h>
#endif
#include "CPH_Threads.h"
#include <stdlib.h>
void StatsCollection()
{
if (StatsCollectionInterval == 0)
return;
StatsProxyCountSize = 0;
StatsProxyCount = NULL;
for (;;) {
msleep(StatsCollectionInterval);
pthread_mutex_lock(&LockStatsProxyCount); {
uint64_t uproxy, proxy;
pthread_mutex_lock(&LockCheckedProxies); {
proxy = SizeCheckedProxies;
} pthread_mutex_unlock(&LockCheckedProxies);
pthread_mutex_lock(&LockUncheckedProxies); {
uproxy = SizeUncheckedProxies;
} pthread_mutex_unlock(&LockUncheckedProxies);
if (StatsProxyCountSize > 0) {
if (StatsProxyCount[StatsProxyCountSize - 1].UProxy == uproxy && StatsProxyCount[StatsProxyCountSize - 1].Proxy == proxy) {
pthread_mutex_unlock(&LockStatsProxyCount);
continue;
}
}
if (StatsProxyCountSize >= StatsMaxItems && StatsProxyCountSize > 0) {
for (size_t x = StatsProxyCountSize;x > 0;x--)
StatsProxyCount[x - 1] = StatsProxyCount[x];
} else {
StatsProxyCountSize++;
StatsProxyCount = StatsProxyCount == NULL ? malloc(sizeof(STATS_PROXY_COUNT)) : realloc(StatsProxyCount, StatsProxyCountSize * sizeof(STATS_PROXY_COUNT));
}
STATS_PROXY_COUNT *entry = &(StatsProxyCount[StatsProxyCountSize - 1]);
entry->UProxy = uproxy;
entry->Proxy = proxy;
entry->Time = GetUnixTimestampMilliseconds();
} pthread_mutex_unlock(&LockStatsProxyCount);
Log(LOG_LEVEL_DEBUG, "Collected stats");
}
}