1 /* 2 * Copyright (C) 2024 The Android Open Source Project 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 #ifndef SRC_TRACE_PROCESSOR_IMPORTERS_PERF_TIME_CONV_RECORD_H_ 18 #define SRC_TRACE_PROCESSOR_IMPORTERS_PERF_TIME_CONV_RECORD_H_ 19 20 #include <cstdint> 21 22 namespace perfetto::trace_processor::perf_importer { 23 24 struct TimeConvRecord { 25 uint64_t time_shift; 26 uint64_t time_mult; 27 uint64_t time_zero; 28 uint64_t time_cycles; 29 uint64_t time_mask; 30 uint8_t cap_user_time_zero; 31 uint8_t cap_user_time_short; 32 uint8_t reserved[6]; // alignment 33 ConvertTscToPerfTimeTimeConvRecord34 uint64_t ConvertTscToPerfTime(uint64_t cycles) const { 35 uint64_t quot, rem; 36 37 if (cap_user_time_short) { 38 cycles = time_cycles + ((cycles - time_cycles) & time_mask); 39 } 40 41 quot = cycles >> time_shift; 42 rem = cycles & ((uint64_t(1) << time_shift) - 1); 43 return time_zero + quot * time_mult + ((rem * time_mult) >> time_shift); 44 } 45 }; 46 47 } // namespace perfetto::trace_processor::perf_importer 48 49 #endif // SRC_TRACE_PROCESSOR_IMPORTERS_PERF_TIME_CONV_RECORD_H_ 50