-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmemorywnd.xcsm
368 lines (293 loc) · 12 KB
/
memorywnd.xcsm
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
//xlang Source, Name:memorywnd.xcsm
//Date: Thu Sep 17:49:58 2018
class XMemoryWnd : QDockWidget{
QTreeWidget _listview;
QPushButton btnGc, btnRefresh;
JsonObject meminfo;
Object memLock = new Object();
public static XMemoryWnd memoryWnd;
MemoryWaveWidget memwidget;
static const int COMPILE_INFO_NOTIFY = 2;
onTreeViewItemEvent listlistener = new onTreeViewItemEvent(){
};
Vector<long> memhistroy = new Vector<long>();
public static class MemoryWaveWidget : QWidget{
double []histroy = new double[100];
int currentidx = 0;
bool bupdated = false;
QPainter.Paint mempaint = new QPainter.Paint();
QPainter.Paint ptpaint = new QPainter.Paint();
QPainter.Paint txtpaint = new QPainter.Paint();
QPath _currentpath = nilptr;
double hmax = 0;
bool bpressed = false;
double pressx = 0;
int bkcolor = 0xfffefefe;
String tipsText = "";
double tipy;
public void onAttach()override{
mempaint.setStyle(QPainter.Paint.FILL_AND_STROKE);
mempaint.setColor(0x7f64d9f0);
ptpaint.setColor(0xffff0000);
ptpaint.setStyle(QPainter.Paint.STROKE);
txtpaint.setColor(0xff00ff00);
}
public QPath buildpath(double w, double h){
QPath mempath = new QPath();
mempath.moveto(0,h);
for (int i = 0; i < 100; i ++){
if (histroy[i] > hmax){
hmax = histroy[i];
}
}
double dp = w / 100;
double yp = h * 0.8f / hmax;
for (int i = 0; i < currentidx + 1; i ++){
mempath.lineto(dp * i,h - (yp * histroy[i]));
}
mempath.lineto(dp * (currentidx),h);
bupdated = false;
if (bpressed){
int id = pressx / dp;
if (id >=0 && id < currentidx + 1){
double ptmem = histroy[id];
tipy = h - (yp * histroy[id]);
tipsText = "快照" + (id + 1) + ":" + formatByte(ptmem);
}
}
return mempath;
}
public void onMouseMove(int Button,int x,int y,int flags,int source)override{
if (bpressed){
pressx = x;
bupdated = true;
update();
}
}
public void onMouseButtonRelease(int Button,int x,int y,int flags,int source)override{
bpressed = false;
bupdated = true;
update();
}
public void onMouseButtonPress(int Button,int x,int y,int flags,int source)override{
bpressed = true;
pressx = x;
bupdated = true;
update();
}
public void applySetting(){
if (Setting.isDarkStyle()){
bkcolor = 0xff252526;
txtpaint.setColor(0xffe0e0e0);
}else{
txtpaint.setColor(0xff252627);
bkcolor = 0xfffefefe;
}
}
public void onPaint(int l,int t,int r,int b,long hpaint)override{
QPainter painter = new QPainter(hpaint);
int w = width(), h = height();
painter.fillRect(0,0,w,h,bkcolor,QBrush.Style.SolidPattern);
painter.setPaint(mempaint);
QPath __cpath;
synchronized(this){
if (bupdated){
_currentpath = buildpath(w, h);
}
__cpath = _currentpath;
}
if (__cpath != nilptr){
painter.drawPath(__cpath);
}
if (bpressed){
painter.setPaint(ptpaint);
painter.drawLine(pressx,0,pressx,h);
painter.drawLine(0,tipy,w,tipy);
painter.drawText(tipsText,pressx,tipy, txtpaint);
}else{
painter.drawText("峰值:" + formatByte(hmax),5,15, txtpaint);
}
}
public void addMemhistroy(long value){
synchronized(this){
if (currentidx < 99){
currentidx++;
}else{
_system_.arrayCopy(histroy,1,histroy,0,99);
}
histroy[currentidx] = value;
bupdated = true;
}
}
public void reset(){
currentidx = 0;
}
};
public static void reconfig(){
memoryWnd.memwidget.applySetting();
}
public static void reset(){
memoryWnd.memwidget.reset();
}
public void onAttach(){
_listview = (QTreeWidget)attachByName(new QTreeWidget(), "memlist");
memwidget = (MemoryWaveWidget)attachByName(new MemoryWaveWidget(), "memwidget");
btnGc = (QPushButton)attachByName(new QPushButton(), "btnGc");
btnRefresh = (QPushButton)attachByName(new QPushButton(), "btnRefresh");
/*setOnLayoutEventListener(new onLayoutEventListener(){
void onResize(QObject obj, int w, int h, int oldw, int oldh)override {
if (_listview != nilptr){
_listview.resize(w, h - 60);
btnGc.move(0, h - 55);
btnRefresh.move(80, h - 55);
}else{
_system_.consoleWrite("XMemoryWnd listview no prepared");
}
}
});*/
btnGc.setOnClickListener(
new onClickListener(){
void onClick(QObject obj, bool checked)override{
XWorkspace.workspace.debuggee.requestGc();
}
});
btnRefresh.setOnClickListener(
new onClickListener(){
void onClick(QObject obj, bool checked)override{
XWorkspace.workspace.debuggee.queryMemory();
}
});
String [] columns = {"项目", "计数", "内存"};
_listview.setColumns(columns);
_listview.setColumnWidth(0, 100);
_listview.setColumnWidth(1, 50);
_listview.setColumnWidth(2, 200);
_listview.setOnTreeViewItemEvent(listlistener);
memoryWnd = this;
new Timer().schedule(
new TimerTask(){
void run(){
if (XWorkspace.workspace != nilptr){
XWorkspace.workspace.debuggee.queryMemory();
}
}
}, 1000, -1);
}
public void showInfo(JsonObject infos){
synchronized(memLock){
meminfo = infos;
this.Notify(COMPILE_INFO_NOTIFY);
}
}
public static String formatByte(long bytes){
if (bytes < 1024){
return "" + bytes + " Byte(s)";
}
if (bytes >= 1024 && bytes < (1024 * 512)){
return String.format("%.4f Kb", (bytes / 1024.f));
}
if (bytes >= (1024 * 512) && bytes < 1024 * 1024 * 1024){
return String.format("%.4f Mb", (bytes / 1048576.f));
}
return String.format("%.4f Gb", (bytes / (1048576.f * 1024.f)));
}
long getJsonLong(@NotNilptr JsonObject jroot, String name){
String str = jroot.getString(name);
if (str != nilptr){
return str.parseLong();
}
return 0;
}
public void onNotification(long id){
JsonObject _meminfo = nilptr;
synchronized(memLock){
_meminfo = meminfo;
_listview.clear();
if (_meminfo != nilptr){
long lc = _meminfo.getInt("lc");
long ls = _meminfo.getInt("ls");
long dc = _meminfo.getInt("dc");
long ds = _meminfo.getInt("ds");
long ac = _meminfo.getInt("ac");
long as = _meminfo.getInt("as");
long bc = _meminfo.getInt("bc");
long bs = _meminfo.getInt("bs");
long cc = _meminfo.getInt("cc");
long cs = _meminfo.getInt("cs");
long sc = _meminfo.getInt("sc");
long ss = _meminfo.getInt("ss");
long cxc = _meminfo.getInt("cxc");
long cxs = _meminfo.getInt("cxs");
long oc = _meminfo.getInt("oc");
long os = _meminfo.getInt("os");
long au = _meminfo.getInt("au");
long js = _meminfo.getInt("js");
long ts = _meminfo.getInt("ts");
long tc = _meminfo.getInt("tc");
long heap = 0;
long uheap = 0;
try{
heap = getJsonLong(_meminfo, "heap");
uheap = getJsonLong(_meminfo, "uheap");
}catch(Exception e){
}
long item = _listview.addItem(nilptr, "数组对象");
_listview.setItemText(item, 1, "" + ac);
_listview.setItemText(item, 2, formatByte(ac * as));
item = _listview.addItem(nilptr, "数组数据");
_listview.setItemText(item, 1, "" + au);
_listview.setItemText(item, 2, formatByte(au));
item = _listview.addItem(nilptr, "Json数据");
_listview.setItemText(item, 1, "" + js);
_listview.setItemText(item, 2, formatByte(js));
item = _listview.addItem(nilptr, "类实例");
_listview.setItemText(item, 1, "" + bc);
_listview.setItemText(item, 2, formatByte(bc * bs));
item = _listview.addItem(nilptr, "类对象");
_listview.setItemText(item, 1, "" + cc);
_listview.setItemText(item, 2, formatByte(cc * cs));
item = _listview.addItem(nilptr, "栈");
_listview.setItemText(item, 1, "" + sc);
_listview.setItemText(item, 2, formatByte(sc * ss));
item = _listview.addItem(nilptr, "线程");
_listview.setItemText(item, 1, "" + cxc);
_listview.setItemText(item, 2, formatByte(cxc * cxs));
item = _listview.addItem(nilptr, "用户对象");
_listview.setItemText(item, 1, "" + oc);
_listview.setItemText(item, 2, formatByte(oc * os));
item = _listview.addItem(nilptr, "读写锁");
_listview.setItemText(item, 1, "" + lc);
_listview.setItemText(item, 2, formatByte(lc * ls));
item = _listview.addItem(nilptr, "锁(条件变量)");
_listview.setItemText(item, 1, "" + dc);
_listview.setItemText(item, 2, formatByte(dc * ds));
item = _listview.addItem(nilptr, "字符串");
_listview.setItemText(item, 1, "" + tc);
_listview.setItemText(item, 2, formatByte(ts));
item = _listview.addItem(nilptr, "堆(已使用)");
_listview.setItemText(item, 1, "" + heap);
_listview.setItemText(item, 2, formatByte(heap));
if (_system_.getPlatformId() == 0){
item = _listview.addItem(nilptr, "堆(空闲)");
_listview.setItemText(item, 1, "" + uheap);
_listview.setItemText(item, 2, formatByte(uheap));
}else{
item = _listview.addItem(nilptr, "堆空闲(未监控)");
}
int pooltotal = ac * as + bc * bs + cc * cs + sc * ss + cxc * cxs + oc * os + lc * ls + dc * ds;
item = _listview.addItem(nilptr, "池");
_listview.setItemText(item, 1, "" + (int)pooltotal);
_listview.setItemText(item, 2, formatByte(pooltotal));
item = _listview.addItem(nilptr, "总计(已使用)");
_listview.setItemText(item, 1, "" + (long)(pooltotal + heap));
_listview.setItemText(item, 2, formatByte(pooltotal + heap));
long total_used_mem = pooltotal + heap + uheap + ts + au + js;
item = _listview.addItem(nilptr, "全部");
_listview.setItemText(item, 1, "" + (long)(pooltotal + heap + uheap));
_listview.setItemText(item, 2, formatByte(total_used_mem));
memwidget.addMemhistroy(total_used_mem);
memwidget.postUpdate();
}
}
}
};