feat(cpp,gui): C++ Analytics Engine + live GUI Analytics app

Kernel (C++17 freestanding):
  - New Analytics Engine (kernel/cpp/cpp_analytics.cpp): templated rolling
    time-series (TimeSeries<N>) sampling four live channels -- CPU load %,
    memory %, kernel-heap %, network pkt/interval -- with windowed statistics
    (min/max/mean/stddev) computed in pure integer math (kernel is -mno-sse, so
    no FP; stddev uses a Newton integer isqrt). Demonstrates virtual dispatch
    via an Observer pattern (IAnalyticsObserver + a ThresholdAlarmObserver that
    counts breaches) and RAII singletons.
  - Extended cpp_containers.hpp with Optional<T>, Pair<A,B>, and the kmin/kmax/
    kclamp/kswap algorithms.
  - Full C fallback (cpp_fallback.c) so the engine is functionally identical on
    aarch64/armv8i, which don't build the .cpp path.
  - Wired cpp_analytics_init() into boot [8/14]; seeds a few samples so graphs
    are populated immediately.

GUI:
  - New "Analytics" desktop app (gui/gui_apps.c): a 2x2 grid of live line-charts
    backed by the C++ engine, each with gridlines, a soft baseline fill, and
    min/avg/max(/stddev) overlays; click a panel to focus one channel full-size,
    click again to return. Throttled to ~2 Hz sampling off the compositor's
    repaint cadence. Registered on the desktop and in the start menu.

Userland: new `cppstat [samples]` applet dumps the engine's per-channel stats
and Observer breach counters.

Verified in QEMU (x86_64): boots clean on x86_64/aarch64/armv8i; `cppstat`
prints live stats (CPU 6%, Mem 7%, Heap 22%, computed min/avg/max/stddev,
Observer breaches); the GUI Analytics window renders all four graphs with the
Kernel Heap curve visibly climbing 22->55% as windows open, compositor steady
at ~53 FPS.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Fh5z6V7nGPbHvqVG5p4CXX
This commit is contained in:
subhobhai943andClaude Opus 4.8 committed 2026-08-26 10:42:48 +05:30
1 parent cd840d5799
commit 5bd18c4733
9 files changed
+762 -2

No files matched your search

+52
View File
@@ -0,0 +1,52 @@
#ifndef _KERNEL_CPP_ANALYTICS_H
#define _KERNEL_CPP_ANALYTICS_H
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
// The C++ analytics engine keeps a rolling time-series per channel and computes
// online statistics (min/max/mean/variance via Welford) over it. Channels are:
// 0 = CPU load % 1 = Memory used %
// 2 = Kernel heap % 3 = Network packets/interval
#define CPP_ANALYTICS_CHANNELS 4
#define CPP_ANALYTICS_HISTORY 64
// Bring up the engine (registers channels + an example observer). Idempotent.
void cpp_analytics_init(void);
// Pull one live sample from the kernel (metrics/pmm/heap/NIC) into every
// channel. Call this periodically (the GUI Analytics app and the `cppstat`
// applet both drive it). Returns the total number of samples taken so far.
uint64_t cpp_analytics_sample(void);
// Copy up to `max` most-recent values of a channel into `out` (oldest first,
// newest last). Returns the number written.
int cpp_analytics_get_series(int channel, uint32_t* out, int max);
// Fetch the online statistics for a channel. Any out pointer may be NULL.
void cpp_analytics_get_stats(int channel, uint32_t* out_min, uint32_t* out_max,
uint32_t* out_avg, uint32_t* out_last,
uint32_t* out_stddev);
// Human-readable channel name / unit suffix and the current scale ceiling used
// for graphing (e.g. 100 for a percentage channel).
const char* cpp_analytics_channel_name(int channel);
const char* cpp_analytics_channel_unit(int channel);
uint32_t cpp_analytics_channel_scale(int channel);
int cpp_analytics_channel_count(void);
uint64_t cpp_analytics_sample_count(void);
// Print a textual dashboard (used by the `cppstat` lazybox applet).
void cpp_analytics_dump(void);
#ifdef __cplusplus
}
#endif
#endif // _KERNEL_CPP_ANALYTICS_H