Repository navigation
Expand file tree
/
Copy pathprofile.java
More file actions
124 lines (107 loc) · 2.82 KB
/
Copy pathprofile.java
File metadata and controls
124 lines (107 loc) · 2.82 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package fakescript;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
class profile
{
private fake m_f;
private boolean m_isopen;
private HashMap<String, profilefuncele> m_map = new HashMap<String, profilefuncele>();
private int[] m_codetype = new int[command.OPCODE_MAX];
public profile(fake f)
{
m_f = f;
}
public void open()
{
m_isopen = true;
}
public void close()
{
m_isopen = false;
}
public boolean isopen()
{
return m_isopen;
}
public void add_func_sample(String func, long calltime)
{
profilefuncele p = m_map.get(func);
if (p == null)
{
profilefuncele tmp = new profilefuncele();
tmp.m_callnum = 1;
tmp.m_calltime = calltime;
m_map.put(func, tmp);
return;
}
p.m_callnum++;
p.m_calltime += calltime;
}
public String dump()
{
ArrayList<Map.Entry<String, profilefuncele>> sortelevec = new ArrayList<Map.Entry<String, profilefuncele>>();
for (Map.Entry<String, profilefuncele> e : m_map.entrySet())
{
sortelevec.add(e);
}
Collections.sort(sortelevec, new Comparator<Map.Entry<String, profilefuncele>>() {
public int compare(Map.Entry<String, profilefuncele> arg0, Map.Entry<String, profilefuncele> arg1)
{
Long a0 = arg0.getValue().m_calltime;
Long a1 = arg1.getValue().m_calltime;
return a1.compareTo(a0);
}
});
String dumpstr = "";
int wraplen = 30;
dumpstr += "Call Func:\n";
dumpstr += "\t";
dumpstr += fix_string_wrap("Func", wraplen);
dumpstr += fix_string_wrap("Calls", wraplen);
dumpstr += fix_string_wrap("TotalTime(ms)", wraplen);
dumpstr += fix_string_wrap("PerCallTime(ms)", wraplen);
dumpstr += "\n";
for (int i = 0; i < (int) sortelevec.size(); i++)
{
profilefuncele ele = sortelevec.get(i).getValue();
dumpstr += "\t";
dumpstr += fix_string_wrap(sortelevec.get(i).getKey(), wraplen);
dumpstr += fix_string_wrap("" + ele.m_callnum, wraplen);
dumpstr += fix_string_wrap("" + ele.m_calltime, wraplen);
dumpstr += fix_string_wrap("" + (ele.m_callnum != 0 ? ele.m_calltime / ele.m_callnum : 0), wraplen);
dumpstr += "\n";
}
dumpstr += "Code Num:\n";
for (int i = 0; i < command.OPCODE_MAX; i++)
{
dumpstr += "\t";
dumpstr += types.OpCodeStr(i);
for (int j = 0; j < (int) (20 - types.OpCodeStr(i).length()); j++)
{
dumpstr += " ";
}
dumpstr += m_codetype[i];
dumpstr += "\n";
}
return dumpstr;
}
public void add_code_sample(int code)
{
m_codetype[code]++;
}
private String fix_string_wrap(String str, int len)
{
String ret = str;
if ((int) ret.length() < len)
{
for (int i = 0; i < len - ret.length() + 1; i++)
{
ret += " ";
}
}
return ret;
}
}