From 369d73e7f6f5bd045dcb3d619324dff9bb42d44b Mon Sep 17 00:00:00 2001 From: kaetemi Date: Fri, 9 Mar 2012 19:33:29 +0100 Subject: [PATCH] Added: #1440 Test command for task queue loading --HG-- branch : build_pipeline_v3 --- .../pipeline/service/build_task_queue.cpp | 45 +++++++++++++++++-- .../tools/pipeline/service/build_task_queue.h | 5 +++ .../pipeline/service/pipeline_service.cpp | 30 +++++++++++++ 3 files changed, 76 insertions(+), 4 deletions(-) diff --git a/code/nel/tools/pipeline/service/build_task_queue.cpp b/code/nel/tools/pipeline/service/build_task_queue.cpp index 08a2f93f7..fb103cb9c 100644 --- a/code/nel/tools/pipeline/service/build_task_queue.cpp +++ b/code/nel/tools/pipeline/service/build_task_queue.cpp @@ -129,7 +129,7 @@ CBuildTaskInfo *CBuildTaskQueue::getTaskForSlave(const std::vector &avai m_Mutex.lock(); std::vector availableTasks; createBuildableTaskList(availableTasks, m_BypassDependencyError); - sortBuildableTaskListByMostDependents(availableTasks); + sortBuildableTaskListByMostWaitingDependents(availableTasks); for (std::vector::iterator it = availableTasks.begin(), end = availableTasks.end(); it != end; ++it) { CBuildTaskInfo *task = (*it); @@ -243,9 +243,23 @@ uint CBuildTaskQueue::countRemainingBuildableTasksAndWorkingTasks() void CBuildTaskQueue::listTaskQueueByMostDependents(std::vector &result) { result.clear(); - result.reserve(m_Tasks.size()); - /*copy(m_Tasks.begin(), m_Tasks.end(), result); - sortBuildableTaskListByMostDependents(result);*/ + result = m_Tasks; // copy + sortBuildableTaskListByMostDependents(result); +} + +void CBuildTaskQueue::countWaitingDependents(uint &dependentResult, CBuildTaskInfo *taskInfo) +{ + uint nb = 0; + for (std::vector::size_type i = 0; i < m_Tasks.size(); ++i) + if (m_Tasks[i]->State == TASK_WAITING && doesTaskDependOnTask(m_Tasks[i], taskInfo)) ++nb; + dependentResult = nb; +} + +void CBuildTaskQueue::flagWaitingDependents(std::vector &dependentResult, CBuildTaskInfo *taskInfo) +{ + dependentResult.resize(m_Tasks.size()); + for (std::vector::size_type i = 0; i < dependentResult.size(); ++i) + dependentResult[i] = (m_Tasks[i]->State == TASK_WAITING && doesTaskDependOnTask(m_Tasks[i], taskInfo)); } void CBuildTaskQueue::countDependents(uint &dependentResult, CBuildTaskInfo *taskInfo) @@ -330,6 +344,29 @@ void CBuildTaskQueue::sortBuildableTaskListByMostDependents(std::vector &result) +{ + // brings most urgent tasks on top + std::vector dependentsCache; + dependentsCache.resize(result.size()); + for (std::vector::size_type i = 0; i < dependentsCache.size(); ++i) + countWaitingDependents(dependentsCache[i], result[i]); + uint sc; + do + { + sc = 0; + for (std::vector::size_type i = 0; i < dependentsCache.size() - 1; ++i) + { + if (dependentsCache[i + 1] > dependentsCache[i]) + { + swap(dependentsCache[i], dependentsCache[i + 1]); + swap(result[i], result[i + 1]); + ++sc; + } + } + } while (sc != 0); +} + } /* namespace PIPELINE */ /* end of file */ diff --git a/code/nel/tools/pipeline/service/build_task_queue.h b/code/nel/tools/pipeline/service/build_task_queue.h index d25f1e39c..6a27da0fc 100644 --- a/code/nel/tools/pipeline/service/build_task_queue.h +++ b/code/nel/tools/pipeline/service/build_task_queue.h @@ -121,6 +121,10 @@ public: private: // void countDependencies(uint &waitingResult, uint &failAbortResult, CBuildTaskInfo *taskInfo); + /// Same as next but only counts depending tasks that are waiting. + void countWaitingDependents(uint &dependentResult, CBuildTaskInfo *taskInfo); + void flagWaitingDependents(std::vector &dependentResult, CBuildTaskInfo *taskInfo); + /// Recursively count the number of tasks that depend on this task. void countDependents(uint &dependentResult, CBuildTaskInfo *taskInfo); void flagDependents(std::vector &dependentResult, CBuildTaskInfo *taskInfo); @@ -129,6 +133,7 @@ private: void createBuildableTaskList(std::vector &result, bool bypassError); void sortBuildableTaskListByMostDependents(std::vector &result); + void sortBuildableTaskListByMostWaitingDependents(std::vector &result); }; /* class CBuildTaskQueue */ diff --git a/code/nel/tools/pipeline/service/pipeline_service.cpp b/code/nel/tools/pipeline/service/pipeline_service.cpp index 4ab8374c4..00845293b 100644 --- a/code/nel/tools/pipeline/service/pipeline_service.cpp +++ b/code/nel/tools/pipeline/service/pipeline_service.cpp @@ -56,6 +56,7 @@ #include "pipeline_interface_impl.h" #include "pipeline_process_impl.h" #include "../plugin_library/process_info.h" +#include "build_task_queue.h" // using namespace std; using namespace NLMISC; @@ -720,6 +721,35 @@ NLMISC_COMMAND(showDependencies, "Show dependencies.", " tasks; + taskQueue.listTaskQueueByMostDependents(tasks); + + log.displayNL("COUNT: %i", tasks.size()); + + for (std::vector::iterator it = tasks.begin(), end = tasks.end(); it != end; ++it) + { + PIPELINE::CBuildTaskInfo *task = *it; + PIPELINE::CProcessPluginInfo pluginInfo; + PIPELINE::g_PipelineWorkspace->getProcessPlugin(pluginInfo, task->ProcessPluginId); + log.displayNL("TASK: %i: %s, %s", task->Id.Global, task->ProjectName.c_str(), pluginInfo.Handler.c_str()); + } + + taskQueue.abortQueue(); + + log.displayNL("**********************************************************************"); + + return true; +} + NLNET_SERVICE_MAIN(PIPELINE::CPipelineService, PIPELINE_SHORT_SERVICE_NAME, PIPELINE_LONG_SERVICE_NAME, 0, PIPELINE::s_ShardCallbacks, PIPELINE_SERVICE_DIRECTORY, PIPELINE_SERVICE_DIRECTORY) /* end of file */