Introduce Metrics namespace

This commit is contained in:
Alexander Karatarakis 2017-04-03 14:26:13 -07:00
parent 3033da9142
commit c86dbc960e
11 changed files with 29 additions and 29 deletions

View File

@ -2,7 +2,7 @@
#include <string> #include <string>
namespace vcpkg namespace vcpkg::Metrics
{ {
void SetSendMetrics(bool should_send_metrics); void SetSendMetrics(bool should_send_metrics);
void SetPrintMetrics(bool should_print_metrics); void SetPrintMetrics(bool should_print_metrics);

View File

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

View File

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

View File

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

View File

@ -4,7 +4,7 @@
#include "vcpkg_Strings.h" #include "vcpkg_Strings.h"
#include "vcpkg_System.h" #include "vcpkg_System.h"
namespace vcpkg namespace vcpkg::Metrics
{ {
static std::string GetCurrentDateTime() static std::string GetCurrentDateTime()
{ {

View File

@ -26,7 +26,7 @@ void invalid_command(const std::string& cmd)
static void inner(const vcpkg_cmd_arguments& args) static void inner(const vcpkg_cmd_arguments& args)
{ {
TrackProperty("command", args.command); Metrics::TrackProperty("command", args.command);
if (args.command.empty()) if (args.command.empty())
{ {
Commands::Help::print_usage(); Commands::Help::print_usage();
@ -130,7 +130,7 @@ static void loadConfig()
auto user_time = keys["User-Since"]; auto user_time = keys["User-Since"];
if (!user_id.empty() && !user_time.empty()) if (!user_id.empty() && !user_time.empty())
{ {
SetUserInformation(user_id, user_time); Metrics::SetUserInformation(user_id, user_time);
return; return;
} }
} }
@ -139,8 +139,8 @@ static void loadConfig()
// config file not found, could not be read, or invalid // config file not found, could not be read, or invalid
std::string user_id, user_time; std::string user_id, user_time;
InitUserInformation(user_id, user_time); Metrics::InitUserInformation(user_id, user_time);
SetUserInformation(user_id, user_time); Metrics::SetUserInformation(user_id, user_time);
try try
{ {
std::error_code ec; std::error_code ec;
@ -183,23 +183,23 @@ int wmain(const int argc, const wchar_t* const* const argv)
atexit([]() atexit([]()
{ {
auto elapsed_us = g_timer.microseconds(); auto elapsed_us = g_timer.microseconds();
TrackMetric("elapsed_us", elapsed_us); Metrics::TrackMetric("elapsed_us", elapsed_us);
Flush(); 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())); 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(); loadConfig();
TrackProperty("sqmuser", GetSQMUser()); Metrics::TrackProperty("sqmuser", Metrics::GetSQMUser());
const vcpkg_cmd_arguments args = vcpkg_cmd_arguments::create_from_command_line(argc, argv); const vcpkg_cmd_arguments args = vcpkg_cmd_arguments::create_from_command_line(argc, argv);
if (args.printmetrics != opt_bool_t::UNSPECIFIED) 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) 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) 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(...)"; exc_msg = "unknown error(...)";
} }
TrackProperty("error", exc_msg); Metrics::TrackProperty("error", exc_msg);
fflush(stdout); fflush(stdout);
System::print( System::print(

View File

@ -26,7 +26,7 @@ namespace vcpkg::Input
if (!paths.is_valid_triplet(t)) if (!paths.is_valid_triplet(t))
{ {
System::println(System::color::error, "Error: invalid triplet: %s", t.canonical_name()); 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); Commands::Help::help_topic_valid_triplet(paths);
Checks::exit_fail(VCPKG_LINE_INFO); Checks::exit_fail(VCPKG_LINE_INFO);
} }

View File

@ -15,7 +15,7 @@ namespace vcpkg
if (arg_begin == arg_end) if (arg_begin == arg_end)
{ {
System::println(System::color::error, "Error: expected value after %s", option_name); 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(); Commands::Help::print_usage();
Checks::exit_fail(VCPKG_LINE_INFO); Checks::exit_fail(VCPKG_LINE_INFO);
} }
@ -23,7 +23,7 @@ namespace vcpkg
if (option_field != nullptr) if (option_field != nullptr)
{ {
System::println(System::color::error, "Error: %s specified multiple times", option_name); 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(); Commands::Help::print_usage();
Checks::exit_fail(VCPKG_LINE_INFO); Checks::exit_fail(VCPKG_LINE_INFO);
} }
@ -39,7 +39,7 @@ namespace vcpkg
if (option_field != opt_bool_t::UNSPECIFIED && option_field != new_setting) if (option_field != opt_bool_t::UNSPECIFIED && option_field != new_setting)
{ {
System::println(System::color::error, "Error: conflicting values specified for --%s", option_name); 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(); Commands::Help::print_usage();
Checks::exit_fail(VCPKG_LINE_INFO); Checks::exit_fail(VCPKG_LINE_INFO);
} }
@ -72,7 +72,7 @@ namespace vcpkg
if (arg[0] == '-' && arg[1] != '-') 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); Checks::exit_with_message(VCPKG_LINE_INFO, "Error: short options are not supported: %s", arg);
} }

View File

@ -13,5 +13,5 @@ int WINAPI WinMain(_In_ HINSTANCE, _In_opt_ HINSTANCE, _In_ LPSTR, _In_ int)
szArgList = CommandLineToArgvW(GetCommandLineW(), &argCount); szArgList = CommandLineToArgvW(GetCommandLineW(), &argCount);
Checks::check_exit(VCPKG_LINE_INFO, argCount == 2, "Requires exactly one argument, the path to the payload file"); 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));
} }

View File

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

View File

@ -120,7 +120,7 @@ namespace vcpkg
if (!was_tracked) if (!was_tracked)
{ {
was_tracked = true; 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 // The files are sorted such that directories are placed just before the files they contain