### Eclipse Workspace Patch 1.0 #P org.eclipse.swt.tools Index: Sleak/org/eclipse/swt/tools/internal/Sleak.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.swt.tools/Sleak/org/eclipse/swt/tools/internal/Sleak.java,v retrieving revision 1.8 diff -u -r1.8 Sleak.java --- Sleak/org/eclipse/swt/tools/internal/Sleak.java 5 Sep 2008 14:02:30 -0000 1.8 +++ Sleak/org/eclipse/swt/tools/internal/Sleak.java 25 Mar 2009 14:18:49 -0000 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. + * Copyright (c) 2007, 2009 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -27,7 +27,7 @@ Shell shell; List list; Canvas canvas; - Button start, stop, check; + Button start, stop, check, print; Text text; Label label; @@ -90,6 +90,8 @@ start.addListener (SWT.Selection, new Listener () { public void handleEvent (Event event) { refreshAll (); + if (print.getSelection()) + exportDifference (); } }); stop = new Button (shell, SWT.PUSH); @@ -97,8 +99,13 @@ stop.addListener (SWT.Selection, new Listener () { public void handleEvent (Event event) { refreshDifference (); + if (print.getSelection()) + exportDifference (); } }); + print = new Button (shell, SWT.CHECK); + print.setText ("Dump to file"); + print.setToolTipText ("Dumps Snaps/Diffs stack traces to file"); label = new Label (shell, SWT.BORDER); label.setText ("0 object(s)"); shell.addListener (SWT.Resize, new Listener () { @@ -185,6 +192,35 @@ layout (); } +void exportDifference () { + File file = new File(Long.toString(System.currentTimeMillis()) + ".sleakdump"); + PrintStream pw = null; + try { + pw = new PrintStream(new FileOutputStream(file)); + } catch (FileNotFoundException e) { + MessageBox dialog = new MessageBox (shell, SWT.ICON_WARNING | SWT.OK); + dialog.setText (shell.getText ()); + dialog.setMessage (e.getMessage()+" Difference will be printed to standard output."); + dialog.open (); + pw = System.out; + } + try { + for (int i=0; i