blob: ec6d9a063b75ee226c5eb9b1f1fce43b6a3806b2 [file] [log] [blame]
// Copyright 2016 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.
#include <memory>
#include <string>
#include <vector>
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/optional.h"
#include "base/threading/thread_checker.h"
#include "base/time/time.h"
#include "chromeos/dbus/pipe_reader.h"
namespace metrics {
// Class for handling getting output from perf over DBus. Manages the
// asynchronous DBus call and retrieving data from quipper over a pipe.
class PerfOutputCall {
// Called once GetPerfOutput() is complete, or an error occurred.
// The callback may delete this object.
// The argument is one of:
// - Output from "perf record", in PerfDataProto format, OR
// - Output from "perf stat", in PerfStatProto format, OR
// - The empty string if there was an error.
using DoneCallback = base::OnceCallback<void(const std::string& perf_stdout)>;
PerfOutputCall(base::TimeDelta duration,
const std::vector<std::string>& perf_args,
DoneCallback callback);
// Internal callbacks.
void OnIOComplete(base::Optional<std::string> data);
void OnGetPerfOutput(base::Optional<uint64_t> result);
// Used to capture perf data written to a pipe.
std::unique_ptr<chromeos::PipeReader> perf_data_pipe_reader_;
// Saved arguments.
base::TimeDelta duration_;
std::vector<std::string> perf_args_;
DoneCallback done_callback_;
// To pass around the "this" pointer across threads safely.
base::WeakPtrFactory<PerfOutputCall> weak_factory_;
} // namespace metrics