Home | History | Annotate | Download | only in memunreachable
      1 /*
      2  * Copyright (C) 2016 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 #ifndef LIBMEMUNREACHABLE_MEMUNREACHABLE_H_
     18 #define LIBMEMUNREACHABLE_MEMUNREACHABLE_H_
     19 
     20 #include <string.h>
     21 #include <sys/cdefs.h>
     22 
     23 #ifdef __cplusplus
     24 
     25 #include <string>
     26 #include <vector>
     27 
     28 namespace android {
     29 
     30 struct Leak {
     31   uintptr_t begin;
     32   size_t size;
     33 
     34   size_t referenced_count;
     35   size_t referenced_size;
     36 
     37   size_t similar_count;
     38   size_t similar_size;
     39   size_t similar_referenced_count;
     40   size_t similar_referenced_size;
     41 
     42   size_t total_size;
     43 
     44   static const size_t contents_length = 32;
     45   char contents[contents_length];
     46 
     47   struct Backtrace {
     48     size_t num_frames;
     49 
     50     static const size_t max_frames = 16;
     51     uintptr_t frames[max_frames];
     52   } backtrace;
     53 
     54   std::string ToString(bool log_contents) const;
     55 };
     56 
     57 struct UnreachableMemoryInfo {
     58   std::vector<Leak> leaks;
     59   size_t num_leaks;
     60   size_t leak_bytes;
     61   size_t num_allocations;
     62   size_t allocation_bytes;
     63 
     64   UnreachableMemoryInfo() {}
     65   ~UnreachableMemoryInfo();
     66 
     67   std::string ToString(bool log_contents) const;
     68 };
     69 
     70 bool GetUnreachableMemory(UnreachableMemoryInfo& info, size_t limit = 100);
     71 
     72 std::string GetUnreachableMemoryString(bool log_contents = false, size_t limit = 100);
     73 
     74 }  // namespace android
     75 
     76 #endif
     77 
     78 __BEGIN_DECLS
     79 
     80 bool LogUnreachableMemory(bool log_contents, size_t limit);
     81 
     82 bool NoLeaks();
     83 
     84 __END_DECLS
     85 
     86 #endif  // LIBMEMUNREACHABLE_MEMUNREACHABLE_H_
     87