The pv_memory_profiling(type int) and environment variable MALLOC_CONF are used by GaussDB(DWS) to control the enabling and disabling of the memory allocation call stack recording module and the output of the process-level memory call stack. The following figure illustrates the process.
The environment variable MALLOC_CONF is used to enable the monitoring module. It is in the ${BIGDATA_HOME}/mppdb/.mppdbgs_profile file and is enabled by default. Note the following points:
Commands for enabling and disabling MALLOC_CONF:
export MALLOC_CONF=prof:true
export MALLOC_CONF=prof:false
Parameter description: Controls the backtrace recording and output of memory allocation functions such as malloc in the gaussdb process.
Value range: a positive integer from 0 to 3.
pv_memory_profiling Value |
Description |
---|---|
0 |
Disables the memory trace function and does not record information of call stacks such as malloc. |
1 |
Enables the memory trace function to record information of call stacks such as malloc. |
2 |
Outputs trace logs of call stacks such as malloc.
|
3 |
Outputs memory statistics.
|
Return type: Boolean
Note:
Procedure:
1 | SELECT * FROM pv_memory_profiling(2); |
jeprof --text --show_bytes $GAUSSHOME/bin/gaussdb trace file 1 >prof.txt
Method 2: Export the report in PDF format.
jeprof --pdf --show_bytes $GAUSSHOME/bin/gaussdb trace file 1 > prof.pdf
Log in as the system administrator, set environment variables, and start the database.
1 | export MALLOC_CONF=prof:true |
Disable the memory trace recording function when the database is running.
1 2 3 4 5 | postgres=#SELECT pv_memory_profiling(0); pv_memory_profiling ---------------------------- t (1 row) |
Enable the memory trace recording function when the database is running.
1 2 3 4 5 | postgres=#SELECT pv_memory_profiling(1); pv_memory_profiling ---------------------------- t (1 row) |
Output memory trace records.
1 2 3 4 | postgres=#SELECT pv_memory_profiling(2); pv_memory_profiling ---------------------------- t |
(1 row)
Generate the trace file in text or PDF format in the directory where the GaussDB process is located.
1 2 | jeprof --text --show_bytes $GAUSSHOME/bin/gaussdb trace file 1 >prof.txt jeprof --pdf --show_bytes $GAUSSHOME/bin/gaussdb trace file 1 > prof.pdf |
Outputs memory statistics. Execute the following statement to generate the memory statistics file in the directory where the GaussDB process is located. The file can be directly read.
1 2 3 4 5 | postgres=#SELECT pv_memory_profiling(3); pv_memory_profiling ---------------------------- t (1 row) |