generate_memory_usage_report/gcc_map_reader BUG? #721
handling "bss", "text", "data", "rodata"
This commit is contained in:
parent
24ed35ac9c
commit
892a423b60
Binary file not shown.
|
@ -16,7 +16,8 @@ import java.util.regex.Pattern;
|
|||
*/
|
||||
public class GccMapReader {
|
||||
private static final Pattern MULTI_LINE_PATTERN = Pattern.compile(".*0x(\\S*)(.*)");
|
||||
private static final Pattern SINGLE_LINE_PATTERN = Pattern.compile(".*\\.bss\\.(\\S*).*0x.*0x(\\S*)(.*)");
|
||||
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*)(.*)");
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
if (args.length != 1) {
|
||||
|
@ -34,7 +35,12 @@ public class GccMapReader {
|
|||
|
||||
debug("Got " + lines.size() + " lines");
|
||||
|
||||
List<Record> records = process(lines);
|
||||
for (String region : REGIONS)
|
||||
processAndPrint(lines, region);
|
||||
}
|
||||
|
||||
private static void processAndPrint(List<String> lines, String region) {
|
||||
List<Record> records = process(lines, region);
|
||||
|
||||
Collections.sort(records, Comparator.reverseOrder());
|
||||
|
||||
|
@ -44,15 +50,15 @@ public class GccMapReader {
|
|||
totalSize += record.size;
|
||||
}
|
||||
|
||||
System.out.println("Total size: " + totalSize);
|
||||
System.out.println(region + " Total size: " + totalSize);
|
||||
}
|
||||
|
||||
static List<Record> process(List<String> lines) {
|
||||
static List<Record> process(List<String> lines, String region) {
|
||||
|
||||
List<Record> result = new ArrayList<Record>();
|
||||
for (int i = 0; i < lines.size(); i++) {
|
||||
String line = lines.get(i);
|
||||
if (!line.contains(".bss."))
|
||||
if (!line.contains("." + region + "."))
|
||||
continue;
|
||||
debug("Got: " + line);
|
||||
|
||||
|
@ -61,13 +67,13 @@ public class GccMapReader {
|
|||
if (m1.matches()) {
|
||||
parseSingleLine(result, line, m1, i);
|
||||
} else {
|
||||
i = parseMultiLine(lines, result, i, line);
|
||||
i = parseMultiLine(lines, result, i, line, region);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static int parseMultiLine(List<String> lines, List<Record> result, int lineIndex, String line) {
|
||||
private static int parseMultiLine(List<String> lines, List<Record> result, int lineIndex, String line, String region) {
|
||||
debug("Multi-line " + line);
|
||||
String suffix = line;
|
||||
line = lines.get(++lineIndex);
|
||||
|
@ -101,16 +107,18 @@ public class GccMapReader {
|
|||
debug("Name " + name);
|
||||
debug("size " + size);
|
||||
|
||||
result.add(new Record(size, name));
|
||||
result.add(new Record(size, name, region));
|
||||
return lineIndex;
|
||||
}
|
||||
|
||||
private static void parseSingleLine(List<Record> result, String line, Matcher m1, int lineIndex) {
|
||||
debug("Single-line " + line);
|
||||
|
||||
String suffix = m1.group(1);
|
||||
String sizeString = m1.group(2);
|
||||
String prefix = m1.group(3);
|
||||
int i = 1;
|
||||
String region = m1.group(i++);
|
||||
String suffix = m1.group(i++);
|
||||
String sizeString = m1.group(i++);
|
||||
String prefix = m1.group(i++);
|
||||
|
||||
String name = prefix + "@" + suffix;
|
||||
|
||||
|
@ -124,7 +132,7 @@ public class GccMapReader {
|
|||
debug("Name " + name);
|
||||
debug("size " + size);
|
||||
|
||||
result.add(new Record(size, name));
|
||||
result.add(new Record(size, name, region));
|
||||
}
|
||||
|
||||
private static void debug(String s) {
|
||||
|
@ -134,10 +142,12 @@ public class GccMapReader {
|
|||
static class Record implements Comparable<Record> {
|
||||
private final int size;
|
||||
private final String name;
|
||||
private String region;
|
||||
|
||||
public Record(int size, String name) {
|
||||
public Record(int size, String name, String region) {
|
||||
this.size = size;
|
||||
this.name = name;
|
||||
this.region = region;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -153,6 +163,7 @@ public class GccMapReader {
|
|||
return "Record{" +
|
||||
"size=" + size +
|
||||
", name='" + name + '\'' +
|
||||
", region='" + region + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
|
@ -163,5 +174,9 @@ public class GccMapReader {
|
|||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getRegion() {
|
||||
return region;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,9 +10,11 @@ import static org.junit.Assert.assertEquals;
|
|||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
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"));
|
||||
List<GccMapReader.Record> r = GccMapReader.process(Collections.singletonList(" .bss.PWMD1 0x1fff9a0c 0x18 build_kinetis/obj/hal_pwm_lld.o"), BSS);
|
||||
assertNotNull(r);
|
||||
assertEquals(1, r.size());
|
||||
assertEquals(0x18, r.get(0).getSize());
|
||||
|
@ -22,7 +24,7 @@ public class GccMapReaderTest {
|
|||
public void testMultiLine() {
|
||||
List<GccMapReader.Record> r = GccMapReader.process(Arrays.asList(
|
||||
" .bss._ZL12turnOffEvent",
|
||||
"0x1fff9db8 0x60 build_kinetis/obj/aux_valves.o"));
|
||||
"0x1fff9db8 0x60 build_kinetis/obj/aux_valves.o"), BSS);
|
||||
assertNotNull(r);
|
||||
assertEquals(1, r.size());
|
||||
assertEquals(0x60, r.get(0).getSize());
|
||||
|
@ -33,7 +35,7 @@ public class GccMapReaderTest {
|
|||
List<GccMapReader.Record> r = GccMapReader.process(Arrays.asList(
|
||||
" .bss.ch_idle_thread_wa",
|
||||
" 0x1fff8d10 0x610 build_kinetis/obj/chsys.o",
|
||||
" 0x1fff8d10 ch_idle_thread_wa"));
|
||||
" 0x1fff8d10 ch_idle_thread_wa"), BSS);
|
||||
assertNotNull(r);
|
||||
assertEquals(1, r.size());
|
||||
assertEquals(0x610, r.get(0).getSize());
|
||||
|
@ -51,10 +53,33 @@ public class GccMapReaderTest {
|
|||
" 0x1fff8d10 0x610 build_kinetis/obj/chsys.o",
|
||||
" 0x1fff8d10 ch_idle_thread_wa",
|
||||
" .bss.ch 0x1fff9320 0x80 build_kinetis/obj/chschd.o",
|
||||
" 0x1fff9320 ch"));
|
||||
" 0x1fff9320 ch"), BSS);
|
||||
assertNotNull(r);
|
||||
assertEquals(2, r.size());
|
||||
assertEquals(0x610, r.get(0).getSize());
|
||||
assertEquals(0x80, r.get(1).getSize());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testData() {
|
||||
String[] strings = {" .text._dbg_check_suspend",
|
||||
" 0x00000000 0x1c build_kinetis/obj/chdebug.o",
|
||||
" .rodata._dbg_check_disable.str1.4",
|
||||
" 0x00000000 0x5 build_kinetis/obj/chdebug.o",
|
||||
" .rodata._dbg_check_suspend.str1.4",
|
||||
" 0x00000000 0x5 build_kinetis/obj/chdebug.o",
|
||||
" .text 0x00000000 0x0 build_kinetis/obj/chtrace.o",
|
||||
" .data 0x00000000 0x0 build_kinetis/obj/chtrace.o",
|
||||
" .bss.f 0x00000000 0x7 build_kinetis/obj/chtrace.o",
|
||||
" .comment 0x00000000 0x80 build_kinetis/obj/chtrace.o"};
|
||||
List<GccMapReader.Record> rodata = GccMapReader.process(Arrays.asList(strings), "rodata");
|
||||
assertNotNull(rodata);
|
||||
assertEquals(2, rodata.size());
|
||||
assertEquals(5, rodata.get(0).getSize());
|
||||
|
||||
List<GccMapReader.Record> bss = GccMapReader.process(Arrays.asList(strings), BSS);
|
||||
assertNotNull(bss);
|
||||
assertEquals(1, bss.size());
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue