- ๐ณ Directory Tree - Intuitive tree structure visualization
- ๐ Detailed Statistics - Separate code/comment/blank line counting
- ๐ Multi-language - Support for 50+ programming languages
- ๐ฐ COCOMO Estimation - Development cost, effort, and schedule estimation
- ๐ฅ Health Analysis - Comment ratio, large file warnings, etc.
- ๐ Top N Analysis - Ranking of largest and most complex files
- ๐จ Multiple Formats - Terminal/JSON/Markdown/HTML output
- ๐ Auto-save Reports - One-click multi-format report generation
- โ๏ธ Global Config - Customizable exclusion rules
- ๐ Zero Dependencies - Pure Python standard library implementation
# Clone the repository
git clone https://github.com/TbusOS/CodeMetrics.git
cd CodeMetrics
# One-click installation
./scripts/install.shThe installation script will automatically:
- โ Check Python version (requires >= 3.6)
- โ Set executable permissions
- โ
Create symbolic link to
~/.local/bin/codemetrics - โ Check and configure PATH
# Analyze embedded project (driver code)
codemetrics /path/to/driver -p embedded
# Analyze web project (medium complexity)
codemetrics /path/to/webapp -p semi-detached
# Analyze utility scripts (simple project)
codemetrics /path/to/scripts -p organicDefault output includes:
- ๐ Directory tree structure
- ๐ Language statistics table
- ๐ฐ COCOMO cost estimation
- ๐ฅ Code health analysis
- ๐ Top 10 largest files
| Option | Short | Description |
|---|---|---|
path |
- | Directory path to analyze (required) |
--project-type |
-p |
Required COCOMO project type: organic/semi-detached/embedded |
--top N |
-n N |
Number of top files to display (default: 10) |
--exclude |
-e |
Additional patterns to exclude (comma-separated) |
--no-color |
- | Disable colored output |
--no-save |
- | Don't save reports |
| Type | Description | Use Cases |
|---|---|---|
| organic | Simple projects | Small teams, familiar tech stack |
| semi-detached | Medium projects | Medium teams, mixed experience |
| embedded | Complex projects | Embedded systems, drivers, real-time systems, hardware-related |
codemetrics /path/to/project -p embedded# Automatically save JSON/Markdown/HTML reports
codemetrics /path/to/project -p embedded
# Reports saved in the output folder of the tool directorycodemetrics /path/to/project -p embedded -n 20codemetrics /path/to/project -p embedded -e "test/*,docs/*"CodeMetrics automatically generates reports in multiple formats:
- Colored tree structure
- Formatted statistics tables
- Real-time progress display
# Location: output/report_YYYYMMDD_HHMMSS.jsonSuitable for program parsing, CI/CD integration, data analysis
# Location: output/report_YYYYMMDD_HHMMSS.mdSuitable for documentation generation, GitHub/GitLab display
# Location: output/report_YYYYMMDD_HHMMSS.htmlSuitable for browser viewing, team sharing, presentation demos
System Programming: C, C++, Rust, Go, Assembly
Scripting Languages: Python, Ruby, Perl, Shell, Bash, Lua
Web Frontend: JavaScript, TypeScript, React JSX, React TSX, HTML, CSS, SCSS, Vue
JVM Languages: Java, Kotlin, Scala, Groovy
.NET Platform: C#, F#
Configuration: JSON, YAML, TOML, XML, INI
Documentation: Markdown, reStructuredText
Others: SQL, Dockerfile, Makefile, CMake
And 50+ more programming languages.
Global configuration file located in tool directory: config.json
{
"name": "CodeMetrics Global Configuration",
"exclude": {
"patterns": ["*.md", "*.json", "*.o", "*.ko"],
"dirs": [".git", "node_modules", "__pycache__", "build"]
},
"cocomo": {
"cost_per_month_usd": 5000,
"cost_per_month_cny": 30000
},
"health": {
"comment_ratio_min": 0.15,
"comment_ratio_max": 0.30,
"large_file_threshold": 800
}
}COCOMO (Constructive Cost Model) is a software cost estimation model proposed by Barry Boehm.
Person-Months (PM) = a ร (KLOC)^b
Duration (months) = c ร (PM)^d
Team Size = PM / Duration
| Type | a | b | c | d | Use Case |
|---|---|---|---|---|---|
| organic | 2.4 | 1.05 | 2.5 | 0.38 | Simple projects |
| semi-detached | 3.0 | 1.12 | 2.5 | 0.35 | Medium projects |
| embedded | 3.6 | 1.20 | 2.5 | 0.32 | Complex projects |
| Metric | Recommended Value | Description |
|---|---|---|
| Comment Ratio | 15-30% | Code maintainability |
| Average File Lines | 100-500 | Modularity level |
| Large Files (>800 lines) | 0 | Should be split |
| Low Comment Files (<5%) | 0 | Should add comments |
- ๐ Examples - Detailed usage scenarios and examples
- ๐ Design Document - Project architecture and design
- ๐ Contributing Guide - How to contribute
- ๐ Changelog - Version history and updates
- ๐ COCOMO Model - Cost estimation model details
- ๐ฑ Embedded Development - Linux kernel drivers, firmware development, real-time systems
- ๐ Web Development - React/Vue frontend, Node.js/Django/Flask backend
- ๐ง Utility Scripts - Shell scripts, Python automation tools, DevOps scripts
- ๐ Project Assessment - Code review, cost estimation, technical debt analysis
- ๐ Education & Research - Code metrics research, software engineering courses
Contributions are welcome! Please see CONTRIBUTING.md for details.
- ๐ Report bugs and issues
- ๐ก Suggest new features
- ๐ Improve documentation
- ๐ง Submit Pull Requests
- ๐ Add translations to other languages
A: No! CodeMetrics is implemented using pure Python standard library with zero dependencies.
A: Primarily targeted at Linux/macOS. Windows users need to use WSL or Git Bash.
A: Run ./scripts/uninstall.sh.
A: By default, saved in the <project_name>_output/ directory within the tool directory.
A: Yes! Edit the cocomo section in the config.json file.
MIT License - See LICENSE file for details.
Made with โค๏ธ for developers worldwide
โญ Star this project if you find it helpful!