1// Copyright 2014 The Chromium Authors 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5syntax = "proto2"; 6 7option optimize_for = LITE_RUNTIME; 8option java_package = "org.chromium.components.metrics"; 9 10option java_outer_classname = "PerfDataProtos"; 11 12package metrics; 13 14// Stores information from a perf session generated via running: 15// "perf record" 16// 17// See $kernel/tools/perf/design.txt for more details. 18 19// This is a read-only copy of the upstream protobuf; "Next tag:" comments are 20// absent. 21message PerfDataProto { 22 // Perf event attribute. Stores the event description. 23 // This data structure is defined in the linux kernel: 24 // $kernel/include/uapi/linux/perf_event.h. 25 message PerfEventAttr { 26 // Type of the event. Type is an enumeration and can be one of the values 27 // described at: $kernel/include/linux/perf_event.h. 28 // Example types are: 29 // PERF_TYPE_HARDWARE 30 // PERF_TYPE_SOFTWARE, etc. 31 optional uint32 type = 1; 32 33 // Size of the event data in bytes. 34 optional uint32 size = 2; 35 36 // The config stores the CPU-specific counter information. 37 optional uint64 config = 3; 38 39 // Sample period of the event. Indicates how often the event is 40 // triggered in terms of # of events. After |sample_period| events, an event 41 // will be recorded and stored. 42 optional uint64 sample_period = 4; 43 44 // Sample frequency of the event. Indicates how often the event is 45 // triggered in terms of # per second. The kernel will try to record 46 // |sample_freq| events per second. 47 optional uint64 sample_freq = 5; 48 49 // Sample type is a bitfield that records attributes of the sample. Example, 50 // whether an entire callchain was recorded, etc. 51 optional uint64 sample_type = 6; 52 53 // Bitfield that indicates whether reads on the counter will return the 54 // total time enabled and total time running. 55 optional uint64 read_format = 7; 56 57 // Indicates whether the counter starts off disabled. 58 optional bool disabled = 8; 59 60 // Indicates whether child processes inherit the counter. 61 optional bool inherit = 9; 62 63 // Indicates whether the counter is pinned to a particular CPU. 64 optional bool pinned = 10; 65 66 // Indicates whether this counter's group has exclusive access to the CPU's 67 // counters. 68 optional bool exclusive = 11; 69 70 // The following bits restrict events to be counted when the CPU is in user, 71 // kernel, hypervisor or idle modes. 72 optional bool exclude_user = 12; 73 optional bool exclude_kernel = 13; 74 optional bool exclude_hv = 14; 75 optional bool exclude_idle = 15; 76 77 // Indicates whether mmap events should be recorded. 78 optional bool mmap = 16; 79 80 // Indicates whether process comm information should be recorded upon 81 // process creation. 82 optional bool comm = 17; 83 84 // Indicates that we are in frequency mode, not period mode. 85 optional bool freq = 18; 86 87 // Indicates whether we have per-task counts. 88 optional bool inherit_stat = 19; 89 90 // Indicates whether we enable perf events after an exec() function call. 91 optional bool enable_on_exec = 20; 92 93 // Indicates whether we trace fork/exit. 94 optional bool task = 21; 95 96 // Indicates whether we are using a watermark to wake up. 97 optional bool watermark = 22; 98 99 // CPUs often "skid" when recording events. That means the instruction 100 // pointer may not be the same as the one that caused the counter overflow. 101 // Indicates the capabilities of the CPU in terms of recording precise 102 // instruction pointer. 103 optional uint32 precise_ip = 23; 104 105 // Indicates whether we have non-exec mmap data. 106 optional bool mmap_data = 24; 107 108 // If set, all the event types will have the same sample_type. 109 optional bool sample_id_all = 25; 110 111 // Indicates whether we are counting events from the host (when running a 112 // VM). 113 optional bool exclude_host = 26; 114 115 // Exclude events that happen on a guest OS. 116 optional bool exclude_guest = 27; 117 118 // Contains the number of events after which we wake up. 119 optional uint32 wakeup_events = 28; 120 121 // Contains the number of bytes after which we wake up. 122 optional uint32 wakeup_watermark = 29; 123 124 // Information about the type of the breakpoint. 125 optional uint32 bp_type = 30; 126 127 // Contains the breakpoint address. 128 optional uint64 bp_addr = 31; 129 130 // This is an extension of config (see above). 131 optional uint64 config1 = 32; 132 133 // The length of the breakpoint data in bytes. 134 optional uint64 bp_len = 33; 135 136 // This is an extension of config (see above). 137 optional uint64 config2 = 34; 138 139 // Contains the type of branch, example: user, kernel, call, return, etc. 140 optional uint64 branch_sample_type = 35; 141 } 142 143 // Describes a perf.data file attribute. 144 message PerfFileAttr { 145 optional PerfEventAttr attr = 1; 146 147 // List of perf file attribute ids. Each id describes an event. 148 repeated uint64 ids = 2; 149 } 150 151 // Protobuf version of the perf_event_type struct found in perf/util/event.h. 152 // Contains the name of the event (such as "cycles" or "branch-misses") and 153 // the event id (which is not unique). 154 message PerfEventType { 155 // Event id. This is not unique across event types. 156 // The combination of the event id and the type field in PerfEventAttr is 157 // unique across event types. 158 optional uint64 id = 1; 159 160 // Event name's md5 prefix. 161 // The event name string was field 2 and has been intentionally left out. 162 optional uint64 name_md5_prefix = 3; 163 } 164 165 // This message contains information about a perf sample itself, as opposed to 166 // a perf event captured by a sample. 167 message SampleInfo { 168 // Process ID / thread ID from which this sample was taken. 169 optional uint32 pid = 1; 170 optional uint32 tid = 2; 171 172 // Time this sample was taken (NOT the same as an event time). 173 // It is the number of nanoseconds since bootup. 174 optional uint64 sample_time_ns = 3; 175 176 // The ID of the sample's event type (cycles, instructions, etc). 177 // The event type IDs are defined in PerfFileAttr. 178 optional uint64 id = 4; 179 180 // The CPU on which this sample was taken. 181 optional uint32 cpu = 5; 182 } 183 184 message CommEvent { 185 // Process id. 186 optional uint32 pid = 1; 187 188 // Thread id. 189 optional uint32 tid = 2; 190 191 // Comm string's md5 prefix. 192 // The comm string was field 3 and has been intentionally left out. 193 optional uint64 comm_md5_prefix = 4; 194 195 // Time the sample was taken. 196 // Deprecated, use |sample_info| instead. 197 optional uint64 sample_time = 5 [deprecated = true]; 198 199 // Info about the perf sample containing this event. 200 optional SampleInfo sample_info = 6; 201 } 202 203 message MMapEvent { 204 // Process id. 205 optional uint32 pid = 1; 206 207 // Thread id. 208 optional uint32 tid = 2; 209 210 // Start address. 211 optional uint64 start = 3; 212 213 // Length. 214 optional uint64 len = 4; 215 216 // PG Offset. 217 optional uint64 pgoff = 5; 218 219 // Not added from original: fields 9-14. 220 221 // Filename's md5 prefix. 222 // The filename was field 6 and has been intentionally left out. 223 optional uint64 filename_md5_prefix = 7; 224 225 // Root path's md5 prefix. It helps to categorize filenames we could not 226 // recover by the filename_md5_prefix. 227 // The root_path was field 15 and has been intentionally left out. 228 optional uint64 root_path_md5_prefix = 16; 229 230 // Info about the perf sample containing this event. 231 optional SampleInfo sample_info = 8; 232 } 233 234 // The kernel collects the number of events it couldn't send in a stretch and 235 // when possible sends this number in a PERF_RECORD_LOST event, which is 236 // stored in LostEvent. 237 message LostEvent { 238 // ID of the event which has been lost. This should be an id found in a 239 // PerfFileAttr. 240 optional uint64 id = 1; 241 242 // Number of events that were lost. 243 optional uint64 lost = 2; 244 245 // Info about the perf sample containing this event. 246 optional SampleInfo sample_info = 3; 247 } 248 249 message ThrottleEvent { 250 // Time of throttle event, in nanoseconds since system startup. 251 optional uint64 time_ns = 1; 252 253 // Event ID. 254 optional uint64 id = 2; 255 256 // Stream ID. 257 optional uint64 stream_id = 3; 258 259 // Info about the perf sample containing this event. 260 optional SampleInfo sample_info = 4; 261 } 262 263 message BranchStackEntry { 264 // Branch source address. 265 optional uint64 from_ip = 1; 266 267 // Branch destination address. 268 optional uint64 to_ip = 2; 269 270 // Indicates a mispredicted branch. 271 optional bool mispredicted = 3; 272 273 // Indicates a predicted branch. 274 optional bool predicted = 4; 275 276 // Indicates running in a hardware transaction 277 optional bool in_transaction = 5; 278 279 // Indicates aborting a hardware transaction 280 optional bool abort = 6; 281 282 // Cycle count to last branch 283 optional uint32 cycles = 7; 284 } 285 286 message SampleEvent { 287 // Instruction pointer. 288 optional uint64 ip = 1; 289 290 // Process id. 291 optional uint32 pid = 2; 292 293 // Thread id. 294 optional uint32 tid = 3; 295 296 // The time after boot when the sample was recorded, in nanoseconds. 297 optional uint64 sample_time_ns = 4; 298 299 // The address of the sample. 300 optional uint64 addr = 5; 301 302 // The id of the sample. 303 optional uint64 id = 6; 304 305 // The stream id of the sample. 306 optional uint64 stream_id = 7; 307 308 // The period of the sample. 309 optional uint64 period = 8; 310 311 // The CPU where the event was recorded. 312 optional uint32 cpu = 9; 313 314 // The raw size of the event in bytes. 315 optional uint32 raw_size = 10; 316 317 // Not added from original: field 18. 318 319 // Sample callchain info. 320 repeated uint64 callchain = 11; 321 322 // Branch stack info. 323 repeated BranchStackEntry branch_stack = 12; 324 325 // Not added from original: fields 13 and 14. 326 327 // Sample weight for special events. 328 optional uint64 weight = 15; 329 330 // Sample data source flags. 331 // Possible flag values: 332 // http://lxr.free-electrons.com/source/include/uapi/linux/perf_event.h#L849 333 optional uint64 data_src = 16; 334 335 // Sample transaction flags for special events. 336 // Flag fields: 337 // http://lxr.free-electrons.com/source/include/uapi/linux/perf_event.h#L209 338 optional uint64 transaction = 17; 339 340 // Not added from original: fields 19-25. 341 } 342 343 // ForkEvent is used for both FORK and EXIT events, which have the same data 344 // format. We don't want to call this "ForkOrExitEvent", in case a separate 345 // exit event is introduced in the future. 346 message ForkEvent { 347 // Forked process ID. 348 optional uint32 pid = 1; 349 350 // Parent process ID. 351 optional uint32 ppid = 2; 352 353 // Forked process thread ID. 354 optional uint32 tid = 3; 355 356 // Parent process thread ID. 357 optional uint32 ptid = 4; 358 359 // Time of fork event in nanoseconds since bootup. 360 optional uint64 fork_time_ns = 5; 361 362 // Info about the perf sample containing this event. 363 optional SampleInfo sample_info = 11; 364 } 365 366 message EventHeader { 367 // Type of event. 368 optional uint32 type = 1; 369 optional uint32 misc = 2; 370 // Size of event. 371 optional uint32 size = 3; 372 } 373 374 message PerfEvent { 375 optional EventHeader header = 1; 376 oneof event_type { 377 MMapEvent mmap_event = 2; 378 SampleEvent sample_event = 3; 379 CommEvent comm_event = 4; 380 // FORK and EXIT events are structurally identical. They only differ by 381 // the event type. But using two distinct fields allows us to 382 // differentiate between them without having to check the event type under 383 // |header|. 384 ForkEvent fork_event = 5; 385 ForkEvent exit_event = 9; 386 LostEvent lost_event = 6; 387 ThrottleEvent throttle_event = 7; 388 389 // Not added from original: fields 8, 11-24. 390 } 391 // Time after boot in nanoseconds corresponding to the event. 392 optional uint64 timestamp = 10; 393 } 394 395 message PerfEventStats { 396 // Total number of events read from perf data. 397 optional uint32 num_events_read = 1; 398 399 // Total number of various types of events. 400 optional uint32 num_sample_events = 2; 401 optional uint32 num_mmap_events = 3; 402 optional uint32 num_fork_events = 4; 403 optional uint32 num_exit_events = 5; 404 405 // Number of sample events that were successfully mapped by the address 406 // mapper, a quipper module that is used to obscure addresses and convert 407 // them to DSO name + offset. Sometimes it fails to process sample events. 408 // This field allows us to track the success rate of the address mapper. 409 optional uint32 num_sample_events_mapped = 6; 410 411 // Whether address remapping was enabled. 412 optional bool did_remap = 7; 413 } 414 415 message PerfBuildID { 416 // Misc field in perf_event_header. 417 // Indicates whether the file is mapped in kernel mode or user mode. 418 optional uint32 misc = 1; 419 420 // Process ID. 421 optional uint32 pid = 2; 422 423 // Build id. Should always contain kBuildIDArraySize bytes of data. 424 // perf_reader.h defines kBuildIDArraySize = 20. 425 optional bytes build_id_hash = 3; 426 427 // Filename Md5sum prefix. 428 // The filename was field 4 and has been intentionally left out. 429 optional uint64 filename_md5_prefix = 5; 430 431 // Not added from original: field 6. 432 } 433 434 message PerfPMUMappingsMetadata { 435 // Mapping type. 436 // It is a number the kernel uses to map to PMU devices when initializing 437 // them. It is used to reconstruct the event type across different machines. 438 optional uint32 type = 1; 439 440 // The mapping name, field 2, has been intentionally left out. 441 442 // Mapping name's md5 prefix. 443 optional uint64 name_md5_prefix = 3; 444 } 445 446 message PerfHybridTopologyMetadata { 447 // The pmu name, field 1, has been intentionally left out. 448 449 // The 16 most significant bytes of the pmu name's md5 prefix. 450 optional uint64 pmu_name_md5_prefix = 2; 451 452 // The string version of cpus, field 3, has been intentionally left out. 453 454 // A range of cpu numbers for this pmu. 455 repeated uint32 cpu_list = 4 [packed = true]; 456 } 457 458 repeated PerfFileAttr file_attrs = 1; 459 repeated PerfEvent events = 2; 460 461 repeated PerfEventType event_types = 10; 462 463 // Time when quipper generated this perf data / protobuf, given as seconds 464 // since the epoch. 465 optional uint64 timestamp_sec = 3; 466 467 // Records some stats about the serialized perf events. 468 optional PerfEventStats stats = 4; 469 470 // Not added from original: repeated uint64 metadata_mask = 5; 471 // Not added from original: optional PerfTracingMetadata tracing_data = 14; 472 473 // Build ID metadata. 474 repeated PerfBuildID build_ids = 7; 475 476 // Not added from original: repeated PerfUint32Metadata uint32_metadata = 8; 477 // Not added from original: repeated PerfUint64Metadata uint64_metadata = 9; 478 // Not added from original: 479 // optional PerfCPUTopologyMetadata cpu_topology = 11; 480 // Not added from original: 481 // repeated PerfNodeTopologyMetadata numa_topology = 12; 482 483 repeated PerfPMUMappingsMetadata pmu_mappings = 15; 484 485 // Not added from original: repeated PerfGroupDescMetadata group_desc = 16; 486 487 repeated PerfHybridTopologyMetadata hybrid_topology = 17; 488 489 message StringMetadata { 490 message StringAndMd5sumPrefix { 491 // The string value was field 1 and has been intentionally left out. 492 493 // The string value's md5sum prefix. 494 optional uint64 value_md5_prefix = 2; 495 } 496 497 // Not added from original: optional StringAndMd5sumPrefix hostname = 1; 498 // Not added from original: 499 // optional StringAndMd5sumPrefix kernel_version =2; 500 // Not added from original: optional StringAndMd5sumPrefix perf_version = 3; 501 // Not added from original: optional StringAndMd5sumPrefix architecture = 4; 502 // Not added from original: 503 // optional StringAndMd5sumPrefix cpu_description = 5; 504 // Not added from original: optional StringAndMd5sumPrefix cpu_id = 6; 505 // Not added from original: 506 // repeated StringAndMd5sumPrefix perf_command_line_token = 7; 507 508 // The command line stored as a single string. 509 optional StringAndMd5sumPrefix perf_command_line_whole = 8; 510 } 511 512 // All the string metadata from the perf data file. 513 optional StringMetadata string_metadata = 13; 514} 515