SleakManager.java

Go to the documentation of this file.
00001 package edu.rice.cs.hpc.common.util;
00002 
00003 import java.util.Hashtable;
00004 
00005 import org.eclipse.swt.graphics.DeviceData;
00006 import org.eclipse.swt.widgets.Display;
00007 
00008 /******************************************************
00009  * 
00010  * Managing sleak objects across different windows 
00011  * 
00012  * To use SleakManager, make sure the tracing configuration
00013  * is set correctly for the following attributes:
00014  * 
00015  *     org.eclipse.ui/debug=true 
00016  *     org.eclipse.ui/trace/graphics=true
00017  *     
00018  * and environment variable HPCTOOLKIT_MEMLEAK=1
00019  * 
00020  ******************************************************/
00021 public class SleakManager {
00022 
00023     private static final String VAR_MEMLEAK = "HPCTOOLKIT_MEMLEAK";
00024     
00025     static final private Hashtable<Display, Sleak> lists = new Hashtable<Display, Sleak>(1);
00026     
00027     
00028     /************
00029      * retrieve the sleak object of this display iff HPCTOOLKIT_MEMLEAK has value "1" or "T"
00030      * 
00031      * @param display
00032      * 
00033      * @return sleak object if the environement variable is true, null otherwise
00034      ************/
00035     static public Sleak getSleak(final Display display) {
00036         
00037         Sleak sleak = null;
00038 
00039         String mem = System.getenv(VAR_MEMLEAK);
00040         
00041         // we activate sleak if the value of variable HPCTOOLKIT_MEMLEAK is not "f" or "0"
00042         
00043         if ( mem != null &&  !mem.isEmpty()) {
00044             boolean memleak = !(mem.equalsIgnoreCase("f") || mem.equals("0"));
00045             
00046             if (memleak) {
00047                 // memleak is on. Check if it's already on for this display.
00048                 // we don't want to have two sleaks work on the same display
00049                 
00050                 sleak = lists.get(display);
00051 
00052                 if (sleak == null) {
00053                     
00054                     DeviceData data = display.getDeviceData();
00055                     if (data.tracking) {
00056                         sleak = new Sleak();
00057                         lists.put(display, sleak);
00058                     }
00059                 }
00060             }
00061         }
00062         return sleak;
00063     }
00064     
00065     
00066     /************
00067      * initialize sleak. If sleak is not activated by the environment variable HPCTOOLKIT_MEMLEAK,
00068      * it won't be started.
00069      * 
00070      * @param display
00071      ************/
00072     static public void init(final Display display) {
00073         Sleak sleak = getSleak( display );
00074         if (sleak != null) {
00075             sleak.open();
00076         }
00077     }
00078 }

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1