| 1 |
/* |
| 2 |
* Copyright (c) 2018, Intel Corporation |
| 3 |
* |
| 4 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 5 |
* copy of this software and associated documentation files (the "Software"), |
| 6 |
* to deal in the Software without restriction, including without limitation |
| 7 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 9 |
* Software is furnished to do so, subject to the following conditions: |
| 10 |
* |
| 11 |
* The above copyright notice and this permission notice shall be included |
| 12 |
* in all copies or substantial portions of the Software. |
| 13 |
* |
| 14 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 15 |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 18 |
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 19 |
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 20 |
* OTHER DEALINGS IN THE SOFTWARE. |
| 21 |
*/ |
| 22 |
#ifndef __MEMORY_LEAK_DETECTOR_H__ |
| 23 |
#define __MEMORY_LEAK_DETECTOR_H__ |
| 24 |
|
| 25 |
#include <map> |
| 26 |
#include <vector> |
| 27 |
#include "devconfig.h" |
| 28 |
|
| 29 |
#define LOG_PATH "./igd_0.log" |
| 30 |
#define HLT_PATH "./igd_0.hlt" |
| 31 |
#define MEM_LEAK_REPORT_PATH "./memory_leak_report.txt" |
| 32 |
|
| 33 |
enum MemInfoType |
| 34 |
{ |
| 35 |
MEM_INFO_TYPE_ALLOC_SYS, |
| 36 |
MEM_INFO_TYPE_ALLOC_GFX, |
| 37 |
MEM_INFO_TYPE_FREE_SYS, |
| 38 |
MEM_INFO_TYPE_FREE_GFX, |
| 39 |
MEM_INFO_TYPE_COUNT |
| 40 |
}; |
| 41 |
|
| 42 |
struct MemInfo |
| 43 |
{ |
| 44 |
MemInfoType type; |
| 45 |
std::string ptr; |
| 46 |
std::string functionName; |
| 47 |
std::string filename; |
| 48 |
std::string line; |
| 49 |
}; |
| 50 |
|
| 51 |
class MemoryLeakDetector |
| 52 |
{ |
| 53 |
public: |
| 54 |
|
| 55 |
static void Detect(int32_t memNinjaCnt, int32_t memNinjaCntGfx, Platform_t platform); |
| 56 |
}; |
| 57 |
|
| 58 |
class MemoryLeakDetectorIpl |
| 59 |
{ |
| 60 |
public: |
| 61 |
|
| 62 |
static MemoryLeakDetectorIpl *GetInstance(); |
| 63 |
|
| 64 |
void Detect(const std::string &logPath); |
| 65 |
|
| 66 |
void GenerateReport(const std::string &reportPath, const std::string &title) const; |
| 67 |
|
| 68 |
private: |
| 69 |
|
| 70 |
bool ParseLine(const std::string &line, MemInfo &memInfo) const; |
| 71 |
|
| 72 |
uint32_t GetHitNum(int32_t idx) const; |
| 73 |
|
| 74 |
private: |
| 75 |
|
| 76 |
static MemoryLeakDetectorIpl *m_instance; |
| 77 |
std::map<uint64_t, int32_t> m_memPtr; |
| 78 |
std::vector<MemInfo> m_memInfoTable; |
| 79 |
}; |
| 80 |
|
| 81 |
#endif // __MEMORY_LEAK_DETECTOR_H__ |