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


C++ cdtime函数代码示例

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


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

示例1: 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

示例2: wt_flush_nolock

/* NOTE: You must hold cb->send_lock when calling this function! */
static int wt_flush_nolock (cdtime_t timeout, struct wt_callback *cb)
{
    int status;

    DEBUG ("write_tsdb plugin: wt_flush_nolock: timeout = %.3f; "
            "send_buf_fill = %zu;",
            (double)timeout,
            cb->send_buf_fill);

    /* timeout == 0  => flush unconditionally */
    if (timeout > 0)
    {
        cdtime_t now;

        now = cdtime ();
        if ((cb->send_buf_init_time + timeout) > now)
            return (0);
    }

    if (cb->send_buf_fill <= 0)
    {
        cb->send_buf_init_time = cdtime ();
        return (0);
    }

    status = wt_send_buffer (cb);
    wt_reset_buffer (cb);

    return (status);
}
开发者ID:bpiraeus,项目名称:collectd,代码行数:31,代码来源:write_tsdb.c

示例3: cc_read_page

static int cc_read_page (web_page_t *wp) /* {{{ */
{
  int status;
  cdtime_t start = 0;

  if (wp->response_time)
    start = cdtime ();

  wp->buffer_fill = 0;
  status = curl_easy_perform (wp->curl);
  if (status != CURLE_OK)
  {
    ERROR ("curl plugin: curl_easy_perform failed with status %i: %s",
        status, wp->curl_errbuf);
    return (-1);
  }

  if (wp->response_time)
    cc_submit_response_time (wp, cdtime() - start);
  if (wp->stats != NULL)
    curl_stats_dispatch (wp->stats, wp->curl, hostname_g, "curl", wp->instance);

  if(wp->response_code)
  {
    long response_code = 0;
    status = curl_easy_getinfo(wp->curl, CURLINFO_RESPONSE_CODE, &response_code);
    if(status != CURLE_OK) {
      ERROR ("curl plugin: Fetching response code failed with status %i: %s",
        status, wp->curl_errbuf);
    } else {
      cc_submit_response_code(wp, response_code);
    }
  }

  for (web_match_t *wm = wp->matches; wm != NULL; wm = wm->next)
  {
    cu_match_value_t *mv;

    status = match_apply (wm->match, wp->buffer);
    if (status != 0)
    {
      WARNING ("curl plugin: match_apply failed.");
      continue;
    }

    mv = match_get_user_data (wm->match);
    if (mv == NULL)
    {
      WARNING ("curl plugin: match_get_user_data returned NULL.");
      continue;
    }

    cc_submit (wp, wm, mv);
    match_value_reset (mv);
  } /* for (wm = wp->matches; wm != NULL; wm = wm->next) */

  return (0);
} /* }}} int cc_read_page */
开发者ID:brd,项目名称:collectd,代码行数:58,代码来源:curl.c

示例4: 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

示例5: 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

示例6: c_ipmi_notification_init

static notification_t c_ipmi_notification_init(c_ipmi_instance_t const *st,
                                               int severity) {
  notification_t n = {severity, cdtime(), "", "", "ipmi", "", "", "", NULL};

  sstrncpy(n.host, (st->host != NULL) ? st->host : hostname_g, sizeof(n.host));
  return n;
} /* notification_t c_ipmi_notification_init */
开发者ID:Stackdriver,项目名称:collectd,代码行数:7,代码来源:ipmi.c

示例7: dpdk_helper_link_status_get

static int dpdk_helper_link_status_get(dpdk_helper_ctx_t *phc) {
  dpdk_events_ctx_t *ec = DPDK_EVENTS_CTX_GET(phc);

  /* get Link Status values from DPDK */
  uint8_t nb_ports = rte_eth_dev_count();
  if (nb_ports == 0) {
    DPDK_CHILD_LOG("dpdkevent-helper: No DPDK ports available. "
                   "Check bound devices to DPDK driver.\n");
    return -ENODEV;
  }
  ec->nb_ports = nb_ports > RTE_MAX_ETHPORTS ? RTE_MAX_ETHPORTS : nb_ports;

  for (int i = 0; i < ec->nb_ports; i++) {
    if (ec->config.link_status.enabled_port_mask & (1 << i)) {
      struct rte_eth_link link;
      ec->link_info[i].read_time = cdtime();
      rte_eth_link_get_nowait(i, &link);
      if ((link.link_status == ETH_LINK_NA) ||
          (link.link_status != ec->link_info[i].link_status)) {
        ec->link_info[i].link_status = link.link_status;
        ec->link_info[i].status_updated = 1;
        DPDK_CHILD_LOG(" === PORT %d Link Status: %s\n", i,
                       link.link_status ? "UP" : "DOWN");
      }
    }
  }

  return 0;
}
开发者ID:Feandil,项目名称:collectd,代码行数:29,代码来源:dpdkevents.c

示例8: 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

示例9: xencpu_read

static int xencpu_read (void)
{
    cdtime_t now = cdtime ();

    int rc, nr_cpus;

    rc = xc_getcpuinfo(xc_handle, num_cpus, cpu_info, &nr_cpus);
    if (rc < 0) {
        ERROR ("xencpu: xc_getcpuinfo() Failed: %d %s\n", rc, xc_strerror(xc_handle,errno));
        return (-1);
    }

    int status;
    for (int cpu = 0; cpu < nr_cpus; cpu++) {
        gauge_t rate = NAN;
        value_t value = {.derive = cpu_info[cpu].idletime};

        status = value_to_rate (&rate, value, DS_TYPE_DERIVE, now, &cpu_states[cpu]);
        if (status == 0) {
            submit_value(cpu, 100 - rate/10000000);
        }
    }

    return (0);
} /* static int xencpu_read */

void module_register (void)
{
    plugin_register_init ("xencpu", xencpu_init);
    plugin_register_read ("xencpu", xencpu_read);
    plugin_register_shutdown ("xencpu", xencpu_shutdown);
} /* void module_register */
开发者ID:brd,项目名称:collectd,代码行数:32,代码来源:xencpu.c

示例10: wt_reset_buffer

/*
 * Functions
 */
static void wt_reset_buffer (struct wt_callback *cb)
{
    memset (cb->send_buf, 0, sizeof (cb->send_buf));
    cb->send_buf_free = sizeof (cb->send_buf);
    cb->send_buf_fill = 0;
    cb->send_buf_init_time = cdtime ();
}
开发者ID:bpiraeus,项目名称:collectd,代码行数:10,代码来源:write_tsdb.c

示例11: __attribute__

/* vcomplain returns 0 if it did not report, 1 else */
__attribute__((format(printf, 3, 0))) static int
vcomplain(int level, c_complain_t *c, const char *format, va_list ap) {
  cdtime_t now;
  char message[512];

  now = cdtime();

  if (c->last + c->interval > now)
    return 0;

  c->last = now;

  if (c->interval < plugin_get_interval())
    c->interval = plugin_get_interval();
  else
    c->interval *= 2;

  if (c->interval > TIME_T_TO_CDTIME_T(86400))
    c->interval = TIME_T_TO_CDTIME_T(86400);

  vsnprintf(message, sizeof(message), format, ap);
  message[sizeof(message) - 1] = '\0';

  plugin_log(level, "%s", message);
  return 1;
} /* vcomplain */
开发者ID:hasso,项目名称:collectd,代码行数:27,代码来源:utils_complain.c

示例12: latency_counter_reset

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

  memset (lc, 0, sizeof (*lc));
  lc->start_time = cdtime ();
} /* }}} void latency_counter_reset */
开发者ID:Altiscale,项目名称:collectd,代码行数:8,代码来源:utils_latency.c

示例13: we_reset_buffer

static void we_reset_buffer (we_callback_t *cb)  
{
  memset (cb->send_buffer, 0, sizeof (cb->send_buffer));
  cb->send_buffer_free = sizeof (cb->send_buffer);
  cb->send_buffer_fill = 0;
  cb->send_buffer_init_time = cdtime ();
  gettimeofday(&cb->last_write,NULL);
}
开发者ID:zbyufei,项目名称:ExtreMon,代码行数:8,代码来源:write_extremon.c

示例14: sysconfig_notify

static void sysconfig_notify(notification_t *notif, const char *type, const char *message) {
        memset (notif, '\0', sizeof (*notif));
        notif->severity = NOTIF_OKAY;
        notif->time = cdtime ();
        sstrncpy(notif->host, hostname_g, sizeof(notif->host));
        sstrncpy(notif->plugin, "sysconfig", sizeof(notif->plugin));
        sstrncpy(notif->type, type, sizeof(notif->type));
        sstrncpy(notif->message, message, sizeof(notif->message));
        plugin_dispatch_notification(notif);
}
开发者ID:sseshachala,项目名称:xervmon_collectd_pw,代码行数:10,代码来源:sysconfig.c

示例15: parse_time

static cdtime_t parse_time(char const *tbuf) {
  double t;
  char *endptr = NULL;

  errno = 0;
  t = strtod(tbuf, &endptr);
  if ((errno != 0) || (endptr == NULL) || (endptr[0] != 0))
    return (cdtime());

  return (DOUBLE_TO_CDTIME_T(t));
}
开发者ID:hasso,项目名称:collectd,代码行数:11,代码来源:tail_csv.c


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