Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 10 additions & 7 deletions src/coreclr/scripts/superpmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2947,15 +2947,15 @@ def write_ps_row(name, diffs, perfscore_geomean):
for (mch_file, base_metrics, diff_metrics, _, _, _) in asm_diffs]

def write_row(name, diffed_contexts, num_minopts, num_fullopts, num_missed_base, num_missed_diff, total_num_contexts):
write_fh.write("|{}|{:,d}|{:,d}|{:,d}|{:,d} ({:1.2f}%)|{:,d} ({:1.2f}%)|\n".format(
write_fh.write("|{}|{:,d}|{:,d}|{:,d}|{:,d} ({}%)|{:,d} ({}%)|\n".format(
name,
diffed_contexts,
num_minopts,
num_fullopts,
num_missed_base,
num_missed_base / total_num_contexts * 100,
"{:1.2f}".format(num_missed_base / total_num_contexts * 100) if total_num_contexts != 0 else "N/A",
num_missed_diff,
num_missed_diff / total_num_contexts * 100))
"{:1.2f}".format(num_missed_diff / total_num_contexts * 100) if total_num_contexts != 0 else "N/A"))

for t in rows:
write_row(*t)
Expand Down Expand Up @@ -4118,9 +4118,12 @@ def process_local_mch_files(coreclr_args, mch_files, mch_cache_dir):
if os.path.isfile(mct_file):
urls.append(mct_file)
else:
urls += get_files_from_path(mch_file, match_func=lambda path: any(path.lower().endswith(extension) for extension in [".mch", ".mct", ".zip"]))
urls += get_files_from_path(mch_file, match_func=lambda path: any(path.lower().endswith(extension) for extension in [".mch", ".mc", ".mct", ".zip"]))
elif item.lower().startswith("http:") or item.lower().startswith("https:"): # probably could use urllib.parse to be more precise
urls.append(item)
elif os.path.isdir(item):
# If it's a directory, we'll search recursively for .mch and .mc files in it
local_mch_files.extend(get_files_from_path(item, match_func=lambda path: any(path.lower().endswith(extension) for extension in [".mch", ".mc"])))
Comment thread
jakobbotsch marked this conversation as resolved.
else:
# Doesn't appear to be a UNC path (on Windows) or a URL, so just use it as-is.
local_mch_files.append(item)
Expand Down Expand Up @@ -4148,8 +4151,8 @@ def filter_local_path(path):
if len(mct_urls) != 0:
local_mch_files += download_files(mct_urls, mch_cache_dir, fail_if_not_found=False, is_azure_storage=True, display_progress=not skip_progress)

# Even though we might have downloaded MCT files, only return the set of MCH files.
local_mch_files = [file for file in local_mch_files if any(file.lower().endswith(extension) for extension in [".mch"])]
# Even though we might have downloaded MCT files, only return the set of MCH/MC files.
local_mch_files = [file for file in local_mch_files if any(file.lower().endswith(extension) for extension in [".mch", ".mc"])]

return local_mch_files

Expand Down Expand Up @@ -4695,7 +4698,7 @@ def get_mch_files_for_replay(local_mch_paths, filters):
# If there are specified filters, only run those matching files.
mch_files += get_files_from_path(item,
match_func=lambda path:
any(path.endswith(extension) for extension in [".mch"])
any(path.lower().endswith(extension) for extension in [".mch", ".mc"])
and ((filters is None) or any(filter_item.lower() in path for filter_item in filters)))
Comment thread
jakobbotsch marked this conversation as resolved.

if len(mch_files) == 0:
Expand Down
7 changes: 1 addition & 6 deletions src/coreclr/tools/superpmi/mcs/verbstrip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,9 @@ int verbStrip::DoWork(
st1->Start();
}

if (!MethodContext::Initialize(loadedCount, mcb.buff, mcb.size, &mc))
if (!MethodContext::Initialize(loadedCount, mcb.buff, mcb.size, !stripCR, &mc))
return -1;

if (stripCR)
{
delete mc->cr;
mc->cr = new CompileResult();
}
mc->saveToFile(hFileOut);
savedCount++;
delete mc;
Expand Down
49 changes: 29 additions & 20 deletions src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,14 @@ void MethodContext::Destroy()
break; \
}

#define sparseReadFileCR(target, key, value) \
#define sparseReadFileCR(target, key, value, readCompileResults) \
case PacketCR_##target: \
{ \
cr->target = new LightWeightMap<key, value>(); \
cr->target->ReadFromArray(&buff2[buffIndex], localsize); \
if (readCompileResults) \
{ \
cr->target = new LightWeightMap<key, value>(); \
cr->target->ReadFromArray(&buff2[buffIndex], localsize); \
} \
break; \
}

Expand All @@ -106,11 +109,14 @@ void MethodContext::Destroy()
break; \
}

#define sparseReadFileCRDense(target, value) \
#define sparseReadFileCRDense(target, value, readCompileResults) \
case PacketCR_##target: \
{ \
cr->target = new DenseLightWeightMap<value>(); \
cr->target->ReadFromArray(&buff2[buffIndex], localsize); \
if (readCompileResults) \
{ \
cr->target = new DenseLightWeightMap<value>(); \
cr->target->ReadFromArray(&buff2[buffIndex], localsize); \
} \
break; \
}

Expand Down Expand Up @@ -174,24 +180,24 @@ unsigned int MethodContext::saveToFile(HANDLE hFile)
// (and sets *ppmc with new MethodContext), false on failure.
//
// static
bool MethodContext::Initialize(int mcIndex, unsigned char* buff, DWORD size, /* OUT */ MethodContext** ppmc)
bool MethodContext::Initialize(int mcIndex, unsigned char* buff, DWORD size, bool readCompileResults, /* OUT */ MethodContext** ppmc)
{
MethodContext* mc = new MethodContext();
mc->index = mcIndex;
*ppmc = mc;
return mc->Initialize(mcIndex, buff, size);
return mc->Initialize(mcIndex, buff, size, readCompileResults);
}

// static
bool MethodContext::Initialize(int mcIndex, HANDLE hFile, /* OUT */ MethodContext** ppmc)
bool MethodContext::Initialize(int mcIndex, HANDLE hFile, bool readCompileResults, /* OUT */ MethodContext** ppmc)
{
MethodContext* mc = new MethodContext();
mc->index = mcIndex;
*ppmc = mc;
return mc->Initialize(mcIndex, hFile);
return mc->Initialize(mcIndex, hFile, readCompileResults);
}

bool MethodContext::Initialize(int mcIndex, unsigned char* buff, DWORD size)
bool MethodContext::Initialize(int mcIndex, unsigned char* buff, DWORD size, bool readCompileResults)
{
bool result = true;

Expand All @@ -200,14 +206,15 @@ bool MethodContext::Initialize(int mcIndex, unsigned char* buff, DWORD size)
unsigned char* buff;
DWORD size;
MethodContext* pThis;
bool readCompileResults;
} param;
param.buff = buff;
param.size = size;
param.pThis = this;

param.readCompileResults = readCompileResults;
PAL_TRY(Param*, pParam, &param)
{
pParam->pThis->MethodInitHelper(pParam->buff, pParam->size);
pParam->pThis->MethodInitHelper(pParam->buff, pParam->size, pParam->readCompileResults);
}
PAL_EXCEPT_FILTER(FilterSuperPMIExceptions_CatchMC)
{
Expand All @@ -219,21 +226,23 @@ bool MethodContext::Initialize(int mcIndex, unsigned char* buff, DWORD size)
return result;
}

bool MethodContext::Initialize(int mcIndex, HANDLE hFile)
bool MethodContext::Initialize(int mcIndex, HANDLE hFile, bool readCompileResults)
{
bool result = true;

struct Param
{
HANDLE hFile;
MethodContext* pThis;
bool readCompileResults;
} param;
param.hFile = hFile;
param.pThis = this;
param.readCompileResults = readCompileResults;

PAL_TRY(Param*, pParam, &param)
{
pParam->pThis->MethodInitHelperFile(pParam->hFile);
pParam->pThis->MethodInitHelperFile(pParam->hFile, pParam->readCompileResults);
}
PAL_EXCEPT_FILTER(FilterSuperPMIExceptions_CatchMC)
{
Expand All @@ -245,7 +254,7 @@ bool MethodContext::Initialize(int mcIndex, HANDLE hFile)
return result;
}

void MethodContext::MethodInitHelperFile(HANDLE hFile)
void MethodContext::MethodInitHelperFile(HANDLE hFile, bool readCompileResults)
{
DWORD bytesRead;
char buff[512];
Expand All @@ -258,10 +267,10 @@ void MethodContext::MethodInitHelperFile(HANDLE hFile)
unsigned char* buff2 = new unsigned char[totalLen + 2]; // total + End Canary
AssertCode(ReadFile(hFile, buff2, totalLen + 2, &bytesRead, NULL) == TRUE, EXCEPTIONCODE_MC);
AssertCodeMsg((buff2[totalLen] == '4') && (buff2[totalLen + 1] == '2'), EXCEPTIONCODE_MC, "Didn't find end canary");
MethodInitHelper(buff2, totalLen);
MethodInitHelper(buff2, totalLen, readCompileResults);
}

void MethodContext::MethodInitHelper(unsigned char* buff2, unsigned int totalLen)
void MethodContext::MethodInitHelper(unsigned char* buff2, unsigned int totalLen, bool readCompileResults)
{
unsigned int buffIndex = 0;
unsigned int localsize = 0;
Expand All @@ -282,8 +291,8 @@ void MethodContext::MethodInitHelper(unsigned char* buff2, unsigned int totalLen
#define DENSELWM(map, value) sparseReadFileDense(map, value)
#include "lwmlist.h"

#define LWM(map, key, value) sparseReadFileCR(map, key, value)
#define DENSELWM(map, value) sparseReadFileCRDense(map, value)
#define LWM(map, key, value) sparseReadFileCR(map, key, value, readCompileResults)
#define DENSELWM(map, value) sparseReadFileCRDense(map, value, readCompileResults)
#include "crlwmlist.h"

default:
Expand Down
12 changes: 6 additions & 6 deletions src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,17 @@ class MethodContext
MethodContext();

private:
void MethodInitHelper(unsigned char* buff, unsigned int totalLen);
void MethodInitHelperFile(HANDLE hFile);
void MethodInitHelper(unsigned char* buff, unsigned int totalLen, bool readCompileResults);
void MethodInitHelperFile(HANDLE hFile, bool readCompileResults);

bool Initialize(int mcIndex, unsigned char* buff, DWORD size);
bool Initialize(int mcIndex, HANDLE hFile);
bool Initialize(int mcIndex, unsigned char* buff, DWORD size, bool readCompileResults);
bool Initialize(int mcIndex, HANDLE hFile, bool readCompileResults);

int dumpHashToBuffer(BYTE* pBuffer, int bufLen, char* buff, int len);

public:
static bool Initialize(int mcIndex, unsigned char* buff, DWORD size, /* OUT */ MethodContext** ppmc);
static bool Initialize(int mcIndex, HANDLE hFile, /* OUT */ MethodContext** ppmc);
static bool Initialize(int mcIndex, unsigned char* buff, DWORD size, bool readCompileResults, /* OUT */ MethodContext** ppmc);
static bool Initialize(int mcIndex, HANDLE hFile, bool readCompileResults, /* OUT */ MethodContext** ppmc);
~MethodContext();
void Destroy();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ bool MethodContextIterator::MoveNext()
}
}

if (!MethodContext::Initialize(m_methodContextNumber, m_hFile, &m_mc))
if (!MethodContext::Initialize(m_methodContextNumber, m_hFile, /* readCompileResults */ true, &m_mc))
return false;

// If we have an array of indexes, skip the loaded indexes that have not been specified.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ MethodContextBuffer MethodContextReader::GetNextMethodContextFromHash()

MethodContext* mc;

if (!MethodContext::Initialize(-1, buff, mcb.size, &mc))
if (!MethodContext::Initialize(-1, buff, mcb.size, /* readCompileResults */ true, &mc))
return MethodContextBuffer(-1);

mc->dumpMethodHashToBuffer(mcHash, MM3_HASH_BUFFER_SIZE);
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/tools/superpmi/superpmi/streamingsuperpmi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ static MethodContext* getMethodContext(int index, MethodContextReader* reader)
}

MethodContext* mc = nullptr;
if (!MethodContext::Initialize(index, mcb.buff, mcb.size, &mc))
if (!MethodContext::Initialize(index, mcb.buff, mcb.size, /* readCompileResults */ false, &mc))
{
return nullptr;
}
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/tools/superpmi/superpmi/superpmi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ int __cdecl main(int argc, char* argv[])
loadedCount++;
const int mcIndex = reader->GetMethodContextIndex();
MethodContext* mc = nullptr;
if (!MethodContext::Initialize(mcIndex, mcb.buff, mcb.size, &mc))
if (!MethodContext::Initialize(mcIndex, mcb.buff, mcb.size, /* readCompileResults */ false, &mc))
{
return (int)SpmiResult::GeneralFailure;
}
Expand Down
Loading