Source
static void procstat_get_monitored_pids(zbx_vector_uint64_t *pids, const zbx_vector_ptr_t *queries, int pids_num)
/*
** Zabbix
** Copyright (C) 2001-2022 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
/*
* The process CPU statistics are stored using the following memory layout.
*
* .--------------------------------------.
* | header |
* | ------------------------------------ |
* | process cpu utilization queries |
* | and historical data |
* | ------------------------------------ |
* | free space |
* '--------------------------------------'
*
* Because the shared memory can be resized by other processes instead of
* using pointers (when allocating strings, building single linked lists)
* the memory offsets from the beginning of shared memory segment are used.
* 0 offset is interpreted similarly to NULL pointer.
*
* Currently integer values are used to store offsets to internally allocated
* memory which leads to 2GB total size limit.
*
* During every data collection cycle collector does the following:
* 1) acquires list of all processes running on system
* 2) builds a list of processes monitored by queries
* 3) reads total cpu utilization snapshot for the monitored processes
* 4) calculates cpu utilization difference by comparing with previous snapshot
* 5) updates cpu utilization values for queries.
* 6) saves the last cpu utilization snapshot
*
* Initialisation.
* * zbx_procstat_init() initialises procstat dshm structure but doesn't allocate memory from the system
* (zbx_dshm_create() called with size 0).
* * the first call of procstat_add() allocates the shared memory for the header and the first query
* via call to zbx_dshm_realloc().
* * The header is initialised in procstat_copy_data() which is called back from zbx_dshm_realloc().
*