Esempio n. 1
0
int vt_metric_open()
{
  int i;
  char* env;
  char* env_sep;
  char* var;
  char* token;
  const int max_metrics = sizeof (vt_sx_metrics) / sizeof (vt_sx_metrics[0]);

  /* read environment variable "VT_METRICS"; return if unset. */
  env = vt_env_metrics();
  if ( env == NULL )
    return nmetrics;

  env_sep = vt_env_metrics_sep();

  var = strdup(env);
  vt_cntl_msg(2, "VT_METRICS=%s", var);

  /* convert VT_METRICS's letters to lower case */
  token = var;
  while ( *token ) { *token = tolower(*token); token++; }

  /* read metrics from specification string */
  token = strtok(var, env_sep);
  if (token && (0 == strcmp (token, "all"))) {
    vt_cntl_msg(2, "token:%s Adding all metrics", token);
    for (i = 0; i < max_metrics; i++) {
      metricv_add(i);
      vt_cntl_msg(2, "metric i:%d name:%s", i, vt_sx_metrics[i].name);
    }
  } else {
    while ( token && (nmetrics < VT_METRIC_MAXNUM) ) {
      /* search metricmap for a suitable definition */
      /* printf("Token%d: <%s>\n", nmetrics, token); */
      for (i = 0; i < max_metrics; i++) {
	if (0 == strcmp (token, vt_sx_metrics[i].name)) {
	  metricv_add(i);
	  vt_cntl_msg(2, "metric i:%d token:%s", i, token);
	  break;
	}
      }
      if (i == max_metrics) {
	vt_error_msg ("Metric <%s> not supported", token);
      }
      token = strtok(NULL, env_sep);
    }
  }

  sx_ctr_array = calloc(SX_CTR_MAX, sizeof (uint64_t));

  /* clean up */
  free(var);

  return nmetrics;
}
Esempio n. 2
0
int vt_metric_open()
{
  char* env;
  char* env_sep;
  char* var;
  char* token;

  /* read environment variable "VT_METRICS" */
  if ( ( env = vt_env_metrics() ) == NULL )
    return 0;

  env_sep = vt_env_metrics_sep();

  var = strdup(env);
  vt_cntl_msg(2, "VT_METRICS=%s", var);

  /* initialize CPC */
  if ( ( cpc = cpc_open(CPC_VER_CURRENT) ) == NULL )
    vt_error_msg("cpc_open: %s", strerror(errno));

  /* read metrics from specification string */
  token = strtok(var, env_sep);
  while ( token && (nmetrics < VT_METRIC_MAXNUM) )
  {
    metricv_add( token );
    token = strtok(NULL, env_sep);
  }

  free(var);

  return nmetrics;
}
Esempio n. 3
0
int vt_metric_open()
{
  int retval;
  char* env;
  char* env_sep;
  char* var;
  char* token;
  char* saveptr;
  PAPI_event_info_t info;
  metricmap_t* mapv = NULL;
  metricmap_t* map;

  /* read environment variable "VT_METRICS". Return if
     uset and no PAPI timer used. */
  env = vt_env_metrics();
  if( env == NULL )
  {
#if TIMER != TIMER_PAPI_REAL_CYC && TIMER != TIMER_PAPI_REAL_USEC
    return nmetrics;
#endif
  }

  env_sep = vt_env_metrics_sep();

  mapv = vt_metricmap_init(
    (metmap_t)(METMAP_MEASURE|METMAP_AGGROUP));
  metricmap_dump(mapv);

  /* initialize PAPI */
  retval = PAPI_library_init(PAPI_VER_CURRENT);
  if ( retval != PAPI_VER_CURRENT )
    metric_error(retval, "PAPI_library_init");

  /* return if environment variable is unset */
  if ( env == NULL )
    return nmetrics;

  var = strdup(env);
  vt_cntl_msg(2, "VT_METRICS=%s", var);

  /* read metrics from specification string */
  token = strtok_r(var, env_sep, &saveptr);
  while ( token && (nmetrics < VT_METRIC_MAXNUM) ) {
    /* set counter properties */
    uint32_t props;
    if (token[0]=='!')
    {
      props = VT_CNTR_ABS | VT_CNTR_NEXT;
      token++;
    }
    else
    {
      props = VT_CNTR_ACC;
    }
    /* search metricmap for a suitable definition */
    map = mapv;
    /*printf("Token%d: <%s>\n", nmetrics, token);*/
    while (map != NULL) {
      if ( strcmp(map->event_name, token) == 0 ) {
        /*printf("Definition %s = <%s>\n", token, map->alias_name);*/
        /* expand definition and set components */
        char* c_token = map->alias_name;
        int len = strcspn(c_token, " \t"); /* first token */
        int got_valid_match = 1; /* to be verified */
        int k = 0;
        do { /* verify each component of definition is available */
          char component[64];
          int code = -1;
          strncpy(component, c_token, len);
          component[len] = '\0';
          /*printf("Comp[%d] <%s>\n", k, component);*/
          c_token += len + strspn(c_token+len, " \t");
          len = strcspn(c_token, " \t"); /* next token */

          PAPI_event_name_to_code(component, &code);
          memset(&info, 0, sizeof(PAPI_event_info_t));
          retval = PAPI_get_event_info(code, &info);
          /*printf("v[%d] %s [0x%X] %d\n", k, component, code, info.count);*/

          if (info.count == 0) {
            /*printf("Event %s *N/A*\n", component);*/
            got_valid_match = 0;
          } else if ((k==0) && (len==0)) { /* use provided event name */
            metricv_add(token, code, props);
          } else { /* use alias component name */
            metricv_add(component, code, props);
          }
          k++;
        } while (got_valid_match && (len > 0));
        if (got_valid_match) {
          /*printf("Definition %s = <%s> OK\n", map->event_name, map->alias_name);*/
          break; /* accept this event definition */
        }
      }
      map = map->next;
    }

    if (map == NULL) { /* no map match, so try given name */
      int code = -1;
      char* component = token;
      /*printf("Comp[X] <%s>\n", component);*/
      retval = PAPI_event_name_to_code(component, &code);
      if (retval != PAPI_OK || code == -1)
        vt_error_msg("Metric <%s> not supported\n", component);

      memset(&info, 0, sizeof(PAPI_event_info_t));
      retval = PAPI_get_event_info(code, &info);
      /*printf("v[%d] %s [0x%X] %d\n", nmetrics, component, code, info.count);*/
      if (retval != PAPI_OK)
        vt_error_msg("Metric <%s> not available\n", component);

      metricv_add(component, code, props);
    }

    token = strtok_r(NULL, env_sep, &saveptr);
  }

  /*printf("nmetrics=%d\n", nmetrics);*/

  /* clean up */
  metricmap_free(mapv);
  free(var);

  /* Check whether event combination is valid. This is done here to
     avoid errors when creating the event set for each thread, which
     would multiply the error messages. */
  metric_test();

  metric_descriptions();

  return nmetrics;
}
int esd_metric_open()
{
  int retval;
  const char* env;
  char* var;
  char* token;
  PAPI_event_info_t info;
  epk_metricmap_t* mapv = NULL;

  /* read configuration variable "EPK_METRICS". Return if unset. */
  env = epk_get(EPK_METRICS);
  if ( env == NULL || strlen(env)==0)
    return nmetrics;

  mapv = epk_metricmap_init(EPK_METMAP_MEASURE|EPK_METMAP_AGGROUP);
  /*epk_metricmap_dump(mapv);*/

  /* initialize PAPI */
  retval = PAPI_library_init(PAPI_VER_CURRENT);
  if ( retval != PAPI_VER_CURRENT )
    esd_metric_error(retval, "PAPI_library_init");

  var = calloc(strlen(env) + 1, sizeof(char));
  strcpy(var, env);
  elg_cntl_msg("EPK_METRICS=%s", var);
        
  /* read metrics from specification string */
  /*! using a colon is a poor choice; it doesn't work for native PAPI event names with colons
   */
  token = strtok(var, ",");
  while ( token && (nmetrics < ELG_METRIC_MAXNUM) ) {
    /* search metricmap for a suitable definition */
    epk_metricmap_t* map = mapv;
    /*printf("Token%d: <%s>\n", nmetrics, token);*/
    while (map != NULL) {
      if ( strcmp(map->event_name, token) == 0 ) {
        /*printf("Definition %s = <%s>\n", token, map->alias_name);*/
        /* expand definition and set components */
        char* c_token = map->alias_name;
        int len = strcspn(c_token, " \t"); /* first token */
        int got_valid_match = 1; /* to be verified */
        int k = 0;
        do { /* verify each component of definition is available */
          char component[64];
          int code = -1;
          strncpy(component, c_token, len);
          component[len] = '\0';
          /*printf("Comp[%d] <%s>\n", k, component);*/
          c_token += len + strspn(c_token+len, " \t");
          len = strcspn(c_token, " \t"); /* next token */

          retval = PAPI_event_name_to_code(component, &code);
          if (retval == PAPI_OK) {
            memset(&info, 0, sizeof(PAPI_event_info_t));
            retval = PAPI_get_event_info(code, &info);
          }
          if (retval != PAPI_OK) {
              elg_warning("Event %s *N/A*", component);
              got_valid_match = 0;
          } else if ((k==0) && (len==0)) { /* use provided event name */
              metricv_add(token, code);
          } else { /* use alias component name */
              metricv_add(component, code);
          }
          elg_cntl_msg("v[%d] %s [0x%X] %d", k, component, code, info.count);
          k++;
        } while (got_valid_match && (len > 0));
        if (got_valid_match) {
            /*printf("Definition %s = <%s> OK\n", map->event_name, map->alias_name);*/
            break; /* accept this event definition */
        }
      }
      map = map->next;
    }

    if (map == NULL) { /* no map match, so try given name */
      int code = -1;
      char* component = token;
      /*elg_warning("v[%d] <%s>", nmetrics, component);*/
      retval = PAPI_event_name_to_code(component, &code);
	    
	    /* KF: the retval of PAPI_event_name_to_code seems to indicate
	       failure even when things went alright with non-cpu components, 
	       workaround: call PAPI_query_event() afterwords, that seems to 
	       correctly detect failure/success */
	    retval = PAPI_query_event( code );

      if ((retval != PAPI_OK) || (code == -1))
          elg_error_msg("Metric <%s> not supported", component);

      memset(&info, 0, sizeof(PAPI_event_info_t));
      retval = PAPI_get_event_info(code, &info);
      if (retval != PAPI_OK)
          esd_metric_error(retval, "PAPI_get_event_info");
      /*elg_cntl_msg("Metric <%s> info has %d fields", component, info.count);*/

      elg_cntl_msg("v[%d] %s [0x%X] %d", nmetrics, component, code, info.count);

      metricv_add(component, code);
    }

    token = strtok(NULL, ",");
  }

  /*printf("nmetrics=%d\n", nmetrics);*/

  /* clean up */
  epk_metricmap_free(mapv);
  free(var);

  /* Check whether event combination is valid. This is done here to
     avoid errors when creating the event set for each thread, which
     would multiply the error messages. */
  esd_metric_test();

  esd_metric_descriptions();

  return nmetrics;
}