added statistics

This commit is contained in:
ALEXks
2024-10-07 14:50:37 +03:00
parent 5fda069476
commit 1a1705d2e4
3 changed files with 125 additions and 13 deletions

View File

@@ -16,6 +16,8 @@
#include "../DynamicAnalysis/gcov_info.h"
#include "PredictScheme.h"
#include "../Utils/SgUtils.h"
#include "../DirectiveProcessing/directive_parser.h"
#include "../Distribution/DvmhDirective.h"
using std::map;
using std::string;
@@ -125,7 +127,7 @@ void processFileToPredict(SgFile *file, PredictorStats &predictorCounts)
predictorCounts.TotalScorePar += predictorCounts.ParallelCount;
}
static void calculate_for_parallel_loop(SgStatement* loop, const map<int, Gcov_info>& gcov,
static void calculateForParallelLoop(SgStatement* loop, const map<int, Gcov_info>& gcov,
uint64_t& paralle_exec_count, uint64_t& count_of_parallel_lines) {
for (auto st = loop; st != loop->lastNodeOfStmt(); st = st->lexNext()) {
int line = st->lineNumber();
@@ -150,39 +152,42 @@ static void calculate_for_parallel_loop(SgStatement* loop, const map<int, Gcov_i
}
}
void calculate_stats_for_predictor(const map<string, vector<FuncInfo*>>& allFuncInfo,
void calculateStatsForPredictor(const map<string, vector<FuncInfo*>>& allFuncInfo,
const map<string, map<int, Gcov_info>>& gCovInfo) {
uint64_t total_exec_count = 0;
uint64_t parallel_exec_count = 0;
uint64_t count_of_parallel_lines = 0;
for (auto& byFile : allFuncInfo) {
for (auto& byFile : allFuncInfo)
{
int ok = SgFile::switchToFile(byFile.first);
if (ok == -1)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
auto it = gCovInfo.find(byFile.first);
if (it == gCovInfo.end()) {
if (it == gCovInfo.end())
{
__spf_print(1, "bad gcov info\n");
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
}
auto& gcov = it->second;
for (auto& func : byFile.second) {
for (auto& func : byFile.second)
{
SgStatement* stat = func->funcPointer->GetOriginal();
for (auto st = stat->lexNext(); st != stat->lastNodeOfStmt(); st = st->lexNext())
{
uint64_t paralle_exec = 0;
uint64_t lines_count = 0;
if (st->variant() == DVM_PARALLEL_ON_DIR) {
if (st->variant() == DVM_PARALLEL_ON_DIR)
{
auto loop = st->lexNext();
checkNull(loop, convertFileName(__FILE__).c_str(), __LINE__);
if (loop->variant() != FOR_NODE)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
calculate_for_parallel_loop(loop, gcov, paralle_exec, lines_count);
calculateForParallelLoop(loop, gcov, paralle_exec, lines_count);
st = loop->lastNodeOfStmt();
parallel_exec_count += paralle_exec;
@@ -207,8 +212,8 @@ void calculate_stats_for_predictor(const map<string, vector<FuncInfo*>>& allFunc
continue;
auto& info = it->second;
if (info.getNumLine() != line) {
if (info.getNumLine() != line)
{
__spf_print(1, "bad gcov info\n");
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
}
@@ -226,3 +231,106 @@ void calculate_stats_for_predictor(const map<string, vector<FuncInfo*>>& allFunc
stats << "parallel_rate;" << parallel_exec_count / (double)total_exec_count << std::endl;
stats.close();
}
void parseDvmDirForPredictor(const map<string, vector<FuncInfo*>>& allFuncInfo,
const map<string, map<int, Gcov_info>>& gCovInfo)
{
ofstream dirs("dirs.csv");
for (auto& byFile : allFuncInfo)
{
int ok = SgFile::switchToFile(byFile.first);
if (ok == -1)
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
auto it = gCovInfo.find(byFile.first);
if (it == gCovInfo.end())
{
__spf_print(1, "bad gcov info\n");
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
}
auto& gcov = it->second;
for (auto& func : byFile.second)
{
SgStatement* stat = func->funcPointer->GetOriginal();
for (auto st = stat->lexNext(); st != stat->lastNodeOfStmt(); st = st->lexNext())
{
SgExpression* list;
SgExpression* dup;
auto line = 0;
switch (st->variant())
{
case DVM_PARALLEL_ON_DIR:
{
auto stat = st;
while (isDVM_stat(stat))
stat = stat->lexPrev();
line = stat->lineNumber(); // XXX
list = st->expr(1);
auto it = gcov.find(line);
auto& info = it->second;
if (info.getNumLine() != line)
{
__spf_print(1, "bad gcov info\n");
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
}
dirs << info.getExecutedCount() << ";" << "PARALLEL;" << st->expr(2)->unparse() << ";" << st->expr(0)->unparse() << ";";
while (list)
{
dirs << list->lhs()->unparse() << ";";
list = list->rhs();
}
dirs << std::endl;
}
break;
case DVM_VAR_DECL: // TODO
dup = st->expr(2)->lhs()->copyPtr();
dup->setLhs(NULL);
dirs << "1;" << dup->unparse() << ";" << st->expr(2)->lhs()->lhs()->unparse() << ";" << st->expr(0)->unparse() << ";\n";
break;
case DVM_DISTRIBUTE_DIR:
dirs << "1;" << "DISTRIBUTE;" << st->expr(1)->unparse() << ";" << st->expr(0)->unparse() << ";\n";
break;
case DVM_ALIGN_DIR:
dirs << "1;" << "ALIGN;" << st->expr(0)->unparse() << "(" << st->expr(1)->unparse() << ");" << st->expr(2)->unparse() << ";\n";
break;
case DVM_SHADOW_DIR:
dirs << "1;" << "SHADOW;" << st->expr(0)->unparse() << "(" << st->expr(1)->unparse() << ");\n";
break;
case DVM_REMOTE_ACCESS_DIR:
{
line = st->lexNext()->lineNumber();
auto it = gcov.find(line);
auto& info = it->second;
if (info.getNumLine() != line)
{
__spf_print(1, "bad gcov info\n");
printInternalError(convertFileName(__FILE__).c_str(), __LINE__);
}
dirs << info.getExecutedCount() << ";" << "REMOTE_ACCESS;";
list = st->expr(0);
while (list)
{
dirs << list->lhs()->unparse() << ";";
list = list->rhs();
}
dirs << "\n";
break;
}
default:
//printf("var = %d line %d\n", st->variant(), st->lineNumber());
break;
}
}
}
}
dirs.close();
}

View File

@@ -54,4 +54,5 @@ public:
void processFileToPredict(SgFile *file, PredictorStats &predictorCounts);
void calculate_stats_for_predictor(const std::map<std::string, std::vector<FuncInfo*>>& allFuncInfo, const std::map<std::string, std::map<int, Gcov_info>>& gCovInfo);
void calculateStatsForPredictor(const std::map<std::string, std::vector<FuncInfo*>>& allFuncInfo, const std::map<std::string, std::map<int, Gcov_info>>& gCovInfo);
void parseDvmDirForPredictor(const std::map<std::string, std::vector<FuncInfo*>>& allFuncInfo, const std::map<std::string, std::map<int, Gcov_info>>& gCovInfo);

View File

@@ -1894,7 +1894,10 @@ static bool runAnalysis(SgProject &project, const int curr_regime, const bool ne
else if (curr_regime == GET_MIN_MAX_BLOCK_DIST)
__spf_print(1, "GET_MIN_MAX_BLOCK_DIST: %d %d\n", min_max_block.first, min_max_block.second);
else if (curr_regime == GET_STATS_FOR_PREDICTOR)
calculate_stats_for_predictor(allFuncInfo, gCovInfo);
{
calculateStatsForPredictor(allFuncInfo, gCovInfo);
parseDvmDirForPredictor(allFuncInfo, gCovInfo);
}
const float elapsed = duration_cast<milliseconds>(high_resolution_clock::now() - timeForPass).count() / 1000.;
const float elapsedGlobal = duration_cast<milliseconds>(high_resolution_clock::now() - globalTime).count() / 1000.;