timeprofile.h
Go to the documentation of this file.
1 /* Copyright (C) 2013-2016, The Regents of The University of Michigan.
2 All rights reserved.
3 
4 This software was developed in the APRIL Robotics Lab under the
5 direction of Edwin Olson, ebolson@umich.edu. This software may be
6 available under alternative licensing terms; contact the address above.
7 
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
10 
11 1. Redistributions of source code must retain the above copyright notice, this
12  list of conditions and the following disclaimer.
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 The views and conclusions contained in the software and documentation are those
29 of the authors and should not be interpreted as representing official policies,
30 either expressed or implied, of the Regents of The University of Michigan.
31 */
32 
33 #ifndef _TIME_PROFILE_H
34 #define _TIME_PROFILE_H
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 #include <stdio.h>
41 #include <sys/time.h>
42 #include <string.h>
43 #include <stdint.h>
44 
45 #include "time_util.h"
46 #include "zarray.h"
47 
49 {
50  char name[32];
51  int64_t utime;
52 };
53 
54 typedef struct timeprofile timeprofile_t;
56 {
57  int64_t utime;
59 };
60 
62 {
63  timeprofile_t *tp = (timeprofile_t*) calloc(1, sizeof(timeprofile_t));
64  tp->stamps = zarray_create(sizeof(struct timeprofile_entry));
65 
66  tp->utime = utime_now();
67 
68  return tp;
69 }
70 
71 static inline void timeprofile_destroy(timeprofile_t *tp)
72 {
74  free(tp);
75 }
76 
77 static inline void timeprofile_clear(timeprofile_t *tp)
78 {
79  zarray_clear(tp->stamps);
80  tp->utime = utime_now();
81 }
82 
83 static inline void timeprofile_stamp(timeprofile_t *tp, const char *name)
84 {
85  struct timeprofile_entry tpe;
86 
87  strncpy(tpe.name, name, sizeof(tpe.name));
88  tpe.name[sizeof(tpe.name)-1] = 0;
89  tpe.utime = utime_now();
90 
91  zarray_add(tp->stamps, &tpe);
92 }
93 
94 static inline void timeprofile_display(timeprofile_t *tp)
95 {
96  int64_t lastutime = tp->utime;
97 
98  for (int i = 0; i < zarray_size(tp->stamps); i++) {
99  struct timeprofile_entry *stamp;
100 
101  zarray_get_volatile(tp->stamps, i, &stamp);
102 
103  double cumtime = (stamp->utime - tp->utime)/1000000.0;
104 
105  double parttime = (stamp->utime - lastutime)/1000000.0;
106 
107  printf("%2d %32s %15f ms %15f ms\n", i, stamp->name, parttime*1000, cumtime*1000);
108 
109  lastutime = stamp->utime;
110  }
111 }
112 
113 static inline uint64_t timeprofile_total_utime(timeprofile_t *tp)
114 {
115  if (zarray_size(tp->stamps) == 0)
116  return 0;
117 
118  struct timeprofile_entry *first, *last;
119  zarray_get_volatile(tp->stamps, 0, &first);
120  zarray_get_volatile(tp->stamps, zarray_size(tp->stamps) - 1, &last);
121 
122  return last->utime - first->utime;
123 }
124 
125 #ifdef __cplusplus
126 }
127 #endif
128 
129 #endif
static void zarray_get_volatile(const zarray_t *za, int idx, void *p)
Definition: zarray.h:218
static void timeprofile_stamp(timeprofile_t *tp, const char *name)
Definition: timeprofile.h:83
static int zarray_size(const zarray_t *za)
Definition: zarray.h:136
static void zarray_destroy(zarray_t *za)
Definition: zarray.h:76
zarray_t * stamps
Definition: timeprofile.h:58
static void timeprofile_display(timeprofile_t *tp)
Definition: timeprofile.h:94
int64_t utime
Definition: timeprofile.h:51
char name[32]
Definition: timeprofile.h:50
static zarray_t * zarray_create(size_t el_sz)
Definition: zarray.h:63
int64_t utime
Definition: timeprofile.h:57
static timeprofile_t * timeprofile_create()
Definition: timeprofile.h:61
static uint64_t timeprofile_total_utime(timeprofile_t *tp)
Definition: timeprofile.h:113
Definition: zarray.h:49
Definition: timeprofile.h:48
static void zarray_clear(zarray_t *za)
Definition: zarray.h:391
static void timeprofile_clear(timeprofile_t *tp)
Definition: timeprofile.h:77
int64_t utime_now()
Definition: time_util.c:54
static void timeprofile_destroy(timeprofile_t *tp)
Definition: timeprofile.h:71
static void zarray_add(zarray_t *za, const void *p)
Definition: zarray.h:185


apriltags2
Author(s): Danylo Malyuta
autogenerated on Fri Oct 19 2018 04:02:32