libtracefs(3)

# libtracefs(3) Manual Page

## NAME

tracefs_hist_alloc, tracefs_hist_alloc_2d, tracefs_hist_alloc_nd, tracefs_hist_alloc_nd_cnt, tracefs_hist_free, tracefs_hist_add_key, tracefs_hist_add_key_cnt, tracefs_hist_add_value - Create and destroy event histograms

## SYNOPSIS

    #include <tracefs.h>

    enum tracefs_hist_key_type {
            TRACEFS_HIST_KEY_NORMAL = 0,
            TRACEFS_HIST_KEY_HEX,
            TRACEFS_HIST_KEY_SYM,
            TRACEFS_HIST_KEY_SYM_OFFSET,
            TRACEFS_HIST_KEY_SYSCALL,
            TRACEFS_HIST_KEY_EXECNAME,
            TRACEFS_HIST_KEY_LOG,
            TRACEFS_HIST_KEY_USECS,
            TRACEFS_HIST_KEY_MAX
    };

    struct tracefs_hist_axis {
            const char *key;
            enum tracefs_hist_key_type type;
    };

    struct tracefs_hist *tracefs_hist_alloc(struct tracefs_tep * tep,
                            const char *system, const char *event,
                            const char *key, enum tracefs_hist_key_type type);
    struct tracefs_hist *tracefs_hist_alloc_2d(struct tracefs_tep * tep,
                            const char *system, const char *event,
                            const char *key1, enum tracefs_hist_key_type type1,
                            const char *key2, enum tracefs_hist_key_type type2));
    struct tracefs_hist *tracefs_hist_alloc_nd(struct tracefs_tep * tep,
                            const char *system, const char *event,
                            struct tracefs_hist_axis *axes);
    struct tracefs_hist *tracefs_hist_alloc_nd_cnt(struct tep_handle *tep,
                              const char *system, const char *event_name,
                              struct tracefs_hist_axis_cnt *axes);
    void tracefs_hist_free(struct tracefs_hist *hist);

    int tracefs_hist_add_key(struct tracefs_hist *hist, const char *key,
                             enum tracefs_hist_key_type type);
    int tracefs_hist_add_key_cnt(struct tracefs_hist *hist, const char *key,
                             enum tracefs_hist_key_type type, int cnt);
    int tracefs_hist_add_value(struct tracefs_hist *hist, const char *value);

## DESCRIPTION

Event histograms are created by the trigger file in the event directory. The syntax can be complex and difficult to get correct. This API handles the syntax, and facilitates the creation and interaction with the event histograms. See https://www.kernel.org/doc/html/latest/trace/histogram.html for more information.

tracefs_hist_alloc() allocates a "struct tracefs_hist" descriptor of a one-dimensional histogram and returns the address of it. This descriptor must be freed by tracefs_hist_free(). The tep is a trace event handle (see tracefs_local_events(3)), that holds the system and event that the histogram will be attached to. The system is the system or group of the event. The event is the event to attach the histogram to. The key is a field of the event that will be used as the key(dimension) of the histogram. The type is the type of the key. See KEY TYPES below.

tracefs_hist_alloc_2d() allocates a "struct tracefs_hist" descriptor of a two-dimensional histogram and returns the address of it. This descriptor must be freed by tracefs_hist_free(). The tep is a trace event handle (see tracefs_local_events(3)), that holds the system and event that the histogram will be attached to. The system is the system or group of the event. The event is the event to attach the histogram to. The key1 is the first field of the event that will be used as the key(dimension) of the histogram. The type1 is the type of the key1. See KEY TYPES below. The key2 is the second field of the event that will be used as the key(dimension) of the histogram. The type2 is the type of the key2. See KEY TYPES below.

tracefs_hist_alloc_nd() allocates a "struct tracefs_hist" descriptor of an N-dimensional histogram and returns the address of it. This descriptor must be freed by tracefs_hist_free(). The tep is a trace event handle (see tracefs_local_events(3)), that holds the system and event that the histogram will be attached to. The system is the system or group of the event. The event is the event to attach the histogram to. The axes is an array of key / type pairs, defining the dimensions of the histogram.

tracefs_hist_alloc_nd_cnt() will initialize a histogram descriptor that will be attached to the system/event. This only initializes the descriptor with the given axes keys as primaries. This only initializes the descriptor, it does not start the histogram in the kernel. The difference between this and tracefs_hist_alloc_nd() is that the axes parameter is of type struct tracefs_hist_axis_cnt and not struct tracefs_hist_axis.

tracefs_hist_free() frees the tracefs_hist descriptor. Note, it does not stop or disable the running histogram if it was started. tracefs_hist_destroy() needs to be called to do so.

tracefs_hist_add_key() Adds a secondary or tertiary key to the histogram. The key passed to tracefs_hist_alloc_nd() is the primary key of the histogram. The first time this function is called, it will add a secondary key (or two dimensional histogram). If this function is called again on the same histogram, it will add a tertiary key (or three dimensional histogram). The hist parameter is the histogram descriptor to add the key to. The type is the type of key to add (See KEY TYPES below).

The tracefs_hist_add_key_cnt() is the same as tracefs_hist_add_key() except that it allows to add a counter for the given type. Currently, there’s only the buckets type that requires a counter. When adding a key with the buckets type, tracefs_hist_add_key() is not sufficient, as the buckets type requires a counter or bucket size. Use tracefs_hist_add_key_cnt() when specifing a key that is broken up into buckets, and pass in the size of those buckets into cnt.

tracefs_hist_add_value() will add a value to record. By default, the value is simply the "hitcount" of the number of times a instance of the histogram’s key was hit. The hist is the histogram descriptor to add the value to. The value is a field in the histogram to add to when an instance of the key is hit.

## KEY TYPES

tracefs_hist_alloc_nd() and tracefs_hist_add_key() both add a key and requires that key to have a type. The types may be:

TRACEFS_HIST_KEY_NORMAL or zero (0) which is to not modify the type.

TRACEFS_HIST_KEY_HEX to display the key in hex.

TRACEFS_HIST_KEY_SYM to display the key as a kernel symbol (if found). If the key is an address, this is useful as it will display the function names instead of just a number.

TRACEFS_HIST_KEY_SYM_OFFSET similar to TRACEFS_HIST_KEY_SYM but will also include the offset of the function to match the exact address.

TRACEFS_HIST_KEY_SYSCALL If the key is a system call "id" (the number passed from user space to the kernel to tell it what system call it is calling), then the name of the system call is displayed.

TRACEFS_HIST_KEY_EXECNAME If "common_pid" is the key (the pid of the executing task), instead of showing the number, show the name of the running task.

TRACEFS_HIST_KEY_LOG will display the key in a binary logarithmic scale.

TRACEFS_HIST_KEY_USECS for use with "common_timestamp" or TRACEFS_HIST_TIMESTAMP, in which case it will show the timestamp in microseconds instead of nanoseconds.

## RETURN VALUE

tracefs_hist_alloc_nd() returns an allocated histogram descriptor which must be freed by tracefs_hist_free() or NULL on error.

All the other functions return zero on success or -1 on error.

If tracefs_hist_start() returns an error, a message may be displayed in the kernel that can be retrieved by tracefs_error_last().

## EXAMPLE

## FILES

    tracefs.h
            Header file to include in order to have access to the library APIs.
    -ltracefs
            Linker switch to add when building a program that uses the library.

## SEE ALSO

libtracefs(3), libtraceevent(3), trace-cmd(1), tracefs_hist_pause(3), tracefs_hist_continue(3), tracefs_hist_reset(3)

## AUTHOR

    Steven Rostedt <rostedt@goodmis.org>
    Tzvetomir Stoyanov <tz.stoyanov@gmail.com>
    sameeruddin shaik <sameeruddin.shaik8@gmail.com>

## REPORTING BUGS

Report bugs to <linux-trace-devel@vger.kernel.org>

## LICENSE

libtracefs is Free Software licensed under the GNU LGPL 2.1

## RESOURCES

https://git.kernel.org/pub/scm/libs/libtrace/libtracefs.git/

## COPYING

Copyright (C) 2020 VMware, Inc. Free use of this software is granted under the terms of the GNU Public License (GPL).