2 * Copyright (c) 2017 ARM Limited.
4 * SPDX-License-Identifier: MIT
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 #ifdef CYCLE_PROFILING
32 static const int maxevents = 10000;
33 unsigned long times[maxevents];
34 unsigned long units[maxevents];
35 int events[maxevents];
42 countfd=open_cycle_counter();
48 unsigned long counts[5];
49 unsigned long tunits[5];
50 const char * descs[] = { "Prepare A", "Prepare B", "Kernel", "Merge" };
52 for (int i=1; i<5; i++) {
58 printf("Profiled events:\n");
59 for (int i=0; i<currentevent; i++) {
61 counts[events[i]] += times[i];
62 tunits[events[i]] += units[i];
65 printf("%20s %9s %9s %9s %12s %9s\n", "", "Events", "Total", "Average", "Bytes/MACs", "Per cycle");
66 for (int i=1; i<5; i++) {
67 printf("%20s: %9d %9ld %9ld %12lu %9.2f\n",descs[i-1],tots[i],counts[i],counts[i]/tots[i],tunits[i],(float)tunits[i]/counts[i]);
72 void operator() (int i, unsigned long u, T func) {
73 if (currentevent==maxevents) {
76 events[currentevent] = i;
77 units[currentevent] = u;
78 start_counter(countfd);
80 long long cycs = stop_counter(countfd);
81 times[currentevent++] = cycs;
91 void operator() (int i, unsigned long u, T func) {
98 #define PROFILE_PREPA 1
99 #define PROFILE_PREPB 2
100 #define PROFILE_KERNEL 3
101 #define PROFILE_MERGE 4