Skip to content

Commit

Permalink
Allow explicit skips in batch mode (#914)
Browse files Browse the repository at this point in the history
* Allow explicit skips in batch mode

* Fix bug in CLI11 wrapper that inhibits multi-value flag parsing
  • Loading branch information
jherico authored Feb 26, 2024
1 parent ec6d636 commit 780f62f
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 8 deletions.
25 changes: 24 additions & 1 deletion app/plugins/batch_mode/batch_mode.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2020-2023, Arm Limited and Contributors
/* Copyright (c) 2020-2024, Arm Limited and Contributors
*
* SPDX-License-Identifier: Apache-2.0
*
Expand Down Expand Up @@ -65,7 +65,30 @@ void BatchMode::init(const vkb::CommandParser &parser)
categories = parser.as<std::vector<std::string>>(&categories_flag);
}

std::unordered_set<std::string> skips;
if (parser.contains(&skip_flag))
{
skips = parser.as<std::unordered_set<std::string>>(&skip_flag);
}

sample_list = apps::get_samples(categories, tags);
if (!skips.empty())
{
std::vector<apps::AppInfo *> filtered_list;
filtered_list.reserve(sample_list.size());

std::copy_if(
sample_list.begin(), sample_list.end(),
std::back_inserter(filtered_list),
[&](const apps::AppInfo *app) {
return skips.find(app->id) == skips.end();
});

if (filtered_list.size() != sample_list.size())
{
sample_list.swap(filtered_list);
}
}

if (sample_list.empty())
{
Expand Down
10 changes: 6 additions & 4 deletions app/plugins/batch_mode/batch_mode.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ using BatchModeTags = vkb::PluginBase<vkb::tags::Entrypoint, vkb::tags::FullCont

/**
* @brief Batch Mode
*
*
* Run a subset of samples. The next sample in the set will start after the current sample being executed has finished. Using --wrap-to-start will start again from the first sample after the last sample is executed.
*
*
* Usage: vulkan_samples batch --duration 3 --category performance --tag arm
*
*
*/
class BatchMode : public BatchModeTags
{
Expand All @@ -62,7 +62,9 @@ class BatchMode : public BatchModeTags

vkb::FlagCommand categories_flag{vkb::FlagType::ManyValues, "category", "C", "Filter samples by categories"};

vkb::SubCommand batch_cmd{"batch", "Enable batch mode", {&duration_flag, &wrap_flag, &tags_flag, &categories_flag}};
vkb::FlagCommand skip_flag{vkb::FlagType::ManyValues, "skip", "", "Skip a sample by id"};

vkb::SubCommand batch_cmd{"batch", "Enable batch mode", {&duration_flag, &wrap_flag, &tags_flag, &categories_flag, &skip_flag}};

private:
/// The list of suitable samples to be run in conjunction with batch mode
Expand Down
10 changes: 9 additions & 1 deletion framework/platform/parser.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2021-2023, Arm Limited and Contributors
/* Copyright (c) 2021-2024, Arm Limited and Contributors
*
* SPDX-License-Identifier: Apache-2.0
*
Expand All @@ -21,6 +21,7 @@
#include <cstdint>
#include <string>
#include <typeindex>
#include <unordered_set>
#include <vector>

namespace vkb
Expand Down Expand Up @@ -306,6 +307,13 @@ inline bool CommandParser::convert_type(const std::vector<std::string> &values,
return true;
}

template <>
inline bool CommandParser::convert_type(const std::vector<std::string> &values, std::unordered_set<std::string> *type) const
{
*type = std::unordered_set<std::string>(values.begin(), values.end());
return true;
}

template <>
inline bool CommandParser::convert_type(const std::vector<std::string> &values, std::string *type) const
{
Expand Down
14 changes: 12 additions & 2 deletions framework/platform/parsers/CLI11.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2021-2023, Arm Limited and Contributors
/* Copyright (c) 2021-2024, Arm Limited and Contributors
*
* SPDX-License-Identifier: Apache-2.0
*
Expand All @@ -17,6 +17,8 @@

#include "CLI11.h"

#include <climits>

#include "common/logging.h"
#include "common/strings.h"

Expand Down Expand Up @@ -100,7 +102,8 @@ void CLI11CommandParser::parse(CLI11CommandContext *context, FlagCommand *comman
{
CLI::Option *flag;

switch (command->get_flag_type())
auto flagType = command->get_flag_type();
switch (flagType)
{
case FlagType::FlagOnly:
flag = context->cli11->add_flag(command->get_name(), command->get_help_line());
Expand All @@ -109,6 +112,13 @@ void CLI11CommandParser::parse(CLI11CommandContext *context, FlagCommand *comman
case FlagType::ManyValues:
flag = context->cli11->add_option(command->get_name(), command->get_help_line());
break;
default:
throw std::runtime_error("Unknown flag type");
}

if (flagType == FlagType::ManyValues)
{
flag = flag->expected(1, INT_MAX);
}

_options.emplace(command, flag);
Expand Down

0 comments on commit 780f62f

Please sign in to comment.