1 /* 2 * Copyright (C) 2022 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 #pragma once 18 19 #include <stdint.h> 20 21 #include <string> 22 23 namespace memory_trace { 24 25 enum TypeEnum : uint8_t { 26 MALLOC = 0, 27 CALLOC, 28 MEMALIGN, 29 REALLOC, 30 FREE, 31 THREAD_DONE, 32 UNKNOWN, 33 }; 34 35 struct Entry { 36 pid_t tid; 37 TypeEnum type; 38 uint64_t ptr = 0; 39 size_t size = 0; 40 union { 41 uint64_t old_ptr = 0; 42 uint64_t n_elements; 43 uint64_t align; 44 } u; 45 int64_t present_bytes = -1; 46 uint64_t start_ns = 0; 47 uint64_t end_ns = 0; 48 }; 49 50 bool FillInEntryFromString(const std::string& line, Entry& entry, std::string& error); 51 52 std::string CreateStringFromEntry(const Entry& entry); 53 54 // Guaranteed not to allocate. 55 bool WriteEntryToFd(int fd, const Entry& entry); 56 57 } // namespace memory_trace 58