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 @@ ...@@ -4,10 +4,6 @@
#include "components/metrics/call_stack_profile_builder.h" #include "components/metrics/call_stack_profile_builder.h"
#include <stddef.h>
#include <cstring>
#include <map>
#include <string> #include <string>
#include <utility> #include <utility>
...@@ -17,8 +13,6 @@ ...@@ -17,8 +13,6 @@
#include "base/metrics/metrics_hashes.h" #include "base/metrics/metrics_hashes.h"
#include "base/stl_util.h" #include "base/stl_util.h"
using base::StackSamplingProfiler;
namespace metrics { namespace metrics {
namespace { namespace {
...@@ -80,9 +74,8 @@ uint64_t HashModuleFilename(const base::FilePath& filename) { ...@@ -80,9 +74,8 @@ uint64_t HashModuleFilename(const base::FilePath& filename) {
// Transcode |sample| into |proto_sample|, using base addresses in |modules| to // Transcode |sample| into |proto_sample|, using base addresses in |modules| to
// compute module instruction pointer offsets. // compute module instruction pointer offsets.
void CopySampleToProto( void CopySampleToProto(const CallStackProfileBuilder::Sample& sample,
const CallStackProfileBuilder::Sample& sample, const std::vector<base::ModuleCache::Module>& modules,
const std::vector<CallStackProfileBuilder::Module>& modules,
CallStackProfile::Sample* proto_sample) { CallStackProfile::Sample* proto_sample) {
for (const auto& frame : sample.frames) { for (const auto& frame : sample.frames) {
CallStackProfile::Entry* entry = proto_sample->add_entry(); CallStackProfile::Entry* entry = proto_sample->add_entry();
...@@ -187,17 +180,6 @@ SampledProfile::TriggerEvent ToSampledProfileTriggerEvent( ...@@ -187,17 +180,6 @@ SampledProfile::TriggerEvent ToSampledProfileTriggerEvent(
} // namespace } // 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 ---------------------------------------------
CallStackProfileBuilder::Frame::Frame(uintptr_t instruction_pointer, CallStackProfileBuilder::Frame::Frame(uintptr_t instruction_pointer,
...@@ -240,8 +222,8 @@ void CallStackProfileBuilder::RecordAnnotations() { ...@@ -240,8 +222,8 @@ void CallStackProfileBuilder::RecordAnnotations() {
} }
void CallStackProfileBuilder::OnSampleCompleted( void CallStackProfileBuilder::OnSampleCompleted(
std::vector<StackSamplingProfiler::Frame> frames) { std::vector<base::StackSamplingProfiler::Frame> frames) {
// Assemble sample_ first. // Assemble sample_ from |frames| first.
for (const auto& frame : frames) { for (const auto& frame : frames) {
const base::ModuleCache::Module& module(frame.module); const base::ModuleCache::Module& module(frame.module);
if (!module.is_valid) { if (!module.is_valid) {
...@@ -250,19 +232,18 @@ void CallStackProfileBuilder::OnSampleCompleted( ...@@ -250,19 +232,18 @@ void CallStackProfileBuilder::OnSampleCompleted(
continue; continue;
} }
// Dedup modules. // Dedup modules and cache them in modules_.
auto loc = module_index_.find(module.base_address); auto loc = module_index_.find(module.base_address);
if (loc == module_index_.end()) { 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; size_t index = modules_.size() - 1;
loc = module_index_.insert(std::make_pair(module.base_address, index)) loc = module_index_.insert(std::make_pair(module.base_address, index))
.first; .first;
} }
// convert Frames to Frames.
sample_.frames.emplace_back(frame.instruction_pointer, loc->second); 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; int existing_sample_index = -1;
auto location = sample_index_.find(sample_); auto location = sample_index_.find(sample_);
if (location != sample_index_.end()) if (location != sample_index_.end())
...@@ -306,7 +287,7 @@ void CallStackProfileBuilder::OnProfileCompleted( ...@@ -306,7 +287,7 @@ void CallStackProfileBuilder::OnProfileCompleted(
module_index_.clear(); module_index_.clear();
sample_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. // callback to pass it.
SampledProfile sampled_profile; SampledProfile sampled_profile;
CallStackProfile* proto_profile = CallStackProfile* proto_profile =
......
...@@ -6,53 +6,31 @@ ...@@ -6,53 +6,31 @@
#define COMPONENTS_METRICS_CALL_STACK_PROFILE_BUILDER_H_ #define COMPONENTS_METRICS_CALL_STACK_PROFILE_BUILDER_H_
#include <map> #include <map>
#include <string>
#include <vector> #include <vector>
#include "base/callback.h" #include "base/callback.h"
#include "base/files/file_path.h"
#include "base/profiler/stack_sampling_profiler.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 "components/metrics/call_stack_profile_params.h"
#include "third_party/metrics_proto/sampled_profile.pb.h" #include "third_party/metrics_proto/sampled_profile.pb.h"
namespace metrics { namespace metrics {
// CallStackProfileBuilder builds a CallStackProfile from the collected sampling // CallStackProfileBuilder builds a SampledProfile in the protocol buffer
// data. // message format from the collected sampling data. The message is then passed
// // to the completed callback.
// The results of the profile building -- a CallStackProfile, is encoded to
// metrics.SampledProfile protocol message. The message is then passed to the // A SampledProfile message (third_party/metrics_proto/sampled_profile.proto)
// completed callback. A CallStackProfile contains a set of Samples and Modules, // contains a CallStackProfile message
// and other sampling information. One Sample corresponds to a single recorded // (third_party/metrics_proto/call_stack_profile.proto) and associated profile
// stack, and the Modules record those modules associated with the recorded // parameters (process/thread/trigger event). A CallStackProfile message
// stack frames. // 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 class CallStackProfileBuilder
: public base::StackSamplingProfiler::ProfileBuilder { : public base::StackSamplingProfiler::ProfileBuilder {
public: 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. // Frame represents an individual sampled stack frame with module information.
struct Frame { struct Frame {
Frame(uintptr_t instruction_pointer, size_t module_index); Frame(uintptr_t instruction_pointer, size_t module_index);
...@@ -153,7 +131,7 @@ class CallStackProfileBuilder ...@@ -153,7 +131,7 @@ class CallStackProfileBuilder
std::map<uintptr_t, size_t> module_index_; std::map<uintptr_t, size_t> module_index_;
// The distinct modules in the current profile. // The distinct modules in the current profile.
std::vector<Module> modules_; std::vector<base::ModuleCache::Module> modules_;
// The process milestones of a previous sample. // The process milestones of a previous sample.
uint32_t milestones_ = 0; 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