📄 sleak.java
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: Sleak.java
package org.gudy.azureus2.ui.swt;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
// Referenced classes of package org.gudy.azureus2.ui.swt:
// Main
public class Sleak
{
Display display;
Shell shell;
List list;
Canvas canvas;
Button start;
Button stop;
Button check;
Text text;
Text label;
Object oldObjects[];
Error oldErrors[];
Object objects[];
Error errors[];
Map all;
ArrayList oldNonResources;
public Sleak()
{
oldObjects = new Object[0];
oldErrors = new Error[0];
objects = new Object[0];
errors = new Error[0];
all = new HashMap();
oldNonResources = new ArrayList();
}
public void open()
{
display = Display.getCurrent();
shell = new Shell(display);
shell.setText("S-Leak");
list = new List(shell, 2560);
list.addListener(13, new Listener() {
final Sleak this$0;
public void handleEvent(Event event)
{
refreshObject();
}
{
this$0 = Sleak.this;
super();
}
});
text = new Text(shell, 2816);
canvas = new Canvas(shell, 2048);
canvas.addListener(9, new Listener() {
final Sleak this$0;
public void handleEvent(Event event)
{
paintCanvas(event);
}
{
this$0 = Sleak.this;
super();
}
});
check = new Button(shell, 32);
check.setText("Stack");
check.addListener(13, new Listener() {
final Sleak this$0;
public void handleEvent(Event e)
{
toggleStackTrace();
}
{
this$0 = Sleak.this;
super();
}
});
start = new Button(shell, 8);
start.setText("Snap");
start.addListener(13, new Listener() {
final Sleak this$0;
public void handleEvent(Event event)
{
refreshAll();
}
{
this$0 = Sleak.this;
super();
}
});
stop = new Button(shell, 8);
stop.setText("Diff");
stop.addListener(13, new Listener() {
final Sleak this$0;
public void handleEvent(Event event)
{
refreshDifference();
}
{
this$0 = Sleak.this;
super();
}
});
label = new Text(shell, 2058);
label.setText("0 object(s)");
shell.addListener(11, new Listener() {
final Sleak this$0;
public void handleEvent(Event e)
{
layout();
}
{
this$0 = Sleak.this;
super();
}
});
check.setSelection(false);
text.setVisible(false);
Point size = shell.getSize();
shell.setSize(size.x / 2, size.y / 2);
shell.open();
}
void refreshLabel()
{
int colors = 0;
int cursors = 0;
int fonts = 0;
int gcs = 0;
int images = 0;
int regions = 0;
int others = 0;
int composites = 0;
int labels = 0;
for (int i = 0; i < objects.length; i++)
{
Object object = objects[i];
if (object instanceof Color)
{
colors++;
continue;
}
if (object instanceof Cursor)
{
cursors++;
continue;
}
if (object instanceof Font)
{
fonts++;
continue;
}
if (object instanceof GC)
{
gcs++;
continue;
}
if (object instanceof Image)
{
images++;
continue;
}
if (object instanceof Region)
{
regions++;
continue;
}
if (object instanceof Composite)
{
composites++;
continue;
}
if (object instanceof Label)
labels++;
else
others++;
}
String string = "";
if (colors != 0)
string = (new StringBuilder()).append(string).append(colors).append(" Color(s)\n").toString();
if (cursors != 0)
string = (new StringBuilder()).append(string).append(cursors).append(" Cursor(s)\n").toString();
if (fonts != 0)
string = (new StringBuilder()).append(string).append(fonts).append(" Font(s)\n").toString();
if (gcs != 0)
string = (new StringBuilder()).append(string).append(gcs).append(" GC(s)\n").toString();
if (images != 0)
string = (new StringBuilder()).append(string).append(images).append(" Image(s)\n").toString();
if (composites != 0)
string = (new StringBuilder()).append(string).append(composites).append(" composite(s)\n").toString();
if (labels != 0)
string = (new StringBuilder()).append(string).append(labels).append(" label(s)\n").toString();
if (others != 0)
string = (new StringBuilder()).append(string).append(others).append(" Other(s)\n").toString();
if (string.length() != 0)
string = string.substring(0, string.length() - 1);
label.setText(string);
}
void refreshDifference()
{
DeviceData info = display.getDeviceData();
if (!info.tracking)
{
MessageBox dialog = new MessageBox(this.shell, 40);
dialog.setText(this.shell.getText());
dialog.setMessage("Warning: Device is not tracking resource allocation");
dialog.open();
}
Object newObjects[] = info.objects;
Error newErrors[] = info.errors;
Object diffObjects[] = new Object[newObjects.length];
Error diffErrors[] = new Error[newErrors.length];
int countResourceType = 0;
for (int i = 0; i < newObjects.length; i++)
{
int index;
for (index = 0; index < oldObjects.length && newObjects[i] != oldObjects[index]; index++);
if (index == oldObjects.length)
{
diffObjects[countResourceType] = newObjects[i];
diffErrors[countResourceType] = newErrors[i];
countResourceType++;
}
}
Shell shells[] = display.getShells();
ArrayList nonResourceList = new ArrayList();
for (int i = 0; i < shells.length; i++)
{
Shell shell = shells[i];
if (shell != this.shell)
buildObjectList(shell, nonResourceList);
}
oldNonResources = nonResourceList;
Object nonResources[] = nonResourceList.toArray();
int countNonResources = nonResources.length;
int total = countResourceType + countNonResources;
objects = new Object[total];
errors = new Error[total];
System.arraycopy(((Object) (diffObjects)), 0, ((Object) (objects)), 0, countResourceType);
System.arraycopy(diffErrors, 0, errors, 0, countResourceType);
System.arraycopy(((Object) (nonResources)), 0, ((Object) (objects)), countResourceType, countNonResources);
list.removeAll();
text.setText("");
canvas.redraw();
for (int i = 0; i < objects.length; i++)
list.add(objectName(objects[i]));
System.out.println(countResourceType);
refreshLabel();
layout();
}
private void buildObjectList(Control control, ArrayList list)
{
if (!oldNonResources.contains(control))
list.add(control);
if (control instanceof Composite)
{
Composite c = (Composite)control;
Control children[] = c.getChildren();
for (int i = 0; i < children.length; i++)
{
Control control2 = children[i];
buildObjectList(control2, list);
}
}
}
String objectName(Object object)
{
Date timeAdded = (Date)all.get(object);
if (timeAdded == null)
{
timeAdded = new Date();
all.put(object, timeAdded);
}
String string = (new StringBuilder()).append(timeAdded).append("] ").append(object.toString()).toString();
if (object instanceof Resource)
return string;
int index = string.indexOf(" {");
if (index == -1)
return string;
string = string.substring(0, index);
if (object instanceof Composite)
{
Control children[] = ((Composite)object).getChildren();
string = (new StringBuilder()).append(string).append(": ").append(children.length).append(" kids").toString();
}
return string;
}
void toggleStackTrace()
{
refreshObject();
layout();
}
void paintCanvas(Event event)
{
canvas.setCursor(null);
int index = list.getSelectionIndex();
if (index == -1)
return;
GC gc = event.gc;
Object object = objects[index];
if (object instanceof Color)
if (((Color)object).isDisposed())
{
gc.drawString("Color disposed", 0, 0);
return;
} else
{
gc.setBackground((Color)object);
gc.fillRectangle(canvas.getClientArea());
return;
}
if (object instanceof Cursor)
if (((Cursor)object).isDisposed())
{
gc.drawString("Cursor disposed", 0, 0);
return;
} else
{
canvas.setCursor((Cursor)object);
return;
}
if (object instanceof Font)
{
if (((Font)object).isDisposed())
{
gc.drawString("Font disposed", 0, 0);
return;
}
gc.setFont((Font)object);
FontData array[] = gc.getFont().getFontData();
String string = "";
String lf = text.getLineDelimiter();
for (int i = 0; i < array.length; i++)
{
FontData data = array[i];
String style = "NORMAL";
int bits = data.getStyle();
if (bits != 0)
{
if ((bits & 1) != 0)
style = "BOLD ";
if ((bits & 2) != 0)
style = (new StringBuilder()).append(style).append("ITALIC").toString();
}
string = (new StringBuilder()).append(string).append(data.getName()).append(" ").append(data.getHeight()).append(" ").append(style).append(lf).toString();
}
gc.drawString(string, 0, 0);
return;
}
if (object instanceof Image)
if (((Image)object).isDisposed())
{
gc.drawString("Image disposed", 0, 0);
return;
} else
{
gc.drawImage((Image)object, 0, 0);
return;
}
if (object instanceof Region)
if (((Region)object).isDisposed())
{
return;
} else
{
String string = ((Region)object).getBounds().toString();
gc.drawString(string, 0, 0);
return;
}
if (object instanceof Control)
{
gc.drawString(object.toString(), 0, 0);
gc.drawString(((Control)object).getBounds().toString(), 0, 20);
if (object instanceof Widget)
{
Object data = ((Widget)object).getData("sleak");
if (data != null)
gc.drawString(data.toString(), 0, 35);
}
return;
} else
{
return;
}
}
void refreshObject()
{
int index = list.getSelectionIndex();
if (index == -1)
return;
if (check.getSelection() && index < errors.length && errors[index] == null)
{
ByteArrayOutputStream stream = new ByteArrayOutputStream();
PrintStream s = new PrintStream(stream);
errors[index].printStackTrace(s);
text.setText(stream.toString());
text.setVisible(true);
canvas.setVisible(false);
} else
{
canvas.setVisible(true);
text.setVisible(false);
canvas.redraw();
}
}
void refreshAll()
{
oldObjects = new Object[0];
oldErrors = new Error[0];
oldNonResources = new ArrayList();
refreshDifference();
oldObjects = objects;
oldErrors = errors;
}
void layout()
{
Rectangle rect = shell.getClientArea();
int width = 0;
String items[] = list.getItems();
GC gc = new GC(list);
for (int i = 0; i < objects.length; i++)
width = Math.max(width, gc.stringExtent(items[i]).x);
gc.dispose();
Point size1 = start.computeSize(-1, -1);
Point size2 = stop.computeSize(-1, -1);
Point size3 = check.computeSize(-1, -1);
Point size4 = label.computeSize(-1, -1);
width = Math.max(size1.x, Math.max(size2.x, Math.max(size3.x, width)));
width = Math.max(64, Math.max(size4.x, list.computeSize(width, -1).x));
start.setBounds(0, 0, width, size1.y);
stop.setBounds(0, size1.y, width, size2.y);
check.setBounds(0, size1.y + size2.y, width, size3.y);
label.setBounds(0, rect.height - size4.y, width, size4.y);
int height = size1.y + size2.y + size3.y;
list.setBounds(0, height, width, rect.height - height - size4.y);
text.setBounds(width, 0, rect.width - width, rect.height);
canvas.setBounds(width, 0, rect.width - width, rect.height);
}
public static void main(String args[])
{
DeviceData data = new DeviceData();
data.tracking = true;
Display display = new Display(data);
Sleak sleak = new Sleak();
Main.main(args);
sleak.open();
do
{
if (sleak.shell.isDisposed())
break;
if (!display.readAndDispatch())
display.sleep();
} while (true);
try
{
if (!display.isDisposed())
display.dispose();
}
catch (Exception e) { }
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -