Blame src/libpfm-3.y/lib/pfmlib_priv.c

Packit 577717
/*
Packit 577717
 * pfmlib_priv.c: set of internal utility functions for all architectures
Packit 577717
 *
Packit 577717
 * Copyright (c) 2006 Hewlett-Packard Development Company, L.P.
Packit 577717
 * Contributed by Stephane Eranian <eranian@hpl.hp.com>
Packit 577717
 *
Packit 577717
 * Permission is hereby granted, free of charge, to any person obtaining a copy
Packit 577717
 * of this software and associated documentation files (the "Software"), to deal
Packit 577717
 * in the Software without restriction, including without limitation the rights
Packit 577717
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
Packit 577717
 * of the Software, and to permit persons to whom the Software is furnished to do so,
Packit 577717
 * subject to the following conditions:
Packit 577717
 *
Packit 577717
 * The above copyright notice and this permission notice shall be included in all
Packit 577717
 * copies or substantial portions of the Software.
Packit 577717
 *
Packit 577717
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
Packit 577717
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
Packit 577717
 * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
Packit 577717
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
Packit 577717
 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
Packit 577717
 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Packit 577717
 */
Packit 577717
#include <sys/types.h>
Packit 577717
#include <ctype.h>
Packit 577717
#include <string.h>
Packit 577717
#include <stdio.h>
Packit 577717
#include <stdlib.h>
Packit 577717
#include <stdarg.h>
Packit 577717
#include <limits.h>
Packit 577717
Packit 577717
#include <perfmon/pfmlib.h>
Packit 577717
Packit 577717
#include "pfmlib_priv.h"
Packit 577717
Packit 577717
/*
Packit 577717
 * file for all libpfm verbose and debug output
Packit 577717
 *
Packit 577717
 * By default, it is set to stderr, unless the
Packit 577717
 * PFMLIB_DEBUG_STDOUT environment variable is set
Packit 577717
 */
Packit 577717
FILE *libpfm_fp;
Packit 577717
Packit 577717
/*
Packit 577717
 * by convention all internal utility function must be prefixed by __
Packit 577717
 */
Packit 577717
Packit 577717
/*
Packit 577717
 * debug printf
Packit 577717
 */
Packit 577717
void
Packit 577717
__pfm_vbprintf(const char *fmt, ...)
Packit 577717
{
Packit 577717
	va_list ap;
Packit 577717
Packit 577717
	if (pfm_config.options.pfm_verbose == 0)
Packit 577717
		return;
Packit 577717
Packit 577717
	va_start(ap, fmt);
Packit 577717
	vfprintf(libpfm_fp, fmt, ap);
Packit 577717
	va_end(ap);
Packit 577717
}
Packit 577717
Packit 577717
int
Packit 577717
__pfm_check_event(pfmlib_event_t *e)
Packit 577717
{
Packit 577717
	unsigned int n, j;
Packit 577717
Packit 577717
	if (e->event >= pfm_current->pme_count)
Packit 577717
		return PFMLIB_ERR_INVAL;
Packit 577717
Packit 577717
	n = pfm_num_masks(e->event);
Packit 577717
	if (n == 0 && e->num_masks)
Packit 577717
		return PFMLIB_ERR_UMASK;
Packit 577717
Packit 577717
	for(j=0; j < e->num_masks; j++) {
Packit 577717
		if (e->unit_masks[j] >= n)
Packit 577717
			return PFMLIB_ERR_UMASK;
Packit 577717
	}
Packit 577717
	/*
Packit 577717
	 * if event has umask, but non specified by user, then
Packit 577717
	 * return:
Packit 577717
	 *   - error if no default umask is defined
Packit 577717
	 *   - success if default umask exists for event
Packit 577717
	 */
Packit 577717
	if (n && j == 0) {
Packit 577717
		if (pfm_current->has_umask_default
Packit 577717
		    && pfm_current->has_umask_default(e->event))
Packit 577717
			return PFMLIB_SUCCESS;
Packit 577717
		return PFMLIB_ERR_UMASK;
Packit 577717
	}
Packit 577717
	return PFMLIB_SUCCESS;
Packit 577717
}