53 lines
1.8 KiB
C
53 lines
1.8 KiB
C
|
|
// hakmem_sizeclass_dist.h - Size Class Distribution Signature
|
||
|
|
// Purpose: Detect workload changes via L1 distance
|
||
|
|
//
|
||
|
|
// License: MIT
|
||
|
|
// Date: 2025-10-21
|
||
|
|
|
||
|
|
#ifndef HAKMEM_SIZECLASS_DIST_H
|
||
|
|
#define HAKMEM_SIZECLASS_DIST_H
|
||
|
|
|
||
|
|
#include <stdint.h>
|
||
|
|
#include <stddef.h>
|
||
|
|
|
||
|
|
// ============================================================================
|
||
|
|
// Size Class Distribution (4 classes: 1MB, 2MB, 4MB, 8MB)
|
||
|
|
// ============================================================================
|
||
|
|
|
||
|
|
#define SIZECLASS_NUM_CLASSES 4
|
||
|
|
|
||
|
|
typedef struct {
|
||
|
|
uint32_t freq[SIZECLASS_NUM_CLASSES]; // Frequency of each class
|
||
|
|
uint64_t total; // Total allocations recorded
|
||
|
|
} hak_sizeclass_dist_t;
|
||
|
|
|
||
|
|
// ============================================================================
|
||
|
|
// Public API
|
||
|
|
// ============================================================================
|
||
|
|
|
||
|
|
// Initialize distribution
|
||
|
|
void hak_sizeclass_dist_init(hak_sizeclass_dist_t* dist);
|
||
|
|
|
||
|
|
// Record an allocation size (will classify into size class)
|
||
|
|
void hak_sizeclass_dist_record(hak_sizeclass_dist_t* dist, size_t size);
|
||
|
|
|
||
|
|
// Calculate L1 distance between two distributions
|
||
|
|
// Returns: 0.0 (identical) to 2.0 (completely different)
|
||
|
|
double hak_sizeclass_dist_l1(const hak_sizeclass_dist_t* a,
|
||
|
|
const hak_sizeclass_dist_t* b);
|
||
|
|
|
||
|
|
// Copy distribution
|
||
|
|
void hak_sizeclass_dist_copy(hak_sizeclass_dist_t* dst,
|
||
|
|
const hak_sizeclass_dist_t* src);
|
||
|
|
|
||
|
|
// Reset distribution (start new window)
|
||
|
|
void hak_sizeclass_dist_reset(hak_sizeclass_dist_t* dist);
|
||
|
|
|
||
|
|
// Get total allocations
|
||
|
|
uint64_t hak_sizeclass_dist_total(const hak_sizeclass_dist_t* dist);
|
||
|
|
|
||
|
|
// Print distribution (for debugging)
|
||
|
|
void hak_sizeclass_dist_print(const hak_sizeclass_dist_t* dist, const char* label);
|
||
|
|
|
||
|
|
#endif // HAKMEM_SIZECLASS_DIST_H
|