sensors_plugin.c
void * thread_report(void * ignored){
    int retVal=0;
    /* we have to report uint64_t, but read double */
    union{
        double dbl;
        uint64_t uint64;
    } value;
    thread_finished=0;
    /* as long as finalize isn't called from Score-P */
    while (counter_enabled){
        int i=0;
        if (wtime==NULL) continue;
      pthread_mutex_lock(&read_mutex);
        for (i=0; i< added_sensor_counters; i++ ){
            // buffer size not sufficient?
            // if so increase buffersize
            if (nr_results[i]==max_results[i]){
              SCOREP_MetricTimeValuePair * reallocated;
              reallocated = realloc(results[i],nr_results[i]*2*sizeof(SCOREP_MetricTimeValuePair));
              /* if reallocation failed */
              if (reallocated == NULL){
                fprintf(stderr, "Score-P Sensors Plugin: failed to allocate more memory for results.\n"
                    "Stopping Sensor measurement after %d readings",nr_results[i]);
                counter_enabled = 0;
              }
              else {
                /* allocation ok */
                results[i] = reallocated;
              }
              max_results[i]=nr_results[i]*2;
            }
            /* read values and store them in array */
            results[i][nr_results[i]].timestamp=wtime();
                if (sensors_get_value(sensor_counters[i].chip,
                                    sensor_counters[i].subFeature->number,
                                    &value.dbl)<0)
                  /* TODO find better way then atof() */
                  value.dbl=atof("NaN");
                results[i][nr_results[i]].value=value.uint64;
            nr_results[i]++;
        }
        pthread_mutex_unlock(&read_mutex);
        usleep(period);
    }
    thread_finished=1;
    return NULL;
}
/* thread function that reads sensors information on a regular base */
thread function that reads sensors information on a regular base
thread function that reads sensors information on a regular base
void * thread_report(void * ignored){
    int retVal=0;
    union{
        double dbl;
        uint64_t uint64;
    } value;
    thread_finished=0;
    while (counter_enabled){
        int i=0;
        if (wtime==NULL) continue;
      pthread_mutex_lock(&read_mutex);
        for (i=0; i< added_sensor_counters; i++ ){
            if (nr_results[i]==max_results[i]){
              SCOREP_MetricTimeValuePair * reallocated;
              reallocated = realloc(results[i],nr_results[i]*2*sizeof(SCOREP_MetricTimeValuePair));
              if (reallocated == NULL){
                fprintf(stderr, "Score-P Sensors Plugin: failed to allocate more memory for results.\n"
                    "Stopping Sensor measurement after %d readings",nr_results[i]);
                counter_enabled = 0;
              }
              else {
                results[i] = reallocated;
              }
              max_results[i]=nr_results[i]*2;
            }
            results[i][nr_results[i]].timestamp=wtime();
                if (sensors_get_value(sensor_counters[i].chip,
                                    sensor_counters[i].subFeature->number,
                                    &value.dbl)<0)
                  value.dbl=atof("NaN");
                results[i][nr_results[i]].value=value.uint64;
            nr_results[i]++;
        }
        pthread_mutex_unlock(&read_mutex);
        usleep(period);
    }
    thread_finished=1;
    return NULL;
}
void * thread_report ( void * ignored ) { int retVal = 0 ; union { double dbl ; uint64_t uint64 ; } value ; thread_finished = 0 ; while ( counter_enabled ) { int i = 0 ; if ( wtime == NULL ) continue ; pthread_mutex_lock ( & read_mutex ) ; for ( i = 0 ; i < added_sensor_counters ; i ++ ) { if ( nr_results [ i ] == max_results [ i ] ) { SCOREP_MetricTimeValuePair * reallocated ; reallocated = realloc ( results [ i ] , nr_results [ i ] * 2 * sizeof ( SCOREP_MetricTimeValuePair ) ) ; if ( reallocated == NULL ) { fprintf ( stderr , " \n " " " , nr_results [ i ] ) ; counter_enabled = 0 ; } else { results [ i ] = reallocated ; } max_results [ i ] = nr_results [ i ] * 2 ; } results [ i ] [ nr_results [ i ] ] . timestamp = wtime ( ) ; if ( sensors_get_value ( sensor_counters [ i ] . chip , sensor_counters [ i ] . subFeature -> number , & value . dbl ) < 0 ) value . dbl = atof ( " " ) ; results [ i ] [ nr_results [ i ] ] . value = value . uint64 ; nr_results [ i ] ++ ; } pthread_mutex_unlock ( & read_mutex ) ; usleep ( period ) ; } thread_finished = 1 ; return NULL ; }
thread function that reads sensors information on a regular base
thread function that reads sensors information on a regular base
/* we have to report uint64_t, but read double */ /* as long as finalize isn't called from Score-P */ // buffer size not sufficient? // if so increase buffersize /* if reallocation failed */ /* allocation ok */ /* read values and store them in array */ /* TODO find better way then atof() */