From 37bf289e0673800c758e2838c8dc0b1f50e46a20 Mon Sep 17 00:00:00 2001 From: Victor Romero Date: Tue, 2 Aug 2022 11:51:19 -0700 Subject: [PATCH 01/14] initialize timestamp in metrics message --- src/vcpkg/metrics.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/vcpkg/metrics.cpp b/src/vcpkg/metrics.cpp index ce5d72f750..0de1962dd0 100644 --- a/src/vcpkg/metrics.cpp +++ b/src/vcpkg/metrics.cpp @@ -74,7 +74,6 @@ namespace vcpkg { std::string user_id; std::string user_timestamp; - std::string timestamp; Json::Object properties; Json::Object measurements; @@ -126,7 +125,7 @@ namespace vcpkg obj.insert("ver", Json::Value::integer(1)); obj.insert("name", Json::Value::string("Microsoft.ApplicationInsights.Event")); - obj.insert("time", Json::Value::string(timestamp)); + obj.insert("time", Json::Value::string(get_current_date_time_string())); obj.insert("sampleRate", Json::Value::number(100.0)); obj.insert("seq", Json::Value::string("0:0")); obj.insert("iKey", Json::Value::string("b4e88960-4393-4dd9-ab8e-97e8fe6d7603")); From 2f7e0b2f71d174dc3bed3bed8c50846b2cc96f94 Mon Sep 17 00:00:00 2001 From: Victor Romero Date: Wed, 31 Aug 2022 14:45:46 -0700 Subject: [PATCH 02/14] refactor track_property() --- include/vcpkg/metrics.h | 59 ++++++++++++++++++++++++- src/vcpkg.cpp | 11 ++--- src/vcpkg/binarycaching.cpp | 29 +++++++++--- src/vcpkg/build.cpp | 4 +- src/vcpkg/commands.add.cpp | 8 ++-- src/vcpkg/commands.find.cpp | 8 ++-- src/vcpkg/commands.integrate.cpp | 4 +- src/vcpkg/commands.setinstalled.cpp | 2 +- src/vcpkg/input.cpp | 3 +- src/vcpkg/install.cpp | 13 +++--- src/vcpkg/metrics.cpp | 68 +++++++++++++++++++++++++++-- src/vcpkg/portfileprovider.cpp | 2 +- src/vcpkg/registries.cpp | 15 ++++--- src/vcpkg/sourceparagraph.cpp | 10 ++--- src/vcpkg/vcpkgcmdarguments.cpp | 19 ++++---- src/vcpkg/vcpkglib.cpp | 2 +- src/vcpkg/vcpkgpaths.cpp | 14 +++--- 17 files changed, 205 insertions(+), 66 deletions(-) diff --git a/include/vcpkg/metrics.h b/include/vcpkg/metrics.h index 4e67fe7809..c62980463f 100644 --- a/include/vcpkg/metrics.h +++ b/include/vcpkg/metrics.h @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -10,6 +11,57 @@ namespace vcpkg { struct Metrics { + enum class SetMetric + { + AssetSource, + BinaryCachingAws, + BinaryCachingAzBlob, + BinaryCachingCos, + BinaryCachingDefault, + BinaryCachingFiles, + BinaryCachingGcs, + BinaryCachingHttp, + BinaryCachingNuget, + BinaryCachingSource, + ErrorVersioningDisabled, + ErrorVersioningNoBaseline, + GitHubRepository, + ManifestBaseline, + ManifestOverrides, + ManifestVersionConstraint, + RegistriesErrorCouldNotFindBaseline, + RegistriesErrorNoVersionsAtCommit, + VcpkgBinarySources, + VcpkgDefaultBinaryCache, + VcpkgNugetRepository, + VersioningErrorBaseline, + VersioningErrorVersion, + X_VcpkgRegistriesCache, + X_WriteNugetPackagesConfig + }; + + enum class StringMetric + { + BuildError, + CommandArgs, + CommandContext, + CommandName, + Error, + InstallPlan_1, + ListFile, + RegistriesDefaultRegistryKind, + RegistriesKindsUsed, + Title, + UserMac, + VcpkgVersion, + Warning + }; + + enum class BoolMetric + { + InstallManifestMode + }; + Metrics() = default; Metrics(const Metrics&) = delete; Metrics& operator=(const Metrics&) = delete; @@ -22,8 +74,11 @@ namespace vcpkg void track_metric(const std::string& name, double value); void track_buildtime(const std::string& name, double value); - void track_property(const std::string& name, const std::string& value); - void track_property(const std::string& name, bool value); + + void track_property(SetMetric metric); + void track_property(StringMetric metric, const std::string& value); + void track_property(BoolMetric metric, bool value); + void track_feature(const std::string& feature, bool value); void track_option(const std::string& option, bool value); diff --git a/src/vcpkg.cpp b/src/vcpkg.cpp index 51573a67ae..2dbef5644a 100644 --- a/src/vcpkg.cpp +++ b/src/vcpkg.cpp @@ -44,7 +44,8 @@ static void invalid_command(const std::string& cmd) static void inner(vcpkg::Filesystem& fs, const VcpkgCmdArguments& args) { // track version on each invocation - LockGuardPtr(g_metrics)->track_property("vcpkg_version", Commands::Version::version.to_string()); + LockGuardPtr(g_metrics)->track_property(Metrics::StringMetric::VcpkgVersion, + Commands::Version::version.to_string()); if (args.command.empty()) { @@ -71,7 +72,7 @@ static void inner(vcpkg::Filesystem& fs, const VcpkgCmdArguments& args) if (const auto command_function = find_command(Commands::get_available_basic_commands())) { - LockGuardPtr(g_metrics)->track_property("command_name", command_function->name); + LockGuardPtr(g_metrics)->track_property(Metrics::StringMetric::CommandName, command_function->name); return command_function->function->perform_and_exit(args, fs); } @@ -82,7 +83,7 @@ static void inner(vcpkg::Filesystem& fs, const VcpkgCmdArguments& args) if (const auto command_function = find_command(Commands::get_available_paths_commands())) { - LockGuardPtr(g_metrics)->track_property("command_name", command_function->name); + LockGuardPtr(g_metrics)->track_property(Metrics::StringMetric::CommandName, command_function->name); return command_function->function->perform_and_exit(args, paths); } @@ -93,7 +94,7 @@ static void inner(vcpkg::Filesystem& fs, const VcpkgCmdArguments& args) if (const auto command_function = find_command(Commands::get_available_triplet_commands())) { - LockGuardPtr(g_metrics)->track_property("command_name", command_function->name); + LockGuardPtr(g_metrics)->track_property(Metrics::StringMetric::CommandName, command_function->name); return command_function->function->perform_and_exit(args, paths, default_triplet, host_triplet); } @@ -316,7 +317,7 @@ int main(const int argc, const char* const* const argv) exc_msg = "unknown error(...)"; } - LockGuardPtr(g_metrics)->track_property("error", exc_msg); + LockGuardPtr(g_metrics)->track_property(Metrics::StringMetric::Error, exc_msg); fflush(stdout); msg::println(msgVcpkgHasCrashed); diff --git a/src/vcpkg/binarycaching.cpp b/src/vcpkg/binarycaching.cpp index a7cffdd664..3810b56e05 100644 --- a/src/vcpkg/binarycaching.cpp +++ b/src/vcpkg/binarycaching.cpp @@ -1579,7 +1579,7 @@ namespace auto maybe_cachepath = get_environment_variable("VCPKG_DEFAULT_BINARY_CACHE"); if (auto p_str = maybe_cachepath.get()) { - LockGuardPtr(g_metrics)->track_property("VCPKG_DEFAULT_BINARY_CACHE", "defined"); + LockGuardPtr(g_metrics)->track_property(Metrics::SetMetric::VcpkgDefaultBinaryCache); Path path = *p_str; path.make_preferred(); if (!get_real_filesystem().is_directory(path)) @@ -1999,7 +1999,22 @@ namespace for (const auto& cache_provider : state->binary_cache_providers) { - LockGuardPtr(g_metrics)->track_property("binarycaching_" + cache_provider, "defined"); + static const std::map metric_names{ + {"aws", Metrics::SetMetric::BinaryCachingAws}, + {"azblob", Metrics::SetMetric::BinaryCachingAzBlob}, + {"cos", Metrics::SetMetric::BinaryCachingCos}, + {"default", Metrics::SetMetric::BinaryCachingDefault}, + {"files", Metrics::SetMetric::BinaryCachingFiles}, + {"gcs", Metrics::SetMetric::BinaryCachingGcs}, + {"http", Metrics::SetMetric::BinaryCachingHttp}, + {"nuget", Metrics::SetMetric::BinaryCachingNuget}, + }; + + auto it = metric_names.find(cache_provider); + if (it != metric_names.end()) + { + LockGuardPtr(g_metrics)->track_property(it->second); + } } } }; @@ -2132,7 +2147,7 @@ ExpectedS vcpkg::parse_download_configuration(const Optio { if (!arg || arg.get()->empty()) return DownloadManagerConfig{}; - LockGuardPtr(g_metrics)->track_property("asset-source", "defined"); + LockGuardPtr(g_metrics)->track_property(Metrics::SetMetric::AssetSource); AssetSourcesState s; AssetSourcesParser parser(*arg.get(), Strings::concat("$", VcpkgCmdArguments::ASSET_SOURCES_ENV), &s); @@ -2187,12 +2202,12 @@ ExpectedS vcpkg::create_binary_providers_from_configs_p LockGuardPtr metrics(g_metrics); if (!env_string.empty()) { - metrics->track_property("VCPKG_BINARY_SOURCES", "defined"); + metrics->track_property(Metrics::SetMetric::VcpkgBinarySources); } if (args.size() != 0) { - metrics->track_property("binarycaching-source", "defined"); + metrics->track_property(Metrics::SetMetric::BinaryCachingSource); } } @@ -2331,7 +2346,7 @@ details::NuGetRepoInfo details::get_nuget_repo_info_from_env() auto vcpkg_nuget_repository = get_environment_variable("VCPKG_NUGET_REPOSITORY"); if (auto p = vcpkg_nuget_repository.get()) { - LockGuardPtr(g_metrics)->track_property("VCPKG_NUGET_REPOSITORY", "defined"); + LockGuardPtr(g_metrics)->track_property(Metrics::SetMetric::VcpkgNugetRepository); return {std::move(*p)}; } @@ -2347,7 +2362,7 @@ details::NuGetRepoInfo details::get_nuget_repo_info_from_env() return {}; } - LockGuardPtr(g_metrics)->track_property("GITHUB_REPOSITORY", "defined"); + LockGuardPtr(g_metrics)->track_property(Metrics::SetMetric::GitHubRepository); return {Strings::concat(gh_server, '/', gh_repo, ".git"), get_environment_variable("GITHUB_REF").value_or(""), get_environment_variable("GITHUB_SHA").value_or("")}; diff --git a/src/vcpkg/build.cpp b/src/vcpkg/build.cpp index 9e0dff4161..afa066061c 100644 --- a/src/vcpkg/build.cpp +++ b/src/vcpkg/build.cpp @@ -947,8 +947,8 @@ namespace vcpkg buildtimeus); if (!succeeded(return_code)) { - metrics->track_property("error", "build failed"); - metrics->track_property("build_error", spec_string); + metrics->track_property(Metrics::StringMetric::Error, "build failed"); + metrics->track_property(Metrics::StringMetric::BuildError, spec_string); const auto logs = buildpath / Strings::concat("error-logs-", action.spec.triplet(), ".txt"); std::vector error_logs; if (fs.exists(logs, VCPKG_LINE_INFO)) diff --git a/src/vcpkg/commands.add.cpp b/src/vcpkg/commands.add.cpp index cf6411e42d..4d150435cc 100644 --- a/src/vcpkg/commands.add.cpp +++ b/src/vcpkg/commands.add.cpp @@ -46,8 +46,8 @@ namespace vcpkg::Commands auto artifact_hash = Hash::get_string_hash(artifact_name, Hash::Algorithm::Sha256); { auto metrics = LockGuardPtr(g_metrics); - metrics->track_property("command_context", "artifact"); - metrics->track_property("command_args", artifact_hash); + metrics->track_property(Metrics::StringMetric::CommandContext, "artifact"); + metrics->track_property(Metrics::StringMetric::CommandArgs, artifact_hash); } // unlock g_metrics std::string ce_args[] = {"add", artifact_name}; @@ -122,8 +122,8 @@ namespace vcpkg::Commands })); { auto metrics = LockGuardPtr(g_metrics); - metrics->track_property("command_context", "port"); - metrics->track_property("command_args", command_args_hash); + metrics->track_property(Metrics::StringMetric::CommandContext, "port"); + metrics->track_property(Metrics::StringMetric::CommandArgs, command_args_hash); } // unlock metrics Checks::exit_success(VCPKG_LINE_INFO); diff --git a/src/vcpkg/commands.find.cpp b/src/vcpkg/commands.find.cpp index 0a381a176b..6fe915375b 100644 --- a/src/vcpkg/commands.find.cpp +++ b/src/vcpkg/commands.find.cpp @@ -229,10 +229,10 @@ namespace vcpkg::Commands auto args_hash = Hash::get_string_hash(filter.value_or_exit(VCPKG_LINE_INFO), Hash::Algorithm::Sha256); { auto metrics = LockGuardPtr(g_metrics); - metrics->track_property("command_context", "artifact"); + metrics->track_property(Metrics::StringMetric::CommandContext, "artifact"); if (auto p_filter_hash = filter_hash.get()) { - metrics->track_property("command_args", *p_filter_hash); + metrics->track_property(Metrics::StringMetric::CommandArgs, *p_filter_hash); } } // unlock metrics @@ -244,10 +244,10 @@ namespace vcpkg::Commands Optional filter_hash = filter.map(Hash::get_string_sha256); { auto metrics = LockGuardPtr(g_metrics); - metrics->track_property("command_context", "port"); + metrics->track_property(Metrics::StringMetric::CommandContext, "port"); if (auto p_filter_hash = filter_hash.get()) { - metrics->track_property("command_args", *p_filter_hash); + metrics->track_property(Metrics::StringMetric::CommandArgs, *p_filter_hash); } } // unlock metrics diff --git a/src/vcpkg/commands.integrate.cpp b/src/vcpkg/commands.integrate.cpp index bb27d4e75c..e666258d69 100644 --- a/src/vcpkg/commands.integrate.cpp +++ b/src/vcpkg/commands.integrate.cpp @@ -472,8 +472,8 @@ namespace vcpkg::Commands::Integrate .append_raw("\n" + script_path.generic_u8string())); { auto locked_metrics = LockGuardPtr(g_metrics); - locked_metrics->track_property("error", "powershell script failed"); - locked_metrics->track_property("title", TITLE.to_string()); + locked_metrics->track_property(Metrics::StringMetric::Error, "powershell script failed"); + locked_metrics->track_property(Metrics::StringMetric::Title, TITLE.to_string()); } } diff --git a/src/vcpkg/commands.setinstalled.cpp b/src/vcpkg/commands.setinstalled.cpp index ea9ad58529..2d3960cf97 100644 --- a/src/vcpkg/commands.setinstalled.cpp +++ b/src/vcpkg/commands.setinstalled.cpp @@ -165,7 +165,7 @@ namespace vcpkg::Commands::SetInstalled auto it_pkgsconfig = options.settings.find(OPTION_WRITE_PACKAGES_CONFIG); if (it_pkgsconfig != options.settings.end()) { - LockGuardPtr(g_metrics)->track_property("x-write-nuget-packages-config", "defined"); + LockGuardPtr(g_metrics)->track_property(Metrics::SetMetric::X_WriteNugetPackagesConfig); pkgsconfig = it_pkgsconfig->second; } diff --git a/src/vcpkg/input.cpp b/src/vcpkg/input.cpp index 91b8fb1bb0..c44aa3a5f6 100644 --- a/src/vcpkg/input.cpp +++ b/src/vcpkg/input.cpp @@ -35,7 +35,8 @@ namespace vcpkg if (!paths.is_valid_triplet(t)) { print2(Color::error, "Error: invalid triplet: ", t, '\n'); - LockGuardPtr(g_metrics)->track_property("error", "invalid triplet: " + t.to_string()); + LockGuardPtr(g_metrics)->track_property(Metrics::StringMetric::Error, + "invalid triplet: " + t.to_string()); Help::help_topic_valid_triplet(paths); Checks::exit_fail(VCPKG_LINE_INFO); } diff --git a/src/vcpkg/install.cpp b/src/vcpkg/install.cpp index baa50ee3ac..8672a45b22 100644 --- a/src/vcpkg/install.cpp +++ b/src/vcpkg/install.cpp @@ -861,7 +861,8 @@ namespace vcpkg ? UnsupportedPortAction::Warn : UnsupportedPortAction::Error; - LockGuardPtr(g_metrics)->track_property("install_manifest_mode", paths.manifest_mode_enabled()); + LockGuardPtr(g_metrics)->track_property(Metrics::BoolMetric::InstallManifestMode, + paths.manifest_mode_enabled()); if (auto p = paths.get_manifest().get()) { @@ -950,7 +951,7 @@ namespace vcpkg auto it_pkgsconfig = options.settings.find(OPTION_WRITE_PACKAGES_CONFIG); if (it_pkgsconfig != options.settings.end()) { - LockGuardPtr(g_metrics)->track_property("x-write-nuget-packages-config", "defined"); + LockGuardPtr(g_metrics)->track_property(Metrics::SetMetric::X_WriteNugetPackagesConfig); pkgsconfig = Path(it_pkgsconfig->second); } auto maybe_manifest_scf = @@ -1018,12 +1019,12 @@ namespace vcpkg return dep.constraint.type != VersionConstraintKind::None; })) { - LockGuardPtr(g_metrics)->track_property("manifest_version_constraint", "defined"); + LockGuardPtr(g_metrics)->track_property(Metrics::SetMetric::ManifestVersionConstraint); } if (!manifest_core.overrides.empty()) { - LockGuardPtr(g_metrics)->track_property("manifest_overrides", "defined"); + LockGuardPtr(g_metrics)->track_property(Metrics::SetMetric::ManifestOverrides); } auto verprovider = make_versioned_portfile_provider(paths); @@ -1153,7 +1154,7 @@ namespace vcpkg auto it_pkgsconfig = options.settings.find(OPTION_WRITE_PACKAGES_CONFIG); if (it_pkgsconfig != options.settings.end()) { - LockGuardPtr(g_metrics)->track_property("x-write-nuget-packages-config", "defined"); + LockGuardPtr(g_metrics)->track_property(Metrics::SetMetric::X_WriteNugetPackagesConfig); compute_all_abis(paths, action_plan, var_provider, status_db); auto pkgsconfig_path = paths.original_cwd / it_pkgsconfig->second; @@ -1298,6 +1299,6 @@ namespace vcpkg Hash::get_string_hash(version_as_string, Hash::Algorithm::Sha256)); } - LockGuardPtr(g_metrics)->track_property("installplan_1", specs_string); + LockGuardPtr(g_metrics)->track_property(Metrics::StringMetric::InstallPlan_1, specs_string); } } diff --git a/src/vcpkg/metrics.cpp b/src/vcpkg/metrics.cpp index 0de1962dd0..9bc6d1b402 100644 --- a/src/vcpkg/metrics.cpp +++ b/src/vcpkg/metrics.cpp @@ -17,6 +17,58 @@ #pragma comment(lib, "winhttp") #endif +namespace +{ + using namespace vcpkg; + + static std::map SET_METRIC_NAMES{ + {Metrics::SetMetric::AssetSource, "asset-source"}, + {Metrics::SetMetric::BinaryCachingAws, "binarycaching_aws"}, + {Metrics::SetMetric::BinaryCachingAzBlob, "binarycaching_azblob"}, + {Metrics::SetMetric::BinaryCachingCos, "binarycaching_cos"}, + {Metrics::SetMetric::BinaryCachingDefault, "binarycaching_default"}, + {Metrics::SetMetric::BinaryCachingFiles, "binarycaching_files"}, + {Metrics::SetMetric::BinaryCachingGcs, "binarycaching_gcs"}, + {Metrics::SetMetric::BinaryCachingHttp, "binarycaching_http"}, + {Metrics::SetMetric::BinaryCachingNuget, "binarycaching_nuget"}, + {Metrics::SetMetric::BinaryCachingSource, "binarycaching-source"}, + {Metrics::SetMetric::ErrorVersioningDisabled, "error-versioning-disabled"}, + {Metrics::SetMetric::ErrorVersioningNoBaseline, "error-versioning-no-baseline"}, + {Metrics::SetMetric::GitHubRepository, "GITHUB_REPOSITORY"}, + {Metrics::SetMetric::ManifestBaseline, "manifest_baseline"}, + {Metrics::SetMetric::ManifestOverrides, "manifest_overrides"}, + {Metrics::SetMetric::ManifestVersionConstraint, "manifest_version_constraint"}, + {Metrics::SetMetric::RegistriesErrorCouldNotFindBaseline, "registries-error-could-not-find-baseline"}, + {Metrics::SetMetric::RegistriesErrorNoVersionsAtCommit, "registries-error-no-versions-at-commit"}, + {Metrics::SetMetric::VcpkgBinarySources, "VCPKG_BINARY_SOURCES"}, + {Metrics::SetMetric::VcpkgDefaultBinaryCache, "VCPKG_DEFAULT_BINARY_CACHE"}, + {Metrics::SetMetric::VcpkgNugetRepository, "VCPKG_NUGET_REPOSITORY"}, + {Metrics::SetMetric::VersioningErrorBaseline, "versioning-error-baseline"}, + {Metrics::SetMetric::VersioningErrorVersion, "versioning-error-version"}, + {Metrics::SetMetric::X_VcpkgRegistriesCache, "X_VCPKG_REGISTRIES_CACHE"}, + {Metrics::SetMetric::X_WriteNugetPackagesConfig, "x-write-nuget-packages-config"}, + }; + + static std::map STRING_METRIC_NAMES{ + {Metrics::StringMetric::BuildError, "build_error"}, + {Metrics::StringMetric::CommandArgs, "command_args"}, + {Metrics::StringMetric::CommandContext, "command_context"}, + {Metrics::StringMetric::CommandName, "command_name"}, + {Metrics::StringMetric::Error, "error"}, + {Metrics::StringMetric::InstallPlan_1, "installplan_1"}, + {Metrics::StringMetric::ListFile, "listfile"}, + {Metrics::StringMetric::RegistriesDefaultRegistryKind, "registries-default-registry-kind"}, + {Metrics::StringMetric::RegistriesKindsUsed, "registries-kinds-used"}, + {Metrics::StringMetric::Title, "title"}, + {Metrics::StringMetric::UserMac, "user_mac"}, + {Metrics::StringMetric::Warning, "warning"}, + }; + + static std::map BOOL_METRIC_NAMES = { + {Metrics::BoolMetric::InstallManifestMode, "install_manifest_mode"}, + }; +} + namespace vcpkg { LockGuarded g_metrics; @@ -231,7 +283,7 @@ namespace vcpkg g_metricmessage.user_id = config.user_id; g_metricmessage.user_timestamp = config.user_time; - metrics->track_property("user_mac", config.user_mac); + metrics->track_property(Metrics::StringMetric::UserMac, config.user_mac); g_metrics_disabled = false; } @@ -246,12 +298,20 @@ namespace vcpkg g_metricmessage.track_buildtime(name, value); } - void Metrics::track_property(const std::string& name, const std::string& value) + void Metrics::track_property(SetMetric metric) + { + g_metricmessage.track_property(SET_METRIC_NAMES[metric], "defined"); + } + + void Metrics::track_property(StringMetric metric, const std::string& value) { - g_metricmessage.track_property(name, value); + g_metricmessage.track_property(STRING_METRIC_NAMES[metric], value); } - void Metrics::track_property(const std::string& name, bool value) { g_metricmessage.track_property(name, value); } + void Metrics::track_property(BoolMetric metric, bool value) + { + g_metricmessage.track_property(BOOL_METRIC_NAMES[metric], value); + } void Metrics::track_feature(const std::string& name, bool value) { g_metricmessage.track_feature(name, value); } diff --git a/src/vcpkg/portfileprovider.cpp b/src/vcpkg/portfileprovider.cpp index d4c956f314..1624847e1a 100644 --- a/src/vcpkg/portfileprovider.cpp +++ b/src/vcpkg/portfileprovider.cpp @@ -204,7 +204,7 @@ namespace vcpkg } else { - LockGuardPtr(g_metrics)->track_property("versioning-error-version", "defined"); + LockGuardPtr(g_metrics)->track_property(Metrics::SetMetric::VersioningErrorVersion); return maybe_path.error(); } } diff --git a/src/vcpkg/registries.cpp b/src/vcpkg/registries.cpp index 12b2fa9101..d6e50d3f91 100644 --- a/src/vcpkg/registries.cpp +++ b/src/vcpkg/registries.cpp @@ -85,8 +85,8 @@ namespace e.commit_id(), registry_versions_dir_name.to_string()); if (!maybe_tree) { - LockGuardPtr(g_metrics)->track_property("registries-error-no-versions-at-commit", - "defined"); + LockGuardPtr(g_metrics)->track_property( + Metrics::SetMetric::RegistriesErrorNoVersionsAtCommit); Checks::exit_with_message( VCPKG_LINE_INFO, "Error: could not find the git tree for `versions` in repo `%s` at commit `%s`: %s", @@ -661,8 +661,8 @@ namespace auto maybe_err = m_paths.git_fetch(m_repo, m_baseline_identifier); if (!maybe_err) { - LockGuardPtr(g_metrics)->track_property("registries-error-could-not-find-baseline", - "defined"); + LockGuardPtr(g_metrics)->track_property( + Metrics::SetMetric::RegistriesErrorCouldNotFindBaseline); Checks::exit_with_message( VCPKG_LINE_INFO, "Error: Couldn't find baseline `\"%s\"` for repo %s:\n%s\nError: Failed to fetch %s:\n%s", @@ -678,7 +678,8 @@ namespace if (!maybe_contents) { - LockGuardPtr(g_metrics)->track_property("registries-error-could-not-find-baseline", "defined"); + LockGuardPtr(g_metrics)->track_property( + Metrics::SetMetric::RegistriesErrorCouldNotFindBaseline); Checks::exit_with_message(VCPKG_LINE_INFO, "Error: Couldn't find baseline in commit `\"%s\"` from repo %s:\n%s\n", m_baseline_identifier, @@ -696,8 +697,8 @@ namespace } else { - LockGuardPtr(g_metrics)->track_property("registries-error-could-not-find-baseline", - "defined"); + LockGuardPtr(g_metrics)->track_property( + Metrics::SetMetric::RegistriesErrorCouldNotFindBaseline); Checks::exit_maybe_upgrade( VCPKG_LINE_INFO, "The baseline.json from commit `\"%s\"` in the repo %s did not contain a \"default\" field.", diff --git a/src/vcpkg/sourceparagraph.cpp b/src/vcpkg/sourceparagraph.cpp index a2bdb81405..7714248603 100644 --- a/src/vcpkg/sourceparagraph.cpp +++ b/src/vcpkg/sourceparagraph.cpp @@ -1297,7 +1297,7 @@ namespace vcpkg { if (dep.constraint.type != VersionConstraintKind::None) { - LockGuardPtr(g_metrics)->track_property("error-versioning-disabled", "defined"); + LockGuardPtr(g_metrics)->track_property(Metrics::SetMetric::ErrorVersioningDisabled); return Strings::concat( origin, " was rejected because it uses constraints and the `", @@ -1318,7 +1318,7 @@ namespace vcpkg if (core_paragraph->overrides.size() != 0) { - LockGuardPtr(g_metrics)->track_property("error-versioning-disabled", "defined"); + LockGuardPtr(g_metrics)->track_property(Metrics::SetMetric::ErrorVersioningDisabled); return Strings::concat( origin, format_error_message(ManifestDeserializer::OVERRIDES, VcpkgCmdArguments::VERSIONS_FEATURE), @@ -1327,7 +1327,7 @@ namespace vcpkg if (core_paragraph->builtin_baseline.has_value()) { - LockGuardPtr(g_metrics)->track_property("error-versioning-disabled", "defined"); + LockGuardPtr(g_metrics)->track_property(Metrics::SetMetric::ErrorVersioningDisabled); return Strings::concat( origin, format_error_message(ManifestDeserializer::BUILTIN_BASELINE, VcpkgCmdArguments::VERSIONS_FEATURE), @@ -1344,7 +1344,7 @@ namespace vcpkg return dependency.constraint.type != VersionConstraintKind::None; })) { - LockGuardPtr(g_metrics)->track_property("error-versioning-no-baseline", "defined"); + LockGuardPtr(g_metrics)->track_property(Metrics::SetMetric::ErrorVersioningNoBaseline); return Strings::concat( origin, " was rejected because it uses \"version>=\" and does not have a \"builtin-baseline\".\n", @@ -1353,7 +1353,7 @@ namespace vcpkg if (!core_paragraph->overrides.empty()) { - LockGuardPtr(g_metrics)->track_property("error-versioning-no-baseline", "defined"); + LockGuardPtr(g_metrics)->track_property(Metrics::SetMetric::ErrorVersioningNoBaseline); return Strings::concat( origin, " was rejected because it uses \"overrides\" and does not have a \"builtin-baseline\".\n", diff --git a/src/vcpkg/vcpkgcmdarguments.cpp b/src/vcpkg/vcpkgcmdarguments.cpp index 614c46ae26..2be1eaa085 100644 --- a/src/vcpkg/vcpkgcmdarguments.cpp +++ b/src/vcpkg/vcpkgcmdarguments.cpp @@ -39,7 +39,7 @@ namespace vcpkg if (place.has_value()) { msg::println_error(msgTwoFeatureFlagsSpecified, msg::value = flag); - LockGuardPtr(g_metrics)->track_property("error", + LockGuardPtr(g_metrics)->track_property(Metrics::StringMetric::Error, "error feature flag +-" + flag.to_string()); Checks::exit_fail(VCPKG_LINE_INFO); } @@ -79,7 +79,8 @@ namespace vcpkg if (nullptr != option_field) { msg::println_error(msgDuplicateOptions, msg::value = option_name); - LockGuardPtr(g_metrics)->track_property("error", "error option specified multiple times"); + LockGuardPtr(g_metrics)->track_property(Metrics::StringMetric::Error, + "error option specified multiple times"); print_usage(); Checks::exit_fail(VCPKG_LINE_INFO); } @@ -92,7 +93,8 @@ namespace vcpkg if (option_field && option_field != new_setting) { msg::println_error(msgConflictingValuesForOption, msg::value = option_name); - LockGuardPtr(g_metrics)->track_property("error", "error conflicting switches"); + LockGuardPtr(g_metrics)->track_property(Metrics::StringMetric::Error, + "error conflicting switches"); print_usage(); Checks::exit_fail(VCPKG_LINE_INFO); } @@ -106,7 +108,7 @@ namespace vcpkg if (new_value.size() == 0) { msg::println_error(msgExpectedValueForOption, msg::value = option_name); - LockGuardPtr(g_metrics)->track_property("error", "error option name"); + LockGuardPtr(g_metrics)->track_property(Metrics::StringMetric::Error, "error option name"); print_usage(); Checks::exit_fail(VCPKG_LINE_INFO); } @@ -121,7 +123,7 @@ namespace vcpkg if (new_value.size() == 0) { msg::println_error(msgExpectedValueForOption, msg::value = option_name); - LockGuardPtr(g_metrics)->track_property("error", "error option name"); + LockGuardPtr(g_metrics)->track_property(Metrics::StringMetric::Error, "error option name"); print_usage(); Checks::exit_fail(VCPKG_LINE_INFO); } @@ -188,7 +190,7 @@ namespace vcpkg } msg::println_error(msgExpectedValueForOption, msg::value = option); - LockGuardPtr(g_metrics)->track_property("error", "error option name"); + LockGuardPtr(g_metrics)->track_property(Metrics::StringMetric::Error, "error option name"); print_usage(); Checks::exit_fail(VCPKG_LINE_INFO); } @@ -261,7 +263,8 @@ namespace vcpkg if (basic_arg.size() >= 2 && basic_arg[0] == '-' && basic_arg[1] != '-') { - LockGuardPtr(g_metrics)->track_property("error", "error short options are not supported"); + LockGuardPtr(g_metrics)->track_property(Metrics::StringMetric::Error, + "error short options are not supported"); Checks::msg_exit_with_message(VCPKG_LINE_INFO, msgUnsupportedShortOptions, msg::value = basic_arg); } @@ -836,7 +839,7 @@ namespace vcpkg msgSpecifiedFeatureTurnedOff, msg::command_name = el.flag, msg::option = el.option); msg::println_warning(msgDefaultFlag, msg::option = el.flag); LockGuardPtr(g_metrics)->track_property( - "warning", Strings::format("warning %s alongside %s", el.flag, el.option)); + Metrics::StringMetric::Warning, Strings::format("warning %s alongside %s", el.flag, el.option)); } } } diff --git a/src/vcpkg/vcpkglib.cpp b/src/vcpkg/vcpkglib.cpp index 662faa39ce..72405346b3 100644 --- a/src/vcpkg/vcpkglib.cpp +++ b/src/vcpkg/vcpkglib.cpp @@ -111,7 +111,7 @@ namespace vcpkg if (!was_tracked) { was_tracked = true; - LockGuardPtr(g_metrics)->track_property("listfile", "update to new format"); + LockGuardPtr(g_metrics)->track_property(Metrics::StringMetric::ListFile, "update to new format"); } // The files are sorted such that directories are placed just before the files they contain diff --git a/src/vcpkg/vcpkgpaths.cpp b/src/vcpkg/vcpkgpaths.cpp index 61e9ab3cf7..e12514b387 100644 --- a/src/vcpkg/vcpkgpaths.cpp +++ b/src/vcpkg/vcpkgpaths.cpp @@ -187,10 +187,11 @@ namespace vcpkg { if (auto p_baseline = manifest->builtin_baseline.get()) { - LockGuardPtr(g_metrics)->track_property("manifest_baseline", "defined"); + LockGuardPtr(g_metrics)->track_property(Metrics::SetMetric::ManifestBaseline); if (!is_git_commit_sha(*p_baseline)) { - LockGuardPtr(g_metrics)->track_property("versioning-error-baseline", "defined"); + // TODO: + LockGuardPtr(g_metrics)->track_property(Metrics::SetMetric::VersioningErrorBaseline); Checks::exit_maybe_upgrade(VCPKG_LINE_INFO, "Error: the top-level builtin-baseline%s was not a valid commit sha: " "expected 40 lowercase hexadecimal characters.\n%s\n", @@ -325,7 +326,7 @@ namespace vcpkg Path ret; if (args.registries_cache_dir) { - LockGuardPtr(g_metrics)->track_property("X_VCPKG_REGISTRIES_CACHE", "defined"); + LockGuardPtr(g_metrics)->track_property(Metrics::SetMetric::X_VcpkgRegistriesCache); ret = *args.registries_cache_dir; const auto status = get_real_filesystem().status(ret, VCPKG_LINE_INFO); if (!vcpkg::exists(status)) @@ -666,11 +667,12 @@ namespace vcpkg LockGuardPtr metrics(g_metrics); if (default_registry) { - metrics->track_property("registries-default-registry-kind", default_registry->kind().to_string()); + metrics->track_property(Metrics::StringMetric::RegistriesDefaultRegistryKind, + default_registry->kind().to_string()); } else { - metrics->track_property("registries-default-registry-kind", "disabled"); + metrics->track_property(Metrics::StringMetric::RegistriesDefaultRegistryKind, "disabled"); } if (other_registries.size() != 0) @@ -681,7 +683,7 @@ namespace vcpkg registry_kinds.push_back(reg.implementation().kind()); } Util::sort_unique_erase(registry_kinds); - metrics->track_property("registries-kinds-used", Strings::join(",", registry_kinds)); + metrics->track_property(Metrics::StringMetric::RegistriesKindsUsed, Strings::join(",", registry_kinds)); } } } From ef11cfabc9cda36c1b39efeaa5391fb65c192e70 Mon Sep 17 00:00:00 2001 From: Victor Romero Date: Wed, 31 Aug 2022 16:07:35 -0700 Subject: [PATCH 03/14] Update src/vcpkg/vcpkgpaths.cpp --- src/vcpkg/vcpkgpaths.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/vcpkg/vcpkgpaths.cpp b/src/vcpkg/vcpkgpaths.cpp index 0950538b39..4c857e2bdb 100644 --- a/src/vcpkg/vcpkgpaths.cpp +++ b/src/vcpkg/vcpkgpaths.cpp @@ -190,7 +190,6 @@ namespace vcpkg LockGuardPtr(g_metrics)->track_property(Metrics::SetMetric::ManifestBaseline); if (!is_git_commit_sha(*p_baseline)) { - // TODO: LockGuardPtr(g_metrics)->track_property(Metrics::SetMetric::VersioningErrorBaseline); Checks::exit_maybe_upgrade(VCPKG_LINE_INFO, "Error: the top-level builtin-baseline%s was not a valid commit sha: " From c4ff3d164510e81b54eadd81ce0c257a7eff9c09 Mon Sep 17 00:00:00 2001 From: Victor Romero Date: Wed, 31 Aug 2022 16:40:48 -0700 Subject: [PATCH 04/14] Remove `track_option()` --- include/vcpkg/metrics.h | 6 ++---- src/vcpkg.cpp | 2 +- src/vcpkg/metrics.cpp | 8 +------- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/include/vcpkg/metrics.h b/include/vcpkg/metrics.h index c62980463f..74bdf2b453 100644 --- a/include/vcpkg/metrics.h +++ b/include/vcpkg/metrics.h @@ -59,7 +59,8 @@ namespace vcpkg enum class BoolMetric { - InstallManifestMode + InstallManifestMode, + OptionOverlayPorts }; Metrics() = default; @@ -80,7 +81,6 @@ namespace vcpkg void track_property(BoolMetric metric, bool value); void track_feature(const std::string& feature, bool value); - void track_option(const std::string& option, bool value); bool metrics_enabled(); @@ -88,7 +88,5 @@ namespace vcpkg void flush(Filesystem& fs); }; - Optional find_first_nonzero_mac(StringView sv); - extern LockGuarded g_metrics; } diff --git a/src/vcpkg.cpp b/src/vcpkg.cpp index 2dbef5644a..852ee4c1e6 100644 --- a/src/vcpkg.cpp +++ b/src/vcpkg.cpp @@ -68,7 +68,7 @@ static void inner(vcpkg::Filesystem& fs, const VcpkgCmdArguments& args) } }; - LockGuardPtr(g_metrics)->track_option("overlay_ports", !args.overlay_ports.empty()); + LockGuardPtr(g_metrics)->track_property(Metrics::BoolMetric::OptionOverlayPorts, !args.overlay_ports.empty()); if (const auto command_function = find_command(Commands::get_available_basic_commands())) { diff --git a/src/vcpkg/metrics.cpp b/src/vcpkg/metrics.cpp index 9bc6d1b402..fa6f279834 100644 --- a/src/vcpkg/metrics.cpp +++ b/src/vcpkg/metrics.cpp @@ -66,6 +66,7 @@ namespace static std::map BOOL_METRIC_NAMES = { {Metrics::BoolMetric::InstallManifestMode, "install_manifest_mode"}, + {Metrics::BoolMetric::OptionOverlayPorts, "option_overlay_ports"}, }; } @@ -158,11 +159,6 @@ namespace vcpkg properties.insert(Strings::concat("feature-flag-", name), Json::Value::boolean(value)); } - void track_option(StringView name, bool value) - { - properties.insert(Strings::concat("option_", name), Json::Value::boolean(value)); - } - std::string format_event_data_template() const { auto props_plus_buildtimes = properties; @@ -315,8 +311,6 @@ namespace vcpkg void Metrics::track_feature(const std::string& name, bool value) { g_metricmessage.track_feature(name, value); } - void Metrics::track_option(const std::string& name, bool value) { g_metricmessage.track_option(name, value); } - void Metrics::upload(const std::string& payload) { if (!metrics_enabled()) From caf08c72fdb2c14ed11c8fba7a46fe323e9835f7 Mon Sep 17 00:00:00 2001 From: Victor Romero Date: Wed, 31 Aug 2022 16:46:50 -0700 Subject: [PATCH 05/14] Renamed SetMetric to DefineMetric --- include/vcpkg/metrics.h | 5 ++--- src/vcpkg/binarycaching.cpp | 30 +++++++++++++++--------------- src/vcpkg/install.cpp | 8 ++++---- src/vcpkg/portfileprovider.cpp | 2 +- src/vcpkg/registries.cpp | 8 ++++---- src/vcpkg/sourceparagraph.cpp | 11 ++++++----- src/vcpkg/vcpkgpaths.cpp | 6 +++--- 7 files changed, 35 insertions(+), 35 deletions(-) diff --git a/include/vcpkg/metrics.h b/include/vcpkg/metrics.h index 74bdf2b453..7022787e39 100644 --- a/include/vcpkg/metrics.h +++ b/include/vcpkg/metrics.h @@ -1,7 +1,6 @@ #pragma once #include -#include #include #include @@ -11,7 +10,7 @@ namespace vcpkg { struct Metrics { - enum class SetMetric + enum class DefineMetric { AssetSource, BinaryCachingAws, @@ -76,7 +75,7 @@ namespace vcpkg void track_metric(const std::string& name, double value); void track_buildtime(const std::string& name, double value); - void track_property(SetMetric metric); + void track_property(DefineMetric metric); void track_property(StringMetric metric, const std::string& value); void track_property(BoolMetric metric, bool value); diff --git a/src/vcpkg/binarycaching.cpp b/src/vcpkg/binarycaching.cpp index d4abe8b9b1..fd80570ea2 100644 --- a/src/vcpkg/binarycaching.cpp +++ b/src/vcpkg/binarycaching.cpp @@ -1579,7 +1579,7 @@ namespace auto maybe_cachepath = get_environment_variable("VCPKG_DEFAULT_BINARY_CACHE"); if (auto p_str = maybe_cachepath.get()) { - LockGuardPtr(g_metrics)->track_property(Metrics::SetMetric::VcpkgDefaultBinaryCache); + LockGuardPtr(g_metrics)->track_property(Metrics::DefineMetric::VcpkgDefaultBinaryCache); Path path = *p_str; path.make_preferred(); if (!get_real_filesystem().is_directory(path)) @@ -1999,15 +1999,15 @@ namespace for (const auto& cache_provider : state->binary_cache_providers) { - static const std::map metric_names{ - {"aws", Metrics::SetMetric::BinaryCachingAws}, - {"azblob", Metrics::SetMetric::BinaryCachingAzBlob}, - {"cos", Metrics::SetMetric::BinaryCachingCos}, - {"default", Metrics::SetMetric::BinaryCachingDefault}, - {"files", Metrics::SetMetric::BinaryCachingFiles}, - {"gcs", Metrics::SetMetric::BinaryCachingGcs}, - {"http", Metrics::SetMetric::BinaryCachingHttp}, - {"nuget", Metrics::SetMetric::BinaryCachingNuget}, + static const std::map metric_names{ + {"aws", Metrics::DefineMetric::BinaryCachingAws}, + {"azblob", Metrics::DefineMetric::BinaryCachingAzBlob}, + {"cos", Metrics::DefineMetric::BinaryCachingCos}, + {"default", Metrics::DefineMetric::BinaryCachingDefault}, + {"files", Metrics::DefineMetric::BinaryCachingFiles}, + {"gcs", Metrics::DefineMetric::BinaryCachingGcs}, + {"http", Metrics::DefineMetric::BinaryCachingHttp}, + {"nuget", Metrics::DefineMetric::BinaryCachingNuget}, }; auto it = metric_names.find(cache_provider); @@ -2147,7 +2147,7 @@ ExpectedS vcpkg::parse_download_configuration(const Optio { if (!arg || arg.get()->empty()) return DownloadManagerConfig{}; - LockGuardPtr(g_metrics)->track_property(Metrics::SetMetric::AssetSource); + LockGuardPtr(g_metrics)->track_property(Metrics::DefineMetric::AssetSource); AssetSourcesState s; AssetSourcesParser parser(*arg.get(), Strings::concat("$", VcpkgCmdArguments::ASSET_SOURCES_ENV), &s); @@ -2202,12 +2202,12 @@ ExpectedS vcpkg::create_binary_providers_from_configs_p LockGuardPtr metrics(g_metrics); if (!env_string.empty()) { - metrics->track_property(Metrics::SetMetric::VcpkgBinarySources); + metrics->track_property(Metrics::DefineMetric::VcpkgBinarySources); } if (args.size() != 0) { - metrics->track_property(Metrics::SetMetric::BinaryCachingSource); + metrics->track_property(Metrics::DefineMetric::BinaryCachingSource); } } @@ -2346,7 +2346,7 @@ details::NuGetRepoInfo details::get_nuget_repo_info_from_env() auto vcpkg_nuget_repository = get_environment_variable("VCPKG_NUGET_REPOSITORY"); if (auto p = vcpkg_nuget_repository.get()) { - LockGuardPtr(g_metrics)->track_property(Metrics::SetMetric::VcpkgNugetRepository); + LockGuardPtr(g_metrics)->track_property(Metrics::DefineMetric::VcpkgNugetRepository); return {std::move(*p)}; } @@ -2362,7 +2362,7 @@ details::NuGetRepoInfo details::get_nuget_repo_info_from_env() return {}; } - LockGuardPtr(g_metrics)->track_property(Metrics::SetMetric::GitHubRepository); + LockGuardPtr(g_metrics)->track_property(Metrics::DefineMetric::GitHubRepository); return {Strings::concat(gh_server, '/', gh_repo, ".git"), get_environment_variable("GITHUB_REF").value_or(""), get_environment_variable("GITHUB_SHA").value_or("")}; diff --git a/src/vcpkg/install.cpp b/src/vcpkg/install.cpp index fbd1e2c979..5970d74fa0 100644 --- a/src/vcpkg/install.cpp +++ b/src/vcpkg/install.cpp @@ -966,7 +966,7 @@ namespace vcpkg auto it_pkgsconfig = options.settings.find(OPTION_WRITE_PACKAGES_CONFIG); if (it_pkgsconfig != options.settings.end()) { - LockGuardPtr(g_metrics)->track_property(Metrics::SetMetric::X_WriteNugetPackagesConfig); + LockGuardPtr(g_metrics)->track_property(Metrics::DefineMetric::X_WriteNugetPackagesConfig); pkgsconfig = Path(it_pkgsconfig->second); } auto maybe_manifest_scf = @@ -1034,12 +1034,12 @@ namespace vcpkg return dep.constraint.type != VersionConstraintKind::None; })) { - LockGuardPtr(g_metrics)->track_property(Metrics::SetMetric::ManifestVersionConstraint); + LockGuardPtr(g_metrics)->track_property(Metrics::DefineMetric::ManifestVersionConstraint); } if (!manifest_core.overrides.empty()) { - LockGuardPtr(g_metrics)->track_property(Metrics::SetMetric::ManifestOverrides); + LockGuardPtr(g_metrics)->track_property(Metrics::DefineMetric::ManifestOverrides); } auto verprovider = make_versioned_portfile_provider(paths); @@ -1169,7 +1169,7 @@ namespace vcpkg auto it_pkgsconfig = options.settings.find(OPTION_WRITE_PACKAGES_CONFIG); if (it_pkgsconfig != options.settings.end()) { - LockGuardPtr(g_metrics)->track_property(Metrics::SetMetric::X_WriteNugetPackagesConfig); + LockGuardPtr(g_metrics)->track_property(Metrics::DefineMetric::X_WriteNugetPackagesConfig); compute_all_abis(paths, action_plan, var_provider, status_db); auto pkgsconfig_path = paths.original_cwd / it_pkgsconfig->second; diff --git a/src/vcpkg/portfileprovider.cpp b/src/vcpkg/portfileprovider.cpp index 1624847e1a..d7c22d1bb0 100644 --- a/src/vcpkg/portfileprovider.cpp +++ b/src/vcpkg/portfileprovider.cpp @@ -204,7 +204,7 @@ namespace vcpkg } else { - LockGuardPtr(g_metrics)->track_property(Metrics::SetMetric::VersioningErrorVersion); + LockGuardPtr(g_metrics)->track_property(Metrics::DefineMetric::VersioningErrorVersion); return maybe_path.error(); } } diff --git a/src/vcpkg/registries.cpp b/src/vcpkg/registries.cpp index 7787c3848c..ef058aeadf 100644 --- a/src/vcpkg/registries.cpp +++ b/src/vcpkg/registries.cpp @@ -86,7 +86,7 @@ namespace if (!maybe_tree) { LockGuardPtr(g_metrics)->track_property( - Metrics::SetMetric::RegistriesErrorNoVersionsAtCommit); + Metrics::DefineMetric::RegistriesErrorNoVersionsAtCommit); Checks::exit_with_message( VCPKG_LINE_INFO, "Error: could not find the git tree for `versions` in repo `%s` at commit `%s`: %s", @@ -662,7 +662,7 @@ namespace if (!maybe_err) { LockGuardPtr(g_metrics)->track_property( - Metrics::SetMetric::RegistriesErrorCouldNotFindBaseline); + Metrics::DefineMetric::RegistriesErrorCouldNotFindBaseline); Checks::exit_with_message( VCPKG_LINE_INFO, "Error: Couldn't find baseline `\"%s\"` for repo %s:\n%s\nError: Failed to fetch %s:\n%s", @@ -679,7 +679,7 @@ namespace if (!maybe_contents) { LockGuardPtr(g_metrics)->track_property( - Metrics::SetMetric::RegistriesErrorCouldNotFindBaseline); + Metrics::DefineMetric::RegistriesErrorCouldNotFindBaseline); Checks::exit_with_message(VCPKG_LINE_INFO, "Error: Couldn't find baseline in commit `\"%s\"` from repo %s:\n%s\n", m_baseline_identifier, @@ -698,7 +698,7 @@ namespace else { LockGuardPtr(g_metrics)->track_property( - Metrics::SetMetric::RegistriesErrorCouldNotFindBaseline); + Metrics::DefineMetric::RegistriesErrorCouldNotFindBaseline); Checks::exit_maybe_upgrade( VCPKG_LINE_INFO, "The baseline.json from commit `\"%s\"` in the repo %s did not contain a \"default\" field.", diff --git a/src/vcpkg/sourceparagraph.cpp b/src/vcpkg/sourceparagraph.cpp index edee7659c3..f73c569ee7 100644 --- a/src/vcpkg/sourceparagraph.cpp +++ b/src/vcpkg/sourceparagraph.cpp @@ -1290,7 +1290,8 @@ namespace vcpkg { if (dep.constraint.type != VersionConstraintKind::None) { - LockGuardPtr(g_metrics)->track_property(Metrics::SetMetric::ErrorVersioningDisabled); + LockGuardPtr(g_metrics)->track_property( + Metrics::DefineMetric::ErrorVersioningDisabled); return Strings::concat( origin, " was rejected because it uses constraints and the `", @@ -1311,7 +1312,7 @@ namespace vcpkg if (core_paragraph->overrides.size() != 0) { - LockGuardPtr(g_metrics)->track_property(Metrics::SetMetric::ErrorVersioningDisabled); + LockGuardPtr(g_metrics)->track_property(Metrics::DefineMetric::ErrorVersioningDisabled); return Strings::concat( origin, format_error_message(ManifestDeserializer::OVERRIDES, VcpkgCmdArguments::VERSIONS_FEATURE), @@ -1320,7 +1321,7 @@ namespace vcpkg if (core_paragraph->builtin_baseline.has_value()) { - LockGuardPtr(g_metrics)->track_property(Metrics::SetMetric::ErrorVersioningDisabled); + LockGuardPtr(g_metrics)->track_property(Metrics::DefineMetric::ErrorVersioningDisabled); return Strings::concat( origin, format_error_message(ManifestDeserializer::BUILTIN_BASELINE, VcpkgCmdArguments::VERSIONS_FEATURE), @@ -1337,7 +1338,7 @@ namespace vcpkg return dependency.constraint.type != VersionConstraintKind::None; })) { - LockGuardPtr(g_metrics)->track_property(Metrics::SetMetric::ErrorVersioningNoBaseline); + LockGuardPtr(g_metrics)->track_property(Metrics::DefineMetric::ErrorVersioningNoBaseline); return Strings::concat( origin, " was rejected because it uses \"version>=\" and does not have a \"builtin-baseline\".\n", @@ -1346,7 +1347,7 @@ namespace vcpkg if (!core_paragraph->overrides.empty()) { - LockGuardPtr(g_metrics)->track_property(Metrics::SetMetric::ErrorVersioningNoBaseline); + LockGuardPtr(g_metrics)->track_property(Metrics::DefineMetric::ErrorVersioningNoBaseline); return Strings::concat( origin, " was rejected because it uses \"overrides\" and does not have a \"builtin-baseline\".\n", diff --git a/src/vcpkg/vcpkgpaths.cpp b/src/vcpkg/vcpkgpaths.cpp index 4c857e2bdb..63f5a74d3e 100644 --- a/src/vcpkg/vcpkgpaths.cpp +++ b/src/vcpkg/vcpkgpaths.cpp @@ -187,10 +187,10 @@ namespace vcpkg { if (auto p_baseline = manifest->builtin_baseline.get()) { - LockGuardPtr(g_metrics)->track_property(Metrics::SetMetric::ManifestBaseline); + LockGuardPtr(g_metrics)->track_property(Metrics::DefineMetric::ManifestBaseline); if (!is_git_commit_sha(*p_baseline)) { - LockGuardPtr(g_metrics)->track_property(Metrics::SetMetric::VersioningErrorBaseline); + LockGuardPtr(g_metrics)->track_property(Metrics::DefineMetric::VersioningErrorBaseline); Checks::exit_maybe_upgrade(VCPKG_LINE_INFO, "Error: the top-level builtin-baseline%s was not a valid commit sha: " "expected 40 hexadecimal characters.\n%s\n", @@ -325,7 +325,7 @@ namespace vcpkg Path ret; if (args.registries_cache_dir) { - LockGuardPtr(g_metrics)->track_property(Metrics::SetMetric::X_VcpkgRegistriesCache); + LockGuardPtr(g_metrics)->track_property(Metrics::DefineMetric::X_VcpkgRegistriesCache); ret = *args.registries_cache_dir; const auto status = get_real_filesystem().status(ret, VCPKG_LINE_INFO); if (!vcpkg::exists(status)) From 109ae2b9bdb7ec77f98cfe78f4c6f73f169edefe Mon Sep 17 00:00:00 2001 From: Victor Romero Date: Wed, 31 Aug 2022 16:57:24 -0700 Subject: [PATCH 06/14] Never trust VS's `Ctrl+R,Ctrl+R` --- src/vcpkg/commands.setinstalled.cpp | 2 +- src/vcpkg/metrics.cpp | 64 ++++++++++++++--------------- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/vcpkg/commands.setinstalled.cpp b/src/vcpkg/commands.setinstalled.cpp index 781b50ab23..af2931818b 100644 --- a/src/vcpkg/commands.setinstalled.cpp +++ b/src/vcpkg/commands.setinstalled.cpp @@ -164,7 +164,7 @@ namespace vcpkg::Commands::SetInstalled auto it_pkgsconfig = options.settings.find(OPTION_WRITE_PACKAGES_CONFIG); if (it_pkgsconfig != options.settings.end()) { - LockGuardPtr(g_metrics)->track_property(Metrics::SetMetric::X_WriteNugetPackagesConfig); + LockGuardPtr(g_metrics)->track_property(Metrics::DefineMetric::X_WriteNugetPackagesConfig); pkgsconfig = it_pkgsconfig->second; } diff --git a/src/vcpkg/metrics.cpp b/src/vcpkg/metrics.cpp index fa6f279834..fb30228884 100644 --- a/src/vcpkg/metrics.cpp +++ b/src/vcpkg/metrics.cpp @@ -21,35 +21,35 @@ namespace { using namespace vcpkg; - static std::map SET_METRIC_NAMES{ - {Metrics::SetMetric::AssetSource, "asset-source"}, - {Metrics::SetMetric::BinaryCachingAws, "binarycaching_aws"}, - {Metrics::SetMetric::BinaryCachingAzBlob, "binarycaching_azblob"}, - {Metrics::SetMetric::BinaryCachingCos, "binarycaching_cos"}, - {Metrics::SetMetric::BinaryCachingDefault, "binarycaching_default"}, - {Metrics::SetMetric::BinaryCachingFiles, "binarycaching_files"}, - {Metrics::SetMetric::BinaryCachingGcs, "binarycaching_gcs"}, - {Metrics::SetMetric::BinaryCachingHttp, "binarycaching_http"}, - {Metrics::SetMetric::BinaryCachingNuget, "binarycaching_nuget"}, - {Metrics::SetMetric::BinaryCachingSource, "binarycaching-source"}, - {Metrics::SetMetric::ErrorVersioningDisabled, "error-versioning-disabled"}, - {Metrics::SetMetric::ErrorVersioningNoBaseline, "error-versioning-no-baseline"}, - {Metrics::SetMetric::GitHubRepository, "GITHUB_REPOSITORY"}, - {Metrics::SetMetric::ManifestBaseline, "manifest_baseline"}, - {Metrics::SetMetric::ManifestOverrides, "manifest_overrides"}, - {Metrics::SetMetric::ManifestVersionConstraint, "manifest_version_constraint"}, - {Metrics::SetMetric::RegistriesErrorCouldNotFindBaseline, "registries-error-could-not-find-baseline"}, - {Metrics::SetMetric::RegistriesErrorNoVersionsAtCommit, "registries-error-no-versions-at-commit"}, - {Metrics::SetMetric::VcpkgBinarySources, "VCPKG_BINARY_SOURCES"}, - {Metrics::SetMetric::VcpkgDefaultBinaryCache, "VCPKG_DEFAULT_BINARY_CACHE"}, - {Metrics::SetMetric::VcpkgNugetRepository, "VCPKG_NUGET_REPOSITORY"}, - {Metrics::SetMetric::VersioningErrorBaseline, "versioning-error-baseline"}, - {Metrics::SetMetric::VersioningErrorVersion, "versioning-error-version"}, - {Metrics::SetMetric::X_VcpkgRegistriesCache, "X_VCPKG_REGISTRIES_CACHE"}, - {Metrics::SetMetric::X_WriteNugetPackagesConfig, "x-write-nuget-packages-config"}, + static const std::map SET_METRIC_NAMES{ + {Metrics::DefineMetric::AssetSource, "asset-source"}, + {Metrics::DefineMetric::BinaryCachingAws, "binarycaching_aws"}, + {Metrics::DefineMetric::BinaryCachingAzBlob, "binarycaching_azblob"}, + {Metrics::DefineMetric::BinaryCachingCos, "binarycaching_cos"}, + {Metrics::DefineMetric::BinaryCachingDefault, "binarycaching_default"}, + {Metrics::DefineMetric::BinaryCachingFiles, "binarycaching_files"}, + {Metrics::DefineMetric::BinaryCachingGcs, "binarycaching_gcs"}, + {Metrics::DefineMetric::BinaryCachingHttp, "binarycaching_http"}, + {Metrics::DefineMetric::BinaryCachingNuget, "binarycaching_nuget"}, + {Metrics::DefineMetric::BinaryCachingSource, "binarycaching-source"}, + {Metrics::DefineMetric::ErrorVersioningDisabled, "error-versioning-disabled"}, + {Metrics::DefineMetric::ErrorVersioningNoBaseline, "error-versioning-no-baseline"}, + {Metrics::DefineMetric::GitHubRepository, "GITHUB_REPOSITORY"}, + {Metrics::DefineMetric::ManifestBaseline, "manifest_baseline"}, + {Metrics::DefineMetric::ManifestOverrides, "manifest_overrides"}, + {Metrics::DefineMetric::ManifestVersionConstraint, "manifest_version_constraint"}, + {Metrics::DefineMetric::RegistriesErrorCouldNotFindBaseline, "registries-error-could-not-find-baseline"}, + {Metrics::DefineMetric::RegistriesErrorNoVersionsAtCommit, "registries-error-no-versions-at-commit"}, + {Metrics::DefineMetric::VcpkgBinarySources, "VCPKG_BINARY_SOURCES"}, + {Metrics::DefineMetric::VcpkgDefaultBinaryCache, "VCPKG_DEFAULT_BINARY_CACHE"}, + {Metrics::DefineMetric::VcpkgNugetRepository, "VCPKG_NUGET_REPOSITORY"}, + {Metrics::DefineMetric::VersioningErrorBaseline, "versioning-error-baseline"}, + {Metrics::DefineMetric::VersioningErrorVersion, "versioning-error-version"}, + {Metrics::DefineMetric::X_VcpkgRegistriesCache, "X_VCPKG_REGISTRIES_CACHE"}, + {Metrics::DefineMetric::X_WriteNugetPackagesConfig, "x-write-nuget-packages-config"}, }; - static std::map STRING_METRIC_NAMES{ + static const std::map STRING_METRIC_NAMES{ {Metrics::StringMetric::BuildError, "build_error"}, {Metrics::StringMetric::CommandArgs, "command_args"}, {Metrics::StringMetric::CommandContext, "command_context"}, @@ -64,7 +64,7 @@ namespace {Metrics::StringMetric::Warning, "warning"}, }; - static std::map BOOL_METRIC_NAMES = { + static const std::map BOOL_METRIC_NAMES = { {Metrics::BoolMetric::InstallManifestMode, "install_manifest_mode"}, {Metrics::BoolMetric::OptionOverlayPorts, "option_overlay_ports"}, }; @@ -294,19 +294,19 @@ namespace vcpkg g_metricmessage.track_buildtime(name, value); } - void Metrics::track_property(SetMetric metric) + void Metrics::track_property(DefineMetric metric) { - g_metricmessage.track_property(SET_METRIC_NAMES[metric], "defined"); + g_metricmessage.track_property(SET_METRIC_NAMES.at(metric), "defined"); } void Metrics::track_property(StringMetric metric, const std::string& value) { - g_metricmessage.track_property(STRING_METRIC_NAMES[metric], value); + g_metricmessage.track_property(STRING_METRIC_NAMES.at(metric), value); } void Metrics::track_property(BoolMetric metric, bool value) { - g_metricmessage.track_property(BOOL_METRIC_NAMES[metric], value); + g_metricmessage.track_property(BOOL_METRIC_NAMES.at(metric), value); } void Metrics::track_feature(const std::string& name, bool value) { g_metricmessage.track_feature(name, value); } From 2e783edfedb199487b1ee00e05f2fb9dab7a17ce Mon Sep 17 00:00:00 2001 From: Victor Romero Date: Wed, 31 Aug 2022 21:00:41 -0700 Subject: [PATCH 07/14] Add missing metric name --- src/vcpkg/binarycaching.cpp | 24 ++++++++++++------------ src/vcpkg/metrics.cpp | 23 +++++++++++++++++++---- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/vcpkg/binarycaching.cpp b/src/vcpkg/binarycaching.cpp index fd80570ea2..a43ceb0a2f 100644 --- a/src/vcpkg/binarycaching.cpp +++ b/src/vcpkg/binarycaching.cpp @@ -1997,23 +1997,23 @@ namespace return add_error(msg::format(msgUnknownBinaryProviderType), segments[0].first); } + static const std::map metric_names{ + {"aws", Metrics::DefineMetric::BinaryCachingAws}, + {"azblob", Metrics::DefineMetric::BinaryCachingAzBlob}, + {"cos", Metrics::DefineMetric::BinaryCachingCos}, + {"default", Metrics::DefineMetric::BinaryCachingDefault}, + {"files", Metrics::DefineMetric::BinaryCachingFiles}, + {"gcs", Metrics::DefineMetric::BinaryCachingGcs}, + {"http", Metrics::DefineMetric::BinaryCachingHttp}, + {"nuget", Metrics::DefineMetric::BinaryCachingNuget}, + }; + auto metrics = LockGuardPtr(g_metrics); for (const auto& cache_provider : state->binary_cache_providers) { - static const std::map metric_names{ - {"aws", Metrics::DefineMetric::BinaryCachingAws}, - {"azblob", Metrics::DefineMetric::BinaryCachingAzBlob}, - {"cos", Metrics::DefineMetric::BinaryCachingCos}, - {"default", Metrics::DefineMetric::BinaryCachingDefault}, - {"files", Metrics::DefineMetric::BinaryCachingFiles}, - {"gcs", Metrics::DefineMetric::BinaryCachingGcs}, - {"http", Metrics::DefineMetric::BinaryCachingHttp}, - {"nuget", Metrics::DefineMetric::BinaryCachingNuget}, - }; - auto it = metric_names.find(cache_provider); if (it != metric_names.end()) { - LockGuardPtr(g_metrics)->track_property(it->second); + metrics->track_property(it->second); } } } diff --git a/src/vcpkg/metrics.cpp b/src/vcpkg/metrics.cpp index fb30228884..33e49d1d38 100644 --- a/src/vcpkg/metrics.cpp +++ b/src/vcpkg/metrics.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -21,7 +22,7 @@ namespace { using namespace vcpkg; - static const std::map SET_METRIC_NAMES{ + static const std::map DEFINE_METRIC_NAMES{ {Metrics::DefineMetric::AssetSource, "asset-source"}, {Metrics::DefineMetric::BinaryCachingAws, "binarycaching_aws"}, {Metrics::DefineMetric::BinaryCachingAzBlob, "binarycaching_azblob"}, @@ -61,6 +62,7 @@ namespace {Metrics::StringMetric::RegistriesKindsUsed, "registries-kinds-used"}, {Metrics::StringMetric::Title, "title"}, {Metrics::StringMetric::UserMac, "user_mac"}, + {Metrics::StringMetric::VcpkgVersion, "vcpkg_version"}, {Metrics::StringMetric::Warning, "warning"}, }; @@ -68,6 +70,19 @@ namespace {Metrics::BoolMetric::InstallManifestMode, "install_manifest_mode"}, {Metrics::BoolMetric::OptionOverlayPorts, "option_overlay_ports"}, }; + + template + const std::string& get_metric_name(T metric, const std::map& names) + { + auto it = names.find(metric); + if (it != names.end()) + { + return it->second; + } + // All metric enums should have corresponding names + Debug::println("Error: Metric is missing a name"); + Checks::exit_fail(VCPKG_LINE_INFO); + } } namespace vcpkg @@ -296,17 +311,17 @@ namespace vcpkg void Metrics::track_property(DefineMetric metric) { - g_metricmessage.track_property(SET_METRIC_NAMES.at(metric), "defined"); + g_metricmessage.track_property(get_metric_name(metric, DEFINE_METRIC_NAMES), "defined"); } void Metrics::track_property(StringMetric metric, const std::string& value) { - g_metricmessage.track_property(STRING_METRIC_NAMES.at(metric), value); + g_metricmessage.track_property(get_metric_name(metric, STRING_METRIC_NAMES), value); } void Metrics::track_property(BoolMetric metric, bool value) { - g_metricmessage.track_property(BOOL_METRIC_NAMES.at(metric), value); + g_metricmessage.track_property(get_metric_name(metric, BOOL_METRIC_NAMES), value); } void Metrics::track_feature(const std::string& name, bool value) { g_metricmessage.track_feature(name, value); } From e0f287ae10f04f1b931383dc84985f58795405c0 Mon Sep 17 00:00:00 2001 From: Victor Romero Date: Wed, 31 Aug 2022 22:49:39 -0700 Subject: [PATCH 08/14] format --- src/vcpkg.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/vcpkg.cpp b/src/vcpkg.cpp index 852ee4c1e6..21c0e545f6 100644 --- a/src/vcpkg.cpp +++ b/src/vcpkg.cpp @@ -68,7 +68,8 @@ static void inner(vcpkg::Filesystem& fs, const VcpkgCmdArguments& args) } }; - LockGuardPtr(g_metrics)->track_property(Metrics::BoolMetric::OptionOverlayPorts, !args.overlay_ports.empty()); + LockGuardPtr(g_metrics)->track_property(Metrics::BoolMetric::OptionOverlayPorts, + !args.overlay_ports.empty()); if (const auto command_function = find_command(Commands::get_available_basic_commands())) { From 012deb69377e6a43092111f82f378c0e3ec3d089 Mon Sep 17 00:00:00 2001 From: Victor Romero Date: Thu, 1 Sep 2022 16:00:58 -0700 Subject: [PATCH 09/14] Partially address Robert's comments --- CMakeLists.txt | 2 +- include/vcpkg/metrics.h | 25 +++++++- src/vcpkg/metrics.cpp | 134 +++++++++++++++++++++++----------------- 3 files changed, 101 insertions(+), 60 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7cd01f3eb4..dcd7072be8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -119,7 +119,7 @@ endif() set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) if(MSVC) string(APPEND CMAKE_CXX_FLAGS " /EHsc") if(CMAKE_BUILD_TYPE STREQUAL "Release") diff --git a/include/vcpkg/metrics.h b/include/vcpkg/metrics.h index 7022787e39..435a6840d2 100644 --- a/include/vcpkg/metrics.h +++ b/include/vcpkg/metrics.h @@ -8,6 +8,13 @@ namespace vcpkg { + template + struct MetricEntry + { + T metric; + StringLiteral name; + }; + struct Metrics { enum class DefineMetric @@ -36,7 +43,8 @@ namespace vcpkg VersioningErrorBaseline, VersioningErrorVersion, X_VcpkgRegistriesCache, - X_WriteNugetPackagesConfig + X_WriteNugetPackagesConfig, + DefineMetric_COUNT // always keep COUNT last }; enum class StringMetric @@ -53,15 +61,21 @@ namespace vcpkg Title, UserMac, VcpkgVersion, - Warning + Warning, + StringMetric_COUNT // always keep COUNT last }; enum class BoolMetric { InstallManifestMode, - OptionOverlayPorts + OptionOverlayPorts, + BoolMetric_COUNT // always keep COUNT last }; + using enum Metrics::BoolMetric; + using enum Metrics::DefineMetric; + using enum Metrics::StringMetric; + Metrics() = default; Metrics(const Metrics&) = delete; Metrics& operator=(const Metrics&) = delete; @@ -85,6 +99,11 @@ namespace vcpkg void upload(const std::string& payload); void flush(Filesystem& fs); + + // exposed for testing + static constexpr View> get_define_metrics(); + static constexpr View> get_string_metrics(); + static constexpr View> get_bool_metrics(); }; extern LockGuarded g_metrics; diff --git a/src/vcpkg/metrics.cpp b/src/vcpkg/metrics.cpp index 33e49d1d38..db32fd1871 100644 --- a/src/vcpkg/metrics.cpp +++ b/src/vcpkg/metrics.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -22,63 +23,17 @@ namespace { using namespace vcpkg; - static const std::map DEFINE_METRIC_NAMES{ - {Metrics::DefineMetric::AssetSource, "asset-source"}, - {Metrics::DefineMetric::BinaryCachingAws, "binarycaching_aws"}, - {Metrics::DefineMetric::BinaryCachingAzBlob, "binarycaching_azblob"}, - {Metrics::DefineMetric::BinaryCachingCos, "binarycaching_cos"}, - {Metrics::DefineMetric::BinaryCachingDefault, "binarycaching_default"}, - {Metrics::DefineMetric::BinaryCachingFiles, "binarycaching_files"}, - {Metrics::DefineMetric::BinaryCachingGcs, "binarycaching_gcs"}, - {Metrics::DefineMetric::BinaryCachingHttp, "binarycaching_http"}, - {Metrics::DefineMetric::BinaryCachingNuget, "binarycaching_nuget"}, - {Metrics::DefineMetric::BinaryCachingSource, "binarycaching-source"}, - {Metrics::DefineMetric::ErrorVersioningDisabled, "error-versioning-disabled"}, - {Metrics::DefineMetric::ErrorVersioningNoBaseline, "error-versioning-no-baseline"}, - {Metrics::DefineMetric::GitHubRepository, "GITHUB_REPOSITORY"}, - {Metrics::DefineMetric::ManifestBaseline, "manifest_baseline"}, - {Metrics::DefineMetric::ManifestOverrides, "manifest_overrides"}, - {Metrics::DefineMetric::ManifestVersionConstraint, "manifest_version_constraint"}, - {Metrics::DefineMetric::RegistriesErrorCouldNotFindBaseline, "registries-error-could-not-find-baseline"}, - {Metrics::DefineMetric::RegistriesErrorNoVersionsAtCommit, "registries-error-no-versions-at-commit"}, - {Metrics::DefineMetric::VcpkgBinarySources, "VCPKG_BINARY_SOURCES"}, - {Metrics::DefineMetric::VcpkgDefaultBinaryCache, "VCPKG_DEFAULT_BINARY_CACHE"}, - {Metrics::DefineMetric::VcpkgNugetRepository, "VCPKG_NUGET_REPOSITORY"}, - {Metrics::DefineMetric::VersioningErrorBaseline, "versioning-error-baseline"}, - {Metrics::DefineMetric::VersioningErrorVersion, "versioning-error-version"}, - {Metrics::DefineMetric::X_VcpkgRegistriesCache, "X_VCPKG_REGISTRIES_CACHE"}, - {Metrics::DefineMetric::X_WriteNugetPackagesConfig, "x-write-nuget-packages-config"}, - }; - - static const std::map STRING_METRIC_NAMES{ - {Metrics::StringMetric::BuildError, "build_error"}, - {Metrics::StringMetric::CommandArgs, "command_args"}, - {Metrics::StringMetric::CommandContext, "command_context"}, - {Metrics::StringMetric::CommandName, "command_name"}, - {Metrics::StringMetric::Error, "error"}, - {Metrics::StringMetric::InstallPlan_1, "installplan_1"}, - {Metrics::StringMetric::ListFile, "listfile"}, - {Metrics::StringMetric::RegistriesDefaultRegistryKind, "registries-default-registry-kind"}, - {Metrics::StringMetric::RegistriesKindsUsed, "registries-kinds-used"}, - {Metrics::StringMetric::Title, "title"}, - {Metrics::StringMetric::UserMac, "user_mac"}, - {Metrics::StringMetric::VcpkgVersion, "vcpkg_version"}, - {Metrics::StringMetric::Warning, "warning"}, - }; - - static const std::map BOOL_METRIC_NAMES = { - {Metrics::BoolMetric::InstallManifestMode, "install_manifest_mode"}, - {Metrics::BoolMetric::OptionOverlayPorts, "option_overlay_ports"}, - }; - template - const std::string& get_metric_name(T metric, const std::map& names) + StringLiteral get_metric_name(const T metric, View> entries) { - auto it = names.find(metric); - if (it != names.end()) + for (auto&& entry : entries) { - return it->second; + if (entry.metric == metric) + { + return entry.name; + } } + // All metric enums should have corresponding names Debug::println("Error: Metric is missing a name"); Checks::exit_fail(VCPKG_LINE_INFO); @@ -89,6 +44,73 @@ namespace vcpkg { LockGuarded g_metrics; + constexpr View> Metrics::get_define_metrics() + { + constexpr std::array, static_cast(Metrics::DefineMetric_COUNT)> + ENTRIES{ + MetricEntry{Metrics::AssetSource, "asset-source"}, + MetricEntry{Metrics::BinaryCachingAws, "binarycaching_aws"}, + MetricEntry{Metrics::BinaryCachingAzBlob, "binarycaching_azblob"}, + MetricEntry{Metrics::BinaryCachingCos, "binarycaching_cos"}, + MetricEntry{Metrics::BinaryCachingDefault, "binarycaching_default"}, + MetricEntry{Metrics::BinaryCachingFiles, "binarycaching_files"}, + MetricEntry{Metrics::BinaryCachingGcs, "binarycaching_gcs"}, + MetricEntry{Metrics::BinaryCachingHttp, "binarycaching_http"}, + MetricEntry{Metrics::BinaryCachingNuget, "binarycaching_nuget"}, + MetricEntry{Metrics::BinaryCachingSource, "binarycaching-source"}, + MetricEntry{Metrics::ErrorVersioningDisabled, "error-versioning-disabled"}, + MetricEntry{Metrics::ErrorVersioningNoBaseline, "error-versioning-no-baseline"}, + MetricEntry{Metrics::GitHubRepository, "GITHUB_REPOSITORY"}, + MetricEntry{Metrics::ManifestBaseline, "manifest_baseline"}, + MetricEntry{Metrics::ManifestOverrides, "manifest_overrides"}, + MetricEntry{Metrics::ManifestVersionConstraint, "manifest_version_constraint"}, + MetricEntry{Metrics::RegistriesErrorCouldNotFindBaseline, + "registries-error-could-not-find-baseline"}, + MetricEntry{Metrics::RegistriesErrorNoVersionsAtCommit, + "registries-error-no-versions-at-commit"}, + MetricEntry{Metrics::VcpkgBinarySources, "VCPKG_BINARY_SOURCES"}, + MetricEntry{Metrics::VcpkgDefaultBinaryCache, "VCPKG_DEFAULT_BINARY_CACHE"}, + MetricEntry{Metrics::VcpkgNugetRepository, "VCPKG_NUGET_REPOSITORY"}, + MetricEntry{Metrics::VersioningErrorBaseline, "versioning-error-baseline"}, + MetricEntry{Metrics::VersioningErrorVersion, "versioning-error-version"}, + MetricEntry{Metrics::X_VcpkgRegistriesCache, "X_VCPKG_REGISTRIES_CACHE"}, + MetricEntry{Metrics::X_WriteNugetPackagesConfig, + "x-write-nuget-packages-config"}, + }; + return {ENTRIES.data(), ENTRIES.size()}; + } + + constexpr View> Metrics::get_string_metrics() + { + constexpr std::array, static_cast(Metrics::StringMetric_COUNT)> + ENTRIES{ + MetricEntry{Metrics::BuildError, "build_error"}, + MetricEntry{Metrics::CommandArgs, "command_args"}, + MetricEntry{Metrics::CommandContext, "command_context"}, + MetricEntry{Metrics::CommandName, "command_name"}, + MetricEntry{Metrics::Error, "error"}, + MetricEntry{Metrics::InstallPlan_1, "installplan_1"}, + MetricEntry{Metrics::ListFile, "listfile"}, + MetricEntry{Metrics::RegistriesDefaultRegistryKind, + "registries-default-registry-kind"}, + MetricEntry{Metrics::RegistriesKindsUsed, "registries-kinds-used"}, + MetricEntry{Metrics::Title, "title"}, + MetricEntry{Metrics::UserMac, "user_mac"}, + MetricEntry{Metrics::VcpkgVersion, "vcpkg_version"}, + MetricEntry{Metrics::Warning, "warning"}, + }; + return {ENTRIES.data(), ENTRIES.size()}; + } + + constexpr View> Metrics::get_bool_metrics() + { + constexpr std::array, static_cast(Metrics::BoolMetric_COUNT)> ENTRIES{ + MetricEntry{Metrics::InstallManifestMode, "install_manifest_mode"}, + MetricEntry{Metrics::OptionOverlayPorts, "option_overlay_ports"}, + }; + return {ENTRIES.data(), ENTRIES.size()}; + } + static std::string get_current_date_time_string() { auto maybe_time = CTime::get_current_date_time(); @@ -311,17 +333,17 @@ namespace vcpkg void Metrics::track_property(DefineMetric metric) { - g_metricmessage.track_property(get_metric_name(metric, DEFINE_METRIC_NAMES), "defined"); + g_metricmessage.track_property(get_metric_name(metric, get_define_metrics()), "defined"); } void Metrics::track_property(StringMetric metric, const std::string& value) { - g_metricmessage.track_property(get_metric_name(metric, STRING_METRIC_NAMES), value); + g_metricmessage.track_property(get_metric_name(metric, get_string_metrics()), value); } void Metrics::track_property(BoolMetric metric, bool value) { - g_metricmessage.track_property(get_metric_name(metric, BOOL_METRIC_NAMES), value); + g_metricmessage.track_property(get_metric_name(metric, get_bool_metrics()), value); } void Metrics::track_feature(const std::string& name, bool value) { g_metricmessage.track_feature(name, value); } From a5316e5b78fd55412de7cfdb80b0bd4ce020dcee Mon Sep 17 00:00:00 2001 From: Victor Romero Date: Thu, 1 Sep 2022 16:08:52 -0700 Subject: [PATCH 10/14] Change `track_property()` call sites --- CMakeLists.txt | 2 +- include/vcpkg/metrics.h | 120 ++++++++++++++-------------- src/vcpkg.cpp | 13 ++- src/vcpkg/binarycaching.cpp | 30 +++---- src/vcpkg/build.cpp | 4 +- src/vcpkg/commands.add.cpp | 8 +- src/vcpkg/commands.find.cpp | 8 +- src/vcpkg/commands.integrate.cpp | 4 +- src/vcpkg/commands.setinstalled.cpp | 2 +- src/vcpkg/input.cpp | 3 +- src/vcpkg/install.cpp | 12 +-- src/vcpkg/metrics.cpp | 106 ++++++++++++------------ src/vcpkg/portfileprovider.cpp | 2 +- src/vcpkg/registries.cpp | 12 +-- src/vcpkg/sourceparagraph.cpp | 11 ++- src/vcpkg/vcpkgcmdarguments.cpp | 17 ++-- src/vcpkg/vcpkglib.cpp | 2 +- src/vcpkg/vcpkgpaths.cpp | 12 +-- 18 files changed, 175 insertions(+), 193 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dcd7072be8..7cd01f3eb4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -119,7 +119,7 @@ endif() set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD 17) if(MSVC) string(APPEND CMAKE_CXX_FLAGS " /EHsc") if(CMAKE_BUILD_TYPE STREQUAL "Release") diff --git a/include/vcpkg/metrics.h b/include/vcpkg/metrics.h index 435a6840d2..354d73ffdf 100644 --- a/include/vcpkg/metrics.h +++ b/include/vcpkg/metrics.h @@ -15,67 +15,63 @@ namespace vcpkg StringLiteral name; }; - struct Metrics + enum class DefineMetric + { + AssetSource, + BinaryCachingAws, + BinaryCachingAzBlob, + BinaryCachingCos, + BinaryCachingDefault, + BinaryCachingFiles, + BinaryCachingGcs, + BinaryCachingHttp, + BinaryCachingNuget, + BinaryCachingSource, + ErrorVersioningDisabled, + ErrorVersioningNoBaseline, + GitHubRepository, + ManifestBaseline, + ManifestOverrides, + ManifestVersionConstraint, + RegistriesErrorCouldNotFindBaseline, + RegistriesErrorNoVersionsAtCommit, + VcpkgBinarySources, + VcpkgDefaultBinaryCache, + VcpkgNugetRepository, + VersioningErrorBaseline, + VersioningErrorVersion, + X_VcpkgRegistriesCache, + X_WriteNugetPackagesConfig, + _COUNT // always keep COUNT last + }; + + enum class StringMetric + { + BuildError, + CommandArgs, + CommandContext, + CommandName, + Error, + InstallPlan_1, + ListFile, + RegistriesDefaultRegistryKind, + RegistriesKindsUsed, + Title, + UserMac, + VcpkgVersion, + Warning, + _COUNT // always keep COUNT last + }; + + enum class BoolMetric { - enum class DefineMetric - { - AssetSource, - BinaryCachingAws, - BinaryCachingAzBlob, - BinaryCachingCos, - BinaryCachingDefault, - BinaryCachingFiles, - BinaryCachingGcs, - BinaryCachingHttp, - BinaryCachingNuget, - BinaryCachingSource, - ErrorVersioningDisabled, - ErrorVersioningNoBaseline, - GitHubRepository, - ManifestBaseline, - ManifestOverrides, - ManifestVersionConstraint, - RegistriesErrorCouldNotFindBaseline, - RegistriesErrorNoVersionsAtCommit, - VcpkgBinarySources, - VcpkgDefaultBinaryCache, - VcpkgNugetRepository, - VersioningErrorBaseline, - VersioningErrorVersion, - X_VcpkgRegistriesCache, - X_WriteNugetPackagesConfig, - DefineMetric_COUNT // always keep COUNT last - }; - - enum class StringMetric - { - BuildError, - CommandArgs, - CommandContext, - CommandName, - Error, - InstallPlan_1, - ListFile, - RegistriesDefaultRegistryKind, - RegistriesKindsUsed, - Title, - UserMac, - VcpkgVersion, - Warning, - StringMetric_COUNT // always keep COUNT last - }; - - enum class BoolMetric - { - InstallManifestMode, - OptionOverlayPorts, - BoolMetric_COUNT // always keep COUNT last - }; - - using enum Metrics::BoolMetric; - using enum Metrics::DefineMetric; - using enum Metrics::StringMetric; + InstallManifestMode, + OptionOverlayPorts, + _COUNT // always keep COUNT last + }; + struct Metrics + { Metrics() = default; Metrics(const Metrics&) = delete; Metrics& operator=(const Metrics&) = delete; @@ -101,9 +97,9 @@ namespace vcpkg void flush(Filesystem& fs); // exposed for testing - static constexpr View> get_define_metrics(); - static constexpr View> get_string_metrics(); - static constexpr View> get_bool_metrics(); + static View> get_define_metrics(); + static View> get_string_metrics(); + static View> get_bool_metrics(); }; extern LockGuarded g_metrics; diff --git a/src/vcpkg.cpp b/src/vcpkg.cpp index 21c0e545f6..2f18a7620a 100644 --- a/src/vcpkg.cpp +++ b/src/vcpkg.cpp @@ -44,7 +44,7 @@ static void invalid_command(const std::string& cmd) static void inner(vcpkg::Filesystem& fs, const VcpkgCmdArguments& args) { // track version on each invocation - LockGuardPtr(g_metrics)->track_property(Metrics::StringMetric::VcpkgVersion, + LockGuardPtr(g_metrics)->track_property(StringMetric::VcpkgVersion, Commands::Version::version.to_string()); if (args.command.empty()) @@ -68,12 +68,11 @@ static void inner(vcpkg::Filesystem& fs, const VcpkgCmdArguments& args) } }; - LockGuardPtr(g_metrics)->track_property(Metrics::BoolMetric::OptionOverlayPorts, - !args.overlay_ports.empty()); + LockGuardPtr(g_metrics)->track_property(BoolMetric::OptionOverlayPorts, !args.overlay_ports.empty()); if (const auto command_function = find_command(Commands::get_available_basic_commands())) { - LockGuardPtr(g_metrics)->track_property(Metrics::StringMetric::CommandName, command_function->name); + LockGuardPtr(g_metrics)->track_property(StringMetric::CommandName, command_function->name); return command_function->function->perform_and_exit(args, fs); } @@ -84,7 +83,7 @@ static void inner(vcpkg::Filesystem& fs, const VcpkgCmdArguments& args) if (const auto command_function = find_command(Commands::get_available_paths_commands())) { - LockGuardPtr(g_metrics)->track_property(Metrics::StringMetric::CommandName, command_function->name); + LockGuardPtr(g_metrics)->track_property(StringMetric::CommandName, command_function->name); return command_function->function->perform_and_exit(args, paths); } @@ -95,7 +94,7 @@ static void inner(vcpkg::Filesystem& fs, const VcpkgCmdArguments& args) if (const auto command_function = find_command(Commands::get_available_triplet_commands())) { - LockGuardPtr(g_metrics)->track_property(Metrics::StringMetric::CommandName, command_function->name); + LockGuardPtr(g_metrics)->track_property(StringMetric::CommandName, command_function->name); return command_function->function->perform_and_exit(args, paths, default_triplet, host_triplet); } @@ -318,7 +317,7 @@ int main(const int argc, const char* const* const argv) exc_msg = "unknown error(...)"; } - LockGuardPtr(g_metrics)->track_property(Metrics::StringMetric::Error, exc_msg); + LockGuardPtr(g_metrics)->track_property(StringMetric::Error, exc_msg); fflush(stdout); msg::println(msgVcpkgHasCrashed); diff --git a/src/vcpkg/binarycaching.cpp b/src/vcpkg/binarycaching.cpp index a43ceb0a2f..6d3847cf88 100644 --- a/src/vcpkg/binarycaching.cpp +++ b/src/vcpkg/binarycaching.cpp @@ -1579,7 +1579,7 @@ namespace auto maybe_cachepath = get_environment_variable("VCPKG_DEFAULT_BINARY_CACHE"); if (auto p_str = maybe_cachepath.get()) { - LockGuardPtr(g_metrics)->track_property(Metrics::DefineMetric::VcpkgDefaultBinaryCache); + LockGuardPtr(g_metrics)->track_property(DefineMetric::VcpkgDefaultBinaryCache); Path path = *p_str; path.make_preferred(); if (!get_real_filesystem().is_directory(path)) @@ -1997,15 +1997,15 @@ namespace return add_error(msg::format(msgUnknownBinaryProviderType), segments[0].first); } - static const std::map metric_names{ - {"aws", Metrics::DefineMetric::BinaryCachingAws}, - {"azblob", Metrics::DefineMetric::BinaryCachingAzBlob}, - {"cos", Metrics::DefineMetric::BinaryCachingCos}, - {"default", Metrics::DefineMetric::BinaryCachingDefault}, - {"files", Metrics::DefineMetric::BinaryCachingFiles}, - {"gcs", Metrics::DefineMetric::BinaryCachingGcs}, - {"http", Metrics::DefineMetric::BinaryCachingHttp}, - {"nuget", Metrics::DefineMetric::BinaryCachingNuget}, + static const std::map metric_names{ + {"aws", DefineMetric::BinaryCachingAws}, + {"azblob", DefineMetric::BinaryCachingAzBlob}, + {"cos", DefineMetric::BinaryCachingCos}, + {"default", DefineMetric::BinaryCachingDefault}, + {"files", DefineMetric::BinaryCachingFiles}, + {"gcs", DefineMetric::BinaryCachingGcs}, + {"http", DefineMetric::BinaryCachingHttp}, + {"nuget", DefineMetric::BinaryCachingNuget}, }; auto metrics = LockGuardPtr(g_metrics); for (const auto& cache_provider : state->binary_cache_providers) @@ -2147,7 +2147,7 @@ ExpectedS vcpkg::parse_download_configuration(const Optio { if (!arg || arg.get()->empty()) return DownloadManagerConfig{}; - LockGuardPtr(g_metrics)->track_property(Metrics::DefineMetric::AssetSource); + LockGuardPtr(g_metrics)->track_property(DefineMetric::AssetSource); AssetSourcesState s; AssetSourcesParser parser(*arg.get(), Strings::concat("$", VcpkgCmdArguments::ASSET_SOURCES_ENV), &s); @@ -2202,12 +2202,12 @@ ExpectedS vcpkg::create_binary_providers_from_configs_p LockGuardPtr metrics(g_metrics); if (!env_string.empty()) { - metrics->track_property(Metrics::DefineMetric::VcpkgBinarySources); + metrics->track_property(DefineMetric::VcpkgBinarySources); } if (args.size() != 0) { - metrics->track_property(Metrics::DefineMetric::BinaryCachingSource); + metrics->track_property(DefineMetric::BinaryCachingSource); } } @@ -2346,7 +2346,7 @@ details::NuGetRepoInfo details::get_nuget_repo_info_from_env() auto vcpkg_nuget_repository = get_environment_variable("VCPKG_NUGET_REPOSITORY"); if (auto p = vcpkg_nuget_repository.get()) { - LockGuardPtr(g_metrics)->track_property(Metrics::DefineMetric::VcpkgNugetRepository); + LockGuardPtr(g_metrics)->track_property(DefineMetric::VcpkgNugetRepository); return {std::move(*p)}; } @@ -2362,7 +2362,7 @@ details::NuGetRepoInfo details::get_nuget_repo_info_from_env() return {}; } - LockGuardPtr(g_metrics)->track_property(Metrics::DefineMetric::GitHubRepository); + LockGuardPtr(g_metrics)->track_property(DefineMetric::GitHubRepository); return {Strings::concat(gh_server, '/', gh_repo, ".git"), get_environment_variable("GITHUB_REF").value_or(""), get_environment_variable("GITHUB_SHA").value_or("")}; diff --git a/src/vcpkg/build.cpp b/src/vcpkg/build.cpp index afa066061c..c2ab3f8347 100644 --- a/src/vcpkg/build.cpp +++ b/src/vcpkg/build.cpp @@ -947,8 +947,8 @@ namespace vcpkg buildtimeus); if (!succeeded(return_code)) { - metrics->track_property(Metrics::StringMetric::Error, "build failed"); - metrics->track_property(Metrics::StringMetric::BuildError, spec_string); + metrics->track_property(StringMetric::Error, "build failed"); + metrics->track_property(StringMetric::BuildError, spec_string); const auto logs = buildpath / Strings::concat("error-logs-", action.spec.triplet(), ".txt"); std::vector error_logs; if (fs.exists(logs, VCPKG_LINE_INFO)) diff --git a/src/vcpkg/commands.add.cpp b/src/vcpkg/commands.add.cpp index 4d150435cc..e8b8f120fd 100644 --- a/src/vcpkg/commands.add.cpp +++ b/src/vcpkg/commands.add.cpp @@ -46,8 +46,8 @@ namespace vcpkg::Commands auto artifact_hash = Hash::get_string_hash(artifact_name, Hash::Algorithm::Sha256); { auto metrics = LockGuardPtr(g_metrics); - metrics->track_property(Metrics::StringMetric::CommandContext, "artifact"); - metrics->track_property(Metrics::StringMetric::CommandArgs, artifact_hash); + metrics->track_property(StringMetric::CommandContext, "artifact"); + metrics->track_property(StringMetric::CommandArgs, artifact_hash); } // unlock g_metrics std::string ce_args[] = {"add", artifact_name}; @@ -122,8 +122,8 @@ namespace vcpkg::Commands })); { auto metrics = LockGuardPtr(g_metrics); - metrics->track_property(Metrics::StringMetric::CommandContext, "port"); - metrics->track_property(Metrics::StringMetric::CommandArgs, command_args_hash); + metrics->track_property(StringMetric::CommandContext, "port"); + metrics->track_property(StringMetric::CommandArgs, command_args_hash); } // unlock metrics Checks::exit_success(VCPKG_LINE_INFO); diff --git a/src/vcpkg/commands.find.cpp b/src/vcpkg/commands.find.cpp index 4ed7c92407..800bde3315 100644 --- a/src/vcpkg/commands.find.cpp +++ b/src/vcpkg/commands.find.cpp @@ -237,10 +237,10 @@ namespace vcpkg::Commands auto args_hash = Hash::get_string_hash(filter.value_or_exit(VCPKG_LINE_INFO), Hash::Algorithm::Sha256); { auto metrics = LockGuardPtr(g_metrics); - metrics->track_property(Metrics::StringMetric::CommandContext, "artifact"); + metrics->track_property(StringMetric::CommandContext, "artifact"); if (auto p_filter_hash = filter_hash.get()) { - metrics->track_property(Metrics::StringMetric::CommandArgs, *p_filter_hash); + metrics->track_property(StringMetric::CommandArgs, *p_filter_hash); } } // unlock metrics @@ -252,10 +252,10 @@ namespace vcpkg::Commands Optional filter_hash = filter.map(Hash::get_string_sha256); { auto metrics = LockGuardPtr(g_metrics); - metrics->track_property(Metrics::StringMetric::CommandContext, "port"); + metrics->track_property(StringMetric::CommandContext, "port"); if (auto p_filter_hash = filter_hash.get()) { - metrics->track_property(Metrics::StringMetric::CommandArgs, *p_filter_hash); + metrics->track_property(StringMetric::CommandArgs, *p_filter_hash); } } // unlock metrics diff --git a/src/vcpkg/commands.integrate.cpp b/src/vcpkg/commands.integrate.cpp index e666258d69..62308af6c4 100644 --- a/src/vcpkg/commands.integrate.cpp +++ b/src/vcpkg/commands.integrate.cpp @@ -472,8 +472,8 @@ namespace vcpkg::Commands::Integrate .append_raw("\n" + script_path.generic_u8string())); { auto locked_metrics = LockGuardPtr(g_metrics); - locked_metrics->track_property(Metrics::StringMetric::Error, "powershell script failed"); - locked_metrics->track_property(Metrics::StringMetric::Title, TITLE.to_string()); + locked_metrics->track_property(StringMetric::Error, "powershell script failed"); + locked_metrics->track_property(StringMetric::Title, TITLE.to_string()); } } diff --git a/src/vcpkg/commands.setinstalled.cpp b/src/vcpkg/commands.setinstalled.cpp index af2931818b..9b14e943a7 100644 --- a/src/vcpkg/commands.setinstalled.cpp +++ b/src/vcpkg/commands.setinstalled.cpp @@ -164,7 +164,7 @@ namespace vcpkg::Commands::SetInstalled auto it_pkgsconfig = options.settings.find(OPTION_WRITE_PACKAGES_CONFIG); if (it_pkgsconfig != options.settings.end()) { - LockGuardPtr(g_metrics)->track_property(Metrics::DefineMetric::X_WriteNugetPackagesConfig); + LockGuardPtr(g_metrics)->track_property(DefineMetric::X_WriteNugetPackagesConfig); pkgsconfig = it_pkgsconfig->second; } diff --git a/src/vcpkg/input.cpp b/src/vcpkg/input.cpp index c44aa3a5f6..1f07992b54 100644 --- a/src/vcpkg/input.cpp +++ b/src/vcpkg/input.cpp @@ -35,8 +35,7 @@ namespace vcpkg if (!paths.is_valid_triplet(t)) { print2(Color::error, "Error: invalid triplet: ", t, '\n'); - LockGuardPtr(g_metrics)->track_property(Metrics::StringMetric::Error, - "invalid triplet: " + t.to_string()); + LockGuardPtr(g_metrics)->track_property(StringMetric::Error, "invalid triplet: " + t.to_string()); Help::help_topic_valid_triplet(paths); Checks::exit_fail(VCPKG_LINE_INFO); } diff --git a/src/vcpkg/install.cpp b/src/vcpkg/install.cpp index 5970d74fa0..608dc2de87 100644 --- a/src/vcpkg/install.cpp +++ b/src/vcpkg/install.cpp @@ -875,7 +875,7 @@ namespace vcpkg : UnsupportedPortAction::Error; const bool no_print_usage = Util::Sets::contains(options.switches, OPTION_NO_PRINT_USAGE); - LockGuardPtr(g_metrics)->track_property(Metrics::BoolMetric::InstallManifestMode, + LockGuardPtr(g_metrics)->track_property(BoolMetric::InstallManifestMode, paths.manifest_mode_enabled()); if (auto p = paths.get_manifest().get()) @@ -966,7 +966,7 @@ namespace vcpkg auto it_pkgsconfig = options.settings.find(OPTION_WRITE_PACKAGES_CONFIG); if (it_pkgsconfig != options.settings.end()) { - LockGuardPtr(g_metrics)->track_property(Metrics::DefineMetric::X_WriteNugetPackagesConfig); + LockGuardPtr(g_metrics)->track_property(DefineMetric::X_WriteNugetPackagesConfig); pkgsconfig = Path(it_pkgsconfig->second); } auto maybe_manifest_scf = @@ -1034,12 +1034,12 @@ namespace vcpkg return dep.constraint.type != VersionConstraintKind::None; })) { - LockGuardPtr(g_metrics)->track_property(Metrics::DefineMetric::ManifestVersionConstraint); + LockGuardPtr(g_metrics)->track_property(DefineMetric::ManifestVersionConstraint); } if (!manifest_core.overrides.empty()) { - LockGuardPtr(g_metrics)->track_property(Metrics::DefineMetric::ManifestOverrides); + LockGuardPtr(g_metrics)->track_property(DefineMetric::ManifestOverrides); } auto verprovider = make_versioned_portfile_provider(paths); @@ -1169,7 +1169,7 @@ namespace vcpkg auto it_pkgsconfig = options.settings.find(OPTION_WRITE_PACKAGES_CONFIG); if (it_pkgsconfig != options.settings.end()) { - LockGuardPtr(g_metrics)->track_property(Metrics::DefineMetric::X_WriteNugetPackagesConfig); + LockGuardPtr(g_metrics)->track_property(DefineMetric::X_WriteNugetPackagesConfig); compute_all_abis(paths, action_plan, var_provider, status_db); auto pkgsconfig_path = paths.original_cwd / it_pkgsconfig->second; @@ -1318,6 +1318,6 @@ namespace vcpkg Hash::get_string_hash(version_as_string, Hash::Algorithm::Sha256)); } - LockGuardPtr(g_metrics)->track_property(Metrics::StringMetric::InstallPlan_1, specs_string); + LockGuardPtr(g_metrics)->track_property(StringMetric::InstallPlan_1, specs_string); } } diff --git a/src/vcpkg/metrics.cpp b/src/vcpkg/metrics.cpp index db32fd1871..d97253502b 100644 --- a/src/vcpkg/metrics.cpp +++ b/src/vcpkg/metrics.cpp @@ -44,70 +44,64 @@ namespace vcpkg { LockGuarded g_metrics; - constexpr View> Metrics::get_define_metrics() + View> Metrics::get_define_metrics() { - constexpr std::array, static_cast(Metrics::DefineMetric_COUNT)> - ENTRIES{ - MetricEntry{Metrics::AssetSource, "asset-source"}, - MetricEntry{Metrics::BinaryCachingAws, "binarycaching_aws"}, - MetricEntry{Metrics::BinaryCachingAzBlob, "binarycaching_azblob"}, - MetricEntry{Metrics::BinaryCachingCos, "binarycaching_cos"}, - MetricEntry{Metrics::BinaryCachingDefault, "binarycaching_default"}, - MetricEntry{Metrics::BinaryCachingFiles, "binarycaching_files"}, - MetricEntry{Metrics::BinaryCachingGcs, "binarycaching_gcs"}, - MetricEntry{Metrics::BinaryCachingHttp, "binarycaching_http"}, - MetricEntry{Metrics::BinaryCachingNuget, "binarycaching_nuget"}, - MetricEntry{Metrics::BinaryCachingSource, "binarycaching-source"}, - MetricEntry{Metrics::ErrorVersioningDisabled, "error-versioning-disabled"}, - MetricEntry{Metrics::ErrorVersioningNoBaseline, "error-versioning-no-baseline"}, - MetricEntry{Metrics::GitHubRepository, "GITHUB_REPOSITORY"}, - MetricEntry{Metrics::ManifestBaseline, "manifest_baseline"}, - MetricEntry{Metrics::ManifestOverrides, "manifest_overrides"}, - MetricEntry{Metrics::ManifestVersionConstraint, "manifest_version_constraint"}, - MetricEntry{Metrics::RegistriesErrorCouldNotFindBaseline, - "registries-error-could-not-find-baseline"}, - MetricEntry{Metrics::RegistriesErrorNoVersionsAtCommit, - "registries-error-no-versions-at-commit"}, - MetricEntry{Metrics::VcpkgBinarySources, "VCPKG_BINARY_SOURCES"}, - MetricEntry{Metrics::VcpkgDefaultBinaryCache, "VCPKG_DEFAULT_BINARY_CACHE"}, - MetricEntry{Metrics::VcpkgNugetRepository, "VCPKG_NUGET_REPOSITORY"}, - MetricEntry{Metrics::VersioningErrorBaseline, "versioning-error-baseline"}, - MetricEntry{Metrics::VersioningErrorVersion, "versioning-error-version"}, - MetricEntry{Metrics::X_VcpkgRegistriesCache, "X_VCPKG_REGISTRIES_CACHE"}, - MetricEntry{Metrics::X_WriteNugetPackagesConfig, - "x-write-nuget-packages-config"}, - }; + static constexpr std::array, static_cast(DefineMetric::_COUNT)> ENTRIES{{ + {DefineMetric::AssetSource, "asset-source"}, + {DefineMetric::BinaryCachingAws, "binarycaching_aws"}, + {DefineMetric::BinaryCachingAzBlob, "binarycaching_azblob"}, + {DefineMetric::BinaryCachingCos, "binarycaching_cos"}, + {DefineMetric::BinaryCachingDefault, "binarycaching_default"}, + {DefineMetric::BinaryCachingFiles, "binarycaching_files"}, + {DefineMetric::BinaryCachingGcs, "binarycaching_gcs"}, + {DefineMetric::BinaryCachingHttp, "binarycaching_http"}, + {DefineMetric::BinaryCachingNuget, "binarycaching_nuget"}, + {DefineMetric::BinaryCachingSource, "binarycaching-source"}, + {DefineMetric::ErrorVersioningDisabled, "error-versioning-disabled"}, + {DefineMetric::ErrorVersioningNoBaseline, "error-versioning-no-baseline"}, + {DefineMetric::GitHubRepository, "GITHUB_REPOSITORY"}, + {DefineMetric::ManifestBaseline, "manifest_baseline"}, + {DefineMetric::ManifestOverrides, "manifest_overrides"}, + {DefineMetric::ManifestVersionConstraint, "manifest_version_constraint"}, + {DefineMetric::RegistriesErrorCouldNotFindBaseline, "registries-error-could-not-find-baseline"}, + {DefineMetric::RegistriesErrorNoVersionsAtCommit, "registries-error-no-versions-at-commit"}, + {DefineMetric::VcpkgBinarySources, "VCPKG_BINARY_SOURCES"}, + {DefineMetric::VcpkgDefaultBinaryCache, "VCPKG_DEFAULT_BINARY_CACHE"}, + {DefineMetric::VcpkgNugetRepository, "VCPKG_NUGET_REPOSITORY"}, + {DefineMetric::VersioningErrorBaseline, "versioning-error-baseline"}, + {DefineMetric::VersioningErrorVersion, "versioning-error-version"}, + {DefineMetric::X_VcpkgRegistriesCache, "X_VCPKG_REGISTRIES_CACHE"}, + {DefineMetric::X_WriteNugetPackagesConfig, "x-write-nuget-packages-config"}, + }}; return {ENTRIES.data(), ENTRIES.size()}; } - constexpr View> Metrics::get_string_metrics() + View> Metrics::get_string_metrics() { - constexpr std::array, static_cast(Metrics::StringMetric_COUNT)> - ENTRIES{ - MetricEntry{Metrics::BuildError, "build_error"}, - MetricEntry{Metrics::CommandArgs, "command_args"}, - MetricEntry{Metrics::CommandContext, "command_context"}, - MetricEntry{Metrics::CommandName, "command_name"}, - MetricEntry{Metrics::Error, "error"}, - MetricEntry{Metrics::InstallPlan_1, "installplan_1"}, - MetricEntry{Metrics::ListFile, "listfile"}, - MetricEntry{Metrics::RegistriesDefaultRegistryKind, - "registries-default-registry-kind"}, - MetricEntry{Metrics::RegistriesKindsUsed, "registries-kinds-used"}, - MetricEntry{Metrics::Title, "title"}, - MetricEntry{Metrics::UserMac, "user_mac"}, - MetricEntry{Metrics::VcpkgVersion, "vcpkg_version"}, - MetricEntry{Metrics::Warning, "warning"}, - }; + static constexpr std::array, static_cast(StringMetric::_COUNT)> ENTRIES{{ + {StringMetric::BuildError, "build_error"}, + {StringMetric::CommandArgs, "command_args"}, + {StringMetric::CommandContext, "command_context"}, + {StringMetric::CommandName, "command_name"}, + {StringMetric::Error, "error"}, + {StringMetric::InstallPlan_1, "installplan_1"}, + {StringMetric::ListFile, "listfile"}, + {StringMetric::RegistriesDefaultRegistryKind, "registries-default-registry-kind"}, + {StringMetric::RegistriesKindsUsed, "registries-kinds-used"}, + {StringMetric::Title, "title"}, + {StringMetric::UserMac, "user_mac"}, + {StringMetric::VcpkgVersion, "vcpkg_version"}, + {StringMetric::Warning, "warning"}, + }}; return {ENTRIES.data(), ENTRIES.size()}; } - constexpr View> Metrics::get_bool_metrics() + View> Metrics::get_bool_metrics() { - constexpr std::array, static_cast(Metrics::BoolMetric_COUNT)> ENTRIES{ - MetricEntry{Metrics::InstallManifestMode, "install_manifest_mode"}, - MetricEntry{Metrics::OptionOverlayPorts, "option_overlay_ports"}, - }; + static constexpr std::array, static_cast(BoolMetric::_COUNT)> ENTRIES{{ + {BoolMetric::InstallManifestMode, "install_manifest_mode"}, + {BoolMetric::OptionOverlayPorts, "option_overlay_ports"}, + }}; return {ENTRIES.data(), ENTRIES.size()}; } @@ -316,7 +310,7 @@ namespace vcpkg g_metricmessage.user_id = config.user_id; g_metricmessage.user_timestamp = config.user_time; - metrics->track_property(Metrics::StringMetric::UserMac, config.user_mac); + metrics->track_property(StringMetric::UserMac, config.user_mac); g_metrics_disabled = false; } diff --git a/src/vcpkg/portfileprovider.cpp b/src/vcpkg/portfileprovider.cpp index d7c22d1bb0..cef6679b6c 100644 --- a/src/vcpkg/portfileprovider.cpp +++ b/src/vcpkg/portfileprovider.cpp @@ -204,7 +204,7 @@ namespace vcpkg } else { - LockGuardPtr(g_metrics)->track_property(Metrics::DefineMetric::VersioningErrorVersion); + LockGuardPtr(g_metrics)->track_property(DefineMetric::VersioningErrorVersion); return maybe_path.error(); } } diff --git a/src/vcpkg/registries.cpp b/src/vcpkg/registries.cpp index ef058aeadf..a56a23e59e 100644 --- a/src/vcpkg/registries.cpp +++ b/src/vcpkg/registries.cpp @@ -85,8 +85,7 @@ namespace e.commit_id(), registry_versions_dir_name.to_string()); if (!maybe_tree) { - LockGuardPtr(g_metrics)->track_property( - Metrics::DefineMetric::RegistriesErrorNoVersionsAtCommit); + LockGuardPtr(g_metrics)->track_property(DefineMetric::RegistriesErrorNoVersionsAtCommit); Checks::exit_with_message( VCPKG_LINE_INFO, "Error: could not find the git tree for `versions` in repo `%s` at commit `%s`: %s", @@ -661,8 +660,7 @@ namespace auto maybe_err = m_paths.git_fetch(m_repo, m_baseline_identifier); if (!maybe_err) { - LockGuardPtr(g_metrics)->track_property( - Metrics::DefineMetric::RegistriesErrorCouldNotFindBaseline); + LockGuardPtr(g_metrics)->track_property(DefineMetric::RegistriesErrorCouldNotFindBaseline); Checks::exit_with_message( VCPKG_LINE_INFO, "Error: Couldn't find baseline `\"%s\"` for repo %s:\n%s\nError: Failed to fetch %s:\n%s", @@ -678,8 +676,7 @@ namespace if (!maybe_contents) { - LockGuardPtr(g_metrics)->track_property( - Metrics::DefineMetric::RegistriesErrorCouldNotFindBaseline); + LockGuardPtr(g_metrics)->track_property(DefineMetric::RegistriesErrorCouldNotFindBaseline); Checks::exit_with_message(VCPKG_LINE_INFO, "Error: Couldn't find baseline in commit `\"%s\"` from repo %s:\n%s\n", m_baseline_identifier, @@ -697,8 +694,7 @@ namespace } else { - LockGuardPtr(g_metrics)->track_property( - Metrics::DefineMetric::RegistriesErrorCouldNotFindBaseline); + LockGuardPtr(g_metrics)->track_property(DefineMetric::RegistriesErrorCouldNotFindBaseline); Checks::exit_maybe_upgrade( VCPKG_LINE_INFO, "The baseline.json from commit `\"%s\"` in the repo %s did not contain a \"default\" field.", diff --git a/src/vcpkg/sourceparagraph.cpp b/src/vcpkg/sourceparagraph.cpp index f73c569ee7..165e4b32b3 100644 --- a/src/vcpkg/sourceparagraph.cpp +++ b/src/vcpkg/sourceparagraph.cpp @@ -1290,8 +1290,7 @@ namespace vcpkg { if (dep.constraint.type != VersionConstraintKind::None) { - LockGuardPtr(g_metrics)->track_property( - Metrics::DefineMetric::ErrorVersioningDisabled); + LockGuardPtr(g_metrics)->track_property(DefineMetric::ErrorVersioningDisabled); return Strings::concat( origin, " was rejected because it uses constraints and the `", @@ -1312,7 +1311,7 @@ namespace vcpkg if (core_paragraph->overrides.size() != 0) { - LockGuardPtr(g_metrics)->track_property(Metrics::DefineMetric::ErrorVersioningDisabled); + LockGuardPtr(g_metrics)->track_property(DefineMetric::ErrorVersioningDisabled); return Strings::concat( origin, format_error_message(ManifestDeserializer::OVERRIDES, VcpkgCmdArguments::VERSIONS_FEATURE), @@ -1321,7 +1320,7 @@ namespace vcpkg if (core_paragraph->builtin_baseline.has_value()) { - LockGuardPtr(g_metrics)->track_property(Metrics::DefineMetric::ErrorVersioningDisabled); + LockGuardPtr(g_metrics)->track_property(DefineMetric::ErrorVersioningDisabled); return Strings::concat( origin, format_error_message(ManifestDeserializer::BUILTIN_BASELINE, VcpkgCmdArguments::VERSIONS_FEATURE), @@ -1338,7 +1337,7 @@ namespace vcpkg return dependency.constraint.type != VersionConstraintKind::None; })) { - LockGuardPtr(g_metrics)->track_property(Metrics::DefineMetric::ErrorVersioningNoBaseline); + LockGuardPtr(g_metrics)->track_property(DefineMetric::ErrorVersioningNoBaseline); return Strings::concat( origin, " was rejected because it uses \"version>=\" and does not have a \"builtin-baseline\".\n", @@ -1347,7 +1346,7 @@ namespace vcpkg if (!core_paragraph->overrides.empty()) { - LockGuardPtr(g_metrics)->track_property(Metrics::DefineMetric::ErrorVersioningNoBaseline); + LockGuardPtr(g_metrics)->track_property(DefineMetric::ErrorVersioningNoBaseline); return Strings::concat( origin, " was rejected because it uses \"overrides\" and does not have a \"builtin-baseline\".\n", diff --git a/src/vcpkg/vcpkgcmdarguments.cpp b/src/vcpkg/vcpkgcmdarguments.cpp index ed016a74f2..12dfbbf079 100644 --- a/src/vcpkg/vcpkgcmdarguments.cpp +++ b/src/vcpkg/vcpkgcmdarguments.cpp @@ -39,7 +39,7 @@ namespace vcpkg if (place.has_value()) { msg::println_error(msgTwoFeatureFlagsSpecified, msg::value = flag); - LockGuardPtr(g_metrics)->track_property(Metrics::StringMetric::Error, + LockGuardPtr(g_metrics)->track_property(StringMetric::Error, "error feature flag +-" + flag.to_string()); Checks::exit_fail(VCPKG_LINE_INFO); } @@ -79,7 +79,7 @@ namespace vcpkg if (nullptr != option_field) { msg::println_error(msgDuplicateOptions, msg::value = option_name); - LockGuardPtr(g_metrics)->track_property(Metrics::StringMetric::Error, + LockGuardPtr(g_metrics)->track_property(StringMetric::Error, "error option specified multiple times"); print_usage(); Checks::exit_fail(VCPKG_LINE_INFO); @@ -93,8 +93,7 @@ namespace vcpkg if (option_field && option_field != new_setting) { msg::println_error(msgConflictingValuesForOption, msg::option = option_name); - LockGuardPtr(g_metrics)->track_property(Metrics::StringMetric::Error, - "error conflicting switches"); + LockGuardPtr(g_metrics)->track_property(StringMetric::Error, "error conflicting switches"); print_usage(); Checks::exit_fail(VCPKG_LINE_INFO); } @@ -108,7 +107,7 @@ namespace vcpkg if (new_value.size() == 0) { msg::println_error(msgExpectedValueForOption, msg::option = option_name); - LockGuardPtr(g_metrics)->track_property(Metrics::StringMetric::Error, "error option name"); + LockGuardPtr(g_metrics)->track_property(StringMetric::Error, "error option name"); print_usage(); Checks::exit_fail(VCPKG_LINE_INFO); } @@ -123,7 +122,7 @@ namespace vcpkg if (new_value.size() == 0) { msg::println_error(msgExpectedValueForOption, msg::option = option_name); - LockGuardPtr(g_metrics)->track_property(Metrics::StringMetric::Error, "error option name"); + LockGuardPtr(g_metrics)->track_property(StringMetric::Error, "error option name"); print_usage(); Checks::exit_fail(VCPKG_LINE_INFO); } @@ -190,7 +189,7 @@ namespace vcpkg } msg::println_error(msgExpectedValueForOption, msg::option = option); - LockGuardPtr(g_metrics)->track_property(Metrics::StringMetric::Error, "error option name"); + LockGuardPtr(g_metrics)->track_property(StringMetric::Error, "error option name"); print_usage(); Checks::exit_fail(VCPKG_LINE_INFO); } @@ -263,7 +262,7 @@ namespace vcpkg if (basic_arg.size() >= 2 && basic_arg[0] == '-' && basic_arg[1] != '-') { - LockGuardPtr(g_metrics)->track_property(Metrics::StringMetric::Error, + LockGuardPtr(g_metrics)->track_property(StringMetric::Error, "error short options are not supported"); Checks::msg_exit_with_message(VCPKG_LINE_INFO, msgUnsupportedShortOptions, msg::value = basic_arg); } @@ -839,7 +838,7 @@ namespace vcpkg msgSpecifiedFeatureTurnedOff, msg::command_name = el.flag, msg::option = el.option); msg::println_warning(msgDefaultFlag, msg::option = el.flag); LockGuardPtr(g_metrics)->track_property( - Metrics::StringMetric::Warning, Strings::format("warning %s alongside %s", el.flag, el.option)); + StringMetric::Warning, Strings::format("warning %s alongside %s", el.flag, el.option)); } } } diff --git a/src/vcpkg/vcpkglib.cpp b/src/vcpkg/vcpkglib.cpp index 72405346b3..bcd244b422 100644 --- a/src/vcpkg/vcpkglib.cpp +++ b/src/vcpkg/vcpkglib.cpp @@ -111,7 +111,7 @@ namespace vcpkg if (!was_tracked) { was_tracked = true; - LockGuardPtr(g_metrics)->track_property(Metrics::StringMetric::ListFile, "update to new format"); + LockGuardPtr(g_metrics)->track_property(StringMetric::ListFile, "update to new format"); } // The files are sorted such that directories are placed just before the files they contain diff --git a/src/vcpkg/vcpkgpaths.cpp b/src/vcpkg/vcpkgpaths.cpp index 63f5a74d3e..53c58b18ba 100644 --- a/src/vcpkg/vcpkgpaths.cpp +++ b/src/vcpkg/vcpkgpaths.cpp @@ -187,10 +187,10 @@ namespace vcpkg { if (auto p_baseline = manifest->builtin_baseline.get()) { - LockGuardPtr(g_metrics)->track_property(Metrics::DefineMetric::ManifestBaseline); + LockGuardPtr(g_metrics)->track_property(DefineMetric::ManifestBaseline); if (!is_git_commit_sha(*p_baseline)) { - LockGuardPtr(g_metrics)->track_property(Metrics::DefineMetric::VersioningErrorBaseline); + LockGuardPtr(g_metrics)->track_property(DefineMetric::VersioningErrorBaseline); Checks::exit_maybe_upgrade(VCPKG_LINE_INFO, "Error: the top-level builtin-baseline%s was not a valid commit sha: " "expected 40 hexadecimal characters.\n%s\n", @@ -325,7 +325,7 @@ namespace vcpkg Path ret; if (args.registries_cache_dir) { - LockGuardPtr(g_metrics)->track_property(Metrics::DefineMetric::X_VcpkgRegistriesCache); + LockGuardPtr(g_metrics)->track_property(DefineMetric::X_VcpkgRegistriesCache); ret = *args.registries_cache_dir; const auto status = get_real_filesystem().status(ret, VCPKG_LINE_INFO); if (!vcpkg::exists(status)) @@ -666,12 +666,12 @@ namespace vcpkg LockGuardPtr metrics(g_metrics); if (default_registry) { - metrics->track_property(Metrics::StringMetric::RegistriesDefaultRegistryKind, + metrics->track_property(StringMetric::RegistriesDefaultRegistryKind, default_registry->kind().to_string()); } else { - metrics->track_property(Metrics::StringMetric::RegistriesDefaultRegistryKind, "disabled"); + metrics->track_property(StringMetric::RegistriesDefaultRegistryKind, "disabled"); } if (other_registries.size() != 0) @@ -682,7 +682,7 @@ namespace vcpkg registry_kinds.push_back(reg.implementation().kind()); } Util::sort_unique_erase(registry_kinds); - metrics->track_property(Metrics::StringMetric::RegistriesKindsUsed, Strings::join(",", registry_kinds)); + metrics->track_property(StringMetric::RegistriesKindsUsed, Strings::join(",", registry_kinds)); } } } From c2e0f508927b412a4a03ee858662630a7fb58964 Mon Sep 17 00:00:00 2001 From: Victor Romero Date: Wed, 7 Sep 2022 13:45:24 -0700 Subject: [PATCH 11/14] Review comments and tests --- include/vcpkg/metrics.h | 8 +++--- src/vcpkg-test/metrics.cpp | 51 ++++++++++++++++++++++++++++++++++++++ src/vcpkg/metrics.cpp | 32 +++++++++++------------- 3 files changed, 69 insertions(+), 22 deletions(-) create mode 100644 src/vcpkg-test/metrics.cpp diff --git a/include/vcpkg/metrics.h b/include/vcpkg/metrics.h index 354d73ffdf..e80ba254e1 100644 --- a/include/vcpkg/metrics.h +++ b/include/vcpkg/metrics.h @@ -42,7 +42,7 @@ namespace vcpkg VersioningErrorVersion, X_VcpkgRegistriesCache, X_WriteNugetPackagesConfig, - _COUNT // always keep COUNT last + COUNT // always keep COUNT last }; enum class StringMetric @@ -60,14 +60,14 @@ namespace vcpkg UserMac, VcpkgVersion, Warning, - _COUNT // always keep COUNT last + COUNT // always keep COUNT last }; enum class BoolMetric { InstallManifestMode, OptionOverlayPorts, - _COUNT // always keep COUNT last + COUNT // always keep COUNT last }; struct Metrics @@ -86,7 +86,7 @@ namespace vcpkg void track_buildtime(const std::string& name, double value); void track_property(DefineMetric metric); - void track_property(StringMetric metric, const std::string& value); + void track_property(StringMetric metric, StringView value); void track_property(BoolMetric metric, bool value); void track_feature(const std::string& feature, bool value); diff --git a/src/vcpkg-test/metrics.cpp b/src/vcpkg-test/metrics.cpp new file mode 100644 index 0000000000..50db6ac5f0 --- /dev/null +++ b/src/vcpkg-test/metrics.cpp @@ -0,0 +1,51 @@ +#include + +#include + +#include + +using namespace vcpkg; + +template +void validate_enum_values_and_names(View> entries) +{ + size_t enum_value = 0; + std::set used_names; + for (auto m : entries) + { + // fails when a metric is not in the right order in the entries array + // - check that there are no duplicate metric entries + // - check that the order in Metrics::get__metrics() and in the Metric enum is the same + REQUIRE(static_cast(m.metric) == enum_value); + ++enum_value; + + // fails when there's a repeated metric name + auto it_names = used_names.find(m.name); + REQUIRE(it_names == used_names.end()); + used_names.insert(m.name); + } +} + +TEST_CASE ("Check metric enum types", "[metrics]") +{ + SECTION ("define metrics") + { + auto define_metrics = Metrics::get_define_metrics(); + REQUIRE(define_metrics.size() == static_cast(DefineMetric::COUNT)); + validate_enum_values_and_names(define_metrics); + } + + SECTION ("string metrics") + { + auto string_metrics = Metrics::get_string_metrics(); + REQUIRE(string_metrics.size() == static_cast(StringMetric::COUNT)); + validate_enum_values_and_names(string_metrics); + } + + SECTION ("bool metrics") + { + auto bool_metrics = Metrics::get_bool_metrics(); + REQUIRE(bool_metrics.size() == static_cast(BoolMetric::COUNT)); + validate_enum_values_and_names(bool_metrics); + } +} \ No newline at end of file diff --git a/src/vcpkg/metrics.cpp b/src/vcpkg/metrics.cpp index d97253502b..c86ee7159c 100644 --- a/src/vcpkg/metrics.cpp +++ b/src/vcpkg/metrics.cpp @@ -26,17 +26,13 @@ namespace template StringLiteral get_metric_name(const T metric, View> entries) { - for (auto&& entry : entries) + auto metric_index = static_cast(metric); + if (metric_index < entries.size()) { - if (entry.metric == metric) - { - return entry.name; - } + return entries[metric_index].name; } - - // All metric enums should have corresponding names - Debug::println("Error: Metric is missing a name"); - Checks::exit_fail(VCPKG_LINE_INFO); + // abort() is used because Checks:: will call back into metrics machinery. + abort(); } } @@ -46,7 +42,7 @@ namespace vcpkg View> Metrics::get_define_metrics() { - static constexpr std::array, static_cast(DefineMetric::_COUNT)> ENTRIES{{ + static constexpr std::array, static_cast(DefineMetric::COUNT)> ENTRIES{{ {DefineMetric::AssetSource, "asset-source"}, {DefineMetric::BinaryCachingAws, "binarycaching_aws"}, {DefineMetric::BinaryCachingAzBlob, "binarycaching_azblob"}, @@ -78,7 +74,7 @@ namespace vcpkg View> Metrics::get_string_metrics() { - static constexpr std::array, static_cast(StringMetric::_COUNT)> ENTRIES{{ + static constexpr std::array, static_cast(StringMetric::COUNT)> ENTRIES{{ {StringMetric::BuildError, "build_error"}, {StringMetric::CommandArgs, "command_args"}, {StringMetric::CommandContext, "command_context"}, @@ -98,7 +94,7 @@ namespace vcpkg View> Metrics::get_bool_metrics() { - static constexpr std::array, static_cast(BoolMetric::_COUNT)> ENTRIES{{ + static constexpr std::array, static_cast(BoolMetric::COUNT)> ENTRIES{{ {BoolMetric::InstallManifestMode, "install_manifest_mode"}, {BoolMetric::OptionOverlayPorts, "option_overlay_ports"}, }}; @@ -165,12 +161,12 @@ namespace vcpkg Json::Array buildtime_names; Json::Array buildtime_times; - void track_property(StringView name, const std::string& value) + void track_string(StringView name, StringView value) { properties.insert_or_replace(name, Json::Value::string(value)); } - void track_property(StringView name, bool value) + void track_bool(StringView name, bool value) { properties.insert_or_replace(name, Json::Value::boolean(value)); } @@ -327,17 +323,17 @@ namespace vcpkg void Metrics::track_property(DefineMetric metric) { - g_metricmessage.track_property(get_metric_name(metric, get_define_metrics()), "defined"); + g_metricmessage.track_string(get_metric_name(metric, get_define_metrics()), "defined"); } - void Metrics::track_property(StringMetric metric, const std::string& value) + void Metrics::track_property(StringMetric metric, StringView value) { - g_metricmessage.track_property(get_metric_name(metric, get_string_metrics()), value); + g_metricmessage.track_string(get_metric_name(metric, get_string_metrics()), value); } void Metrics::track_property(BoolMetric metric, bool value) { - g_metricmessage.track_property(get_metric_name(metric, get_bool_metrics()), value); + g_metricmessage.track_bool(get_metric_name(metric, get_bool_metrics()), value); } void Metrics::track_feature(const std::string& name, bool value) { g_metricmessage.track_feature(name, value); } From ff56e69e0e47aba6444cbcf3061b8f521e2eb911 Mon Sep 17 00:00:00 2001 From: Victor Romero Date: Wed, 7 Sep 2022 15:29:22 -0700 Subject: [PATCH 12/14] Update src/vcpkg-test/metrics.cpp Co-authored-by: Robert Schumacher --- src/vcpkg-test/metrics.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vcpkg-test/metrics.cpp b/src/vcpkg-test/metrics.cpp index 50db6ac5f0..9d1658e433 100644 --- a/src/vcpkg-test/metrics.cpp +++ b/src/vcpkg-test/metrics.cpp @@ -11,7 +11,7 @@ void validate_enum_values_and_names(View> entries) { size_t enum_value = 0; std::set used_names; - for (auto m : entries) + for (auto&& m : entries) { // fails when a metric is not in the right order in the entries array // - check that there are no duplicate metric entries From c15a4a56c9332a691a8ff31bc0453dd303ea1577 Mon Sep 17 00:00:00 2001 From: Victor Romero Date: Wed, 7 Sep 2022 15:36:40 -0700 Subject: [PATCH 13/14] simplify tests --- src/vcpkg-test/metrics.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/vcpkg-test/metrics.cpp b/src/vcpkg-test/metrics.cpp index 9d1658e433..36360358b0 100644 --- a/src/vcpkg-test/metrics.cpp +++ b/src/vcpkg-test/metrics.cpp @@ -7,19 +7,22 @@ using namespace vcpkg; template -void validate_enum_values_and_names(View> entries) +void validate_enum_values_and_names(View> entries, const size_t expected_size) { + REQUIRE(expected_size == entries.size()); + size_t enum_value = 0; std::set used_names; for (auto&& m : entries) { // fails when a metric is not in the right order in the entries array - // - check that there are no duplicate metric entries + // - check that there are no duplicate or skipped metric entries // - check that the order in Metrics::get__metrics() and in the Metric enum is the same REQUIRE(static_cast(m.metric) == enum_value); ++enum_value; // fails when there's a repeated metric name + REQUIRE(!m.name.empty()); auto it_names = used_names.find(m.name); REQUIRE(it_names == used_names.end()); used_names.insert(m.name); @@ -30,22 +33,16 @@ TEST_CASE ("Check metric enum types", "[metrics]") { SECTION ("define metrics") { - auto define_metrics = Metrics::get_define_metrics(); - REQUIRE(define_metrics.size() == static_cast(DefineMetric::COUNT)); - validate_enum_values_and_names(define_metrics); + validate_enum_values_and_names(Metrics::get_define_metrics(), static_cast(DefineMetric::COUNT)); } SECTION ("string metrics") { - auto string_metrics = Metrics::get_string_metrics(); - REQUIRE(string_metrics.size() == static_cast(StringMetric::COUNT)); - validate_enum_values_and_names(string_metrics); + validate_enum_values_and_names(Metrics::get_string_metrics(), static_cast(StringMetric::COUNT)); } SECTION ("bool metrics") { - auto bool_metrics = Metrics::get_bool_metrics(); - REQUIRE(bool_metrics.size() == static_cast(BoolMetric::COUNT)); - validate_enum_values_and_names(bool_metrics); + validate_enum_values_and_names(Metrics::get_bool_metrics(), static_cast(BoolMetric::COUNT)); } } \ No newline at end of file From c65d21123d32457f98c4ee1ea34cc288b0cca79d Mon Sep 17 00:00:00 2001 From: Victor Romero Date: Mon, 12 Sep 2022 12:58:54 -0700 Subject: [PATCH 14/14] Remove `track_property()` overrides --- include/vcpkg/metrics.h | 6 +++--- src/vcpkg.cpp | 14 +++++++------- src/vcpkg/binarycaching.cpp | 14 +++++++------- src/vcpkg/build.cpp | 4 ++-- src/vcpkg/commands.add.cpp | 8 ++++---- src/vcpkg/commands.find.cpp | 8 ++++---- src/vcpkg/commands.integrate.cpp | 4 ++-- src/vcpkg/commands.setinstalled.cpp | 2 +- src/vcpkg/input.cpp | 3 ++- src/vcpkg/install.cpp | 14 +++++++------- src/vcpkg/metrics.cpp | 8 ++++---- src/vcpkg/portfileprovider.cpp | 2 +- src/vcpkg/registries.cpp | 12 ++++++++---- src/vcpkg/sourceparagraph.cpp | 10 +++++----- src/vcpkg/vcpkgcmdarguments.cpp | 22 +++++++++++----------- src/vcpkg/vcpkglib.cpp | 2 +- src/vcpkg/vcpkgpaths.cpp | 14 +++++++------- 17 files changed, 76 insertions(+), 71 deletions(-) diff --git a/include/vcpkg/metrics.h b/include/vcpkg/metrics.h index e80ba254e1..fc5e269f91 100644 --- a/include/vcpkg/metrics.h +++ b/include/vcpkg/metrics.h @@ -85,9 +85,9 @@ namespace vcpkg void track_metric(const std::string& name, double value); void track_buildtime(const std::string& name, double value); - void track_property(DefineMetric metric); - void track_property(StringMetric metric, StringView value); - void track_property(BoolMetric metric, bool value); + void track_define_property(DefineMetric metric); + void track_string_property(StringMetric metric, StringView value); + void track_bool_property(BoolMetric metric, bool value); void track_feature(const std::string& feature, bool value); diff --git a/src/vcpkg.cpp b/src/vcpkg.cpp index 2f18a7620a..e523833904 100644 --- a/src/vcpkg.cpp +++ b/src/vcpkg.cpp @@ -44,8 +44,8 @@ static void invalid_command(const std::string& cmd) static void inner(vcpkg::Filesystem& fs, const VcpkgCmdArguments& args) { // track version on each invocation - LockGuardPtr(g_metrics)->track_property(StringMetric::VcpkgVersion, - Commands::Version::version.to_string()); + LockGuardPtr(g_metrics)->track_string_property(StringMetric::VcpkgVersion, + Commands::Version::version.to_string()); if (args.command.empty()) { @@ -68,11 +68,11 @@ static void inner(vcpkg::Filesystem& fs, const VcpkgCmdArguments& args) } }; - LockGuardPtr(g_metrics)->track_property(BoolMetric::OptionOverlayPorts, !args.overlay_ports.empty()); + LockGuardPtr(g_metrics)->track_bool_property(BoolMetric::OptionOverlayPorts, !args.overlay_ports.empty()); if (const auto command_function = find_command(Commands::get_available_basic_commands())) { - LockGuardPtr(g_metrics)->track_property(StringMetric::CommandName, command_function->name); + LockGuardPtr(g_metrics)->track_string_property(StringMetric::CommandName, command_function->name); return command_function->function->perform_and_exit(args, fs); } @@ -83,7 +83,7 @@ static void inner(vcpkg::Filesystem& fs, const VcpkgCmdArguments& args) if (const auto command_function = find_command(Commands::get_available_paths_commands())) { - LockGuardPtr(g_metrics)->track_property(StringMetric::CommandName, command_function->name); + LockGuardPtr(g_metrics)->track_string_property(StringMetric::CommandName, command_function->name); return command_function->function->perform_and_exit(args, paths); } @@ -94,7 +94,7 @@ static void inner(vcpkg::Filesystem& fs, const VcpkgCmdArguments& args) if (const auto command_function = find_command(Commands::get_available_triplet_commands())) { - LockGuardPtr(g_metrics)->track_property(StringMetric::CommandName, command_function->name); + LockGuardPtr(g_metrics)->track_string_property(StringMetric::CommandName, command_function->name); return command_function->function->perform_and_exit(args, paths, default_triplet, host_triplet); } @@ -317,7 +317,7 @@ int main(const int argc, const char* const* const argv) exc_msg = "unknown error(...)"; } - LockGuardPtr(g_metrics)->track_property(StringMetric::Error, exc_msg); + LockGuardPtr(g_metrics)->track_string_property(StringMetric::Error, exc_msg); fflush(stdout); msg::println(msgVcpkgHasCrashed); diff --git a/src/vcpkg/binarycaching.cpp b/src/vcpkg/binarycaching.cpp index 6d3847cf88..b766a9413c 100644 --- a/src/vcpkg/binarycaching.cpp +++ b/src/vcpkg/binarycaching.cpp @@ -1579,7 +1579,7 @@ namespace auto maybe_cachepath = get_environment_variable("VCPKG_DEFAULT_BINARY_CACHE"); if (auto p_str = maybe_cachepath.get()) { - LockGuardPtr(g_metrics)->track_property(DefineMetric::VcpkgDefaultBinaryCache); + LockGuardPtr(g_metrics)->track_define_property(DefineMetric::VcpkgDefaultBinaryCache); Path path = *p_str; path.make_preferred(); if (!get_real_filesystem().is_directory(path)) @@ -2013,7 +2013,7 @@ namespace auto it = metric_names.find(cache_provider); if (it != metric_names.end()) { - metrics->track_property(it->second); + metrics->track_define_property(it->second); } } } @@ -2147,7 +2147,7 @@ ExpectedS vcpkg::parse_download_configuration(const Optio { if (!arg || arg.get()->empty()) return DownloadManagerConfig{}; - LockGuardPtr(g_metrics)->track_property(DefineMetric::AssetSource); + LockGuardPtr(g_metrics)->track_define_property(DefineMetric::AssetSource); AssetSourcesState s; AssetSourcesParser parser(*arg.get(), Strings::concat("$", VcpkgCmdArguments::ASSET_SOURCES_ENV), &s); @@ -2202,12 +2202,12 @@ ExpectedS vcpkg::create_binary_providers_from_configs_p LockGuardPtr metrics(g_metrics); if (!env_string.empty()) { - metrics->track_property(DefineMetric::VcpkgBinarySources); + metrics->track_define_property(DefineMetric::VcpkgBinarySources); } if (args.size() != 0) { - metrics->track_property(DefineMetric::BinaryCachingSource); + metrics->track_define_property(DefineMetric::BinaryCachingSource); } } @@ -2346,7 +2346,7 @@ details::NuGetRepoInfo details::get_nuget_repo_info_from_env() auto vcpkg_nuget_repository = get_environment_variable("VCPKG_NUGET_REPOSITORY"); if (auto p = vcpkg_nuget_repository.get()) { - LockGuardPtr(g_metrics)->track_property(DefineMetric::VcpkgNugetRepository); + LockGuardPtr(g_metrics)->track_define_property(DefineMetric::VcpkgNugetRepository); return {std::move(*p)}; } @@ -2362,7 +2362,7 @@ details::NuGetRepoInfo details::get_nuget_repo_info_from_env() return {}; } - LockGuardPtr(g_metrics)->track_property(DefineMetric::GitHubRepository); + LockGuardPtr(g_metrics)->track_define_property(DefineMetric::GitHubRepository); return {Strings::concat(gh_server, '/', gh_repo, ".git"), get_environment_variable("GITHUB_REF").value_or(""), get_environment_variable("GITHUB_SHA").value_or("")}; diff --git a/src/vcpkg/build.cpp b/src/vcpkg/build.cpp index c2ab3f8347..262f71b6c3 100644 --- a/src/vcpkg/build.cpp +++ b/src/vcpkg/build.cpp @@ -947,8 +947,8 @@ namespace vcpkg buildtimeus); if (!succeeded(return_code)) { - metrics->track_property(StringMetric::Error, "build failed"); - metrics->track_property(StringMetric::BuildError, spec_string); + metrics->track_string_property(StringMetric::Error, "build failed"); + metrics->track_string_property(StringMetric::BuildError, spec_string); const auto logs = buildpath / Strings::concat("error-logs-", action.spec.triplet(), ".txt"); std::vector error_logs; if (fs.exists(logs, VCPKG_LINE_INFO)) diff --git a/src/vcpkg/commands.add.cpp b/src/vcpkg/commands.add.cpp index e8b8f120fd..e4d1704be4 100644 --- a/src/vcpkg/commands.add.cpp +++ b/src/vcpkg/commands.add.cpp @@ -46,8 +46,8 @@ namespace vcpkg::Commands auto artifact_hash = Hash::get_string_hash(artifact_name, Hash::Algorithm::Sha256); { auto metrics = LockGuardPtr(g_metrics); - metrics->track_property(StringMetric::CommandContext, "artifact"); - metrics->track_property(StringMetric::CommandArgs, artifact_hash); + metrics->track_string_property(StringMetric::CommandContext, "artifact"); + metrics->track_string_property(StringMetric::CommandArgs, artifact_hash); } // unlock g_metrics std::string ce_args[] = {"add", artifact_name}; @@ -122,8 +122,8 @@ namespace vcpkg::Commands })); { auto metrics = LockGuardPtr(g_metrics); - metrics->track_property(StringMetric::CommandContext, "port"); - metrics->track_property(StringMetric::CommandArgs, command_args_hash); + metrics->track_string_property(StringMetric::CommandContext, "port"); + metrics->track_string_property(StringMetric::CommandArgs, command_args_hash); } // unlock metrics Checks::exit_success(VCPKG_LINE_INFO); diff --git a/src/vcpkg/commands.find.cpp b/src/vcpkg/commands.find.cpp index 800bde3315..63062c24df 100644 --- a/src/vcpkg/commands.find.cpp +++ b/src/vcpkg/commands.find.cpp @@ -237,10 +237,10 @@ namespace vcpkg::Commands auto args_hash = Hash::get_string_hash(filter.value_or_exit(VCPKG_LINE_INFO), Hash::Algorithm::Sha256); { auto metrics = LockGuardPtr(g_metrics); - metrics->track_property(StringMetric::CommandContext, "artifact"); + metrics->track_string_property(StringMetric::CommandContext, "artifact"); if (auto p_filter_hash = filter_hash.get()) { - metrics->track_property(StringMetric::CommandArgs, *p_filter_hash); + metrics->track_string_property(StringMetric::CommandArgs, *p_filter_hash); } } // unlock metrics @@ -252,10 +252,10 @@ namespace vcpkg::Commands Optional filter_hash = filter.map(Hash::get_string_sha256); { auto metrics = LockGuardPtr(g_metrics); - metrics->track_property(StringMetric::CommandContext, "port"); + metrics->track_string_property(StringMetric::CommandContext, "port"); if (auto p_filter_hash = filter_hash.get()) { - metrics->track_property(StringMetric::CommandArgs, *p_filter_hash); + metrics->track_string_property(StringMetric::CommandArgs, *p_filter_hash); } } // unlock metrics diff --git a/src/vcpkg/commands.integrate.cpp b/src/vcpkg/commands.integrate.cpp index 62308af6c4..a30b1e5d56 100644 --- a/src/vcpkg/commands.integrate.cpp +++ b/src/vcpkg/commands.integrate.cpp @@ -472,8 +472,8 @@ namespace vcpkg::Commands::Integrate .append_raw("\n" + script_path.generic_u8string())); { auto locked_metrics = LockGuardPtr(g_metrics); - locked_metrics->track_property(StringMetric::Error, "powershell script failed"); - locked_metrics->track_property(StringMetric::Title, TITLE.to_string()); + locked_metrics->track_string_property(StringMetric::Error, "powershell script failed"); + locked_metrics->track_string_property(StringMetric::Title, TITLE.to_string()); } } diff --git a/src/vcpkg/commands.setinstalled.cpp b/src/vcpkg/commands.setinstalled.cpp index 9b14e943a7..a44c5b35b3 100644 --- a/src/vcpkg/commands.setinstalled.cpp +++ b/src/vcpkg/commands.setinstalled.cpp @@ -164,7 +164,7 @@ namespace vcpkg::Commands::SetInstalled auto it_pkgsconfig = options.settings.find(OPTION_WRITE_PACKAGES_CONFIG); if (it_pkgsconfig != options.settings.end()) { - LockGuardPtr(g_metrics)->track_property(DefineMetric::X_WriteNugetPackagesConfig); + LockGuardPtr(g_metrics)->track_define_property(DefineMetric::X_WriteNugetPackagesConfig); pkgsconfig = it_pkgsconfig->second; } diff --git a/src/vcpkg/input.cpp b/src/vcpkg/input.cpp index 1f07992b54..3c1a06210f 100644 --- a/src/vcpkg/input.cpp +++ b/src/vcpkg/input.cpp @@ -35,7 +35,8 @@ namespace vcpkg if (!paths.is_valid_triplet(t)) { print2(Color::error, "Error: invalid triplet: ", t, '\n'); - LockGuardPtr(g_metrics)->track_property(StringMetric::Error, "invalid triplet: " + t.to_string()); + LockGuardPtr(g_metrics)->track_string_property(StringMetric::Error, + "invalid triplet: " + t.to_string()); Help::help_topic_valid_triplet(paths); Checks::exit_fail(VCPKG_LINE_INFO); } diff --git a/src/vcpkg/install.cpp b/src/vcpkg/install.cpp index 608dc2de87..3a08a564d4 100644 --- a/src/vcpkg/install.cpp +++ b/src/vcpkg/install.cpp @@ -875,8 +875,8 @@ namespace vcpkg : UnsupportedPortAction::Error; const bool no_print_usage = Util::Sets::contains(options.switches, OPTION_NO_PRINT_USAGE); - LockGuardPtr(g_metrics)->track_property(BoolMetric::InstallManifestMode, - paths.manifest_mode_enabled()); + LockGuardPtr(g_metrics)->track_bool_property(BoolMetric::InstallManifestMode, + paths.manifest_mode_enabled()); if (auto p = paths.get_manifest().get()) { @@ -966,7 +966,7 @@ namespace vcpkg auto it_pkgsconfig = options.settings.find(OPTION_WRITE_PACKAGES_CONFIG); if (it_pkgsconfig != options.settings.end()) { - LockGuardPtr(g_metrics)->track_property(DefineMetric::X_WriteNugetPackagesConfig); + LockGuardPtr(g_metrics)->track_define_property(DefineMetric::X_WriteNugetPackagesConfig); pkgsconfig = Path(it_pkgsconfig->second); } auto maybe_manifest_scf = @@ -1034,12 +1034,12 @@ namespace vcpkg return dep.constraint.type != VersionConstraintKind::None; })) { - LockGuardPtr(g_metrics)->track_property(DefineMetric::ManifestVersionConstraint); + LockGuardPtr(g_metrics)->track_define_property(DefineMetric::ManifestVersionConstraint); } if (!manifest_core.overrides.empty()) { - LockGuardPtr(g_metrics)->track_property(DefineMetric::ManifestOverrides); + LockGuardPtr(g_metrics)->track_define_property(DefineMetric::ManifestOverrides); } auto verprovider = make_versioned_portfile_provider(paths); @@ -1169,7 +1169,7 @@ namespace vcpkg auto it_pkgsconfig = options.settings.find(OPTION_WRITE_PACKAGES_CONFIG); if (it_pkgsconfig != options.settings.end()) { - LockGuardPtr(g_metrics)->track_property(DefineMetric::X_WriteNugetPackagesConfig); + LockGuardPtr(g_metrics)->track_define_property(DefineMetric::X_WriteNugetPackagesConfig); compute_all_abis(paths, action_plan, var_provider, status_db); auto pkgsconfig_path = paths.original_cwd / it_pkgsconfig->second; @@ -1318,6 +1318,6 @@ namespace vcpkg Hash::get_string_hash(version_as_string, Hash::Algorithm::Sha256)); } - LockGuardPtr(g_metrics)->track_property(StringMetric::InstallPlan_1, specs_string); + LockGuardPtr(g_metrics)->track_string_property(StringMetric::InstallPlan_1, specs_string); } } diff --git a/src/vcpkg/metrics.cpp b/src/vcpkg/metrics.cpp index c86ee7159c..616a1bca93 100644 --- a/src/vcpkg/metrics.cpp +++ b/src/vcpkg/metrics.cpp @@ -306,7 +306,7 @@ namespace vcpkg g_metricmessage.user_id = config.user_id; g_metricmessage.user_timestamp = config.user_time; - metrics->track_property(StringMetric::UserMac, config.user_mac); + metrics->track_string_property(StringMetric::UserMac, config.user_mac); g_metrics_disabled = false; } @@ -321,17 +321,17 @@ namespace vcpkg g_metricmessage.track_buildtime(name, value); } - void Metrics::track_property(DefineMetric metric) + void Metrics::track_define_property(DefineMetric metric) { g_metricmessage.track_string(get_metric_name(metric, get_define_metrics()), "defined"); } - void Metrics::track_property(StringMetric metric, StringView value) + void Metrics::track_string_property(StringMetric metric, StringView value) { g_metricmessage.track_string(get_metric_name(metric, get_string_metrics()), value); } - void Metrics::track_property(BoolMetric metric, bool value) + void Metrics::track_bool_property(BoolMetric metric, bool value) { g_metricmessage.track_bool(get_metric_name(metric, get_bool_metrics()), value); } diff --git a/src/vcpkg/portfileprovider.cpp b/src/vcpkg/portfileprovider.cpp index cef6679b6c..d1cef89f9c 100644 --- a/src/vcpkg/portfileprovider.cpp +++ b/src/vcpkg/portfileprovider.cpp @@ -204,7 +204,7 @@ namespace vcpkg } else { - LockGuardPtr(g_metrics)->track_property(DefineMetric::VersioningErrorVersion); + LockGuardPtr(g_metrics)->track_define_property(DefineMetric::VersioningErrorVersion); return maybe_path.error(); } } diff --git a/src/vcpkg/registries.cpp b/src/vcpkg/registries.cpp index a56a23e59e..ac1eb1a326 100644 --- a/src/vcpkg/registries.cpp +++ b/src/vcpkg/registries.cpp @@ -85,7 +85,8 @@ namespace e.commit_id(), registry_versions_dir_name.to_string()); if (!maybe_tree) { - LockGuardPtr(g_metrics)->track_property(DefineMetric::RegistriesErrorNoVersionsAtCommit); + LockGuardPtr(g_metrics)->track_define_property( + DefineMetric::RegistriesErrorNoVersionsAtCommit); Checks::exit_with_message( VCPKG_LINE_INFO, "Error: could not find the git tree for `versions` in repo `%s` at commit `%s`: %s", @@ -660,7 +661,8 @@ namespace auto maybe_err = m_paths.git_fetch(m_repo, m_baseline_identifier); if (!maybe_err) { - LockGuardPtr(g_metrics)->track_property(DefineMetric::RegistriesErrorCouldNotFindBaseline); + LockGuardPtr(g_metrics)->track_define_property( + DefineMetric::RegistriesErrorCouldNotFindBaseline); Checks::exit_with_message( VCPKG_LINE_INFO, "Error: Couldn't find baseline `\"%s\"` for repo %s:\n%s\nError: Failed to fetch %s:\n%s", @@ -676,7 +678,8 @@ namespace if (!maybe_contents) { - LockGuardPtr(g_metrics)->track_property(DefineMetric::RegistriesErrorCouldNotFindBaseline); + LockGuardPtr(g_metrics)->track_define_property( + DefineMetric::RegistriesErrorCouldNotFindBaseline); Checks::exit_with_message(VCPKG_LINE_INFO, "Error: Couldn't find baseline in commit `\"%s\"` from repo %s:\n%s\n", m_baseline_identifier, @@ -694,7 +697,8 @@ namespace } else { - LockGuardPtr(g_metrics)->track_property(DefineMetric::RegistriesErrorCouldNotFindBaseline); + LockGuardPtr(g_metrics)->track_define_property( + DefineMetric::RegistriesErrorCouldNotFindBaseline); Checks::exit_maybe_upgrade( VCPKG_LINE_INFO, "The baseline.json from commit `\"%s\"` in the repo %s did not contain a \"default\" field.", diff --git a/src/vcpkg/sourceparagraph.cpp b/src/vcpkg/sourceparagraph.cpp index 165e4b32b3..49e0eb800b 100644 --- a/src/vcpkg/sourceparagraph.cpp +++ b/src/vcpkg/sourceparagraph.cpp @@ -1290,7 +1290,7 @@ namespace vcpkg { if (dep.constraint.type != VersionConstraintKind::None) { - LockGuardPtr(g_metrics)->track_property(DefineMetric::ErrorVersioningDisabled); + LockGuardPtr(g_metrics)->track_define_property(DefineMetric::ErrorVersioningDisabled); return Strings::concat( origin, " was rejected because it uses constraints and the `", @@ -1311,7 +1311,7 @@ namespace vcpkg if (core_paragraph->overrides.size() != 0) { - LockGuardPtr(g_metrics)->track_property(DefineMetric::ErrorVersioningDisabled); + LockGuardPtr(g_metrics)->track_define_property(DefineMetric::ErrorVersioningDisabled); return Strings::concat( origin, format_error_message(ManifestDeserializer::OVERRIDES, VcpkgCmdArguments::VERSIONS_FEATURE), @@ -1320,7 +1320,7 @@ namespace vcpkg if (core_paragraph->builtin_baseline.has_value()) { - LockGuardPtr(g_metrics)->track_property(DefineMetric::ErrorVersioningDisabled); + LockGuardPtr(g_metrics)->track_define_property(DefineMetric::ErrorVersioningDisabled); return Strings::concat( origin, format_error_message(ManifestDeserializer::BUILTIN_BASELINE, VcpkgCmdArguments::VERSIONS_FEATURE), @@ -1337,7 +1337,7 @@ namespace vcpkg return dependency.constraint.type != VersionConstraintKind::None; })) { - LockGuardPtr(g_metrics)->track_property(DefineMetric::ErrorVersioningNoBaseline); + LockGuardPtr(g_metrics)->track_define_property(DefineMetric::ErrorVersioningNoBaseline); return Strings::concat( origin, " was rejected because it uses \"version>=\" and does not have a \"builtin-baseline\".\n", @@ -1346,7 +1346,7 @@ namespace vcpkg if (!core_paragraph->overrides.empty()) { - LockGuardPtr(g_metrics)->track_property(DefineMetric::ErrorVersioningNoBaseline); + LockGuardPtr(g_metrics)->track_define_property(DefineMetric::ErrorVersioningNoBaseline); return Strings::concat( origin, " was rejected because it uses \"overrides\" and does not have a \"builtin-baseline\".\n", diff --git a/src/vcpkg/vcpkgcmdarguments.cpp b/src/vcpkg/vcpkgcmdarguments.cpp index 12dfbbf079..150323f677 100644 --- a/src/vcpkg/vcpkgcmdarguments.cpp +++ b/src/vcpkg/vcpkgcmdarguments.cpp @@ -39,8 +39,8 @@ namespace vcpkg if (place.has_value()) { msg::println_error(msgTwoFeatureFlagsSpecified, msg::value = flag); - LockGuardPtr(g_metrics)->track_property(StringMetric::Error, - "error feature flag +-" + flag.to_string()); + LockGuardPtr(g_metrics)->track_string_property(StringMetric::Error, + "error feature flag +-" + flag.to_string()); Checks::exit_fail(VCPKG_LINE_INFO); } @@ -79,8 +79,8 @@ namespace vcpkg if (nullptr != option_field) { msg::println_error(msgDuplicateOptions, msg::value = option_name); - LockGuardPtr(g_metrics)->track_property(StringMetric::Error, - "error option specified multiple times"); + LockGuardPtr(g_metrics)->track_string_property(StringMetric::Error, + "error option specified multiple times"); print_usage(); Checks::exit_fail(VCPKG_LINE_INFO); } @@ -93,7 +93,7 @@ namespace vcpkg if (option_field && option_field != new_setting) { msg::println_error(msgConflictingValuesForOption, msg::option = option_name); - LockGuardPtr(g_metrics)->track_property(StringMetric::Error, "error conflicting switches"); + LockGuardPtr(g_metrics)->track_string_property(StringMetric::Error, "error conflicting switches"); print_usage(); Checks::exit_fail(VCPKG_LINE_INFO); } @@ -107,7 +107,7 @@ namespace vcpkg if (new_value.size() == 0) { msg::println_error(msgExpectedValueForOption, msg::option = option_name); - LockGuardPtr(g_metrics)->track_property(StringMetric::Error, "error option name"); + LockGuardPtr(g_metrics)->track_string_property(StringMetric::Error, "error option name"); print_usage(); Checks::exit_fail(VCPKG_LINE_INFO); } @@ -122,7 +122,7 @@ namespace vcpkg if (new_value.size() == 0) { msg::println_error(msgExpectedValueForOption, msg::option = option_name); - LockGuardPtr(g_metrics)->track_property(StringMetric::Error, "error option name"); + LockGuardPtr(g_metrics)->track_string_property(StringMetric::Error, "error option name"); print_usage(); Checks::exit_fail(VCPKG_LINE_INFO); } @@ -189,7 +189,7 @@ namespace vcpkg } msg::println_error(msgExpectedValueForOption, msg::option = option); - LockGuardPtr(g_metrics)->track_property(StringMetric::Error, "error option name"); + LockGuardPtr(g_metrics)->track_string_property(StringMetric::Error, "error option name"); print_usage(); Checks::exit_fail(VCPKG_LINE_INFO); } @@ -262,8 +262,8 @@ namespace vcpkg if (basic_arg.size() >= 2 && basic_arg[0] == '-' && basic_arg[1] != '-') { - LockGuardPtr(g_metrics)->track_property(StringMetric::Error, - "error short options are not supported"); + LockGuardPtr(g_metrics)->track_string_property(StringMetric::Error, + "error short options are not supported"); Checks::msg_exit_with_message(VCPKG_LINE_INFO, msgUnsupportedShortOptions, msg::value = basic_arg); } @@ -837,7 +837,7 @@ namespace vcpkg msg::println_warning( msgSpecifiedFeatureTurnedOff, msg::command_name = el.flag, msg::option = el.option); msg::println_warning(msgDefaultFlag, msg::option = el.flag); - LockGuardPtr(g_metrics)->track_property( + LockGuardPtr(g_metrics)->track_string_property( StringMetric::Warning, Strings::format("warning %s alongside %s", el.flag, el.option)); } } diff --git a/src/vcpkg/vcpkglib.cpp b/src/vcpkg/vcpkglib.cpp index bcd244b422..27e7c87386 100644 --- a/src/vcpkg/vcpkglib.cpp +++ b/src/vcpkg/vcpkglib.cpp @@ -111,7 +111,7 @@ namespace vcpkg if (!was_tracked) { was_tracked = true; - LockGuardPtr(g_metrics)->track_property(StringMetric::ListFile, "update to new format"); + LockGuardPtr(g_metrics)->track_string_property(StringMetric::ListFile, "update to new format"); } // The files are sorted such that directories are placed just before the files they contain diff --git a/src/vcpkg/vcpkgpaths.cpp b/src/vcpkg/vcpkgpaths.cpp index 53c58b18ba..49d48cef08 100644 --- a/src/vcpkg/vcpkgpaths.cpp +++ b/src/vcpkg/vcpkgpaths.cpp @@ -187,10 +187,10 @@ namespace vcpkg { if (auto p_baseline = manifest->builtin_baseline.get()) { - LockGuardPtr(g_metrics)->track_property(DefineMetric::ManifestBaseline); + LockGuardPtr(g_metrics)->track_define_property(DefineMetric::ManifestBaseline); if (!is_git_commit_sha(*p_baseline)) { - LockGuardPtr(g_metrics)->track_property(DefineMetric::VersioningErrorBaseline); + LockGuardPtr(g_metrics)->track_define_property(DefineMetric::VersioningErrorBaseline); Checks::exit_maybe_upgrade(VCPKG_LINE_INFO, "Error: the top-level builtin-baseline%s was not a valid commit sha: " "expected 40 hexadecimal characters.\n%s\n", @@ -325,7 +325,7 @@ namespace vcpkg Path ret; if (args.registries_cache_dir) { - LockGuardPtr(g_metrics)->track_property(DefineMetric::X_VcpkgRegistriesCache); + LockGuardPtr(g_metrics)->track_define_property(DefineMetric::X_VcpkgRegistriesCache); ret = *args.registries_cache_dir; const auto status = get_real_filesystem().status(ret, VCPKG_LINE_INFO); if (!vcpkg::exists(status)) @@ -666,12 +666,12 @@ namespace vcpkg LockGuardPtr metrics(g_metrics); if (default_registry) { - metrics->track_property(StringMetric::RegistriesDefaultRegistryKind, - default_registry->kind().to_string()); + metrics->track_string_property(StringMetric::RegistriesDefaultRegistryKind, + default_registry->kind().to_string()); } else { - metrics->track_property(StringMetric::RegistriesDefaultRegistryKind, "disabled"); + metrics->track_string_property(StringMetric::RegistriesDefaultRegistryKind, "disabled"); } if (other_registries.size() != 0) @@ -682,7 +682,7 @@ namespace vcpkg registry_kinds.push_back(reg.implementation().kind()); } Util::sort_unique_erase(registry_kinds); - metrics->track_property(StringMetric::RegistriesKindsUsed, Strings::join(",", registry_kinds)); + metrics->track_string_property(StringMetric::RegistriesKindsUsed, Strings::join(",", registry_kinds)); } } }