[HIPIFY][fix] Fixer for #801
[issue #801] Errors in hipification statistics
[ROCm/clr commit: 8d28db9c8d]
此提交包含在:
@@ -130,8 +130,12 @@ Statistics::Statistics(const std::string& name): fileName(name) {
|
|||||||
std::ifstream src_file(name, std::ios::binary | std::ios::ate);
|
std::ifstream src_file(name, std::ios::binary | std::ios::ate);
|
||||||
src_file.clear();
|
src_file.clear();
|
||||||
src_file.seekg(0);
|
src_file.seekg(0);
|
||||||
totalLines = (int) std::count(std::istreambuf_iterator<char>(src_file), std::istreambuf_iterator<char>(), '\n');
|
totalLines = (unsigned) std::count(std::istreambuf_iterator<char>(src_file), std::istreambuf_iterator<char>(), '\n');
|
||||||
totalBytes = (int) src_file.tellg();
|
totalBytes = (int) src_file.tellg();
|
||||||
|
if (totalBytes < 0) {
|
||||||
|
totalBytes = 0;
|
||||||
|
hasErrors = true;
|
||||||
|
}
|
||||||
startTime = chr::steady_clock::now();
|
startTime = chr::steady_clock::now();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,23 +175,24 @@ void Statistics::print(std::ostream* csv, llvm::raw_ostream* printOut, bool skip
|
|||||||
std::string str = "file \'" + fileName + "\' statistics:\n";
|
std::string str = "file \'" + fileName + "\' statistics:\n";
|
||||||
conditionalPrint(csv, printOut, "\n" + str, "\n[HIPIFY] info: " + str);
|
conditionalPrint(csv, printOut, "\n" + str, "\n[HIPIFY] info: " + str);
|
||||||
}
|
}
|
||||||
|
if (hasErrors || totalBytes <= 0 || totalLines <= 0) {
|
||||||
|
std::string str = "\n ERROR: Statistics is invalid due to failed hipification.\n\n";
|
||||||
|
conditionalPrint(csv, printOut, str, str);
|
||||||
|
}
|
||||||
size_t changedLines = touchedLines.size();
|
size_t changedLines = touchedLines.size();
|
||||||
// Total number of (un)supported refs that were converted.
|
// Total number of (un)supported refs that were converted.
|
||||||
int supportedSum = supported.getConvSum();
|
int supportedSum = supported.getConvSum();
|
||||||
int unsupportedSum = unsupported.getConvSum();
|
int unsupportedSum = unsupported.getConvSum();
|
||||||
|
int allSum = supportedSum + unsupportedSum;
|
||||||
printStat(csv, printOut, "CONVERTED refs count", supportedSum);
|
printStat(csv, printOut, "CONVERTED refs count", supportedSum);
|
||||||
printStat(csv, printOut, "UNCONVERTED refs count", unsupportedSum);
|
printStat(csv, printOut, "UNCONVERTED refs count", unsupportedSum);
|
||||||
printStat(csv, printOut, "CONVERSION %", 100 - std::lround(double(unsupportedSum * 100) / double(supportedSum + unsupportedSum)));
|
printStat(csv, printOut, "CONVERSION %", 100 - (0 == allSum ? 100 : std::lround(double(unsupportedSum * 100) / double(allSum))));
|
||||||
printStat(csv, printOut, "REPLACED bytes", touchedBytes);
|
printStat(csv, printOut, "REPLACED bytes", touchedBytes);
|
||||||
printStat(csv, printOut, "TOTAL bytes", totalBytes);
|
printStat(csv, printOut, "TOTAL bytes", totalBytes);
|
||||||
printStat(csv, printOut, "CHANGED lines of code", changedLines);
|
printStat(csv, printOut, "CHANGED lines of code", changedLines);
|
||||||
printStat(csv, printOut, "TOTAL lines of code", totalLines);
|
printStat(csv, printOut, "TOTAL lines of code", totalLines);
|
||||||
if (totalBytes > 0) {
|
printStat(csv, printOut, "CODE CHANGED (in bytes) %", 0 == totalBytes ? 0 : std::lround(double(touchedBytes * 100) / double(totalBytes)));
|
||||||
printStat(csv, printOut, "CODE CHANGED (in bytes) %", std::lround(double(touchedBytes * 100) / double(totalBytes)));
|
printStat(csv, printOut, "CODE CHANGED (in lines) %", 0 == totalLines ? 0 : std::lround(double(changedLines * 100) / double(totalLines)));
|
||||||
}
|
|
||||||
if (totalLines > 0) {
|
|
||||||
printStat(csv, printOut, "CODE CHANGED (in lines) %", std::lround(double(changedLines * 100) / double(totalLines)));
|
|
||||||
}
|
|
||||||
typedef std::chrono::duration<double, std::milli> duration;
|
typedef std::chrono::duration<double, std::milli> duration;
|
||||||
duration elapsed = completionTime - startTime;
|
duration elapsed = completionTime - startTime;
|
||||||
std::stringstream stream;
|
std::stringstream stream;
|
||||||
@@ -199,6 +204,7 @@ void Statistics::print(std::ostream* csv, llvm::raw_ostream* printOut, bool skip
|
|||||||
|
|
||||||
void Statistics::printAggregate(std::ostream *csv, llvm::raw_ostream* printOut) {
|
void Statistics::printAggregate(std::ostream *csv, llvm::raw_ostream* printOut) {
|
||||||
Statistics globalStats = getAggregate();
|
Statistics globalStats = getAggregate();
|
||||||
|
globalStats.hasErrors = false;
|
||||||
conditionalPrint(csv, printOut, "\nTOTAL statistics:\n", "\n[HIPIFY] info: TOTAL statistics:\n");
|
conditionalPrint(csv, printOut, "\nTOTAL statistics:\n", "\n[HIPIFY] info: TOTAL statistics:\n");
|
||||||
// A file is considered "converted" if we made any changes to it.
|
// A file is considered "converted" if we made any changes to it.
|
||||||
int convertedFiles = 0;
|
int convertedFiles = 0;
|
||||||
@@ -206,16 +212,23 @@ void Statistics::printAggregate(std::ostream *csv, llvm::raw_ostream* printOut)
|
|||||||
if (!p.second.touchedLines.empty()) {
|
if (!p.second.touchedLines.empty()) {
|
||||||
convertedFiles++;
|
convertedFiles++;
|
||||||
}
|
}
|
||||||
|
if (!globalStats.hasErrors && p.second.hasErrors) {
|
||||||
|
globalStats.hasErrors = true;
|
||||||
|
}
|
||||||
|
if (globalStats.startTime > p.second.startTime) {
|
||||||
|
globalStats.startTime = p.second.startTime;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
printStat(csv, printOut, "CONVERTED files", convertedFiles);
|
printStat(csv, printOut, "CONVERTED files", convertedFiles);
|
||||||
printStat(csv, printOut, "PROCESSED files", stats.size());
|
printStat(csv, printOut, "PROCESSED files", stats.size());
|
||||||
|
globalStats.markCompletion();
|
||||||
globalStats.print(csv, printOut);
|
globalStats.print(csv, printOut);
|
||||||
}
|
}
|
||||||
|
|
||||||
//// Static state management ////
|
//// Static state management ////
|
||||||
|
|
||||||
Statistics Statistics::getAggregate() {
|
Statistics Statistics::getAggregate() {
|
||||||
Statistics globalStats("global");
|
Statistics globalStats("GLOBAL");
|
||||||
for (const auto& p : stats) {
|
for (const auto& p : stats) {
|
||||||
globalStats.add(p.second);
|
globalStats.add(p.second);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -158,8 +158,8 @@ class Statistics {
|
|||||||
StatCounter unsupported;
|
StatCounter unsupported;
|
||||||
std::string fileName;
|
std::string fileName;
|
||||||
std::set<int> touchedLines = {};
|
std::set<int> touchedLines = {};
|
||||||
int touchedBytes = 0;
|
unsigned touchedBytes = 0;
|
||||||
int totalLines = 0;
|
unsigned totalLines = 0;
|
||||||
int totalBytes = 0;
|
int totalBytes = 0;
|
||||||
chr::steady_clock::time_point startTime;
|
chr::steady_clock::time_point startTime;
|
||||||
chr::steady_clock::time_point completionTime;
|
chr::steady_clock::time_point completionTime;
|
||||||
@@ -202,4 +202,6 @@ public:
|
|||||||
* timestamp into the currently active one.
|
* timestamp into the currently active one.
|
||||||
*/
|
*/
|
||||||
static void setActive(const std::string& name);
|
static void setActive(const std::string& name);
|
||||||
|
// Set this flag in case of hipification errors
|
||||||
|
bool hasErrors = false;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -117,6 +117,8 @@ int main(int argc, const char **argv) {
|
|||||||
Tool.appendArgumentsAdjuster(ct::getClangSyntaxOnlyAdjuster());
|
Tool.appendArgumentsAdjuster(ct::getClangSyntaxOnlyAdjuster());
|
||||||
// Hipify _all_ the things!
|
// Hipify _all_ the things!
|
||||||
if (Tool.runAndSave(&actionFactory)) {
|
if (Tool.runAndSave(&actionFactory)) {
|
||||||
|
Statistics& currentStat = Statistics::current();
|
||||||
|
currentStat.hasErrors = true;
|
||||||
LLVM_DEBUG(llvm::dbgs() << "Skipped some replacements.\n");
|
LLVM_DEBUG(llvm::dbgs() << "Skipped some replacements.\n");
|
||||||
}
|
}
|
||||||
// Either move the tmpfile to the output, or remove it.
|
// Either move the tmpfile to the output, or remove it.
|
||||||
|
|||||||
新增問題並參考
封鎖使用者