// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Performance metrics collected via Chrome's built-in profiler.

syntax = "proto2";

option optimize_for = LITE_RUNTIME;
option java_outer_classname = "ProfilerEventProtos";
option java_package = "org.chromium.components.metrics";

package metrics;

// Next tag: 7
message ProfilerEventProto {
  // The version of this profile.
  enum ProfileVersion {
    VERSION_UNKNOWN = 0;          // Unknown version (should not reach here).
    VERSION_STARTUP_PROFILE = 1;  // Startup profile, logged approximately 60
                                  // seconds after launch.
    VERSION_SPLIT_PROFILE = 2;    // Part of a profile logged in pieces, where
                                  // we finish a piece when a ProfilerEvent or a
                                  // special end-of-recording event gets
                                  // triggered.
  }
  optional ProfileVersion profile_version = 1;

  // The source based upon which "time" measurements are made.
  // We currently only measure wall clock time; but we are exploring other
  // measurement sources as well, such as CPU time or TCMalloc statistics.
  enum TimeSource {
    UNKNOWN_TIME_SOURCE = 0;  // Unknown type (should not reach here).
    WALL_CLOCK_TIME = 1;      // Total time elapsed between the start and end of
                              // the task's execution.
  }
  optional TimeSource time_source = 2;

  // An event in the browser life that causes the client-side profiler framework
  // to finish recording of its current instance of ProfilerEventProto, and
  // start recording a new one.
  // It's not guaranteed that the events get triggered in the order they are
  // defined.
  enum ProfilerEvent {
    // The first non-empty paint of the first web contents happened.
    // Corresponds to the Startup.FirstWebContents.NonEmptyPaint2 histogram.
    EVENT_FIRST_NONEMPTY_PAINT = 0;
  }

  // The set of events, in no particular order, that were triggered in the
  // current Chrome session before the recording of this ProfilerEventProto
  // started. It doesn't include the event that triggered the end of this
  // ProfilerEventProto. A given event will not occur twice in this set.
  // The field can be used to find all ProfilerEventProto instances recorded
  // before or not before a given event.
  repeated ProfilerEvent past_session_event = 4;

  // Time when profiling started. This is recorded as a time delta relative to
  // the start time of the profiler data recording in the current browser
  // session.
  optional int64 profiling_start_ms = 5;

  // Time when profiling finished. This is recorded as a time delta relative to
  // the start time of the profiler data recording in the current browser
  // session.
  optional int64 profiling_finish_ms = 6;

  // Data for a single tracked object (typically, a Task).
  message TrackedObject {
    // The name of the thread from which this task was posted, hashed.
    optional fixed64 birth_thread_name_hash = 1;

    // The name of the thread on which this task was executed, hashed.
    optional fixed64 exec_thread_name_hash = 2;

    // The source file name from which this task was posted, hashed.
    optional fixed64 source_file_name_hash = 3;

    // Function name from which this task was posted, hashed.
    optional fixed64 source_function_name_hash = 4;

    // The line number within the source file from which this task was posted.
    optional int32 source_line_number = 5;

    // The number of times this task was executed.
    optional int32 exec_count = 6;

    // The total execution time for instances this task.
    optional int32 exec_time_total = 7;

    // The execution time for a uniformly randomly sampled instance of this
    // task.
    optional int32 exec_time_sampled = 8;

    // The total time instances this task spent waiting (e.g. in a message loop)
    // before they were run.
    optional int32 queue_time_total = 9;

    // The time that a uniformly randomly sampled instance of this task spent
    // waiting (e.g.  in a message loop) before it was run.
    optional int32 queue_time_sampled = 10;

    // The type of process within which this task was executed.
    enum ProcessType {
      UNKNOWN = 0;  // Should not reach here
      BROWSER = 1;
      RENDERER = 2;
      PLUGIN = 3;  // Deprecated. Should not be sent as of M51 due to
                   // NPAPI removal.
      WORKER = 4;
      NACL_LOADER = 5;
      UTILITY = 6;
      PROFILE_IMPORT = 7;
      ZYGOTE = 8;
      SANDBOX_HELPER = 9;
      NACL_BROKER = 10;
      GPU = 11;
      PPAPI_PLUGIN = 12;
      PPAPI_BROKER = 13;
    }
    optional ProcessType process_type = 11;

    // The local PID for the process within which this task was executed.
    optional uint32 process_id = 12;
  }
  repeated TrackedObject tracked_object = 3;
}
