Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions src/builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
#include <utility>
#include <vector>

#include <unordered_map>
#include <unordered_set>
#include "absl/container/flat_hash_map.h"
#include "absl/container/flat_hash_set.h"
#include "absl/strings/string_view.h"

#include "src/quipper/base/logging.h"
#include "google/protobuf/io/gzip_stream.h"
Expand All @@ -31,13 +32,9 @@ using google::protobuf::RepeatedField;

namespace perftools {
namespace profiles {
typedef std::unordered_map<uint64, uint64> IndexMap;
typedef std::unordered_set<uint64> IndexSet;
} // namespace profiles
} // namespace perftools

namespace perftools {
namespace profiles {
typedef absl::flat_hash_map<uint64_t, uint64_t> IndexMap;
typedef absl::flat_hash_set<uint64_t> IndexSet;

void AddCallstackToSample(Sample *sample, const void *const *stack, int depth,
CallstackType type) {
Expand All @@ -59,14 +56,14 @@ Builder::Builder() : profile_(new Profile()) {
profile_->add_string_table("");
}

int64_t Builder::StringId(const char *str) {
if (str == nullptr || !str[0]) {
int64_t Builder::StringId(absl::string_view str) {
if (str.empty()) {
return 0;
}
return InternalStringId(str);
}

int64_t Builder::InternalStringId(const std::string &str) {
int64_t Builder::InternalStringId(absl::string_view str) {
const int64_t index = profile_->string_table_size();
const auto inserted = strings_.emplace(str, index);
if (!inserted.second) {
Expand Down
42 changes: 12 additions & 30 deletions src/builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,40 +16,19 @@
#include <tuple>
#include <utility>

#include <unordered_map>

namespace perftools {
namespace profiles {

typedef int64_t int64;
typedef uint64_t uint64;
typedef std::string string;

typedef std::unordered_map<string, int64> StringIndexMap;

class FunctionHasher {
public:
size_t operator()(const std::tuple<int64, int64, int64, int64> &f) const {
int64 hash = std::get<0>(f);
hash = hash + ((hash << 8) ^ std::get<1>(f));
hash = hash + ((hash << 8) ^ std::get<2>(f));
hash = hash + ((hash << 8) ^ std::get<3>(f));
return static_cast<size_t>(hash);
}
};

typedef std::unordered_map<std::tuple<int64, int64, int64, int64>, int64,
FunctionHasher>
FunctionIndexMap;

} // namespace profiles
} // namespace perftools
#include "absl/container/flat_hash_map.h"
#include "absl/strings/string_view.h"

#include "src/profile.pb.h"

namespace perftools {
namespace profiles {

typedef absl::flat_hash_map<std::string, int64_t> StringIndexMap;
typedef absl::flat_hash_map<std::tuple<int64_t, int64_t, int64_t, int64_t>,
int64_t>
FunctionIndexMap;

enum CallstackType { kRegular = 0, kInterrupt = 1 };

void AddCallstackToSample(Sample *sample, const void *const *stack, int depth,
Expand All @@ -68,7 +47,10 @@ class Builder {

// Adds a string to the profile string table if not already present.
// Returns a unique integer id for this string.
int64_t StringId(const char *str);
int64_t StringId(const char* str) {
return StringId(absl::NullSafeStringView(str));
}
int64_t StringId(absl::string_view str);

// Adds a function with these attributes to the profile function
// table, if not already present. Returns a unique integer id for
Expand Down Expand Up @@ -123,7 +105,7 @@ class Builder {
Profile *mutable_profile() { return profile_.get(); }

private:
int64_t InternalStringId(const std::string &str);
int64_t InternalStringId(absl::string_view str);

// Maps to deduplicate strings and functions.
StringIndexMap strings_;
Expand Down
4 changes: 2 additions & 2 deletions src/perf_data_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -759,8 +759,8 @@ static bool IsVirtualMapping(const std::string& map_name) {
void Normalizer::ConvertMmapFromKsymbol(
const quipper::PerfDataProto_KsymbolEvent& ksymbol_event, uint32_t prot,
quipper::PerfDataProto_MMapEvent* mmap) {
uint32_t pid = 1;
uint32_t tid = 1;
uint32_t pid = kKernelPid;
uint32_t tid = 0;
uint32_t flags = 0;
uint64_t pgoff = 0;
mmap->set_pid(pid);
Expand Down
4 changes: 0 additions & 4 deletions src/quipper/huge_page_deducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ bool IsAnon(const MMapEvent& event) {
bool is_anon = (event.filename() == kAnonFilename ||
event.filename() == kAnonHugepageFilename ||
event.filename() == kAnonHugepageDeletedFilename);
if (is_anon && event.pgoff() != 0) {
LOG(WARNING) << "//anon should have offset=0 for mmap "
<< event.ShortDebugString();
}
return is_anon;
}

Expand Down
Loading