Skip to content

Cellular: Improve ATHandler AT debug traces #10121

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

Merged
merged 1 commit into from
Apr 3, 2019
Merged

Cellular: Improve ATHandler AT debug traces #10121

merged 1 commit into from
Apr 3, 2019

Conversation

kivaisan
Copy link
Contributor

@kivaisan kivaisan commented Mar 15, 2019

Description

Original AT debug traces had several issues:

  • Can be overwritten by other traces (printf/mbed-trace)
  • No way to know which direction message was going (TX or RX)
  • and characters were not visible in trace
    etc.

This commit addresses those issues using mbed-trace and showing separately
each filehandle write and read.

Pull request type

[X] Fix
[ ] Refactor
[ ] Target update
[ ] Functionality change
[ ] Docs update
[ ] Test update
[ ] Breaking change

Reviewers

@AriParkkila @mirelachirica @jarvte

Release Notes

@ciarmcom ciarmcom requested review from AriParkkila, jarvte, mirelachirica and a team March 15, 2019 12:00
@ciarmcom
Copy link
Member

@kivaisan, thank you for your changes.
@AriParkkila @mirelachirica @jarvte @ARMmbed/mbed-os-wan @ARMmbed/mbed-os-maintainers please review.

@NirSonnenschein
Copy link
Contributor

@kivaisan , please fix the a-style issues

@kivaisan
Copy link
Contributor Author

a-style issues are now fixed.

@@ -1225,30 +1222,41 @@ void ATHandler::flush()
}
}

void ATHandler::debug_print(const char *p, int len)
void ATHandler::debug_print(const char *p, int len, ATType type)
Copy link
Contributor

Choose a reason for hiding this comment

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

I really don't like that we have this precedent of internal/external APIs, and which are alright to change in a patch, but so it goes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Especially since this a debug function.

if (isprint(c)) {
*pbuf++ = c;
} else if (c == '\r') {
sprintf(pbuf, "<cr>");
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the commit message. Made it really easy to tell why \r and \n were changed.

@cmonr
Copy link
Contributor

cmonr commented Mar 27, 2019

Anyone else want to review the PR?

@mbed-os-wan @AriParkkila @mirelachirica @jarvte

@AriParkkila
Copy link

This fixes the problems mentioned in the description but it seems to be quite verbose, which is likely to cause timing issues. For example, instead of AT+CEREG? it prints:

[INFO][CELL]: AT TX ( 8): AT+CEREG
[INFO][CELL]: AT TX ( 1): ?
[INFO][CELL]: AT TX ( 1): <cr>

AT debug prints are very useful when running Mbed OS Greentea TESTS. It seems that debug macro (used by the current AT debug) prints now fine but with this new debugging TESTS should be updated to use mbed-trace.

#endif
char c;
const int buf_size = len * 4; // x4 -> reserve space for extra characters
char *buffer = (char *)malloc(buf_size);

Choose a reason for hiding this comment

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

Check for NULL or use nothrow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

mbed_cellular_trace::mutex_wait();
#endif
char c;
const int buf_size = len * 4; // x4 -> reserve space for extra characters

Choose a reason for hiding this comment

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

len * 4 + 1 where +1 for sprintf zero termination.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@kivaisan
Copy link
Contributor Author

@AriParkkila timing issue is true but that is really problematic in our current mbed-os tracing system which uses UART on traces. On the other hand those time traces are really useful in some debugging cases so that's why I'd like to use it. And we get extra overhead especially for RX traces as modems tend to send responses in multiple pieces and there is nothing we can do for it. TX we could maybe improve in future to construct full command before sending. Also debug() prints tend to have a problem that other trace overwrites the written data.

@trowbridgec
Copy link

For what it's worth, I pulled in these changes and was able to diagnose cell module communication issues much easier. This PR is a great idea.

@cmonr
Copy link
Contributor

cmonr commented Mar 28, 2019

CI started

@mbed-ci
Copy link

mbed-ci commented Mar 29, 2019

Test run: FAILED

Summary: 1 of 13 test jobs failed
Build number : 1
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_greentea-test

@alekla01
Copy link
Contributor

Restarted jenkins-ci/greentea-test

@adbridge
Copy link
Contributor

@AriParkkila are you happy with the changes on this PR after review ?

@AriParkkila
Copy link

@kivaisan do you have any idea how to avoid timing issues. I tried this with some real world applications and they tend to fail when this new logging is enabled - That's likely because debug prints take so much time that data from a modem is lost.

@SeppoTakalo do you think we could enable mbed-trace for Mbed OS networking TESTS?

@kivaisan
Copy link
Contributor Author

kivaisan commented Apr 1, 2019

One workaround is to increase baud rate on boards which support bigger baud rates for UART. This (PDMC) seems to work on WISE-1570 with 230400 baud rate, but as long as we use UART, these all are workarounds and we cannot guarantee any trace print is not causing timing issues.

@SeppoTakalo
Copy link
Contributor

Enabling mbed-trace would require code changes and test cases are not using mbed-trace.
I would therefore wait until they provide a module that initialises the trace library automatically, if enabled.

}

delete buffer;
Copy link
Contributor

Choose a reason for hiding this comment

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

You get the buffer from malloc() and free it by calling delete. This is a bit inconstant.

Use malloc()/free() pair or new/delete pair.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Fixed.

Original AT traces had several issue:
- Can be overwritten by other traces (printf/mbed-trace)
- No way to know which direction message was going (TX or RX)
- <cr> and <ln> characters were not visible in trace
etc.

This commit addresses those issues using mbed-trace and showing separately
each filehandle write and read.
@cmonr cmonr requested a review from SeppoTakalo April 1, 2019 19:13
@0xc0170
Copy link
Contributor

0xc0170 commented Apr 2, 2019

CI started

@AriParkkila Please leave the review feedback

@mbed-ci
Copy link

mbed-ci commented Apr 2, 2019

Test run: FAILED

Summary: 1 of 13 test jobs failed
Build number : 2
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_exporter

@0xc0170
Copy link
Contributor

0xc0170 commented Apr 3, 2019

CI was restarted, all green

@0xc0170 0xc0170 merged commit 8cbcc55 into ARMmbed:master Apr 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.