extern int acct_gather_conf_destroy(void)
{
	int rc;

	if (!inited)
		return SLURM_SUCCESS;

	rc = acct_gather_energy_fini();
	rc = MAX(rc, acct_gather_filesystem_fini());
	rc = MAX(rc, acct_gather_infiniband_fini());
	rc = MAX(rc, acct_gather_profile_fini());
	return rc;
}
extern int acct_gather_profile_fini(void)
{
	int rc = SLURM_SUCCESS, i;

	if (!g_context)
		return SLURM_SUCCESS;

	slurm_mutex_lock(&g_context_lock);

	if (!g_context)
		goto done;

	init_run = false;

	for (i=0; i < PROFILE_CNT; i++) {
		switch (i) {
		case PROFILE_ENERGY:
			acct_gather_energy_fini();
			break;
		case PROFILE_TASK:
			jobacct_gather_fini();
			break;
		case PROFILE_FILESYSTEM:
			acct_gather_filesystem_fini();
			break;
		case PROFILE_NETWORK:
			acct_gather_infiniband_fini();
			break;
		default:
			fatal("Unhandled profile option %d please update "
			      "slurm_acct_gather_profile.c "
			      "(acct_gather_profile_fini)", i);
		}
	}

	if (timer_thread_id) {
		pthread_cancel(timer_thread_id);
		pthread_join(timer_thread_id, NULL);
	}

	rc = plugin_context_destroy(g_context);
	g_context = NULL;
done:
	slurm_mutex_unlock(&g_context_lock);

	return rc;
}