1// Copyright 2016 The Chromium OS Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#ifndef CHROMIUMOS_WIDE_PROFILING_DSO_H_ 6#define CHROMIUMOS_WIDE_PROFILING_DSO_H_ 7 8#include <sys/stat.h> 9 10#include <unordered_set> 11#include <utility> 12 13#include "compat/string.h" 14#include "data_reader.h" 15 16namespace quipper { 17 18// Defines a type for a pid:tid pair. 19using PidTid = std::pair<u32, u32>; 20 21// A struct containing all relevant info for a mapped DSO, independent of any 22// samples. 23struct DSOInfo { 24 string name; 25 string build_id; 26 u32 maj = 0; 27 u32 min = 0; 28 u64 ino = 0; 29 bool hit = false; // Have we seen any samples in this DSO? 30 // unordered_set of pids this DSO had samples in. 31 std::unordered_set<uint64_t> threads; 32}; 33 34// Do the |DSOInfo| and |struct stat| refer to the same inode? 35bool SameInode(const DSOInfo& dso, const struct stat* s); 36 37// Must be called at least once before using libelf. 38void InitializeLibelf(); 39// Read buildid from an ELF file using libelf. 40bool ReadElfBuildId(const string& filename, string* buildid); 41bool ReadElfBuildId(int fd, string* buildid); 42 43// Read buildid from /sys/module/<module_name>/notes/.note.gnu.build-id 44// (Does not use libelf.) 45bool ReadModuleBuildId(const string& module_name, string* buildid); 46// Read builid from Elf note data section. 47bool ReadBuildIdNote(DataReader* data, string* buildid); 48 49// Is |name| match one of the things reported by the kernel that is known 50// not to be a kernel module? 51bool IsKernelNonModuleName(string name); 52 53} // namespace quipper 54 55#endif // CHROMIUMOS_WIDE_PROFILING_DSO_H_ 56