Mercurial > hg > release > thermostat-1.0
changeset 398:146714814131
Istogram analysis
review-thread: http://icedtea.classpath.org/pipermail/thermostat/2012-June/001919.html
reviewed-by: rkennke
line wrap: on
line diff
--- a/client/core/src/main/java/com/redhat/thermostat/client/internal/osgi/ApplicationServiceProvider.java Tue Jun 19 19:33:50 2012 -0400 +++ b/client/core/src/main/java/com/redhat/thermostat/client/internal/osgi/ApplicationServiceProvider.java Wed Jun 20 13:31:58 2012 +0200 @@ -36,6 +36,7 @@ package com.redhat.thermostat.client.internal.osgi; +import com.redhat.thermostat.client.osgi.service.ApplicationCache; import com.redhat.thermostat.client.osgi.service.ApplicationService; import com.redhat.thermostat.common.appctx.ApplicationContext; import com.redhat.thermostat.common.dao.DAOFactory; @@ -43,10 +44,16 @@ public class ApplicationServiceProvider implements ApplicationService { + private ApplicationCache cache = new ApplicationCache(); + @Override public DAOFactory getDAOFactory() { // TODO: Eventually we will no longer need a singleton for ApplicationContext! return ApplicationContext.getInstance().getDAOFactory(); } + @Override + public ApplicationCache getApplicationCache() { + return cache; + } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/client/core/src/main/java/com/redhat/thermostat/client/osgi/service/ApplicationCache.java Wed Jun 20 13:31:58 2012 +0200 @@ -0,0 +1,55 @@ +/* + * Copyright 2012 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.client.osgi.service; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +public class ApplicationCache { + @SuppressWarnings("rawtypes") + private Map cache = new ConcurrentHashMap(); + + + @SuppressWarnings("unchecked") + public void addAttribute(Object key, Object value) { + cache.put(key, value); + } + + public Object getAttribute(Object key) { + return cache.get(key); + } +}
--- a/client/core/src/main/java/com/redhat/thermostat/client/osgi/service/ApplicationService.java Tue Jun 19 19:33:50 2012 -0400 +++ b/client/core/src/main/java/com/redhat/thermostat/client/osgi/service/ApplicationService.java Wed Jun 20 13:31:58 2012 +0200 @@ -41,4 +41,6 @@ public interface ApplicationService { DAOFactory getDAOFactory(); + + ApplicationCache getApplicationCache(); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/client/core/src/test/java/com/redhat/thermostat/client/internal/osgi/ApplicationServiceProviderTest.java Wed Jun 20 13:31:58 2012 +0200 @@ -0,0 +1,16 @@ +package com.redhat.thermostat.client.internal.osgi; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class ApplicationServiceProviderTest { + + @Test + public void testCache() { + ApplicationServiceProvider provider = new ApplicationServiceProvider(); + provider.getApplicationCache().addAttribute("test", "fluff"); + assertEquals("fluff", provider.getApplicationCache().getAttribute("test")); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/client/core/src/test/java/com/redhat/thermostat/client/osgi/service/ApplicationCacheTest.java Wed Jun 20 13:31:58 2012 +0200 @@ -0,0 +1,15 @@ +package com.redhat.thermostat.client.osgi.service; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class ApplicationCacheTest { + + @Test + public void verityCache() { + ApplicationCache cache = new ApplicationCache(); + cache.addAttribute("test", "fluff"); + assertEquals("fluff", cache.getAttribute("test")); + } +}
--- a/client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/HeapDump.java Tue Jun 19 19:33:50 2012 -0400 +++ b/client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/HeapDump.java Wed Jun 20 13:31:58 2012 +0200 @@ -43,6 +43,7 @@ public class HeapDump { private HeapInfo info; + private Histogram histogram; public String getName() { return info.getVm().getName(); @@ -60,4 +61,16 @@ public void setHeapInfo(HeapInfo info) { this.info = info; } + + void setHistogram(Histogram histogram) { + this.histogram = histogram; + } + + public Histogram getHistogram() { + return histogram; + } + + public HeapInfo getInfo() { + return info; + } }
--- a/client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/HeapDumpController.java Tue Jun 19 19:33:50 2012 -0400 +++ b/client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/HeapDumpController.java Wed Jun 20 13:31:58 2012 +0200 @@ -37,12 +37,19 @@ package com.redhat.thermostat.client.heap; import java.awt.Component; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + import javax.swing.JComponent; import java.text.DecimalFormat; import java.text.NumberFormat; +import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.StringTokenizer; import java.util.concurrent.TimeUnit; import com.redhat.thermostat.client.heap.HeapView.HeadDumperAction; @@ -65,6 +72,7 @@ import com.redhat.thermostat.common.model.VmMemoryStat.Generation; import com.redhat.thermostat.common.model.VmMemoryStat.Space; +import com.redhat.thermostat.common.utils.DescriptorConverter; import com.redhat.thermostat.common.utils.DisplayableValues.Scale; public class HeapDumpController implements VmInformationServiceController { @@ -136,12 +144,71 @@ break; case ANALYSE: + dump = (HeapDump) actionEvent.getPayload(); + readAndSetHistogram(dump); view.openDumpView(dump); break; } } }); } + + private String[] histogramHeader = { "Class", "Instances", "Size (in bytes)" }; + private void readAndSetHistogram(HeapDump dump) { + Histogram histogram = new Histogram(histogramHeader); + + HeapInfo info = dump.getInfo(); + InputStream stream = heapDAO.getHistogram(info); + + List<String[]> instances = new ArrayList<>(); + + if (stream != null) { + BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); + String line = null; + try { + + DecimalFormat formatter = new DecimalFormat("###,###.###"); + + boolean startParsing = false; + while ((line = reader.readLine()) != null) { + if (line.startsWith("-")) { + startParsing = true; + continue; + + } else if (line.startsWith("Total")) { + break; + } + + if (startParsing) { + + String[] data = new String[3]; + + StringTokenizer tokenizer = new StringTokenizer(line); + tokenizer.nextToken(); + long number = Long.parseLong(tokenizer.nextToken()); + String token = formatter.format(number); + data[1] = token; + + number = Long.parseLong(tokenizer.nextToken()); + token = formatter.format(number); + data[2] = token; + + token = DescriptorConverter.toJavaType(tokenizer.nextToken()); + data[0] = token; + + instances.add(data); + } + } + + + } catch (IOException e) { + e.printStackTrace(); + } + + histogram.setData(instances); + } + dump.setHistogram(histogram); + } @Override public Component getComponent() {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/Histogram.java Wed Jun 20 13:31:58 2012 +0200 @@ -0,0 +1,62 @@ +/* + * Copyright 2012 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.client.heap; + +import java.util.List; + +public class Histogram { + + private String[] header; + + private List<String[]> data; + + Histogram(String[] header) { + this.header = header; + } + + public String[] getHistogramColums() { + return header; + } + + void setData(List<String[]> data) { + this.data = data; + } + + public List<String[]> getData() { + return data; + } +}
--- a/client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/swing/HeapSwingView.java Tue Jun 19 19:33:50 2012 -0400 +++ b/client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/swing/HeapSwingView.java Wed Jun 20 13:31:58 2012 +0200 @@ -180,29 +180,10 @@ heapDetailPanel.divideView(); heapDetailPanel.setTop(overview); - String[] columnNames = {"First Name", - "Last Name", - "Sport", - "# of Years", - "Vegetarian"}; - Object[][] data = { - {"Kathy", "Smith", - "Snowboarding", new Integer(5), new Boolean(false)}, - {"John", "Doe", - "Rowing", new Integer(3), new Boolean(true)}, - {"Sue", "Black", - "Knitting", new Integer(2), new Boolean(false)}, - {"Jane", "White", - "Speed reading", new Integer(20), new Boolean(true)}, - {"Joe", "Brown", - "Pool", new Integer(10), new Boolean(false)} - }; - JTable table = new JTable(data, columnNames); - JPanel bottom = new JPanel(); - bottom.setLayout(new BoxLayout(bottom, BoxLayout.X_AXIS)); - bottom.add(table); - heapDetailPanel.setBottom(bottom); - + HistogramPanel histogram = new HistogramPanel(); + histogram.display(dump.getHistogram()); + heapDetailPanel.setBottom(histogram); + visiblePane.add(heapDetailPanel); visiblePane.revalidate();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/client/heapdumper/src/main/java/com/redhat/thermostat/client/heap/swing/HistogramPanel.java Wed Jun 20 13:31:58 2012 +0200 @@ -0,0 +1,106 @@ +/* + * Copyright 2012 Red Hat, Inc. + * + * This file is part of Thermostat. + * + * Thermostat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2, or (at your + * option) any later version. + * + * Thermostat 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Thermostat; see the file COPYING. If not see + * <http://www.gnu.org/licenses/>. + * + * Linking this code with other modules is making a combined work + * based on this code. Thus, the terms and conditions of the GNU + * General Public License cover the whole combination. + * + * As a special exception, the copyright holders of this code give + * you permission to link this code with independent modules to + * produce an executable, regardless of the license terms of these + * independent modules, and to copy and distribute the resulting + * executable under terms of your choice, provided that you also + * meet, for each linked independent module, the terms and conditions + * of the license of that module. An independent module is a module + * which is not derived from or based on this code. If you modify + * this code, you may extend this exception to your version of the + * library, but you are not obligated to do so. If you do not wish + * to do so, delete this exception statement from your version. + */ + +package com.redhat.thermostat.client.heap.swing; + +import javax.swing.JPanel; +import javax.swing.BoxLayout; +import javax.swing.JScrollPane; + +import com.redhat.thermostat.client.heap.Histogram; +import javax.swing.JTable; +import javax.swing.table.DefaultTableModel; + +public class HistogramPanel extends JPanel { + + private HeaderPanel headerPanel; + + public HistogramPanel() { + setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); + + headerPanel = new HeaderPanel("Classes Usage"); + add(headerPanel); + } + + public void display(Histogram histogram) { + JTable table = new JTable(new HistogramTableModel(histogram)); + table.setFillsViewportHeight(true); + + JScrollPane scrollPane = new JScrollPane(table); + headerPanel.setContent(scrollPane); + } + + private class HistogramTableModel extends DefaultTableModel { + + private Histogram histogram; + public HistogramTableModel(Histogram histogram) { + this.histogram = histogram; + } + + @Override + public String getColumnName(int column) { + if (histogram != null) { + return histogram.getHistogramColums()[column]; + } + return ""; + } + + @Override + public Object getValueAt(int row, int column) { + String result = null; + if (histogram != null) { + result = histogram.getData().get(row)[column]; + } + return result; + } + + @Override + public int getColumnCount() { + if (histogram != null) { + return histogram.getHistogramColums().length; + } + return 0; + } + + @Override + public int getRowCount() { + if (histogram != null) { + return histogram.getData().size(); + } + return 0; + } + } +}
--- a/common/core/src/main/java/com/redhat/thermostat/common/appctx/ApplicationContext.java Tue Jun 19 19:33:50 2012 -0400 +++ b/common/core/src/main/java/com/redhat/thermostat/common/appctx/ApplicationContext.java Wed Jun 20 13:31:58 2012 +0200 @@ -86,5 +86,4 @@ public void setViewFactory(ViewFactory viewFactory) { this.viewFactory = viewFactory; } - }
--- a/common/core/src/main/java/com/redhat/thermostat/common/dao/HeapDAOImpl.java Tue Jun 19 19:33:50 2012 -0400 +++ b/common/core/src/main/java/com/redhat/thermostat/common/dao/HeapDAOImpl.java Wed Jun 20 13:31:58 2012 +0200 @@ -67,9 +67,11 @@ String histogramId = "histogram-" + vm.getAgent().getStringID() + "-" + vm.getId() + "-" + heapInfo.getTimestamp(); if (heapDumpData != null) { chunk.put(heapDumpIdKey, heapDumpId); + heapInfo.setHeapDumpId(heapDumpId); } if (histogramData != null) { chunk.put(histogramIdKey, histogramId); + heapInfo.setHistogramId(histogramId); } storage.putChunk(chunk); if (heapDumpData != null) {