1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
/*
* Copyright (C) 2020-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "level_zero/core/source/module/module_build_log.h"
#include "shared/source/helpers/debug_helpers.h"
#include "shared/source/helpers/string.h"
#include <string>
namespace L0 {
struct ModuleBuildLogImp : public ModuleBuildLog {
ModuleBuildLogImp() {}
~ModuleBuildLogImp() override {}
ze_result_t destroy() override {
delete this;
return ZE_RESULT_SUCCESS;
}
ze_result_t getString(size_t *pSize, char *pBuildLog) override {
const size_t requiredSize{buildLog.size() + 1};
if (pBuildLog == nullptr) {
*pSize = requiredSize;
return ZE_RESULT_SUCCESS;
}
if (*pSize < requiredSize) {
return ZE_RESULT_ERROR_INVALID_SIZE;
}
memcpy_s(pBuildLog, *pSize, buildLog.c_str(), buildLog.size());
pBuildLog[buildLog.size()] = '\0';
*pSize = requiredSize;
return ZE_RESULT_SUCCESS;
}
void appendString(const char *pBuildLog, size_t size) override {
if ((pBuildLog == nullptr) || (size == 0) || (pBuildLog[0] == '\0')) {
return;
}
if (pBuildLog[size - 1] == '\0') {
--size;
}
if (this->buildLog.length() != 0) {
this->buildLog.append("\n");
}
this->buildLog.append(pBuildLog, size);
}
protected:
std::string buildLog;
};
ModuleBuildLog *ModuleBuildLog::create() {
auto moduleBuildLog = new ModuleBuildLogImp();
UNRECOVERABLE_IF(moduleBuildLog == nullptr);
return moduleBuildLog;
}
} // namespace L0
|