Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log_dump: Add api to get size of the log dump #6394

Merged
merged 2 commits into from
Sep 17, 2024

Conversation

ritesh55555
Copy link
Contributor

This commit adds an api to get the size of the compressed log dump.

Copy link
Contributor

@sunghan-chang sunghan-chang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove log_dump.c from the title. You don't make a change only in that file.

@ritesh55555 ritesh55555 changed the title log_dump/log_dump.c: Add api to get size of the log dump log_dump: Add api to get size of the log dump Sep 11, 2024
apps/examples/log_dump/log_dump_main.c Outdated Show resolved Hide resolved
size_t log_dump_get_size(void)
{
size_t size = 0;
struct log_dump_chunk_s* head = (struct log_dump_chunk_s *)sq_peek(&log_dump_chunks);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In code readability, head != tail? It looks strange.
How about renaming the variable like log_node?
It does not have the head always.

Comment on lines 512 to 531
while (head != (struct log_dump_chunk_s *)sq_tail(&log_dump_chunks)) {
head = (struct log_dump_chunk_s *)sq_next((sq_entry_t *)head);
size += CONFIG_LOG_DUMP_CHUNK_SIZE;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Don't you need to do lock / unlock for log dump?
  2. If tail should be fixed, I think we can get it once. Not every while loop.
  3. How about calculating current size at every node allocation and free in some static global variable? We already need to get current size to adjust node total size based on free heap size.

Comment on lines 520 to 521
* Note: It is recommended to use this log_dump_get_size api after
* log_dump_read_wake() is performed, so that it has correct value of last_comp_block_size.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

App will use this API and App can't know whether log_dump_read_wake is performed or not. This recommendation looks redundant. Is there any other way to do it automatically?

* Note: It is recommended to use this log_dump_get_size api after
* log_dump_read_wake() is performed, so that it has correct value of last_comp_block_size.
* Else it might add old last_comp_block_size which is already present in log_dump_chunk list */
size += last_comp_block_size;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You return compressed log size + uncompressed log size. When we read saved log dump, don't we compress uncompressed log?? If we don't, then how can we know how many data should be uncompressed and how many data should be used as it is?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Earlier, when we were opening the procfs file of log dump, it was compressing the partially filled log buffer. Now the compressing the partially filled log buffer has been shifted to when log dump save is stopped . So that whenever we stop log dump process, we will compress the partially filled log buffer and update the size.
two cases while getting log dump size:

  1. When log dump save is true and log dump is saving character : In this case , log dump size will return the size of compressed logs till now in the log_dump_chuck and it will not include last_comp_block_size becuase it is not valid.
  2. when log dump save is false and log dump is not saving : In this case , log dump size will include compressed logs in log_dump_chunk + last_comp_block_size becuase after log dump save is stopped we will compress the last partially filled logs.

@sunghan-chang
Copy link
Contributor

@ritesh55555 One question, after getting the size using new API, is there any chance that node size is changed?
If it can be, app will do abnormal operation.

@ritesh55555
Copy link
Contributor Author

@ritesh55555 One question, after getting the size using new API, is there any chance that node size is changed? If it can be, app will do abnormal operation.

It is recommended that log dump size and log dump read should be done after stopping log dump save process. Else app might not get the value wanted .
Apart from that if app tries to get log dump size during log dump process is happening, then it will get the size of compressed logs till that point.

@ritesh55555 ritesh55555 force-pushed the log_dump_size branch 2 times, most recently from 8046bc3 to aa3b9f9 Compare September 12, 2024 07:59
apps/examples/log_dump/log_dump_main.c Outdated Show resolved Hide resolved
* is compressed and size should include last_comp_block_size */
if (is_started_to_save == false) {
return log_dump_chunk_node_cnt * CONFIG_LOG_DUMP_CHUNK_SIZE + compress_curbytes + last_comp_block_size;
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The else case means, top_logsave has not been called. So, if we return some size here and there is some timegap before read, then the size will differ. It is better to return error code here. This api must be called only when log dump has been stopped.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you added the else case to check stop first. How about adding it at the read function as well? Because it's the same.

@ritesh55555 ritesh55555 force-pushed the log_dump_size branch 2 times, most recently from 2e567e6 to 10cd880 Compare September 12, 2024 09:05
kishore-sn
kishore-sn previously approved these changes Sep 12, 2024
@kishore-sn
Copy link
Contributor

@ritesh55555 Pls add the output of the log dump app in the commit description.

apps/examples/log_dump/log_dump_main.c Show resolved Hide resolved
os/fs/procfs/fs_procfslogsave.c Show resolved Hide resolved
os/kernel/log_dump/log_dump.c Outdated Show resolved Hide resolved
os/kernel/log_dump/log_dump.c Show resolved Hide resolved
	- This commit adds an api to get the size of
	  the compressed log dump. It also places the work
	  of compressing the partially filled log buffer when
	  log save is stopped.
	- This commit add code in log_dump_main app to
	  verify working of log_dump_get_size() api. It
	  calculates total length of compressed logs by
	  continuously reading throught a fixed buffer and
	  then verify the size with the value returned from
	  log_dump_get_size() api.

	  followings are the logs from log_dump_main app:
          (Note the compressed output is commented because it gives
           garbage value , we are only printing to check log dump
           size comparison with total read value from buffer)

          TASH>>log_dump
          TASH>>This Log Should NOT be saved!!!

          *********************   LOG DUMP START  *********************
          This Log Should be saved!!!
          log_dump_size = 2892, and total_read = 2892, Both should be equal

          *********************   LOG DUMP END  ***********************
/* Should we return error from here?? because partially filled uncompressed buffer
* might not be compressed but log_dump save has stopped now, so operation is success */
}
} else if (strncmp(buffer, LOGDUMP_GET_SIZE, strlen(LOGDUMP_GET_SIZE) + 1) == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are 3 strncmp s to check a command. It looks not good.
Because the data is a just character, how about using switch / case?

* is compressed and size should include last_comp_block_size */
if (is_started_to_save == false) {
return log_dump_chunk_node_cnt * CONFIG_LOG_DUMP_CHUNK_SIZE + compress_curbytes + last_comp_block_size;
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you added the else case to check stop first. How about adding it at the read function as well? Because it's the same.

@sunghan-chang
Copy link
Contributor

@ritesh55555 I left two comments, but I think it's different topic against this PR so that you can do that with new PR or new commit.

@kishore-sn kishore-sn merged commit 2f722e6 into Samsung:master Sep 17, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants