mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
add bytes statistic for librtmp
This commit is contained in:
parent
a639eb0596
commit
cccc483ab3
3 changed files with 29 additions and 1 deletions
|
@ -43,6 +43,10 @@ int main(int argc, char** argv)
|
||||||
int64_t time_cleanup = 0;
|
int64_t time_cleanup = 0;
|
||||||
// delay = actual - expect time when quit.
|
// delay = actual - expect time when quit.
|
||||||
int delay = 0;
|
int delay = 0;
|
||||||
|
// bytes
|
||||||
|
int64_t bytes_nsend = 0;
|
||||||
|
int time_duration = 0;
|
||||||
|
int64_t bytes_nrecv = 0;
|
||||||
|
|
||||||
// packet data
|
// packet data
|
||||||
int type, size;
|
int type, size;
|
||||||
|
@ -145,8 +149,12 @@ int main(int argc, char** argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
rtmp_destroy:
|
rtmp_destroy:
|
||||||
|
bytes_nsend = srs_get_nsend_bytes(rtmp);
|
||||||
|
bytes_nrecv = srs_get_nrecv_bytes(rtmp);
|
||||||
|
|
||||||
srs_rtmp_destroy(rtmp);
|
srs_rtmp_destroy(rtmp);
|
||||||
time_cleanup = srs_get_time_ms();
|
time_cleanup = srs_get_time_ms();
|
||||||
|
time_duration = (int)(time_cleanup - time_startup);
|
||||||
|
|
||||||
// print result to stderr.
|
// print result to stderr.
|
||||||
fprintf(stderr, "{"
|
fprintf(stderr, "{"
|
||||||
|
@ -159,10 +167,12 @@ rtmp_destroy:
|
||||||
"\"%s\":%d, " // #6
|
"\"%s\":%d, " // #6
|
||||||
"\"%s\":%d, " // #7
|
"\"%s\":%d, " // #7
|
||||||
"\"%s\":%d, " // #8
|
"\"%s\":%d, " // #8
|
||||||
|
"\"%s\":%d, " // #9
|
||||||
|
"\"%s\":%d, " // #10
|
||||||
"%s,%s,%s,%s}",
|
"%s,%s,%s,%s}",
|
||||||
"code", ret, //#0
|
"code", ret, //#0
|
||||||
// total = dns + tcp_connect + start_play + first_packet + last_packet
|
// total = dns + tcp_connect + start_play + first_packet + last_packet
|
||||||
"total", (int)(time_cleanup - time_startup), //#1
|
"total", time_duration, //#1
|
||||||
"dns", (int)(time_dns_resolve - time_startup), //#2
|
"dns", (int)(time_dns_resolve - time_startup), //#2
|
||||||
"tcp_connect", (int)(time_socket_connect - time_dns_resolve), //#3
|
"tcp_connect", (int)(time_socket_connect - time_dns_resolve), //#3
|
||||||
"start_play", (int)(time_play_stream - time_socket_connect), //#4
|
"start_play", (int)(time_play_stream - time_socket_connect), //#4
|
||||||
|
@ -173,6 +183,8 @@ rtmp_destroy:
|
||||||
// actual = stream
|
// actual = stream
|
||||||
// delay = actual - expect
|
// delay = actual - expect
|
||||||
"delay", (int)(timestamp - (time_cleanup - time_first_packet)), //#8
|
"delay", (int)(timestamp - (time_cleanup - time_first_packet)), //#8
|
||||||
|
"publish_kbps", (int)((time_duration <= 0)? 0:(bytes_nsend * 8 / time_duration)), //#9
|
||||||
|
"play_kbps", (int)((time_duration <= 0)? 0:(bytes_nrecv * 8 / time_duration)), //#10
|
||||||
// unit in ms.
|
// unit in ms.
|
||||||
"\"unit\": \"ms\"",
|
"\"unit\": \"ms\"",
|
||||||
"\"remark0\": \"total = dns + tcp_connect + start_play + first_packet + last_packet\"",
|
"\"remark0\": \"total = dns + tcp_connect + start_play + first_packet + last_packet\"",
|
||||||
|
|
|
@ -451,6 +451,20 @@ int64_t srs_get_time_ms()
|
||||||
return srs_get_system_time_ms();
|
return srs_get_system_time_ms();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int64_t srs_get_nsend_bytes(srs_rtmp_t rtmp)
|
||||||
|
{
|
||||||
|
srs_assert(rtmp != NULL);
|
||||||
|
Context* context = (Context*)rtmp;
|
||||||
|
return context->rtmp->get_send_bytes();
|
||||||
|
}
|
||||||
|
|
||||||
|
int64_t srs_get_nrecv_bytes(srs_rtmp_t rtmp)
|
||||||
|
{
|
||||||
|
srs_assert(rtmp != NULL);
|
||||||
|
Context* context = (Context*)rtmp;
|
||||||
|
return context->rtmp->get_recv_bytes();
|
||||||
|
}
|
||||||
|
|
||||||
struct FlvContext
|
struct FlvContext
|
||||||
{
|
{
|
||||||
SrsFileStream fs;
|
SrsFileStream fs;
|
||||||
|
|
|
@ -157,6 +157,8 @@ int srs_version_revision();
|
||||||
* utilities
|
* utilities
|
||||||
*/
|
*/
|
||||||
int64_t srs_get_time_ms();
|
int64_t srs_get_time_ms();
|
||||||
|
int64_t srs_get_nsend_bytes(srs_rtmp_t rtmp);
|
||||||
|
int64_t srs_get_nrecv_bytes(srs_rtmp_t rtmp);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* flv codec
|
* flv codec
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue