Skip to content

Commit

Permalink
Change track_property() call sites
Browse files Browse the repository at this point in the history
  • Loading branch information
vicroms committed Sep 1, 2022
1 parent 012deb6 commit 2d31fb5
Show file tree
Hide file tree
Showing 16 changed files with 66 additions and 78 deletions.
14 changes: 6 additions & 8 deletions src/vcpkg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +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<Metrics>(g_metrics)->track_property(Metrics::StringMetric::VcpkgVersion,
Commands::Version::version.to_string());
LockGuardPtr<Metrics>(g_metrics)->track_property(Metrics::VcpkgVersion, Commands::Version::version.to_string());

if (args.command.empty())
{
Expand All @@ -68,12 +67,11 @@ static void inner(vcpkg::Filesystem& fs, const VcpkgCmdArguments& args)
}
};

LockGuardPtr<Metrics>(g_metrics)->track_property(Metrics::BoolMetric::OptionOverlayPorts,
!args.overlay_ports.empty());
LockGuardPtr<Metrics>(g_metrics)->track_property(Metrics::OptionOverlayPorts, !args.overlay_ports.empty());

if (const auto command_function = find_command(Commands::get_available_basic_commands()))
{
LockGuardPtr<Metrics>(g_metrics)->track_property(Metrics::StringMetric::CommandName, command_function->name);
LockGuardPtr<Metrics>(g_metrics)->track_property(Metrics::CommandName, command_function->name);
return command_function->function->perform_and_exit(args, fs);
}

Expand All @@ -84,7 +82,7 @@ static void inner(vcpkg::Filesystem& fs, const VcpkgCmdArguments& args)

if (const auto command_function = find_command(Commands::get_available_paths_commands()))
{
LockGuardPtr<Metrics>(g_metrics)->track_property(Metrics::StringMetric::CommandName, command_function->name);
LockGuardPtr<Metrics>(g_metrics)->track_property(Metrics::CommandName, command_function->name);
return command_function->function->perform_and_exit(args, paths);
}

Expand All @@ -95,7 +93,7 @@ static void inner(vcpkg::Filesystem& fs, const VcpkgCmdArguments& args)

if (const auto command_function = find_command(Commands::get_available_triplet_commands()))
{
LockGuardPtr<Metrics>(g_metrics)->track_property(Metrics::StringMetric::CommandName, command_function->name);
LockGuardPtr<Metrics>(g_metrics)->track_property(Metrics::CommandName, command_function->name);
return command_function->function->perform_and_exit(args, paths, default_triplet, host_triplet);
}

Expand Down Expand Up @@ -318,7 +316,7 @@ int main(const int argc, const char* const* const argv)
exc_msg = "unknown error(...)";
}

LockGuardPtr<Metrics>(g_metrics)->track_property(Metrics::StringMetric::Error, exc_msg);
LockGuardPtr<Metrics>(g_metrics)->track_property(Metrics::Error, exc_msg);

fflush(stdout);
msg::println(msgVcpkgHasCrashed);
Expand Down
28 changes: 14 additions & 14 deletions src/vcpkg/binarycaching.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1579,7 +1579,7 @@ namespace
auto maybe_cachepath = get_environment_variable("VCPKG_DEFAULT_BINARY_CACHE");
if (auto p_str = maybe_cachepath.get())
{
LockGuardPtr<Metrics>(g_metrics)->track_property(Metrics::DefineMetric::VcpkgDefaultBinaryCache);
LockGuardPtr<Metrics>(g_metrics)->track_property(Metrics::VcpkgDefaultBinaryCache);
Path path = *p_str;
path.make_preferred();
if (!get_real_filesystem().is_directory(path))
Expand Down Expand Up @@ -1998,14 +1998,14 @@ namespace
}

static const std::map<StringLiteral, Metrics::DefineMetric> 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},
{"aws", Metrics::BinaryCachingAws},
{"azblob", Metrics::BinaryCachingAzBlob},
{"cos", Metrics::BinaryCachingCos},
{"default", Metrics::BinaryCachingDefault},
{"files", Metrics::BinaryCachingFiles},
{"gcs", Metrics::BinaryCachingGcs},
{"http", Metrics::BinaryCachingHttp},
{"nuget", Metrics::BinaryCachingNuget},
};
auto metrics = LockGuardPtr<Metrics>(g_metrics);
for (const auto& cache_provider : state->binary_cache_providers)
Expand Down Expand Up @@ -2147,7 +2147,7 @@ ExpectedS<DownloadManagerConfig> vcpkg::parse_download_configuration(const Optio
{
if (!arg || arg.get()->empty()) return DownloadManagerConfig{};

LockGuardPtr<Metrics>(g_metrics)->track_property(Metrics::DefineMetric::AssetSource);
LockGuardPtr<Metrics>(g_metrics)->track_property(Metrics::AssetSource);

AssetSourcesState s;
AssetSourcesParser parser(*arg.get(), Strings::concat("$", VcpkgCmdArguments::ASSET_SOURCES_ENV), &s);
Expand Down Expand Up @@ -2202,12 +2202,12 @@ ExpectedS<BinaryConfigParserState> vcpkg::create_binary_providers_from_configs_p
LockGuardPtr<Metrics> metrics(g_metrics);
if (!env_string.empty())
{
metrics->track_property(Metrics::DefineMetric::VcpkgBinarySources);
metrics->track_property(Metrics::VcpkgBinarySources);
}

if (args.size() != 0)
{
metrics->track_property(Metrics::DefineMetric::BinaryCachingSource);
metrics->track_property(Metrics::BinaryCachingSource);
}
}

Expand Down Expand Up @@ -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<Metrics>(g_metrics)->track_property(Metrics::DefineMetric::VcpkgNugetRepository);
LockGuardPtr<Metrics>(g_metrics)->track_property(Metrics::VcpkgNugetRepository);
return {std::move(*p)};
}

Expand All @@ -2362,7 +2362,7 @@ details::NuGetRepoInfo details::get_nuget_repo_info_from_env()
return {};
}

LockGuardPtr<Metrics>(g_metrics)->track_property(Metrics::DefineMetric::GitHubRepository);
LockGuardPtr<Metrics>(g_metrics)->track_property(Metrics::GitHubRepository);
return {Strings::concat(gh_server, '/', gh_repo, ".git"),
get_environment_variable("GITHUB_REF").value_or(""),
get_environment_variable("GITHUB_SHA").value_or("")};
Expand Down
4 changes: 2 additions & 2 deletions src/vcpkg/build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(Metrics::Error, "build failed");
metrics->track_property(Metrics::BuildError, spec_string);
const auto logs = buildpath / Strings::concat("error-logs-", action.spec.triplet(), ".txt");
std::vector<std::string> error_logs;
if (fs.exists(logs, VCPKG_LINE_INFO))
Expand Down
8 changes: 4 additions & 4 deletions src/vcpkg/commands.add.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ namespace vcpkg::Commands
auto artifact_hash = Hash::get_string_hash(artifact_name, Hash::Algorithm::Sha256);
{
auto metrics = LockGuardPtr<Metrics>(g_metrics);
metrics->track_property(Metrics::StringMetric::CommandContext, "artifact");
metrics->track_property(Metrics::StringMetric::CommandArgs, artifact_hash);
metrics->track_property(Metrics::CommandContext, "artifact");
metrics->track_property(Metrics::CommandArgs, artifact_hash);
} // unlock g_metrics

std::string ce_args[] = {"add", artifact_name};
Expand Down Expand Up @@ -122,8 +122,8 @@ namespace vcpkg::Commands
}));
{
auto metrics = LockGuardPtr<Metrics>(g_metrics);
metrics->track_property(Metrics::StringMetric::CommandContext, "port");
metrics->track_property(Metrics::StringMetric::CommandArgs, command_args_hash);
metrics->track_property(Metrics::CommandContext, "port");
metrics->track_property(Metrics::CommandArgs, command_args_hash);
} // unlock metrics

Checks::exit_success(VCPKG_LINE_INFO);
Expand Down
8 changes: 4 additions & 4 deletions src/vcpkg/commands.find.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Metrics>(g_metrics);
metrics->track_property(Metrics::StringMetric::CommandContext, "artifact");
metrics->track_property(Metrics::CommandContext, "artifact");
if (auto p_filter_hash = filter_hash.get())
{
metrics->track_property(Metrics::StringMetric::CommandArgs, *p_filter_hash);
metrics->track_property(Metrics::CommandArgs, *p_filter_hash);
}
} // unlock metrics

Expand All @@ -252,10 +252,10 @@ namespace vcpkg::Commands
Optional<std::string> filter_hash = filter.map(Hash::get_string_sha256);
{
auto metrics = LockGuardPtr<Metrics>(g_metrics);
metrics->track_property(Metrics::StringMetric::CommandContext, "port");
metrics->track_property(Metrics::CommandContext, "port");
if (auto p_filter_hash = filter_hash.get())
{
metrics->track_property(Metrics::StringMetric::CommandArgs, *p_filter_hash);
metrics->track_property(Metrics::CommandArgs, *p_filter_hash);
}
} // unlock metrics

Expand Down
4 changes: 2 additions & 2 deletions src/vcpkg/commands.integrate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,8 @@ namespace vcpkg::Commands::Integrate
.append_raw("\n" + script_path.generic_u8string()));
{
auto locked_metrics = LockGuardPtr<Metrics>(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(Metrics::Error, "powershell script failed");
locked_metrics->track_property(Metrics::Title, TITLE.to_string());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/vcpkg/commands.setinstalled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Metrics>(g_metrics)->track_property(Metrics::DefineMetric::X_WriteNugetPackagesConfig);
LockGuardPtr<Metrics>(g_metrics)->track_property(Metrics::X_WriteNugetPackagesConfig);
pkgsconfig = it_pkgsconfig->second;
}

Expand Down
3 changes: 1 addition & 2 deletions src/vcpkg/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ namespace vcpkg
if (!paths.is_valid_triplet(t))
{
print2(Color::error, "Error: invalid triplet: ", t, '\n');
LockGuardPtr<Metrics>(g_metrics)->track_property(Metrics::StringMetric::Error,
"invalid triplet: " + t.to_string());
LockGuardPtr<Metrics>(g_metrics)->track_property(Metrics::Error, "invalid triplet: " + t.to_string());
Help::help_topic_valid_triplet(paths);
Checks::exit_fail(VCPKG_LINE_INFO);
}
Expand Down
13 changes: 6 additions & 7 deletions src/vcpkg/install.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -875,8 +875,7 @@ namespace vcpkg
: UnsupportedPortAction::Error;
const bool no_print_usage = Util::Sets::contains(options.switches, OPTION_NO_PRINT_USAGE);

LockGuardPtr<Metrics>(g_metrics)->track_property(Metrics::BoolMetric::InstallManifestMode,
paths.manifest_mode_enabled());
LockGuardPtr<Metrics>(g_metrics)->track_property(Metrics::InstallManifestMode, paths.manifest_mode_enabled());

if (auto p = paths.get_manifest().get())
{
Expand Down Expand Up @@ -966,7 +965,7 @@ namespace vcpkg
auto it_pkgsconfig = options.settings.find(OPTION_WRITE_PACKAGES_CONFIG);
if (it_pkgsconfig != options.settings.end())
{
LockGuardPtr<Metrics>(g_metrics)->track_property(Metrics::DefineMetric::X_WriteNugetPackagesConfig);
LockGuardPtr<Metrics>(g_metrics)->track_property(Metrics::X_WriteNugetPackagesConfig);
pkgsconfig = Path(it_pkgsconfig->second);
}
auto maybe_manifest_scf =
Expand Down Expand Up @@ -1034,12 +1033,12 @@ namespace vcpkg
return dep.constraint.type != VersionConstraintKind::None;
}))
{
LockGuardPtr<Metrics>(g_metrics)->track_property(Metrics::DefineMetric::ManifestVersionConstraint);
LockGuardPtr<Metrics>(g_metrics)->track_property(Metrics::ManifestVersionConstraint);
}

if (!manifest_core.overrides.empty())
{
LockGuardPtr<Metrics>(g_metrics)->track_property(Metrics::DefineMetric::ManifestOverrides);
LockGuardPtr<Metrics>(g_metrics)->track_property(Metrics::ManifestOverrides);
}

auto verprovider = make_versioned_portfile_provider(paths);
Expand Down Expand Up @@ -1169,7 +1168,7 @@ namespace vcpkg
auto it_pkgsconfig = options.settings.find(OPTION_WRITE_PACKAGES_CONFIG);
if (it_pkgsconfig != options.settings.end())
{
LockGuardPtr<Metrics>(g_metrics)->track_property(Metrics::DefineMetric::X_WriteNugetPackagesConfig);
LockGuardPtr<Metrics>(g_metrics)->track_property(Metrics::X_WriteNugetPackagesConfig);
compute_all_abis(paths, action_plan, var_provider, status_db);

auto pkgsconfig_path = paths.original_cwd / it_pkgsconfig->second;
Expand Down Expand Up @@ -1318,6 +1317,6 @@ namespace vcpkg
Hash::get_string_hash(version_as_string, Hash::Algorithm::Sha256));
}

LockGuardPtr<Metrics>(g_metrics)->track_property(Metrics::StringMetric::InstallPlan_1, specs_string);
LockGuardPtr<Metrics>(g_metrics)->track_property(Metrics::InstallPlan_1, specs_string);
}
}
2 changes: 1 addition & 1 deletion src/vcpkg/metrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,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(Metrics::UserMac, config.user_mac);

g_metrics_disabled = false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/vcpkg/portfileprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ namespace vcpkg
}
else
{
LockGuardPtr<Metrics>(g_metrics)->track_property(Metrics::DefineMetric::VersioningErrorVersion);
LockGuardPtr<Metrics>(g_metrics)->track_property(Metrics::VersioningErrorVersion);
return maybe_path.error();
}
}
Expand Down
12 changes: 4 additions & 8 deletions src/vcpkg/registries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ namespace
e.commit_id(), registry_versions_dir_name.to_string());
if (!maybe_tree)
{
LockGuardPtr<Metrics>(g_metrics)->track_property(
Metrics::DefineMetric::RegistriesErrorNoVersionsAtCommit);
LockGuardPtr<Metrics>(g_metrics)->track_property(Metrics::RegistriesErrorNoVersionsAtCommit);
Checks::exit_with_message(
VCPKG_LINE_INFO,
"Error: could not find the git tree for `versions` in repo `%s` at commit `%s`: %s",
Expand Down Expand Up @@ -661,8 +660,7 @@ namespace
auto maybe_err = m_paths.git_fetch(m_repo, m_baseline_identifier);
if (!maybe_err)
{
LockGuardPtr<Metrics>(g_metrics)->track_property(
Metrics::DefineMetric::RegistriesErrorCouldNotFindBaseline);
LockGuardPtr<Metrics>(g_metrics)->track_property(Metrics::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",
Expand All @@ -678,8 +676,7 @@ namespace

if (!maybe_contents)
{
LockGuardPtr<Metrics>(g_metrics)->track_property(
Metrics::DefineMetric::RegistriesErrorCouldNotFindBaseline);
LockGuardPtr<Metrics>(g_metrics)->track_property(Metrics::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,
Expand All @@ -697,8 +694,7 @@ namespace
}
else
{
LockGuardPtr<Metrics>(g_metrics)->track_property(
Metrics::DefineMetric::RegistriesErrorCouldNotFindBaseline);
LockGuardPtr<Metrics>(g_metrics)->track_property(Metrics::RegistriesErrorCouldNotFindBaseline);
Checks::exit_maybe_upgrade(
VCPKG_LINE_INFO,
"The baseline.json from commit `\"%s\"` in the repo %s did not contain a \"default\" field.",
Expand Down
Loading

0 comments on commit 2d31fb5

Please sign in to comment.