mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-20 00:24:58 +08:00
Suppressing output could be achieved with quiet option "-q", but some information was gone because of it. Call to oclocInvoke with output parameters passed should not print message to stdout. All messages should be stored, and returned to the user via output as stdout.log file. This commit turns off printing messages to stdout when output parameters are present. Signed-off-by: Krystian Chmielewski <krystian.chmielewski@intel.com>
71 lines
1.8 KiB
C++
71 lines
1.8 KiB
C++
/*
|
|
* Copyright (C) 2018-2022 Intel Corporation
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*
|
|
*/
|
|
|
|
#pragma once
|
|
#include "shared/source/os_interface/os_library.h"
|
|
|
|
#include "igfxfmid.h"
|
|
|
|
#include <exception>
|
|
#include <memory>
|
|
#include <sstream>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
void addSlash(std::string &path);
|
|
|
|
std::vector<char> readBinaryFile(const std::string &fileName);
|
|
|
|
void readFileToVectorOfStrings(std::vector<std::string> &lines, const std::string &fileName, bool replaceTabs = false);
|
|
|
|
size_t findPos(const std::vector<std::string> &lines, const std::string &whatToFind);
|
|
|
|
PRODUCT_FAMILY getProductFamilyFromDeviceName(const std::string &deviceName);
|
|
|
|
class MessagePrinter {
|
|
public:
|
|
MessagePrinter() = default;
|
|
MessagePrinter(bool suppressMessages) : suppressMessages(suppressMessages) {}
|
|
|
|
void printf(const char *message) {
|
|
if (!suppressMessages) {
|
|
::printf("%s", message);
|
|
}
|
|
ss << std::string(message);
|
|
}
|
|
|
|
template <typename... Args>
|
|
void printf(const char *format, Args... args) {
|
|
if (!suppressMessages) {
|
|
::printf(format, std::forward<Args>(args)...);
|
|
}
|
|
ss << stringFormat(format, std::forward<Args>(args)...);
|
|
}
|
|
|
|
const std::stringstream &getLog() {
|
|
return ss;
|
|
}
|
|
|
|
bool isSuppressed() const { return suppressMessages; }
|
|
|
|
private:
|
|
template <typename... Args>
|
|
std::string stringFormat(const std::string &format, Args... args) {
|
|
std::string outputString;
|
|
size_t size = static_cast<size_t>(snprintf(nullptr, 0, format.c_str(), args...) + 1);
|
|
if (size <= 0) {
|
|
return outputString;
|
|
}
|
|
outputString.resize(size);
|
|
snprintf(&*outputString.begin(), size, format.c_str(), args...);
|
|
return outputString.c_str();
|
|
}
|
|
|
|
std::stringstream ss;
|
|
bool suppressMessages = false;
|
|
};
|