1*288bf522SAndroid Build Coastguard Worker/* 2*288bf522SAndroid Build Coastguard Worker * Copyright (C) 2022 The Android Open Source Project 3*288bf522SAndroid Build Coastguard Worker * 4*288bf522SAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*288bf522SAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*288bf522SAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*288bf522SAndroid Build Coastguard Worker * 8*288bf522SAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*288bf522SAndroid Build Coastguard Worker * 10*288bf522SAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*288bf522SAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*288bf522SAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*288bf522SAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*288bf522SAndroid Build Coastguard Worker * limitations under the License. 15*288bf522SAndroid Build Coastguard Worker */ 16*288bf522SAndroid Build Coastguard Worker 17*288bf522SAndroid Build Coastguard Worker// The file format generated by cmd_report_sample.proto is as below: 18*288bf522SAndroid Build Coastguard Worker// char magic[10] = "SIMPLEPERF"; 19*288bf522SAndroid Build Coastguard Worker// LittleEndian16(version) = 1; 20*288bf522SAndroid Build Coastguard Worker// LittleEndian32(record_size_0) 21*288bf522SAndroid Build Coastguard Worker// message Record(record_0) (having record_size_0 bytes) 22*288bf522SAndroid Build Coastguard Worker// LittleEndian32(record_size_1) 23*288bf522SAndroid Build Coastguard Worker// message Record(record_1) (having record_size_1 bytes) 24*288bf522SAndroid Build Coastguard Worker// ... 25*288bf522SAndroid Build Coastguard Worker// LittleEndian32(record_size_N) 26*288bf522SAndroid Build Coastguard Worker// message Record(record_N) (having record_size_N bytes) 27*288bf522SAndroid Build Coastguard Worker// LittleEndian32(0) 28*288bf522SAndroid Build Coastguard Worker 29*288bf522SAndroid Build Coastguard Workersyntax = "proto2"; 30*288bf522SAndroid Build Coastguard Workeroption optimize_for = LITE_RUNTIME; 31*288bf522SAndroid Build Coastguard Workerpackage simpleperf_report_proto; 32*288bf522SAndroid Build Coastguard Workeroption java_package = "com.android.tools.profiler.proto"; 33*288bf522SAndroid Build Coastguard Workeroption java_outer_classname = "SimpleperfReport"; 34*288bf522SAndroid Build Coastguard Worker 35*288bf522SAndroid Build Coastguard Workermessage Sample { 36*288bf522SAndroid Build Coastguard Worker // Monotonic clock time in nanoseconds. On kernel < 4.1, it's perf clock instead. 37*288bf522SAndroid Build Coastguard Worker optional uint64 time = 1; 38*288bf522SAndroid Build Coastguard Worker optional int32 thread_id = 2; 39*288bf522SAndroid Build Coastguard Worker 40*288bf522SAndroid Build Coastguard Worker message CallChainEntry { 41*288bf522SAndroid Build Coastguard Worker // virtual address of the instruction in elf file 42*288bf522SAndroid Build Coastguard Worker optional uint64 vaddr_in_file = 1; 43*288bf522SAndroid Build Coastguard Worker 44*288bf522SAndroid Build Coastguard Worker // index of the elf file containing the instruction 45*288bf522SAndroid Build Coastguard Worker optional uint32 file_id = 2; 46*288bf522SAndroid Build Coastguard Worker 47*288bf522SAndroid Build Coastguard Worker // symbol_id refers to the name of the function containing the instruction. 48*288bf522SAndroid Build Coastguard Worker // If the function name is found, it is a valid index in the symbol table 49*288bf522SAndroid Build Coastguard Worker // of File with 'id' field being file_id, otherwise it is -1. 50*288bf522SAndroid Build Coastguard Worker optional int32 symbol_id = 3; 51*288bf522SAndroid Build Coastguard Worker 52*288bf522SAndroid Build Coastguard Worker enum ExecutionType { 53*288bf522SAndroid Build Coastguard Worker // methods belong to native libraries, AOT compiled JVM code and ART methods not used near 54*288bf522SAndroid Build Coastguard Worker // JVM methods 55*288bf522SAndroid Build Coastguard Worker NATIVE_METHOD = 0; 56*288bf522SAndroid Build Coastguard Worker INTERPRETED_JVM_METHOD = 1; 57*288bf522SAndroid Build Coastguard Worker JIT_JVM_METHOD = 2; 58*288bf522SAndroid Build Coastguard Worker // ART methods used near JVM methods. It's shown only when --show-art-frames is used. 59*288bf522SAndroid Build Coastguard Worker ART_METHOD = 3; 60*288bf522SAndroid Build Coastguard Worker } 61*288bf522SAndroid Build Coastguard Worker optional ExecutionType execution_type = 4 [default = NATIVE_METHOD]; 62*288bf522SAndroid Build Coastguard Worker } 63*288bf522SAndroid Build Coastguard Worker 64*288bf522SAndroid Build Coastguard Worker repeated CallChainEntry callchain = 3; 65*288bf522SAndroid Build Coastguard Worker 66*288bf522SAndroid Build Coastguard Worker // Simpleperf generates one sample whenever a specified amount of events happen 67*288bf522SAndroid Build Coastguard Worker // while running a monitored thread. So each sample belongs to one event type. 68*288bf522SAndroid Build Coastguard Worker // Event type can be cpu-cycles, cpu-clock, sched:sched_switch or other types. 69*288bf522SAndroid Build Coastguard Worker // By using '-e' option, we can ask simpleperf to record samples for one or more 70*288bf522SAndroid Build Coastguard Worker // event types. 71*288bf522SAndroid Build Coastguard Worker // Each event type generates samples independently. But recording more event types 72*288bf522SAndroid Build Coastguard Worker // will cost more cpu time generating samples, which may affect the monitored threads 73*288bf522SAndroid Build Coastguard Worker // and sample lost rate. 74*288bf522SAndroid Build Coastguard Worker // event_count field shows the count of the events (belong to the sample's event type) 75*288bf522SAndroid Build Coastguard Worker // that have happened since last sample (belong to the sample's event type) for the 76*288bf522SAndroid Build Coastguard Worker // same thread. However, if there are lost samples between current sample and previous 77*288bf522SAndroid Build Coastguard Worker // sample, the event_count is the count of events from the last lost sample. 78*288bf522SAndroid Build Coastguard Worker optional uint64 event_count = 4; 79*288bf522SAndroid Build Coastguard Worker 80*288bf522SAndroid Build Coastguard Worker // An index in meta_info.event_type, shows which event type current sample belongs to. 81*288bf522SAndroid Build Coastguard Worker optional uint32 event_type_id = 5; 82*288bf522SAndroid Build Coastguard Worker 83*288bf522SAndroid Build Coastguard Worker message UnwindingResult { 84*288bf522SAndroid Build Coastguard Worker // error code provided by libunwindstack, in 85*288bf522SAndroid Build Coastguard Worker // https://cs.android.com/android/platform/superproject/+/master:system/unwinding/libunwindstack/include/unwindstack/Error.h 86*288bf522SAndroid Build Coastguard Worker optional uint32 raw_error_code = 1; 87*288bf522SAndroid Build Coastguard Worker // error addr provided by libunwindstack 88*288bf522SAndroid Build Coastguard Worker optional uint64 error_addr = 2; 89*288bf522SAndroid Build Coastguard Worker 90*288bf522SAndroid Build Coastguard Worker // error code interpreted by simpleperf 91*288bf522SAndroid Build Coastguard Worker enum ErrorCode { 92*288bf522SAndroid Build Coastguard Worker ERROR_NONE = 0; // No error 93*288bf522SAndroid Build Coastguard Worker ERROR_UNKNOWN = 1; // Error not interpreted by simpleperf, see raw_error_code 94*288bf522SAndroid Build Coastguard Worker ERROR_NOT_ENOUGH_STACK = 2; // Simpleperf doesn't record enough stack data 95*288bf522SAndroid Build Coastguard Worker ERROR_MEMORY_INVALID = 3; // Memory read failed 96*288bf522SAndroid Build Coastguard Worker ERROR_UNWIND_INFO = 4; // No debug info in binary to support unwinding 97*288bf522SAndroid Build Coastguard Worker ERROR_INVALID_MAP = 5; // Unwind in an invalid map 98*288bf522SAndroid Build Coastguard Worker ERROR_MAX_FRAME_EXCEEDED = 6; // Stopped at MAX_UNWINDING_FRAMES, which is 512. 99*288bf522SAndroid Build Coastguard Worker ERROR_REPEATED_FRAME = 7; // The last frame has the same pc/sp as the next. 100*288bf522SAndroid Build Coastguard Worker ERROR_INVALID_ELF = 8; // Unwind in an invalid elf file 101*288bf522SAndroid Build Coastguard Worker } 102*288bf522SAndroid Build Coastguard Worker optional ErrorCode error_code = 3; 103*288bf522SAndroid Build Coastguard Worker } 104*288bf522SAndroid Build Coastguard Worker 105*288bf522SAndroid Build Coastguard Worker // Unwinding result is provided for samples without a complete callchain, when recorded with 106*288bf522SAndroid Build Coastguard Worker // --keep-failed-unwinding-result or --keep-failed-unwinding-debug-info. 107*288bf522SAndroid Build Coastguard Worker optional UnwindingResult unwinding_result = 6; 108*288bf522SAndroid Build Coastguard Worker} 109*288bf522SAndroid Build Coastguard Worker 110*288bf522SAndroid Build Coastguard Workermessage LostSituation { 111*288bf522SAndroid Build Coastguard Worker optional uint64 sample_count = 1; 112*288bf522SAndroid Build Coastguard Worker optional uint64 lost_count = 2; 113*288bf522SAndroid Build Coastguard Worker} 114*288bf522SAndroid Build Coastguard Worker 115*288bf522SAndroid Build Coastguard Workermessage File { 116*288bf522SAndroid Build Coastguard Worker // unique id for each file, starting from 0, and add 1 each time. 117*288bf522SAndroid Build Coastguard Worker optional uint32 id = 1; 118*288bf522SAndroid Build Coastguard Worker 119*288bf522SAndroid Build Coastguard Worker // file path, like /system/lib/libc.so. 120*288bf522SAndroid Build Coastguard Worker optional string path = 2; 121*288bf522SAndroid Build Coastguard Worker 122*288bf522SAndroid Build Coastguard Worker // symbol table of the file. 123*288bf522SAndroid Build Coastguard Worker repeated string symbol = 3; 124*288bf522SAndroid Build Coastguard Worker 125*288bf522SAndroid Build Coastguard Worker // mangled symbol table of the file. 126*288bf522SAndroid Build Coastguard Worker repeated string mangled_symbol = 4; 127*288bf522SAndroid Build Coastguard Worker} 128*288bf522SAndroid Build Coastguard Worker 129*288bf522SAndroid Build Coastguard Workermessage Thread { 130*288bf522SAndroid Build Coastguard Worker optional uint32 thread_id = 1; 131*288bf522SAndroid Build Coastguard Worker optional uint32 process_id = 2; 132*288bf522SAndroid Build Coastguard Worker optional string thread_name = 3; 133*288bf522SAndroid Build Coastguard Worker} 134*288bf522SAndroid Build Coastguard Worker 135*288bf522SAndroid Build Coastguard Workermessage MetaInfo { 136*288bf522SAndroid Build Coastguard Worker repeated string event_type = 1; 137*288bf522SAndroid Build Coastguard Worker optional string app_package_name = 2; 138*288bf522SAndroid Build Coastguard Worker optional string app_type = 3; // debuggable, profileable or non_profileable 139*288bf522SAndroid Build Coastguard Worker optional string android_sdk_version = 4; 140*288bf522SAndroid Build Coastguard Worker optional string android_build_type = 5; // user, userdebug or eng 141*288bf522SAndroid Build Coastguard Worker 142*288bf522SAndroid Build Coastguard Worker // True if the profile is recorded with --trace-offcpu option. 143*288bf522SAndroid Build Coastguard Worker optional bool trace_offcpu = 6; 144*288bf522SAndroid Build Coastguard Worker} 145*288bf522SAndroid Build Coastguard Worker 146*288bf522SAndroid Build Coastguard Worker// Thread context switch info. It is available when MetaInfo.trace_offcpu = true. 147*288bf522SAndroid Build Coastguard Workermessage ContextSwitch { 148*288bf522SAndroid Build Coastguard Worker // If true, the thread is scheduled on cpu, otherwise it is scheduled off cpu. 149*288bf522SAndroid Build Coastguard Worker optional bool switch_on = 1; 150*288bf522SAndroid Build Coastguard Worker 151*288bf522SAndroid Build Coastguard Worker // Monotonic clock time in nanoseconds. On kernel < 4.1, it's perf clock instead. 152*288bf522SAndroid Build Coastguard Worker optional uint64 time = 2; 153*288bf522SAndroid Build Coastguard Worker optional uint32 thread_id = 3; 154*288bf522SAndroid Build Coastguard Worker} 155*288bf522SAndroid Build Coastguard Worker 156*288bf522SAndroid Build Coastguard Workermessage Record { 157*288bf522SAndroid Build Coastguard Worker oneof record_data { 158*288bf522SAndroid Build Coastguard Worker Sample sample = 1; 159*288bf522SAndroid Build Coastguard Worker LostSituation lost = 2; 160*288bf522SAndroid Build Coastguard Worker File file = 3; 161*288bf522SAndroid Build Coastguard Worker Thread thread = 4; 162*288bf522SAndroid Build Coastguard Worker MetaInfo meta_info = 5; 163*288bf522SAndroid Build Coastguard Worker ContextSwitch context_switch = 6; 164*288bf522SAndroid Build Coastguard Worker } 165*288bf522SAndroid Build Coastguard Worker}