示例#1
0
void RandomQueueGenerator::createRandomApp(unsigned int numTasks) {
    Time now = Time::getCurrentTime();
    int a = getRandomAppLength() / numTasks;
    Duration alreadyExecuted(0.0);
    double r;
    Time endtime = now;
    TaskDescription description;
    description.setNumTasks(numTasks);
    description.setLength(a);
    // TODO: memory and disk
    if (currentTasks.empty()) {
        // Get a release date so that the first task is still executing
        currentrfirst = -a / currentPower;
        currentrfirst = tsum = r = getRandomReleaseDelta();
        alreadyExecuted -= Duration(r);
    } else {
        r = getRandomReleaseDelta();
        endtime = currentTasks.back()->getDescription().getDeadline();
    }
    Time creationTime = now + Duration(r);
    tsum += a * numTasks / currentPower;
    if (endtime < now + Duration(tsum))
        endtime = now + Duration(tsum);
    description.setDeadline(endtime + Duration(getRandomAppLength() / numTasks / currentPower));
    for (unsigned int taskid = 0; taskid < numTasks; ++taskid) {
        std::shared_ptr<TestTask> newTask(new TestTask(CommAddress(), appId, taskid, description, currentPower));
        newTask->setCreationTime(creationTime);
        currentTasks.push_back(newTask);
    }
    ++appId;
    std::static_pointer_cast<TestTask>(currentTasks.front())->execute(alreadyExecuted);
}