[jboss-cvs] JBoss Profiler SVN: r492 - in branches/JBossProfiler2/src/main/org/jboss/profiler: shared and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Oct 29 10:15:55 EDT 2008
Author: jesper.pedersen
Date: 2008-10-29 10:15:55 -0400 (Wed, 29 Oct 2008)
New Revision: 492
Added:
branches/JBossProfiler2/src/main/org/jboss/profiler/shared/ThreadInfoProxy.java
Modified:
branches/JBossProfiler2/src/main/org/jboss/profiler/client/SnapshotUtil.java
branches/JBossProfiler2/src/main/org/jboss/profiler/shared/SnapshotHelper.java
branches/JBossProfiler2/src/main/org/jboss/profiler/shared/ThreadInfo.java
Log:
When reading from disk lazy load all data
Modified: branches/JBossProfiler2/src/main/org/jboss/profiler/client/SnapshotUtil.java
===================================================================
--- branches/JBossProfiler2/src/main/org/jboss/profiler/client/SnapshotUtil.java 2008-10-29 11:36:23 UTC (rev 491)
+++ branches/JBossProfiler2/src/main/org/jboss/profiler/client/SnapshotUtil.java 2008-10-29 14:15:55 UTC (rev 492)
@@ -32,6 +32,7 @@
import org.jboss.profiler.shared.SnapshotHelper;
import org.jboss.profiler.shared.ThreadComparator;
import org.jboss.profiler.shared.ThreadInfo;
+import org.jboss.profiler.shared.ThreadInfoProxy;
import java.io.BufferedWriter;
import java.io.File;
@@ -98,6 +99,11 @@
for (FrameInfo fi: ti.getFrames()) {
frameInformation(fi, tt, data);
}
+
+ if (ti instanceof ThreadInfoProxy) {
+ ThreadInfoProxy tip = (ThreadInfoProxy)ti;
+ tip.resetFrames();
+ }
}
Map<String, List<CombinedFrameInfo>> result = new HashMap<String, List<CombinedFrameInfo>>();
@@ -242,6 +248,11 @@
for (ThreadInfo ti: snapshot.getThreads()) {
bw.write("Thread-" + ti.getId() + "\t" + df.format(Math.nanoToMilli(ti.getTotalTime())) + " ms");
bw.write(NEW_LINE);
+
+ if (ti instanceof ThreadInfoProxy) {
+ ThreadInfoProxy tip = (ThreadInfoProxy)ti;
+ tip.resetFrames();
+ }
}
bw.write(NEW_LINE);
@@ -312,6 +323,11 @@
}
bw.flush();
bw.close();
+
+ if (ti instanceof ThreadInfoProxy) {
+ ThreadInfoProxy tip = (ThreadInfoProxy)ti;
+ tip.resetFrames();
+ }
}
}
@@ -765,6 +781,11 @@
for (FrameInfo fi: ti.getFrames()) {
getCallerInformation(fi, data);
}
+
+ if (ti instanceof ThreadInfoProxy) {
+ ThreadInfoProxy tip = (ThreadInfoProxy)ti;
+ tip.resetFrames();
+ }
}
DecimalFormat df = new DecimalFormat("#0.00");
Modified: branches/JBossProfiler2/src/main/org/jboss/profiler/shared/SnapshotHelper.java
===================================================================
--- branches/JBossProfiler2/src/main/org/jboss/profiler/shared/SnapshotHelper.java 2008-10-29 11:36:23 UTC (rev 491)
+++ branches/JBossProfiler2/src/main/org/jboss/profiler/shared/SnapshotHelper.java 2008-10-29 14:15:55 UTC (rev 492)
@@ -167,26 +167,8 @@
if (entry.isDirectory()) {
File tf = new File(directory, entry.getName());
ThreadInfo ti = ThreadHelper.load(tf);
-
- boolean found = true;
- long counter = 0;
- while (found) {
- try {
- File f = new File(entry, Long.toString(counter));
- if (f.exists()) {
- FrameInfo fi = FrameHelper.load(f);
- ti.add(fi);
-
- counter += 1;
- } else {
- found = false;
- }
- } catch (Exception e) {
- found = false;
- }
- }
-
- threads.add(ti);
+ ThreadInfoProxy tip = new ThreadInfoProxy(entry, ti);
+ threads.add(tip);
}
}
Modified: branches/JBossProfiler2/src/main/org/jboss/profiler/shared/ThreadInfo.java
===================================================================
--- branches/JBossProfiler2/src/main/org/jboss/profiler/shared/ThreadInfo.java 2008-10-29 11:36:23 UTC (rev 491)
+++ branches/JBossProfiler2/src/main/org/jboss/profiler/shared/ThreadInfo.java 2008-10-29 14:15:55 UTC (rev 492)
@@ -50,7 +50,7 @@
private List<String> groups;
/** Frames */
- private LinkedList<FrameInfo> frames;
+ protected LinkedList<FrameInfo> frames;
/** The total time */
private transient long totalTime;
Added: branches/JBossProfiler2/src/main/org/jboss/profiler/shared/ThreadInfoProxy.java
===================================================================
--- branches/JBossProfiler2/src/main/org/jboss/profiler/shared/ThreadInfoProxy.java (rev 0)
+++ branches/JBossProfiler2/src/main/org/jboss/profiler/shared/ThreadInfoProxy.java 2008-10-29 14:15:55 UTC (rev 492)
@@ -0,0 +1,139 @@
+/*
+ * 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.File;
+import java.util.LinkedList;
+import java.util.List;
+
+/**
+ * Represents a thread and its frames - the frame for this class are lazy initialized
+ * @author Jesper Pedersen <jesper.pedersen at jboss.org>
+ */
+public class ThreadInfoProxy extends ThreadInfo {
+
+ /** Serial version UID */
+ static final long serialVersionUID = -4842008327790962286L;
+
+ /** Frame path */
+ private File framePath;
+
+ /** Initialized */
+ private boolean initialized;
+
+ /**
+ * Constructor
+ * @param fp The frame path
+ * @param ti The thread info
+ */
+ public ThreadInfoProxy(File fp, ThreadInfo ti) {
+ super(ti.getId(), ti.getName(), ti.getPriority(), ti.isDaemon(), ti.getGroups());
+
+ this.framePath = fp;
+ this.initialized = false;
+ }
+
+ /**
+ * Get the frames
+ * @return The frames
+ */
+ @Override
+ public List<FrameInfo> getFrames() {
+ if (!initialized) {
+ init();
+ }
+
+ return super.getFrames();
+ }
+
+ /**
+ * Add a frame to a thread
+ * @param f The frame
+ */
+ @Override
+ public void add(FrameInfo f) {
+ if (!initialized) {
+ init();
+ }
+
+ super.add(f);
+ }
+
+ /**
+ * Get the recent frame for a thread
+ * @return The frame
+ */
+ @Override
+ public FrameInfo getRecentFrame() {
+ if (!initialized) {
+ init();
+ }
+
+ return super.getRecentFrame();
+ }
+
+ /**
+ * Get the total time
+ * @return The total time
+ */
+ @Override
+ public long getTotalTime() {
+ if (!initialized) {
+ init();
+ }
+
+ return super.getTotalTime();
+ }
+
+ /**
+ * Reset the frame info
+ */
+ public void resetFrames() {
+ frames = new LinkedList<FrameInfo>();
+ initialized = false;
+ }
+
+ /**
+ * Init
+ */
+ private void init() {
+ boolean found = true;
+ long counter = 0;
+ while (found) {
+ try {
+ File f = new File(framePath, Long.toString(counter));
+ if (f.exists()) {
+ FrameInfo fi = FrameHelper.load(f);
+ super.add(fi);
+
+ counter += 1;
+ } else {
+ found = false;
+ }
+ } catch (Exception e) {
+ found = false;
+ }
+ }
+
+ initialized = true;
+ }
+}
More information about the jboss-cvs-commits
mailing list