mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-02 03:39:43 -06:00
instrumentation: Reuse single cmsys::SystemInformation
This commit is contained in:
@@ -3,11 +3,11 @@
|
||||
#include <chrono>
|
||||
#include <ctime>
|
||||
#include <iomanip>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
#include <utility>
|
||||
|
||||
#include <cm/memory>
|
||||
#include <cm/optional>
|
||||
|
||||
#include <cm3p/json/writer.h>
|
||||
@@ -126,6 +126,14 @@ void cmInstrumentation::LoadQueries()
|
||||
}
|
||||
}
|
||||
|
||||
cmsys::SystemInformation& cmInstrumentation::GetSystemInformation()
|
||||
{
|
||||
if (!this->systemInformation) {
|
||||
this->systemInformation = cm::make_unique<cmsys::SystemInformation>();
|
||||
}
|
||||
return *this->systemInformation;
|
||||
}
|
||||
|
||||
bool cmInstrumentation::ReadJSONQueries(std::string const& directory)
|
||||
{
|
||||
cmsys::Directory d;
|
||||
@@ -210,8 +218,7 @@ bool cmInstrumentation::HasPreOrPostBuildHook() const
|
||||
int cmInstrumentation::CollectTimingData(cmInstrumentationQuery::Hook hook)
|
||||
{
|
||||
// Don't run collection if hook is disabled
|
||||
if (hook != cmInstrumentationQuery::Hook::Manual &&
|
||||
this->hooks.find(hook) == this->hooks.end()) {
|
||||
if (hook != cmInstrumentationQuery::Hook::Manual && !this->HasHook(hook)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -299,36 +306,38 @@ int cmInstrumentation::CollectTimingData(cmInstrumentationQuery::Hook hook)
|
||||
void cmInstrumentation::InsertDynamicSystemInformation(
|
||||
Json::Value& root, std::string const& prefix)
|
||||
{
|
||||
cmsys::SystemInformation info;
|
||||
Json::Value data;
|
||||
info.RunCPUCheck();
|
||||
info.RunMemoryCheck();
|
||||
double memory;
|
||||
double load;
|
||||
this->GetDynamicSystemInformation(memory, load);
|
||||
if (!root.isMember("dynamicSystemInformation")) {
|
||||
root["dynamicSystemInformation"] = Json::objectValue;
|
||||
}
|
||||
root["dynamicSystemInformation"][cmStrCat(prefix, "HostMemoryUsed")] =
|
||||
(double)info.GetHostMemoryUsed();
|
||||
root["dynamicSystemInformation"][cmStrCat(prefix, "CPULoadAverage")] =
|
||||
info.GetLoadAverage();
|
||||
memory;
|
||||
root["dynamicSystemInformation"][cmStrCat(prefix, "CPULoadAverage")] = load;
|
||||
}
|
||||
|
||||
void cmInstrumentation::GetDynamicSystemInformation(double& memory,
|
||||
double& load)
|
||||
{
|
||||
cmsys::SystemInformation info;
|
||||
Json::Value data;
|
||||
info.RunCPUCheck();
|
||||
info.RunMemoryCheck();
|
||||
cmsys::SystemInformation& info = this->GetSystemInformation();
|
||||
if (!this->ranSystemChecks) {
|
||||
info.RunCPUCheck();
|
||||
info.RunMemoryCheck();
|
||||
this->ranSystemChecks = true;
|
||||
}
|
||||
memory = (double)info.GetHostMemoryUsed();
|
||||
load = info.GetLoadAverage();
|
||||
}
|
||||
|
||||
void cmInstrumentation::InsertStaticSystemInformation(Json::Value& root)
|
||||
{
|
||||
cmsys::SystemInformation info;
|
||||
info.RunCPUCheck();
|
||||
info.RunOSCheck();
|
||||
info.RunMemoryCheck();
|
||||
cmsys::SystemInformation& info = this->GetSystemInformation();
|
||||
if (!this->ranOSCheck) {
|
||||
info.RunOSCheck();
|
||||
this->ranOSCheck = true;
|
||||
}
|
||||
Json::Value infoRoot;
|
||||
infoRoot["familyId"] = info.GetFamilyID();
|
||||
infoRoot["hostname"] = info.GetHostname();
|
||||
@@ -408,7 +417,7 @@ std::string cmInstrumentation::InstrumentTest(
|
||||
this->InsertDynamicSystemInformation(root, "after");
|
||||
}
|
||||
|
||||
cmsys::SystemInformation info;
|
||||
cmsys::SystemInformation& info = this->GetSystemInformation();
|
||||
std::string file_name = cmStrCat(
|
||||
"test-",
|
||||
this->ComputeSuffixHash(cmStrCat(command_str, info.GetProcessId())),
|
||||
@@ -468,7 +477,7 @@ int cmInstrumentation::InstrumentCommand(
|
||||
// Exit early if configure didn't generate a query
|
||||
if (reloadQueriesAfterCommand) {
|
||||
this->LoadQueries();
|
||||
if (!this->hasQuery) {
|
||||
if (!this->HasQuery()) {
|
||||
return ret;
|
||||
}
|
||||
if (this->HasQuery(
|
||||
@@ -530,7 +539,7 @@ int cmInstrumentation::InstrumentCommand(
|
||||
root["workingDir"] = cmSystemTools::GetLogicalWorkingDirectory();
|
||||
|
||||
// Write Json
|
||||
cmsys::SystemInformation info;
|
||||
cmsys::SystemInformation& info = this->GetSystemInformation();
|
||||
std::string const& file_name = cmStrCat(
|
||||
command_type, "-",
|
||||
this->ComputeSuffixHash(cmStrCat(command_str, info.GetProcessId())),
|
||||
|
||||
@@ -11,9 +11,13 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <cm/memory>
|
||||
#include <cm/optional>
|
||||
|
||||
#include <cm3p/json/value.h>
|
||||
#ifndef CMAKE_BOOTSTRAP
|
||||
# include <cmsys/SystemInformation.hxx>
|
||||
#endif
|
||||
#include <stdint.h>
|
||||
|
||||
#include "cmInstrumentationQuery.h"
|
||||
@@ -60,13 +64,13 @@ private:
|
||||
void WriteInstrumentationJson(Json::Value& index,
|
||||
std::string const& directory,
|
||||
std::string const& file_name);
|
||||
static void InsertStaticSystemInformation(Json::Value& index);
|
||||
static void GetDynamicSystemInformation(double& memory, double& load);
|
||||
static void InsertDynamicSystemInformation(Json::Value& index,
|
||||
std::string const& instant);
|
||||
static void InsertTimingData(
|
||||
Json::Value& root, std::chrono::steady_clock::time_point steadyStart,
|
||||
std::chrono::system_clock::time_point systemStart);
|
||||
void InsertStaticSystemInformation(Json::Value& index);
|
||||
void GetDynamicSystemInformation(double& memory, double& load);
|
||||
void InsertDynamicSystemInformation(Json::Value& index,
|
||||
std::string const& instant);
|
||||
void InsertTimingData(Json::Value& root,
|
||||
std::chrono::steady_clock::time_point steadyStart,
|
||||
std::chrono::system_clock::time_point systemStart);
|
||||
bool HasQueryFile(std::string const& file);
|
||||
static std::string GetCommandStr(std::vector<std::string> const& args);
|
||||
static std::string ComputeSuffixHash(std::string const& command_str);
|
||||
@@ -84,4 +88,10 @@ private:
|
||||
std::map<std::string, std::string> cdashSnippetsMap;
|
||||
Json::Value preTestStats;
|
||||
bool hasQuery = false;
|
||||
bool ranSystemChecks = false;
|
||||
bool ranOSCheck = false;
|
||||
#ifndef CMAKE_BOOTSTRAP
|
||||
std::unique_ptr<cmsys::SystemInformation> systemInformation;
|
||||
cmsys::SystemInformation& GetSystemInformation();
|
||||
#endif
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user