disable tlog calls, add param gate to tlog client

- Comment out all tlog() calls in controlsd (100Hz) and carstate (100Hz)
  — was causing controlsd to lag from JSON serialization + ZMQ overhead
- tlog() now checks TelemetryEnabled memory param (1/sec file read),
  returns immediately when disabled — zero cost when telemetry is off

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-14 02:28:19 -05:00
parent 73472e5fab
commit 4756d8e32c
3 changed files with 35 additions and 63 deletions

View File

@@ -6,20 +6,39 @@ Usage from any process:
tlog("canbus", {"speed": 45.2, "speed_limit": 60})
Sends JSON packets over ZMQ PUSH to telemetryd, which diffs and writes CSV.
Only sends when TelemetryEnabled memory param is set — zero cost when disabled.
"""
import json
import os
import time
import zmq
TELEMETRY_SOCK = "ipc:///tmp/clearpilot_telemetry"
_PARAM_PATH = "/dev/shm/params/d/TelemetryEnabled"
_ctx = None
_sock = None
_last_check = 0
_enabled = False
def tlog(group: str, data: dict):
"""Log a telemetry packet. Only changed values will be written to CSV by telemetryd."""
global _ctx, _sock
global _ctx, _sock, _last_check, _enabled
# Check param at most once per second to avoid filesystem overhead
now = time.monotonic()
if now - _last_check > 1.0:
_last_check = now
try:
with open(_PARAM_PATH, 'r') as f:
_enabled = f.read().strip() == "1"
except (FileNotFoundError, IOError):
_enabled = False
if not _enabled:
return
if _sock is None:
_ctx = zmq.Context.instance()
_sock = _ctx.socket(zmq.PUSH)