blob: e1eef9e47284821e302c3b25ea34a4a116604cd3 [file] [log] [blame]
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef TOOLS_TRACE_TO_TEXT_LOCAL_SYMBOLIZER_H_
#define TOOLS_TRACE_TO_TEXT_LOCAL_SYMBOLIZER_H_
#include <map>
#include <string>
#include <vector>
#include "perfetto/ext/base/optional.h"
#include "perfetto/ext/base/pipe.h"
#include "perfetto/profiling/symbolizer.h"
namespace perfetto {
namespace trace_to_text {
class LocalBinaryFinder {
public:
LocalBinaryFinder(std::vector<std::string> roots)
: roots_(std::move(roots)) {}
base::Optional<std::string> FindBinary(const std::string& abspath,
const std::string& build_id);
private:
bool IsCorrectFile(const std::string& symbol_file,
const std::string& build_id);
base::Optional<std::string> FindBinaryInRoot(const std::string& root_str,
const std::string& abspath,
const std::string& build_id);
private:
std::vector<std::string> roots_;
std::map<std::string, base::Optional<std::string>> cache_;
};
class Subprocess {
public:
Subprocess(const std::string& file, std::vector<std::string> args);
~Subprocess();
int read_fd() { return output_pipe_.rd.get(); }
int write_fd() { return input_pipe_.wr.get(); }
private:
base::Pipe input_pipe_;
base::Pipe output_pipe_;
pid_t pid_ = -1;
};
class LLVMSymbolizerProcess {
public:
LLVMSymbolizerProcess();
std::vector<SymbolizedFrame> Symbolize(const std::string& binary,
uint64_t address);
private:
Subprocess subprocess_;
FILE* read_file_;
};
class LocalSymbolizer : public Symbolizer {
public:
LocalSymbolizer(std::vector<std::string> roots) : finder_(std::move(roots)) {}
std::vector<std::vector<SymbolizedFrame>> Symbolize(
const std::string& mapping_name,
const std::string& build_id,
const std::vector<uint64_t>& address) override;
~LocalSymbolizer() override;
private:
LLVMSymbolizerProcess llvm_symbolizer_;
LocalBinaryFinder finder_;
};
} // namespace trace_to_text
} // namespace perfetto
#endif // TOOLS_TRACE_TO_TEXT_LOCAL_SYMBOLIZER_H_