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

Classes

struct  cpu_times_t
struct  cpugraph_state_t

Macros

#define LINE_BUFFER_SIZE   256

Functions

static bool _cpu_state_arrays_alloc (cpugraph_state_t *state, const uint32_t cpu_usage_num)
static void _state_free (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 [] = "wlmcpugraph"
static const char _app_help []

Detailed Description

CPU 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

◆ LINE_BUFFER_SIZE

#define LINE_BUFFER_SIZE   256

Line buffer size for /proc/stat parsing.

Function Documentation

◆ _cpu_state_arrays_alloc()

bool _cpu_state_arrays_alloc ( cpugraph_state_t * state,
const uint32_t cpu_usage_num )
static

Allocates state arrays for the given number of CPUs.

Parameters
stateCPU graph state.
cpu_usage_numNumber of CPUs.
Returns
true on success, false on allocation failure.

◆ _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 CPU statistics from /proc/stat.

Uses the pre-opened file handle, counts CPUs, reallocates the buffer if needed, and fills it with per-CPU usage values.

Parameters
app_stateApp state (cpugraph_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 CPU usage as a scrolling graph.\n"
"\n"
"The peak shows maximum CPU usage.\n"
"\n"
"Colors below indicate multi-core activity:\n"
" - 1 core active (blue)\n"
" - 1/4 cores active (cyan)\n"
" - 1/2 cores active (green)\n"
" - 3/4 cores active (yellow)\n"
" - All cores active (red)"

Application help.

◆ _app_name

const char _app_name[] = "wlmcpugraph"
static

Application name.