generate_memory_usage_report/gcc_map_reader BUG? #721

This commit is contained in:
rusefi 2019-03-31 16:36:57 -04:00
parent 56d026b8e2
commit 3bf616a63c
3 changed files with 30 additions and 19 deletions

Binary file not shown.

View File

@ -1,8 +1,9 @@
package rusefi;
import java.io.*;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.regex.Matcher;
@ -16,8 +17,9 @@ import java.util.regex.Pattern;
*/
public class GccMapReader {
private static final Pattern MULTI_LINE_PATTERN = Pattern.compile(".*0x(\\S*)(.*)");
private static final String REGIONS[] = {"bss", "text", "data", "rodata"};
private static final String[] REGIONS = {"bss", "text", "data", "rodata"};
private static final Pattern SINGLE_LINE_PATTERN = Pattern.compile(".*\\.(bss|text|data|rodata)\\.(\\S*).*0x.*0x(\\S*)(.*)");
static final String START_OF_DATA_TAG = "Linker script and memory map";
public static void main(String[] args) throws IOException {
if (args.length != 1) {
@ -42,7 +44,7 @@ public class GccMapReader {
private static void processAndPrint(List<String> lines, String region) {
List<Record> records = process(lines, region);
Collections.sort(records, Comparator.reverseOrder());
records.sort(Comparator.reverseOrder());
int totalSize = 0;
for (Record record : records) {
@ -55,9 +57,15 @@ public class GccMapReader {
static List<Record> process(List<String> lines, String region) {
List<Record> result = new ArrayList<Record>();
List<Record> result = new ArrayList<>();
boolean isUsefulData = false;
for (int i = 0; i < lines.size(); i++) {
String line = lines.get(i);
if (line.contains(START_OF_DATA_TAG)) {
isUsefulData = true;
}
if (!isUsefulData)
continue;
if (!line.contains("." + region + "."))
continue;
debug("Got: " + line);
@ -118,6 +126,7 @@ public class GccMapReader {
String region = m1.group(i++);
String suffix = m1.group(i++);
String sizeString = m1.group(i++);
//noinspection UnusedAssignment
String prefix = m1.group(i++);
String name = prefix + "@" + suffix;
@ -135,6 +144,7 @@ public class GccMapReader {
result.add(new Record(size, name, region));
}
@SuppressWarnings("unused")
private static void debug(String s) {
// System.out.println(s);
}
@ -144,7 +154,7 @@ public class GccMapReader {
private final String name;
private String region;
public Record(int size, String name, String region) {
Record(int size, String name, String region) {
this.size = size;
this.name = name;
this.region = region;
@ -167,16 +177,8 @@ public class GccMapReader {
'}';
}
public int getSize() {
int getSize() {
return size;
}
public String getName() {
return name;
}
public String getRegion() {
return region;
}
}
}

View File

@ -3,7 +3,6 @@ package rusefi;
import org.junit.Test;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static org.junit.Assert.assertEquals;
@ -13,8 +12,13 @@ public class GccMapReaderTest {
private static final String BSS = "bss";
@Test
public void testSingleLine() {
List<GccMapReader.Record> r = GccMapReader.process(Collections.singletonList(" .bss.PWMD1 0x1fff9a0c 0x18 build_kinetis/obj/hal_pwm_lld.o"), BSS);
public void testSimpleLinesWithTagInTheMiddle() {
List<GccMapReader.Record> r = GccMapReader.process(Arrays.asList(
" .bss.PWMD1 0x1fff9a0c 0x18 build_kinetis/obj/hal_pwm_lld.o",
GccMapReader.START_OF_DATA_TAG,
" .bss.PWMD2 0x1fff9a0c 0x18 build_kinetis/obj/hal_pwm_lld.o"
), BSS);
assertNotNull(r);
assertEquals(1, r.size());
assertEquals(0x18, r.get(0).getSize());
@ -23,6 +27,7 @@ public class GccMapReaderTest {
@Test
public void testMultiLine() {
List<GccMapReader.Record> r = GccMapReader.process(Arrays.asList(
GccMapReader.START_OF_DATA_TAG,
" .bss._ZL12turnOffEvent",
"0x1fff9db8 0x60 build_kinetis/obj/aux_valves.o"), BSS);
assertNotNull(r);
@ -33,6 +38,7 @@ public class GccMapReaderTest {
@Test
public void testThreeLine() {
List<GccMapReader.Record> r = GccMapReader.process(Arrays.asList(
GccMapReader.START_OF_DATA_TAG,
" .bss.ch_idle_thread_wa",
" 0x1fff8d10 0x610 build_kinetis/obj/chsys.o",
" 0x1fff8d10 ch_idle_thread_wa"), BSS);
@ -44,6 +50,7 @@ public class GccMapReaderTest {
@Test
public void testIssue() {
List<GccMapReader.Record> r = GccMapReader.process(Arrays.asList(
GccMapReader.START_OF_DATA_TAG,
".bss 0x1fff8d10 0xf2e4 load address 0x0002b1bc",
" 0x1fff8d10 . = ALIGN (0x4)",
" 0x1fff8d10 _bss_start = .",
@ -62,7 +69,9 @@ public class GccMapReaderTest {
@Test
public void testData() {
String[] strings = {" .text._dbg_check_suspend",
String[] strings = {
GccMapReader.START_OF_DATA_TAG,
" .text._dbg_check_suspend",
" 0x00000000 0x1c build_kinetis/obj/chdebug.o",
" .rodata._dbg_check_disable.str1.4",
" 0x00000000 0x5 build_kinetis/obj/chdebug.o",