[Kst] Custom datasource plugin readField() weirdness

bug.zilla.vynce at neverbox.com bug.zilla.vynce at neverbox.com
Fri May 29 22:12:32 CEST 2009


I've written a custom datasource plugin that is essentially a binary
equivalent to an ASCII CSV file. It works fine, but the readField()
function gets requests that alternate between reading the two most
recent records and rereading the entire file. Rereading the entire
file every 2 s is less efficient than I'd like. Am I causing this
somehow or is this a problem in Kst? I'm running Kst 1.7.0. Plot
update timer is set to 1000 ms. One record is added to the data file
every 1 s.

Here is some logging output from my datasource plugin. I have logging
output in every other function and I don't see any of it, so none of
the other datasource plugin functions that I've reimplemented are
getting called while this is going on.

Update number of records: 581 -> 582
readField: field0  s: 580  n: 2
readField: field1  s: 580  n: 2
readField: field2  s: 580  n: 2

Update number of records: 582 -> 583
readField: field0  s: 0    n: 583
readField: field1  s: 0    n: 583
readField: field2  s: 0    n: 583

Update number of records: 583 -> 584
readField: field0  s: 582  n: 2
readField: field1  s: 582  n: 2
readField: field2  s: 582  n: 2

Update number of records: 584 -> 585
readField: field0  s: 0    n: 585
readField: field0  s: 0    n: 585
readField: field0  s: 0    n: 585


Here are the relevant functions:

KstObject::UpdateType MySource::update(int u)
{
    printf("Update ");
    if (KstObject::checkUpdateCounter(u)) {
        printf("Returning previous result\n");
        return lastUpdateResult();
    }

    int newRecordCount = (int)floor((float)(_file.size() -
_dataOffset) / (float)_recordSize);

    if (newRecordCount == _recordCount) {
        printf("No change\n");
        return setLastUpdateResult(KstObject::NO_CHANGE);
    } else {
        printf("number of records: %i -> %i\n", _recordCount, newRecordCount);
        _recordCount = newRecordCount;
        updateNumFramesScalar();
        return setLastUpdateResult(KstObject::UPDATE);
    }
}


int MySource::readField(double *v, const QString& field, int s, int n)
{
    printf("readField: %20s\ts: %3i\tn: %3i\n", field.ascii(), s, n);

    // n < 0 means read one sample, not frame - irrelevent here
    if (n < 0) {
        n = 1;
    }

    // seek to the first record
    _file.at(_dataOffset + (_recordSize * s));

    int samplesRead = 0;
    int index = _fieldList.findIndex(field);

    LogfileRecord* file_record = (LogfileRecord*) malloc(_recordSize);
    for (int i = 0; i < n; i++) {
        if (_file.readBlock((char*)file_record, _recordSize) <
(Q_LONG)_recordSize) {
            printf("Error reading record %i\n", s + i);
            break;
        }

        v[i] = file_record->value[index];
        samplesRead++;
    }
    free(file_record);

    return samplesRead;
}

Thanks,
Michael


More information about the Kst mailing list