PX4 Firmware
PX4 Autopilot Software http://px4.io
test_perf.c
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright (C) 2012-2019 PX4 Development Team. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in
13  * the documentation and/or other materials provided with the
14  * distribution.
15  * 3. Neither the name PX4 nor the names of its contributors may be
16  * used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  *
32  ****************************************************************************/
33 
34 /**
35  * @file test_perf.c
36  * Tests related to the performance counter.
37  */
38 
39 #include <px4_platform_common/px4_config.h>
40 #include <px4_platform_common/posix.h>
41 
42 #include <perf/perf_counter.h>
43 
44 #include "tests_main.h"
45 
46 int
47 test_perf(int argc, char *argv[])
48 {
49  perf_counter_t cc = perf_alloc(PC_COUNT, "test_count");
50  perf_counter_t ec = perf_alloc(PC_ELAPSED, "test_elapsed");
51 
52  if ((cc == NULL) || (ec == NULL)) {
53  printf("perf: counter alloc failed\n");
54  return 1;
55  }
56 
57  perf_begin(ec);
58  perf_count(cc);
59  perf_count(cc);
60  perf_count(cc);
61  perf_count(cc);
62  printf("perf: expect count of 4\n");
64  perf_end(ec);
65  printf("perf: expect count of 1\n");
67  printf("perf: expect at least two counters\n");
68  perf_print_all(1);
69 
70  perf_free(cc);
71  perf_free(ec);
72 
73  return OK;
74 }
measure the time elapsed performing an event
Definition: perf_counter.h:56
count the number of times an event occurs
Definition: perf_counter.h:55
void perf_count(perf_counter_t handle)
Count a performance event.
Header common to all counters.
void perf_free(perf_counter_t handle)
Free a counter.
int test_perf(int argc, char *argv[])
Definition: test_perf.c:47
#define perf_alloc(a, b)
Definition: px4io.h:59
void perf_print_all(int fd)
Print all of the performance counters.
Tests declaration file.
void perf_end(perf_counter_t handle)
End a performance event.
void perf_print_counter(perf_counter_t handle)
Print one performance counter to stdout.
#define OK
Definition: uavcan_main.cpp:71
void perf_begin(perf_counter_t handle)
Begin a performance event.
Performance measuring tools.