| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | // Copyright 2019 Juan Palacios <[email protected]> |
| 3 | |
| 4 | #pragma once |
| 5 | |
| 6 | #include "../icpuinfo.h" |
| 7 | #include "core/idatasource.h" |
| 8 | #include <memory> |
| 9 | #include <string> |
| 10 | #include <string_view> |
| 11 | #include <utility> |
| 12 | #include <vector> |
| 13 | |
| 14 | class CPUInfoLsCpu final : public ICPUInfo::IProvider |
| 15 | { |
| 16 | public: |
| 17 | struct Keys |
| 18 | { |
| 19 | |
| 20 | static constexpr std::string_view arch{"arch"}; |
| 21 | static constexpr std::string_view opMode{"opmode"}; |
| 22 | static constexpr std::string_view byteOrder{"byteorder"}; |
| 23 | static constexpr std::string_view virt{"virt"}; |
| 24 | static constexpr std::string_view l1dCache{"l1dcache"}; |
| 25 | static constexpr std::string_view l1iCache{"l1icache"}; |
| 26 | static constexpr std::string_view l2Cache{"l2cache"}; |
| 27 | }; |
| 28 | |
| 29 | CPUInfoLsCpu(std::unique_ptr<IDataSource<std::vector<std::string>>> |
| 30 | &&dataSource) noexcept; |
| 31 | |
| 32 | std::vector<std::pair<std::string, std::string>> provideInfo( |
| 33 | int physicalId, |
| 34 | std::vector<ICPUInfo::ExecutionUnit> const &executionUnits) override; |
| 35 | |
| 36 | std::vector<std::string> provideCapabilities( |
| 37 | int physicalId, |
| 38 | std::vector<ICPUInfo::ExecutionUnit> const &executionUnits) override; |
| 39 | |
| 40 | private: |
| 41 | std::string extractLineData(std::string const &line) const; |
| 42 | void addInfo(std::string_view target, std::string_view key, |
| 43 | std::vector<std::pair<std::string, std::string>> &info, |
| 44 | std::vector<std::string> const &data) const; |
| 45 | |
| 46 | std::unique_ptr<IDataSource<std::vector<std::string>>> const dataSource_; |
| 47 | static bool registered_; |
| 48 | }; |