diff --git a/daemon/call.c b/daemon/call.c index b71a7da75..0753c1973 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -141,13 +141,13 @@ static void call_timer_iterator(call_t *c, struct iterator_helper *hlp) { // final timeout applicable to all calls (own and foreign) if (atomic_get_na(&rtpe_config.final_timeout) - && timeval_from_us(rtpe_now).tv_sec >= (c->created.tv_sec + atomic_get_na(&rtpe_config.final_timeout))) + && timeval_from_us(rtpe_now).tv_sec >= (timeval_from_us(c->created).tv_sec + atomic_get_na(&rtpe_config.final_timeout))) { ilog(LOG_INFO, "Closing call due to final timeout"); tmp_t_reason = FINAL_TIMEOUT; for (__auto_type it = c->monologues.head; it; it = it->next) { __auto_type ml = it->data; - gettimeofday(&(ml->terminated),NULL); + ml->terminated = rtpe_now; ml->term_reason = tmp_t_reason; } @@ -282,7 +282,7 @@ next: for (__auto_type it = c->monologues.head; it; it = it->next) { __auto_type ml = it->data; - gettimeofday(&(ml->terminated),NULL); + ml->terminated = rtpe_now; ml->term_reason = tmp_t_reason; } @@ -3963,10 +3963,10 @@ static int64_t add_ongoing_calls_dur_in_interval(int64_t interval_start, if (!call->monologues.head || IS_FOREIGN_CALL(call)) goto next; ml = call->monologues.head->data; - if (interval_start > timeval_us(ml->started)) { + if (interval_start > ml->started) { res += interval_duration; } else { - call_duration = rtpe_now - timeval_us(ml->started); + call_duration = rtpe_now - ml->started; res += call_duration; } next: @@ -4199,12 +4199,12 @@ void call_destroy(call_t *c) { se->average_mos.mos / mos_samples % 10, se->lowest_mos->mos / 10, se->lowest_mos->mos % 10, - ((se->lowest_mos->reported - timeval_us(c->created)) / 1000000) / 60, - ((se->lowest_mos->reported - timeval_us(c->created)) / 1000000) % 60, + ((se->lowest_mos->reported - c->created) / 1000000) / 60, + ((se->lowest_mos->reported - c->created) / 1000000) % 60, se->highest_mos->mos / 10, se->highest_mos->mos % 10, - ((se->highest_mos->reported - timeval_us(c->created)) / 1000000) / 60, - ((se->highest_mos->reported - timeval_us(c->created)) / 1000000) % 60, + ((se->highest_mos->reported - c->created) / 1000000) / 60, + ((se->highest_mos->reported - c->created) / 1000000) % 60, (unsigned int) se->packets_lost); ilog(LOG_INFO, "------ respective (avg/min/max) jitter %" PRIu64 "/%" PRIu64 "/%" PRIu64 " ms, " "RTT-e2e %" PRIu64 ".%" PRIu64 "/%" PRIu64 ".%" PRIu64 @@ -4388,7 +4388,7 @@ static call_t *call_create(const str *callid) { c->labels = labels_ht_new(); call_memory_arena_set(c); c->callid = call_str_cpy(callid); - c->created = timeval_from_us(rtpe_now); + c->created = rtpe_now; c->dtls_cert = dtls_cert(); c->tos = rtpe_config.default_tos; c->poller = rtpe_get_poller(); @@ -4687,7 +4687,7 @@ struct call_monologue *__monologue_create(call_t *call) { /* explicitely set b=RR/b=RS to -1 so it's not considered as 0 inadvertently */ RESET_BANDWIDTH(ret->sdp_session_bandwidth, -1); - gettimeofday(&ret->started, NULL); + ret->started = rtpe_now; return ret; } @@ -5270,7 +5270,7 @@ int call_delete_branch(call_t *c, const str *branch, for (__auto_type i = c->monologues.head; i; i = i->next) { ml = i->data; - gettimeofday(&(ml->terminated), NULL); + ml->terminated = rtpe_now; ml->term_reason = REGULAR; } @@ -5320,7 +5320,7 @@ int call_delete_branch(call_t *c, const str *branch, } do_delete: - c->destroyed = timeval_from_us(rtpe_now); + c->destroyed = rtpe_now; /* stop media player and all medias of ml. * same for media subscribers */ @@ -5353,7 +5353,7 @@ del_all: monologue_stop(ml, false); } - c->destroyed = timeval_from_us(rtpe_now); + c->destroyed = rtpe_now; if (delete_delay > 0) { ilog(LOG_INFO, "Scheduling deletion of entire call in %d seconds", delete_delay); diff --git a/daemon/call_interfaces.c b/daemon/call_interfaces.c index 4a0b41f1a..4ec6bdce6 100644 --- a/daemon/call_interfaces.c +++ b/daemon/call_interfaces.c @@ -224,7 +224,7 @@ static str call_update_lookup_udp(char **out, enum ng_opmode opmode, const char* redis_update_onekey(c, rtpe_redis_write); - gettimeofday(&(from_ml->started), NULL); + from_ml->started = rtpe_now; ilog(LOG_INFO, "Returning to SIP proxy: " STR_FORMAT, STR_FMT(&ret)); goto out; @@ -448,7 +448,7 @@ static void call_status_iterator(call_t *c, struct streambuf_stream *s) { streambuf_printf(s->outbuf, "session "STR_FORMAT" - - - - %" PRId64 "\n", STR_FMT(&c->callid), - timeval_diff(timeval_from_us(rtpe_now), c->created) / 1000000); + (rtpe_now - c->created) / 1000000); /* XXX restore function */ @@ -2658,7 +2658,7 @@ static const char *call_offer_answer_ng(ng_command_ctx_t *ctx, const char* addr, ilog(LOG_DEBUG, "Not updating Redis due to present no-redis-update flag"); } - gettimeofday(&(from_ml->started), NULL); + from_ml->started = rtpe_now; errstr = "Error rewriting SDP"; @@ -3095,8 +3095,9 @@ void ng_call_stats(ng_command_ctx_t *ctx, call_t *call, const str *fromtag, cons parser = ctx->parser_ctx.parser; - parser->dict_add_int(ctx->resp, "created", call->created.tv_sec); - parser->dict_add_int(ctx->resp, "created_us", call->created.tv_usec); + parser->dict_add_int(ctx->resp, "created", call->created / 1000000); + parser->dict_add_int(ctx->resp, "created_us", call->created % 1000000); + parser->dict_add_int(ctx->resp, "created_ts", call->created); parser->dict_add_int(ctx->resp, "last signal", call->last_signal); parser->dict_add_int(ctx->resp, "last redis update", atomic64_get_na(&call->last_redis_update)); if (call->metadata.s) diff --git a/daemon/cdr.c b/daemon/cdr.c index 15a5f8a78..3ec4e9088 100644 --- a/daemon/cdr.c +++ b/daemon/cdr.c @@ -34,7 +34,7 @@ static const char * get_term_reason_text(enum termination_reason t) { void cdr_update_entry(call_t * c) { struct call_monologue *ml; - struct timeval tim_result_duration; + int64_t tim_result_duration; int cdrlinecnt = 0; g_autoptr(GString) cdr = g_string_new(""); struct call_media *md; @@ -55,24 +55,24 @@ void cdr_update_entry(call_t * c) { for (__auto_type l = c->monologues.head; l; l = l->next) { ml = l->data; - if (!ml->terminated.tv_sec) { - gettimeofday(&ml->terminated, NULL); + if (!ml->terminated) { + ml->terminated = rtpe_now; ml->term_reason = UNKNOWN; } - tim_result_duration = timeval_subtract(ml->terminated, ml->started); + tim_result_duration = ml->terminated - ml->started; if (_log_facility_cdr) { g_string_append_printf(cdr, - "ml%i_start_time=%" TIME_T_INT_FMT ".%06" TIME_T_INT_FMT ", " - "ml%i_end_time=%" TIME_T_INT_FMT ".%06" TIME_T_INT_FMT ", " - "ml%i_duration=%" TIME_T_INT_FMT ".%06" TIME_T_INT_FMT ", " + "ml%i_start_time=%" PRId64 ".%06" PRId64 ", " + "ml%i_end_time=%" PRId64 ".%06" PRId64 ", " + "ml%i_duration=%" PRId64 ".%06" PRId64 ", " "ml%i_termination=%s, " "ml%i_local_tag=%s, " "ml%i_local_tag_type=%s, ", - cdrlinecnt, ml->started.tv_sec, ml->started.tv_usec, - cdrlinecnt, ml->terminated.tv_sec, ml->terminated.tv_usec, - cdrlinecnt, tim_result_duration.tv_sec, tim_result_duration.tv_usec, + cdrlinecnt, ml->started / 1000000, ml->started % 1000000, + cdrlinecnt, ml->terminated / 1000000, ml->terminated % 1000000, + cdrlinecnt, tim_result_duration / 1000000, tim_result_duration % 1000000, cdrlinecnt, get_term_reason_text(ml->term_reason), cdrlinecnt, ml->tag.s, cdrlinecnt, get_tag_type_text(ml->tagtype)); diff --git a/daemon/cli.c b/daemon/cli.c index df688c861..f71567432 100644 --- a/daemon/cli.c +++ b/daemon/cli.c @@ -366,7 +366,7 @@ next:; if (!c->ml_deleted) { for (__auto_type i = c->monologues.head; i; i = i->next) { ml = i->data; - gettimeofday(&(ml->terminated), NULL); + ml->terminated = rtpe_now; ml->term_reason = FORCED; } } @@ -692,7 +692,7 @@ static void cli_list_call_info(struct cli_writer *cw, call_t *c) { "\n" "callid: %s\n" "deletionmark: %s\n" - "created: %i\n" + "created: %" PRId64 "\n" "proxy: %s\n" "tos: %u\n" "last_signal: %llu\n" @@ -701,7 +701,7 @@ static void cli_list_call_info(struct cli_writer *cw, call_t *c) { "foreign: %s\n" "recording: %s\n" "\n", - c->callid.s, c->ml_deleted ? "yes" : "no", (int) c->created.tv_sec, c->created_from, + c->callid.s, c->ml_deleted ? "yes" : "no", c->created / 1000000, c->created_from, (unsigned int) c->tos, (unsigned long long) c->last_signal, c->redis_hosted_db, (unsigned long long) atomic64_get_na(&c->last_redis_update), IS_FOREIGN_CALL(c) ? "yes" : "no", c->recording ? "yes" : "no"); @@ -717,26 +717,26 @@ static void cli_list_call_info(struct cli_writer *cw, call_t *c) { static void cli_list_tag_info(struct cli_writer *cw, struct call_monologue *ml) { struct call_media *md; struct packet_stream *ps; - struct timeval tim_result_duration; - struct timeval now; + int64_t tim_result_duration; + int64_t now; char *local_addr; - if (!ml->terminated.tv_sec) - gettimeofday(&now, NULL); + if (!ml->terminated) + now = rtpe_now; else now = ml->terminated; - tim_result_duration = timeval_subtract(now, ml->started); + tim_result_duration = now - ml->started; cw->cw_printf(cw, "--- Tag '" STR_FORMAT "', type: %s, label '" STR_FORMAT "', " "branch '" STR_FORMAT "', " "callduration " - "%" TIME_T_INT_FMT ".%06" TIME_T_INT_FMT "\n", + "%" PRId64 ".%06" PRId64 "\n", STR_FMT(&ml->tag), get_tag_type_text(ml->tagtype), STR_FMT(ml->label.s ? &ml->label : &STR_EMPTY), STR_FMT(&ml->viabranch), - tim_result_duration.tv_sec, - tim_result_duration.tv_usec); + tim_result_duration / 1000000, + tim_result_duration % 1000000); if (ml->tag_aliases.length) { __auto_type alias = ml->tag_aliases.head; @@ -867,9 +867,9 @@ static void cli_incoming_list_sessions(str *instr, struct cli_writer *cw, const } found = true; - cw->cw_printf(cw, "ID: %60s | del:%s | creat:%12li | prx:%s | redis:%2i | frgn:%s | rec:%s\n", + cw->cw_printf(cw, "ID: %60s | del:%s | creat:%12" PRId64 " | prx:%s | redis:%2i | frgn:%s | rec:%s\n", call->callid.s, call->ml_deleted ? "y" : "n", - (long) call->created.tv_sec, + call->created / 1000000, call->created_from, call->redis_hosted_db, IS_FOREIGN_CALL(call) ? "y" : "n", call->recording ? "y" : "n"); @@ -1132,7 +1132,7 @@ static void cli_incoming_terminate(str *instr, struct cli_writer *cw, const cli_ if (!c->ml_deleted) { for (__auto_type i = c->monologues.head; i; i = i->next) { ml = i->data; - gettimeofday(&(ml->terminated), NULL); + ml->terminated = rtpe_now; ml->term_reason = FORCED; } } diff --git a/daemon/media_socket.c b/daemon/media_socket.c index 1fadd2e0f..9a476456b 100644 --- a/daemon/media_socket.c +++ b/daemon/media_socket.c @@ -2521,9 +2521,9 @@ static bool media_packet_address_check(struct packet_handler_ctx *phc) && phc->mp.stream->advertised_endpoint.port) { // check if we need to reset our learned endpoints - if (timeval_diff(timeval_from_us(rtpe_now), phc->mp.stream->ep_detect_signal) != 0) { + if ((rtpe_now - phc->mp.stream->ep_detect_signal) != 0) { memset(&phc->mp.stream->detected_endpoints, 0, sizeof(phc->mp.stream->detected_endpoints)); - phc->mp.stream->ep_detect_signal = timeval_from_us(rtpe_now); + phc->mp.stream->ep_detect_signal = rtpe_now; } // possible endpoints that can be detected in order of preference: diff --git a/daemon/recording.c b/daemon/recording.c index 84bba8aab..107e6e2d2 100644 --- a/daemon/recording.c +++ b/daemon/recording.c @@ -540,7 +540,7 @@ static void sdp_after_pcap(struct recording *recording, const str *s, struct cal fprintf(meta_fp, "\nLabel: " STR_FORMAT, STR_FMT(&ml->label)); } fprintf(meta_fp, "\nTimestamp started ms: "); - fprintf(meta_fp, "%.3lf", ml->started.tv_sec*1000.0+ml->started.tv_usec/1000.0); + fprintf(meta_fp, "%.3lf", ml->started / 1000.); fprintf(meta_fp, "\nSDP mode: "); fprintf(meta_fp, "%s", get_opmode_text(opmode)); fprintf(meta_fp, "\nSDP before RTP packet: %" PRIu64 "\n\n", recording->pcap.packet_num); @@ -562,13 +562,13 @@ static void rec_pcap_meta_finish_file(call_t *call) { // Print start timestamp and end timestamp // YYYY-MM-DDThh:mm:ss - time_t start = call->created.tv_sec; + time_t start = timeval_from_us(call->created).tv_sec; time_t end = timeval_from_us(rtpe_now).tv_sec; char timebuffer[20]; struct tm timeinfo; - struct timeval *terminate; - terminate = &(((struct call_monologue *)call->monologues.head->data)->terminated); - fprintf(recording->pcap.meta_fp, "\nTimestamp terminated ms(first monologue): %.3lf", terminate->tv_sec*1000.0 + terminate->tv_usec/1000.0); + int64_t terminate; + terminate = (((struct call_monologue *)call->monologues.head->data)->terminated); + fprintf(recording->pcap.meta_fp, "\nTimestamp terminated ms(first monologue): %.3lf", terminate / 1000.); if (localtime_r(&start, &timeinfo) == NULL) { ilog(LOG_ERROR, "Cannot get start local time, while cleaning up recording meta file: %s", strerror(errno)); } else { diff --git a/daemon/redis.c b/daemon/redis.c index addef4cfe..fc3e8b6b9 100644 --- a/daemon/redis.c +++ b/daemon/redis.c @@ -969,7 +969,7 @@ static int redis_check_conn(struct redis *r) { rtpe_now = now_us(); // XXX this needed here? if ((r->state == REDIS_STATE_DISCONNECTED) && (r->restore_tick > timeval_from_us(rtpe_now).tv_sec)) { - ilog(LOG_WARNING, "Redis server '%s' is disabled. Don't try RE-Establishing for %" TIME_T_INT_FMT " more seconds", + ilog(LOG_WARNING, "Redis server '%s' is disabled. Don't try RE-Establishing for %" PRId64 " more seconds", r->hostname, r->restore_tick - timeval_from_us(rtpe_now).tv_sec); return REDIS_STATE_DISCONNECTED; } @@ -1119,13 +1119,9 @@ static atomic64 strtoa64(const char *c, char **endp, int base) { atomic64_set_na(&ret, u); return ret; } -static struct timeval strtotimeval(const char *c, char **endp, int base) { - long long ll = strtoll(c, endp, base); - return timeval_from_us(ll); -} define_get_int_type(time_t, time_t, strtoull); -define_get_int_type(timeval, struct timeval, strtotimeval); +define_get_int_type(int64_t, int64_t, strtoll); define_get_int_type(int, int, strtol); define_get_int_type(llu, unsigned long long, strtoll); define_get_int_type(ld, long, strtoll); @@ -2100,9 +2096,9 @@ static void json_restore_call(struct redis *r, const str *callid, bool foreign) goto err7; err = "missing 'created' timestamp"; - if (redis_hash_get_timeval(&c->created, &call, "created")) + if (redis_hash_get_int64_t(&c->created, &call, "created")) goto err8; - redis_hash_get_timeval(&c->destroyed, &call, "destroyed"); + redis_hash_get_int64_t(&c->destroyed, &call, "destroyed"); c->last_signal = last_signal; if (redis_hash_get_int(&i, &call, "tos")) c->tos = 184; @@ -2456,8 +2452,8 @@ static str redis_encode_json(ng_parser_ctx_t *ctx, call_t *c, void **to_free) { parser_arg inner = parser->dict_add_dict(root, "json"); { - JSON_SET_SIMPLE("created","%" PRId64, timeval_us(c->created)); - JSON_SET_SIMPLE("destroyed","%" PRId64, timeval_us(c->destroyed)); + JSON_SET_SIMPLE("created","%" PRId64, c->created); + JSON_SET_SIMPLE("destroyed","%" PRId64, c->destroyed); JSON_SET_SIMPLE("last_signal","%ld", (long int) c->last_signal); JSON_SET_SIMPLE("tos","%u", (int) c->tos); JSON_SET_SIMPLE("deleted","%ld", (long int) c->deleted); diff --git a/daemon/statistics.c b/daemon/statistics.c index 5716f401d..2f1ddbce9 100644 --- a/daemon/statistics.c +++ b/daemon/statistics.c @@ -182,9 +182,9 @@ found:; RTPE_STATS_INC(managed_sess); - if (!c->destroyed.tv_sec) - c->destroyed = timeval_from_us(rtpe_now); - int64_t duration = timeval_diff(c->destroyed, c->created); + if (!c->destroyed) + c->destroyed = rtpe_now; + int64_t duration = c->destroyed - c->created; RTPE_STATS_ADD(call_duration, duration); duration /= 1000; // millisecond precision for the squared value to avoid overflows RTPE_STATS_ADD(call_duration2, duration * duration); diff --git a/include/call.h b/include/call.h index 2f58aaee4..2ef800f53 100644 --- a/include/call.h +++ b/include/call.h @@ -435,7 +435,7 @@ struct packet_stream { sink_handler_q rtp_mirrors; /* LOCK: call->master_lock, in_lock for streamhandler */ struct endpoint endpoint; /* LOCK: out_lock */ struct endpoint detected_endpoints[4]; /* LOCK: out_lock */ - struct timeval ep_detect_signal; /* LOCK: out_lock */ + int64_t ep_detect_signal; /* LOCK: out_lock */ struct endpoint advertised_endpoint; /* RO */ struct endpoint learned_endpoint; /* LOCK: out_lock */ struct crypto_context crypto; /* OUT direction, LOCK: out_lock */ @@ -590,8 +590,8 @@ struct call_monologue { str label; time_t created; /* RO */ time_t deleted; - struct timeval started; /* for CDR */ - struct timeval terminated; /* for CDR */ + int64_t started; /* for CDR */ + int64_t terminated; /* for CDR */ enum termination_reason term_reason; sockfamily_t *desired_family; struct logical_intf *logical_intf; @@ -768,8 +768,8 @@ struct call { str callid; str_q callid_aliases; - struct timeval created; - struct timeval destroyed; + int64_t created; + int64_t destroyed; time_t last_signal; time_t deleted; time_t ml_deleted; diff --git a/lib/loglib.h b/lib/loglib.h index 4fa8ece68..3c4eee9fd 100644 --- a/lib/loglib.h +++ b/lib/loglib.h @@ -9,14 +9,6 @@ #include "compat.h" #include "auxlib.h" -#ifndef TIME_T_INT_FMT -#ifdef __USE_TIME_BITS64 -#define TIME_T_INT_FMT PRId64 -#else -#define TIME_T_INT_FMT "ld" -#endif -#endif - extern int ilog_facility; extern int get_local_log_level(unsigned int); diff --git a/t/test-stats.c b/t/test-stats.c index bf0f1cbec..b17d7cc69 100644 --- a/t/test-stats.c +++ b/t/test-stats.c @@ -4845,8 +4845,8 @@ int main(void) { struct call_monologue *ml1 = call_get_or_create_monologue(call1, &callid1); call_t *call2 = call_get_or_create(&callid2, true); struct call_monologue *ml2 = call_get_or_create_monologue(call2, &callid2); - call1->created = ml1->started = (struct timeval) {157,0}; - call2->created = ml2->started = (struct timeval) {57,0}; + call1->created = ml1->started = 157 * 1000000LL; + call2->created = ml2->started = 57 * 1000000LL; graph_str = print_graphite_data(); assert_g_string_eq(graph_str,