ProcedureClassMap.java

Go to the documentation of this file.
00001 package edu.rice.cs.hpc.traceviewer.data.util;
00002 
00003 import java.util.Iterator;
00004 import java.util.Map.Entry;
00005 import org.eclipse.core.runtime.IPath;
00006 import org.eclipse.core.runtime.Platform;
00007 import org.eclipse.swt.SWT;
00008 import org.eclipse.swt.graphics.Color;
00009 import org.eclipse.swt.graphics.RGB;
00010 import org.eclipse.swt.widgets.Display;
00011 import edu.rice.cs.hpc.common.util.AliasMap;
00012 import edu.rice.cs.hpc.common.util.ProcedureClassData;
00013 
00014 
00015 /***
00016  * 
00017  * Class to manage map between a procedure and its class
00018  * For instance, we want to class all MPI_* into mpi class, 
00019  *  the get() method will then return all MPI functions into mpi
00020  *
00021  */
00022 public class ProcedureClassMap extends AliasMap<String,ProcedureClassData> {
00023 
00024     static public final String CLASS_IDLE = "idle";
00025     static private final String FILENAME = "proc-class.map";
00026     private final Display display;
00027     
00028     public ProcedureClassMap(Display display) {
00029         this.display = display;
00030     }
00031     
00032     /*
00033      * (non-Javadoc)
00034      * @see edu.rice.cs.hpc.common.util.ProcedureMap#getFilename()
00035      */
00036     public String getFilename() {
00037         IPath path;
00038         if (Platform.isRunning()) {
00039             path = Platform.getLocation().makeAbsolute();           
00040             return path.append(FILENAME).makeAbsolute().toString();
00041         } else {
00042             return FILENAME;
00043         }
00044     }
00045     
00046     /*
00047      * (non-Javadoc)
00048      * @see edu.rice.cs.hpc.common.util.ProcedureMap#initDefault()
00049      */
00050     public void initDefault() {
00051 
00052         final Color COLOR_GRAY;
00053         if (display != null) {
00054             COLOR_GRAY = display.getSystemColor(SWT.COLOR_GRAY);
00055         } else {
00056             COLOR_GRAY = null;
00057         }
00058 
00059         this.put("GPU_IDLE", CLASS_IDLE, COLOR_GRAY);
00060         this.put("cudaEventSynchronize", CLASS_IDLE, COLOR_GRAY);
00061         this.put("cudaStreamSynchronize", CLASS_IDLE, COLOR_GRAY);
00062         this.put("cudaDeviceSynchronize", CLASS_IDLE, COLOR_GRAY);
00063         this.put("cudaThreadSynchronize", CLASS_IDLE, COLOR_GRAY);
00064         this.put("cuStreamSynchronize", CLASS_IDLE, COLOR_GRAY);
00065         this.put("cuEventSynchronize", CLASS_IDLE, COLOR_GRAY);
00066         this.put("cuCtxSynchronize", CLASS_IDLE, COLOR_GRAY);
00067     }
00068     
00069     public Object[] getEntrySet() {
00070         checkData();
00071         return data.entrySet().toArray();
00072     }
00073 
00074     public ProcedureClassData get(String key) {
00075         checkData();
00076         Iterator<Entry<String, ProcedureClassData>> iterator = data.entrySet().iterator();
00077         while (iterator.hasNext()) {
00078             Entry<String, ProcedureClassData> entry = iterator.next();
00079             String glob = entry.getKey().replace("*", ".*").replace("?", ".?");
00080             if (key.equals(glob) || key.matches(glob)) {
00081                 return entry.getValue();
00082             }
00083         }
00084         return null;
00085     }
00086 
00087     public void put(String key, String val, Color image) {
00088         if (image != null)
00089         put(key,new ProcedureClassData(val,image));
00090     }
00091 
00092     public void put(String key, String val, RGB rgb) {
00093         put(key,new ProcedureClassData(val,rgb));
00094     }
00095 
00096     public ProcedureClassData remove(String key) {
00097         return data.remove(key);
00098     }
00099     
00100 
00101 }

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1