diff --git a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/size/IDFSizeAnalysisEditor.java b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/size/IDFSizeAnalysisEditor.java index 9c2711063..95e522c57 100644 --- a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/size/IDFSizeAnalysisEditor.java +++ b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/size/IDFSizeAnalysisEditor.java @@ -49,6 +49,7 @@ protected void createPages() String osString = file.getLocation().toOSString(); Logger.log("Editor input:" + osString); //$NON-NLS-1$ + createNewOverviewPage(); createOverviewPage(); createDetailsPage(); } @@ -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() { diff --git a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/size/IDFSizeOverviewComposite2.java b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/size/IDFSizeOverviewComposite2.java new file mode 100644 index 000000000..98c67c932 --- /dev/null +++ b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/size/IDFSizeOverviewComposite2.java @@ -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 + * + */ +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; + } + +} diff --git a/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/size/size.json b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/size/size.json new file mode 100644 index 000000000..cc6002efd --- /dev/null +++ b/bundles/com.espressif.idf.ui/src/com/espressif/idf/ui/size/size.json @@ -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" + } + } +] + +} \ No newline at end of file