Simple profiler for IDF Monitor

JoaoLopesF
Posts: 59
Joined: Thu Aug 17, 2017 5:40 pm

Simple profiler for IDF Monitor

Postby JoaoLopesF » Wed Sep 06, 2017 4:37 pm

I needed to make a simple profiler for my project,
so I modified idf_monitor.py for this.

It's very simple, I read the time in micros at the beginning of each line,
calculate and show the difference between the time of the line and the time of the previous line
and display this in yellow or red.
There is an parameter in line 276:
self.MIN_MICROS_RED = 50 #if the time is equal or greater, show profiler in red

This was very useful for me, because my project was generating a lot of debugging, and with this profiler it became easier to identify the bottlenecks

Follow the file idf_monitor.py, just go to $ IDF_PATH, rename the original file and copy the new idf_monitor.py

I am not a python programmer,
I tried to put a control-key for turn on / off the profiler, but I did not succeed

If the profiler is useful to other people,
my suggestion is that this can be evaluated, corrected and go to the framework.

I hope it's useful

Regards

Joao Lopes
-------------

An example of the profiler in action (please note the value after P( ):

I (4114) P (0) wifi :: Connected !!! IP: 192.168.0.117
I (4119) P (5) wifi :: Initialized -> Running callback
I (4125) P (6) uart :: Submitting data: (22) -> T0123456789001234567890
I (4131) P (6) socket_server :: WiFi connected
I (4135) P (4) socket_server :: Creating TCP Server ...
I (4141) P (6) socket_server :: Creating TCP port server = NNNN
I (4148) P (7) socket_server :: TCP server created successfully!
I (4153) P (5) socket_server :: Socket Server initialized
I (4159) P (6) socket_server :: Server socket - waiting for connections ...
I (4646) P (487) main :: test
I (5646) P (1000) main :: test
I (6646) P (1000) main :: test
I (7646) P (1000) main :: test
I (8646) P (1000) main :: test

permal
Posts: 384
Joined: Sun May 14, 2017 5:36 pm

Re: Simple profiler for IDF Monitor

Postby permal » Wed Sep 06, 2017 6:03 pm

I like this idea, simple but useful.

JoaoLopesF
Posts: 59
Joined: Thu Aug 17, 2017 5:40 pm

Re: Simple profiler for IDF Monitor

Postby JoaoLopesF » Wed Sep 06, 2017 6:17 pm

Hi, I do a new version of profiler with some improvements.

Please download it in github: https://github.com/JoaoLopesF/ESP-IDF-M ... e_Profiler

Tip: In MacOSX or Linux, You can put the out of monitor in a file, for for further analysis:

For MacOSX (tested):

Code: Select all

make monitor | tee monitor.txt
LC_ALL=C sed -i -- $'s/\x1b\\[[0-9;]*[a-zA-Z]//g' monitor.txt
For Linux (not tested):

Code: Select all

make monitor | tee monitor.txt
sed -r "s/\x1B\[(([0-9]+)(;[0-9]+)*)?[m,K,H,f,J]//g"  monitor.txt
The sed is for remove escapes sequences of colors

You can put this in your .bash_profile (tested on MacOSX)

Code: Select all


# Espressif - IDF

esp32() {
  echo "Setting the environment for  Esp32 IDF"
  export PATH=$PATH:<put your path here>/xtensa-esp32-elf/bin
  export IDF_PATH=<put your path here>/esp-idf
}

esp32cd() {
  cd <put your projects path here>
  ls
}
esp32template () {
  [ "$1" == "" ] && exit
  git clone https://github.com/espressif/esp-idf-template.git $1
  cd "$1" || exit
  sed -i -- 's/ttyUSB0/tty.SLAB_USBtoUART/g' sdkconfig
  ls
  echo "* Project created!"
}
esp32mon() {
  make monitor
}
esp32monlog() {
  make monitor | tee monitor.txt
  LC_ALL=C sed -i -- $'s/\x1b\\[[0-9;]*[a-zA-Z]//g' monitor.txt
  echo "** monitor.txt saved"
}
esp32killmon() {
  ps | fgrep idf_monitor | fgrep python
  set `ps | fgrep idf_monitor | fgrep python`
  if [ $# -gt 0 ] ; then
     echo Kill ESP32 Monitor - PID $1
     kill -9 $1
  fi
}   
esp32make() {
  esp32killmon
  make 
}
esp32flash() {
  esp32killmon
  make flash
}      
esp32cfg() {
  make menuconfig
}
After edit, you must reload it:

Code: Select all

. .bash_profile
So you can use this "macros":

Code: Select all

esp32
esp32cd
cd <project>
esp32monlog
I hope it's useful
Regards

Joao Lopes

zhivko
Posts: 23
Joined: Tue Dec 01, 2015 12:02 pm

Re: Simple profiler for IDF Monitor

Postby zhivko » Fri Mar 08, 2019 10:32 am

Very nice tool! :!: Thanks!
Can you show printf line where you print micros() - I think this is needed for profiler to properly read time diferences?

Who is online

Users browsing this forum: walkabout and 61 guests