1 // Copyright (C) 2017 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 PREFETCHER_READAHEAD_H_ 16 #define PREFETCHER_READAHEAD_H_ 17 18 #include <memory> 19 #include <optional> 20 21 namespace android { 22 class Printer; 23 } // namespace android 24 25 namespace iorap { 26 namespace prefetcher { 27 28 struct TaskId; 29 struct ReadAheadFileEntry; 30 31 // Manage I/O readahead for a task. 32 class ReadAhead { 33 struct Impl; 34 public: 35 // Process a task *now*. Currently will block until all readaheads have been 36 // issued for all entries in that task. 37 // 38 // Any memory mapped or file descriptors opened as a side effect must be 39 // cleaned up with #FinishTask. 40 void BeginTask(const TaskId& id); 41 // Complete a task, releasing any memory/file descriptors associated with it. 42 void FinishTask(const TaskId& id); 43 44 static void Dump(/*borrow*/::android::Printer& printer); 45 46 // Calculate the sum of file_lengths. Returns nullopt if the file path does not 47 // point to a valid compiled TraceFile. 48 static std::optional<size_t> PrefetchSizeInBytes(const std::string& file_path); 49 50 ReadAhead(bool use_sockets); 51 52 ReadAhead(); 53 ~ReadAhead(); 54 private: 55 void BeginTaskForSockets(const TaskId& id, int32_t trace_cookie); 56 std::unique_ptr<Impl> impl_; 57 }; 58 59 } // namespace prefetcher 60 } // namespace iorap 61 62 #endif 63 64