Program Listing for File grind.h

Return to documentation for file (rcsw/tool/grind.h)

#pragma once

/*******************************************************************************
 * Includes
 ******************************************************************************/
#include "rcsw/rcsw.h"
#include "rcsw/common/flags.h"

/*******************************************************************************
 * Macros
 ******************************************************************************/
#if defined(RCSW_NO_GRIND)
#define RCSW_GRIND_START(the_grinder, name)
#define RCSW_GRIND_END(the_grinder, name)
#define RCSW_GRIND_COUNT(the_grinder, name)
#define RCSW_GRIND_TICK(the_grinder, name)
#else
#define RCSW_GRIND_START(the_grinder, name) grind_capture_start(the_grinder, \
                                                                name)

#define RCSW_GRIND_END(the_grinder, name) grind_capture_end(the_grinder, name)


#define RCSW_GRIND_COUNT(the_grinder, name) grind_capture_count(the_grinder, \
                                                                name)

#define RCSW_GRIND_TICK(the_grinder, name) grind_capture_tick(the_grinder, name)

#endif

/*******************************************************************************
 * Constant Definitions
 ******************************************************************************/
#define RCSW_GRIND_INTERVAL (1 << RCSW_MODFLAGS_START)

#define RCSW_GRIND_RESET_AUTO (1 << (RCSW_MODFLAGS_START + 1))

#define RCSW_GRIND_REPORT_AUTO (1 << (RCSW_MODFLAGS_START + 2))

#define RCSW_GRIND_REPORT_REQ_FULL (1 << (RCSW_MODFLAGS_START + 3))

#define RCSW_GRIND_REPORT_DATAPOINTS (1 << (RCSW_MODFLAGS_START + 4))

#define RCSW_GRIND_REPORT_HISTOGRAM (1 << (RCSW_MODFLAGS_START + 5))

#define RCSW_GRINDEE_NAMELEN 32

/*******************************************************************************
 * Type Definitions
 ******************************************************************************/
enum grind_mode {
  ekRCSW_GRIND_COUNT,

  ekRCSW_GRIND_DURATION,

  ekRCSW_GRIND_PERIOD,
};

/*******************************************************************************
 * Structure Definitions
 ******************************************************************************/
struct grindee {
  char                name[RCSW_GRINDEE_NAMELEN];

  size_t               count;

  size_t               tindex;

  bool_t               full;

  size_t*              table;

  size_t               tsize;

  union grind_mode_impl {
    struct {
      size_t          accum;

      struct timespec start;

      struct timespec end;

      bool_t          active;
    } duration;

    struct {
      struct timespec current;

      bool_t          first;

      size_t          accum;
    } tick;
  } domain;
};

struct grind_params {
  char**          names;

  size_t          n_inst;

  uint32_t        flags;
  enum grind_mode mode;

  size_t          res;

  size_t          tsize;

  struct timespec interval;

  struct timespec (*gettime)(void);
};

struct grinder {
  enum grind_mode mode;

  size_t                     n_inst;

  size_t                     res;

  bool_t                     avail;

  bool_t                     in_interval;

  uint32_t                   flags;

  struct     grindee         *grindees;

  struct     timespec        interval;

  struct  timespec           interval_start;

  struct timespec (*gettime)(void);
};


/*******************************************************************************
 * API Functions
 ******************************************************************************/
struct grinder * grind_init(struct grinder* grind_in,
                            const struct grind_params* const params);

void grind_destroy(struct grinder * const the_grinder);

status_t grind_capture_start(struct grinder* const the_grinder,
                             const char* const name);

status_t grind_capture_end(struct grinder * const the_grinder,
                           const char *const name);

status_t grind_capture_count(struct grinder * const the_grinder,
                             const char *const name);

status_t grind_capture_tick(struct grinder * const the_grinder,
                            const char *const name);

void grind_report_all(const struct grinder * const the_grinder);

status_t grind_report(const struct grinder * const the_grinder,
                      struct grindee *const fm);

status_t grind_report_utilization(const struct grinder * const the_grinder);

int grind_report_utilization2(const struct grinder * const the_grinder,
                              char * const buf);

void grind_reset_all(struct grinder * const the_grinder);

void grind_reset(const struct grinder * const the_grinder,
                 struct grindee * const grindee);

int grindee_lookup(const struct grinder * const the_grinder,
                   const char *const name) RCSW_PURE;

size_t grindee_data_max(const struct grindee* const grindee);

size_t grindee_data_min(const struct grindee * const grindee);

size_t grindee_data_sum(const struct grindee * const grindee);


size_t grind_sum_all(const struct grinder * const the_grinder);

double grind_get_utilization(struct grinder * the_grinder,
                             const char * const name);