| 1 | // SPDX-License-Identifier: GPL-3.0-or-latercxx . . $ `<file>/src/core/components/cpuprofilepart.cpp`/ |
| 2 | // Copyright 2019 Juan Palacios <[email protected]> |
| 3 | |
| 4 | #include "cpuprofilepart.h"cxx . . $ `<file>/src/core/components/cpuprofilepart.h`/ |
| 5 | |
| 6 | #include "core/info/icpuinfo.h"cxx . . $ `<file>/src/core/info/icpuinfo.h`/ |
| 7 | #include "core/profilepart.h"cxx . . $ `<file>/src/core/profilepart.h`/ |
| 8 | #include "core/profilepartprovider.h"cxx . . $ `<file>/src/core/profilepartprovider.h`/ |
| 9 | #include "sensors/isensor.h"cxx . . $ `<file>/src/core/components/sensors/isensor.h`/ |
| 10 | #include <algorithm> |
| 11 | #include <iterator> |
| 12 | #include <unordered_map> |
| 13 | #include <utility> |
| 14 | |
| 15 | class CPUProfilePartcxx . . $ CPUProfilePart#::Factorycxx . . $ CPUProfilePart#Factory# final |
| 16 | : public ProfilePartcxx . . $ ProfilePart#::Factorycxx . . $ ProfilePart#Factory# |
| 17 | , public ICPUcxx . . $ ICPU#::Exportercxx . . $ ICPU#Exporter# |
| 18 | { |
| 19 | public: |
| 20 | Factorycxx . . $ CPUProfilePart#Factory#Factory(5a80ec14891bbda5).(IProfilePartProvidercxx . . $ IProfilePartProvider# const &profilePartProvider, |
| 21 | CPUProfilePartcxx . . $ CPUProfilePart# &outer) noexcept |
| 22 | : ProfilePartcxx . . $ ProfilePart#::Factorycxx . . $ ProfilePart#Factory#(profilePartProvider) |
| 23 | , outer_cxx . . $ CPUProfilePart#Factory#outer_.(outer) |
| 24 | { |
| 25 | } |
| 26 | |
| 27 | void takeProfilePartcxx . . $ CPUProfilePart#Factory#takeProfilePart(8c7717026cb6ec4).(stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<IProfilePartcxx . . $ IProfilePart#> &&part) override; |
| 28 | |
| 29 | stdcxx . . $ std/::optionalcxx . . $ std/optional#<stdcxx . . $ std/::reference_wrappercxx . . $ std/reference_wrapper#<Exportablecxx . . $ Exportable#::Exportercxx . . $ Exportable#Exporter#>> |
| 30 | provideExportercxx . . $ CPUProfilePart#Factory#provideExporter(3acccbde2694e33a).(Itemcxx . . $ Item# const &i) override; |
| 31 | |
| 32 | void takeActivecxx . . $ CPUProfilePart#Factory#takeActive(b45ddcbc8423892c).(bool) override |
| 33 | { |
| 34 | } |
| 35 | |
| 36 | void takeInfocxx . . $ CPUProfilePart#Factory#takeInfo(b148e3110650f661).(ICPUInfocxx . . $ ICPUInfo# const &) override; |
| 37 | void takeSensorcxx . . $ CPUProfilePart#Factory#takeSensor(73745a8c6f82d10e).(ISensorcxx . . $ ISensor# const &) override; |
| 38 | |
| 39 | private: |
| 40 | CPUProfilePartcxx . . $ CPUProfilePart# &outer_cxx . . $ CPUProfilePart#Factory#outer_.; |
| 41 | }; |
| 42 | |
| 43 | void CPUProfilePartcxx . . $ CPUProfilePart#::Factorycxx . . $ CPUProfilePart#Factory#::takeProfilePartcxx . . $ CPUProfilePart#Factory#takeProfilePart(8c7717026cb6ec4).(stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<IProfilePartcxx . . $ IProfilePart#> &&part) |
| 44 | { |
| 45 | outer_cxx . . $ CPUProfilePart#Factory#outer_..parts_cxx . . $ CPUProfilePart#parts_..emplace_backcxx . . $ std/vector#emplace_back(a1bcdfdabc3a37df).(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(part)); |
| 46 | } |
| 47 | |
| 48 | stdcxx . . $ std/::optionalcxx . . $ std/optional#<stdcxx . . $ std/::reference_wrappercxx . . $ std/reference_wrapper#<Exportablecxx . . $ Exportable#::Exportercxx . . $ Exportable#Exporter#>> |
| 49 | CPUProfilePartcxx . . $ CPUProfilePart#::Factorycxx . . $ CPUProfilePart#Factory#::provideExportercxx . . $ CPUProfilePart#Factory#provideExporter(3acccbde2694e33a).(Itemcxx . . $ Item# const &i) |
| 50 | { |
| 51 | return factorycxx . . $ ProfilePart#Factory#factory(f4c9227945a043b8).(i.IDcxx . . $ Item#ID(f4fff0029955a25f).()); |
| 52 | } |
| 53 | |
| 54 | void CPUProfilePartcxx . . $ CPUProfilePart#::Factorycxx . . $ CPUProfilePart#Factory#::takeInfocxx . . $ CPUProfilePart#Factory#takeInfo(b148e3110650f661).(ICPUInfocxx . . $ ICPUInfo# const &info) |
| 55 | { |
| 56 | // NOTE info and system component key must be initialized here |
| 57 | outer_cxx . . $ CPUProfilePart#Factory#outer_..physicalId_cxx . . $ CPUProfilePart#physicalId_. = info.physicalIdcxx . . $ ICPUInfo#physicalId(455f465bc33b4cdf).(); |
| 58 | outer_cxx . . $ CPUProfilePart#Factory#outer_..updateKeycxx . . $ CPUProfilePart#updateKey(49f6e7a06ebc5aa8).(); |
| 59 | } |
| 60 | |
| 61 | void CPUProfilePartcxx . . $ CPUProfilePart#::Factorycxx . . $ CPUProfilePart#Factory#::takeSensorcxx . . $ CPUProfilePart#Factory#takeSensor(73745a8c6f82d10e).(ISensorcxx . . $ ISensor# const &sensor) |
| 62 | { |
| 63 | auto sensorProfilePart = createPartcxx . . $ ProfilePart#Factory#createPart(eebc246fe191e829).(sensor.IDcxx . . $ Item#ID(f4fff0029955a25f).()); |
| 64 | if (sensorProfilePart != nullptr) |
| 65 | outer_cxx . . $ CPUProfilePart#Factory#outer_..parts_cxx . . $ CPUProfilePart#parts_..emplace_backcxx . . $ std/vector#emplace_back(a1bcdfdabc3a37df).(stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(sensorProfilePart)); |
| 66 | } |
| 67 | |
| 68 | class CPUProfilePartcxx . . $ CPUProfilePart#::Initializercxx . . $ CPUProfilePart#Initializer# final : public ICPUcxx . . $ ICPU#::Exportercxx . . $ ICPU#Exporter# |
| 69 | { |
| 70 | public: |
| 71 | Initializercxx . . $ CPUProfilePart#Initializer#Initializer(34a863d5e6d4039f).(CPUProfilePartcxx . . $ CPUProfilePart# &outer) noexcept |
| 72 | : outer_cxx . . $ CPUProfilePart#Initializer#outer_.(outer) |
| 73 | { |
| 74 | } |
| 75 | |
| 76 | stdcxx . . $ std/::optionalcxx . . $ std/optional#<stdcxx . . $ std/::reference_wrappercxx . . $ std/reference_wrapper#<Exportablecxx . . $ Exportable#::Exportercxx . . $ Exportable#Exporter#>> |
| 77 | provideExportercxx . . $ CPUProfilePart#Initializer#provideExporter(3acccbde2694e33a).(Itemcxx . . $ Item# const &i) override; |
| 78 | |
| 79 | void takeActivecxx . . $ CPUProfilePart#Initializer#takeActive(b45ddcbc8423892c).(bool active) override; |
| 80 | |
| 81 | void takeInfocxx . . $ CPUProfilePart#Initializer#takeInfo(b148e3110650f661).(ICPUInfocxx . . $ ICPUInfo# const &) override |
| 82 | { |
| 83 | } |
| 84 | |
| 85 | void takeSensorcxx . . $ CPUProfilePart#Initializer#takeSensor(73745a8c6f82d10e).(ISensorcxx . . $ ISensor# const &) override |
| 86 | { |
| 87 | } |
| 88 | |
| 89 | private: |
| 90 | CPUProfilePartcxx . . $ CPUProfilePart# &outer_cxx . . $ CPUProfilePart#Initializer#outer_.; |
| 91 | stdcxx . . $ std/::unordered_mapcxx . . $ std/unordered_map#<stdcxx . . $ std/::stringcxx . . $ std/string#, stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<Exportablecxx . . $ Exportable#::Exportercxx . . $ Exportable#Exporter#>> initializers_cxx . . $ CPUProfilePart#Initializer#initializers_.; |
| 92 | }; |
| 93 | |
| 94 | stdcxx . . $ std/::optionalcxx . . $ std/optional#<stdcxx . . $ std/::reference_wrappercxx . . $ std/reference_wrapper#<Exportablecxx . . $ Exportable#::Exportercxx . . $ Exportable#Exporter#>> |
| 95 | CPUProfilePartcxx . . $ CPUProfilePart#::Initializercxx . . $ CPUProfilePart#Initializer#::provideExportercxx . . $ CPUProfilePart#Initializer#provideExporter(3acccbde2694e33a).(Itemcxx . . $ Item# const &i) |
| 96 | { |
| 97 | for (auto &part : outer_cxx . . $ CPUProfilePart#Initializer#outer_..parts_cxx . . $ CPUProfilePart#parts_.) { |
| 98 | auto &id = part->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).IDcxx . . $ Item#ID(f4fff0029955a25f).(); |
| 99 | if (id ==cxx . . $ std/`operator==`(5ea818b58063a774). i.IDcxx . . $ Item#ID(f4fff0029955a25f).()) { |
| 100 | if (initializers_cxx . . $ CPUProfilePart#Initializer#initializers_..countcxx . . $ std/unordered_map#count(b71ff106d381144b).(id) > 0) |
| 101 | return *cxx . . $ std/optional#optional(e3f0d6382bd52f24).initializers_cxx . . $ CPUProfilePart#Initializer#initializers_..atcxx . . $ std/unordered_map#at(4f10b6009f0ee734).(id); |
| 102 | else { |
| 103 | auto initializer = part->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).initializercxx . . $ IProfilePart#initializer(6b4e1016740e578).(); |
| 104 | if (initializer != nullptr) { |
| 105 | initializers_cxx . . $ CPUProfilePart#Initializer#initializers_..emplacecxx . . $ std/unordered_map#emplace(8e800962ae7274b6).(id, stdcxx . . $ std/::movecxx . . $ std/move(e35c19a1ba7baa26).(initializer)); |
| 106 | return *cxx . . $ std/optional#optional(e3f0d6382bd52f24).initializers_cxx . . $ CPUProfilePart#Initializer#initializers_..atcxx . . $ std/unordered_map#at(4f10b6009f0ee734).(id); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | break; |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | return {cxx . . $ std/optional#optional(ced63f7c635d850d).}; |
| 115 | } |
| 116 | |
| 117 | void CPUProfilePartcxx . . $ CPUProfilePart#::Initializercxx . . $ CPUProfilePart#Initializer#::takeActivecxx . . $ CPUProfilePart#Initializer#takeActive(b45ddcbc8423892c).(bool active) |
| 118 | { |
| 119 | outer_cxx . . $ CPUProfilePart#Initializer#outer_..activatecxx . . $ ProfilePart#activate(b45ddcbc8423892c).(active); |
| 120 | } |
| 121 | |
| 122 | CPUProfilePartcxx . . $ CPUProfilePart#::CPUProfilePartcxx . . $ CPUProfilePart#CPUProfilePart(ced63f7c635d850d).() noexcept |
| 123 | : id_cxx . . $ CPUProfilePart#id_.(ICPUcxx . . $ ICPU#::ItemIDcxx . . $ ICPU#ItemID.) |
| 124 | { |
| 125 | } |
| 126 | |
| 127 | stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<Exportablecxx . . $ Exportable#::Exportercxx . . $ Exportable#Exporter#> |
| 128 | CPUProfilePartcxx . . $ CPUProfilePart#::factorycxx . . $ CPUProfilePart#factory(af48dc8d4887b70c).(IProfilePartProvidercxx . . $ IProfilePartProvider# const &profilePartProvider) |
| 129 | { |
| 130 | return stdcxx . . $ std/unique_ptr#unique_ptr(8bcafd3b0b660df8).::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<CPUProfilePartcxx . . $ CPUProfilePart#::Factorycxx . . $ CPUProfilePart#Factory#>(profilePartProvider, *this); |
| 131 | } |
| 132 | |
| 133 | stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<Exportablecxx . . $ Exportable#::Exportercxx . . $ Exportable#Exporter#> CPUProfilePartcxx . . $ CPUProfilePart#::initializercxx . . $ CPUProfilePart#initializer(6b4e1016740e578).() |
| 134 | { |
| 135 | return stdcxx . . $ std/unique_ptr#unique_ptr(8bcafd3b0b660df8).::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<CPUProfilePartcxx . . $ CPUProfilePart#::Initializercxx . . $ CPUProfilePart#Initializer#>(*this); |
| 136 | } |
| 137 | |
| 138 | stdcxx . . $ std/::stringcxx . . $ std/string# const &CPUProfilePartcxx . . $ CPUProfilePart#::IDcxx . . $ CPUProfilePart#ID(f4fff0029955a25f).() const |
| 139 | { |
| 140 | return id_cxx . . $ CPUProfilePart#id_.; |
| 141 | } |
| 142 | |
| 143 | bool CPUProfilePartcxx . . $ CPUProfilePart#::belongsTocxx . . $ CPUProfilePart#belongsTo(744b9d71fca8c8b7).(Itemcxx . . $ Item# const &i) const |
| 144 | { |
| 145 | auto cpu = dynamic_cast<ICPUcxx . . $ ICPU# const *>(&i); |
| 146 | if (cpu != nullptr) |
| 147 | return cpu->infocxx . . $ ICPU#info(95bebdd3f04fe09b).().physicalIdcxx . . $ ICPUInfo#physicalId(455f465bc33b4cdf).() == physicalId_cxx . . $ CPUProfilePart#physicalId_.; |
| 148 | |
| 149 | return false; |
| 150 | } |
| 151 | |
| 152 | stdcxx . . $ std/::stringcxx . . $ std/string# const &CPUProfilePartcxx . . $ CPUProfilePart#::keycxx . . $ CPUProfilePart#key(f4fff0029955a25f).() const |
| 153 | { |
| 154 | return key_cxx . . $ CPUProfilePart#key_.; |
| 155 | } |
| 156 | |
| 157 | stdcxx . . $ std/::optionalcxx . . $ std/optional#<stdcxx . . $ std/::reference_wrappercxx . . $ std/reference_wrapper#<Importablecxx . . $ Importable#::Importercxx . . $ Importable#Importer#>> |
| 158 | CPUProfilePartcxx . . $ CPUProfilePart#::provideImportercxx . . $ CPUProfilePart#provideImporter(c13a3bcac0db4745).(Itemcxx . . $ Item# const &i) |
| 159 | { |
| 160 | auto &id = i.IDcxx . . $ Item#ID(f4fff0029955a25f).(); |
| 161 | auto partIter = stdcxx . . $ std/::find_ifcxx . . $ std/find_if(f0a0a4f94ee5cb00).( |
| 162 | parts_cxx . . $ CPUProfilePart#parts_..cbegincxx . . $ std/vector#cbegin(d1e1699016b9d7e6).(), parts_cxx . . $ CPUProfilePart#parts_..cendcxx . . $ std/vector#cend(d1e1699016b9d7e6).(), |
| 163 | [&](auto const &part) { return part->ID() == id; }); |
| 164 | |
| 165 | if (partIter != parts_cxx . . $ CPUProfilePart#parts_..cendcxx . . $ std/vector#cend(d1e1699016b9d7e6).()) { |
| 166 | auto importer = dynamic_cast<Importablecxx . . $ Importable#::Importercxx . . $ Importable#Importer# *>(partIter->cxx . . $ __gnu_cxx/__normal_iterator#`operator->`(65c2ec7035a77d3e).getcxx . . $ std/unique_ptr#get(ea7391e9eeeaf20e).()); |
| 167 | if (importer != nullptr) |
| 168 | return *cxx . . $ std/optional#optional(e3f0d6382bd52f24).importer; |
| 169 | } |
| 170 | |
| 171 | return {cxx . . $ std/optional#optional(ced63f7c635d850d).}; |
| 172 | } |
| 173 | |
| 174 | bool CPUProfilePartcxx . . $ CPUProfilePart#::provideActivecxx . . $ CPUProfilePart#provideActive(50ce9a9e25b4a850).() const |
| 175 | { |
| 176 | return activecxx . . $ ProfilePart#active(50ce9a9e25b4a850).(); |
| 177 | } |
| 178 | |
| 179 | void CPUProfilePartcxx . . $ CPUProfilePart#::importProfilePartcxx . . $ CPUProfilePart#importProfilePart(d62b6a6dfe9fe695).(IProfilePartcxx . . $ IProfilePart#::Importercxx . . $ IProfilePart#Importer# &i) |
| 180 | { |
| 181 | int oldPhysicalId = physicalId_cxx . . $ CPUProfilePart#physicalId_.; |
| 182 | |
| 183 | auto &partImporter = dynamic_cast<ICPUProfilePartcxx . . $ ICPUProfilePart#::Importercxx . . $ ICPUProfilePart#Importer# &>(i); |
| 184 | physicalId_cxx . . $ CPUProfilePart#physicalId_. = partImporter.providePhysicalIdcxx . . $ ICPUProfilePart#Importer#providePhysicalId(455f465bc33b4cdf).(); |
| 185 | |
| 186 | if (oldPhysicalId != physicalId_cxx . . $ CPUProfilePart#physicalId_.) |
| 187 | updateKeycxx . . $ CPUProfilePart#updateKey(49f6e7a06ebc5aa8).(); |
| 188 | |
| 189 | for (auto &part : parts_cxx . . $ CPUProfilePart#parts_.) |
| 190 | part->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).importWithcxx . . $ Importable#importWith(94eddebf9440278).(i); |
| 191 | } |
| 192 | |
| 193 | void CPUProfilePartcxx . . $ CPUProfilePart#::exportProfilePartcxx . . $ CPUProfilePart#exportProfilePart(702e13e8794d0da4).(IProfilePartcxx . . $ IProfilePart#::Exportercxx . . $ IProfilePart#Exporter# &e) const |
| 194 | { |
| 195 | auto &partExporter = dynamic_cast<ICPUProfilePartcxx . . $ ICPUProfilePart#::Exportercxx . . $ ICPUProfilePart#Exporter# &>(e); |
| 196 | partExporter.takePhysicalIdcxx . . $ ICPUProfilePart#Exporter#takePhysicalId(d4f767463ce0a6b3).(physicalId_cxx . . $ CPUProfilePart#physicalId_.); |
| 197 | |
| 198 | for (auto const &part : parts_cxx . . $ CPUProfilePart#parts_.) |
| 199 | part->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).exportWithcxx . . $ Exportable#exportWith(5b5c94ff60635419).(e); |
| 200 | } |
| 201 | |
| 202 | stdcxx . . $ std/::unique_ptrcxx . . $ std/unique_ptr#<IProfilePartcxx . . $ IProfilePart#> CPUProfilePartcxx . . $ CPUProfilePart#::cloneProfilePartcxx . . $ CPUProfilePart#cloneProfilePart(1378fcc1caef3e7b).() const |
| 203 | { |
| 204 | auto clone = stdcxx . . $ std/::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<CPUProfilePartcxx . . $ CPUProfilePart#>(); |
| 205 | clone->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).physicalId_cxx . . $ CPUProfilePart#physicalId_. = physicalId_cxx . . $ CPUProfilePart#physicalId_.; |
| 206 | clone->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).key_cxx . . $ CPUProfilePart#key_. =cxx . . $ std/__cxx11/basic_string#`operator=`(c0b47be1fddc0e75). key_cxx . . $ CPUProfilePart#key_.; |
| 207 | clone->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).parts_cxx . . $ CPUProfilePart#parts_..reservecxx . . $ std/vector#reserve(2c44cd906ae4e829).(parts_cxx . . $ CPUProfilePart#parts_..sizecxx . . $ std/vector#size(c9b1e749b64d5edc).()); |
| 208 | stdcxx . . $ std/::transformcxx . . $ std/transform(da30451c4a040264).(parts_cxx . . $ CPUProfilePart#parts_..cbegincxx . . $ std/vector#cbegin(d1e1699016b9d7e6).(), parts_cxx . . $ CPUProfilePart#parts_..cendcxx . . $ std/vector#cend(d1e1699016b9d7e6).(), |
| 209 | stdcxx . . $ std/::back_insertercxx . . $ std/back_inserter(7b559d6bdd90ff74).(clone->cxx . . $ std/unique_ptr#`operator->`(ea7391e9eeeaf20e).parts_cxx . . $ CPUProfilePart#parts_.), |
| 210 | [](auto const &part) { return part->clone(); }); |
| 211 | |
| 212 | return stdcxx . . $ std/unique_ptr#unique_ptr(8bcafd3b0b660df8).::movecxx . . $ std/move(e35c19a1ba7baa26).(clone); |
| 213 | } |
| 214 | |
| 215 | void CPUProfilePartcxx . . $ CPUProfilePart#::updateKeycxx . . $ CPUProfilePart#updateKey(49f6e7a06ebc5aa8).() |
| 216 | { |
| 217 | key_cxx . . $ CPUProfilePart#key_. =cxx . . $ std/__cxx11/basic_string#`operator=`(36befb0d0c9f966). "CPU" +cxx . . $ std/operator+(39ed2c165380f78e). stdcxx . . $ std/::to_stringcxx . . $ std/__cxx11/to_string(3d81e17e7a87eecc).(physicalId_cxx . . $ CPUProfilePart#physicalId_.); |
| 218 | } |
| 219 | |
| 220 | bool const CPUProfilePartcxx . . $ CPUProfilePart#::registered_cxx . . $ CPUProfilePart#registered_. = ProfilePartProvidercxx . . $ ProfilePartProvider#::registerProvidercxx . . $ ProfilePartProvider#registerProvider(f190789c485b6dcd).( |
| 221 | ICPUcxx . . $ std/basic_string_view#basic_string_view(b419d9def655ef02).::ItemIDcxx . . $ ICPU#ItemID., [cxx . . $ std/function#function(bdc3712e480e4d04).]() { return stdcxx . . $ std/::make_uniquecxx . . $ std/make_unique(5cd499e8540a10bb).<CPUProfilePartcxx . . $ CPUProfilePart#>(); }); |