[jboss-cvs] JBoss Profiler SVN: r496 - in branches/JBossProfiler2/src/main/org/jboss/profiler: client and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sun Nov 16 15:01:02 EST 2008


Author: jesper.pedersen
Date: 2008-11-16 15:01:00 -0500 (Sun, 16 Nov 2008)
New Revision: 496

Added:
   branches/JBossProfiler2/src/main/org/jboss/profiler/shared/MethodRepository.java
Modified:
   branches/JBossProfiler2/src/main/org/jboss/profiler/agent/Profiler.java
   branches/JBossProfiler2/src/main/org/jboss/profiler/agent/ProfilerThreadImpl.java
   branches/JBossProfiler2/src/main/org/jboss/profiler/client/DifferenceUtil.java
   branches/JBossProfiler2/src/main/org/jboss/profiler/client/SnapshotUtil.java
   branches/JBossProfiler2/src/main/org/jboss/profiler/client/web/ThreadHotspotBean.java
   branches/JBossProfiler2/src/main/org/jboss/profiler/shared/FrameInfo.java
   branches/JBossProfiler2/src/main/org/jboss/profiler/shared/Snapshot.java
   branches/JBossProfiler2/src/main/org/jboss/profiler/shared/SnapshotHelper.java
Log:
Introduce MethodRepository -- reduce space requirements up to 20%

Modified: branches/JBossProfiler2/src/main/org/jboss/profiler/agent/Profiler.java
===================================================================
--- branches/JBossProfiler2/src/main/org/jboss/profiler/agent/Profiler.java	2008-11-05 20:44:24 UTC (rev 495)
+++ branches/JBossProfiler2/src/main/org/jboss/profiler/agent/Profiler.java	2008-11-16 20:01:00 UTC (rev 496)
@@ -26,6 +26,7 @@
 import org.jboss.profiler.shared.FrameHelper;
 import org.jboss.profiler.shared.FrameInfo;
 import org.jboss.profiler.shared.MethodInfo;
+import org.jboss.profiler.shared.MethodRepository;
 import org.jboss.profiler.shared.Snapshot;
 import org.jboss.profiler.shared.SnapshotHelper;
 import org.jboss.profiler.shared.ThreadHelper;
@@ -93,6 +94,8 @@
       profilerThreadMap = new ConcurrentHashMap<Long, ProfilerThreadImpl>();
       from = new Date();
 
+      MethodRepository.getInstance().clear();
+
       if (!Agent.isMemoryStore()) {
         Calendar c = Calendar.getInstance();
         DecimalFormat df = new DecimalFormat("00");
@@ -166,6 +169,7 @@
           Snapshot snapshot = new Snapshot(threadInfos,
                                            new ArrayList<AllocationInfo>(allocationInfos.values()),
                                            classList,
+                                           MethodRepository.getInstance(),
                                            from,
                                            to);
           snapshots.add(snapshot);
@@ -199,6 +203,7 @@
             Snapshot snapshot = new Snapshot(null,
                                              new ArrayList<AllocationInfo>(allocationInfos.values()),
                                              classList,
+                                             MethodRepository.getInstance(),
                                              from,
                                              to);
             SnapshotHelper.save(snapshot, new File(root, "data"));

Modified: branches/JBossProfiler2/src/main/org/jboss/profiler/agent/ProfilerThreadImpl.java
===================================================================
--- branches/JBossProfiler2/src/main/org/jboss/profiler/agent/ProfilerThreadImpl.java	2008-11-05 20:44:24 UTC (rev 495)
+++ branches/JBossProfiler2/src/main/org/jboss/profiler/agent/ProfilerThreadImpl.java	2008-11-16 20:01:00 UTC (rev 496)
@@ -26,6 +26,7 @@
 import org.jboss.profiler.shared.FrameHelper;
 import org.jboss.profiler.shared.FrameInfo;
 import org.jboss.profiler.shared.MethodInfo;
+import org.jboss.profiler.shared.MethodRepository;
 import org.jboss.profiler.shared.Snapshot;
 import org.jboss.profiler.shared.SnapshotHelper;
 import org.jboss.profiler.shared.ThreadHelper;
@@ -109,7 +110,7 @@
       return;
     }
 
-    MethodInfo mi = new MethodInfo(methodName, className);
+    Integer mi = MethodRepository.getInstance().getId(className, methodName);
     
     FrameInfo parent = activeFrame;
     FrameInfo fi = null;
@@ -222,8 +223,9 @@
     FrameInfo fi = activeFrame;
       
     // Constructor delegation
-    if (fi != null && fi.getMethod().getClassName().equals(className)
-        && "<init>".equals(fi.getMethod().getMethodName())) {
+    MethodInfo mi = MethodRepository.getInstance().getInfo(fi.getMethod());
+    if (fi != null && mi.getClassName().equals(className)
+        && "<init>".equals(mi.getMethodName())) {
       return;
     }
       
@@ -270,8 +272,9 @@
     FrameInfo fi = activeFrame;
     
     while (fi != null) {
-      if (fi.getMethod().getClassName().equals(className) 
-          && fi.getMethod().getMethodName().equals(methodName)) {
+      MethodInfo mi = MethodRepository.getInstance().getInfo(fi.getMethod());
+      if (mi.getClassName().equals(className) 
+          && mi.getMethodName().equals(methodName)) {
         // Found the first frame
         return fi;
       } else {

Modified: branches/JBossProfiler2/src/main/org/jboss/profiler/client/DifferenceUtil.java
===================================================================
--- branches/JBossProfiler2/src/main/org/jboss/profiler/client/DifferenceUtil.java	2008-11-05 20:44:24 UTC (rev 495)
+++ branches/JBossProfiler2/src/main/org/jboss/profiler/client/DifferenceUtil.java	2008-11-16 20:01:00 UTC (rev 496)
@@ -24,6 +24,8 @@
 import org.jboss.profiler.shared.AllocationInfo;
 import org.jboss.profiler.shared.ClassInfo;
 import org.jboss.profiler.shared.FrameInfo;
+import org.jboss.profiler.shared.MethodInfo;
+import org.jboss.profiler.shared.MethodRepository;
 import org.jboss.profiler.shared.Snapshot;
 import org.jboss.profiler.shared.ThreadInfo;
 
@@ -114,7 +116,7 @@
       Map<String, List<CombinedFrameInfo>> nInfo = getInformation(ns);
       List<TimedClassInfo> nClasses = getTimedClasses(ns.getClasses(), nInfo);
 
-      dumpThreads(ns.getThreads(), directory);
+      dumpThreads(ns.getMethodRepository(), ns.getThreads(), directory);
       dumpOverview(ns, nInfo, nClasses, directory);
       dumpMethods(oInfo, nInfo, directory);
       dumpHotspots(nInfo, directory);

Modified: branches/JBossProfiler2/src/main/org/jboss/profiler/client/SnapshotUtil.java
===================================================================
--- branches/JBossProfiler2/src/main/org/jboss/profiler/client/SnapshotUtil.java	2008-11-05 20:44:24 UTC (rev 495)
+++ branches/JBossProfiler2/src/main/org/jboss/profiler/client/SnapshotUtil.java	2008-11-16 20:01:00 UTC (rev 496)
@@ -28,6 +28,8 @@
 import org.jboss.profiler.shared.FrameComparator;
 import org.jboss.profiler.shared.FrameInfo;
 import org.jboss.profiler.shared.Math;
+import org.jboss.profiler.shared.MethodInfo;
+import org.jboss.profiler.shared.MethodRepository;
 import org.jboss.profiler.shared.Snapshot;
 import org.jboss.profiler.shared.SnapshotHelper;
 import org.jboss.profiler.shared.ThreadComparator;
@@ -102,7 +104,7 @@
 
     for (ThreadInfo ti: snapshot.getThreads()) {
       for (FrameInfo fi: ti.getFrames()) {
-        frameInformation(fi, tt, data);
+        frameInformation(snapshot.getMethodRepository(), fi, tt, data);
       }
 
       if (ti instanceof ThreadInfoProxy) {
@@ -127,23 +129,25 @@
 
   /**
    * Generate frame information
+   * @param mr The method repository
    * @param fi The frame
    * @param tt The total time (ns)
    * @param data The data
    */
-  private void frameInformation(FrameInfo fi, long tt, Map<String, Map<String, CombinedFrameInfo>> data) {
-    Map<String, CombinedFrameInfo> classData = data.get(fi.getMethod().getClassName());
+  private void frameInformation(MethodRepository mr, FrameInfo fi, long tt, Map<String, Map<String, CombinedFrameInfo>> data) {
+    MethodInfo mi = mr.getInfo(fi.getMethod());
+    Map<String, CombinedFrameInfo> classData = data.get(mi.getClassName());
       
     if (classData == null) {
       classData = new HashMap<String, CombinedFrameInfo>();
-      data.put(fi.getMethod().getClassName(), classData);
+      data.put(mi.getClassName(), classData);
     }
 
-    String prettyName = Util.getPrettyName(fi.getMethod());
+    String prettyName = Util.getPrettyName(mi);
     CombinedFrameInfo methodData = classData.get(prettyName);
     
     if (methodData == null) {
-      methodData = new CombinedFrameInfo(fi.getMethod().getClassName(), prettyName);
+      methodData = new CombinedFrameInfo(mi.getClassName(), prettyName);
       classData.put(prettyName, methodData);
     }
     
@@ -159,7 +163,7 @@
     List<FrameInfo> l = fi.getChildren();
     if (l != null) {
       for (FrameInfo child: l) {
-        frameInformation(child, tt, data);
+        frameInformation(mr, child, tt, data);
       }
     }
   }
@@ -207,7 +211,7 @@
 
       String directory = dir.getPath() + File.separator;
 
-      dumpThreads(snapshot.getThreads(), directory);
+      dumpThreads(snapshot.getMethodRepository(), snapshot.getThreads(), directory);
 
       Map<String, List<CombinedFrameInfo>> info = getInformation(snapshot);
       List<TimedClassInfo> classes = getTimedClasses(snapshot.getClasses(), info);
@@ -217,7 +221,7 @@
       dumpHotspots(info, directory);
       dumpPackages(info, directory);
       dumpClasses(classes, info, snapshot.getAllocations(), directory);
-      dumpCaller(snapshot.getThreads(), directory);
+      dumpCaller(snapshot.getMethodRepository(), snapshot.getThreads(), directory);
       dumpWaitTime(classes, directory);
     }
   }
@@ -285,11 +289,11 @@
 
   /**
    * Dump the threads to a file writer
-   * @param threads The threads
+   * @param snapshot The snapshot
    * @param directory The directory
    * @exception Exception If an error occurs
    */
-  protected void dumpThreads(List<ThreadInfo> threads, String directory) throws Exception {
+  protected void dumpThreads(MethodRepository mr, List<ThreadInfo> threads, String directory) throws Exception {
     File f = new File(directory + "threads");
     f.mkdirs();
 
@@ -323,7 +327,7 @@
       int frameNumber = 1;
 
       for (FrameInfo fi: ti.getFrames()) {
-        dumpFrame(fi, frameNumber, bw);
+        dumpFrame(mr, fi, frameNumber, bw);
         frameNumber++;
         bw.write(NEW_LINE);
       }
@@ -339,28 +343,30 @@
 
   /**
    * Dump the frame to a file writer
+   * @param snapshot The snapshot
    * @param fi The frame
    * @param fn The frame number
    * @param w The writer
    * @exception Exception If an error occurs
    */
-  protected void dumpFrame(FrameInfo fi, int fn, Writer w) throws Exception {
+  protected void dumpFrame(MethodRepository mr, FrameInfo fi, int fn, Writer w) throws Exception {
     w.write("Frame: " + fn + NEW_LINE);
     w.write("Count\tMs (T)\tMs (N)\t% (T)\t% (N)\tMethod" + NEW_LINE);
 
     long totalTime = fi.getTotalTime();
-    dumpFrame(fi, 0, (double)totalTime, w);
+    dumpFrame(mr, fi, 0, (double)totalTime, w);
   }
 
   /**
    * Dump the frame to a file writer
+   * @param snapshot The snapshot
    * @param fi The frame
    * @param level The level
    * @param tt The total time
    * @param w The writer
    * @exception Exception If an error occurs
    */
-  protected void dumpFrame(FrameInfo fi, int level, double tt, Writer w) throws Exception {
+  protected void dumpFrame(MethodRepository mr, FrameInfo fi, int level, double tt, Writer w) throws Exception {
     DecimalFormat df = new DecimalFormat("#0.00");
 
     long total = fi.getTotalTime();
@@ -379,13 +385,14 @@
       w.write(" ");
     }
     
-    w.write(Util.getPrettyName(fi.getMethod()));
+    MethodInfo mi = mr.getInfo(fi.getMethod());
+    w.write(Util.getPrettyName(mi));
     w.write(NEW_LINE);
 
     List<FrameInfo> l = fi.getChildren();
     if (l != null) {
       for (FrameInfo child: l) {      
-        dumpFrame(child, level + 1, tt, w);
+        dumpFrame(mr, child, level + 1, tt, w);
       }
     }
   }
@@ -773,11 +780,12 @@
 
   /**
    * Dump the caller information to a file writer
+   * @param methodRepository The method repository
    * @param threads The threads
    * @param directory The directory
    * @exception Exception If an error occurs
    */
-  protected void dumpCaller(List<ThreadInfo> threads, String directory) throws Exception {
+  protected void dumpCaller(MethodRepository methodRepository, List<ThreadInfo> threads, String directory) throws Exception {
     File f = new File(directory + "caller");
     f.mkdirs();
 
@@ -785,7 +793,7 @@
 
     for (ThreadInfo ti: threads) {
       for (FrameInfo fi: ti.getFrames()) {
-        getCallerInformation(fi, data);
+        getCallerInformation(methodRepository, fi, data);
       }
 
       if (ti instanceof ThreadInfoProxy) {
@@ -896,20 +904,23 @@
 
   /**
    * Get caller information
+   * @param mr The method repository
    * @param fi The frame
    * @param data The data
    */
-  protected void getCallerInformation(FrameInfo fi, Map<String, Map<String, CombinedFrameInfo>> data) {
-    Map<String, CombinedFrameInfo> entry = data.get(fi.getMethod().getClassName());
+  protected void getCallerInformation(MethodRepository mr, FrameInfo fi, Map<String, Map<String, CombinedFrameInfo>> data) {
+    MethodInfo mi = mr.getInfo(fi.getMethod());
+    Map<String, CombinedFrameInfo> entry = data.get(mi.getClassName());
     if (entry == null) {
       entry = new HashMap<String, CombinedFrameInfo>();
-      data.put(fi.getMethod().getClassName(), entry);
+      data.put(mi.getClassName(), entry);
     }
     if (fi.getParent() != null) {
-      String parentName = Util.getPrettyName(fi.getParent().getMethod());
+      MethodInfo pmi = mr.getInfo(fi.getParent().getMethod());
+      String parentName = Util.getPrettyName(pmi);
       CombinedFrameInfo cfi = entry.get(parentName);
       if (cfi == null) {
-        cfi = new CombinedFrameInfo(Util.getPrettyName(fi.getMethod()), parentName);
+        cfi = new CombinedFrameInfo(Util.getPrettyName(mi), parentName);
         entry.put(parentName, cfi);
       }
 
@@ -919,7 +930,7 @@
 
     if (fi.getChildren() != null && fi.getChildren().size() > 0) {
       for (FrameInfo child : fi.getChildren()) {
-        getCallerInformation(child, data);
+        getCallerInformation(mr, child, data);
       }
     }
   }

Modified: branches/JBossProfiler2/src/main/org/jboss/profiler/client/web/ThreadHotspotBean.java
===================================================================
--- branches/JBossProfiler2/src/main/org/jboss/profiler/client/web/ThreadHotspotBean.java	2008-11-05 20:44:24 UTC (rev 495)
+++ branches/JBossProfiler2/src/main/org/jboss/profiler/client/web/ThreadHotspotBean.java	2008-11-16 20:01:00 UTC (rev 496)
@@ -221,6 +221,10 @@
    * @param data The data
    */
   public void getCallerInformation(FrameInfo fi, Map<String, Map<String, CombinedFrameInfo>> data) {
+    /*
+
+    TODO -- common implementation should be placed in the client
+
     Map<String, CombinedFrameInfo> entry = data.get(fi.getMethod().getClassName());
     if (entry == null) {
       entry = new HashMap<String, CombinedFrameInfo>();
@@ -243,5 +247,7 @@
         getCallerInformation(child, data);
       }
     }
+
+    */
   }
 }

Modified: branches/JBossProfiler2/src/main/org/jboss/profiler/shared/FrameInfo.java
===================================================================
--- branches/JBossProfiler2/src/main/org/jboss/profiler/shared/FrameInfo.java	2008-11-05 20:44:24 UTC (rev 495)
+++ branches/JBossProfiler2/src/main/org/jboss/profiler/shared/FrameInfo.java	2008-11-16 20:01:00 UTC (rev 496)
@@ -35,10 +35,10 @@
 public class FrameInfo implements Serializable {
 
   /** Serial version UID */
-  static final long serialVersionUID = 5886070827318986209L;
+  static final long serialVersionUID = -7566505769269778532L;
 
   /** The method */
-  private MethodInfo method;
+  private Integer method;
 
   /** The parent frame */
   private FrameInfo parent;
@@ -56,7 +56,7 @@
   private long waitTime;
 
   /** Child map */
-  private transient Map<MethodInfo, Integer> childMap;
+  private transient Map<Integer, Integer> childMap;
 
   /** The net time */
   private transient long netTime;
@@ -75,7 +75,7 @@
    * @param method The method
    * @param parent The parent
    */
-  public FrameInfo(MethodInfo method, FrameInfo parent) {
+  public FrameInfo(Integer method, FrameInfo parent) {
     this.method = method;
     this.parent = parent;
     this.children = null;
@@ -98,7 +98,7 @@
    * Get the method
    * @return The method
    */
-  public MethodInfo getMethod() {
+  public Integer getMethod() {
     return method;
   }
   
@@ -203,7 +203,7 @@
    * @param m The method
    * @return The frame
    */
-  public FrameInfo getChild(MethodInfo m) {
+  public FrameInfo getChild(Integer m) {
     if (childMap != null) {
       Integer i = childMap.get(m);
       if (i != null) {
@@ -293,7 +293,7 @@
    */
   private void initChildren() {
     if (childMap == null) {
-      childMap = new HashMap<MethodInfo, Integer>(); 
+      childMap = new HashMap<Integer, Integer>(); 
     }
     if (children == null) {
       children = new ArrayList<FrameInfo>(); 
@@ -305,7 +305,7 @@
    * @param mi The method
    * @param fi The child
    */
-  private void addChild(MethodInfo mi, FrameInfo fi) {
+  private void addChild(Integer mi, FrameInfo fi) {
     if (children == null || childMap == null) {
       initChildren();
     }

Added: branches/JBossProfiler2/src/main/org/jboss/profiler/shared/MethodRepository.java
===================================================================
--- branches/JBossProfiler2/src/main/org/jboss/profiler/shared/MethodRepository.java	                        (rev 0)
+++ branches/JBossProfiler2/src/main/org/jboss/profiler/shared/MethodRepository.java	2008-11-16 20:01:00 UTC (rev 496)
@@ -0,0 +1,92 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007-2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.profiler.shared;
+
+import java.io.Serializable;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+/**
+ * Represents a method repository
+ * @author Jesper Pedersen <jesper.pedersen at jboss.org>
+ */
+public class MethodRepository implements Serializable {
+
+  /** Serial version UID */
+  static final long serialVersionUID = 5622833197888854580L;
+
+  /** The instance */
+  private static final MethodRepository instance = new MethodRepository();
+
+  /** The methods */
+  private ConcurrentMap<Integer, MethodInfo> methods;
+
+  /**
+   * Constructor
+   */
+  private MethodRepository() {
+    methods = new ConcurrentHashMap<Integer, MethodInfo>();
+  }
+
+  /**
+   * Get the instance
+   * @return The instance
+   */
+  public static MethodRepository getInstance() {
+    return instance;
+  }
+
+  /**
+   * Clear the method information
+   */
+  public void clear() {
+    methods.clear();
+  }
+
+  /**
+   * Get the method id
+   * @param className The class name
+   * @param methodName The method name
+   * @return The method id
+   */
+  public Integer getId(String className, String methodName) {
+    MethodInfo method = new MethodInfo(methodName, className);
+    Integer hash = Integer.valueOf(method.hashCode());
+
+    MethodInfo value = methods.get(hash); 
+
+    if (value == null) {
+      value = methods.put(hash, method);
+    }
+
+    return hash;
+  }
+
+  /**
+   * Get the method info
+   * @param id The method id
+   * @return The method info
+   */
+  public MethodInfo getInfo(Integer id) {
+    return methods.get(id);
+  }
+}

Modified: branches/JBossProfiler2/src/main/org/jboss/profiler/shared/Snapshot.java
===================================================================
--- branches/JBossProfiler2/src/main/org/jboss/profiler/shared/Snapshot.java	2008-11-05 20:44:24 UTC (rev 495)
+++ branches/JBossProfiler2/src/main/org/jboss/profiler/shared/Snapshot.java	2008-11-16 20:01:00 UTC (rev 496)
@@ -32,7 +32,7 @@
 public class Snapshot implements Serializable {
 
   /** Serial version UID */
-  static final long serialVersionUID = 2227827499078876487L;
+  static final long serialVersionUID = -7221125527680152722L;
 
   /** The threads list */
   private List<ThreadInfo> threadList;
@@ -42,6 +42,9 @@
   
   /** The class list */
   private List<ClassInfo> classList;
+
+  /** The method repository */
+  private MethodRepository methodRepository;
   
   /** From date */
   private Date from;
@@ -53,17 +56,21 @@
    * Constructor
    * @param threadList The thread list
    * @param allocationList The allocation list
+   * @param classList The class list
+   * @param methodRepository The method repository
    * @param from The from date
    * @param to The to date
    */
   public Snapshot(List <ThreadInfo> threadList,
                   List<AllocationInfo> allocationList,
                   List<ClassInfo> classList,
+                  MethodRepository methodRepository,
                   Date from,
                   Date to) {
     this.threadList = threadList;
     this.allocationList = allocationList;
     this.classList = classList;
+    this.methodRepository = methodRepository;
     this.from = from;
     this.to = to;
   }
@@ -107,4 +114,12 @@
   public List<ClassInfo> getClasses() {
     return classList;
   }
+
+  /**
+   * Get the method repository
+   * @return The method repository
+   */
+  public MethodRepository getMethodRepository() {
+    return methodRepository;
+  }
 }

Modified: branches/JBossProfiler2/src/main/org/jboss/profiler/shared/SnapshotHelper.java
===================================================================
--- branches/JBossProfiler2/src/main/org/jboss/profiler/shared/SnapshotHelper.java	2008-11-05 20:44:24 UTC (rev 495)
+++ branches/JBossProfiler2/src/main/org/jboss/profiler/shared/SnapshotHelper.java	2008-11-16 20:01:00 UTC (rev 496)
@@ -175,6 +175,7 @@
     return new Snapshot(threads,
                         base.getAllocations(),
                         base.getClasses(),
+                        base.getMethodRepository(),
                         base.getFrom(),
                         base.getTo());
   }




More information about the jboss-cvs-commits mailing list