OpenOCD
time_support.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 /***************************************************************************
4  * Copyright (C) 2006 by Dominic Rath *
5  * Dominic.Rath@gmx.de *
6  * *
7  * Copyright (C) 2007,2008 Øyvind Harboe *
8  * oyvind.harboe@zylin.com *
9  * *
10  * Copyright (C) 2008 by Spencer Oliver *
11  * spen@spen-soft.co.uk *
12  ***************************************************************************/
13 
14 #ifdef HAVE_CONFIG_H
15 #include "config.h"
16 #endif
17 
18 #include <helper/log.h>
19 
20 #include "time_support.h"
21 
23 {
24  int64_t now = timeval_ms();
25 
26  if (now < 0)
27  return ERROR_FAIL;
28 
29  duration->start_ms = now;
30 
31  return ERROR_OK;
32 }
33 
35 {
36  int64_t now = timeval_ms();
37 
38  if (now < 0)
39  return ERROR_FAIL;
40 
42 
43  return ERROR_OK;
44 }
45 
46 float duration_elapsed(const struct duration *duration)
47 {
48  return ((float)duration->elapsed_ms) / 1000;
49 }
50 
51 float duration_kbps(const struct duration *duration, size_t count)
52 {
53  int64_t elapsed_ms = duration->elapsed_ms;
54 
55  if (elapsed_ms == 0)
56  elapsed_ms = 1;
57 
58  return 1000 * count / (1024 * (float)elapsed_ms);
59 }
#define ERROR_FAIL
Definition: log.h:188
#define ERROR_OK
Definition: log.h:182
int64_t start_ms
Definition: time_support.h:28
int64_t elapsed_ms
Definition: time_support.h:29
float duration_elapsed(const struct duration *duration)
Definition: time_support.c:46
int duration_measure(struct duration *duration)
Update the duration->elapsed field to finish the duration measurement.
Definition: time_support.c:34
int duration_start(struct duration *duration)
Update the duration->start field to start the duration measurement.
Definition: time_support.c:22
float duration_kbps(const struct duration *duration, size_t count)
Definition: time_support.c:51
int64_t timeval_ms(void)
uint8_t count[4]
Definition: vdebug.c:22