T: new function 'bps'
This function is used to print rates (say '1kb/s' or '16Mb/s').
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
void new_thread(void *(*f)(void *), void *data)
|
void new_thread(void *(*f)(void *), void *data)
|
||||||
{
|
{
|
||||||
@@ -36,6 +37,16 @@ void sleepms(int ms)
|
|||||||
if (nanosleep(&t, NULL)) abort();
|
if (nanosleep(&t, NULL)) abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void bps(char *out, float v, char *suffix)
|
||||||
|
{
|
||||||
|
static char *bps_unit[4] = { "", "k", "M", "G" };
|
||||||
|
int flog;
|
||||||
|
if (v < 1000) flog = 0; else flog = floor(floor(log10(v)) / 3);
|
||||||
|
if (flog > 3) flog = 3;
|
||||||
|
v /= pow(10, flog*3);
|
||||||
|
sprintf(out, "%g%s%s", round(v*100)/100, bps_unit[flog], suffix);
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************/
|
/****************************************************************************/
|
||||||
/* list */
|
/* list */
|
||||||
/****************************************************************************/
|
/****************************************************************************/
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
void new_thread(void *(*f)(void *), void *data);
|
void new_thread(void *(*f)(void *), void *data);
|
||||||
void sleepms(int ms);
|
void sleepms(int ms);
|
||||||
|
void bps(char *out, float v, char *suffix);
|
||||||
|
|
||||||
/****************************************************************************/
|
/****************************************************************************/
|
||||||
/* list */
|
/* list */
|
||||||
|
|||||||
Reference in New Issue
Block a user