1 /** 2 * Copyright (c) Glow Contributors. See CONTRIBUTORS file. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 /** 18 * Contributed by Xperi Corporation on August 13, 2019 19 */ 20 21 #ifndef X_PERF_MONITOR_H 22 #define X_PERF_MONITOR_H 23 24 #ifdef ENABLE_PERF_MONITORING 25 26 #include <asm/unistd.h> 27 #include <linux/perf_event.h> 28 #include <stdint.h> 29 #include <stdlib.h> 30 #include <unistd.h> 31 32 /// Performance monitor statistics 33 struct PerfStatistics { 34 /// Number of CPU cycles it took to run inference 35 long long numCPUCycles; 36 /// Number of cases processed (i.e. batch size) 37 size_t numCases; 38 /// The size of constant weights 39 size_t constWeightsSize; 40 }; 41 42 /// The performance data 43 struct PerfData { 44 /// Performance statistics 45 struct PerfStatistics ps; 46 /// Performance event attributes (which performance events to monitor) 47 struct perf_event_attr pe; 48 /// Whether performance should be monitored 49 int doPerfMonitoring; 50 /// Performance event reader file descriptor 51 int fd; 52 }; 53 54 /// Initialize performance data \p pd. 55 int initPerfMonitoring(struct PerfData *pd); 56 57 /// Stop performance monitoring of events specified in \p pd 58 int stopPerfMonitoring(struct PerfData *pd); 59 60 /// Pause performance monitoring of events specified in \p pd 61 int pausePerfMonitoring(struct PerfData *pd); 62 63 /// Resume performance monitoring of events specified in \p pd 64 int resumePerfMonitoring(struct PerfData *pd); 65 66 /// Reset performance statistics specified in \p pd 67 int resetPerfStatistics(struct PerfData *pd); 68 69 /// Read performance statistics from the file specified by the file descriptor 70 /// in \pd 71 int readPerfStatistics(struct PerfData *pd); 72 73 #endif // ENABLE_PERF_MONITORING 74 #endif // X_PERF_MONITOR_H 75