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

Classes

struct  scale_entry_t
struct  rate_history_t
struct  netgraph_state_t

Macros

#define NET_CATEGORY_COUNT   3
#define PEAK_RATE_MIN   (1024ULL * 1024ULL)
#define PEAK_DECAY_DIVISOR   128
#define PEAK_DECAY_THRESHOLD   1024
#define LINE_BUFFER_SIZE   512
#define HEADER_LINE_COUNT   2
#define LABEL_BUFFER_SIZE   16
#define BYTES_PER_KB   1024ULL
#define BYTES_PER_MB   (1024ULL * 1024ULL)
#define BYTES_PER_GB   (1024ULL * 1024ULL * 1024ULL)
#define SCALE_COUNT   (sizeof(_scales) / sizeof(_scales[0]))

Enumerations

enum  { NET_CATEGORY_IN = 0 , NET_CATEGORY_OUT = 1 , NET_CATEGORY_IN_OUT = 2 }

Functions

static size_t _scale_index_ceil (const unsigned long long val)
static const char * _label_fn (void *app_state)
static void _state_free (void *app_state)
static wlm_graph_read_result_t _stats_read_fn (void *app_state, wlm_graph_values_t *values)
static void _regenerate_fn (void *app_state, wlm_graph_values_t *samples, const uint32_t samples_num)
int main (const int argc, const char **argv)

Variables

static const char _app_name [] = "wlmnetgraph"
static const char _app_help []
static const scale_entry_t _scales []

Detailed Description

Network 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

◆ BYTES_PER_GB

#define BYTES_PER_GB   (1024ULL * 1024ULL * 1024ULL)

Bytes per gigabyte.

◆ BYTES_PER_KB

#define BYTES_PER_KB   1024ULL

Bytes per kilobyte.

◆ BYTES_PER_MB

#define BYTES_PER_MB   (1024ULL * 1024ULL)

Bytes per megabyte.

◆ HEADER_LINE_COUNT

#define HEADER_LINE_COUNT   2

Number of header lines to skip in /proc/net/dev.

◆ LABEL_BUFFER_SIZE

#define LABEL_BUFFER_SIZE   16

Maximum length of the label string.

◆ LINE_BUFFER_SIZE

#define LINE_BUFFER_SIZE   512

Line buffer size for /proc/net/dev parsing.

◆ NET_CATEGORY_COUNT

#define NET_CATEGORY_COUNT   3

Number of network categories tracked.

◆ PEAK_DECAY_DIVISOR

#define PEAK_DECAY_DIVISOR   128

Peak rate decay divisor (~1% decay per sample).

◆ PEAK_DECAY_THRESHOLD

#define PEAK_DECAY_THRESHOLD   1024

Threshold below which peak rate doesn't decay.

◆ PEAK_RATE_MIN

#define PEAK_RATE_MIN   (1024ULL * 1024ULL)

Minimum peak rate for scaling (1 MB/s in bytes).

◆ SCALE_COUNT

#define SCALE_COUNT   (sizeof(_scales) / sizeof(_scales[0]))

Number of scale entries.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Network category indices (maps to heat-map colors).

Enumerator
NET_CATEGORY_IN 

Receive activity.

NET_CATEGORY_OUT 

Transmit activity.

NET_CATEGORY_IN_OUT 

Bidirectional activity.

Function Documentation

◆ _label_fn()

const char * _label_fn ( void * app_state)
static

Returns the scale label.

◆ _regenerate_fn()

void _regenerate_fn ( void * app_state,
wlm_graph_values_t * samples,
const uint32_t samples_num )
static

Regenerates historical samples at the current scale.

Parameters
app_stateApp state (netgraph_state_t pointer).
samplesArray of sample buffers to regenerate (newest first).
samples_numNumber of samples to regenerate.

◆ _scale_index_ceil()

size_t _scale_index_ceil ( const unsigned long long val)
static

Finds index of smallest scale >= val.

Parameters
valValue to find ceiling scale for.
Returns
Index into _scales array.

◆ _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 network statistics from /proc/net/dev.

Parses all interfaces (excluding loopback) and sums RX/TX bytes. Computes rate since last read and scales to 0-255 based on peak rate.

Parameters
app_stateApp state (netgraph_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 network activity as a scrolling graph.\n"
"\n"
"Shows three activity categories:\n"
" - Receive: incoming traffic (blue)\n"
" - Transmit: outgoing traffic (cyan)\n"
" - Bidirectional: combined traffic (red)\n"
"\n"
"The label displays current throughput. Scale auto-adjusts to peak rate."

Application help.

◆ _app_name

const char _app_name[] = "wlmnetgraph"
static

Application name.

◆ _scales

const scale_entry_t _scales[]
static
Initial value:
= {
{ 1ULL * BYTES_PER_KB, "1 KB/s" },
{ 10ULL * BYTES_PER_KB, "10 KB/s" },
{ 100ULL * BYTES_PER_KB, "100 KB/s" },
{ 1ULL * BYTES_PER_MB, "1 MB/s" },
{ 10ULL * BYTES_PER_MB, "10 MB/s" },
{ 100ULL * BYTES_PER_MB, "100 MB/s" },
{ 1ULL * BYTES_PER_GB, "1 GB/s" },
{ 10ULL * BYTES_PER_GB, "10 GB/s" },
{ 100ULL * BYTES_PER_GB, "100 GB/s" },
}
#define BYTES_PER_GB
Definition wlmnetgraph.c:75
#define BYTES_PER_KB
Definition wlmnetgraph.c:69
#define BYTES_PER_MB
Definition wlmnetgraph.c:72

Available scale values (1/10/100 × KB/MB/GB).