add function bytes_to_human_str
parent
ce4c5e23d4
commit
3f19715e45
3
HISTORY
3
HISTORY
|
|
@ -1,6 +1,7 @@
|
||||||
|
|
||||||
Version 1.79 2025-08-20
|
Version 1.79 2025-08-29
|
||||||
* logger.h export function log_it_ex3
|
* logger.h export function log_it_ex3
|
||||||
|
* shared_func.[hc]: add function bytes_to_human_str
|
||||||
|
|
||||||
Version 1.78 2025-08-07
|
Version 1.78 2025-08-07
|
||||||
* getIpaddrByName: normalize ip addr when input addr is IPv4 or IPv6
|
* getIpaddrByName: normalize ip addr when input addr is IPv4 or IPv6
|
||||||
|
|
|
||||||
|
|
@ -112,6 +112,13 @@ extern int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int kind);
|
||||||
#define SYNC_LOG_BUFF_DEF_INTERVAL 10
|
#define SYNC_LOG_BUFF_DEF_INTERVAL 10
|
||||||
#define TIME_NONE -1
|
#define TIME_NONE -1
|
||||||
|
|
||||||
|
#define FC_BYTES_ONE_KB ( 1 << 10)
|
||||||
|
#define FC_BYTES_ONE_MB ( 1 << 20)
|
||||||
|
#define FC_BYTES_ONE_GB ( 1 << 30)
|
||||||
|
#define FC_BYTES_ONE_TB (1LL << 40)
|
||||||
|
#define FC_BYTES_ONE_PB (1LL << 50)
|
||||||
|
#define FC_BYTES_ONE_EB (1LL << 60)
|
||||||
|
|
||||||
#if defined(IOV_MAX) && IOV_MAX > 256
|
#if defined(IOV_MAX) && IOV_MAX > 256
|
||||||
#define FC_IOV_BATCH_SIZE 256
|
#define FC_IOV_BATCH_SIZE 256
|
||||||
#else
|
#else
|
||||||
|
|
|
||||||
|
|
@ -3251,6 +3251,72 @@ const char *long2str(const int64_t n, char *buff, const bool thousands_separator
|
||||||
return buff;
|
return buff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *bytes_to_human_str(const int64_t bytes, char *buff)
|
||||||
|
{
|
||||||
|
char *p;
|
||||||
|
|
||||||
|
if (bytes < FC_BYTES_ONE_TB)
|
||||||
|
{
|
||||||
|
if (bytes < FC_BYTES_ONE_MB)
|
||||||
|
{
|
||||||
|
if (bytes < FC_BYTES_ONE_KB)
|
||||||
|
{
|
||||||
|
p = buff + fc_itoa(bytes, buff);
|
||||||
|
*p++ = ' ';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
p = buff + fc_itoa(bytes / FC_BYTES_ONE_KB, buff);
|
||||||
|
*p++ = ' ';
|
||||||
|
*p++ = 'K';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (bytes < FC_BYTES_ONE_GB)
|
||||||
|
{
|
||||||
|
p = buff + fc_itoa(bytes / FC_BYTES_ONE_MB, buff);
|
||||||
|
*p++ = ' ';
|
||||||
|
*p++ = 'M';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
p = buff + fc_itoa(bytes / FC_BYTES_ONE_GB, buff);
|
||||||
|
*p++ = ' ';
|
||||||
|
*p++ = 'G';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (bytes < FC_BYTES_ONE_EB)
|
||||||
|
{
|
||||||
|
if (bytes < FC_BYTES_ONE_PB)
|
||||||
|
{
|
||||||
|
p = buff + fc_itoa(bytes / FC_BYTES_ONE_TB, buff);
|
||||||
|
*p++ = ' ';
|
||||||
|
*p++ = 'T';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
p = buff + fc_itoa(bytes / FC_BYTES_ONE_PB, buff);
|
||||||
|
*p++ = ' ';
|
||||||
|
*p++ = 'P';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
p = buff + fc_itoa(bytes / FC_BYTES_ONE_EB, buff);
|
||||||
|
*p++ = ' ';
|
||||||
|
*p++ = 'E';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*p++ = 'B';
|
||||||
|
*p = '\0';
|
||||||
|
|
||||||
|
return buff;
|
||||||
|
}
|
||||||
|
|
||||||
bool starts_with(const char *str, const char *needle)
|
bool starts_with(const char *str, const char *needle)
|
||||||
{
|
{
|
||||||
int str_len;
|
int str_len;
|
||||||
|
|
|
||||||
|
|
@ -1191,6 +1191,8 @@ static inline const char *long_to_comma_str(const int64_t n, char *buff)
|
||||||
return long2str(n, buff, true);
|
return long2str(n, buff, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char *bytes_to_human_str(const int64_t bytes, char *buff);
|
||||||
|
|
||||||
/** if the string starts with the needle string
|
/** if the string starts with the needle string
|
||||||
* parameters:
|
* parameters:
|
||||||
* str: the string to detect
|
* str: the string to detect
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue