libosmovty 1.9.0.196-9975
Osmocom VTY library
talloc_ctx_vty.c File Reference

Osmocom talloc context introspection via VTY. More...

#include <stdio.h>
#include <regex.h>
#include <string.h>
#include <osmocom/core/talloc.h>
#include <osmocom/vty/command.h>
#include <osmocom/vty/vty.h>

Data Structures

struct  walk_cb_params
 

Macros

#define BASE_CMD_STR    "show talloc-context (application|global|all) (full|brief|DEPTH)"
 
#define BASE_CMD_DESCR
 

Enumerations

enum  walk_filter_type {
  WALK_FILTER_NONE = 0 ,
  WALK_FILTER_REGEXP ,
  WALK_FILTER_TREE
}
 

Functions

static void talloc_ctx_walk_cb (const void *chunk, int depth, int max_depth, int is_ref, void *data)
 Print a talloc memory hierarchy to the given VTY. More...
 
static void talloc_ctx_walk (const char *ctx, const char *depth, struct walk_cb_params *params)
 Parse talloc context and depth values from a VTY command. More...
 
 DEFUN (show_talloc_ctx, show_talloc_ctx_cmd, BASE_CMD_STR, BASE_CMD_DESCR)
 
 DEFUN (show_talloc_ctx_filter, show_talloc_ctx_filter_cmd, BASE_CMD_STR " filter REGEXP", BASE_CMD_DESCR "Filter chunks using regular expression\n" "Regular expression\n")
 
 DEFUN (show_talloc_ctx_tree, show_talloc_ctx_tree_cmd, BASE_CMD_STR " tree ADDRESS", BASE_CMD_DESCR "Display only a specific memory chunk\n" "Chunk address (e.g. 0xdeadbeef)\n")
 
void osmo_talloc_vty_add_cmds (void)
 Install VTY commands for talloc context introspection. More...
 

Variables

void * tall_vty_ctx
 
struct host host
 

Detailed Description

Osmocom talloc context introspection via VTY.

Macro Definition Documentation

◆ BASE_CMD_DESCR

#define BASE_CMD_DESCR
Value:
SHOW_STR "Show talloc memory hierarchy\n" \
"Application's context\n" \
"Global context (OTC_GLOBAL)\n" \
"All contexts, if NULL-context tracking is enabled\n" \
"Display a full talloc memory hierarchy\n" \
"Display a brief talloc memory hierarchy\n" \
"Specify required maximal depth value\n"
#define SHOW_STR
Definition: command.h:372

◆ BASE_CMD_STR

#define BASE_CMD_STR    "show talloc-context (application|global|all) (full|brief|DEPTH)"

Enumeration Type Documentation

◆ walk_filter_type

Enumerator
WALK_FILTER_NONE 
WALK_FILTER_REGEXP 
WALK_FILTER_TREE 

Function Documentation

◆ DEFUN() [1/3]

DEFUN ( show_talloc_ctx  ,
show_talloc_ctx_cmd  ,
BASE_CMD_STR  ,
BASE_CMD_DESCR   
)

◆ DEFUN() [2/3]

DEFUN ( show_talloc_ctx_filter  ,
show_talloc_ctx_filter_cmd  ,
BASE_CMD_STR " filter REGEXP"  ,
BASE_CMD_DESCR "Filter chunks using regular expression\n" "Regular expression\n  
)

◆ DEFUN() [3/3]

DEFUN ( show_talloc_ctx_tree  ,
show_talloc_ctx_tree_cmd  ,
BASE_CMD_STR " tree ADDRESS"  ,
BASE_CMD_DESCR "Display only a specific memory chunk\n" "Chunk address (e.g. 0xdeadbeef)\n  
)

◆ osmo_talloc_vty_add_cmds()

void osmo_talloc_vty_add_cmds ( void  )

Install VTY commands for talloc context introspection.

This installs a set of VTY commands for introspection of a talloc context. Call this once from your application if you want to support those commands.

References install_lib_element_ve().

◆ talloc_ctx_walk()

static void talloc_ctx_walk ( const char *  ctx,
const char *  depth,
struct walk_cb_params params 
)
static

Parse talloc context and depth values from a VTY command.

Parameters
ctxThe context to be printed (a string from argv)
depthThe report depth (a string from argv)
paramsThe walk_cb_params struct instance

References host::app_info, depth, OTC_GLOBAL, params, vty_app_info::tall_ctx, and talloc_ctx_walk_cb().

Referenced by DEFUN().

◆ talloc_ctx_walk_cb()

static void talloc_ctx_walk_cb ( const void *  chunk,
int  depth,
int  max_depth,
int  is_ref,
void *  data 
)
static

Print a talloc memory hierarchy to the given VTY.

To be called by the talloc_report_depth_cb(). If one of supported filters is specified, then only satisfying memory trees would be printed.

Parameters
chunkThe talloc chunk to be printed
depthCurrent depth value
max_depthMaximal depth of report (negative means full)
is_refIs this chunk a reference?
dataThe walk_cb_params struct instance

A filter is being bypassed while current depth value is higher than the 'depth_pass', i.e. the callback does processing the child memory chunks. As soon as this condition becomes false, we need to 'enable' a filter, and resume the processing other chunks.

As soon as a filter passes any chunk, all the memory tree starting from one would be printed. To do that, we need to temporary 'disable' a filter for child chunks (current_depth > depth_pass).

References walk_cb_params::chunk_ptr, data, depth, walk_cb_params::depth_pass, walk_cb_params::filter, walk_cb_params::regexp, walk_cb_params::vty, VTY_NEWLINE, vty_out(), WALK_FILTER_REGEXP, and WALK_FILTER_TREE.

Referenced by talloc_ctx_walk().