auto import from //branches/cupcake/...@137873
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright (C) 2009 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.hierarchyviewer.scene;
|
||||
|
||||
import com.android.ddmlib.Device;
|
||||
import com.android.hierarchyviewer.device.Window;
|
||||
import com.android.hierarchyviewer.device.DeviceBridge;
|
||||
|
||||
import java.net.Socket;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
public class ProfilesLoader {
|
||||
public static double[] loadProfiles(Device device, Window window, String params) {
|
||||
Socket socket = null;
|
||||
BufferedReader in = null;
|
||||
BufferedWriter out = null;
|
||||
|
||||
try {
|
||||
socket = new Socket();
|
||||
socket.connect(new InetSocketAddress("127.0.0.1",
|
||||
DeviceBridge.getDeviceLocalPort(device)));
|
||||
|
||||
out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
|
||||
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||
|
||||
out.write("PROFILE " + window.encode() + " " + params);
|
||||
out.newLine();
|
||||
out.flush();
|
||||
|
||||
String response = in.readLine();
|
||||
String[] data = response.split(" ");
|
||||
|
||||
double[] profiles = new double[data.length];
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
profiles[i] = (Long.parseLong(data[i]) / 1000.0) / 1000.0; // convert to ms
|
||||
}
|
||||
return profiles;
|
||||
} catch (IOException e) {
|
||||
// Empty
|
||||
} finally {
|
||||
try {
|
||||
if (out != null) {
|
||||
out.close();
|
||||
}
|
||||
if (in != null) {
|
||||
in.close();
|
||||
}
|
||||
if (socket != null) {
|
||||
socket.close();
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ import com.android.hierarchyviewer.scene.ViewHierarchyScene;
|
||||
import com.android.hierarchyviewer.scene.ViewManager;
|
||||
import com.android.hierarchyviewer.scene.ViewNode;
|
||||
import com.android.hierarchyviewer.scene.WindowsLoader;
|
||||
import com.android.hierarchyviewer.scene.ProfilesLoader;
|
||||
import com.android.hierarchyviewer.util.OS;
|
||||
import com.android.hierarchyviewer.util.WorkerThread;
|
||||
import com.android.hierarchyviewer.ui.action.ShowDevicesAction;
|
||||
@@ -43,6 +44,7 @@ import com.android.hierarchyviewer.ui.util.PngFileFilter;
|
||||
import com.android.hierarchyviewer.ui.util.IconLoader;
|
||||
import com.android.hierarchyviewer.ui.model.PropertiesTableModel;
|
||||
import com.android.hierarchyviewer.ui.model.ViewsTreeModel;
|
||||
import com.android.hierarchyviewer.ui.model.ProfilesTableModel;
|
||||
import org.jdesktop.swingworker.SwingWorker;
|
||||
import org.netbeans.api.visual.graph.layout.TreeGraphLayout;
|
||||
import org.netbeans.api.visual.model.ObjectSceneEvent;
|
||||
@@ -123,6 +125,7 @@ public class Workspace extends JFrame {
|
||||
private JSplitPane sideSplitter;
|
||||
private JSplitPane mainSplitter;
|
||||
private JTable propertiesTable;
|
||||
private JTable profilingTable;
|
||||
private JComponent pixelPerfectPanel;
|
||||
private JTree pixelPerfectTree;
|
||||
private ScreenViewer screenViewer;
|
||||
@@ -274,11 +277,32 @@ public class Workspace extends JFrame {
|
||||
JScrollPane tableScroller = new JScrollPane(propertiesTable);
|
||||
tableScroller.setBorder(null);
|
||||
|
||||
profilingTable = new JTable();
|
||||
profilingTable.setModel(new DefaultTableModel(new Object[][] {
|
||||
{ " " , " " }, { " " , " " }, { " " , " " } },
|
||||
new String[] { "Operation", "Duration (ms)" }));
|
||||
profilingTable.setBorder(null);
|
||||
profilingTable.getTableHeader().setBorder(null);
|
||||
|
||||
JScrollPane firstTableScroller = new JScrollPane(profilingTable);
|
||||
firstTableScroller.setBorder(null);
|
||||
|
||||
setVisibleRowCount(profilingTable, 5);
|
||||
firstTableScroller.setMinimumSize(profilingTable.getPreferredScrollableViewportSize());
|
||||
|
||||
JSplitPane tablesSplitter = new JSplitPane();
|
||||
tablesSplitter.setBorder(null);
|
||||
tablesSplitter.setOrientation(JSplitPane.VERTICAL_SPLIT);
|
||||
tablesSplitter.setResizeWeight(0);
|
||||
tablesSplitter.setLeftComponent(firstTableScroller);
|
||||
tablesSplitter.setBottomComponent(tableScroller);
|
||||
tablesSplitter.setContinuousLayout(true);
|
||||
|
||||
sideSplitter = new JSplitPane();
|
||||
sideSplitter.setBorder(null);
|
||||
sideSplitter.setOrientation(JSplitPane.VERTICAL_SPLIT);
|
||||
sideSplitter.setResizeWeight(0.5);
|
||||
sideSplitter.setLeftComponent(tableScroller);
|
||||
sideSplitter.setLeftComponent(tablesSplitter);
|
||||
sideSplitter.setBottomComponent(null);
|
||||
sideSplitter.setContinuousLayout(true);
|
||||
|
||||
@@ -603,6 +627,22 @@ public class Workspace extends JFrame {
|
||||
propertiesTable.setModel(new PropertiesTableModel(node));
|
||||
}
|
||||
|
||||
private void updateProfiles(double[] profiles) {
|
||||
profilingTable.setModel(new ProfilesTableModel(profiles));
|
||||
setVisibleRowCount(profilingTable, profiles.length + 1);
|
||||
}
|
||||
|
||||
public static void setVisibleRowCount(JTable table, int rows) {
|
||||
int height = 0;
|
||||
for (int row = 0; row < rows; row++) {
|
||||
height += table.getRowHeight(row);
|
||||
}
|
||||
|
||||
Dimension size = new Dimension(table.getPreferredScrollableViewportSize().width, height);
|
||||
table.setPreferredScrollableViewportSize(size);
|
||||
table.revalidate();
|
||||
}
|
||||
|
||||
private void showPixelPerfectTree() {
|
||||
if (pixelPerfectTree == null) {
|
||||
return;
|
||||
@@ -1134,22 +1174,24 @@ public class Workspace extends JFrame {
|
||||
}
|
||||
}
|
||||
|
||||
private class LoadGraphTask extends SwingWorker<ViewHierarchyScene, Void> {
|
||||
private class LoadGraphTask extends SwingWorker<double[], Void> {
|
||||
public LoadGraphTask() {
|
||||
beginTask();
|
||||
}
|
||||
|
||||
@Override
|
||||
@WorkerThread
|
||||
protected ViewHierarchyScene doInBackground() {
|
||||
protected double[] doInBackground() {
|
||||
scene = ViewHierarchyLoader.loadScene(currentDevice, currentWindow);
|
||||
return scene;
|
||||
return ProfilesLoader.loadProfiles(currentDevice, currentWindow,
|
||||
scene.getRoot().toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void done() {
|
||||
try {
|
||||
createGraph(get());
|
||||
createGraph(scene);
|
||||
updateProfiles(get());
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ExecutionException e) {
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (C) 2009 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.hierarchyviewer.ui.model;
|
||||
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import java.text.NumberFormat;
|
||||
|
||||
public class ProfilesTableModel extends DefaultTableModel {
|
||||
private static final String[] NAMES = { "measure", "layout", "draw" };
|
||||
|
||||
private final double[] profiles;
|
||||
private final NumberFormat formatter;
|
||||
|
||||
public ProfilesTableModel(double[] profiles) {
|
||||
this.profiles = profiles;
|
||||
formatter = NumberFormat.getNumberInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRowCount() {
|
||||
return profiles == null ? 0 : profiles.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getValueAt(int row, int column) {
|
||||
if (profiles == null) return "";
|
||||
|
||||
if (column == 0) {
|
||||
return NAMES[row];
|
||||
}
|
||||
|
||||
|
||||
return formatter.format(profiles[row]) + "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumnCount() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getColumnName(int column) {
|
||||
return column == 0 ? "Operation" : "Duration (ms)";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCellEditable(int arg0, int arg1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setValueAt(Object arg0, int arg1, int arg2) {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user