-
Notifications
You must be signed in to change notification settings - Fork 36
/
PerformanceStatistics.java
63 lines (52 loc) · 1.54 KB
/
PerformanceStatistics.java
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
package com.backend;
import java.util.concurrent.atomic.AtomicLong;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class PerformanceStatistics
{
private static final Logger logger = LoggerFactory
.getLogger(PerformanceStatistics.class);
private volatile AtomicLong totalFileCount = new AtomicLong(0);
private volatile AtomicLong careFileCount = new AtomicLong(0);
private volatile AtomicLong timenow = new AtomicLong(
System.currentTimeMillis());
private static PerformanceStatistics instance = new PerformanceStatistics();
private PerformanceStatistics()
{
}
public static PerformanceStatistics getInstance()
{
return instance;
}
public void reset()
{
careFileCount.set(0);
totalFileCount.set(0);
timenow.set(System.currentTimeMillis());
}
public void addOneFile(boolean isCare)
{
totalFileCount.incrementAndGet();
if (isCare)
{
careFileCount.incrementAndGet();
}
long now = System.currentTimeMillis();
if (now - timenow.get() > 10000)
{
synchronized (this)
{
if (now - timenow.get() > 10000)
{
printPerformanceLog(now);
}
}
}
}
public void printPerformanceLog(long now)
{
timenow.set(now);
logger.warn("total file count: " + totalFileCount.get()
+ " checked file count: " + careFileCount.get());
}
}