Skip to content

Commit 2d0d62d

Browse files
authored
Merge pull request #19 from SWORDIntel/cursor/expand-telemetry-and-metrics-generation-composer-1-2b3f
Expand telemetry and metrics generation
2 parents b77b868 + 0625e94 commit 2d0d62d

20 files changed

+3281
-41
lines changed

clang/include/clang/Basic/CodeGenOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,9 @@ class CodeGenOptions : public CodeGenOptionsBase {
298298
/// file, for example with -save-temps.
299299
std::string MainFileName;
300300

301+
/// DSMIL telemetry instrumentation level: "off", "min", "normal", "debug", "trace"
302+
std::string DSMILTelemetryLevel = "normal";
303+
301304
/// The name for the split debug info file used for the DW_AT_[GNU_]dwo_name
302305
/// attribute in the skeleton CU.
303306
std::string SplitDwarfFile;

clang/include/clang/Options/Options.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3029,6 +3029,12 @@ def finstrument_function_entry_bare : Flag<["-"], "finstrument-function-entry-ba
30293029
Visibility<[ClangOption, CC1Option]>,
30303030
HelpText<"Instrument function entry only, after inlining, without arguments to the instrumentation call">,
30313031
MarshallingInfoFlag<CodeGenOpts<"InstrumentFunctionEntryBare">>;
3032+
def fdsmil_telemetry_level_EQ : Joined<["-"], "fdsmil-telemetry-level=">,
3033+
Group<f_Group>,
3034+
Visibility<[ClangOption, CC1Option]>,
3035+
HelpText<"Set DSMIL telemetry instrumentation level: off, min, normal, debug, trace">,
3036+
Values<"off,min,normal,debug,trace">,
3037+
MarshallingInfoString<CodeGenOpts<"DSMILTelemetryLevel">, "normal">;
30323038
def fcf_protection_EQ : Joined<["-"], "fcf-protection=">,
30333039
Visibility<[ClangOption, CLOption, CC1Option]>, Group<f_Group>,
30343040
HelpText<"Instrument control-flow architecture protection">, Values<"return,branch,full,none">;

dsmil/docs/DSLLVM-COMPLETE-BUILD-GUIDE.md

Lines changed: 209 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,62 @@ export DSMIL_OT_TELEMETRY=0 # Disable
119119

120120
---
121121

122+
### Telemetry Level Flag (v1.9)
123+
124+
**Flag**: `-fdsmil-telemetry-level=<level>`
125+
126+
**Description**: Controls telemetry instrumentation verbosity level.
127+
128+
**Levels**:
129+
- `off` - No telemetry instrumentation
130+
- `min` - Minimal telemetry (safety-critical only: OT events, errors, panics)
131+
- `normal` - Normal telemetry (entry probes for all annotated functions) - **default**
132+
- `debug` - Debug telemetry (entry + exit + elapsed time)
133+
- `trace` - Trace telemetry (all + probabilistic sampling)
134+
135+
**Usage**:
136+
```bash
137+
# Minimal telemetry (production)
138+
dsmil-clang -fdsmil-ot-telemetry \
139+
-fdsmil-telemetry-level=min \
140+
source.c -o source
141+
142+
# Normal telemetry (default)
143+
dsmil-clang -fdsmil-ot-telemetry \
144+
-fdsmil-telemetry-level=normal \
145+
source.c -o source
146+
147+
# Debug telemetry (development)
148+
dsmil-clang -fdsmil-ot-telemetry \
149+
-fdsmil-telemetry-level=debug \
150+
source.c -o source
151+
152+
# Trace telemetry (detailed analysis)
153+
dsmil-clang -fdsmil-ot-telemetry \
154+
-fdsmil-telemetry-level=trace \
155+
source.c -o source
156+
```
157+
158+
**Effects**:
159+
- Controls which events are instrumented
160+
- Affects entry/exit/timing instrumentation
161+
- Level gating at runtime
162+
163+
**Runtime Override**:
164+
```bash
165+
# Override level at runtime
166+
export DSMIL_TELEMETRY_LEVEL=debug
167+
./my_program
168+
169+
# Mission profile affects default level
170+
export DSMIL_MISSION_PROFILE=ics_prod # Forces min level minimum
171+
./my_program
172+
```
173+
174+
**Level Lattice**: `off < min < normal < debug < trace`
175+
176+
---
177+
122178
### Telecom Flags Flag
123179

124180
**Flag**: `-fdsmil-telecom-flags`
@@ -184,18 +240,69 @@ dsmil-clang++ -fsanitize=fuzzer \
184240

185241
**Flag**: `-mllvm -dsmil-ot-telemetry`
186242

187-
**Description**: Enable OT telemetry instrumentation pass.
243+
**Description**: Enable OT telemetry instrumentation pass. Instruments OT-critical functions, generic annotations (NET_IO, CRYPTO, PROCESS, FILE, UNTRUSTED, ERROR_HANDLER), and safety signals.
244+
245+
**Additional Flags**:
246+
- `-mllvm -dsmil-telemetry-level=<level>` - Set telemetry level (off, min, normal, debug, trace)
247+
- `-mllvm -dsmil-telemetry-manifest-path=<path>` - Custom manifest path
248+
- `-mllvm -dsmil-mission-profile=<profile>` - Mission profile name
188249

189250
**Usage**:
190251
```bash
191252
dsmil-clang -mllvm -dsmil-ot-telemetry source.c
192253
```
193254

255+
**Features**:
256+
- Entry/exit instrumentation (based on level)
257+
- Timing measurements (debug/trace levels)
258+
- Generic annotation support
259+
- Error handler detection with panic detection
260+
- Libc symbol heuristics
261+
194262
**Related Flags**:
195263
- `-mllvm -dsmil-telemetry-manifest-path=<path>` - Custom manifest path
196264

197265
---
198266

267+
### Telemetry Metrics Pass (v1.9)
268+
269+
**Flag**: `-mllvm -dsmil-metrics`
270+
271+
**Description**: Collects telemetry instrumentation metrics and generates JSON manifest with statistics.
272+
273+
**Additional Flags**:
274+
- `-mllvm -dsmil-metrics-output-dir=<dir>` - Output directory for metrics JSON files
275+
- `-mllvm -dsmil-mission-profile=<profile>` - Mission profile name
276+
277+
**Usage**:
278+
```bash
279+
dsmil-clang -mllvm -dsmil-metrics source.c
280+
```
281+
282+
**Output**:
283+
- Metrics manifest: `<module>.dsmil.metrics.json`
284+
- Contains: function counts, instrumentation coverage, category distribution, OT tier distribution, telecom statistics
285+
286+
**Example Output**:
287+
```json
288+
{
289+
"module_id": "network_daemon",
290+
"metrics": {
291+
"total_functions": 150,
292+
"instrumented_functions": 45,
293+
"instrumentation_coverage": 30.0,
294+
"net_io_count": 15,
295+
"crypto_count": 8,
296+
"authority_tiers": {
297+
"tier_0": 2,
298+
"tier_1": 8
299+
}
300+
}
301+
}
302+
```
303+
304+
---
305+
199306
### Telecom Pass
200307

201308
**Flag**: `-mllvm -dsmil-telecom-flags`
@@ -636,6 +743,20 @@ void dsmil_ot_telemetry_shutdown(void);
636743
int dsmil_ot_telemetry_is_enabled(void);
637744
```
638745
746+
#### Telemetry Level Management (v1.9)
747+
748+
```c
749+
dsmil_telemetry_level_t dsmil_telemetry_get_level(void);
750+
int dsmil_telemetry_level_allows(dsmil_telemetry_event_type_t event_type, const char *category);
751+
```
752+
753+
**Telemetry Levels**:
754+
- `DSMIL_TELEMETRY_LEVEL_OFF` (0) - No telemetry
755+
- `DSMIL_TELEMETRY_LEVEL_MIN` (1) - Minimal (safety-critical only)
756+
- `DSMIL_TELEMETRY_LEVEL_NORMAL` (2) - Normal (entry probes) - default
757+
- `DSMIL_TELEMETRY_LEVEL_DEBUG` (3) - Debug (entry + exit + timing)
758+
- `DSMIL_TELEMETRY_LEVEL_TRACE` (4) - Trace (all + sampling)
759+
639760
#### Event Logging
640761

641762
```c
@@ -651,6 +772,45 @@ void dsmil_telemetry_safety_signal_update(const dsmil_telemetry_event_t *ev);
651772
- `DSMIL_TELEMETRY_SES_REJECT` (5)
652773
- `DSMIL_TELEMETRY_INVARIANT_HIT` (6)
653774
- `DSMIL_TELEMETRY_INVARIANT_FAIL` (7)
775+
- `DSMIL_TELEMETRY_SS7_MSG_RX` (20)
776+
- `DSMIL_TELEMETRY_SS7_MSG_TX` (21)
777+
- `DSMIL_TELEMETRY_SIGTRAN_MSG_RX` (22)
778+
- `DSMIL_TELEMETRY_SIGTRAN_MSG_TX` (23)
779+
- `DSMIL_TELEMETRY_SIG_ANOMALY` (24)
780+
- `DSMIL_TELEMETRY_NET_IO` (30) - Network I/O
781+
- `DSMIL_TELEMETRY_CRYPTO` (31) - Cryptographic operation
782+
- `DSMIL_TELEMETRY_PROCESS` (32) - Process/system operation
783+
- `DSMIL_TELEMETRY_FILE` (33) - File I/O
784+
- `DSMIL_TELEMETRY_UNTRUSTED` (34) - Untrusted data
785+
- `DSMIL_TELEMETRY_ERROR` (35) - Error handler
786+
- `DSMIL_TELEMETRY_PANIC` (36) - Panic/fatal error
787+
788+
**Event Structure** (v1.9 extended):
789+
```c
790+
typedef struct {
791+
dsmil_telemetry_event_type_t event_type;
792+
const char *module_id;
793+
const char *func_id;
794+
const char *file;
795+
uint32_t line;
796+
uint8_t layer;
797+
uint8_t device;
798+
const char *stage;
799+
const char *mission_profile;
800+
uint8_t authority_tier;
801+
uint64_t build_id;
802+
uint64_t provenance_id;
803+
// ... safety signal fields ...
804+
// ... telecom fields ...
805+
// New fields (v1.9):
806+
const char *category; // Event category
807+
const char *op; // Operation name
808+
int32_t status_code; // Status/return code
809+
const char *resource; // Resource identifier
810+
const char *error_msg; // Error message
811+
uint64_t elapsed_ns; // Elapsed time (debug/trace)
812+
} dsmil_telemetry_event_t;
813+
```
654814

655815
---
656816

@@ -937,6 +1097,7 @@ CC = dsmil-clang
9371097
CXX = dsmil-clang++
9381098
CFLAGS = -fdsmil-mission-profile=ics_ops \
9391099
-fdsmil-ot-telemetry \
1100+
-fdsmil-telemetry-level=normal \
9401101
-O2
9411102
CXXFLAGS = $(CFLAGS)
9421103

@@ -1741,6 +1902,14 @@ void dsmil_fuzz_clear_events(void);
17411902
- `DSMIL_SES_GATE` - SES gate function
17421903
- `DSMIL_SAFETY_SIGNAL(name)` - Safety signal variable
17431904

1905+
### Generic Telemetry Annotations (v1.9)
1906+
- `DSMIL_NET_IO` - Network I/O operation
1907+
- `DSMIL_CRYPTO` - Cryptographic operation
1908+
- `DSMIL_PROCESS` - Process/system operation
1909+
- `DSMIL_FILE` - File I/O operation
1910+
- `DSMIL_UNTRUSTED` - Untrusted data handling
1911+
- `DSMIL_ERROR_HANDLER` - Error handler function
1912+
17441913
### Telecom
17451914
- `DSMIL_TELECOM_STACK(name)` - Telecom stack
17461915
- `DSMIL_SS7_ROLE(role)` - SS7 role
@@ -1793,7 +1962,8 @@ dsmil/runtime/
17931962

17941963
```
17951964
dsmil/lib/Passes/
1796-
├── DsmilTelemetryPass.cpp # OT telemetry pass
1965+
├── DsmilTelemetryPass.cpp # OT telemetry pass (v1.9: expanded)
1966+
├── DsmilMetricsPass.cpp # Telemetry metrics pass (v1.9: NEW)
17971967
├── DsmilTelecomPass.cpp # Telecom pass
17981968
├── DsmilFuzzCoveragePass.cpp # Coverage pass
17991969
├── DsmilFuzzMetricsPass.cpp # Metrics pass
@@ -1804,6 +1974,8 @@ dsmil/lib/Passes/
18041974

18051975
```
18061976
dsmil/tools/
1977+
├── dsmil-telemetry-summary/ # Telemetry summary tool (v1.9: NEW)
1978+
│ └── dsmil-telemetry-summary.cpp # Aggregates metrics from all modules
18071979
├── dsmil-gen-fuzz-harness/
18081980
│ └── dsmil-gen-fuzz-harness.cpp # Harness generator
18091981
└── ...
@@ -1844,6 +2016,41 @@ dsmil-clang -fdsmil-ot-telemetry \
18442016
source.c -o source
18452017
```
18462018

2019+
### With Telemetry Level Control
2020+
2021+
```bash
2022+
# Production: minimal telemetry
2023+
dsmil-clang -fdsmil-ot-telemetry \
2024+
-fdsmil-telemetry-level=min \
2025+
-fdsmil-mission-profile=ics_prod \
2026+
source.c -o source
2027+
2028+
# Development: debug telemetry with timing
2029+
dsmil-clang -fdsmil-ot-telemetry \
2030+
-fdsmil-telemetry-level=debug \
2031+
source.c -o source
2032+
2033+
# Analysis: trace telemetry with sampling
2034+
dsmil-clang -fdsmil-ot-telemetry \
2035+
-fdsmil-telemetry-level=trace \
2036+
source.c -o source
2037+
```
2038+
2039+
### With Metrics Collection
2040+
2041+
```bash
2042+
# Generate telemetry manifest and metrics
2043+
dsmil-clang -fdsmil-ot-telemetry \
2044+
-mllvm -dsmil-metrics \
2045+
-mllvm -dsmil-metrics-output-dir=./metrics \
2046+
source.c -o source
2047+
2048+
# Aggregate metrics from all modules
2049+
dsmil-telemetry-summary \
2050+
--input-glob "*.dsmil.metrics.json" \
2051+
--output dsmil.global.metrics.json
2052+
```
2053+
18472054
### With Telecom Flagging
18482055

18492056
```bash

0 commit comments

Comments
 (0)