Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add benchcat: cat + throughput measurements #15564

Merged
merged 7 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
1 change: 1 addition & 0 deletions .github/actions/spelling/excludes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
^src/terminal/parser/ft_fuzzwrapper/run\.bat$
^src/terminal/parser/ut_parser/Base64Test.cpp$
^src/terminal/parser/ut_parser/run\.bat$
^src/tools/benchcat
^src/tools/integrity/packageuwp/ConsoleUWP\.appxSources$
^src/tools/lnkd/lnkd\.bat$
^src/tools/pixels/pixels\.bat$
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/spelling/expect/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ bcx
bcz
BEFOREPARENT
beginthread
benchcat
bgfx
bgidx
Bgk
Expand Down Expand Up @@ -987,7 +988,6 @@ langid
LANGUAGELIST
lasterror
LASTEXITCODE
lastexitcode
LAYOUTRTL
lbl
LBN
Expand Down
29 changes: 29 additions & 0 deletions OpenConsole.sln
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TerminalStress", "src\tools
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RenderingTests", "src\tools\RenderingTests\RenderingTests.vcxproj", "{37C995E0-2349-4154-8E77-4A52C0C7F46D}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "benchcat", "src\tools\benchcat\benchcat.vcxproj", "{2C836962-9543-4CE5-B834-D28E1F124B66}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
AuditMode|Any CPU = AuditMode|Any CPU
Expand Down Expand Up @@ -2798,6 +2800,32 @@ Global
{37C995E0-2349-4154-8E77-4A52C0C7F46D}.Release|x64.Build.0 = Release|x64
{37C995E0-2349-4154-8E77-4A52C0C7F46D}.Release|x86.ActiveCfg = Release|Win32
{37C995E0-2349-4154-8E77-4A52C0C7F46D}.Release|x86.Build.0 = Release|Win32
{2C836962-9543-4CE5-B834-D28E1F124B66}.AuditMode|Any CPU.ActiveCfg = AuditMode|Win32
{2C836962-9543-4CE5-B834-D28E1F124B66}.AuditMode|ARM.ActiveCfg = AuditMode|Win32
Comment on lines +2797 to +2798
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want this for audit mode too?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We must include a configuration mapping for every platform|config combo in the solution.

Since these do not have a .0 entry (instead of .ActiveCfg), they will not be considered for build.

This and the above are in the correct state :)

{2C836962-9543-4CE5-B834-D28E1F124B66}.AuditMode|ARM64.ActiveCfg = Release|ARM64
{2C836962-9543-4CE5-B834-D28E1F124B66}.AuditMode|x64.ActiveCfg = Release|x64
{2C836962-9543-4CE5-B834-D28E1F124B66}.AuditMode|x86.ActiveCfg = Release|Win32
{2C836962-9543-4CE5-B834-D28E1F124B66}.Debug|Any CPU.ActiveCfg = Debug|Win32
{2C836962-9543-4CE5-B834-D28E1F124B66}.Debug|ARM.ActiveCfg = Debug|Win32
{2C836962-9543-4CE5-B834-D28E1F124B66}.Debug|ARM64.ActiveCfg = Debug|ARM64
{2C836962-9543-4CE5-B834-D28E1F124B66}.Debug|ARM64.Build.0 = Debug|ARM64
{2C836962-9543-4CE5-B834-D28E1F124B66}.Debug|x64.ActiveCfg = Debug|x64
{2C836962-9543-4CE5-B834-D28E1F124B66}.Debug|x64.Build.0 = Debug|x64
{2C836962-9543-4CE5-B834-D28E1F124B66}.Debug|x86.ActiveCfg = Debug|Win32
{2C836962-9543-4CE5-B834-D28E1F124B66}.Debug|x86.Build.0 = Debug|Win32
{2C836962-9543-4CE5-B834-D28E1F124B66}.Fuzzing|Any CPU.ActiveCfg = Fuzzing|Win32
{2C836962-9543-4CE5-B834-D28E1F124B66}.Fuzzing|ARM.ActiveCfg = Fuzzing|Win32
{2C836962-9543-4CE5-B834-D28E1F124B66}.Fuzzing|ARM64.ActiveCfg = Fuzzing|ARM64
{2C836962-9543-4CE5-B834-D28E1F124B66}.Fuzzing|x64.ActiveCfg = Fuzzing|x64
{2C836962-9543-4CE5-B834-D28E1F124B66}.Fuzzing|x86.ActiveCfg = Fuzzing|Win32
Comment on lines +2807 to +2811
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably don't need this for Fuzzing right?

{2C836962-9543-4CE5-B834-D28E1F124B66}.Release|Any CPU.ActiveCfg = Release|Win32
{2C836962-9543-4CE5-B834-D28E1F124B66}.Release|ARM.ActiveCfg = Release|Win32
{2C836962-9543-4CE5-B834-D28E1F124B66}.Release|ARM64.ActiveCfg = Release|ARM64
{2C836962-9543-4CE5-B834-D28E1F124B66}.Release|ARM64.Build.0 = Release|ARM64
{2C836962-9543-4CE5-B834-D28E1F124B66}.Release|x64.ActiveCfg = Release|x64
{2C836962-9543-4CE5-B834-D28E1F124B66}.Release|x64.Build.0 = Release|x64
{2C836962-9543-4CE5-B834-D28E1F124B66}.Release|x86.ActiveCfg = Release|Win32
{2C836962-9543-4CE5-B834-D28E1F124B66}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -2904,6 +2932,7 @@ Global
{3C67784E-1453-49C2-9660-483E2CC7F7AD} = {40BD8415-DD93-4200-8D82-498DDDC08CC8}
{613CCB57-5FA9-48EF-80D0-6B1E319E20C4} = {A10C4720-DCA4-4640-9749-67F4314F527C}
{37C995E0-2349-4154-8E77-4A52C0C7F46D} = {A10C4720-DCA4-4640-9749-67F4314F527C}
{2C836962-9543-4CE5-B834-D28E1F124B66} = {A10C4720-DCA4-4640-9749-67F4314F527C}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3140B1B7-C8EE-43D1-A772-D82A7061A271}
Expand Down
2 changes: 1 addition & 1 deletion build/scripts/Invoke-FormattingCheck.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function Invoke-CheckBadCodeFormatting() {

# returns a non-zero exit code if there are any diffs in the tracked files in the repo
git diff-index --quiet HEAD --
if ($lastExitCode -eq 1) {
if ($LASTEXITCODE -eq 1) {

# Write the list of files that need updating to the log
git diff-index --name-only HEAD
Expand Down
44 changes: 44 additions & 0 deletions src/tools/benchcat/benchcat.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{2C836962-9543-4CE5-B834-D28E1F124B66}</ProjectGuid>
<RootNamespace>benchcat</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<TargetName>bc</TargetName>
</PropertyGroup>
<Import Project="$(SolutionDir)\src\common.build.pre.props" />
<ItemDefinitionGroup>
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<PropertyGroup Condition="'$(Configuration)'=='Release'">
<GenerateManifest>false</GenerateManifest>
<WholeProgramOptimization>false</WholeProgramOptimization>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)'=='Release'">
<ClCompile>
<BufferSecurityCheck>false</BufferSecurityCheck>
<ControlFlowGuard>false</ControlFlowGuard>
<ExceptionHandling>false</ExceptionHandling>
<PreprocessorDefinitions>NODEFAULTLIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<SDLCheck>false</SDLCheck>
</ClCompile>
<Link>
<EntryPointSymbol>main</EntryPointSymbol>
<IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="main.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="crt.cpp" />
</ItemGroup>
<Import Project="$(SolutionDir)\src\common.build.post.props" />
</Project>
224 changes: 224 additions & 0 deletions src/tools/benchcat/crt.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

#ifdef NODEFAULTLIB

#include <intrin.h>

#pragma function(memcpy)
void* memcpy(void* dst, const void* src, size_t size)
{
__movsb(static_cast<BYTE*>(dst), static_cast<const BYTE*>(src), size);
return dst;
}

#pragma function(memset)
void* memset(void* dst, int val, size_t size)
{
__stosb(static_cast<BYTE*>(dst), static_cast<BYTE>(val), size);
return dst;
}

#endif

namespace ucrt
{
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// This is a copy of "startup/argv_parsing.cpp" from the Windows SDK (10.0.22000.0).
// The source code was slightly modified to fit this code style.

template<typename Character>
static bool should_copy_another_character(Character) noexcept
{
return false;
}

template<typename Character>
static void __cdecl parse_command_line(Character* cmdstart, Character** argv, Character* args, size_t* argument_count, size_t* character_count) noexcept
{
*character_count = 0;
*argument_count = 1; // We'll have at least the program name

Character c;
int copy_character; /* 1 = copy char to *args */
unsigned numslash; /* num of backslashes seen */

/* first scan the program name, copy it, and count the bytes */
Character* p = cmdstart;
if (argv)
*argv++ = args;

// A quoted program name is handled here. The handling is much
// simpler than for other arguments. Basically, whatever lies
// between the leading double-quote and next one, or a terminal null
// character is simply accepted. Fancier handling is not required
// because the program name must be a legal NTFS/HPFS file name.
// Note that the double-quote characters are not copied, nor do they
// contribute to character_count.
bool in_quotes = false;
do
{
if (*p == '"')
{
in_quotes = !in_quotes;
c = *p++;
continue;
}

++*character_count;
if (args)
*args++ = *p;

c = *p++;

if (should_copy_another_character(c))
{
++*character_count;
if (args)
*args++ = *p; // Copy 2nd byte too
++p; // skip over trail byte
}
} while (c != '\0' && (in_quotes || (c != ' ' && c != '\t')));

if (c == '\0')
{
p--;
}
else
{
if (args)
*(args - 1) = '\0';
}

in_quotes = false;

// Loop on each argument
for (;;)
{
if (*p)
{
while (*p == ' ' || *p == '\t')
++p;
}

if (*p == '\0')
break; // End of arguments

// Scan an argument:
if (argv)
*argv++ = args;

++*argument_count;

// Loop through scanning one argument:
for (;;)
{
copy_character = 1;

// Rules:
// 2N backslashes + " ==> N backslashes and begin/end quote
// 2N + 1 backslashes + " ==> N backslashes + literal "
// N backslashes ==> N backslashes
numslash = 0;

while (*p == '\\')
{
// Count number of backslashes for use below
++p;
++numslash;
}

if (*p == '"')
{
// if 2N backslashes before, start/end quote, otherwise
// copy literally:
if (numslash % 2 == 0)
{
if (in_quotes && p[1] == '"')
{
p++; // Double quote inside quoted string
}
else
{
// Skip first quote char and copy second:
copy_character = 0; // Don't copy quote
in_quotes = !in_quotes;
}
}

numslash /= 2;
}

// Copy slashes:
while (numslash--)
{
if (args)
*args++ = '\\';
++*character_count;
}

// If at end of arg, break loop:
if (*p == '\0' || (!in_quotes && (*p == ' ' || *p == '\t')))
break;

// Copy character into argument:
if (copy_character)
{
if (args)
*args++ = *p;

if (should_copy_another_character(*p))
{
++p;
++*character_count;

if (args)
*args++ = *p;
}

++*character_count;
}

++p;
}

// Null-terminate the argument:
if (args)
*args++ = '\0'; // Terminate the string

++*character_count;
}

// We put one last argument in -- a null pointer:
if (argv)
*argv++ = nullptr;

++*argument_count;
}

char* acrt_allocate_buffer_for_argv(size_t const argument_count, size_t const character_count, size_t const character_size)
{
const size_t argument_array_size = argument_count * sizeof(void*);
const size_t character_array_size = character_count * character_size;
const size_t total_size = argument_array_size + character_array_size;
return reinterpret_cast<char*>(VirtualAlloc(nullptr, total_size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE));
}

static void common_configure_argv(const char*** argv, int* argc)
{
const auto command_line = GetCommandLineA();

size_t argument_count = 0;
size_t character_count = 0;
ucrt::parse_command_line<char>(command_line, nullptr, nullptr, &argument_count, &character_count);

const auto buffer = ucrt::acrt_allocate_buffer_for_argv(argument_count, character_count, sizeof(char));
const auto first_argument = reinterpret_cast<char**>(buffer);
const auto first_string = reinterpret_cast<char*>(buffer + argument_count * sizeof(char*));
ucrt::parse_command_line(command_line, first_argument, first_string, &argument_count, &character_count);

*argv = const_cast<const char**>(first_argument);
*argc = static_cast<int>(argument_count - 1);
}
} // namespace ucrt
Loading