PAPI 7.1.0.0
Loading...
Searching...
No Matches
pfmlib_priv.c
Go to the documentation of this file.
1/*
2 * pfmlib_priv.c: set of internal utility functions for all architectures
3 *
4 * Copyright (c) 2006 Hewlett-Packard Development Company, L.P.
5 * Contributed by Stephane Eranian <eranian@hpl.hp.com>
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
11 * of the Software, and to permit persons to whom the Software is furnished to do so,
12 * subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
18 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
19 * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
21 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
22 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24#include <sys/types.h>
25#include <ctype.h>
26#include <string.h>
27#include <stdio.h>
28#include <stdlib.h>
29#include <stdarg.h>
30#include <limits.h>
31
32#include <perfmon/pfmlib.h>
33
34#include "pfmlib_priv.h"
35
36/*
37 * file for all libpfm verbose and debug output
38 *
39 * By default, it is set to stderr, unless the
40 * PFMLIB_DEBUG_STDOUT environment variable is set
41 */
43
44/*
45 * by convention all internal utility function must be prefixed by __
46 */
47
48/*
49 * debug printf
50 */
51void
52__pfm_vbprintf(const char *fmt, ...)
53{
54 va_list ap;
55
57 return;
58
59 va_start(ap, fmt);
60 vfprintf(libpfm_fp, fmt, ap);
61 va_end(ap);
62}
63
64int
66{
67 unsigned int n, j;
68
69 if (e->event >= pfm_current->pme_count)
70 return PFMLIB_ERR_INVAL;
71
72 n = pfm_num_masks(e->event);
73 if (n == 0 && e->num_masks)
74 return PFMLIB_ERR_UMASK;
75
76 for(j=0; j < e->num_masks; j++) {
77 if (e->unit_masks[j] >= n)
78 return PFMLIB_ERR_UMASK;
79 }
80 /*
81 * if event has umask, but non specified by user, then
82 * return:
83 * - error if no default umask is defined
84 * - success if default umask exists for event
85 */
86 if (n && j == 0) {
87 if (pfm_current->has_umask_default
88 && pfm_current->has_umask_default(e->event))
89 return PFMLIB_SUCCESS;
90 return PFMLIB_ERR_UMASK;
91 }
92 return PFMLIB_SUCCESS;
93}
__gnuc_va_list va_list
#define PFMLIB_ERR_UMASK
Definition: pfmlib.h:306
#define PFMLIB_SUCCESS
Definition: pfmlib.h:283
#define PFMLIB_ERR_INVAL
Definition: pfmlib.h:285
pfm_config_t pfm_config
void __pfm_vbprintf(const char *fmt,...)
Definition: pfmlib_priv.c:52
int __pfm_check_event(pfmlib_event_t *e)
Definition: pfmlib_priv.c:65
FILE * libpfm_fp
Definition: pfmlib_priv.c:42
#define pfm_current
Definition: pfmlib_priv.h:78
static unsigned int pfm_num_masks(int e)
Definition: pfmlib_priv.h:125
const char * fmt
Definition: pscanf.h:10
va_end(arg_list)
va_start(arg_list, fmt)
pfmlib_options_t options
Definition: pfmlib_priv.h:67
unsigned int num_masks
Definition: pfmlib.h:90
unsigned int unit_masks[PFMLIB_MAX_MASKS_PER_EVENT]
Definition: pfmlib.h:89
unsigned int event
Definition: pfmlib.h:86
unsigned int pfm_verbose
Definition: pfmlib.h:139