diff options
| author | Alexander Karatarakis <alkarata@microsoft.com> | 2017-04-27 18:08:52 -0700 |
|---|---|---|
| committer | Alexander Karatarakis <alkarata@microsoft.com> | 2017-04-27 18:59:57 -0700 |
| commit | 1e9471a1489156720362ef12e1ec6849ea9b45b6 (patch) | |
| tree | 46f0f35093ecd18034c9f9463d6f8b7aa590ade0 /toolsrc/src/metrics.cpp | |
| parent | 75e8752cb90eb8bc7717518d9d6a5c68f27f2b0f (diff) | |
| download | vcpkg-1e9471a1489156720362ef12e1ec6849ea9b45b6.tar.gz vcpkg-1e9471a1489156720362ef12e1ec6849ea9b45b6.zip | |
Run clang-format over the cpp files
Diffstat (limited to 'toolsrc/src/metrics.cpp')
| -rw-r--r-- | toolsrc/src/metrics.cpp | 134 |
1 files changed, 54 insertions, 80 deletions
diff --git a/toolsrc/src/metrics.cpp b/toolsrc/src/metrics.cpp index baefc3c35..67b06d3f1 100644 --- a/toolsrc/src/metrics.cpp +++ b/toolsrc/src/metrics.cpp @@ -1,9 +1,10 @@ #include "pch.h" -#include "metrics.h" + #include "filesystem_fs.h" +#include "metrics.h" +#include "vcpkg_Files.h" #include "vcpkg_Strings.h" #include "vcpkg_System.h" -#include "vcpkg_Files.h" namespace vcpkg::Metrics { @@ -47,7 +48,7 @@ namespace vcpkg::Metrics // Generating UUID format version 4 // http://en.wikipedia.org/wiki/Universally_unique_identifier - for (int i = 0; i < partSizes[part]; i++ , index++) + for (int i = 0; i < partSizes[part]; i++, index++) { if (part == 2 && i == 0) { @@ -98,9 +99,8 @@ namespace vcpkg::Metrics else if (ch < 0x20 || ch >= 0x80) { // Note: this treats incoming Strings as Latin-1 - static constexpr const char hex[16] = { - '0', '1', '2', '3', '4', '5', '6', '7', - '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; + static constexpr const char hex[16] = { '0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; encoded.append("\\u00"); encoded.push_back(hex[ch / 16]); encoded.push_back(hex[ch % 16]); @@ -123,21 +123,18 @@ namespace vcpkg::Metrics path += L"\\kernel32.dll"; auto versz = GetFileVersionInfoSizeW(path.c_str(), nullptr); - if (versz == 0) - return ""; + if (versz == 0) return ""; std::vector<char> verbuf; verbuf.resize(versz); - if (!GetFileVersionInfoW(path.c_str(), 0, static_cast<DWORD>(verbuf.size()), &verbuf[0])) - return ""; + if (!GetFileVersionInfoW(path.c_str(), 0, static_cast<DWORD>(verbuf.size()), &verbuf[0])) return ""; void* rootblock; UINT rootblocksize; - if (!VerQueryValueW(&verbuf[0], L"\\", &rootblock, &rootblocksize)) - return ""; + if (!VerQueryValueW(&verbuf[0], L"\\", &rootblock, &rootblocksize)) return ""; - auto rootblock_ffi = static_cast<VS_FIXEDFILEINFO *>(rootblock); + auto rootblock_ffi = static_cast<VS_FIXEDFILEINFO*>(rootblock); return Strings::format("%d.%d.%d", static_cast<int>(HIWORD(rootblock_ffi->dwProductVersionMS)), @@ -155,8 +152,7 @@ namespace vcpkg::Metrics void TrackProperty(const std::string& name, const std::string& value) { - if (properties.size() != 0) - properties.push_back(','); + if (properties.size() != 0) properties.push_back(','); properties.append(to_json_string(name)); properties.push_back(':'); properties.append(to_json_string(value)); @@ -164,8 +160,7 @@ namespace vcpkg::Metrics void TrackMetric(const std::string& name, double value) { - if (measurements.size() != 0) - measurements.push_back(','); + if (measurements.size() != 0) measurements.push_back(','); measurements.append(to_json_string(name)); measurements.push_back(':'); measurements.append(std::to_string(value)); @@ -212,21 +207,19 @@ namespace vcpkg::Metrics static MetricMessage g_metricmessage; static bool g_should_send_metrics = #if defined(NDEBUG) && (DISABLE_METRICS == 0) -true + true #else - false + false #endif - ; + ; static bool g_should_print_metrics = false; - bool get_compiled_metrics_enabled() - { - return DISABLE_METRICS == 0; - } + bool get_compiled_metrics_enabled() { return DISABLE_METRICS == 0; } std::wstring get_SQM_user() { - auto hkcu_sqmclient = System::get_registry_string(HKEY_CURRENT_USER, LR"(Software\Microsoft\SQMClient)", L"UserId"); + auto hkcu_sqmclient = + System::get_registry_string(HKEY_CURRENT_USER, LR"(Software\Microsoft\SQMClient)", L"UserId"); return hkcu_sqmclient.value_or(L"{}"); } @@ -242,20 +235,11 @@ true first_use_time = get_current_date_time(); } - void set_send_metrics(bool should_send_metrics) - { - g_should_send_metrics = should_send_metrics; - } + void set_send_metrics(bool should_send_metrics) { g_should_send_metrics = should_send_metrics; } - void set_print_metrics(bool should_print_metrics) - { - g_should_print_metrics = should_print_metrics; - } + void set_print_metrics(bool should_print_metrics) { g_should_print_metrics = should_print_metrics; } - void track_metric(const std::string& name, double value) - { - g_metricmessage.TrackMetric(name, value); - } + void track_metric(const std::string& name, double value) { g_metricmessage.TrackMetric(name, value); } void track_property(const std::string& name, const std::wstring& value) { @@ -263,12 +247,7 @@ true std::string converted_value; converted_value.resize(value.size()); std::transform( - value.begin(), value.end(), - converted_value.begin(), - [](wchar_t ch) - { - return static_cast<char>(ch); - }); + value.begin(), value.end(), converted_value.begin(), [](wchar_t ch) { return static_cast<char>(ch); }); g_metricmessage.TrackProperty(name, converted_value); } @@ -283,11 +262,8 @@ true HINTERNET hSession = nullptr, hConnect = nullptr, hRequest = nullptr; BOOL bResults = FALSE; - hSession = WinHttpOpen(L"vcpkg/1.0", - WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, - WINHTTP_NO_PROXY_NAME, - WINHTTP_NO_PROXY_BYPASS, - 0); + hSession = WinHttpOpen( + L"vcpkg/1.0", WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0); if (hSession) hConnect = WinHttpConnect(hSession, L"dc.services.visualstudio.com", INTERNET_DEFAULT_HTTPS_PORT, 0); @@ -302,12 +278,14 @@ true if (hRequest) { - if (MAXDWORD <= payload.size()) - abort(); + if (MAXDWORD <= payload.size()) abort(); std::wstring hdrs = L"Content-Type: application/json\r\n"; bResults = WinHttpSendRequest(hRequest, - hdrs.c_str(), static_cast<DWORD>(hdrs.size()), - (void*)&payload[0], static_cast<DWORD>(payload.size()), static_cast<DWORD>(payload.size()), + hdrs.c_str(), + static_cast<DWORD>(hdrs.size()), + (void*)&payload[0], + static_cast<DWORD>(payload.size()), + static_cast<DWORD>(payload.size()), 0); } @@ -320,7 +298,12 @@ true if (bResults) { - bResults = WinHttpQueryHeaders(hRequest, WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER, nullptr, &http_code, &junk, WINHTTP_NO_HEADER_INDEX); + bResults = WinHttpQueryHeaders(hRequest, + WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER, + nullptr, + &http_code, + &junk, + WINHTTP_NO_HEADER_INDEX); } std::vector<char> responseBuffer; @@ -353,30 +336,24 @@ true #endif } - if (hRequest) - WinHttpCloseHandle(hRequest); - if (hConnect) - WinHttpCloseHandle(hConnect); - if (hSession) - WinHttpCloseHandle(hSession); + if (hRequest) WinHttpCloseHandle(hRequest); + if (hConnect) WinHttpCloseHandle(hConnect); + if (hSession) WinHttpCloseHandle(hSession); } static fs::path get_bindir() { - wchar_t buf[_MAX_PATH ]; + wchar_t buf[_MAX_PATH]; int bytes = GetModuleFileNameW(nullptr, buf, _MAX_PATH); - if (bytes == 0) - std::abort(); + if (bytes == 0) std::abort(); return fs::path(buf, buf + bytes); } void flush() { std::string payload = g_metricmessage.format_event_data_template(); - if (g_should_print_metrics) - std::cerr << payload << "\n"; - if (!g_should_send_metrics) - return; + if (g_should_print_metrics) std::cerr << payload << "\n"; + if (!g_should_send_metrics) return; // upload(payload); @@ -390,30 +367,27 @@ true if (true) { - const fs::path exe_path = [&fs]() -> fs::path - { - auto vcpkgdir = get_bindir().parent_path(); - auto path = vcpkgdir / "vcpkgmetricsuploader.exe"; - if (fs.exists(path)) - return path; + const fs::path exe_path = [&fs]() -> fs::path { + auto vcpkgdir = get_bindir().parent_path(); + auto path = vcpkgdir / "vcpkgmetricsuploader.exe"; + if (fs.exists(path)) return path; - path = vcpkgdir / "scripts" / "vcpkgmetricsuploader.exe"; - if (fs.exists(path)) - return path; + path = vcpkgdir / "scripts" / "vcpkgmetricsuploader.exe"; + if (fs.exists(path)) return path; - return L""; - }(); + return L""; + }(); std::error_code ec; fs.copy_file(exe_path, temp_folder_path_exe, fs::copy_options::skip_existing, ec); - if (ec) - return; + if (ec) return; } const fs::path vcpkg_metrics_txt_path = temp_folder_path / ("vcpkg" + generate_random_UUID() + ".txt"); fs.write_contents(vcpkg_metrics_txt_path, payload); - const std::wstring cmdLine = Strings::wformat(L"start %s %s", temp_folder_path_exe.native(), vcpkg_metrics_txt_path.native()); + const std::wstring cmdLine = + Strings::wformat(L"start %s %s", temp_folder_path_exe.native(), vcpkg_metrics_txt_path.native()); System::cmd_execute_clean(cmdLine); } } |
