• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "tools/trace_to_text/symbolize_profile.h"
18 
19 #include <vector>
20 
21 #include "perfetto/base/logging.h"
22 #include "perfetto/trace_processor/trace_processor.h"
23 
24 #include "src/profiling/symbolizer/symbolize_database.h"
25 #include "src/profiling/symbolizer/symbolizer.h"
26 #include "src/profiling/symbolizer/local_symbolizer.h"
27 
28 #include "protos/perfetto/trace/trace.pbzero.h"
29 #include "protos/perfetto/trace/trace_packet.pbzero.h"
30 #include "tools/trace_to_text/utils.h"
31 
32 namespace perfetto {
33 namespace trace_to_text {
34 
35 // Ingest profile, and emit a symbolization table for each sequence. This can
36 // be prepended to the profile to attach the symbol information.
SymbolizeProfile(std::istream * input,std::ostream * output)37 int SymbolizeProfile(std::istream* input, std::ostream* output) {
38   std::unique_ptr<profiling::Symbolizer> symbolizer =
39       profiling::LocalSymbolizerOrDie(profiling::GetPerfettoBinaryPath(),
40                                       getenv("PERFETTO_SYMBOLIZER_MODE"));
41 
42   if (!symbolizer)
43     PERFETTO_FATAL("No symbolizer selected");
44   trace_processor::Config config;
45   std::unique_ptr<trace_processor::TraceProcessor> tp =
46       trace_processor::TraceProcessor::CreateInstance(config);
47 
48   if (!ReadTrace(tp.get(), input))
49     PERFETTO_FATAL("Failed to read trace.");
50 
51   tp->NotifyEndOfFile();
52 
53   SymbolizeDatabase(
54       tp.get(), symbolizer.get(),
55       [output](const std::string& trace_proto) { *output << trace_proto; });
56   return 0;
57 }
58 
59 }  // namespace trace_to_text
60 }  // namespace perfetto
61