This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Code execution time

Hi,

I'am using sdk14.2 with S140 V5.0.2-alpha.

I want to measure a time execution of a snippet code (ciphering function), and i want to display the time value with NRF_LOG_INFO, or SEGGER_rtt.

i know that there are other methods like toggling GPIO and then use a logic analyzer to visualize  the timing, but i don't have a logic analyzer.

Can any body propose me a method to proceed?

Parents
  • Hi,

    You can setup the application timer library, and use the functions app_timer_cnt_get before and after your function call, and app_timer_cnt_diff_compute at the end to compute the time spent by the function. Note that this will give you the value in ticks, and you will have to calculate the actual time if you need this. Also note that if any interrupts happens within the function, the time spent handling the interrupts will also be counted.

    Best regards,
    Jørgen

  • Hi ,

    Thanks for reply, i had exactly the same idea, i put app_timer_cnt_get() before and after my cifer funtion but in result i have "0".

    i don't know why i have this result but it's seems like when i debug the code, the RTC don't count !!,

    here a snippet code of my application

    /*my cifer function */
    static void skip_encrypt(void){
    	uint32_t begin = 0;
    	uint32_t end = 0;
    
    	/*variables of the cifer function*/
        static BYTE Key[_SKIP32_KEY_LEN] = {1,5,16,18,50,47,54,42,32,47};
        DWORD encrypt = 15;
        DWORD invalue = 45;
    
        /*where i want to calculate code time */
        begin = app_timer_cnt_get();
    	skip32_initWithKey(Key);
        skip32_encrypt(&encrypt,invalue);
        end = app_timer_cnt_get();
        NRF_LOG_INFO("result time in ticks = %d \n", app_timer_cnt_diff_compute(end,begin));
       }
    /**
     * @brief Function for application main entry.
     */
    int main(void)
    {
    	log_init();
    	timers_init();
    	skip_encrypt();
    	ble_stack_init();
    	.
    	.
    	.
    	.
    	.
    	.
    	
    	advertising_init();
    	advertising_start();
    
    
    
    	//application_timers_start();
    	// Enter main loop.
    	for (;;) {
    		if (NRF_LOG_PROCESS() == false) {
    			power_manage();
    		}
    	}
    
    }

    Do you have any idea why i have 0 in output ?

    just a remarque : when i put the first app_timer_cnt_get() just after timer_init(), and the second after advertising_start(), i have an output of "3"

    Regards,

Reply
  • Hi ,

    Thanks for reply, i had exactly the same idea, i put app_timer_cnt_get() before and after my cifer funtion but in result i have "0".

    i don't know why i have this result but it's seems like when i debug the code, the RTC don't count !!,

    here a snippet code of my application

    /*my cifer function */
    static void skip_encrypt(void){
    	uint32_t begin = 0;
    	uint32_t end = 0;
    
    	/*variables of the cifer function*/
        static BYTE Key[_SKIP32_KEY_LEN] = {1,5,16,18,50,47,54,42,32,47};
        DWORD encrypt = 15;
        DWORD invalue = 45;
    
        /*where i want to calculate code time */
        begin = app_timer_cnt_get();
    	skip32_initWithKey(Key);
        skip32_encrypt(&encrypt,invalue);
        end = app_timer_cnt_get();
        NRF_LOG_INFO("result time in ticks = %d \n", app_timer_cnt_diff_compute(end,begin));
       }
    /**
     * @brief Function for application main entry.
     */
    int main(void)
    {
    	log_init();
    	timers_init();
    	skip_encrypt();
    	ble_stack_init();
    	.
    	.
    	.
    	.
    	.
    	.
    	
    	advertising_init();
    	advertising_start();
    
    
    
    	//application_timers_start();
    	// Enter main loop.
    	for (;;) {
    		if (NRF_LOG_PROCESS() == false) {
    			power_manage();
    		}
    	}
    
    }

    Do you have any idea why i have 0 in output ?

    just a remarque : when i put the first app_timer_cnt_get() just after timer_init(), and the second after advertising_start(), i have an output of "3"

    Regards,

Children
No Data
Related