1 // Copyright (C) 2019 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef IORAP_SRC_COMPILER_COMPILER_H_
16 #define IORAP_SRC_COMPILER_COMPILER_H_
17 
18 #include "inode2filename/inode_resolver.h"
19 
20 #include <optional>
21 #include <string>
22 #include <vector>
23 
24 namespace iorap::compiler {
25 struct  CompilationInput {
26   /* The name of the perfetto trace. */
27   std::string filename;
28   /*
29    * The timestamp limit of the trace.
30    * It's used to truncate the trace file.
31    */
32   uint64_t timestamp_limit_ns;
33 
34   /*
35    * The pid of the app.
36    * If positive, it's used to filter out other page cache events.
37    */
38   int32_t pid;
39 };
40 
41 // Compile one or more perfetto TracePacket protobufs that are stored on the filesystem
42 // by the filenames given with `input_file_names` and timestamp limit given with
43 // timestamp_limit_ns.
44 //
45 // For each input file name and timestamp limit, ignore any events from the input that
46 // exceed the associated timestamp limit.
47 //
48 // If blacklist_filter is non-null, ignore any file entries whose file path matches the
49 // regular expression in blacklist_filter.
50 //
51 // The result is stored into the file path specified by `output_file_name`.
52 //
53 // This is a blocking function which returns only when compilation finishes. The return value
54 // determines success/failure.
55 //
56 // Operation is transactional -- that is if there is a failure, `output_file_name` is untouched.
57 bool PerformCompilation(std::vector<iorap::compiler::CompilationInput> perfetto_traces,
58                         std::string output_file_name,
59                         bool output_proto,
60                         std::optional<std::string> blacklist_filter,
61                         inode2filename::InodeResolverDependencies dependencies);
62 
63 // The size and order of timestamp_limit_ns should match that of
64 // input_file_names, if not empty.
65 // If timestamp_limit_ns is empty, will use the max uint64_t.
66 std::vector<CompilationInput> MakeCompilationInputs(
67     std::vector<std::string> input_file_names,
68     std::vector<uint64_t> timestamp_limit_ns,
69     std::vector<int32_t> pids);
70 }
71 
72 #endif  // IORAP_SRC_COMPILER_COMPILER_H_
73