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 }; 33 34 struct Entry { 35 pid_t tid; 36 TypeEnum type; 37 uint64_t ptr = 0; 38 size_t size = 0; 39 union { 40 uint64_t old_ptr = 0; 41 uint64_t n_elements; 42 uint64_t align; 43 } u; 44 uint64_t start_ns = 0; 45 uint64_t end_ns = 0; 46 }; 47 48 bool FillInEntryFromString(const std::string& line, Entry& entry, std::string& error); 49 50 std::string CreateStringFromEntry(const Entry& entry); 51 52 // Guaranteed not to allocate. 53 bool WriteEntryToFd(int fd, const Entry& entry); 54 55 } // namespace memory_trace 56