diff options
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/telemetry.cpp | 65 | ||||
| -rw-r--r-- | src/common/telemetry.h | 12 |
2 files changed, 77 insertions, 0 deletions
diff --git a/src/common/telemetry.cpp b/src/common/telemetry.cpp index bf1f54886..f53a8d193 100644 --- a/src/common/telemetry.cpp +++ b/src/common/telemetry.cpp | |||
| @@ -3,8 +3,15 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <algorithm> | 5 | #include <algorithm> |
| 6 | #include <cstring> | ||
| 7 | #include "common/assert.h" | ||
| 8 | #include "common/scm_rev.h" | ||
| 6 | #include "common/telemetry.h" | 9 | #include "common/telemetry.h" |
| 7 | 10 | ||
| 11 | #ifdef ARCHITECTURE_x86_64 | ||
| 12 | #include "common/x64/cpu_detect.h" | ||
| 13 | #endif | ||
| 14 | |||
| 8 | namespace Telemetry { | 15 | namespace Telemetry { |
| 9 | 16 | ||
| 10 | void FieldCollection::Accept(VisitorInterface& visitor) const { | 17 | void FieldCollection::Accept(VisitorInterface& visitor) const { |
| @@ -37,4 +44,62 @@ template class Field<std::string>; | |||
| 37 | template class Field<const char*>; | 44 | template class Field<const char*>; |
| 38 | template class Field<std::chrono::microseconds>; | 45 | template class Field<std::chrono::microseconds>; |
| 39 | 46 | ||
| 47 | #ifdef ARCHITECTURE_x86_64 | ||
| 48 | static const char* CpuVendorToStr(Common::CPUVendor vendor) { | ||
| 49 | switch (vendor) { | ||
| 50 | case Common::CPUVendor::INTEL: | ||
| 51 | return "Intel"; | ||
| 52 | case Common::CPUVendor::AMD: | ||
| 53 | return "Amd"; | ||
| 54 | case Common::CPUVendor::OTHER: | ||
| 55 | return "Other"; | ||
| 56 | } | ||
| 57 | UNREACHABLE(); | ||
| 58 | } | ||
| 59 | #endif | ||
| 60 | |||
| 61 | void AppendBuildInfo(FieldCollection& fc) { | ||
| 62 | const bool is_git_dirty{std::strstr(Common::g_scm_desc, "dirty") != nullptr}; | ||
| 63 | fc.AddField(FieldType::App, "Git_IsDirty", is_git_dirty); | ||
| 64 | fc.AddField(FieldType::App, "Git_Branch", Common::g_scm_branch); | ||
| 65 | fc.AddField(FieldType::App, "Git_Revision", Common::g_scm_rev); | ||
| 66 | fc.AddField(FieldType::App, "BuildDate", Common::g_build_date); | ||
| 67 | fc.AddField(FieldType::App, "BuildName", Common::g_build_name); | ||
| 68 | } | ||
| 69 | |||
| 70 | void AppendCPUInfo(FieldCollection& fc) { | ||
| 71 | #ifdef ARCHITECTURE_x86_64 | ||
| 72 | fc.AddField(FieldType::UserSystem, "CPU_Model", Common::GetCPUCaps().cpu_string); | ||
| 73 | fc.AddField(FieldType::UserSystem, "CPU_BrandString", Common::GetCPUCaps().brand_string); | ||
| 74 | fc.AddField(FieldType::UserSystem, "CPU_Vendor", CpuVendorToStr(Common::GetCPUCaps().vendor)); | ||
| 75 | fc.AddField(FieldType::UserSystem, "CPU_Extension_x64_AES", Common::GetCPUCaps().aes); | ||
| 76 | fc.AddField(FieldType::UserSystem, "CPU_Extension_x64_AVX", Common::GetCPUCaps().avx); | ||
| 77 | fc.AddField(FieldType::UserSystem, "CPU_Extension_x64_AVX2", Common::GetCPUCaps().avx2); | ||
| 78 | fc.AddField(FieldType::UserSystem, "CPU_Extension_x64_BMI1", Common::GetCPUCaps().bmi1); | ||
| 79 | fc.AddField(FieldType::UserSystem, "CPU_Extension_x64_BMI2", Common::GetCPUCaps().bmi2); | ||
| 80 | fc.AddField(FieldType::UserSystem, "CPU_Extension_x64_FMA", Common::GetCPUCaps().fma); | ||
| 81 | fc.AddField(FieldType::UserSystem, "CPU_Extension_x64_FMA4", Common::GetCPUCaps().fma4); | ||
| 82 | fc.AddField(FieldType::UserSystem, "CPU_Extension_x64_SSE", Common::GetCPUCaps().sse); | ||
| 83 | fc.AddField(FieldType::UserSystem, "CPU_Extension_x64_SSE2", Common::GetCPUCaps().sse2); | ||
| 84 | fc.AddField(FieldType::UserSystem, "CPU_Extension_x64_SSE3", Common::GetCPUCaps().sse3); | ||
| 85 | fc.AddField(FieldType::UserSystem, "CPU_Extension_x64_SSSE3", Common::GetCPUCaps().ssse3); | ||
| 86 | fc.AddField(FieldType::UserSystem, "CPU_Extension_x64_SSE41", Common::GetCPUCaps().sse4_1); | ||
| 87 | fc.AddField(FieldType::UserSystem, "CPU_Extension_x64_SSE42", Common::GetCPUCaps().sse4_2); | ||
| 88 | #else | ||
| 89 | fc.AddField(FieldType::UserSystem, "CPU_Model", "Other"); | ||
| 90 | #endif | ||
| 91 | } | ||
| 92 | |||
| 93 | void AppendOSInfo(FieldCollection& fc) { | ||
| 94 | #ifdef __APPLE__ | ||
| 95 | fc.AddField(FieldType::UserSystem, "OsPlatform", "Apple"); | ||
| 96 | #elif defined(_WIN32) | ||
| 97 | fc.AddField(FieldType::UserSystem, "OsPlatform", "Windows"); | ||
| 98 | #elif defined(__linux__) || defined(linux) || defined(__linux) | ||
| 99 | fc.AddField(FieldType::UserSystem, "OsPlatform", "Linux"); | ||
| 100 | #else | ||
| 101 | fc.AddField(FieldType::UserSystem, "OsPlatform", "Unknown"); | ||
| 102 | #endif | ||
| 103 | } | ||
| 104 | |||
| 40 | } // namespace Telemetry | 105 | } // namespace Telemetry |
diff --git a/src/common/telemetry.h b/src/common/telemetry.h index 3bab75b59..8d6ab986b 100644 --- a/src/common/telemetry.h +++ b/src/common/telemetry.h | |||
| @@ -180,4 +180,16 @@ struct NullVisitor : public VisitorInterface { | |||
| 180 | void Complete() override {} | 180 | void Complete() override {} |
| 181 | }; | 181 | }; |
| 182 | 182 | ||
| 183 | /// Appends build-specific information to the given FieldCollection, | ||
| 184 | /// such as branch name, revision hash, etc. | ||
| 185 | void AppendBuildInfo(FieldCollection& fc); | ||
| 186 | |||
| 187 | /// Appends CPU-specific information to the given FieldCollection, | ||
| 188 | /// such as instruction set extensions, etc. | ||
| 189 | void AppendCPUInfo(FieldCollection& fc); | ||
| 190 | |||
| 191 | /// Appends OS-specific information to the given FieldCollection, | ||
| 192 | /// such as platform name, etc. | ||
| 193 | void AppendOSInfo(FieldCollection& fc); | ||
| 194 | |||
| 183 | } // namespace Telemetry | 195 | } // namespace Telemetry |