Skip to content

Commit

Permalink
Add parse-trx as an installed script, needed to massage file_parser.p…
Browse files Browse the repository at this point in the history
…y's main function to do this
  • Loading branch information
julianneswinoga committed Sep 12, 2023
1 parent b5fc5ee commit e5b10dc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 24 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ In the repository source there are a couple example TraceX traces which can be u

### As a command line utility
[documentation](https://tracex-parser.readthedocs.io/en/latest/cli-interface.html)
The `file_parser` module can also be run as a script, which will provide simple statistics on the trace as well as dumping all the events in the trace:
The `file_parser` module can also be run as a script, which will provide simple statistics on the trace as well as dumping all the events in the trace.
It can be run by either:
- Running the module manually: `python3 -m tracex_parser.file_parser`
- Using the newly installed command: `parse-trx`

Both run methods are identical.
```console
$ python3 -m tracex_parser.file_parser -vvv ./demo_threadx.trx
$ parse-trx -vvv ./demo_threadx.trx
Parsing ./demo_threadx.trx
total events: 974
object registry size: 16
Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ include = [
'*.trx',
]

[tool.poetry.scripts]
parse-trx = "tracex_parser.file_parser:main"

[tool.poetry.dependencies]
python = "^3.6"

Expand Down
44 changes: 22 additions & 22 deletions tracex_parser/file_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,28 @@ def parse_tracex_buffer(filepath: str, custom_events_map: Optional[Dict[int, Tra


def main():
args = parser.parse_args()

from signal import signal, SIGPIPE, SIG_DFL
# Don't break when piping output
signal(SIGPIPE, SIG_DFL)

# set up colours
# Truth table for what we want.
# Precedence is: color, nocolor, tty
# tty | nocolor | color | output
# ==============================
# 0 | 0 | 0 | 0
# 0 | 0 | 1 | 1
# 0 | 1 | 0 | 1
# 0 | 1 | 1 | 1
# 1 | 0 | 0 | 1
# 1 | 0 | 1 | 1
# 1 | 1 | 0 | 0
# 1 | 1 | 1 | 1
have_colours = (sys.stdout.isatty() and not args.nocolor) or args.color
colour = TextColour(have_colours)

for input_filepath in args.input_trxs:
print(f'Parsing {input_filepath}')
tracex_events, obj_reg_map = parse_tracex_buffer(input_filepath)
Expand Down Expand Up @@ -218,26 +240,4 @@ def main():


if __name__ == '__main__':
args = parser.parse_args()

from signal import signal, SIGPIPE, SIG_DFL

# Don't break when piping output
signal(SIGPIPE, SIG_DFL)

# set up colours
# Truth table for what we want.
# Precedence is: color, nocolor, tty
# tty | nocolor | color | output
# ==============================
# 0 | 0 | 0 | 0
# 0 | 0 | 1 | 1
# 0 | 1 | 0 | 1
# 0 | 1 | 1 | 1
# 1 | 0 | 0 | 1
# 1 | 0 | 1 | 1
# 1 | 1 | 0 | 0
# 1 | 1 | 1 | 1
have_colours = (sys.stdout.isatty() and not args.nocolor) or args.color
colour = TextColour(have_colours)
main()

0 comments on commit e5b10dc

Please sign in to comment.