Skip to content

Commit 630aac6

Browse files
committed
microsecond timestamp is added to http_request structure
1 parent 8e23363 commit 630aac6

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

bin/ej-contests.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ cmd_http_request(
349349
hr.fw_state = state;
350350
gettimeofday(&hr.timestamp1, 0);
351351
hr.current_time = hr.timestamp1.tv_sec;
352+
hr.current_time_us = hr.timestamp1.tv_sec * 1000000LL + hr.timestamp1.tv_usec;
352353
hr.locale_id = -1;
353354

354355
if (pkt_size < sizeof(*pkt))
@@ -624,6 +625,7 @@ handle_ws_request(
624625
hr.fw_state = state;
625626
gettimeofday(&hr.timestamp1, 0);
626627
hr.current_time = hr.timestamp1.tv_sec;
628+
hr.current_time_us = hr.timestamp1.tv_sec * 1000000LL + hr.timestamp1.tv_usec;
627629
hr.locale_id = -1;
628630
hr.config = ejudge_config;
629631
hr.json = root;

csp/contests/priv_main_page.csp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -642,11 +642,10 @@
642642
%>
643643

644644
<%
645-
gettimeofday(&phr->timestamp2, 0);
646-
tdiff = ((long long) phr->timestamp2.tv_sec) * 1000000;
647-
tdiff += phr->timestamp2.tv_usec;
648-
tdiff -= ((long long) phr->timestamp1.tv_sec) * 1000000;
649-
tdiff -= phr->timestamp1.tv_usec;
645+
struct timeval timestamp2;
646+
gettimeofday(&timestamp2, NULL);
647+
long long ts2 = timestamp2.tv_sec * 1000000LL + timestamp2.tv_usec;
648+
tdiff = ts2 - phr->current_time_us;
650649
%>
651650

652651
<div class="dotted"><p<s:v escape="false" value="cnts->team_par_style" />><s:_>Page generation time</s:_>: <s:v value="tdiff / 1000" /> <s:_>msec</s:_></p></div>

include/ejudge/http_request.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,10 @@ struct http_request_info
119119
unsigned char content_type[128];
120120

121121
time_t current_time;
122+
// this time is used in priv-main-page to estimate generation time
122123
struct timeval timestamp1;
123-
struct timeval timestamp2;
124+
// microsecond precision current time
125+
long long current_time_us;
124126

125127
const struct contest_desc *cnts;
126128
struct contest_extra *extra;

0 commit comments

Comments
 (0)