wlmaker
Loading...
Searching...
No Matches
wlmmemgraph.c File Reference
#include "wlm_graph_shared.h"
#include <libbase/libbase.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Include dependency graph for wlmmemgraph.c:

Classes

struct  memgraph_state_t

Macros

#define LINE_BUFFER_SIZE   256
#define MEMINFO_FIELD_COUNT   5
#define MEM_CATEGORY_COUNT   3
#define LABEL_BUFFER_SIZE   16
#define KB_PER_MB   1024UL
#define KB_PER_GB   (1024UL * 1024)
#define KB_PER_TB   (1024UL * 1024 * 1024)
#define LABEL_MATCH(literal)

Enumerations

enum  { MEM_CATEGORY_CACHED = 0 , MEM_CATEGORY_BUFFERS = 1 , MEM_CATEGORY_USED = 2 }

Functions

static void _memgraph_lut_init (uint32_t lut[256])
static void _state_free (void *app_state)
static void _format_memory_size (char *buf, const size_t buf_size, const unsigned long kb)
static const char * _label_fn (void *app_state)
static wlm_graph_read_result_t _stats_read_fn (void *app_state, wlm_graph_values_t *values)
int main (const int argc, const char **argv)

Variables

static const char _app_name [] = "wlmmemgraph"
static const char _app_help []

Detailed Description

Memory usage graph dock-app for wlmaker.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Macro Definition Documentation

◆ KB_PER_GB

#define KB_PER_GB   (1024UL * 1024)

Kilobytes per gigabyte.

◆ KB_PER_MB

#define KB_PER_MB   1024UL

Kilobytes per megabyte.

◆ KB_PER_TB

#define KB_PER_TB   (1024UL * 1024 * 1024)

Kilobytes per terabyte.

◆ LABEL_BUFFER_SIZE

#define LABEL_BUFFER_SIZE   16

Maximum length of the label string.

◆ LABEL_MATCH

#define LABEL_MATCH ( literal)
Value:
(sizeof(literal) - 1 == label_len && 0 == memcmp(line, literal, sizeof(literal) - 1))

Matches line label against a string literal.

Compares label_len bytes of line against the literal. Used for parsing /proc/meminfo where each line has format "Label: value kB".

Parameters
literalString literal to match against.

◆ LINE_BUFFER_SIZE

#define LINE_BUFFER_SIZE   256

Line buffer size for /proc/meminfo parsing.

◆ MEM_CATEGORY_COUNT

#define MEM_CATEGORY_COUNT   3

Number of memory categories tracked.

◆ MEMINFO_FIELD_COUNT

#define MEMINFO_FIELD_COUNT   5

Number of fields to parse from /proc/meminfo.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Memory category indices.

Enumerator
MEM_CATEGORY_CACHED 

Cached (including SReclaimable).

MEM_CATEGORY_BUFFERS 

Buffers.

MEM_CATEGORY_USED 

Used (non-reclaimable).

Function Documentation

◆ _format_memory_size()

void _format_memory_size ( char * buf,
const size_t buf_size,
const unsigned long kb )
static

Formats memory size with appropriate suffix (GB, MB, kB).

Parameters
bufOutput buffer.
buf_sizeSize of output buffer.
kbMemory size in kilobytes.

◆ _label_fn()

const char * _label_fn ( void * app_state)
static

Returns the formatted memory usage label.

◆ _memgraph_lut_init()

void _memgraph_lut_init ( uint32_t lut[256])
static

Generates blue-to-green gradient LUT (256 entries).

With 3 memory categories, only indices 0, 127, and 255 are sampled (mapping count 1, 2, 3 respectively). The full 256 entries are required by the API but only 3 discrete colors matter for this use case.

Parameters
lutOutput LUT array (256 entries).

◆ _state_free()

void _state_free ( void * app_state)
static

Frees all allocated state.

◆ _stats_read_fn()

wlm_graph_read_result_t _stats_read_fn ( void * app_state,
wlm_graph_values_t * values )
static

Reads memory statistics from /proc/meminfo.

Parses MemTotal, MemFree, Buffers, Cached, and SReclaimable to compute per-category usage percentages.

Parameters
app_stateApp state (memgraph_state_t pointer).
valuesBuffer to fill (may reallocate data/num).
Returns
WLM_GRAPH_READ_OK on success, WLM_GRAPH_READ_ERROR on error.

◆ main()

int main ( const int argc,
const char ** argv )

Main program.

Variable Documentation

◆ _app_help

const char _app_help[]
static
Initial value:
=
"Displays memory usage as a scrolling graph.\n"
"\n"
"Shows stacked memory categories:\n"
" - Cached: top of graph (dark blue)\n"
" - Buffers: middle of graph (dark cyan)\n"
" - Used: bottom of graph (green)\n"
"\n"
"The label displays total memory usage."

Application help.

◆ _app_name

const char _app_name[] = "wlmmemgraph"
static

Application name.