diff options
author | Tor Brede Vekterli <vekterli@vespa.ai> | 2023-10-31 16:32:58 +0000 |
---|---|---|
committer | Tor Brede Vekterli <vekterli@vespa.ai> | 2023-11-01 10:01:33 +0000 |
commit | fba51caeea9e670dc0ba3fba93d6452105ce4c36 (patch) | |
tree | 342c9780d66d20c5c083abe3dd7dd1bcfaa53109 /vespalib | |
parent | 5f56954b95d9c0201d33373a35d1172b50c994cd (diff) |
Move `HwInfo` from `proton` namespace to `vespalib`
This is information that is valuable to many different components,
not just the search core internals.
Diffstat (limited to 'vespalib')
-rw-r--r-- | vespalib/src/vespa/vespalib/util/hw_info.h | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/vespalib/src/vespa/vespalib/util/hw_info.h b/vespalib/src/vespa/vespalib/util/hw_info.h new file mode 100644 index 00000000000..2632aa70654 --- /dev/null +++ b/vespalib/src/vespa/vespalib/util/hw_info.h @@ -0,0 +1,80 @@ +// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include <cstdint> +#include <algorithm> + +namespace vespalib { + +/* + * Class describing some hardware on the machine. + */ +class HwInfo +{ +public: + class Disk { + private: + uint64_t _sizeBytes; + bool _slow; + bool _shared; + public: + Disk(uint64_t sizeBytes_, bool slow_, bool shared_) + : _sizeBytes(sizeBytes_), _slow(slow_), _shared(shared_) {} + uint64_t sizeBytes() const { return _sizeBytes; } + bool slow() const { return _slow; } + bool shared() const { return _shared; } + bool operator == (const Disk & rhs) const { + return (_sizeBytes == rhs._sizeBytes) && (_slow == rhs._slow) && (_shared == rhs._shared); + } + }; + + class Memory { + private: + uint64_t _sizeBytes; + public: + Memory(uint64_t sizeBytes_) : _sizeBytes(sizeBytes_) {} + uint64_t sizeBytes() const { return _sizeBytes; } + bool operator == (const Memory & rhs) const { return _sizeBytes == rhs._sizeBytes; } + }; + + class Cpu { + private: + uint32_t _cores; + public: + Cpu(uint32_t cores_) : _cores(std::max(1u, cores_)) { } + uint32_t cores() const { return _cores; } + bool operator == (const Cpu & rhs) const { return _cores == rhs._cores; } + }; + +private: + Disk _disk; + Memory _memory; + Cpu _cpu; + +public: + HwInfo() + : _disk(0, false, false), + _memory(0), + _cpu(1) + { + } + + HwInfo(const Disk &disk_, + const Memory &memory_, + const Cpu &cpu_) + : _disk(disk_), + _memory(memory_), + _cpu(cpu_) + { + } + + const Disk &disk() const { return _disk; } + const Memory &memory() const { return _memory; } + const Cpu &cpu() const { return _cpu; } + bool operator == (const HwInfo & rhs) const { + return (_cpu == rhs._cpu) && (_disk == rhs._disk) && (_memory == rhs._memory); + } +}; + +} |