After thinking more on this suggestion, I came up with following generic structure which can be used to store progress of any command per backend in shared memory.
Struct PgBackendProgress
{
int32 *counter[COMMAND_NUM_SLOTS];
float8 *counter_float[COMMAND_NUM_SLOTS];
char *progress_message[COMMAND_NUM_SLOTS];
}
COMMAND_NUM_SLOTS will define maximum number of slots(phases) for any command.
Progress of command will be measured using progress of each phase in command.
For some command the number of phases can be singular and rest of the slots will be NULL.
Each phase will report n integer counters, n float counters and a progress message.
For some phases , any of the above fields can be NULL.
For VACUUM , there can 3 phases as discussed in the earlier mails.
Phase 1. Report 2 integer counters: heap pages scanned and total heap pages, 1 float counter: percentage_complete and progress message.
Phase 2. Report 2 integer counters: index pages scanned and total index pages(across all indexes) and progress message.
Phase 3. 1 integer counter: heap pages vacuumed.
This structure can be accessed by statistics collector to display progress via new view.