jwalsh / jwalsh/2048-cli-debug
Add DTrace support for runtime analysis
- Dominant language
- Python
- Stars
- 0
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
## Feature Request: DTrace Integration
### Description
Add DTrace probes and scripts to enable runtime analysis of the 2048 game, similar to the LLDB debugging infrastructure but for dynamic tracing.
### Motivation
DTrace would enable:
- Real-time performance analysis without stopping the program
- Statistical profiling of game operations
- Memory allocation tracking
- Function call frequency analysis
### Proposed Implementation
1. **Add USDT Probes** to key functions:
```c
// In engine.c
#ifdef HAVE_DTRACE
#include "2048_probes.h"
#endif
void engine_move(struct gamestate *g, int direction) {
DTRACE_PROBE2(game2048, move_start, g, direction);
// ... existing code ...
DTRACE_PROBE3(game2048, move_end, g, direction, result);
}
```
2. **Create D scripts** for common analysis:
```d
/* track-moves.d */
game2048:::move-start {
@moves[arg1] = count();
@directions[arg1] = quantize();
}
```
3. **Memory tracking**:
```d
/* memory-usage.d */
pid$target::malloc:entry {
@bytes = sum(arg0);
}
```
### Reference
- [DTrace Type and Operator Expressions](https://illumos.org/books/dtrace/chp-typeopexpr.html#chp-typeopexpr)
- [USDT Probes](https://illumos.org/books/dtrace/chp-usdt.html)
### Tasks
- [ ] Add DTrace probe definitions
- [ ] Create probe header generation
- [ ] Write D scripts for game analysis
- [ ] Add Makefile support for DTrace
- [ ] Document DTrace usage
- [ ] Test on illumos/SmartOS/macOS
### Benefits
- Zero overhead when probes disabled
- Production-safe analysis
- Rich aggregation capabilities
- Cross-platform (illumos, macOS, FreeBSD)
Contributor guide
Assessment
This issue has not been assessed yet.