]>
git.proxmox.com Git - mirror_frr.git/blob - pimd/pim_time.c
4e5832cc657bab652fef61d1ea372ba2fd6d39b3
3 Copyright (C) 2008 Everton da Silva Marques
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; see the file COPYING; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
20 $QuaggaId: $Format:%an, %ai, %h$ $
34 static int gettime_monotonic(struct timeval
*tv
)
38 result
= gettimeofday(tv
, 0);
40 zlog_err("%s: gettimeofday() failure: errno=%d: %s",
42 errno
, safe_strerror(errno
));
49 pim_time_monotonic_sec():
50 number of seconds since some unspecified starting point
52 int64_t pim_time_monotonic_sec()
54 struct timeval now_tv
;
56 if (gettime_monotonic(&now_tv
)) {
57 zlog_err("%s: gettime_monotonic() failure: errno=%d: %s",
59 errno
, safe_strerror(errno
));
67 pim_time_monotonic_dsec():
68 number of deciseconds since some unspecified starting point
70 int64_t pim_time_monotonic_dsec()
72 struct timeval now_tv
;
75 if (gettime_monotonic(&now_tv
)) {
76 zlog_err("%s: gettime_monotonic() failure: errno=%d: %s",
78 errno
, safe_strerror(errno
));
82 now_dsec
= ((int64_t) now_tv
.tv_sec
) * 10 + ((int64_t) now_tv
.tv_usec
) / 100000;
87 int pim_time_mmss(char *buf
, int buf_size
, long sec
)
92 zassert(buf_size
>= 5);
97 wr
= snprintf(buf
, buf_size
, "%02ld:%02ld", mm
, sec
);
102 static int pim_time_hhmmss(char *buf
, int buf_size
, long sec
)
108 zassert(buf_size
>= 8);
115 wr
= snprintf(buf
, buf_size
, "%02ld:%02ld:%02ld", hh
, mm
, sec
);
120 void pim_time_timer_to_mmss(char *buf
, int buf_size
, struct thread
*t_timer
)
123 pim_time_mmss(buf
, buf_size
,
124 thread_timer_remain_second(t_timer
));
127 snprintf(buf
, buf_size
, "--:--");
131 void pim_time_timer_to_hhmmss(char *buf
, int buf_size
, struct thread
*t_timer
)
134 pim_time_hhmmss(buf
, buf_size
,
135 thread_timer_remain_second(t_timer
));
138 snprintf(buf
, buf_size
, "--:--:--");
142 void pim_time_uptime(char *buf
, int buf_size
, int64_t uptime_sec
)
144 zassert(buf_size
>= 8);
146 pim_time_hhmmss(buf
, buf_size
, uptime_sec
);
149 void pim_time_uptime_begin(char *buf
, int buf_size
, int64_t now
, int64_t begin
)
152 pim_time_uptime(buf
, buf_size
, now
- begin
);
154 snprintf(buf
, buf_size
, "--:--:--");
157 long pim_time_timer_remain_msec(struct thread
*t_timer
)
159 /* FIXME: Actually fetch msec resolution from thread */
161 /* no timer thread running means timer has expired: return 0 */
164 1000 * thread_timer_remain_second(t_timer
) :