android file hist,hist.h - Android社区 - https://www.androidos.net.cn/

本文介绍了一个用C++编写的程序,通过histogram结构实现对时间差以微秒为单位进行精确到10%精度的分类,用于记录和分析大量时间间隔分布,如请求响应延迟。主要涉及HIST_new、HIST_clear、HIST_add和HIST_report等函数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#if TIME_WITH_SYS_TIME

# include # include #else

# if HAVE_SYS_TIME_H

# include # else

# include # endif

#endif

/* hist.h

Given a time difference in microseconds, increment one of 61

different buckets:

0 - 9 in increments of 1 usec

0 - 9 in increments of 10 usecs

0 - 9 in increments of 100 usecs

0 - 9 in increments of 1 msec

0 - 9 in increments of 10 msecs

0 - 9 in increments of 100 msecs

0 - 9 in increments of 1 sec

0 - 9 in increments of 10 sec

> 100 secs

This will allow any time to be recorded to within an accuracy of

10%, and provides a compact representation for capturing the

distribution of a large number of time differences (e.g.

request-response latencies).

Colin Low 10/6/93

Rick Jones 2004-06-15 - extend to 1 and 10 usec

*/

#ifndef _HIST_INCLUDED

#define _HIST_INCLUDED

#ifdef IRIX

#include #endif /* IRIX */

#if defined(HAVE_GET_HRT)

#include "hrt.h"

#endif

struct histogram_struct {

int unit_usec[10];

int ten_usec[10];

int hundred_usec[10];

int unit_msec[10];

int ten_msec[10];

int hundred_msec[10];

int unit_sec[10];

int ten_sec[10];

int ridiculous;

int total;

};

typedef struct histogram_struct *HIST;

/*

HIST_new - return a new, cleared histogram data type

*/

HIST HIST_new(void);

/*

HIST_clear - reset a histogram by clearing all totals to zero

*/

void HIST_clear(HIST h);

/*

HIST_add - add a time difference to a histogram. Time should be in

microseconds.

*/

void HIST_add(register HIST h, int time_delta);

/*

HIST_report - create an ASCII report on the contents of a histogram.

Currently printsto standard out

*/

void HIST_report(HIST h);

/*

HIST_timestamp - take a timestamp suitable for use in a histogram.

*/

#ifdef HAVE_GETHRTIME

void HIST_timestamp(hrtime_t *timestamp);

#elif defined(HAVE_GET_HRT)

void HIST_timestamp(hrt_t *timestamp);

#elif defined(WIN32)

void HIST_timestamp(LARGE_INTEGER *timestamp);

#else

void HIST_timestamp(struct timeval *timestamp);

#endif

/*

delta_micro - calculate the difference in microseconds between two

timestamps

*/

#ifdef HAVE_GETHRTIME

int delta_micro(hrtime_t *begin, hrtime_t *end);

#elif defined(HAVE_GET_HRT)

int delta_micro(hrt_t *begin, hrt_t *end);

#elif defined(WIN32)

int delta_micro(LARGE_INTEGER *begin, LARGE_INTEGER *end);

#else

int delta_micro(struct timeval *begin, struct timeval *end);

#endif

#endif

C++程序

|

117行

|

2.42 KB

#if TIME_WITH_SYS_TIME

# include

# include

#else

# if HAVE_SYS_TIME_H

# include

# else

# include

# endif

#endif

/* hist.h

Given a time difference in microseconds, increment one of 61

different buckets:

0 - 9 in increments of 1 usec

0 - 9 in increments of 10 usecs

0 - 9 in increments of 100 usecs

0 - 9 in increments of 1 msec

0 - 9 in increments of 10 msecs

0 - 9 in increments of 100 msecs

0 - 9 in increments of 1 sec

0 - 9 in increments of 10 sec

> 100 secs

This will allow any time to be recorded to within an accuracy of

10%, and provides a compact representation for capturing the

distribution of a large number of time differences (e.g.

request-response latencies).

Colin Low 10/6/93

Rick Jones 2004-06-15 - extend to 1 and 10 usec

*/

#ifndef _HIST_INCLUDED

#define _HIST_INCLUDED

#ifdef IRIX

#include

#endif /* IRIX */

#if defined(HAVE_GET_HRT)

#include "hrt.h"

#endif

struct histogram_struct {

int unit_usec[10];

int ten_usec[10];

int hundred_usec[10];

int unit_msec[10];

int ten_msec[10];

int hundred_msec[10];

int unit_sec[10];

int ten_sec[10];

int ridiculous;

int total;

};

typedef struct histogram_struct *HIST;

/*

HIST_new - return a new, cleared histogram data type

*/

HIST HIST_new(void);

/*

HIST_clear - reset a histogram by clearing all totals to zero

*/

void HIST_clear(HIST h);

/*

HIST_add - add a time difference to a histogram. Time should be in

microseconds.

*/

void HIST_add(register HIST h, int time_delta);

/*

HIST_report - create an ASCII report on the contents of a histogram.

Currently printsto standard out

*/

void HIST_report(HIST h);

/*

HIST_timestamp - take a timestamp suitable for use in a histogram.

*/

#ifdef HAVE_GETHRTIME

void HIST_timestamp(hrtime_t *timestamp);

#elif defined(HAVE_GET_HRT)

void HIST_timestamp(hrt_t *timestamp);

#elif defined(WIN32)

void HIST_timestamp(LARGE_INTEGER *timestamp);

#else

void HIST_timestamp(struct timeval *timestamp);

#endif

/*

delta_micro - calculate the difference in microseconds between two

timestamps

*/

#ifdef HAVE_GETHRTIME

int delta_micro(hrtime_t *begin, hrtime_t *end);

#elif defined(HAVE_GET_HRT)

int delta_micro(hrt_t *begin, hrt_t *end);

#elif defined(WIN32)

int delta_micro(LARGE_INTEGER *begin, LARGE_INTEGER *end);

#else

int delta_micro(struct timeval *begin, struct timeval *end);

#endif

#endif

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值