#include <stdint.h>#include <stdbool.h>Go to the source code of this file.
Data Structures | |
| struct | CKMetric |
| struct | CKMetricsContext |
Macros | |
| #define | CK_METRICS_BUFFER_SIZE 4096 |
| #define | CK_METRICS_MAX_METRICS 32 |
| #define | CK_METRICS_MAX_NAME_LEN 64 |
| #define | CK_METRICS_MAX_URL_LEN 256 |
Enumerations | |
| enum | CKMetricsMode { CK_METRICS_MODE_HTTP , CK_METRICS_MODE_FILE , CK_METRICS_MODE_STDOUT , CK_METRICS_MODE_DISABLED } |
| enum | CKMetricType { CK_METRIC_FLOAT , CK_METRIC_INT , CK_METRIC_STRING } |
Functions | |
| void | ck_metrics_cleanup (void) |
| CKMetricsContext * | ck_metrics_create_context (void) |
| void | ck_metrics_ctx_end (CKMetricsContext *ctx, const char *status) |
| bool | ck_metrics_ctx_init (CKMetricsContext *ctx, const char *run_id, const char *endpoint, CKMetricsMode mode) |
| void | ck_metrics_ctx_log_f (CKMetricsContext *ctx, const char *name, double value) |
| void | ck_metrics_ctx_log_i (CKMetricsContext *ctx, const char *name, int64_t value) |
| void | ck_metrics_ctx_step (CKMetricsContext *ctx, int64_t step) |
| void | ck_metrics_destroy_context (CKMetricsContext *ctx) |
| void | ck_metrics_end (const char *status) |
| void | ck_metrics_generate_run_id (char *buffer, size_t size) |
| int64_t | ck_metrics_get_memory_mb (void) |
| bool | ck_metrics_init (const char *run_id, const char *endpoint, CKMetricsMode mode) |
| bool | ck_metrics_init_full (const char *run_id, const char *endpoint, CKMetricsMode mode, const char *model, const char *dataset, int batch_size, double lr, int max_steps) |
| void | ck_metrics_log_f (const char *name, double value) |
| void | ck_metrics_log_i (const char *name, int64_t value) |
| void | ck_metrics_log_s (const char *name, const char *value) |
| void | ck_metrics_step (int64_t step) |
| double | ck_metrics_timestamp (void) |
Variables | |
| CKMetricsContext * | ck_metrics_ctx |
| #define CK_METRICS_BUFFER_SIZE 4096 |
Definition at line 44 of file ck_metrics.h.
| #define CK_METRICS_MAX_METRICS 32 |
Definition at line 42 of file ck_metrics.h.
| #define CK_METRICS_MAX_NAME_LEN 64 |
ck_metrics.h - C-Kernel Engine Training Metrics API
Lightweight metrics logging for real-time training dashboards. Sends metrics to the ANTSAND live training dashboard via HTTP POST or writes to a local file for batch upload.
Usage: ck_metrics_init("run_001", "http://localhost/labs/metrics/log");
for (int step = 0; step < max_steps; step++) { // ... training step ... ck_metrics_log_f("loss", loss); ck_metrics_log_f("lr", lr); ck_metrics_log_f("grad_norm", grad_norm); ck_metrics_log_i("tokens_per_sec", tokens_per_sec); ck_metrics_log_i("memory_mb", get_memory_usage_mb()); ck_metrics_step(step); // Flush metrics for this step }
ck_metrics_end("completed");
Build: Link with -lcurl for HTTP mode, or use file mode for no dependencies.
Definition at line 41 of file ck_metrics.h.
| #define CK_METRICS_MAX_URL_LEN 256 |
Definition at line 43 of file ck_metrics.h.
| enum CKMetricsMode |
| Enumerator | |
|---|---|
| CK_METRICS_MODE_HTTP | |
| CK_METRICS_MODE_FILE | |
| CK_METRICS_MODE_STDOUT | |
| CK_METRICS_MODE_DISABLED | |
Definition at line 47 of file ck_metrics.h.
| enum CKMetricType |
| Enumerator | |
|---|---|
| CK_METRIC_FLOAT | |
| CK_METRIC_INT | |
| CK_METRIC_STRING | |
Definition at line 55 of file ck_metrics.h.
| void ck_metrics_cleanup | ( | void | ) |
Cleanup and free resources
| CKMetricsContext* ck_metrics_create_context | ( | void | ) |
| void ck_metrics_ctx_end | ( | CKMetricsContext * | ctx, |
| const char * | status | ||
| ) |
| bool ck_metrics_ctx_init | ( | CKMetricsContext * | ctx, |
| const char * | run_id, | ||
| const char * | endpoint, | ||
| CKMetricsMode | mode | ||
| ) |
| void ck_metrics_ctx_log_f | ( | CKMetricsContext * | ctx, |
| const char * | name, | ||
| double | value | ||
| ) |
| void ck_metrics_ctx_log_i | ( | CKMetricsContext * | ctx, |
| const char * | name, | ||
| int64_t | value | ||
| ) |
| void ck_metrics_ctx_step | ( | CKMetricsContext * | ctx, |
| int64_t | step | ||
| ) |
| void ck_metrics_destroy_context | ( | CKMetricsContext * | ctx | ) |
| void ck_metrics_end | ( | const char * | status | ) |
End the training run
| status | Final status ("completed", "failed", "interrupted") |
| void ck_metrics_generate_run_id | ( | char * | buffer, |
| size_t | size | ||
| ) |
Generate a unique run ID based on current timestamp
| int64_t ck_metrics_get_memory_mb | ( | void | ) |
Get current memory usage in MB (platform-specific)
| bool ck_metrics_init | ( | const char * | run_id, |
| const char * | endpoint, | ||
| CKMetricsMode | mode | ||
| ) |
Initialize metrics logging
| run_id | Unique identifier for this training run (e.g., "run_20260104_093000") |
| endpoint | HTTP endpoint or file path depending on mode |
| mode | Transport mode (HTTP, FILE, STDOUT, DISABLED) |
| bool ck_metrics_init_full | ( | const char * | run_id, |
| const char * | endpoint, | ||
| CKMetricsMode | mode, | ||
| const char * | model, | ||
| const char * | dataset, | ||
| int | batch_size, | ||
| double | lr, | ||
| int | max_steps | ||
| ) |
Initialize with full configuration
| void ck_metrics_log_f | ( | const char * | name, |
| double | value | ||
| ) |
Log a float metric (e.g., loss, learning rate)
| void ck_metrics_log_i | ( | const char * | name, |
| int64_t | value | ||
| ) |
Log an integer metric (e.g., step, tokens_per_sec)
| void ck_metrics_log_s | ( | const char * | name, |
| const char * | value | ||
| ) |
Log a string metric (e.g., phase, status)
| void ck_metrics_step | ( | int64_t | step | ) |
Flush metrics for the current step and advance to next step Call this at the end of each training step
| step | Current training step number |
| double ck_metrics_timestamp | ( | void | ) |
Get current timestamp in seconds with microsecond precision
|
extern |