Introduce Metrics namespace
MODIFY
include/metrics.h
include/metrics.h
#include <string>
-namespace vcpkg
+namespace vcpkg::Metrics
{
void SetSendMetrics(bool should_send_metrics);
void SetPrintMetrics(bool should_print_metrics);

MODIFY
src/commands_build.cpp
src/commands_build.cpp
@@ -68,12 +68,12 @@ namespace vcpkg::Commands::Build
int return_code = System::cmd_execute_clean(command);
auto buildtimeus = timer.microseconds();
- TrackMetric("buildtimeus-" + spec.toString(), buildtimeus);
+ Metrics::TrackMetric("buildtimeus-" + spec.toString(), buildtimeus);
if (return_code != 0)
{
- TrackProperty("error", "build failed");
- TrackProperty("build_error", spec.toString());
+ Metrics::TrackProperty("error", "build failed");
+ Metrics::TrackProperty("build_error", spec.toString());
return BuildResult::BUILD_FAILED;
}

MODIFY
src/commands_install.cpp
src/commands_install.cpp
@@ -210,7 +210,7 @@ namespace vcpkg::Commands::Install
specs_string.push_back(',');
specs_string.append(install_plan[i].spec.toString());
}
- TrackProperty("installplan", specs_string);
+ Metrics::TrackProperty("installplan", specs_string);
// execute the plan
for (const package_spec_with_install_plan& action : install_plan)

MODIFY
src/commands_version.cpp
src/commands_version.cpp
@@ -19,7 +19,7 @@ namespace vcpkg::Commands::Version
#ifndef NDEBUG
+ std::string("-debug")
#endif
- + std::string(GetCompiledMetricsEnabled() ? "" : "-external");
+ + std::string(Metrics::GetCompiledMetricsEnabled() ? "" : "-external");
return s_version;
}

MODIFY
src/metrics.cpp
src/metrics.cpp
#include "vcpkg_Strings.h"
#include "vcpkg_System.h"
-namespace vcpkg
+namespace vcpkg::Metrics
{
static std::string GetCurrentDateTime()
{

MODIFY
src/vcpkg.cpp
src/vcpkg.cpp
@@ -26,7 +26,7 @@ void invalid_command(const std::string& cmd)
static void inner(const vcpkg_cmd_arguments& args)
{
- TrackProperty("command", args.command);
+ Metrics::TrackProperty("command", args.command);
if (args.command.empty())
{
Commands::Help::print_usage();
@@ -130,7 +130,7 @@ static void loadConfig()
auto user_time = keys["User-Since"];
if (!user_id.empty() && !user_time.empty())
{
- SetUserInformation(user_id, user_time);
+ Metrics::SetUserInformation(user_id, user_time);
return;
}
}
@@ -139,8 +139,8 @@ static void loadConfig()
// config file not found, could not be read, or invalid
std::string user_id, user_time;
- InitUserInformation(user_id, user_time);
- SetUserInformation(user_id, user_time);
+ Metrics::InitUserInformation(user_id, user_time);
+ Metrics::SetUserInformation(user_id, user_time);
try
{
std::error_code ec;
@@ -183,23 +183,23 @@ int wmain(const int argc, const wchar_t* const* const argv)
atexit([]()
{
auto elapsed_us = g_timer.microseconds();
- TrackMetric("elapsed_us", elapsed_us);
- Flush();
+ Metrics::TrackMetric("elapsed_us", elapsed_us);
+ Metrics::Flush();
});
- TrackProperty("version", Commands::Version::version());
+ Metrics::TrackProperty("version", Commands::Version::version());
const std::string trimmed_command_line = trim_path_from_command_line(Strings::utf16_to_utf8(GetCommandLineW()));
- TrackProperty("cmdline", trimmed_command_line);
+ Metrics::TrackProperty("cmdline", trimmed_command_line);
loadConfig();
- TrackProperty("sqmuser", GetSQMUser());
+ Metrics::TrackProperty("sqmuser", Metrics::GetSQMUser());
const vcpkg_cmd_arguments args = vcpkg_cmd_arguments::create_from_command_line(argc, argv);
if (args.printmetrics != opt_bool_t::UNSPECIFIED)
- SetPrintMetrics(args.printmetrics == opt_bool_t::ENABLED);
+ Metrics::SetPrintMetrics(args.printmetrics == opt_bool_t::ENABLED);
if (args.sendmetrics != opt_bool_t::UNSPECIFIED)
- SetSendMetrics(args.sendmetrics == opt_bool_t::ENABLED);
+ Metrics::SetSendMetrics(args.sendmetrics == opt_bool_t::ENABLED);
if (args.debug != opt_bool_t::UNSPECIFIED)
{
@@ -226,7 +226,7 @@ int wmain(const int argc, const wchar_t* const* const argv)
{
exc_msg = "unknown error(...)";
}
- TrackProperty("error", exc_msg);
+ Metrics::TrackProperty("error", exc_msg);
fflush(stdout);
System::print(

MODIFY
src/vcpkg_Input.cpp
src/vcpkg_Input.cpp
@@ -26,7 +26,7 @@ namespace vcpkg::Input
if (!paths.is_valid_triplet(t))
{
System::println(System::color::error, "Error: invalid triplet: %s", t.canonical_name());
- TrackProperty("error", "invalid triplet: " + t.canonical_name());
+ Metrics::TrackProperty("error", "invalid triplet: " + t.canonical_name());
Commands::Help::help_topic_valid_triplet(paths);
Checks::exit_fail(VCPKG_LINE_INFO);
}

MODIFY
src/vcpkg_cmd_arguments.cpp
src/vcpkg_cmd_arguments.cpp
@@ -15,7 +15,7 @@ namespace vcpkg
if (arg_begin == arg_end)
{
System::println(System::color::error, "Error: expected value after %s", option_name);
- TrackProperty("error", "error option name");
+ Metrics::TrackProperty("error", "error option name");
Commands::Help::print_usage();
Checks::exit_fail(VCPKG_LINE_INFO);
}
@@ -23,7 +23,7 @@ namespace vcpkg
if (option_field != nullptr)
{
System::println(System::color::error, "Error: %s specified multiple times", option_name);
- TrackProperty("error", "error option specified multiple times");
+ Metrics::TrackProperty("error", "error option specified multiple times");
Commands::Help::print_usage();
Checks::exit_fail(VCPKG_LINE_INFO);
}
@@ -39,7 +39,7 @@ namespace vcpkg
if (option_field != opt_bool_t::UNSPECIFIED && option_field != new_setting)
{
System::println(System::color::error, "Error: conflicting values specified for --%s", option_name);
- TrackProperty("error", "error conflicting switches");
+ Metrics::TrackProperty("error", "error conflicting switches");
Commands::Help::print_usage();
Checks::exit_fail(VCPKG_LINE_INFO);
}
@@ -72,7 +72,7 @@ namespace vcpkg
if (arg[0] == '-' && arg[1] != '-')
{
- TrackProperty("error", "error short options are not supported");
+ Metrics::TrackProperty("error", "error short options are not supported");
Checks::exit_with_message(VCPKG_LINE_INFO, "Error: short options are not supported: %s", arg);
}

MODIFY
src/vcpkg_metrics_uploader.cpp
src/vcpkg_metrics_uploader.cpp
@@ -13,5 +13,5 @@ int WINAPI WinMain(_In_ HINSTANCE, _In_opt_ HINSTANCE, _In_ LPSTR, _In_ int)
szArgList = CommandLineToArgvW(GetCommandLineW(), &argCount);
Checks::check_exit(VCPKG_LINE_INFO, argCount == 2, "Requires exactly one argument, the path to the payload file");
- Upload(Files::read_contents(szArgList[1]).value_or_exit(VCPKG_LINE_INFO));
+ Metrics::Upload(Files::read_contents(szArgList[1]).value_or_exit(VCPKG_LINE_INFO));
}

MODIFY
src/vcpkg_paths.cpp
src/vcpkg_paths.cpp
@@ -74,8 +74,8 @@ namespace vcpkg
if (rc.exit_code)
{
System::println(System::color::error, "Launching powershell failed or was denied");
- TrackProperty("error", "powershell install failed");
- TrackProperty("installcmd", install_cmd);
+ Metrics::TrackProperty("error", "powershell install failed");
+ Metrics::TrackProperty("installcmd", install_cmd);
Checks::exit_with_code(VCPKG_LINE_INFO, rc.exit_code);
}
@@ -166,7 +166,7 @@ namespace vcpkg
if (paths.root.empty())
{
- TrackProperty("error", "Invalid vcpkg root directory");
+ Metrics::TrackProperty("error", "Invalid vcpkg root directory");
Checks::exit_with_message(VCPKG_LINE_INFO, "Invalid vcpkg root directory: %s", paths.root.string());
}

MODIFY
src/vcpkglib.cpp
src/vcpkglib.cpp
@@ -120,7 +120,7 @@ namespace vcpkg
if (!was_tracked)
{
was_tracked = true;
- TrackProperty("listfile", "update to new format");
+ Metrics::TrackProperty("listfile", "update to new format");
}
// The files are sorted such that directories are placed just before the files they contain

Introduce Metrics namespace