1# Memory tests 2 3## Usage 4 5These scripts are made to parse TCMalloc output in order to extract certain 6info from them. 7 8In particular, these scripts rely on the error logging system for ChromeOS in 9order to extract information. In order to use a script (e.g. `total_mem.py`), 10you just have the command: 11 12``` 13./total_mem.py FILENAME 14``` 15 16where `FILENAME` is the name of the log file to be parsed. 17 18## Codebase Changes 19 20There are two ideas that motivate these changes: 21 221. Turn on TCMalloc sampling. 232. Use perf to collect the sample information. 24 25 26The following files have to be changed: 27 28in `chrome/browser/metrics/perf_provider_chrome_os`, add: 29 30``` 31#include "third_party/tcmalloc/chromium/src/gperftools/malloc_extension.h" 32``` 33 34Change the perf profiling interval to something small (60*1000 milliseconds). 35 36Inside DoPeriodicCollection, insert the following code: 37 38``` 39std::string output; 40char* chr_arr = new char[9999]; 41MallocExtension::instance() ->GetHeapSample(&output); 42MallocExtension::instance() ->GetStats(chr_arr, 9999); 43LOG(ERROR) << "Output Heap Data: "; 44LOG(ERROR) << output; 45LOG(ERROR) << "Output Heap Stats: "; 46output = ""; 47for (unsigned int i = 0; i < strlen(chr_arr); i++) { 48 output += chr_arr[i]; 49} 50LOG(ERROR) << output; 51delete[] chr_arr; 52``` 53