Commit eb46484d authored by Xi Cheng's avatar Xi Cheng Committed by Commit Bot

Replace CallStackProfileBuilder::Module with ModuleCache::Module

Bug: 851163, 804942
Change-Id: I4da05d9c4e3a4c12f8b3c851d074fa3cdf97679f
Reviewed-on: https://chromium-review.googlesource.com/1174953
Commit-Queue: Xi Cheng <chengx@chromium.org>
Reviewed-by: default avatarMike Wittman <wittman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#583111}
parent 41e33062
......@@ -4,10 +4,6 @@
#include "components/metrics/call_stack_profile_builder.h"
#include <stddef.h>
#include <cstring>
#include <map>
#include <string>
#include <utility>
......@@ -17,8 +13,6 @@
#include "base/metrics/metrics_hashes.h"
#include "base/stl_util.h"
using base::StackSamplingProfiler;
namespace metrics {
namespace {
......@@ -80,10 +74,9 @@ uint64_t HashModuleFilename(const base::FilePath& filename) {
// Transcode |sample| into |proto_sample|, using base addresses in |modules| to
// compute module instruction pointer offsets.
void CopySampleToProto(
const CallStackProfileBuilder::Sample& sample,
const std::vector<CallStackProfileBuilder::Module>& modules,
CallStackProfile::Sample* proto_sample) {
void CopySampleToProto(const CallStackProfileBuilder::Sample& sample,
const std::vector<base::ModuleCache::Module>& modules,
CallStackProfile::Sample* proto_sample) {
for (const auto& frame : sample.frames) {
CallStackProfile::Entry* entry = proto_sample->add_entry();
// A frame may not have a valid module. If so, we can't compute the
......@@ -187,17 +180,6 @@ SampledProfile::TriggerEvent ToSampledProfileTriggerEvent(
} // namespace
// CallStackProfileBuilder::Module --------------------------------------------
CallStackProfileBuilder::Module::Module() : base_address(0u) {}
CallStackProfileBuilder::Module::Module(uintptr_t base_address,
const std::string& id,
const base::FilePath& filename)
: base_address(base_address), id(id), filename(filename) {}
CallStackProfileBuilder::Module::~Module() = default;
// CallStackProfileBuilder::Frame ---------------------------------------------
CallStackProfileBuilder::Frame::Frame(uintptr_t instruction_pointer,
......@@ -240,8 +222,8 @@ void CallStackProfileBuilder::RecordAnnotations() {
}
void CallStackProfileBuilder::OnSampleCompleted(
std::vector<StackSamplingProfiler::Frame> frames) {
// Assemble sample_ first.
std::vector<base::StackSamplingProfiler::Frame> frames) {
// Assemble sample_ from |frames| first.
for (const auto& frame : frames) {
const base::ModuleCache::Module& module(frame.module);
if (!module.is_valid) {
......@@ -250,19 +232,18 @@ void CallStackProfileBuilder::OnSampleCompleted(
continue;
}
// Dedup modules.
// Dedup modules and cache them in modules_.
auto loc = module_index_.find(module.base_address);
if (loc == module_index_.end()) {
modules_.emplace_back(module.base_address, module.id, module.filename);
modules_.push_back(module);
size_t index = modules_.size() - 1;
loc = module_index_.insert(std::make_pair(module.base_address, index))
.first;
}
// convert Frames to Frames.
sample_.frames.emplace_back(frame.instruction_pointer, loc->second);
}
// Write CallStackProfile::Sample protocol buffer message.
// Write CallStackProfile::Sample protocol buffer message based on sample_.
int existing_sample_index = -1;
auto location = sample_index_.find(sample_);
if (location != sample_index_.end())
......@@ -306,7 +287,7 @@ void CallStackProfileBuilder::OnProfileCompleted(
module_index_.clear();
sample_index_.clear();
// Assemble SampledProfile protocol buffer message and run the associated
// Assemble the SampledProfile protocol buffer message and run the associated
// callback to pass it.
SampledProfile sampled_profile;
CallStackProfile* proto_profile =
......
......@@ -6,53 +6,31 @@
#define COMPONENTS_METRICS_CALL_STACK_PROFILE_BUILDER_H_
#include <map>
#include <string>
#include <vector>
#include "base/callback.h"
#include "base/files/file_path.h"
#include "base/profiler/stack_sampling_profiler.h"
#include "base/sampling_heap_profiler/module_cache.h"
#include "components/metrics/call_stack_profile_params.h"
#include "third_party/metrics_proto/sampled_profile.pb.h"
namespace metrics {
// CallStackProfileBuilder builds a CallStackProfile from the collected sampling
// data.
//
// The results of the profile building -- a CallStackProfile, is encoded to
// metrics.SampledProfile protocol message. The message is then passed to the
// completed callback. A CallStackProfile contains a set of Samples and Modules,
// and other sampling information. One Sample corresponds to a single recorded
// stack, and the Modules record those modules associated with the recorded
// stack frames.
// CallStackProfileBuilder builds a SampledProfile in the protocol buffer
// message format from the collected sampling data. The message is then passed
// to the completed callback.
// A SampledProfile message (third_party/metrics_proto/sampled_profile.proto)
// contains a CallStackProfile message
// (third_party/metrics_proto/call_stack_profile.proto) and associated profile
// parameters (process/thread/trigger event). A CallStackProfile message
// contains a set of Sample messages and ModuleIdentifier messages, and other
// sampling information. One Sample corresponds to a single recorded stack, and
// the ModuleIdentifiers record those modules associated with the recorded stack
// frames.
class CallStackProfileBuilder
: public base::StackSamplingProfiler::ProfileBuilder {
public:
// Module represents the module (DLL or exe) corresponding to a stack frame.
struct Module {
Module();
Module(uintptr_t base_address,
const std::string& id,
const base::FilePath& filename);
~Module();
// Points to the base address of the module.
uintptr_t base_address;
// An opaque binary string that uniquely identifies a particular program
// version with high probability. This is parsed from headers of the loaded
// module.
// For binaries generated by GNU tools:
// Contents of the .note.gnu.build-id field.
// On Windows:
// GUID + AGE in the debug image headers of a module.
std::string id;
// The filename of the module.
base::FilePath filename;
};
// Frame represents an individual sampled stack frame with module information.
struct Frame {
Frame(uintptr_t instruction_pointer, size_t module_index);
......@@ -153,7 +131,7 @@ class CallStackProfileBuilder
std::map<uintptr_t, size_t> module_index_;
// The distinct modules in the current profile.
std::vector<Module> modules_;
std::vector<base::ModuleCache::Module> modules_;
// The process milestones of a previous sample.
uint32_t milestones_ = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment