diff options
| author | Robert Schumacher <roschuma@microsoft.com> | 2017-10-03 15:52:29 -0700 |
|---|---|---|
| committer | Robert Schumacher <roschuma@microsoft.com> | 2017-10-03 15:52:29 -0700 |
| commit | d5705e87c42784607bf462159bebe14044a88eca (patch) | |
| tree | aded4a5806480ad3e6980b8c5f4dacd61a004614 /toolsrc/src/metrics.cpp | |
| parent | c167c70c272a417779e601fffcbdb72278da1848 (diff) | |
| parent | 3838d5880470fdc884f035ed3d1c67d3bdd1e16e (diff) | |
| download | vcpkg-d5705e87c42784607bf462159bebe14044a88eca.tar.gz vcpkg-d5705e87c42784607bf462159bebe14044a88eca.zip | |
Merge branch 'master' into martin-s-patch-vs2013
Diffstat (limited to 'toolsrc/src/metrics.cpp')
| -rw-r--r-- | toolsrc/src/metrics.cpp | 130 |
1 files changed, 65 insertions, 65 deletions
diff --git a/toolsrc/src/metrics.cpp b/toolsrc/src/metrics.cpp index 8a7d02a30..8a0050bfc 100644 --- a/toolsrc/src/metrics.cpp +++ b/toolsrc/src/metrics.cpp @@ -20,9 +20,9 @@ namespace vcpkg::Metrics _ftime_s(&timebuffer); time_t now = timebuffer.time; - int milli = timebuffer.millitm; + const int milli = timebuffer.millitm; - errno_t err = gmtime_s(&newtime, &now); + const errno_t err = gmtime_s(&newtime, &now); if (err) { return Strings::EMPTY; @@ -34,7 +34,7 @@ namespace vcpkg::Metrics static std::string generate_random_UUID() { - int partSizes[] = {8, 4, 4, 4, 12}; + int part_sizes[] = {8, 4, 4, 4, 12}; char uuid[37]; memset(uuid, 0, sizeof(uuid)); int num; @@ -50,7 +50,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 < part_sizes[part]; i++, index++) { if (part == 2 && i == 0) { @@ -81,8 +81,8 @@ namespace vcpkg::Metrics static const std::string& get_session_id() { - static const std::string id = generate_random_UUID(); - return id; + static const std::string ID = generate_random_UUID(); + return ID; } static std::string to_json_string(const std::string& str) @@ -101,11 +101,11 @@ namespace vcpkg::Metrics else if (ch < 0x20 || ch >= 0x80) { // Note: this treats incoming Strings as Latin-1 - static constexpr const char hex[16] = { + 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]); + encoded.push_back(HEX[ch / 16]); + encoded.push_back(HEX[ch % 16]); } else { @@ -120,11 +120,11 @@ namespace vcpkg::Metrics { std::wstring path; path.resize(MAX_PATH); - auto n = GetSystemDirectoryW(&path[0], static_cast<UINT>(path.size())); + const auto n = GetSystemDirectoryW(&path[0], static_cast<UINT>(path.size())); path.resize(n); path += L"\\kernel32.dll"; - auto versz = GetFileVersionInfoSizeW(path.c_str(), nullptr); + const auto versz = GetFileVersionInfoSizeW(path.c_str(), nullptr); if (versz == 0) return Strings::EMPTY; std::vector<char> verbuf; @@ -152,7 +152,7 @@ namespace vcpkg::Metrics std::string properties; std::string measurements; - void TrackProperty(const std::string& name, const std::string& value) + void track_property(const std::string& name, const std::string& value) { if (properties.size() != 0) properties.push_back(','); properties.append(to_json_string(name)); @@ -160,7 +160,7 @@ namespace vcpkg::Metrics properties.append(to_json_string(value)); } - void TrackMetric(const std::string& name, double value) + void track_metric(const std::string& name, double value) { if (measurements.size() != 0) measurements.push_back(','); measurements.append(to_json_string(name)); @@ -241,7 +241,7 @@ namespace vcpkg::Metrics void Metrics::set_print_metrics(bool should_print_metrics) { g_should_print_metrics = should_print_metrics; } - void Metrics::track_metric(const std::string& name, double value) { g_metricmessage.TrackMetric(name, value); } + void Metrics::track_metric(const std::string& name, double value) { g_metricmessage.track_metric(name, value); } void Metrics::track_property(const std::string& name, const std::wstring& value) { @@ -251,85 +251,85 @@ namespace vcpkg::Metrics std::transform( value.begin(), value.end(), converted_value.begin(), [](wchar_t ch) { return static_cast<char>(ch); }); - g_metricmessage.TrackProperty(name, converted_value); + g_metricmessage.track_property(name, converted_value); } void Metrics::track_property(const std::string& name, const std::string& value) { - g_metricmessage.TrackProperty(name, value); + g_metricmessage.track_property(name, value); } void Metrics::upload(const std::string& payload) { - HINTERNET hSession = nullptr, hConnect = nullptr, hRequest = nullptr; - BOOL bResults = FALSE; + HINTERNET connect = nullptr, request = nullptr; + BOOL results = FALSE; - hSession = WinHttpOpen( + const HINTERNET session = 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); - - if (hConnect) - hRequest = WinHttpOpenRequest(hConnect, - L"POST", - L"/v2/track", - nullptr, - WINHTTP_NO_REFERER, - WINHTTP_DEFAULT_ACCEPT_TYPES, - WINHTTP_FLAG_SECURE); - - if (hRequest) + if (session) connect = WinHttpConnect(session, L"dc.services.visualstudio.com", INTERNET_DEFAULT_HTTPS_PORT, 0); + + if (connect) + request = WinHttpOpenRequest(connect, + L"POST", + L"/v2/track", + nullptr, + WINHTTP_NO_REFERER, + WINHTTP_DEFAULT_ACCEPT_TYPES, + WINHTTP_FLAG_SECURE); + + if (request) { 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()), - 0); + std::string& p = const_cast<std::string&>(payload); + results = WinHttpSendRequest(request, + hdrs.c_str(), + static_cast<DWORD>(hdrs.size()), + static_cast<void*>(&p[0]), + static_cast<DWORD>(payload.size()), + static_cast<DWORD>(payload.size()), + 0); } - if (bResults) + if (results) { - bResults = WinHttpReceiveResponse(hRequest, nullptr); + results = WinHttpReceiveResponse(request, nullptr); } DWORD http_code = 0, junk = sizeof(DWORD); - if (bResults) + if (results) { - bResults = WinHttpQueryHeaders(hRequest, - WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER, - nullptr, - &http_code, - &junk, - WINHTTP_NO_HEADER_INDEX); + results = WinHttpQueryHeaders(request, + WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER, + nullptr, + &http_code, + &junk, + WINHTTP_NO_HEADER_INDEX); } - std::vector<char> responseBuffer; - if (bResults) + std::vector<char> response_buffer; + if (results) { - DWORD availableData = 0, readData = 0, totalData = 0; - while ((bResults = WinHttpQueryDataAvailable(hRequest, &availableData)) == TRUE && availableData > 0) + DWORD available_data = 0, read_data = 0, total_data = 0; + while ((results = WinHttpQueryDataAvailable(request, &available_data)) == TRUE && available_data > 0) { - responseBuffer.resize(responseBuffer.size() + availableData); + response_buffer.resize(response_buffer.size() + available_data); - bResults = WinHttpReadData(hRequest, &responseBuffer.data()[totalData], availableData, &readData); + results = WinHttpReadData(request, &response_buffer.data()[total_data], available_data, &read_data); - if (!bResults) + if (!results) { break; } - totalData += readData; + total_data += read_data; - responseBuffer.resize(totalData); + response_buffer.resize(total_data); } } - if (!bResults) + if (!results) { #ifndef NDEBUG __debugbreak(); @@ -338,22 +338,22 @@ namespace vcpkg::Metrics #endif } - if (hRequest) WinHttpCloseHandle(hRequest); - if (hConnect) WinHttpCloseHandle(hConnect); - if (hSession) WinHttpCloseHandle(hSession); + if (request) WinHttpCloseHandle(request); + if (connect) WinHttpCloseHandle(connect); + if (session) WinHttpCloseHandle(session); } static fs::path get_bindir() { wchar_t buf[_MAX_PATH]; - int bytes = GetModuleFileNameW(nullptr, buf, _MAX_PATH); + const int bytes = GetModuleFileNameW(nullptr, buf, _MAX_PATH); if (bytes == 0) std::abort(); return fs::path(buf, buf + bytes); } void Metrics::flush() { - std::string payload = g_metricmessage.format_event_data_template(); + const std::string payload = g_metricmessage.format_event_data_template(); if (g_should_print_metrics) std::cerr << payload << "\n"; if (!g_should_send_metrics) return; @@ -388,8 +388,8 @@ namespace vcpkg::Metrics 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 = + const std::wstring cmd_line = Strings::wformat(L"start %s %s", temp_folder_path_exe.native(), vcpkg_metrics_txt_path.native()); - System::cmd_execute_clean(cmdLine); + System::cmd_execute_clean(cmd_line); } } |
