Skip to content

WIP: New size analysis representation #637

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ protected void createPages()
String osString = file.getLocation().toOSString();
Logger.log("Editor input:" + osString); //$NON-NLS-1$

createNewOverviewPage();
createOverviewPage();
createDetailsPage();
}
Expand Down Expand Up @@ -123,6 +124,20 @@ private void createOverviewPage()
int index = addPage(parent);
setPageText(index, "Overview"); //$NON-NLS-1$
}

/**
* Creates Size Analysis Overview Page
*/
private void createNewOverviewPage()
{
Composite parent = new Composite(getContainer(), SWT.NONE);
parent.setLayout(new FillLayout());

new IDFSizeOverviewComposite2().createPartControl(parent, file, getTarget());

int index = addPage(parent);
setPageText(index, "Size"); //$NON-NLS-1$
}

private String getTarget()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*******************************************************************************
* Copyright 2018-2020 Espressif Systems (Shanghai) PTE LTD. All rights reserved.
* Use is subject to license terms.
*******************************************************************************/
package com.espressif.idf.ui.size;

import java.io.File;
import java.io.FileReader;
import java.net.URL;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.URIUtil;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;

import com.espressif.idf.ui.UIPlugin;

/**
* @author Kondal Kolipaka <[email protected]>
*
*/
public class IDFSizeOverviewComposite2
{

public void createPartControl(Composite parent, IFile file, String targetName)
{
try
{
JSONObject loadJson = loadJson();
JSONArray layout = (JSONArray) loadJson.get("layout");
Object[] array = layout.toArray();
int x = 150;
int y = 20;
for (Object memory : array)
{
if (memory instanceof JSONObject)
{
JSONObject obj = (JSONObject) memory;
String name = (String) obj.get("name");
String total = (String) obj.get("total");

// step 1: Draw total
int convertToKB = convertToKB(Integer.valueOf(total));
final int localy = y;
parent.addListener(SWT.Paint, e -> {

e.gc.drawText(name, x - 100, localy + 35);
e.gc.setLineWidth(2);
e.gc.drawRectangle(x, localy, convertToKB, 70);

});

int totalDrawArea = 0;
// step 2: Draw parts
JSONObject parts = (JSONObject) obj.get("parts");
for (Object key : parts.keySet())
{
Object value = parts.get(key);
System.out.print(key.toString() + ":" + value.toString());

int partArea = convertToKB(Integer.valueOf(value.toString()));
final int localTotal = totalDrawArea;
parent.addListener(SWT.Paint, e -> {

e.gc.setLineWidth(1);
e.gc.drawRectangle(x, localy, partArea + localTotal, 70);
});

totalDrawArea = totalDrawArea + partArea;

}

y = y + 100;
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
}

protected int convertToKB(long value)
{
return Math.round(value / 1024);
}

private JSONObject loadJson() throws Exception
{
URL url = FileLocator.find(UIPlugin.getDefault().getBundle(),
new Path("/src/com/espressif/idf/ui/size/size.json"), null);
url = FileLocator.toFileURL(url);
File file = URIUtil.toFile(URIUtil.toURI(url));
JSONParser parser = new JSONParser();
FileReader reader = new FileReader(file);
try
{
return (JSONObject) parser.parse(reader);
}
catch (Exception e)
{
e.printStackTrace();
reader.close();
}
return null;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"version":"1.0",
"layout":
[
{
"name": "DRAM",
"total": "171728",
"parts": {
".bss": "11288",
".data": "45670",
"free": "114770"
}
},
{
"name": "IRAM",
"total": "131072",
"parts": {
".text": "45243",
".vectors": "1027",
"free": "84802"
}
},
{
"name": "RTC Fast RAM",
"total": "200040",
"parts": {
"data": "17444",
"code": "22220",
"free": "160376"
}
},
{
"name": "RTC Slow RAM",
"total": "290040",
"parts": {
"data": "17444",
"code": "22220",
"free": "160376"
}
},
{
"name": "Flash",
"total": "200040",
"parts": {
".text": "17444",
".rodata": "22220",
"free": "160376"
}
},
{
"name": "PSRAM",
"total": "100040",
"parts": {
"used": "50040",
"free": "50040"
}
}
]

}