Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: haukepetersen/cosy
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: RIOT-OS/cosy
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 17 commits
  • 3 files changed
  • 7 contributors

Commits on Jun 11, 2022

  1. cosy: allow to specify port

    benpicco committed Jun 11, 2022

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    2e9ab56 View commit details

Commits on Jul 8, 2022

  1. Copy the full SHA
    679e72a View commit details

Commits on Dec 2, 2024

  1. Copy the full SHA
    72299ae View commit details
  2. Merge pull request #1 from RIOT-OS/fork-clarity

    README: Clarify that we do intend to keep developing here
    maribu authored Dec 2, 2024
    Copy the full SHA
    eb76924 View commit details
  3. Merge pull request #4 from benpicco/cosy_port

    cosy: allow to specify port
    maribu authored Dec 2, 2024
    Copy the full SHA
    2d07aca View commit details
  4. Merge pull request #3 from OlegHahm/pr/regex_fix

    adapt regex to fit current nm output
    maribu authored Dec 2, 2024
    Copy the full SHA
    b95e058 View commit details

Commits on Dec 6, 2024

  1. Transform regex string pattern into raw string

    This fix invalid escape sequence warnings.
    bastien-buil committed Dec 6, 2024
    Copy the full SHA
    c896499 View commit details
  2. Merge pull request #5 from TinyPART/FixWarningsFromEscapes

    Fix warnings from invalid escapes
    chrysn authored Dec 6, 2024
    Copy the full SHA
    a19b2a2 View commit details
  3. parse_elffile: fix riot_base

    Jana Eisoldt authored and chrysn committed Dec 6, 2024
    Copy the full SHA
    cad085a View commit details
  4. Copy the full SHA
    c36d69a View commit details

Commits on Dec 10, 2024

  1. Merge pull request #7 from chrysn-pull-requests/remaining-patches

    Patches from RIOT
    chrysn authored Dec 10, 2024
    Copy the full SHA
    38c54c3 View commit details
  2. Copy the full SHA
    94c65fa View commit details

Commits on Dec 13, 2024

  1. Copy the full SHA
    5893a5d View commit details
  2. Merge pull request #2 from chrysn-pull-requests/demangle

    Add demangle support using external `rustfilt` tool
    chrysn authored Dec 13, 2024
    Copy the full SHA
    1bdcea7 View commit details

Commits on Jan 22, 2025

  1. Merge pull request #8 from chrysn-pull-requests/canonical-uri

    README: Point to canonical URI to make issue references resolvable
    mguetschow authored Jan 22, 2025
    Copy the full SHA
    8ce1a40 View commit details

Commits on Jan 31, 2025

  1. Add an app category in Cozy

    The app category is for any files that are inside the directory of the current RIOT application
    bastien-buil committed Jan 31, 2025
    Copy the full SHA
    055e436 View commit details
  2. Merge pull request #6 from TinyPART/addAppCategory

    Add an app category in Cozy
    mguetschow authored Jan 31, 2025
    Copy the full SHA
    087fb2d View commit details
Showing with 68 additions and 23 deletions.
  1. +12 −0 README.md
  2. +55 −23 cosy.py
  3. +1 −0 root/sunburst.js
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# cosy

Python tool analyzing memory usage and distribution in .elf files

The project was originally developed [by Hauke Petersen](https://github.com/haukepetersen/cosy);
the [RIOT project](https://riot-os.org/) is maintaining this fork to continue development.

## Repository history

The canonical URI of this project is <https://github.com/RIOT-OS/cosy/>;
all recent mentions of issue numbers and pull requests refer to numbers in that repository.
Issues and PRs mentioned before 2024 refer to numbers in <https://github.com/haukepetersen/cosy>.
<!-- We would not have to do that if we used custom merge messages with full URIs
as enabled through the output of https://github.com/orgs/community/discussions/5955 --
but it is not in GitHub's interest to implement that. -->
78 changes: 55 additions & 23 deletions cosy.py
Original file line number Diff line number Diff line change
@@ -17,9 +17,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import sys
from os import path
from os import path, environ
from pathlib import Path
import argparse
import itertools
import re
import subprocess
import copy
@@ -28,7 +29,6 @@
import frontend_server

ROOT = path.join(Path(path.abspath(__file__)).parent, "root")
PORT = 12345


def add_sym(target, sym):
@@ -154,30 +154,31 @@ def parse_elffile(elffile, prefix, appdir, riot_base=None):
rbase = ["riotbuild/riotproject"]
if riot_base:
rbase.append(riot_base.strip("/"))
else:
rbase.append("RIOT")
rbase.append("riotbuild/riotbase")

rbase.append("RIOT")
rbase.append("riotbuild/riotbase")
if "BUILD_DIR" in environ:
rbase.append(environ["BUILD_DIR"])
riot_base = "|".join([f'{p}/build|{p}' for p in rbase])

c = re.compile(r"(?P<addr>[0-9a-f]+) "
r"(?P<type>[tbdTDB]) "
r"(?P<sym>[0-9a-zA-Z_$.]+)\s+"
r"(.+/)?"
r"(.*/)?"
r"("
r"{appdir}|"
r"{riot_base}|"
r".cargo/registry/src/[^/]+|"
r".cargo/git/checkouts|"
r"/rustc/[0-9a-f]+/?/library|"
r"ip-over-ble_experiments|" # HACK...
r"{appdir}/.*bin/pkg"
r"RIOT/app/.*bin/pkg"
r")/"
r"(?P<path>.+)/"
r"(?P<file>[0-9a-zA-Z_-]+\.(c|h|rs)):"
r"(?P<line>\d+)$".format(riot_base=riot_base,
appdir=appdir))
r"(?P<line>\d+)$".format(riot_base=riot_base))
for line in dump.splitlines():
m = c.match(line.decode("utf-8"))
line = line.decode("utf-8").replace(appdir, "RIOT/app")
m = c.match(line)
if m:
d = {'arcv': '', 'obj': '', 'size': -1, 'alias': []}
d.update(m.groupdict())
@@ -196,28 +197,28 @@ def parse_mapfile(mapfile):
with open(mapfile, 'r') as f:
for line in f:

if re.match("^\.text", line):
if re.match(r"^\.text", line):
cur_type = 't'
continue

if re.match("^\.(bss|stack)", line):
if re.match(r"^\.(bss|stack)", line):
cur_type = 'b'
continue

if re.match("^\.(relocate|data)", line):
if re.match(r"^\.(relocate|data)", line):
cur_type = 'd'
continue

# if re.match("^\..+", line):
if re.match("^OUTPUT.+", line):
# if re.match(r"^\..+", line):
if re.match(r"^OUTPUT.+", line):
add_sym(res, cur_sym)
cur_type = ''
# continue
break

if cur_type:
# fill bytes?
m = re.match("^ *\*fill\* +0x([0-9a-f]+) +0x([0-9a-f])+", line)
m = re.match(r"^ *\*fill\* +0x([0-9a-f]+) +0x([0-9a-f])+", line)
if m:
add_sym(res, cur_sym)
cur_sym = {
@@ -235,7 +236,7 @@ def parse_mapfile(mapfile):
continue

# start of a new symbol
m = re.match(" \.([a-z]+\.)?([-_\.A-Za-z0-9$.]+)", line)
m = re.match(r" \.([a-z]+\.)?([-_\.A-Za-z0-9$.]+)", line)
if m:
# save last symbol
add_sym(res, cur_sym)
@@ -254,22 +255,22 @@ def parse_mapfile(mapfile):
}

# get size, addr and path of current symbol
m = re.match(".+0x([0-9a-f]+) +0x([0-9a-f]+) (/.+)$", line)
m = re.match(r".+0x([0-9a-f]+) +0x([0-9a-f]+) (/.+)$", line)
if m:
cur_sym['addr'] = int(m.group(1), 16)
cur_sym['size'] = int(m.group(2), 16)
# get object and archive files
me = re.match(".+/([-_a-zA-Z0-9]+\.a)\(([-_a-zA-Z0-9]+\.o)\)$", m.group(3))
me = re.match(r".+/([-_a-zA-Z0-9]+\.a)\(([-_a-zA-Z0-9]+\.o)\)$", m.group(3))
if me:
cur_sym['arcv'] = me.group(1)
cur_sym['obj'] = me.group(2)
me = re.match(".+/([-_a-zA-Z0-9]+\.o)$", m.group(3))
me = re.match(r".+/([-_a-zA-Z0-9]+\.o)$", m.group(3))
if me:
cur_sym['arcv'] = ''
cur_sym['obj'] = me.group(1)
continue

m = re.match(" +0x[0-9a-f]+ +([-_a-zA-Z0-9]+)$", line)
m = re.match(r" +0x[0-9a-f]+ +([-_a-zA-Z0-9]+)$", line)
if m:
cur_sym['alias'].append(m.group(1))
return res
@@ -338,6 +339,32 @@ def check_completeness(symbols):
print("Your output will be incomplete!")


def demangle(symtable):
"""Replace the alias entries with more readable names for the same symbol in-place
This is done by passing the collected symbol names through the ``rustfilt``
program if it is present, and returning without any actions otherwise.
"""

all_symbols = list(itertools.chain(*([s['sym']] + s['alias'] for s in symtable)))
assert not any("\n" in s for s in all_symbols)
symbol_count = len(all_symbols)
all_symbols = "\n".join(all_symbols)

try:
filtered_symbols = subprocess.check_output(['rustfilt'], input=all_symbols.encode('utf8'))
except FileNotFoundError:
print("Warning: No `rustfilt` program found, symbols will not be demangled", file=sys.stderr)
return

filtered_symbols = filtered_symbols.decode('utf8').split("\n")
assert len(filtered_symbols) == symbol_count, "%d != %d" % (len(filtered_symbols), symbol_count)

filtered_symbols = iter(filtered_symbols)
for s in symtable:
s['sym'] = next(filtered_symbols)
s['alias'] = [next(filtered_symbols) for _ in s['alias']]

if __name__ == "__main__":
# Define some command line args
p = argparse.ArgumentParser()
@@ -352,6 +379,7 @@ def check_completeness(symbols):
p.add_argument("-c", type=argparse.FileType('w'),
help="Write module sizes to cvs file")
p.add_argument("-d", action="store_true", help="Don't run as web server")
p.add_argument("--port", default="12345", help="Webserver port", type=int)
args = p.parse_args()

# extract path to elf and map file
@@ -382,6 +410,10 @@ def check_completeness(symbols):
# check if the path for all symbols is set
check_completeness(symtable)

# clean up names by running them through rustfilt (if it exists); may later
# be extended to run c++filt as well
demangle(symtable)

# dump symbols to STDIO if verbose option is set
if args.v or args.m:
dump_modules(symtable)
@@ -407,4 +439,4 @@ def check_completeness(symbols):
print(subprocess.check_output((args.p + 'size', elffile)).decode("utf-8"))

if not args.d:
frontend_server.run(ROOT, PORT, 'index.html')
frontend_server.run(ROOT, args.port, 'index.html')
1 change: 1 addition & 0 deletions root/sunburst.js
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@ var b = {

// Mapping of step names to colors.
var colors = {
"app": "#d98b8f",
"core": "#a173d1",
"cpu": "#7b615c",
"boards": "#de783b",