You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2020/10/20 08:50:06 UTC
[GitHub] [nifi-minifi-cpp] adamdebreceni opened a new pull request #928: MINIFICPP-1394 - Speed up ConsumeWindowsEventLog processor
adamdebreceni opened a new pull request #928:
URL: https://github.com/apache/nifi-minifi-cpp/pull/928
Thank you for submitting a contribution to Apache NiFi - MiNiFi C++.
In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:
### For all changes:
- [ ] Is there a JIRA ticket associated with this PR? Is it referenced
in the commit message?
- [ ] Does your PR title start with MINIFICPP-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
- [ ] Has your PR been rebased against the latest commit within the target branch (typically main)?
- [ ] Is your initial contribution a single, squashed commit?
### For code changes:
- [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)?
- [ ] If applicable, have you updated the LICENSE file?
- [ ] If applicable, have you updated the NOTICE file?
### For documentation related changes:
- [ ] Have you ensured that format looks appropriate for the output in which it is rendered?
### Note:
Please ensure that once the PR is submitted, you check GitHub Actions CI results for build issues and submit an update to your PR as soon as possible.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] szaszm commented on a change in pull request #928: MINIFICPP-1394 - Speed up ConsumeWindowsEventLog processor
Posted by GitBox <gi...@apache.org>.
szaszm commented on a change in pull request #928:
URL: https://github.com/apache/nifi-minifi-cpp/pull/928#discussion_r509169143
##########
File path: extensions/windows-event-log/wel/WindowsEventLog.cpp
##########
@@ -43,10 +45,10 @@ void WindowsEventLogMetadataImpl::renderMetadata() {
const auto contextGuard = gsl::finally([&context](){
EvtClose(context);
});
- if (!EvtRender(context, event_ptr_, EvtRenderEventValues, dwBufferSize, nullptr, &dwBufferUsed, &dwPropertyCount)) {
+ if (!EvtRender(context, event_ptr_, EvtRenderEventValues, dwBufferSize, rendered_values.get(), &dwBufferUsed, &dwPropertyCount)) {
if (ERROR_INSUFFICIENT_BUFFER == (status = GetLastError())) {
dwBufferSize = dwBufferUsed;
- rendered_values = std::unique_ptr<EVT_VARIANT, utils::FreeDeleter>((PEVT_VARIANT)(malloc(dwBufferSize)));
+ rendered_values.reset((PEVT_VARIANT)(malloc(dwBufferSize)));
Review comment:
Sorry, I missed that one. It's fine this way.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] arpadboda closed pull request #928: MINIFICPP-1394 - Speed up ConsumeWindowsEventLog processor
Posted by GitBox <gi...@apache.org>.
arpadboda closed pull request #928:
URL: https://github.com/apache/nifi-minifi-cpp/pull/928
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on pull request #928: MINIFICPP-1394 - Speed up ConsumeWindowsEventLog processor
Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on pull request #928:
URL: https://github.com/apache/nifi-minifi-cpp/pull/928#issuecomment-712732711
with the following setup: CWEL -> LogAttribute, CWEL: {batch commit size: 1000, output format both, 1 sec timer driven}, LogAttribute: {1000 batch size, event driven, log level: debug, payload: false}, and setting the log level globally to ERROR, yields the following statistics:
<img width="694" alt="Screenshot 2020-10-20 at 11 46 03" src="https://user-images.githubusercontent.com/64783590/96570119-411c4e80-12ca-11eb-9df7-70f223191367.png">
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] szaszm commented on a change in pull request #928: MINIFICPP-1394 - Speed up ConsumeWindowsEventLog processor
Posted by GitBox <gi...@apache.org>.
szaszm commented on a change in pull request #928:
URL: https://github.com/apache/nifi-minifi-cpp/pull/928#discussion_r508369819
##########
File path: extensions/windows-event-log/wel/WindowsEventLog.cpp
##########
@@ -129,34 +133,30 @@ std::string WindowsEventLogMetadataImpl::getEventData(EVT_FORMAT_MESSAGE_FLAGS f
return event_data;
}
- if (!EvtFormatMessage(metadata_ptr_, event_ptr_, 0, 0, NULL, flags, string_buffer_size, string_buffer, &string_buffer_used)) {
+
+ if (!EvtFormatMessage(metadata_ptr_, event_ptr_, 0, 0, NULL, flags, string_buffer_size, string_buffer.get(), &string_buffer_used)) {
result = GetLastError();
if (ERROR_INSUFFICIENT_BUFFER == result) {
string_buffer_size = string_buffer_used;
- string_buffer = (LPWSTR) malloc(string_buffer_size * sizeof(WCHAR));
-
- if (string_buffer) {
+ string_buffer.reset((LPWSTR) malloc(string_buffer_size * sizeof(WCHAR)));
Review comment:
Again, this should allocate `string_buffer_used`. No multiplication with `sizeof(WCHAR)` needed, because the size is already in bytes.
##########
File path: extensions/windows-event-log/wel/WindowsEventLog.cpp
##########
@@ -43,10 +45,10 @@ void WindowsEventLogMetadataImpl::renderMetadata() {
const auto contextGuard = gsl::finally([&context](){
EvtClose(context);
});
- if (!EvtRender(context, event_ptr_, EvtRenderEventValues, dwBufferSize, nullptr, &dwBufferUsed, &dwPropertyCount)) {
+ if (!EvtRender(context, event_ptr_, EvtRenderEventValues, dwBufferSize, rendered_values.get(), &dwBufferUsed, &dwPropertyCount)) {
if (ERROR_INSUFFICIENT_BUFFER == (status = GetLastError())) {
dwBufferSize = dwBufferUsed;
- rendered_values = std::unique_ptr<EVT_VARIANT, utils::FreeDeleter>((PEVT_VARIANT)(malloc(dwBufferSize)));
+ rendered_values.reset((PEVT_VARIANT)(malloc(dwBufferSize)));
Review comment:
This should allocate `dwBufferUsed` bytes as that's the out param of `EvtRender`. I assume this is a typo, because it's used correctly elsewhere.
```suggestion
rendered_values.reset((PEVT_VARIANT)(malloc(dwBufferUsed)));
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] fgerlits commented on a change in pull request #928: MINIFICPP-1394 - Speed up ConsumeWindowsEventLog processor
Posted by GitBox <gi...@apache.org>.
fgerlits commented on a change in pull request #928:
URL: https://github.com/apache/nifi-minifi-cpp/pull/928#discussion_r508332309
##########
File path: extensions/windows-event-log/ConsumeWindowsEventLog.cpp
##########
@@ -514,30 +515,33 @@ void ConsumeWindowsEventLog::substituteXMLPercentageItems(pugi::xml_document& do
bool ConsumeWindowsEventLog::createEventRender(EVT_HANDLE hEvent, EventRender& eventRender) {
logger_->log_trace("Rendering an event");
- DWORD size = 0;
+ DWORD size = sizeof(WCHAR) * 4096;
+ WCHAR stackBuffer[4096];
+ using Deleter = utils::StackAwareDeleter<WCHAR, utils::FreeDeleter>;
+ std::unique_ptr<WCHAR, Deleter> buf{stackBuffer, Deleter{ stackBuffer }};
+
DWORD used = 0;
DWORD propertyCount = 0;
- EvtRender(NULL, hEvent, EvtRenderEventXml, size, 0, &used, &propertyCount);
- if (ERROR_INSUFFICIENT_BUFFER != GetLastError()) {
- LOG_LAST_ERROR(EvtRender);
- return false;
- }
-
- if (used > maxBufferSize_) {
- logger_->log_error("Dropping event because it couldn't be rendered within %" PRIu64 " bytes.", maxBufferSize_);
- return false;
- }
-
- size = used;
- std::vector<wchar_t> buf(size / 2 + 1);
- if (!EvtRender(NULL, hEvent, EvtRenderEventXml, size, &buf[0], &used, &propertyCount)) {
- LOG_LAST_ERROR(EvtRender);
- return false;
+ if (!EvtRender(NULL, hEvent, EvtRenderEventXml, size, buf.get(), &used, &propertyCount)) {
+ if (ERROR_INSUFFICIENT_BUFFER != GetLastError()) {
+ LOG_LAST_ERROR(EvtRender);
+ return false;
+ }
+ if (used > maxBufferSize_) {
+ logger_->log_error("Dropping event because it couldn't be rendered within %" PRIu64 " bytes.", maxBufferSize_);
+ return false;
+ }
+ size = used;
+ buf.reset((LPWSTR)malloc(size));
+ if (!EvtRender(NULL, hEvent, EvtRenderEventXml, size, buf.get(), &used, &propertyCount)) {
+ LOG_LAST_ERROR(EvtRender);
+ return false;
+ }
}
logger_->log_debug("Event rendered with size %" PRIu32 ". Performing doc traversing...", size);
Review comment:
if the first (on-stack) `EvtRender` is successful, then `size` has not been set to `used` at this point, it is still `sizeof(WCHAR) * 4096`
```suggestion
logger_->log_debug("Event rendered with size %" PRIu32 ". Performing doc traversing...", used);
```
##########
File path: extensions/windows-event-log/ConsumeWindowsEventLog.cpp
##########
@@ -514,30 +515,33 @@ void ConsumeWindowsEventLog::substituteXMLPercentageItems(pugi::xml_document& do
bool ConsumeWindowsEventLog::createEventRender(EVT_HANDLE hEvent, EventRender& eventRender) {
logger_->log_trace("Rendering an event");
- DWORD size = 0;
+ DWORD size = sizeof(WCHAR) * 4096;
+ WCHAR stackBuffer[4096];
+ using Deleter = utils::StackAwareDeleter<WCHAR, utils::FreeDeleter>;
+ std::unique_ptr<WCHAR, Deleter> buf{stackBuffer, Deleter{ stackBuffer }};
+
DWORD used = 0;
DWORD propertyCount = 0;
- EvtRender(NULL, hEvent, EvtRenderEventXml, size, 0, &used, &propertyCount);
- if (ERROR_INSUFFICIENT_BUFFER != GetLastError()) {
- LOG_LAST_ERROR(EvtRender);
- return false;
- }
-
- if (used > maxBufferSize_) {
- logger_->log_error("Dropping event because it couldn't be rendered within %" PRIu64 " bytes.", maxBufferSize_);
- return false;
- }
-
- size = used;
- std::vector<wchar_t> buf(size / 2 + 1);
- if (!EvtRender(NULL, hEvent, EvtRenderEventXml, size, &buf[0], &used, &propertyCount)) {
- LOG_LAST_ERROR(EvtRender);
- return false;
+ if (!EvtRender(NULL, hEvent, EvtRenderEventXml, size, buf.get(), &used, &propertyCount)) {
+ if (ERROR_INSUFFICIENT_BUFFER != GetLastError()) {
+ LOG_LAST_ERROR(EvtRender);
+ return false;
+ }
+ if (used > maxBufferSize_) {
+ logger_->log_error("Dropping event because it couldn't be rendered within %" PRIu64 " bytes.", maxBufferSize_);
+ return false;
+ }
+ size = used;
+ buf.reset((LPWSTR)malloc(size));
Review comment:
I think we should check if the `malloc` succeeded (also in `getEventData()`)
##########
File path: extensions/windows-event-log/wel/WindowsEventLog.cpp
##########
@@ -129,34 +133,30 @@ std::string WindowsEventLogMetadataImpl::getEventData(EVT_FORMAT_MESSAGE_FLAGS f
return event_data;
}
- if (!EvtFormatMessage(metadata_ptr_, event_ptr_, 0, 0, NULL, flags, string_buffer_size, string_buffer, &string_buffer_used)) {
+
+ if (!EvtFormatMessage(metadata_ptr_, event_ptr_, 0, 0, NULL, flags, string_buffer_size, string_buffer.get(), &string_buffer_used)) {
result = GetLastError();
if (ERROR_INSUFFICIENT_BUFFER == result) {
string_buffer_size = string_buffer_used;
- string_buffer = (LPWSTR) malloc(string_buffer_size * sizeof(WCHAR));
-
- if (string_buffer) {
+ string_buffer.reset((LPWSTR) malloc(string_buffer_size * sizeof(WCHAR)));
- if ((EvtFormatMessageKeyword == flags))
- string_buffer[string_buffer_size - 1] = L'\0';
-
- EvtFormatMessage(metadata_ptr_, event_ptr_, 0, 0, NULL, flags, string_buffer_size, string_buffer, &string_buffer_used);
- if ((EvtFormatMessageKeyword == flags))
- string_buffer[string_buffer_used - 1] = L'\0';
- std::wstring str(string_buffer);
- event_data = std::string(str.begin(), str.end());
- free(string_buffer);
- }
+ EvtFormatMessage(metadata_ptr_, event_ptr_, 0, 0, NULL, flags, string_buffer_size, string_buffer.get(), &string_buffer_used);
}
}
+ if ((EvtFormatMessageKeyword == flags))
+ string_buffer.get()[string_buffer_used - 1] = L'\0';
+ std::wstring str(string_buffer.get());
+ event_data = std::string(str.begin(), str.end());
return event_data;
}
std::string WindowsEventLogHandler::getEventMessage(EVT_HANDLE eventHandle) const {
std::string returnValue;
- std::unique_ptr<WCHAR, utils::FreeDeleter> pBuffer;
- DWORD dwBufferSize = 0;
+ DWORD dwBufferSize = 4096;
Review comment:
here, too, I would rename this
##########
File path: extensions/windows-event-log/wel/WindowsEventLog.cpp
##########
@@ -118,8 +120,10 @@ void WindowsEventLogMetadataImpl::renderMetadata() {
}
std::string WindowsEventLogMetadataImpl::getEventData(EVT_FORMAT_MESSAGE_FLAGS flags) const {
- LPWSTR string_buffer = NULL;
- DWORD string_buffer_size = 0;
+ DWORD string_buffer_size = 4096;
Review comment:
I don't know why Microsoft decided to call this `BufferSize` but store the number of characters in it, but we could give it a better name, eg. `num_chars_in_buffer`.
##########
File path: extensions/windows-event-log/wel/WindowsEventLog.cpp
##########
@@ -129,34 +133,30 @@ std::string WindowsEventLogMetadataImpl::getEventData(EVT_FORMAT_MESSAGE_FLAGS f
return event_data;
}
- if (!EvtFormatMessage(metadata_ptr_, event_ptr_, 0, 0, NULL, flags, string_buffer_size, string_buffer, &string_buffer_used)) {
+
+ if (!EvtFormatMessage(metadata_ptr_, event_ptr_, 0, 0, NULL, flags, string_buffer_size, string_buffer.get(), &string_buffer_used)) {
result = GetLastError();
if (ERROR_INSUFFICIENT_BUFFER == result) {
string_buffer_size = string_buffer_used;
- string_buffer = (LPWSTR) malloc(string_buffer_size * sizeof(WCHAR));
-
- if (string_buffer) {
+ string_buffer.reset((LPWSTR) malloc(string_buffer_size * sizeof(WCHAR)));
- if ((EvtFormatMessageKeyword == flags))
- string_buffer[string_buffer_size - 1] = L'\0';
-
- EvtFormatMessage(metadata_ptr_, event_ptr_, 0, 0, NULL, flags, string_buffer_size, string_buffer, &string_buffer_used);
- if ((EvtFormatMessageKeyword == flags))
- string_buffer[string_buffer_used - 1] = L'\0';
- std::wstring str(string_buffer);
- event_data = std::string(str.begin(), str.end());
- free(string_buffer);
- }
+ EvtFormatMessage(metadata_ptr_, event_ptr_, 0, 0, NULL, flags, string_buffer_size, string_buffer.get(), &string_buffer_used);
}
}
+ if ((EvtFormatMessageKeyword == flags))
Review comment:
minor, and old code, but why do we have double `(())` here?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #928: MINIFICPP-1394 - Speed up ConsumeWindowsEventLog processor
Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #928:
URL: https://github.com/apache/nifi-minifi-cpp/pull/928#discussion_r509021609
##########
File path: extensions/windows-event-log/wel/WindowsEventLog.cpp
##########
@@ -129,34 +133,30 @@ std::string WindowsEventLogMetadataImpl::getEventData(EVT_FORMAT_MESSAGE_FLAGS f
return event_data;
}
- if (!EvtFormatMessage(metadata_ptr_, event_ptr_, 0, 0, NULL, flags, string_buffer_size, string_buffer, &string_buffer_used)) {
+
+ if (!EvtFormatMessage(metadata_ptr_, event_ptr_, 0, 0, NULL, flags, string_buffer_size, string_buffer.get(), &string_buffer_used)) {
result = GetLastError();
if (ERROR_INSUFFICIENT_BUFFER == result) {
string_buffer_size = string_buffer_used;
- string_buffer = (LPWSTR) malloc(string_buffer_size * sizeof(WCHAR));
-
- if (string_buffer) {
+ string_buffer.reset((LPWSTR) malloc(string_buffer_size * sizeof(WCHAR)));
- if ((EvtFormatMessageKeyword == flags))
- string_buffer[string_buffer_size - 1] = L'\0';
-
- EvtFormatMessage(metadata_ptr_, event_ptr_, 0, 0, NULL, flags, string_buffer_size, string_buffer, &string_buffer_used);
- if ((EvtFormatMessageKeyword == flags))
- string_buffer[string_buffer_used - 1] = L'\0';
- std::wstring str(string_buffer);
- event_data = std::string(str.begin(), str.end());
- free(string_buffer);
- }
+ EvtFormatMessage(metadata_ptr_, event_ptr_, 0, 0, NULL, flags, string_buffer_size, string_buffer.get(), &string_buffer_used);
}
}
+ if ((EvtFormatMessageKeyword == flags))
Review comment:
done
##########
File path: extensions/windows-event-log/ConsumeWindowsEventLog.cpp
##########
@@ -514,30 +515,33 @@ void ConsumeWindowsEventLog::substituteXMLPercentageItems(pugi::xml_document& do
bool ConsumeWindowsEventLog::createEventRender(EVT_HANDLE hEvent, EventRender& eventRender) {
logger_->log_trace("Rendering an event");
- DWORD size = 0;
+ DWORD size = sizeof(WCHAR) * 4096;
+ WCHAR stackBuffer[4096];
+ using Deleter = utils::StackAwareDeleter<WCHAR, utils::FreeDeleter>;
+ std::unique_ptr<WCHAR, Deleter> buf{stackBuffer, Deleter{ stackBuffer }};
+
DWORD used = 0;
DWORD propertyCount = 0;
- EvtRender(NULL, hEvent, EvtRenderEventXml, size, 0, &used, &propertyCount);
- if (ERROR_INSUFFICIENT_BUFFER != GetLastError()) {
- LOG_LAST_ERROR(EvtRender);
- return false;
- }
-
- if (used > maxBufferSize_) {
- logger_->log_error("Dropping event because it couldn't be rendered within %" PRIu64 " bytes.", maxBufferSize_);
- return false;
- }
-
- size = used;
- std::vector<wchar_t> buf(size / 2 + 1);
- if (!EvtRender(NULL, hEvent, EvtRenderEventXml, size, &buf[0], &used, &propertyCount)) {
- LOG_LAST_ERROR(EvtRender);
- return false;
+ if (!EvtRender(NULL, hEvent, EvtRenderEventXml, size, buf.get(), &used, &propertyCount)) {
+ if (ERROR_INSUFFICIENT_BUFFER != GetLastError()) {
+ LOG_LAST_ERROR(EvtRender);
+ return false;
+ }
+ if (used > maxBufferSize_) {
+ logger_->log_error("Dropping event because it couldn't be rendered within %" PRIu64 " bytes.", maxBufferSize_);
+ return false;
+ }
+ size = used;
+ buf.reset((LPWSTR)malloc(size));
Review comment:
done
##########
File path: extensions/windows-event-log/wel/WindowsEventLog.cpp
##########
@@ -129,34 +133,30 @@ std::string WindowsEventLogMetadataImpl::getEventData(EVT_FORMAT_MESSAGE_FLAGS f
return event_data;
}
- if (!EvtFormatMessage(metadata_ptr_, event_ptr_, 0, 0, NULL, flags, string_buffer_size, string_buffer, &string_buffer_used)) {
+
+ if (!EvtFormatMessage(metadata_ptr_, event_ptr_, 0, 0, NULL, flags, string_buffer_size, string_buffer.get(), &string_buffer_used)) {
result = GetLastError();
if (ERROR_INSUFFICIENT_BUFFER == result) {
string_buffer_size = string_buffer_used;
- string_buffer = (LPWSTR) malloc(string_buffer_size * sizeof(WCHAR));
-
- if (string_buffer) {
+ string_buffer.reset((LPWSTR) malloc(string_buffer_size * sizeof(WCHAR)));
- if ((EvtFormatMessageKeyword == flags))
- string_buffer[string_buffer_size - 1] = L'\0';
-
- EvtFormatMessage(metadata_ptr_, event_ptr_, 0, 0, NULL, flags, string_buffer_size, string_buffer, &string_buffer_used);
- if ((EvtFormatMessageKeyword == flags))
- string_buffer[string_buffer_used - 1] = L'\0';
- std::wstring str(string_buffer);
- event_data = std::string(str.begin(), str.end());
- free(string_buffer);
- }
+ EvtFormatMessage(metadata_ptr_, event_ptr_, 0, 0, NULL, flags, string_buffer_size, string_buffer.get(), &string_buffer_used);
}
}
+ if ((EvtFormatMessageKeyword == flags))
+ string_buffer.get()[string_buffer_used - 1] = L'\0';
+ std::wstring str(string_buffer.get());
+ event_data = std::string(str.begin(), str.end());
return event_data;
}
std::string WindowsEventLogHandler::getEventMessage(EVT_HANDLE eventHandle) const {
std::string returnValue;
- std::unique_ptr<WCHAR, utils::FreeDeleter> pBuffer;
- DWORD dwBufferSize = 0;
+ DWORD dwBufferSize = 4096;
Review comment:
done
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #928: MINIFICPP-1394 - Speed up ConsumeWindowsEventLog processor
Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #928:
URL: https://github.com/apache/nifi-minifi-cpp/pull/928#discussion_r509021203
##########
File path: extensions/windows-event-log/ConsumeWindowsEventLog.cpp
##########
@@ -514,30 +515,33 @@ void ConsumeWindowsEventLog::substituteXMLPercentageItems(pugi::xml_document& do
bool ConsumeWindowsEventLog::createEventRender(EVT_HANDLE hEvent, EventRender& eventRender) {
logger_->log_trace("Rendering an event");
- DWORD size = 0;
+ DWORD size = sizeof(WCHAR) * 4096;
+ WCHAR stackBuffer[4096];
+ using Deleter = utils::StackAwareDeleter<WCHAR, utils::FreeDeleter>;
+ std::unique_ptr<WCHAR, Deleter> buf{stackBuffer, Deleter{ stackBuffer }};
+
DWORD used = 0;
DWORD propertyCount = 0;
- EvtRender(NULL, hEvent, EvtRenderEventXml, size, 0, &used, &propertyCount);
- if (ERROR_INSUFFICIENT_BUFFER != GetLastError()) {
- LOG_LAST_ERROR(EvtRender);
- return false;
- }
-
- if (used > maxBufferSize_) {
- logger_->log_error("Dropping event because it couldn't be rendered within %" PRIu64 " bytes.", maxBufferSize_);
- return false;
- }
-
- size = used;
- std::vector<wchar_t> buf(size / 2 + 1);
- if (!EvtRender(NULL, hEvent, EvtRenderEventXml, size, &buf[0], &used, &propertyCount)) {
- LOG_LAST_ERROR(EvtRender);
- return false;
+ if (!EvtRender(NULL, hEvent, EvtRenderEventXml, size, buf.get(), &used, &propertyCount)) {
+ if (ERROR_INSUFFICIENT_BUFFER != GetLastError()) {
+ LOG_LAST_ERROR(EvtRender);
+ return false;
+ }
+ if (used > maxBufferSize_) {
+ logger_->log_error("Dropping event because it couldn't be rendered within %" PRIu64 " bytes.", maxBufferSize_);
+ return false;
+ }
+ size = used;
+ buf.reset((LPWSTR)malloc(size));
+ if (!EvtRender(NULL, hEvent, EvtRenderEventXml, size, buf.get(), &used, &propertyCount)) {
+ LOG_LAST_ERROR(EvtRender);
+ return false;
+ }
}
logger_->log_debug("Event rendered with size %" PRIu32 ". Performing doc traversing...", size);
Review comment:
done
##########
File path: extensions/windows-event-log/wel/WindowsEventLog.cpp
##########
@@ -118,8 +120,10 @@ void WindowsEventLogMetadataImpl::renderMetadata() {
}
std::string WindowsEventLogMetadataImpl::getEventData(EVT_FORMAT_MESSAGE_FLAGS flags) const {
- LPWSTR string_buffer = NULL;
- DWORD string_buffer_size = 0;
+ DWORD string_buffer_size = 4096;
Review comment:
done
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #928: MINIFICPP-1394 - Speed up ConsumeWindowsEventLog processor
Posted by GitBox <gi...@apache.org>.
adamdebreceni commented on a change in pull request #928:
URL: https://github.com/apache/nifi-minifi-cpp/pull/928#discussion_r509023703
##########
File path: extensions/windows-event-log/wel/WindowsEventLog.cpp
##########
@@ -43,10 +45,10 @@ void WindowsEventLogMetadataImpl::renderMetadata() {
const auto contextGuard = gsl::finally([&context](){
EvtClose(context);
});
- if (!EvtRender(context, event_ptr_, EvtRenderEventValues, dwBufferSize, nullptr, &dwBufferUsed, &dwPropertyCount)) {
+ if (!EvtRender(context, event_ptr_, EvtRenderEventValues, dwBufferSize, rendered_values.get(), &dwBufferUsed, &dwPropertyCount)) {
if (ERROR_INSUFFICIENT_BUFFER == (status = GetLastError())) {
dwBufferSize = dwBufferUsed;
- rendered_values = std::unique_ptr<EVT_VARIANT, utils::FreeDeleter>((PEVT_VARIANT)(malloc(dwBufferSize)));
+ rendered_values.reset((PEVT_VARIANT)(malloc(dwBufferSize)));
Review comment:
if you check all api calls, you can see that it first assigns the required buffer size (here `dwBufferUsed `) to the variable storing the actual buffer size (here `dwBufferSize `) and then calls `malloc` with the actual buffer size (modulo if it is in bytes or chars)
do you think it would be an improvement in readability if we allocate based on the required buffer size and then assign it to the actual buffer size?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [nifi-minifi-cpp] szaszm commented on a change in pull request #928: MINIFICPP-1394 - Speed up ConsumeWindowsEventLog processor
Posted by GitBox <gi...@apache.org>.
szaszm commented on a change in pull request #928:
URL: https://github.com/apache/nifi-minifi-cpp/pull/928#discussion_r508687901
##########
File path: extensions/windows-event-log/wel/WindowsEventLog.cpp
##########
@@ -129,34 +133,30 @@ std::string WindowsEventLogMetadataImpl::getEventData(EVT_FORMAT_MESSAGE_FLAGS f
return event_data;
}
- if (!EvtFormatMessage(metadata_ptr_, event_ptr_, 0, 0, NULL, flags, string_buffer_size, string_buffer, &string_buffer_used)) {
+
+ if (!EvtFormatMessage(metadata_ptr_, event_ptr_, 0, 0, NULL, flags, string_buffer_size, string_buffer.get(), &string_buffer_used)) {
result = GetLastError();
if (ERROR_INSUFFICIENT_BUFFER == result) {
string_buffer_size = string_buffer_used;
- string_buffer = (LPWSTR) malloc(string_buffer_size * sizeof(WCHAR));
-
- if (string_buffer) {
+ string_buffer.reset((LPWSTR) malloc(string_buffer_size * sizeof(WCHAR)));
Review comment:
oops, this is outdated
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org