167d3abd7b26a741347b33402ad32f5c6735ca0bdYabin Cui/* 267d3abd7b26a741347b33402ad32f5c6735ca0bdYabin Cui * Copyright (C) 2015 The Android Open Source Project 367d3abd7b26a741347b33402ad32f5c6735ca0bdYabin Cui * 467d3abd7b26a741347b33402ad32f5c6735ca0bdYabin Cui * Licensed under the Apache License, Version 2.0 (the "License"); 567d3abd7b26a741347b33402ad32f5c6735ca0bdYabin Cui * you may not use this file except in compliance with the License. 667d3abd7b26a741347b33402ad32f5c6735ca0bdYabin Cui * You may obtain a copy of the License at 767d3abd7b26a741347b33402ad32f5c6735ca0bdYabin Cui * 867d3abd7b26a741347b33402ad32f5c6735ca0bdYabin Cui * http://www.apache.org/licenses/LICENSE-2.0 967d3abd7b26a741347b33402ad32f5c6735ca0bdYabin Cui * 1067d3abd7b26a741347b33402ad32f5c6735ca0bdYabin Cui * Unless required by applicable law or agreed to in writing, software 1167d3abd7b26a741347b33402ad32f5c6735ca0bdYabin Cui * distributed under the License is distributed on an "AS IS" BASIS, 1267d3abd7b26a741347b33402ad32f5c6735ca0bdYabin Cui * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1367d3abd7b26a741347b33402ad32f5c6735ca0bdYabin Cui * See the License for the specific language governing permissions and 1467d3abd7b26a741347b33402ad32f5c6735ca0bdYabin Cui * limitations under the License. 1567d3abd7b26a741347b33402ad32f5c6735ca0bdYabin Cui */ 1667d3abd7b26a741347b33402ad32f5c6735ca0bdYabin Cui 1767d3abd7b26a741347b33402ad32f5c6735ca0bdYabin Cui#ifndef SIMPLE_PERF_EVENT_H_ 1867d3abd7b26a741347b33402ad32f5c6735ca0bdYabin Cui#define SIMPLE_PERF_EVENT_H_ 1967d3abd7b26a741347b33402ad32f5c6735ca0bdYabin Cui 2067d3abd7b26a741347b33402ad32f5c6735ca0bdYabin Cui#include <stdint.h> 21d115b2f738f2cef352877b26c2d93460ac9fea25Yabin Cui#include <memory> 2267d3abd7b26a741347b33402ad32f5c6735ca0bdYabin Cui#include <string> 2367d3abd7b26a741347b33402ad32f5c6735ca0bdYabin Cui#include <vector> 2467d3abd7b26a741347b33402ad32f5c6735ca0bdYabin Cui 2526968e6c48dea2eaa217991ade5a04e801f1be8fYabin Cui// A uint32_t value far from 0 is picked, so it is unlikely to conflict with further 2626968e6c48dea2eaa217991ade5a04e801f1be8fYabin Cui// PERF_TYPE_* events. 2726968e6c48dea2eaa217991ade5a04e801f1be8fYabin Cuistatic constexpr uint32_t SIMPLEPERF_TYPE_USER_SPACE_SAMPLERS = 32768; 2826968e6c48dea2eaa217991ade5a04e801f1be8fYabin Cui 2926968e6c48dea2eaa217991ade5a04e801f1be8fYabin Cuienum { 3026968e6c48dea2eaa217991ade5a04e801f1be8fYabin Cui SIMPLEPERF_CONFIG_INPLACE_SAMPLER, 3126968e6c48dea2eaa217991ade5a04e801f1be8fYabin Cui}; 3226968e6c48dea2eaa217991ade5a04e801f1be8fYabin Cui 3367d3abd7b26a741347b33402ad32f5c6735ca0bdYabin Cui// EventType represents one type of event, like cpu_cycle_event, cache_misses_event. 3467d3abd7b26a741347b33402ad32f5c6735ca0bdYabin Cui// The user knows one event type by its name, and the kernel knows one event type by its 3567d3abd7b26a741347b33402ad32f5c6735ca0bdYabin Cui// (type, config) pair. EventType connects the two representations, and tells the user if 3667d3abd7b26a741347b33402ad32f5c6735ca0bdYabin Cui// the event type is supported by the kernel. 3767d3abd7b26a741347b33402ad32f5c6735ca0bdYabin Cui 3867d3abd7b26a741347b33402ad32f5c6735ca0bdYabin Cuistruct EventType { 39f569b478e74560a2d9e29a96824e16b93a55b97fYabin Cui EventType(const std::string& name, uint32_t type, uint64_t config) 40f569b478e74560a2d9e29a96824e16b93a55b97fYabin Cui : name(name), type(type), config(config) { 41f569b478e74560a2d9e29a96824e16b93a55b97fYabin Cui } 42f569b478e74560a2d9e29a96824e16b93a55b97fYabin Cui 43f569b478e74560a2d9e29a96824e16b93a55b97fYabin Cui EventType() : type(0), config(0) { 44f569b478e74560a2d9e29a96824e16b93a55b97fYabin Cui } 45f569b478e74560a2d9e29a96824e16b93a55b97fYabin Cui 46f569b478e74560a2d9e29a96824e16b93a55b97fYabin Cui std::string name; 4767d3abd7b26a741347b33402ad32f5c6735ca0bdYabin Cui uint32_t type; 4867d3abd7b26a741347b33402ad32f5c6735ca0bdYabin Cui uint64_t config; 4967d3abd7b26a741347b33402ad32f5c6735ca0bdYabin Cui}; 5067d3abd7b26a741347b33402ad32f5c6735ca0bdYabin Cui 51d115b2f738f2cef352877b26c2d93460ac9fea25Yabin Cuiconst std::vector<EventType>& GetAllEventTypes(); 529fd3cc1048a3d0338df4a48760dfd655560992a1Yabin Cuiconst EventType* FindEventTypeByName(const std::string& name); 53d115b2f738f2cef352877b26c2d93460ac9fea25Yabin Cui 54d115b2f738f2cef352877b26c2d93460ac9fea25Yabin Cuistruct EventTypeAndModifier { 555872ac6f1f5b804ffea38ff59025441618802d6bYabin Cui std::string name; 56d115b2f738f2cef352877b26c2d93460ac9fea25Yabin Cui EventType event_type; 5704d08a35c5e1cabdf6eb7397536a790b0ff44459Yabin Cui std::string modifier; 58d115b2f738f2cef352877b26c2d93460ac9fea25Yabin Cui bool exclude_user; 59d115b2f738f2cef352877b26c2d93460ac9fea25Yabin Cui bool exclude_kernel; 60d115b2f738f2cef352877b26c2d93460ac9fea25Yabin Cui bool exclude_hv; 61d115b2f738f2cef352877b26c2d93460ac9fea25Yabin Cui bool exclude_host; 62d115b2f738f2cef352877b26c2d93460ac9fea25Yabin Cui bool exclude_guest; 63d115b2f738f2cef352877b26c2d93460ac9fea25Yabin Cui int precise_ip : 2; 64d115b2f738f2cef352877b26c2d93460ac9fea25Yabin Cui 65d115b2f738f2cef352877b26c2d93460ac9fea25Yabin Cui EventTypeAndModifier() 66d115b2f738f2cef352877b26c2d93460ac9fea25Yabin Cui : exclude_user(false), 67d115b2f738f2cef352877b26c2d93460ac9fea25Yabin Cui exclude_kernel(false), 68d115b2f738f2cef352877b26c2d93460ac9fea25Yabin Cui exclude_hv(false), 69d115b2f738f2cef352877b26c2d93460ac9fea25Yabin Cui exclude_host(false), 70d115b2f738f2cef352877b26c2d93460ac9fea25Yabin Cui exclude_guest(false), 71d115b2f738f2cef352877b26c2d93460ac9fea25Yabin Cui precise_ip(0) { 72d115b2f738f2cef352877b26c2d93460ac9fea25Yabin Cui } 7367d3abd7b26a741347b33402ad32f5c6735ca0bdYabin Cui}; 7467d3abd7b26a741347b33402ad32f5c6735ca0bdYabin Cui 759fd3cc1048a3d0338df4a48760dfd655560992a1Yabin Cuistd::unique_ptr<EventTypeAndModifier> ParseEventType(const std::string& event_type_str); 76d115b2f738f2cef352877b26c2d93460ac9fea25Yabin Cui 7767d3abd7b26a741347b33402ad32f5c6735ca0bdYabin Cui#endif // SIMPLE_PERF_EVENT_H_ 78