forked from shiyimin/androidtestdebug
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMemoryLog.java
More file actions
48 lines (41 loc) · 1.08 KB
/
MemoryLog.java
File metadata and controls
48 lines (41 loc) · 1.08 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
import java.util.*;
public class MemoryLog {
private LogEntry[] _entries = null;
private int _index = -1;
private Object _lock = new Object();
public void Init() {
_entries = new LogEntry[1024];
}
public void Add(String msg, Object data) {
int index = 0;
synchronized ( _lock ) {
index = ++_index % 1024;
}
LogEntry entry = new LogEntry();
entry.Data = data;
entry.Message = msg;
entry.Time = new Date();
Thread thread = Thread.currentThread();
entry.ThreadId = thread.getId();
entry.ThreadName = thread.getName();
_entries[index] = entry;
}
public void PrintLog() {
int idx = _index % 1024;
for ( int i = 0; i < idx; ++i ) {
LogEntry entry = _entries[i];
System.out.println(String.format("Thread [%1$d - %2$s@%3$s]: %4$s %5$s", entry.ThreadId,
entry.ThreadName,
entry.Time.toString(),
entry.Message,
entry.Data.toString()));
}
}
static class LogEntry {
public long ThreadId;
public String ThreadName;
public String Message;
public Object Data;
public Date Time;
}
}