172a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
272a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen// Use of this source code is governed by a BSD-style license that can be
372a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen// found in the LICENSE file.
472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
572a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen#ifndef CHROME_COMMON_PROFILING_H_
672a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen#define CHROME_COMMON_PROFILING_H_
772a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen#pragma once
872a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
972a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen#include "build/build_config.h"
1072a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
1172a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen#include "base/basictypes.h"
1272a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen#include "base/debug/profiler.h"
1372a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
1472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen// The Profiling class manages the interaction with a sampling based profiler.
1572a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen// Its function is controlled by the kProfilingAtStart, kProfilingFile, and
1672a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen// kProfilingFlush command line values.
1772a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen// All of the API should only be called from the main thread of the process.
1872a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsenclass Profiling {
1972a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen public:
2072a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // Called early in a process' life to allow profiling of startup time.
2172a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // the presence of kProfilingAtStart is checked.
2272a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  static void ProcessStarted();
2372a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
2472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // Start profiling.
2572a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  static void Start();
2672a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
2772a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // Stop profiling and write out profiling file.
2872a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  static void Stop();
2972a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
3072a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // Returns true if the process is being profiled.
3172a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  static bool BeingProfiled();
3272a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
3372a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // Called when the main message loop is started, so that automatic flushing
3472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // of the profile data file can be done.
3572a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  static void MainMessageLoopStarted();
3672a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
3772a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // Toggle profiling on/off.
3872a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  static void Toggle();
3972a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
4072a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen private:
4172a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  // Do not instantiate this class.
4272a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  Profiling();
4372a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
4472a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen  DISALLOW_COPY_AND_ASSIGN(Profiling);
4572a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen};
4672a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
4772a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen#endif  // CHROME_COMMON_PROFILING_H_
4872a454cd3513ac24fbdd0e0cb9ad70b86a99b801Kristian Monsen
49