当前位置: 首页>>代码示例>>C++>>正文


C++ CDTIME_T_TO_DOUBLE函数代码示例

本文整理汇总了C++中CDTIME_T_TO_DOUBLE函数的典型用法代码示例。如果您正苦于以下问题:C++ CDTIME_T_TO_DOUBLE函数的具体用法?C++ CDTIME_T_TO_DOUBLE怎么用?C++ CDTIME_T_TO_DOUBLE使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了CDTIME_T_TO_DOUBLE函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: lua_cb_dispatch_values

static int lua_cb_dispatch_values(lua_State *L) /* {{{ */
{
  int nargs = lua_gettop(L);

  if (nargs != 1)
    return luaL_error(L, "Invalid number of arguments (%d != 1)", nargs);

  luaL_checktype(L, 1, LUA_TTABLE);

  value_list_t *vl = luaC_tovaluelist(L, -1);
  if (vl == NULL)
    return luaL_error(L, "%s", "luaC_tovaluelist failed");

#if COLLECT_DEBUG
  char identifier[6 * DATA_MAX_NAME_LEN];
  FORMAT_VL(identifier, sizeof(identifier), vl);

  DEBUG("Lua plugin: collectd.dispatch_values(): Received value list \"%s\", "
        "time %.3f, interval %.3f.",
        identifier, CDTIME_T_TO_DOUBLE(vl->time),
        CDTIME_T_TO_DOUBLE(vl->interval));
#endif

  plugin_dispatch_values(vl);

  sfree(vl->values);
  sfree(vl);
  return 0;
} /* }}} lua_cb_dispatch_values */
开发者ID:bzed,项目名称:collectd,代码行数:29,代码来源:lua.c

示例2: latency_counter_reset

void latency_counter_reset(latency_counter_t *lc) /* {{{ */
{
  if (lc == NULL)
    return;

  cdtime_t bin_width = lc->bin_width;
  cdtime_t max_bin = (lc->max - 1) / lc->bin_width;

/*
  If max latency is REDUCE_THRESHOLD times less than histogram's range,
  then cut it in half. REDUCE_THRESHOLD must be >= 2.
  Value of 4 is selected to reduce frequent changes of bin width.
*/
#define REDUCE_THRESHOLD 4
  if ((lc->num > 0) && (lc->bin_width >= HISTOGRAM_DEFAULT_BIN_WIDTH * 2) &&
      (max_bin < HISTOGRAM_NUM_BINS / REDUCE_THRESHOLD)) {
    /* new bin width will be the previous power of 2 */
    bin_width = bin_width / 2;

    DEBUG("utils_latency: latency_counter_reset: max_latency = %.3f; "
          "max_bin = %" PRIu64 "; old_bin_width = %.3f; new_bin_width = %.3f;",
          CDTIME_T_TO_DOUBLE(lc->max), max_bin,
          CDTIME_T_TO_DOUBLE(lc->bin_width), CDTIME_T_TO_DOUBLE(bin_width));
  }

  memset(lc, 0, sizeof(*lc));

  /* preserve bin width */
  lc->bin_width = bin_width;
  lc->start_time = cdtime();
} /* }}} void latency_counter_reset */
开发者ID:BrandonArp,项目名称:collectd,代码行数:31,代码来源:utils_latency.c

示例3: create_putval

int create_putval (char *ret, size_t ret_len, /* {{{ */
	const data_set_t *ds, const value_list_t *vl)
{
	char buffer_ident[6 * DATA_MAX_NAME_LEN];
	char buffer_values[1024];
	int status;

	status = FORMAT_VL (buffer_ident, sizeof (buffer_ident), vl);
	if (status != 0)
		return (status);
	escape_string (buffer_ident, sizeof (buffer_ident));

	status = format_values (buffer_values, sizeof (buffer_values),
			ds, vl, /* store rates = */ 0);
	if (status != 0)
		return (status);
	escape_string (buffer_values, sizeof (buffer_values));

	ssnprintf (ret, ret_len,
			"PUTVAL %s interval=%.3f %s",
			buffer_ident,
			(vl->interval > 0)
			? CDTIME_T_TO_DOUBLE (vl->interval)
			: CDTIME_T_TO_DOUBLE (interval_g),
			buffer_values);

	return (0);
} /* }}} int create_putval */
开发者ID:KIvosak,项目名称:collectd,代码行数:28,代码来源:utils_cmd_putval.c

示例4: plugin_get_interval

static void *camqp_subscribe_thread (void *user_data) /* {{{ */
{
    camqp_config_t *conf = user_data;
    int status;

    cdtime_t interval = plugin_get_interval ();

    while (subscriber_threads_running)
    {
        amqp_frame_t frame;

        status = camqp_connect (conf);
        if (status != 0)
        {
            struct timespec ts_interval;
            ERROR ("amqp plugin: camqp_connect failed. "
                    "Will sleep for %.3f seconds.",
                    CDTIME_T_TO_DOUBLE (interval));
            CDTIME_T_TO_TIMESPEC (interval, &ts_interval);
            nanosleep (&ts_interval, /* remaining = */ NULL);
            continue;
        }

        status = amqp_simple_wait_frame (conf->connection, &frame);
        if (status < 0)
        {
            struct timespec ts_interval;
            ERROR ("amqp plugin: amqp_simple_wait_frame failed. "
                    "Will sleep for %.3f seconds.",
                    CDTIME_T_TO_DOUBLE (interval));
            camqp_close_connection (conf);
            CDTIME_T_TO_TIMESPEC (interval, &ts_interval);
            nanosleep (&ts_interval, /* remaining = */ NULL);
            continue;
        }

        if (frame.frame_type != AMQP_FRAME_METHOD)
        {
            DEBUG ("amqp plugin: Unexpected frame type: %#"PRIx8,
                    frame.frame_type);
            continue;
        }

        if (frame.payload.method.id != AMQP_BASIC_DELIVER_METHOD)
        {
            DEBUG ("amqp plugin: Unexpected method id: %#"PRIx32,
                    frame.payload.method.id);
            continue;
        }

        camqp_read_header (conf);

        amqp_maybe_release_buffers (conf->connection);
    } /* while (subscriber_threads_running) */

    camqp_config_free (conf);
    pthread_exit (NULL);
    return (NULL);
} /* }}} void *camqp_subscribe_thread */
开发者ID:Mindera,项目名称:collectd,代码行数:59,代码来源:amqp.c

示例5: csnmp_read_host

static int csnmp_read_host (user_data_t *ud)
{
  host_definition_t *host;
  cdtime_t time_start;
  cdtime_t time_end;
  int status;
  int success;
  int i;

  host = ud->data;

  if (host->interval == 0)
    host->interval = plugin_get_interval ();

  time_start = cdtime ();

  if (host->sess_handle == NULL)
    csnmp_host_open_session (host);

  if (host->sess_handle == NULL)
    return (-1);

  success = 0;
  for (i = 0; i < host->data_list_len; i++)
  {
    data_definition_t *data = host->data_list[i];

    if (data->is_table)
      status = csnmp_read_table (host, data);
    else
      status = csnmp_read_value (host, data);

    if (status == 0)
      success++;
  }

  time_end = cdtime ();
  if ((time_end - time_start) > host->interval)
  {
    WARNING ("snmp plugin: Host `%s' should be queried every %.3f "
        "seconds, but reading all values takes %.3f seconds.",
        host->name,
        CDTIME_T_TO_DOUBLE (host->interval),
        CDTIME_T_TO_DOUBLE (time_end - time_start));
  }

  if (success == 0)
    return (-1);

  return (0);
} /* int csnmp_read_host */
开发者ID:kmiku7,项目名称:collectd,代码行数:51,代码来源:snmp.c

示例6: latency_counter_get_percentile

cdtime_t latency_counter_get_percentile (latency_counter_t *lc, /* {{{ */
    double percent)
{
  double percent_upper;
  double percent_lower;
  double p;
  cdtime_t latency_lower;
  cdtime_t latency_interpolated;
  int sum;
  size_t i;

  if ((lc == NULL) || (lc->num == 0) || !((percent > 0.0) && (percent < 100.0)))
    return (0);

  /* Find index i so that at least "percent" events are within i+1 ms. */
  percent_upper = 0.0;
  percent_lower = 0.0;
  sum = 0;
  for (i = 0; i < HISTOGRAM_NUM_BINS; i++)
  {
    percent_lower = percent_upper;
    sum += lc->histogram[i];
    if (sum == 0)
      percent_upper = 0.0;
    else
      percent_upper = 100.0 * ((double) sum) / ((double) lc->num);

    if (percent_upper >= percent)
      break;
  }

  if (i >= HISTOGRAM_NUM_BINS)
    return (0);

  assert (percent_upper >= percent);
  assert (percent_lower < percent);

  if (i == 0)
    return (lc->bin_width);

  latency_lower = ((cdtime_t) i) * lc->bin_width;
  p = (percent - percent_lower) / (percent_upper - percent_lower);

  latency_interpolated = latency_lower
    + DOUBLE_TO_CDTIME_T (p * CDTIME_T_TO_DOUBLE (lc->bin_width));

  DEBUG ("latency_counter_get_percentile: latency_interpolated = %.3f",
      CDTIME_T_TO_DOUBLE (latency_interpolated));
  return (latency_interpolated);
} /* }}} cdtime_t latency_counter_get_percentile */
开发者ID:brd,项目名称:collectd,代码行数:50,代码来源:utils_latency.c

示例7: do_loop

static int do_loop(void) {
  cdtime_t interval = cf_get_default_interval();
  cdtime_t wait_until = cdtime() + interval;

  while (loop == 0) {
#if HAVE_LIBKSTAT
    update_kstat();
#endif

    /* Issue all plugins */
    plugin_read_all();

    cdtime_t now = cdtime();
    if (now >= wait_until) {
      WARNING("Not sleeping because the next interval is "
              "%.3f seconds in the past!",
              CDTIME_T_TO_DOUBLE(now - wait_until));
      wait_until = now + interval;
      continue;
    }

    struct timespec ts_wait = CDTIME_T_TO_TIMESPEC(wait_until - now);
    wait_until = wait_until + interval;

    while ((loop == 0) && (nanosleep(&ts_wait, &ts_wait) != 0)) {
      if (errno != EINTR) {
        ERROR("nanosleep failed: %s", STRERRNO);
        return -1;
      }
    }
  } /* while (loop == 0) */

  return 0;
} /* int do_loop */
开发者ID:octo,项目名称:collectd,代码行数:34,代码来源:collectd.c

示例8: tail_match_add_match

int tail_match_add_match(cu_tail_match_t *obj, cu_match_t *match,
                         int (*submit_match)(cu_match_t *match,
                                             void *user_data),
                         void *user_data,
                         void (*free_user_data)(void *user_data)) {
  cu_tail_match_match_t *temp;

  temp = realloc(obj->matches,
                 sizeof(cu_tail_match_match_t) * (obj->matches_num + 1));
  if (temp == NULL)
    return (-1);

  obj->matches = temp;
  obj->matches_num++;

  DEBUG("tail_match_add_match interval %lf",
        CDTIME_T_TO_DOUBLE(((cu_tail_match_simple_t *)user_data)->interval));
  temp = obj->matches + (obj->matches_num - 1);

  temp->match = match;
  temp->user_data = user_data;
  temp->submit = submit_match;
  temp->free = free_user_data;

  return (0);
} /* int tail_match_add_match */
开发者ID:hasso,项目名称:collectd,代码行数:26,代码来源:utils_tail_match.c

示例9: we_flush_nolock

static int we_flush_nolock (cdtime_t timeout, we_callback_t *cb) 
{
  int status;

  DEBUG("write_extremon plugin: we_flush_nolock: timeout = %.3f; "
        "send_buffer_fill = %zu;", CDTIME_T_TO_DOUBLE (timeout),
                                  cb->send_buffer_fill);

  if(timeout>0)
  {
    cdtime_t now;
    now = cdtime ();
    if ((cb->send_buffer_init_time + timeout) > now)
      return (0);
  }

/*  if (cb->send_buffer_fill <= 0)
# {
#   cb->send_buffer_init_time = cdtime ();
#   return (0);
# } */

  status = we_send_buffer (cb);
  we_reset_buffer (cb);

  return (status);
} 
开发者ID:zbyufei,项目名称:ExtreMon,代码行数:27,代码来源:write_extremon.c

示例10: latency_counter_get_rate

double latency_counter_get_rate(const latency_counter_t *lc, /* {{{ */
                                cdtime_t lower, cdtime_t upper,
                                const cdtime_t now) {
  if ((lc == NULL) || (lc->num == 0))
    return NAN;

  if (upper && (upper < lower))
    return NAN;
  if (lower == upper)
    return 0;

  /* Buckets have an exclusive lower bound and an inclusive upper bound. That
   * means that the first bucket, index 0, represents (0-bin_width]. That means
   * that latency==bin_width needs to result in bin=0, that's why we need to
   * subtract one before dividing by bin_width. */
  cdtime_t lower_bin = 0;
  if (lower)
    /* lower is *exclusive* => determine bucket for lower+1 */
    lower_bin = ((lower + 1) - 1) / lc->bin_width;

  /* lower is greater than the longest latency observed => rate is zero. */
  if (lower_bin >= HISTOGRAM_NUM_BINS)
    return 0;

  cdtime_t upper_bin = HISTOGRAM_NUM_BINS - 1;
  if (upper)
    upper_bin = (upper - 1) / lc->bin_width;

  if (upper_bin >= HISTOGRAM_NUM_BINS) {
    upper_bin = HISTOGRAM_NUM_BINS - 1;
    upper = 0;
  }

  double sum = 0;
  for (size_t i = lower_bin; i <= upper_bin; i++)
    sum += lc->histogram[i];

  if (lower) {
    /* Approximate ratio of requests in lower_bin, that fall between
     * lower_bin_boundary and lower. This ratio is then subtracted from sum to
     * increase accuracy. */
    cdtime_t lower_bin_boundary = lower_bin * lc->bin_width;
    assert(lower >= lower_bin_boundary);
    double lower_ratio =
        (double)(lower - lower_bin_boundary) / ((double)lc->bin_width);
    sum -= lower_ratio * lc->histogram[lower_bin];
  }

  if (upper) {
    /* As above: approximate ratio of requests in upper_bin, that fall between
     * upper and upper_bin_boundary. */
    cdtime_t upper_bin_boundary = (upper_bin + 1) * lc->bin_width;
    assert(upper <= upper_bin_boundary);
    double ratio = (double)(upper_bin_boundary - upper) / (double)lc->bin_width;
    sum -= ratio * lc->histogram[upper_bin];
  }

  return sum / (CDTIME_T_TO_DOUBLE(now - lc->start_time));
} /* }}} double latency_counter_get_rate */
开发者ID:BrandonArp,项目名称:collectd,代码行数:59,代码来源:utils_latency.c

示例11: disk_calc_time_incr

static counter_t disk_calc_time_incr (counter_t delta_time, counter_t delta_ops)
{
	double interval = CDTIME_T_TO_DOUBLE (plugin_get_interval ());
	double avg_time = ((double) delta_time) / ((double) delta_ops);
	double avg_time_incr = interval * avg_time;

	return ((counter_t) (avg_time_incr + .5));
}
开发者ID:BrianB2,项目名称:collectd,代码行数:8,代码来源:disk.c

示例12: latency_counter_get_average

cdtime_t latency_counter_get_average (latency_counter_t *lc) /* {{{ */
{
  double average;

  if ((lc == NULL) || (lc->num == 0))
    return (0);

  average = CDTIME_T_TO_DOUBLE (lc->sum) / ((double) lc->num);
  return (DOUBLE_TO_CDTIME_T (average));
} /* }}} cdtime_t latency_counter_get_average */
开发者ID:brd,项目名称:collectd,代码行数:10,代码来源:utils_latency.c

示例13: ts_invoke_absolute

static int ts_invoke_absolute(const data_set_t *ds, value_list_t *vl, /* {{{ */
                              ts_data_t *data, int dsrc_index) {
  uint64_t curr_absolute;
  double rate;
  int status;

  /* Required meta data */
  double int_fraction;
  char key_int_fraction[128];

  curr_absolute = (uint64_t)vl->values[dsrc_index].absolute;

  snprintf(key_int_fraction, sizeof(key_int_fraction),
           "target_scale[%p,%i]:int_fraction", (void *)data, dsrc_index);

  int_fraction = 0.0;

  /* Query the meta data */
  status = uc_meta_data_get_double(vl, key_int_fraction, &int_fraction);
  if (status != 0)
    int_fraction = 0.0;

  rate = ((double)curr_absolute) / CDTIME_T_TO_DOUBLE(vl->interval);

  /* Modify the rate. */
  if (!isnan(data->factor))
    rate *= data->factor;
  if (!isnan(data->offset))
    rate += data->offset;

  /* Calculate the new absolute. */
  int_fraction += (rate * CDTIME_T_TO_DOUBLE(vl->interval));
  curr_absolute = (uint64_t)int_fraction;
  int_fraction -= ((double)curr_absolute);

  vl->values[dsrc_index].absolute = (absolute_t)curr_absolute;

  /* Update to the new absolute value */
  uc_meta_data_add_double(vl, key_int_fraction, int_fraction);

  return 0;
} /* }}} int ts_invoke_absolute */
开发者ID:BrandonArp,项目名称:collectd,代码行数:42,代码来源:target_scale.c

示例14: change_bin_width

/*
* Histogram represents the distribution of data, it has a list of "bins".
* Each bin represents an interval and has a count (frequency) of
* number of values fall within its interval.
*
* Histogram's range is determined by the number of bins and the bin width,
* There are 1000 bins and all bins have the same width of default 1 millisecond.
* When a value above this range is added, Histogram's range is increased by
* increasing the bin width (note that number of bins remains always at 1000).
* This operation of increasing bin width is little expensive as each bin need
* to be visited to update its count. To reduce frequent change of bin width,
* new bin width will be the next nearest power of 2. Example: 2, 4, 8, 16, 32,
* 64, 128, 256, 512, 1024, 2048, 5086, ...
*
* So, if the required bin width is 300, then new bin width will be 512 as it is
* the next nearest power of 2.
*/
static void change_bin_width(latency_counter_t *lc, cdtime_t latency) /* {{{ */
{
  /* This function is called because the new value is above histogram's range.
   * First find the required bin width:
   *           requiredBinWidth = (value + 1) / numBins
   * then get the next nearest power of 2
   *           newBinWidth = 2^(ceil(log2(requiredBinWidth)))
   */
  double required_bin_width =
      ((double)(latency + 1)) / ((double)HISTOGRAM_NUM_BINS);
  double required_bin_width_logbase2 = log(required_bin_width) / log(2.0);
  cdtime_t new_bin_width =
      (cdtime_t)(pow(2.0, ceil(required_bin_width_logbase2)) + .5);
  cdtime_t old_bin_width = lc->bin_width;

  lc->bin_width = new_bin_width;

  /* bin_width has been increased, now iterate through all bins and move the
   * old bin's count to new bin. */
  if (lc->num > 0) // if the histogram has data then iterate else skip
  {
    double width_change_ratio =
        ((double)old_bin_width) / ((double)new_bin_width);

    for (size_t i = 0; i < HISTOGRAM_NUM_BINS; i++) {
      size_t new_bin = (size_t)(((double)i) * width_change_ratio);
      if (i == new_bin)
        continue;
      assert(new_bin < i);

      lc->histogram[new_bin] += lc->histogram[i];
      lc->histogram[i] = 0;
    }
  }

  DEBUG("utils_latency: change_bin_width: latency = %.3f; "
        "old_bin_width = %.3f; new_bin_width = %.3f;",
        CDTIME_T_TO_DOUBLE(latency), CDTIME_T_TO_DOUBLE(old_bin_width),
        CDTIME_T_TO_DOUBLE(new_bin_width));
} /* }}} void change_bin_width */
开发者ID:BrandonArp,项目名称:collectd,代码行数:57,代码来源:utils_latency.c

示例15: cgps_config

/**
 * Read configuration.
 */
static int cgps_config (oconfig_item_t *ci)
{
  int i;

  for (i = 0; i < ci->children_num; i++)
  {
    oconfig_item_t *child = ci->children + i;

    if (strcasecmp ("Host", child->key) == 0)
      cf_util_get_string (child, &cgps_config_data.host);
    else if (strcasecmp ("Port", child->key) == 0)
      cf_util_get_service (child, &cgps_config_data.port);
    else if (strcasecmp ("Timeout", child->key) == 0)
      cf_util_get_cdtime (child, &cgps_config_data.timeout);
    else if (strcasecmp ("PauseConnect", child->key) == 0)
      cf_util_get_cdtime (child, &cgps_config_data.pause_connect);
    else
      WARNING ("gps plugin: Ignoring unknown config option \"%s\".", child->key);
  }

  // Controlling the value for timeout:
  // If set too high it blocks the reading (> 5 s), too low it gets not reading (< 500 us).
  // To avoid any issues we replace "out of range" value by the default value.
  if (
    cgps_config_data.timeout > TIME_T_TO_CDTIME_T(5)
    ||
    cgps_config_data.timeout < US_TO_CDTIME_T(500)
  ) 
  {
    WARNING ("gps plugin: timeout set to %.6f sec. setting to default (%.6f).", 
      CDTIME_T_TO_DOUBLE(cgps_config_data.timeout),
      CDTIME_T_TO_DOUBLE(CGPS_DEFAULT_TIMEOUT)
    );
    cgps_config_data.timeout = CGPS_DEFAULT_TIMEOUT;
  } 

  return (0);
}
开发者ID:NicolasJourden,项目名称:collectd,代码行数:41,代码来源:gps.c


注:本文中的CDTIME_T_TO_DOUBLE函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。