Skip to content

Improve code quality, error handling, and UX#1

Merged
Aswinmcw merged 7 commits into
mainfrom
improve/code-quality-and-ux
May 25, 2026
Merged

Improve code quality, error handling, and UX#1
Aswinmcw merged 7 commits into
mainfrom
improve/code-quality-and-ux

Conversation

@Aswinmcw

Copy link
Copy Markdown
Member

Summary

This PR improves code quality, error handling, user experience, and test coverage across the ttperf codebase. All existing CLI flags and behaviours are preserved.

Changes

1. Dynamic version from package metadata

  • Removed the hardcoded "ttperf version 0.1.7" string from parse_args()
  • Version is now read at import time via importlib.metadata.version("ttperf") with a "dev" fallback, eliminating version drift between pyproject.toml and the source file

2. Better CSV error messages

  • get_device_kernel_duration() now prints all available column names when the expected DEVICE KERNEL DURATION [ns] column is missing, making it much easier to diagnose CSV format issues

3. File existence check after path extraction

  • extract_csv_path() now verifies the extracted CSV path exists on disk before returning it, with a clear error message if the file is absent

4. --verbose / -v flag and proper logging

  • Added import logging and a module-level logger = logging.getLogger(__name__)
  • --verbose sets logging.DEBUG; without it, only WARNING and above are shown
  • Internal diagnostic messages ("Warning: could not parse test file", subprocess debug info) moved to logger.debug() / logger.warning(); user-facing result output stays as print()
  • Note: the old -v shorthand for --version was removed (only --version triggers version output now) since -v is the conventional shorthand for verbose

5. --quiet / -q flag

  • Suppresses emoji and decorative output from set_test_configuration() and the auto-generated profile name line
  • Useful in CI pipelines that parse stdout

6. --output-dir flag

  • After profiling completes, copies the generated CSV to the specified directory
  • Directory is created with os.makedirs(exist_ok=True) if it does not exist

7. Config file support (~/.ttperf.yaml / ./.ttperf.yaml)

  • On startup, load_config_file() checks for a YAML config file (local directory first, then home directory)
  • Loaded values become argparse defaults; CLI flags always win
  • Uses PyYAML if available, falls back to configparser (ini-style) if not — no hard new dependency

8. README improvements

  • Version badge changed from hardcoded https://img.shields.io/badge/version-0.1.6-orange.svg to the dynamic PyPI badge https://img.shields.io/pypi/v/ttperf.svg
  • Added documentation for all new flags (--verbose, --quiet, --output-dir)
  • Added config file section with an example ~/.ttperf.yaml
  • Removed emoji from CLI output examples to reflect --quiet-mode output accurately
  • Updated project structure section to include tests/

9. Unit tests (tests/test_ttperf.py)

  • New test module covering: extract_csv_path, get_device_kernel_duration, parse_shape, validate_dtype, validate_layout, generate_profile_name, load_config_file, extract_test_config_and_status, and __version__
  • Uses unittest.mock to avoid requiring a real TT-Metal environment
  • Uses real temporary CSV files for I/O tests

10. CI workflow updates (.github/workflows/test.yml)

  • Installs package with pip install -e ".[dev]" to get pytest and pytest-cov
  • Runs pytest tests/ -v --cov=ttperf --cov-report=term-missing --cov-report=xml
  • Added pytest configuration and coverage settings to pyproject.toml

11. pyproject.toml additions

  • New optional extras: [dev] (pytest, pytest-cov) and [yaml] (PyYAML)
  • Added [tool.pytest.ini_options] and [tool.coverage.run] sections

What was intentionally NOT changed

  • Module split (splitting ttperf.py into cli.py, csv_parser.py, profiler.py): At ~460 lines the file is manageable and splitting would require updating imports across test files, the entry point, and any downstream consumers. Deferred to a dedicated refactor PR.
  • Existing CLI flags: All flags from the original interface (--debug, --shape, --dtype, --layout, --memory-config, --dram, --l1, --list-ops) continue to work unchanged.
  • pkg_resources removal: Kept as a fallback in load_operation_configs() since importlib.resources API changed between Python 3.8 and 3.9; the function tries the modern API first.

Test plan

  • pip install -e ".[dev]" succeeds
  • pytest tests/ -v passes all tests
  • ttperf --version outputs the version from pyproject.toml
  • ttperf --help shows the updated help text including new flags
  • ttperf --quiet add produces clean output without decorative prefixes
  • ttperf --verbose add shows debug log lines
  • ttperf add --output-dir /tmp/results copies CSV to /tmp/results/
  • Creating ~/.ttperf.yaml with dtype: float32 and running ttperf add picks up the default
  • GitHub Actions CI passes on all Python matrix versions

🤖 Generated with Claude Code

@Aswinmcw Aswinmcw merged commit d6ba4ea into main May 25, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant