HPCToolkit
hpcpapi.c
Go to the documentation of this file.
1 // -*-Mode: C++;-*- // technically C99
2 
3 // * BeginRiceCopyright *****************************************************
4 //
5 // $HeadURL$
6 // $Id$
7 //
8 // --------------------------------------------------------------------------
9 // Part of HPCToolkit (hpctoolkit.org)
10 //
11 // Information about sources of support for research and development of
12 // HPCToolkit is at 'hpctoolkit.org' and in 'README.Acknowledgments'.
13 // --------------------------------------------------------------------------
14 //
15 // Copyright ((c)) 2002-2019, Rice University
16 // All rights reserved.
17 //
18 // Redistribution and use in source and binary forms, with or without
19 // modification, are permitted provided that the following conditions are
20 // met:
21 //
22 // * Redistributions of source code must retain the above copyright
23 // notice, this list of conditions and the following disclaimer.
24 //
25 // * Redistributions in binary form must reproduce the above copyright
26 // notice, this list of conditions and the following disclaimer in the
27 // documentation and/or other materials provided with the distribution.
28 //
29 // * Neither the name of Rice University (RICE) nor the names of its
30 // contributors may be used to endorse or promote products derived from
31 // this software without specific prior written permission.
32 //
33 // This software is provided by RICE and contributors "as is" and any
34 // express or implied warranties, including, but not limited to, the
35 // implied warranties of merchantability and fitness for a particular
36 // purpose are disclaimed. In no event shall RICE or contributors be
37 // liable for any direct, indirect, incidental, special, exemplary, or
38 // consequential damages (including, but not limited to, procurement of
39 // substitute goods or services; loss of use, data, or profits; or
40 // business interruption) however caused and on any theory of liability,
41 // whether in contract, strict liability, or tort (including negligence
42 // or otherwise) arising in any way out of the use of this software, even
43 // if advised of the possibility of such damage.
44 //
45 // ******************************************************* EndRiceCopyright *
46 
47 /****************************************************************************
48 //
49 // File:
50 // $HeadURL$
51 //
52 // Purpose:
53 // General PAPI support.
54 //
55 // Description:
56 // [The set of functions, macros, etc. defined in the file]
57 //
58 // Author:
59 // Written by John Mellor-Crummey and Nathan Tallent, Rice University.
60 //
61 *****************************************************************************/
62 
63 /************************** System Include Files ****************************/
64 
65 #include <unistd.h>
66 #include <string.h>
67 #include <stdio.h>
68 #include <papiStdEventDefs.h>
69 #include <papi.h>
70 
71 /**************************** User Include Files ****************************/
72 
73 #include "hpcpapi.h"
74 
75 /****************************************************************************/
76 
77 int
78 hpc_init_papi(int (*is_init)(void), int (*init)(int))
79 {
80  if ((*is_init)() == PAPI_NOT_INITED) {
81  return hpc_init_papi_force(init);
82  }
83 
84  return 0;
85 }
86 
87 
88 /****************************************************************************/
89 
90 int
91 hpc_init_papi_force(int (*init)(int))
92 {
93  /* Initialize PAPI library */
94  int papi_version;
95  papi_version = (*init)(PAPI_VER_CURRENT);
96  if (papi_version != PAPI_VER_CURRENT) {
97  fprintf(stderr, "(pid %d): PAPI library initialization failure - expected version %d, dynamic library was version %d. Aborting.\n", getpid(), PAPI_VER_CURRENT, papi_version);
98  return 1;
99  }
100 
101  if (papi_version < 3) {
102  fprintf(stderr, "(pid %d): Using PAPI library version %d; expecting version 3 or greater.\n", getpid(), papi_version);
103  return 1;
104  }
105  return 0;
106 }
107 
108 /****************************************************************************/
109 
111  { PAPI_PROFIL_POSIX, "PAPI_PROFIL_POSIX" },
112  { PAPI_PROFIL_RANDOM, "PAPI_PROFIL_RANDOM" },
113  { PAPI_PROFIL_WEIGHTED, "PAPI_PROFIL_WEIGHTED" },
114  { PAPI_PROFIL_COMPRESS, "PAPI_PROFIL_COMPRESS" },
115 /* No support for dynamically changing bucket size yet...
116  { PAPI_PROFIL_BUCKET_16, "PAPI_PROFIL_BUCKET_16" },
117  { PAPI_PROFIL_BUCKET_32, "PAPI_PROFIL_BUCKET_32" },
118  { PAPI_PROFIL_BUCKET_64, "PAPI_PROFIL_BUCKET_64" }, */
119  { PAPI_PROFIL_FORCE_SW, "PAPI_PROFIL_FORCE_SW" },
120  { PAPI_PROFIL_DATA_EAR, "PAPI_PROFIL_DATA_EAR" },
121  { PAPI_PROFIL_INST_EAR, "PAPI_PROFIL_INST_EAR" },
122  { -1, NULL }
123 };
124 
125 const hpcpapi_flagdesc_t *
126 hpcpapi_flag_by_name(const char *name)
127 {
129  for (; i->name != NULL; i++) {
130  if (strcmp(name, i->name) == 0) return i;
131  }
132  return NULL;
133 }
134 
135 /****************************************************************************/
136 
137 
138 void
140 {
141  int i;
142 
143  fprintf(stderr, "{ hpcpapi_profile_desc_vec_t: %d\n", descvec->size);
144  for (i = 0; i < descvec->size; ++i) {
145  dump_hpcpapi_profile_desc(&descvec->vec[i], " ");
146  }
147  fprintf(stderr, "}\n");
148 }
149 
150 
151 void
153 {
154  int i;
155  const char* pre = (prefix) ? prefix : " ";
156 
157  fprintf(stderr, "%s{ %s (%s) : %"PRIu64" : %d entries\n", pre,
158  desc->einfo.symbol, desc->einfo.long_descr, desc->period,
159  desc->numsprofs);
160 
161  for (i = 0; i < desc->numsprofs; ++i) {
162  dump_hpcpapi_profile_desc_buf(desc, i, " ");
163  }
164 
165  fprintf(stderr, "%s}\n", pre);
166 }
167 
168 
169 void
171  const char* prefix)
172 {
173  PAPI_sprofil_t* sprof = &(desc->sprofs[idx]);
174  uint64_t ncounters = (sprof->pr_size / desc->bytesPerCntr);
175  const char* pre = (prefix) ? prefix : " ";
176  fprintf(stderr, "%s[%d](%p): buf %p of size %"PRIu64" for module at %p\n",
177  pre, idx, sprof, sprof->pr_base, ncounters, sprof->pr_off);
178 }
179 
180 
181 /****************************************************************************/
int hpc_init_papi(int(*is_init)(void), int(*init)(int))
Definition: hpcpapi.c:78
const hpcpapi_flagdesc_t * hpcpapi_flag_by_name(const char *name)
Definition: hpcpapi.c:126
static int is_init
Definition: sample_prob.c:67
void dump_hpcpapi_profile_desc_vec(hpcpapi_profile_desc_vec_t *descvec)
Definition: hpcpapi.c:139
PAPI_sprofil_t * sprofs
Definition: hpcpapi.h:138
void dump_hpcpapi_profile_desc(hpcpapi_profile_desc_t *desc, const char *prefix)
Definition: hpcpapi.c:152
unsigned int bytesPerCntr
Definition: hpcpapi.h:135
static char * prefix
Definition: common.c:164
const char * name
Definition: hpcpapi.h:108
int hpc_init_papi_force(int(*init)(int))
Definition: hpcpapi.c:91
hpcpapi_profile_desc_t * vec
Definition: hpcpapi.h:155
unsigned int numsprofs
Definition: hpcpapi.h:139
#define NULL
Definition: ElfHelper.cpp:85
static hpcpapi_flagdesc_t papi_flags[]
Definition: hpcpapi.c:110
PAPI_event_info_t einfo
Definition: hpcpapi.h:129
void dump_hpcpapi_profile_desc_buf(hpcpapi_profile_desc_t *desc, int idx, const char *prefix)
Definition: hpcpapi.c:170