src/components/pcp/linux-pcp.c
//----------------------------------------------------------------------------
// Collect the text description of the EventCode; which is our index into our
// pcp_event_info[] array. We must fit it into descr[len].  
//---------------------------------------------------------------------------
Collect the text description of the EventCode; which is our index into our
pcp_event_info[] array. We must fit it into descr[len].
Collect the text description of the EventCode ; which is our index into our pcp_event_info [] array . We must fit it into descr [ len ] .
static int _pcp_ntv_code_to_descr(unsigned int pcpIdx, char *descr, int len) 
{
   mRtnCnt(_pcp_ntv_code_to_descr);                                     
   pcpIdx &= PAPI_NATIVE_AND_MASK;                                      
   if (pcpIdx >= (unsigned int) sEventCount) {                          
      fprintf(stderr, "%s:%i:%s called with out-of-range pcpIdx=%u.\n", 
         __FILE__, __LINE__, FUNC, pcpIdx);
      return PAPI_EINVAL;                                               
   }
   if (len < 1)  {                                                      
      fprintf(stderr, "%s:%i:%s called with out-of-range descr len=%i.\n", 
         __FILE__, __LINE__, FUNC, len);
      return PAPI_EINVAL;                                               
   }
   char *helpText = NULL;                                               
   int ret = getHelpText(pcpIdx, &helpText);                            
   if (ret != PAPI_OK) {                                                
      if (helpText != NULL) free(helpText);                             
      fprintf(stderr, "%s:%i:%s failed getHelpText; it returned %s.\n", 
         __FILE__, __LINE__, FUNC, PAPI_strerror(ret));
      return ret;                                                       
   }
   strncpy(descr, helpText, len);                                       
   descr[len-1] = 0;                                                    
   free(helpText);                                                      
   return PAPI_OK;                                                      
}
static int _pcp_ntv_code_to_descr ( unsigned int pcpIdx , char * descr , int len ) { mRtnCnt ( _pcp_ntv_code_to_descr ) ; pcpIdx &= PAPI_NATIVE_AND_MASK ; if ( pcpIdx >= ( unsigned int ) sEventCount ) { fprintf ( stderr , " \n " , __FILE__ , __LINE__ , FUNC , pcpIdx ) ; return PAPI_EINVAL ; } if ( len < 1 ) { fprintf ( stderr , " \n " , __FILE__ , __LINE__ , FUNC , len ) ; return PAPI_EINVAL ; } char * helpText = NULL ; int ret = getHelpText ( pcpIdx , & helpText ) ; if ( ret != PAPI_OK ) { if ( helpText != NULL ) free ( helpText ) ; fprintf ( stderr , " \n " , __FILE__ , __LINE__ , FUNC , PAPI_strerror ( ret ) ) ; return ret ; } strncpy ( descr , helpText , len ) ; descr [ len - 1 ] = 0 ; free ( helpText ) ; return PAPI_OK ; }
Collect the text description of the EventCode; which is our index into our
pcp_event_info[] array.
Collect the text description of the EventCode ; which is our index into our pcp_event_info [] array .
// count this function. // We might be called with the NATIVE bit set. // out of range? // exit with error. // If length is ridiculous, // exit with error. // pointer to receive the result. // get it.  // If there is any error, // .. no memory leak. // exit with whatever PAPI error routine had. // copy it over. // force a z-terminator. // release text alloc by pm routine. // EXIT, all good.