From 45b3981b8663d1de9f3cdca2900c3a6f302526c2 Mon Sep 17 00:00:00 2001 From: wxyu Date: Mon, 19 Aug 2019 10:47:30 +0800 Subject: [PATCH] MS-379 Add Dump implementation in Resource Former-commit-id: 99d099bfdaaba7173b2b2a96d8e8c8ef916357e7 --- cpp/CHANGELOG.md | 1 + cpp/src/scheduler/Scheduler.cpp | 1 - cpp/src/scheduler/resource/CpuResource.cpp | 4 ++ cpp/src/scheduler/resource/CpuResource.h | 7 +++ cpp/src/scheduler/resource/DiskResource.cpp | 4 ++ cpp/src/scheduler/resource/DiskResource.h | 7 +++ cpp/src/scheduler/resource/GpuResource.cpp | 4 ++ cpp/src/scheduler/resource/GpuResource.h | 7 +++ cpp/src/scheduler/resource/Resource.cpp | 5 +++ cpp/src/scheduler/resource/Resource.h | 7 +++ cpp/unittest/scheduler/normal_test.cpp | 47 ++++++++++++++++----- 11 files changed, 83 insertions(+), 11 deletions(-) diff --git a/cpp/CHANGELOG.md b/cpp/CHANGELOG.md index 8232bd77..4358c5dd 100644 --- a/cpp/CHANGELOG.md +++ b/cpp/CHANGELOG.md @@ -30,6 +30,7 @@ Please mark all change in change log and use the ticket from JIRA. - MS-376 - Add loader and executor enable flag in Resource avoid diskresource execute task - MS-377 - Improve process thread trigger in ResourceMgr, Scheduler and TaskTable - MS-378 - Debug and Update normal_test in scheduler unittest +- MS-379 - Add Dump implementation in Resource ## New Feature - MS-343 - Implement ResourceMgr diff --git a/cpp/src/scheduler/Scheduler.cpp b/cpp/src/scheduler/Scheduler.cpp index 06dfa669..191d1957 100644 --- a/cpp/src/scheduler/Scheduler.cpp +++ b/cpp/src/scheduler/Scheduler.cpp @@ -4,7 +4,6 @@ * Proprietary and confidential. ******************************************************************************/ -#include #include "Scheduler.h" #include "Cost.h" #include "action/Action.h" diff --git a/cpp/src/scheduler/resource/CpuResource.cpp b/cpp/src/scheduler/resource/CpuResource.cpp index 11c77961..01fca35e 100644 --- a/cpp/src/scheduler/resource/CpuResource.cpp +++ b/cpp/src/scheduler/resource/CpuResource.cpp @@ -11,6 +11,10 @@ namespace zilliz { namespace milvus { namespace engine { +std::ostream &operator<<(std::ostream &out, const CpuResource &resource) { + out << resource.Dump(); + return out; +} CpuResource::CpuResource(std::string name) : Resource(std::move(name), ResourceType::CPU) {} diff --git a/cpp/src/scheduler/resource/CpuResource.h b/cpp/src/scheduler/resource/CpuResource.h index be1340e9..c180ea07 100644 --- a/cpp/src/scheduler/resource/CpuResource.h +++ b/cpp/src/scheduler/resource/CpuResource.h @@ -19,6 +19,13 @@ public: explicit CpuResource(std::string name); + inline std::string + Dump() const override { + return ""; + } + + friend std::ostream &operator<<(std::ostream &out, const CpuResource &resource); + protected: void LoadFile(TaskPtr task) override; diff --git a/cpp/src/scheduler/resource/DiskResource.cpp b/cpp/src/scheduler/resource/DiskResource.cpp index 66cb72b0..8612909e 100644 --- a/cpp/src/scheduler/resource/DiskResource.cpp +++ b/cpp/src/scheduler/resource/DiskResource.cpp @@ -10,6 +10,10 @@ namespace zilliz { namespace milvus { namespace engine { +std::ostream &operator<<(std::ostream &out, const DiskResource &resource) { + out << resource.Dump(); + return out; +} DiskResource::DiskResource(std::string name) : Resource(std::move(name), ResourceType::DISK, true, false) { diff --git a/cpp/src/scheduler/resource/DiskResource.h b/cpp/src/scheduler/resource/DiskResource.h index 39211dbb..0fb9d625 100644 --- a/cpp/src/scheduler/resource/DiskResource.h +++ b/cpp/src/scheduler/resource/DiskResource.h @@ -18,6 +18,13 @@ public: explicit DiskResource(std::string name); + inline std::string + Dump() const override { + return ""; + } + + friend std::ostream &operator<<(std::ostream &out, const DiskResource &resource); + protected: void LoadFile(TaskPtr task) override; diff --git a/cpp/src/scheduler/resource/GpuResource.cpp b/cpp/src/scheduler/resource/GpuResource.cpp index df682788..8606bb78 100644 --- a/cpp/src/scheduler/resource/GpuResource.cpp +++ b/cpp/src/scheduler/resource/GpuResource.cpp @@ -11,6 +11,10 @@ namespace zilliz { namespace milvus { namespace engine { +std::ostream &operator<<(std::ostream &out, const GpuResource &resource) { + out << resource.Dump(); + return out; +} GpuResource::GpuResource(std::string name) : Resource(std::move(name), ResourceType::GPU) {} diff --git a/cpp/src/scheduler/resource/GpuResource.h b/cpp/src/scheduler/resource/GpuResource.h index 84bf1632..1cb38df3 100644 --- a/cpp/src/scheduler/resource/GpuResource.h +++ b/cpp/src/scheduler/resource/GpuResource.h @@ -18,6 +18,13 @@ public: explicit GpuResource(std::string name); + inline std::string + Dump() const override { + return ""; + } + + friend std::ostream &operator<<(std::ostream &out, const GpuResource &resource); + protected: void LoadFile(TaskPtr task) override; diff --git a/cpp/src/scheduler/resource/Resource.cpp b/cpp/src/scheduler/resource/Resource.cpp index ed5d57b7..298d1b7d 100644 --- a/cpp/src/scheduler/resource/Resource.cpp +++ b/cpp/src/scheduler/resource/Resource.cpp @@ -10,6 +10,11 @@ namespace zilliz { namespace milvus { namespace engine { +std::ostream &operator<<(std::ostream &out, const Resource &resource) { + out << resource.Dump(); + return out; +} + Resource::Resource(std::string name, ResourceType type, bool enable_loader, diff --git a/cpp/src/scheduler/resource/Resource.h b/cpp/src/scheduler/resource/Resource.h index 769661c6..c32149b4 100644 --- a/cpp/src/scheduler/resource/Resource.h +++ b/cpp/src/scheduler/resource/Resource.h @@ -74,6 +74,13 @@ public: TaskTable & task_table(); + inline virtual std::string + Dump() const { + return ""; + } + + friend std::ostream &operator<<(std::ostream &out, const Resource &resource); + public: /* * wake up loader; diff --git a/cpp/unittest/scheduler/normal_test.cpp b/cpp/unittest/scheduler/normal_test.cpp index 1123a3fb..4d1fa36d 100644 --- a/cpp/unittest/scheduler/normal_test.cpp +++ b/cpp/unittest/scheduler/normal_test.cpp @@ -36,20 +36,47 @@ TEST(normal_test, test1) { observe->task_table().Put(task2); observe->task_table().Put(task3); observe->task_table().Put(task4); - std::cout << "disk:" << std::endl; - std::cout << observe->task_table().Dump() << std::endl; } +// if (auto disk_r = disk.lock()) { +// if (auto cpu_r = cpu.lock()) { +// if (auto gpu1_r = gpu1.lock()) { +// if (auto gpu2_r = gpu2.lock()) { +// std::cout << "<<<<<<<<<task_table().Dump() << std::endl; +// std::cout << "cpu:" << std::endl; +// std::cout << cpu_r->task_table().Dump() << std::endl; +// std::cout << "gpu1:" << std::endl; +// std::cout << gpu1_r->task_table().Dump() << std::endl; +// std::cout << "gpu2:" << std::endl; +// std::cout << gpu2_r->task_table().Dump() << std::endl; +// std::cout << ">>>>>>>>>>before>>>>>>>>>>" << std::endl; +// } +// } +// } +// } + sleep(5); - if (auto observe = disk.lock()) { - std::cout << "disk:" << std::endl; - std::cout << observe->task_table().Dump() << std::endl; - } - if (auto observe = cpu.lock()) { - std::cout << "cpu:" << std::endl; - std::cout << observe->task_table().Dump() << std::endl; - } +// if (auto disk_r = disk.lock()) { +// if (auto cpu_r = cpu.lock()) { +// if (auto gpu1_r = gpu1.lock()) { +// if (auto gpu2_r = gpu2.lock()) { +// std::cout << "<<<<<<<<<task_table().Dump() << std::endl; +// std::cout << "cpu:" << std::endl; +// std::cout << cpu_r->task_table().Dump() << std::endl; +// std::cout << "gpu1:" << std::endl; +// std::cout << gpu1_r->task_table().Dump() << std::endl; +// std::cout << "gpu2:" << std::endl; +// std::cout << gpu2_r->task_table().Dump() << std::endl; +// std::cout << ">>>>>>>>>>after>>>>>>>>>>" << std::endl; +// } +// } +// } +// } scheduler->Stop(); res_mgr->Stop(); -- GitLab