Repository: mesos Updated Branches: refs/heads/master bdaa698e5 -> 925e99ea7
Windows: Stout: Unified POSIX and Windows implementation of process.hpp. Review: https://reviews.apache.org/r/40102 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/925e99ea Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/925e99ea Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/925e99ea Branch: refs/heads/master Commit: 925e99ea71fd23ee5cca4d0086e57d8866ada086 Parents: bdaa698 Author: Alex Clemmer <[email protected]> Authored: Tue Dec 15 09:53:29 2015 -0800 Committer: Joris Van Remoortere <[email protected]> Committed: Tue Dec 15 10:18:28 2015 -0800 ---------------------------------------------------------------------- .../3rdparty/stout/include/Makefile.am | 2 - .../stout/include/stout/os/posix/process.hpp | 177 ------------------- .../3rdparty/stout/include/stout/os/process.hpp | 165 ++++++++++++++++- .../stout/include/stout/os/windows/process.hpp | 51 ------ 4 files changed, 158 insertions(+), 237 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/925e99ea/3rdparty/libprocess/3rdparty/stout/include/Makefile.am ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/3rdparty/stout/include/Makefile.am b/3rdparty/libprocess/3rdparty/stout/include/Makefile.am index a68de8b..d1ef6f0 100644 --- a/3rdparty/libprocess/3rdparty/stout/include/Makefile.am +++ b/3rdparty/libprocess/3rdparty/stout/include/Makefile.am @@ -94,7 +94,6 @@ nobase_include_HEADERS = \ stout/os/posix/killtree.hpp \ stout/os/posix/ls.hpp \ stout/os/posix/mkdtemp.hpp \ - stout/os/posix/process.hpp \ stout/os/posix/pstree.hpp \ stout/os/posix/sendfile.hpp \ stout/os/posix/shell.hpp \ @@ -109,7 +108,6 @@ nobase_include_HEADERS = \ stout/os/windows/killtree.hpp \ stout/os/windows/ls.hpp \ stout/os/windows/mkdtemp.hpp \ - stout/os/windows/process.hpp \ stout/os/windows/pstree.hpp \ stout/os/windows/sendfile.hpp \ stout/os/windows/shell.hpp \ http://git-wip-us.apache.org/repos/asf/mesos/blob/925e99ea/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/process.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/process.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/process.hpp deleted file mode 100644 index ed28e66..0000000 --- a/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/process.hpp +++ /dev/null @@ -1,177 +0,0 @@ -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef __STOUT_OS_POSIX_PROCESS_HPP__ -#define __STOUT_OS_POSIX_PROCESS_HPP__ - -#include <sys/types.h> // For pid_t. - -#include <list> -#include <ostream> -#include <sstream> -#include <string> - -#include <stout/bytes.hpp> -#include <stout/duration.hpp> -#include <stout/none.hpp> -#include <stout/option.hpp> -#include <stout/strings.hpp> - - -namespace os { - -struct Process -{ - Process(pid_t _pid, - pid_t _parent, - pid_t _group, - const Option<pid_t>& _session, - const Option<Bytes>& _rss, - const Option<Duration>& _utime, - const Option<Duration>& _stime, - const std::string& _command, - bool _zombie) - : pid(_pid), - parent(_parent), - group(_group), - session(_session), - rss(_rss), - utime(_utime), - stime(_stime), - command(_command), - zombie(_zombie) {} - - const pid_t pid; - const pid_t parent; - const pid_t group; - const Option<pid_t> session; - const Option<Bytes> rss; - const Option<Duration> utime; - const Option<Duration> stime; - const std::string command; - const bool zombie; - - // TODO(bmahler): Add additional data as needed. - - bool operator<(const Process& p) const { return pid < p.pid; } - bool operator<=(const Process& p) const { return pid <= p.pid; } - bool operator>(const Process& p) const { return pid > p.pid; } - bool operator>=(const Process& p) const { return pid >= p.pid; } - bool operator==(const Process& p) const { return pid == p.pid; } - bool operator!=(const Process& p) const { return pid != p.pid; } -}; - - -class ProcessTree -{ -public: - // Returns a process subtree rooted at the specified PID, or none if - // the specified pid could not be found in this process tree. - Option<ProcessTree> find(pid_t pid) const - { - if (process.pid == pid) { - return *this; - } - - foreach (const ProcessTree& tree, children) { - Option<ProcessTree> option = tree.find(pid); - if (option.isSome()) { - return option; - } - } - - return None(); - } - - // Checks if the specified pid is contained in this process tree. - bool contains(pid_t pid) const - { - return find(pid).isSome(); - } - - operator Process() const - { - return process; - } - - operator pid_t() const - { - return process.pid; - } - - const Process process; - const std::list<ProcessTree> children; - -private: - friend struct Fork; - friend Try<ProcessTree> pstree(pid_t, const std::list<Process>&); - - ProcessTree( - const Process& _process, - const std::list<ProcessTree>& _children) - : process(_process), - children(_children) {} -}; - - -inline std::ostream& operator<<(std::ostream& stream, const ProcessTree& tree) -{ - if (tree.children.empty()) { - stream << "--- " << tree.process.pid << " "; - if (tree.process.zombie) { - stream << "(" << tree.process.command << ")"; - } else { - stream << tree.process.command; - } - } else { - stream << "-+- " << tree.process.pid << " "; - if (tree.process.zombie) { - stream << "(" << tree.process.command << ")"; - } else { - stream << tree.process.command; - } - size_t size = tree.children.size(); - foreach (const ProcessTree& child, tree.children) { - std::ostringstream out; - out << child; - stream << "\n"; - if (--size != 0) { - stream << " |" << strings::replace(out.str(), "\n", "\n |"); - } else { - stream << " \\" << strings::replace(out.str(), "\n", "\n "); - } - } - } - return stream; -} - -} // namespace os { - - -// An overload of stringify for printing a list of process trees -// (since printing a process tree is rather particular). -inline std::string stringify(const std::list<os::ProcessTree>& list) -{ - std::ostringstream out; - out << "[ " << std::endl; - std::list<os::ProcessTree>::const_iterator iterator = list.begin(); - while (iterator != list.end()) { - out << stringify(*iterator); - if (++iterator != list.end()) { - out << std::endl << std::endl; - } - } - out << std::endl << "]"; - return out.str(); -} - -#endif // __STOUT_OS_POSIX_PROCESS_HPP__ http://git-wip-us.apache.org/repos/asf/mesos/blob/925e99ea/3rdparty/libprocess/3rdparty/stout/include/stout/os/process.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/process.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os/process.hpp index 4ed0c47..a91a9d4 100644 --- a/3rdparty/libprocess/3rdparty/stout/include/stout/os/process.hpp +++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/process.hpp @@ -13,14 +13,165 @@ #ifndef __STOUT_OS_PROCESS_HPP__ #define __STOUT_OS_PROCESS_HPP__ +#include <sys/types.h> // For pid_t. -// For readability, we minimize the number of #ifdef blocks in the code by -// splitting platform specifc system calls into separate directories. -#ifdef __WINDOWS__ -#include <stout/os/windows/process.hpp> -#else -#include <stout/os/posix/process.hpp> -#endif // __WINDOWS__ +#include <list> +#include <ostream> +#include <sstream> +#include <string> +#include <stout/bytes.hpp> +#include <stout/duration.hpp> +#include <stout/none.hpp> +#include <stout/option.hpp> +#include <stout/strings.hpp> + + +namespace os { + +struct Process +{ + Process(pid_t _pid, + pid_t _parent, + pid_t _group, + const Option<pid_t>& _session, + const Option<Bytes>& _rss, + const Option<Duration>& _utime, + const Option<Duration>& _stime, + const std::string& _command, + bool _zombie) + : pid(_pid), + parent(_parent), + group(_group), + session(_session), + rss(_rss), + utime(_utime), + stime(_stime), + command(_command), + zombie(_zombie) {} + + const pid_t pid; + const pid_t parent; + const pid_t group; + const Option<pid_t> session; + const Option<Bytes> rss; + const Option<Duration> utime; + const Option<Duration> stime; + const std::string command; + const bool zombie; + + // TODO(bmahler): Add additional data as needed. + + bool operator<(const Process& p) const { return pid < p.pid; } + bool operator<=(const Process& p) const { return pid <= p.pid; } + bool operator>(const Process& p) const { return pid > p.pid; } + bool operator>=(const Process& p) const { return pid >= p.pid; } + bool operator==(const Process& p) const { return pid == p.pid; } + bool operator!=(const Process& p) const { return pid != p.pid; } +}; + + +class ProcessTree +{ +public: + // Returns a process subtree rooted at the specified PID, or none if + // the specified pid could not be found in this process tree. + Option<ProcessTree> find(pid_t pid) const + { + if (process.pid == pid) { + return *this; + } + + foreach (const ProcessTree& tree, children) { + Option<ProcessTree> option = tree.find(pid); + if (option.isSome()) { + return option; + } + } + + return None(); + } + + // Checks if the specified pid is contained in this process tree. + bool contains(pid_t pid) const + { + return find(pid).isSome(); + } + + operator Process() const + { + return process; + } + + operator pid_t() const + { + return process.pid; + } + + const Process process; + const std::list<ProcessTree> children; + +private: + friend struct Fork; + friend Try<ProcessTree> pstree(pid_t, const std::list<Process>&); + + ProcessTree( + const Process& _process, + const std::list<ProcessTree>& _children) + : process(_process), + children(_children) {} +}; + + +inline std::ostream& operator<<(std::ostream& stream, const ProcessTree& tree) +{ + if (tree.children.empty()) { + stream << "--- " << tree.process.pid << " "; + if (tree.process.zombie) { + stream << "(" << tree.process.command << ")"; + } else { + stream << tree.process.command; + } + } else { + stream << "-+- " << tree.process.pid << " "; + if (tree.process.zombie) { + stream << "(" << tree.process.command << ")"; + } else { + stream << tree.process.command; + } + size_t size = tree.children.size(); + foreach (const ProcessTree& child, tree.children) { + std::ostringstream out; + out << child; + stream << "\n"; + if (--size != 0) { + stream << " |" << strings::replace(out.str(), "\n", "\n |"); + } else { + stream << " \\" << strings::replace(out.str(), "\n", "\n "); + } + } + } + return stream; +} + +} // namespace os { + + +// An overload of stringify for printing a list of process trees +// (since printing a process tree is rather particular). +inline std::string stringify(const std::list<os::ProcessTree>& list) +{ + std::ostringstream out; + out << "[ " << std::endl; + std::list<os::ProcessTree>::const_iterator iterator = list.begin(); + while (iterator != list.end()) { + out << stringify(*iterator); + if (++iterator != list.end()) { + out << std::endl << std::endl; + } + } + out << std::endl << "]"; + return out.str(); +} #endif // __STOUT_OS_PROCESS_HPP__ http://git-wip-us.apache.org/repos/asf/mesos/blob/925e99ea/3rdparty/libprocess/3rdparty/stout/include/stout/os/windows/process.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/windows/process.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os/windows/process.hpp deleted file mode 100644 index 8dfd330..0000000 --- a/3rdparty/libprocess/3rdparty/stout/include/stout/os/windows/process.hpp +++ /dev/null @@ -1,51 +0,0 @@ -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef __STOUT_OS_WINDOWS_PROCESS_HPP__ -#define __STOUT_OS_WINDOWS_PROCESS_HPP__ - -#include <list> -#include <ostream> -#include <string> - - -namespace os { - -struct Process -{ - UNIMPLEMENTED; -}; - - -class ProcessTree -{ - UNIMPLEMENTED; -}; - - -inline std::ostream& operator<<(std::ostream& stream, const ProcessTree& tree) -{ - UNIMPLEMENTED; -} - -} // namespace os { - - -// An overload of stringify for printing a list of process trees -// (since printing a process tree is rather particular). -inline std::string stringify(const std::list<os::ProcessTree>& list) -{ - UNIMPLEMENTED; -} - - -#endif // __STOUT_OS_WINDOWS_PROCESS_HPP__
