Skip to content

Commit

Permalink
Implement the third graph backend implementation.
Browse files Browse the repository at this point in the history
Additional improvements to ETW glue, general graph backend functionality, and
introduction of additional command line arguments: --FixedAttempts,
--MinAttempts, --MaxAttempts, --TargetNumberOfSolutions.
  • Loading branch information
tpn committed Jan 22, 2021
1 parent c4cf6e1 commit 895be9e
Show file tree
Hide file tree
Showing 30 changed files with 2,115 additions and 392 deletions.
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,12 @@ Table Compile Flags:
Table Create Parameters:
--GraphImpl=1|2 [default: 2]
--GraphImpl=1|2|3 [default: 3]
Selects the backend version of the graph assignment step. Version 1
matches the original CHM algorithm, version 2 is faster and was derived
from NetBSD's nbperf routine. Defaults to version 2.
from NetBSD's nbperf module, version 3 is even faster and was derived
from additional improvements to NetBSD's nbperf module in 2020.
--ValueSizeInBytes=4|8
Expand Down Expand Up @@ -462,6 +463,18 @@ Table Create Parameters:
N.B. Only applies to PerfectHashCreate.exe.
--TargetNumberOfSolutions=N
Where N is a positive integer and represents a target number of
solutions to find before stopping graph solving. Typically only useful
for benchmarking.
--FixedAttempts=N
Where N is a positive integer and represents a fixed number of attempts
that will be made (irrespective of whether or not a solution was found)
before graph solving stops. Typically only useful for benchmarking.
--Seeds=<n1,...n8>
Supplies an optional comma-separated list of up to 8 integers that
Expand Down
4 changes: 4 additions & 0 deletions include/PerfectHash.h
Original file line number Diff line number Diff line change
Expand Up @@ -3097,6 +3097,10 @@ typedef RNG_VTBL *PRNG_VTBL;
FIRST_ENTRY(AttemptsBeforeTableResize) \
ENTRY(MaxNumberOfTableResizes) \
ENTRY(InitialNumberOfTableResizes) \
ENTRY(MinAttempts) \
ENTRY(MaxAttempts) \
ENTRY(FixedAttempts) \
ENTRY(TargetNumberOfSolutions) \
ENTRY(BestCoverageAttempts) \
ENTRY(BestCoverageType) \
ENTRY(MaxNumberOfEqualBestGraphs) \
Expand Down
99 changes: 99 additions & 0 deletions include/PerfectHashErrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ Module Name:
//
#define PH_S_NO_KEY_SIZE_EXTRACTED_FROM_FILENAME ((HRESULT)0x20040009L)

//
// MessageId: PH_S_MAX_ATTEMPTS_REACHED
//
// MessageText:
//
// Maximum attempts at solving reached.
//
#define PH_S_MAX_ATTEMPTS_REACHED ((HRESULT)0x2004000AL)


////////////////////////////////////////////////////////////////////////////////
// PH_SEVERITY_INFORMATIONAL
Expand Down Expand Up @@ -3825,3 +3834,93 @@ Module Name:
//
#define PH_E_RNG_NOT_INITIALIZED ((HRESULT)0xE00403C6L)

//
// MessageId: PH_E_INVALID_FIXED_ATTEMPTS
//
// MessageText:
//
// Invalid FixedAttempts.
//
#define PH_E_INVALID_FIXED_ATTEMPTS ((HRESULT)0xE00403C7L)

//
// MessageId: PH_E_INVALID_MIN_ATTEMPTS
//
// MessageText:
//
// Invalid MinAttempts.
//
#define PH_E_INVALID_MIN_ATTEMPTS ((HRESULT)0xE00403C8L)

//
// MessageId: PH_E_INVALID_MAX_ATTEMPTS
//
// MessageText:
//
// Invalid MaxAttempts.
//
#define PH_E_INVALID_MAX_ATTEMPTS ((HRESULT)0xE00403C9L)

//
// MessageId: PH_E_FIXED_ATTEMPTS_CONFLICTS_WITH_MINMAX_ATTEMPTS
//
// MessageText:
//
// FixedAttempts conflicts with MinAttempts/MaxAttempts.
//
#define PH_E_FIXED_ATTEMPTS_CONFLICTS_WITH_MINMAX_ATTEMPTS ((HRESULT)0xE00403CAL)

//
// MessageId: PH_E_MIN_ATTEMPTS_EXCEEDS_MAX_ATTEMPTS
//
// MessageText:
//
// MinAttempts must be less than or equal to MaxAttempts.
//
#define PH_E_MIN_ATTEMPTS_EXCEEDS_MAX_ATTEMPTS ((HRESULT)0xE00403CBL)

//
// MessageId: PH_E_FIXED_ATTEMPTS_CONFLICTS_WITH_FIND_BEST_GRAPH
//
// MessageText:
//
// FixedAttempts conflicts with FindBestGraph.
//
#define PH_E_FIXED_ATTEMPTS_CONFLICTS_WITH_FIND_BEST_GRAPH ((HRESULT)0xE00403CCL)

//
// MessageId: PH_E_MIN_ATTEMPTS_CONFLICTS_WITH_FIND_BEST_GRAPH
//
// MessageText:
//
// MinAttempts conflicts with FindBestGraph.
//
#define PH_E_MIN_ATTEMPTS_CONFLICTS_WITH_FIND_BEST_GRAPH ((HRESULT)0xE00403CDL)

//
// MessageId: PH_E_INVALID_TARGET_NUMBER_OF_SOLUTIONS
//
// MessageText:
//
// Invalid TargetNumberOfSolutions.
//
#define PH_E_INVALID_TARGET_NUMBER_OF_SOLUTIONS ((HRESULT)0xE00403CEL)

//
// MessageId: PH_E_TARGET_NUMBER_OF_SOLUTIONS_CONFLICTS_WITH_FIND_BEST_GRAPH
//
// MessageText:
//
// TargetNumberOfSolutions conflicts with FindBestGraph.
//
#define PH_E_TARGET_NUMBER_OF_SOLUTIONS_CONFLICTS_WITH_FIND_BEST_GRAPH ((HRESULT)0xE00403CFL)

//
// MessageId: PH_E_TARGET_NUMBER_OF_SOLUTIONS_EXCEEDS_MIN_ATTEMPTS
//
// MessageText:
//
// TargetNumberOfSolutions exceeds MinAttempts.
//
#define PH_E_TARGET_NUMBER_OF_SOLUTIONS_EXCEEDS_MIN_ATTEMPTS ((HRESULT)0xE00403D0L)

279 changes: 174 additions & 105 deletions include/PerfectHashEvents.h

Large diffs are not rendered by default.

77 changes: 77 additions & 0 deletions python/perfecthash/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,12 +503,15 @@
' etw:SessionId,'
' KeysFileName,'
' Attempt,'
' SolutionNumber,'
' ElapsedMilliseconds,'
' CoverageType,'
' CoverageValue,'
' CoverageValueAsDouble,'
' StopGraphSolving,'
' IsBest,'
' IsEqual,'
' IsCoverageValueDouble,'
' EqualCount,'
' TotalNumberOfPages,'
' TotalNumberOfLargePages,'
Expand Down Expand Up @@ -575,12 +578,15 @@
'SessionId',
'KeysFileName',
'Attempt',
'SolutionNumber',
'ElapsedMilliseconds',
'CoverageType',
'CoverageValue',
'CoverageValueAsDouble',
'StopGraphSolving',
'IsBest',
'IsEqual',
'IsCoverageValueDouble',
'EqualCount',
'TotalNumberOfPages',
'TotalNumberOfLargePages',
Expand Down Expand Up @@ -644,12 +650,15 @@
'ActivityId',
'KeysFileName',
'Attempt',
'SolutionNumber',
'ElapsedMilliseconds',
'CoverageType',
'CoverageValue',
'CoverageValueAsDouble',
'StopGraphSolving',
'IsBest',
'IsEqual',
'IsCoverageValueDouble',
'EqualCount',
'TotalNumberOfPages',
'TotalNumberOfLargePages',
Expand Down Expand Up @@ -934,6 +943,67 @@
'Result',
)

# GraphIsAcyclic

IS_ACYCLIC = 'PerfectHash/IsAcyclic/win:Info'

IS_ACYCLIC_ETW_HEADER = (
'PerfectHash/IsAcyclic/win:Info,'
' TimeStamp,'
' Process Name ( PID),'
' ThreadID,'
' CPU,'
' etw:ActivityId,'
' etw:Related ActivityId,'
' etw:UserSid,'
' etw:SessionId,'
' KeysFileName,'
' Attempt,'
' FunctionVersion,'
' Cycles,'
' Microseconds,'
' NumberOfKeys,'
' NumberOfVertices,'
' IsAcyclic'
)

IS_ACYCLIC_CSV_HEADER = (
'EventName',
'TimeStamp',
'ProcessID',
'ThreadID',
'CPU',
'ActivityId',
'RelatedActivityId',
'UserSid',
'SessionId',
'KeysFileName',
'Attempt',
'FunctionVersion',
'Cycles',
'Microseconds',
'NumberOfKeys',
'NumberOfVertices',
'IsAcyclic',
)

IS_ACYCLIC_CSV_HEADER_SLIM = (
'LineNumber',
'TimeStamp',
'ProcessID',
'ThreadID',
'CPU',
'ActivityId',
'KeysFileName',
'Attempt',
'FunctionVersion',
'Cycles',
'Microseconds',
'NumberOfKeys',
'NumberOfVertices',
'IsAcyclic',
)

# Maps

EVENT_NAME_TO_ETW_HEADER = {
Expand All @@ -945,6 +1015,7 @@
FOUND_NEW_BEST_GRAPH: FOUND_NEW_BEST_GRAPH_ETW_HEADER,
FOUND_EQUAL_BEST_GRAPH: FOUND_EQUAL_BEST_GRAPH_ETW_HEADER,
FOUND_GRAPH: FOUND_GRAPH_ETW_HEADER,
IS_ACYCLIC: IS_ACYCLIC_ETW_HEADER,
}

EVENT_NAME_TO_CSV_HEADER = {
Expand All @@ -961,6 +1032,7 @@
FOUND_NEW_BEST_GRAPH: FOUND_NEW_BEST_GRAPH_CSV_HEADER,
FOUND_EQUAL_BEST_GRAPH: FOUND_EQUAL_BEST_GRAPH_CSV_HEADER,
FOUND_GRAPH: FOUND_GRAPH_CSV_HEADER,
IS_ACYCLIC: IS_ACYCLIC_CSV_HEADER,
}

EVENT_NAME_TO_CSV_HEADER_SLIM = {
Expand All @@ -977,6 +1049,7 @@
FOUND_NEW_BEST_GRAPH: FOUND_NEW_BEST_GRAPH_CSV_HEADER_SLIM,
FOUND_EQUAL_BEST_GRAPH: FOUND_EQUAL_BEST_GRAPH_CSV_HEADER_SLIM,
FOUND_GRAPH: FOUND_GRAPH_CSV_HEADER_SLIM,
IS_ACYCLIC: IS_ACYCLIC_CSV_HEADER_SLIM,
}

HAS_SEED_DATA = {
Expand Down Expand Up @@ -2118,6 +2191,7 @@ def process_xperf_perfecthash_csv(path, out=None):
generate_random_bytes_stop = GENERATE_RANDOM_BYTES_STOP
cswitch = CSWITCH
pmc = PMC
is_acyclic = IS_ACYCLIC

assign_io = io.StringIO()
generate_random_bytes_io = io.StringIO()
Expand All @@ -2135,6 +2209,7 @@ def process_xperf_perfecthash_csv(path, out=None):
generate_random_bytes_stop: generate_random_bytes_io,
cswitch: io.StringIO(),
pmc: io.StringIO(),
is_acyclic: io.StringIO(),
}

paths = {
Expand All @@ -2150,6 +2225,7 @@ def process_xperf_perfecthash_csv(path, out=None):
generate_random_bytes_stop: f'{prefix}_GenerateRandomBytes.csv',
cswitch: f'{prefix}_ContextSwitch.csv',
pmc: f'{prefix}_Pmc.csv',
is_acyclic: f'{prefix}_IsAcyclic.csv',
}

counts = {
Expand All @@ -2165,6 +2241,7 @@ def process_xperf_perfecthash_csv(path, out=None):
generate_random_bytes_stop: 0,
cswitch: 0,
pmc: 0,
is_acyclic: 0,
}

names = set(counts.keys())
Expand Down
Loading

0 comments on commit 895be9e

Please sign in to comment.