Skip to content
This repository was archived by the owner on Jan 17, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
69f90d6
feat: add arg_parser to user_request
nader-zouaoui Nov 28, 2024
1fbf1c2
feat: update tests
nader-zouaoui Nov 28, 2024
e54f44c
fix: update linker on all configurations
nader-zouaoui Nov 29, 2024
50ff0b1
fix: update file names in project linkers
nader-zouaoui Nov 29, 2024
55ea902
fix: update includes in wperf project
nader-zouaoui Nov 29, 2024
51f4bf9
feat: add export_perf_data argument
nader-zouaoui Nov 29, 2024
1ae1428
feat: added parsed_args vector to keep track
nader-zouaoui Nov 29, 2024
86dcc8a
chore: remove missed comment
nader-zouaoui Nov 29, 2024
1fb59e5
fix: update extra arg description
nader-zouaoui Nov 29, 2024
e188182
feat: add arg_parser to user_request
nader-zouaoui Nov 28, 2024
1e041bd
feat: update tests
nader-zouaoui Nov 28, 2024
2a2146e
fix: update linker on all configurations
nader-zouaoui Nov 29, 2024
984f5a4
fix: update file names in project linkers
nader-zouaoui Nov 29, 2024
816e3c3
fix: update includes in wperf project
nader-zouaoui Nov 29, 2024
9192d13
feat: add export_perf_data argument
nader-zouaoui Nov 29, 2024
5584b5a
feat: added parsed_args vector to keep track
nader-zouaoui Nov 29, 2024
4d06b50
chore: remove missed comment
nader-zouaoui Nov 29, 2024
600d2d1
fix: update extra arg description
nader-zouaoui Nov 29, 2024
0ae8944
docs: add description to export_perf_data flag
nader-zouaoui Nov 29, 2024
9364cfb
chore: removing help function from user request
nader-zouaoui Nov 29, 2024
714332c
Merge branch 'main' into integrate-arg-parser
nader-zouaoui Nov 29, 2024
dfd592f
fix: rename count_command to stat_command
nader-zouaoui Nov 29, 2024
60487f2
fix: refine help output
nader-zouaoui Nov 29, 2024
a87b22c
Merge branch 'arm-developer-tools:main' into integrate-arg-parser
nader-zouaoui Jan 8, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions wperf-lib/wperf-lib.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
<SubSystem>
</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>$(CoreLibraryDependencies);%(AdditionalDependencies);events.obj;output.obj;padding.obj;parsers.obj;pe_file.obj;pmu_device.obj;spe_device.obj;process_api.obj;user_request.obj;utils.obj;wperf.obj;metric.obj;config.obj;timeline.obj;perfdata.obj</AdditionalDependencies>
<AdditionalDependencies>$(CoreLibraryDependencies);%(AdditionalDependencies);events.obj;output.obj;padding.obj;parsers.obj;pe_file.obj;pmu_device.obj;spe_device.obj;process_api.obj;user_request.obj;utils.obj;wperf.obj;metric.obj;config.obj;timeline.obj;perfdata.obj;arg_parser.obj;arg_parser_arg.obj</AdditionalDependencies>
<AdditionalLibraryDirectories>$(SolutionDir)wperf\$(IntDir)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
Expand All @@ -181,7 +181,7 @@
<SubSystem>
</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>$(CoreLibraryDependencies);%(AdditionalDependencies);events.obj;output.obj;padding.obj;parsers.obj;pe_file.obj;pmu_device.obj;spe_device.obj;process_api.obj;user_request.obj;utils.obj;wperf.obj;metric.obj;config.obj;timeline.obj;perfdata.obj</AdditionalDependencies>
<AdditionalDependencies>$(CoreLibraryDependencies);%(AdditionalDependencies);events.obj;output.obj;padding.obj;parsers.obj;pe_file.obj;pmu_device.obj;spe_device.obj;process_api.obj;user_request.obj;utils.obj;wperf.obj;metric.obj;config.obj;timeline.obj;perfdata.obj;arg_parser.obj;arg_parser_arg.obj</AdditionalDependencies>
<AdditionalLibraryDirectories>$(SolutionDir)wperf\$(IntDir)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
Expand All @@ -202,7 +202,7 @@
<SubSystem>
</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>$(CoreLibraryDependencies);%(AdditionalDependencies);events.obj;output.obj;padding.obj;parsers.obj;pe_file.obj;pmu_device.obj;spe_device.obj;process_api.obj;user_request.obj;utils.obj;wperf.obj;metric.obj;config.obj;timeline.obj;perfdata.obj</AdditionalDependencies>
<AdditionalDependencies>$(CoreLibraryDependencies);%(AdditionalDependencies);events.obj;output.obj;padding.obj;parsers.obj;pe_file.obj;pmu_device.obj;spe_device.obj;process_api.obj;user_request.obj;utils.obj;wperf.obj;metric.obj;config.obj;timeline.obj;perfdata.obj;arg_parser.obj;arg_parser_arg.obj</AdditionalDependencies>
<AdditionalLibraryDirectories>$(SolutionDir)wperf\$(IntDir)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
Expand All @@ -223,7 +223,7 @@
<SubSystem>
</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>$(CoreLibraryDependencies);%(AdditionalDependencies);events.obj;output.obj;padding.obj;parsers.obj;pe_file.obj;pmu_device.obj;spe_device.obj;process_api.obj;user_request.obj;utils.obj;wperf.obj;metric.obj;config.obj;timeline.obj;perfdata.obj</AdditionalDependencies>
<AdditionalDependencies>$(CoreLibraryDependencies);%(AdditionalDependencies);events.obj;output.obj;padding.obj;parsers.obj;pe_file.obj;pmu_device.obj;spe_device.obj;process_api.obj;user_request.obj;utils.obj;wperf.obj;metric.obj;config.obj;timeline.obj;perfdata.obj;arg_parser.obj;arg_parser_arg.obj</AdditionalDependencies>
<AdditionalLibraryDirectories>$(SolutionDir)wperf\$(IntDir)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
Expand All @@ -247,7 +247,7 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>$(CoreLibraryDependencies);%(AdditionalDependencies);events.obj;output.obj;padding.obj;parsers.obj;pe_file.obj;pmu_device.obj;spe_device.obj;process_api.obj;user_request.obj;utils.obj;wperf.obj;metric.obj;config.obj;timeline.obj;perfdata.obj</AdditionalDependencies>
<AdditionalDependencies>$(CoreLibraryDependencies);%(AdditionalDependencies);events.obj;output.obj;padding.obj;parsers.obj;pe_file.obj;pmu_device.obj;spe_device.obj;process_api.obj;user_request.obj;utils.obj;wperf.obj;metric.obj;config.obj;timeline.obj;perfdata.obj;arg_parser.obj;arg_parser_arg.obj</AdditionalDependencies>
<AdditionalLibraryDirectories>$(SolutionDir)wperf\$(IntDir)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
Expand All @@ -272,7 +272,7 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>$(CoreLibraryDependencies);%(AdditionalDependencies);events.obj;output.obj;padding.obj;parsers.obj;pe_file.obj;pmu_device.obj;spe_device.obj;process_api.obj;user_request.obj;utils.obj;wperf.obj;metric.obj;config.obj;timeline.obj;perfdata.obj</AdditionalDependencies>
<AdditionalDependencies>$(CoreLibraryDependencies);%(AdditionalDependencies);events.obj;output.obj;padding.obj;parsers.obj;pe_file.obj;pmu_device.obj;spe_device.obj;process_api.obj;user_request.obj;utils.obj;wperf.obj;metric.obj;config.obj;timeline.obj;perfdata.obj;arg_parser.obj;arg_parser_arg.obj</AdditionalDependencies>
<AdditionalLibraryDirectories>$(SolutionDir)wperf\$(IntDir)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
Expand All @@ -293,7 +293,7 @@
<SubSystem>
</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>$(CoreLibraryDependencies);%(AdditionalDependencies);events.obj;output.obj;padding.obj;parsers.obj;pe_file.obj;pmu_device.obj;spe_device.obj;process_api.obj;user_request.obj;utils.obj;wperf.obj;metric.obj;config.obj;timeline.obj;perfdata.obj</AdditionalDependencies>
<AdditionalDependencies>$(CoreLibraryDependencies);%(AdditionalDependencies);events.obj;output.obj;padding.obj;parsers.obj;pe_file.obj;pmu_device.obj;spe_device.obj;process_api.obj;user_request.obj;utils.obj;wperf.obj;metric.obj;config.obj;timeline.obj;perfdata.obj;arg_parser.obj;arg_parser_arg.obj</AdditionalDependencies>
<AdditionalLibraryDirectories>$(SolutionDir)wperf\$(IntDir)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
Expand All @@ -314,7 +314,7 @@
<SubSystem>
</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>$(CoreLibraryDependencies);%(AdditionalDependencies);events.obj;output.obj;padding.obj;parsers.obj;pe_file.obj;pmu_device.obj;spe_device.obj;process_api.obj;user_request.obj;utils.obj;wperf.obj;metric.obj;config.obj;timeline.obj;perfdata.obj</AdditionalDependencies>
<AdditionalDependencies>$(CoreLibraryDependencies);%(AdditionalDependencies);events.obj;output.obj;padding.obj;parsers.obj;pe_file.obj;pmu_device.obj;spe_device.obj;process_api.obj;user_request.obj;utils.obj;wperf.obj;metric.obj;config.obj;timeline.obj;perfdata.obj;arg_parser.obj;arg_parser_arg.obj</AdditionalDependencies>
<AdditionalLibraryDirectories>$(SolutionDir)wperf\$(IntDir)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
Expand All @@ -339,7 +339,7 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
<AdditionalDependencies>$(CoreLibraryDependencies);%(AdditionalDependencies);events.obj;output.obj;padding.obj;parsers.obj;pe_file.obj;pmu_device.obj;spe_device.obj;process_api.obj;user_request.obj;utils.obj;wperf.obj;metric.obj;config.obj;timeline.obj;perfdata.obj</AdditionalDependencies>
<AdditionalDependencies>$(CoreLibraryDependencies);%(AdditionalDependencies);events.obj;output.obj;padding.obj;parsers.obj;pe_file.obj;pmu_device.obj;spe_device.obj;process_api.obj;user_request.obj;utils.obj;wperf.obj;metric.obj;config.obj;timeline.obj;perfdata.obj;arg_parser.obj;arg_parser_arg.obj</AdditionalDependencies>
<AdditionalLibraryDirectories>$(SolutionDir)wperf\$(IntDir)</AdditionalLibraryDirectories>
</Link>
</ItemDefinitionGroup>
Expand Down
19 changes: 10 additions & 9 deletions wperf-test/wperf-test-arg_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "CppUnitTest.h"
#include <unordered_map>
#include "wperf/arg_parser.h"
#include "wperf/exception.h"

using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace ArgParser;
Expand Down Expand Up @@ -61,7 +62,7 @@ namespace wperftest
const wchar_t* argv[] = { L"wperf", L"test", L"-v", L"--json", L"random" };
const int argc = _countof(argv);
arg_parser parser;
Assert::ExpectException<std::invalid_argument>([&parser, argc, &argv]() {
Assert::ExpectException<fatal_exception>([&parser, argc, &argv]() {
parser.parse(argc, argv);
}
);
Expand Down Expand Up @@ -117,7 +118,7 @@ namespace wperftest
const wchar_t* argv[] = { L"wperf", L"sample", L"--timeout" };
const int argc = _countof(argv);
arg_parser parser;
Assert::ExpectException<std::invalid_argument>([&parser, argc, &argv]() {
Assert::ExpectException<fatal_exception>([&parser, argc, &argv]() {
parser.parse(argc, argv);
}
);
Expand All @@ -129,7 +130,7 @@ namespace wperftest
const wchar_t* argv[] = { L"wperf", L"invalid_command" };
const int argc = _countof(argv);
arg_parser parser;
Assert::ExpectException<std::invalid_argument>([&parser, argc, &argv]() {
Assert::ExpectException<fatal_exception>([&parser, argc, &argv]() {
parser.parse(argc, argv);
}
);
Expand All @@ -150,7 +151,7 @@ namespace wperftest
const wchar_t* argv[] = { L"wperf", L"sample", L"--timeout", L"5.4", L"ms" };
const int argc = _countof(argv);
arg_parser parser;
Assert::ExpectException<std::invalid_argument>([&parser, argc, &argv]() {
Assert::ExpectException<fatal_exception>([&parser, argc, &argv]() {
parser.parse(argc, argv);
}
);
Expand Down Expand Up @@ -266,7 +267,7 @@ namespace wperftest
const wchar_t* argv[] = { L"wperf", L"sample", L"--unknown" };
const int argc = _countof(argv);
arg_parser parser;
Assert::ExpectException<std::invalid_argument>([&parser, argc, &argv]() {
Assert::ExpectException<fatal_exception>([&parser, argc, &argv]() {
parser.parse(argc, argv);
}
);
Expand All @@ -278,7 +279,7 @@ namespace wperftest
const wchar_t* argv[] = { L"wperf", L"--annotate", L"--json" };
const int argc = _countof(argv);
arg_parser parser;
Assert::ExpectException<std::invalid_argument>([&parser, argc, &argv]() {
Assert::ExpectException<fatal_exception>([&parser, argc, &argv]() {
parser.parse(argc, argv);
}
);
Expand Down Expand Up @@ -309,7 +310,7 @@ namespace wperftest
Assert::IsFalse(parser.version_command.is_set());
Assert::IsFalse(parser.detect_command.is_set());
Assert::IsFalse(parser.sample_command.is_set());
Assert::IsTrue(parser.count_command.is_set());
Assert::IsTrue(parser.stat_command.is_set());
Assert::IsFalse(parser.man_command.is_set());

// Check all _arg flags setup
Expand Down Expand Up @@ -358,7 +359,7 @@ namespace wperftest
Assert::IsFalse(parser.version_command.is_set());
Assert::IsFalse(parser.detect_command.is_set());
Assert::IsFalse(parser.sample_command.is_set());
Assert::IsFalse(parser.count_command.is_set());
Assert::IsFalse(parser.stat_command.is_set());
Assert::IsFalse(parser.man_command.is_set());

// Check all _arg flags setup
Expand Down Expand Up @@ -416,7 +417,7 @@ namespace wperftest
Assert::IsFalse(parser.version_command.is_set());
Assert::IsFalse(parser.detect_command.is_set());
Assert::IsFalse(parser.sample_command.is_set());
Assert::IsFalse(parser.count_command.is_set());
Assert::IsFalse(parser.stat_command.is_set());
Assert::IsFalse(parser.man_command.is_set());

// Check all _opt flags setup
Expand Down
6 changes: 3 additions & 3 deletions wperf-test/wperf-test-arg_parser_arg-utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,21 @@ namespace wperftest
{
std::wstring input = L"Line one.\nLine two is a bit longer.\nShort.";
size_t max_width = 15;
std::wstring expected = L"Line one.\n\nLine two is a\nbit longer.\n\nShort.";
std::wstring expected = L"Line one.\nLine two is a\nbit longer.\nShort.";
Assert::AreEqual(expected, arg_parser_format_string_to_length(input, max_width));
}
TEST_METHOD(TestTrailingNewlineRemoval)
{
std::wstring input = L"Line one.\nLine two is a bit longer.\nShort.\n";
size_t max_width = 15;
std::wstring expected = L"Line one.\n\nLine two is a\nbit longer.\n\nShort.";
std::wstring expected = L"Line one.\nLine two is a\nbit longer.\nShort.";
Assert::AreEqual(expected, arg_parser_format_string_to_length(input, max_width));
}
TEST_METHOD(TestMultipleLinesAndMultipleTrailingReturnToLines)
{
std::wstring input = L"Line one.\nLine two is a bit longer.\nShort.\n\n\n\n\n\n\n";
size_t max_width = 15;
std::wstring expected = L"Line one.\n\nLine two is a\nbit longer.\n\nShort.\n\n\n\n\n\n";
std::wstring expected = L"Line one.\nLine two is a\nbit longer.\nShort.\n\n\n\n\n\n";
Assert::AreEqual(expected, arg_parser_format_string_to_length(input, max_width));
}
TEST_METHOD(MultipleRetrunToLines)
Expand Down
29 changes: 13 additions & 16 deletions wperf/arg_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "arg_parser.h"
#include <iostream>
#include <codecvt>
#include <locale>
#include <cwchar>
#include <vector>
#include <sstream>
#include "arg_parser.h"
#include "output.h"
#include "exception.h"

namespace ArgParser {
arg_parser::arg_parser() {}
Expand Down Expand Up @@ -82,6 +84,7 @@ namespace ArgParser {
{
if (current_flag->parse(raw_args)) {
raw_args.erase(raw_args.begin(), raw_args.begin() + current_flag->get_arg_count() + 1);
parsed_args.push_back(current_flag);
}
}
catch (const std::exception& err)
Expand All @@ -101,26 +104,25 @@ namespace ArgParser {

void arg_parser::print_help() const
{
std::wcout << L"NAME:\n"

m_out.GetOutputStream() << L"NAME:\n"
<< L"\twperf - Performance analysis tools for Windows on Arm\n\n"
<< L"\tUsage: wperf <command> [options]\n\n"
<< L"SYNOPSIS:\n\n";
for (auto& command : m_commands_list)
{
std::wcout << L"\t" << command->get_all_flags_string() << L"\n" << command->get_usage_text() << L"\n";
m_out.GetOutputStream() << L"\t" << command->get_all_flags_string() << L"\n" << command->get_usage_text() << L"\n";
}

std::wcout << L"OPTIONS:\n\n";
m_out.GetOutputStream() << L"OPTIONS:\n\n";
for (auto& flag : m_flags_list)
{
std::wcout << L" " << flag->get_help() << L"\n";
m_out.GetOutputStream() << flag->get_help() << L"\n\n";
}
std::wcout << L"EXAMPLES:\n\n";
m_out.GetOutputStream() << L"EXAMPLES:\n\n";
for (auto& command : m_commands_list)
{
if (command->get_examples().empty()) continue;
std::wcout << L" " << command->get_examples() << L"\n";
m_out.GetOutputStream() << command->get_examples() << L"\n\n";
}
}

Expand All @@ -143,20 +145,15 @@ namespace ArgParser {
std::wstring indicator(pos, L'~');
indicator += L'^';

/*
TODO: THIS function should change to use GetErrorOutputStream before migrating to wperf

*/

std::wostringstream error_message;
error_message << L"Invalid argument detected:\n"
<< command << L"\n"
<< indicator << L"\n";
if (!additional_message.empty()) {
error_message << additional_message << L"\n";
}
std::wcerr << error_message.str();
throw std::invalid_argument("INVALID_ARGUMENT");
m_out.GetErrorOutputStream() << error_message.str();
throw fatal_exception("INVALID_ARGUMENT");
}

#pragma endregion
Expand All @@ -171,7 +168,7 @@ namespace ArgParser {
{
std::wstring example_output;
for (auto& example : m_examples) {
example_output += example + L"\n";
example_output += example + L"\n\n";
}
return arg_parser_add_wstring_behind_multiline_text(arg_parser_format_string_to_length(example_output), L"\t");
}
Expand Down
Loading