Adding rocprofilerv2

Change-Id: Ic0cc280ba207d2b8f6ccae1cd4ac3184152fc1ad


[ROCm/rocprofiler commit: 8032adb64f]
Tento commit je obsažen v:
Ammar ELWazir
2023-02-03 12:31:39 -06:00
rodič b23a2f3029
revize de4abd0d0f
263 změnil soubory, kde provedl 607729 přidání a 307 odebrání
@@ -0,0 +1,170 @@
/*
Copyright (c) 2015-2016 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include "utils/csv_parser.h"
namespace rocmtools {
namespace tests {
namespace utility {
// Tokenize a comma separated string and saves result in vector
int CSVParser::GetTockenizedString(std::string str,
std::vector<std::string> &stringVec,
char delim) {
char *token = strtok(const_cast<char *>(str.c_str()), &delim);
while (token) {
std::string temp = token;
stringVec.push_back(temp);
token = strtok(NULL, &delim);
}
return stringVec.size();
}
// Get map for collected counters
countermap &CSVParser::GetCounterMap() { return counter_map_; }
// Read counter value based on row-column
std::string *CSVParser::ReadCounter(uint32_t row, uint32_t col) {
auto itr = counter_map_.find(row);
if (itr != counter_map_.end()) {
std::map<uint32_t, std::string> &rowmap = itr->second;
auto it = rowmap.find(col);
if (it != rowmap.end()) {
return &(it->second);
} else {
return nullptr;
}
} else {
return nullptr;
}
}
// Parses CSV file and saves result in a map
void CSVParser::ParseCSV(const char *path) {
FILE *pFile = fopen(path, "r");
if (pFile) {
// Relocate the file pointer on the stream.
fseek(pFile, 0, SEEK_END);
// returns the current file position of the specified stream
// with respect to the starting of the file
uint32_t uSize = ftell(pFile);
// Make the position pointer of the file pFile point
// to the beginning of the file
rewind(pFile);
char *fileBuffer = new char[uSize];
size_t size = fread(fileBuffer, 1, uSize, pFile);
if (size < 0) std::cerr << "Incorrect File!" << std::endl;
std::map<uint32_t, std::string> rowmap;
uint32_t uiIndex = 1;
char *pBegin = fileBuffer;
char *pEnd = strchr(pBegin, '\n');
// The beginning of the second line, discarding the first line
pBegin = pEnd + 1;
pEnd = strchr(pBegin, '\n');
while (pEnd) {
std::string tmp;
tmp.insert(0, pBegin, pEnd - pBegin);
assert(!tmp.empty());
// Store the string of each line in the map,
// the key is the sequence number,
// and the value is the string
rowmap[uiIndex++] = tmp;
pBegin = pEnd + 1;
pEnd = strchr(pBegin, '\n');
}
// clear buffers
delete[] fileBuffer;
fileBuffer = nullptr;
pBegin = nullptr;
pEnd = nullptr;
auto itr = rowmap.begin();
for (; itr != rowmap.end(); ++itr) {
std::vector<std::string> countervec;
std::map<uint32_t, std::string> rowmap_tmp;
assert(GetTockenizedString(itr->second, countervec) > 0);
std::vector<std::string>::size_type idx = 0;
for (; idx != countervec.size(); ++idx) {
rowmap_tmp[idx + 1] = countervec[idx];
}
counter_map_[itr->first] = rowmap_tmp;
}
}
fclose(pFile);
}
// Parses profiler output buffer and saves result in a map
void CSVParser::ParseCSV(std::string buffer) {
std::vector<char> buff(buffer.begin(), buffer.end());
char *pBegin = &buff[0];
char *pEnd = strchr(pBegin, '\n');
// The beginning of the second line, discarding the first line
pBegin = pEnd + 1;
pEnd = strchr(pBegin, '\n');
std::map<uint32_t, std::string> rowmap;
uint32_t uiIndex = 1;
while (pEnd) {
std::string tmp;
tmp.insert(0, pBegin, pEnd - pBegin);
// Store the string of each line in the map,
// the key is the sequence number,
// and the value is the string
rowmap[uiIndex++] = tmp;
pBegin = pEnd + 1;
pEnd = strchr(pBegin, '\n');
}
// clear buffers
buff.clear();
pBegin = nullptr;
pEnd = nullptr;
auto itr = rowmap.begin();
for (; itr != rowmap.end(); ++itr) {
std::vector<std::string> countervec;
std::map<uint32_t, std::string> rowmap_tmp;
GetTockenizedString(itr->second, countervec);
std::vector<std::string>::size_type idx = 0;
for (; idx != countervec.size(); ++idx) {
rowmap_tmp[idx + 1] = countervec[idx];
}
counter_map_[itr->first] = rowmap_tmp;
}
}
} // namespace utility
} // namespace tests
} // namespace rocmtools
+118
Zobrazit soubor
@@ -0,0 +1,118 @@
/*
Copyright (c) 2015-2016 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef TESTS_FEATURETESTS_PROFILER_UTILS_CSV_PARSER_H_
#define TESTS_FEATURETESTS_PROFILER_UTILS_CSV_PARSER_H_
#include <assert.h>
#include <stdio.h>
#include <cstring>
#include <iostream>
#include <map>
#include <string>
#include <vector>
/* --------------------------------------------------------------------------*/
/**
* @Synopsis Implementation of a CSV Parser class for Profiler output
* when running to collect counters.Subsequent counter collection tests
* can use this to parse different applications.
*/
/* --------------------------------------------------------------------------*/
namespace rocmtools {
namespace tests {
namespace utility {
using countermap = std::map<uint32_t, std::map<uint32_t, std::string>>;
class CSVParser {
public:
CSVParser() {}
/**
* Parses CSV file and saves result in a map
*
* Stores csv data as a 2-D array in row-column format
* Skips first line of input csv as it only contains field names
*
* @param[in] path Pointer to the csv path.
*
* @return Returns 0 on success and -1 on error.
*/
void ParseCSV(const char *path);
/**
* Parses profiler output buffer and saves result in a map
*
* Stores csv data as a 2-D array in row-column format
* Skips first line of input csv as it only contains field names
*
* @param[in] path Pointer to the csv path.
*
* @return Returns 0 on success and -1 on error.
*/
void ParseCSV(std::string buffer);
/**
* Read counter value based on row-column
*
* @param[in] row row number to be read in csv.
*
* @param[in] col column to be read in csv.(i.e: counter value)
*
* @return If found, returns counter value as a string pointer, nullptr
* otherwise.
*/
std::string *ReadCounter(uint32_t row, uint32_t col);
/**
* Tokenize a comma separated string and saves result in vector
*
* @param[in] str input string to be tokenized
*
* @param[in] csvtable vector to store tokenized values
*
* @param[in] delim delimitre used for tokenizing
*
* @return returns vector size of delimitd values
*/
int GetTockenizedString(std::string str, std::vector<std::string> &csvtable,
char delim = ',');
/**
* A getter for a map of collected counters
* *
* @return Returns a map of collected counters.
*/
countermap &GetCounterMap();
private:
// map for counter collection
countermap counter_map_;
};
} // namespace utility
} // namespace tests
} // namespace rocmtools
using rocmtools::tests::utility::countermap;
using rocmtools::tests::utility::CSVParser;
#endif // TESTS_FEATURETESTS_PROFILER_UTILS_CSV_PARSER_H_
@@ -0,0 +1,64 @@
/*
Copyright (c) 2015-2016 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include "utils/test_utils.h"
namespace rocmtools {
namespace tests {
namespace utility {
// This function returns the running path of executable
std::string GetRunningPath(std::string string_to_erase) {
std::string path;
char *real_path;
Dl_info dl_info;
if (0 != dladdr(reinterpret_cast<void *>(main), &dl_info)) {
std::string to_erase = string_to_erase;
path = dl_info.dli_fname;
real_path = realpath(path.c_str(), NULL);
if (real_path == nullptr) {
throw(std::string("Error! in extracting real path"));
}
path.clear(); // reset path
path.append(real_path);
size_t pos = path.find(to_erase);
if (pos != std::string::npos) path.erase(pos, to_erase.length());
} else {
throw(std::string("Error! in extracting real path"));
}
return path;
}
// This function returns number of cores
// available in system
int GetNumberOfCores() {
std::ifstream cpuinfo("/proc/cpuinfo");
const int num_cpu_cores = std::count(
std::istream_iterator<std::string>(cpuinfo),
std::istream_iterator<std::string>(), std::string("processor"));
return num_cpu_cores;
}
} // namespace utility
} // namespace tests
} // namespace rocmtools
+57
Zobrazit soubor
@@ -0,0 +1,57 @@
/*
Copyright (c) 2015-2016 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef TESTS_FEATURETESTS_PROFILER_UTILS_TEST_UTILS_H_
#define TESTS_FEATURETESTS_PROFILER_UTILS_TEST_UTILS_H_
#include <cxxabi.h> // for __cxa_demangle
#include <dlfcn.h> // for dladdr
#include <execinfo.h> // for backtrace
#include <algorithm>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <iterator>
#include <string>
namespace rocmtools {
namespace tests {
namespace utility {
// Get current running path
std::string GetRunningPath(std::string string_to_erase);
// Get Number of cores in the system
int GetNumberOfCores();
} // namespace utility
} // namespace tests
} // namespace rocmtools
// used for dl_addr to locate the running
// path for executable
int main(int argc, char** argv);
using rocmtools::tests::utility::GetNumberOfCores;
using rocmtools::tests::utility::GetRunningPath;
#endif // TESTS_FEATURETESTS_PROFILER_UTILS_TEST_UTILS_H_