Mayank Gupta / Mbed OS pelion-example-frdm

Dependencies:   FXAS21002 FXOS8700Q

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers fcc_time_profiling.c Source File

fcc_time_profiling.c

00001 // ----------------------------------------------------------------------------
00002 // Copyright 2016-2017 ARM Ltd.
00003 //  
00004 // Licensed under the Apache License, Version 2.0 (the "License");
00005 // you may not use this file except in compliance with the License.
00006 // You may obtain a copy of the License at
00007 //  
00008 //     http://www.apache.org/licenses/LICENSE-2.0
00009 //  
00010 // Unless required by applicable law or agreed to in writing, software
00011 // distributed under the License is distributed on an "AS IS" BASIS,
00012 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013 // See the License for the specific language governing permissions and
00014 // limitations under the License.
00015 // ----------------------------------------------------------------------------
00016 
00017 
00018 #include "fcc_time_profiling.h"
00019 
00020 #ifdef FCC_TIME_PROFILING
00021 
00022 uint64_t fcc_gen_timer = 0;
00023 uint64_t fcc_bundle_timer = 0;
00024 uint64_t fcc_key_timer = 0;
00025 uint64_t fcc_certificate_timer = 0;
00026 uint64_t fcc_config_param_timer = 0;
00027 uint64_t fcc_certificate_chain_timer = 0;
00028 uint64_t fcc_generate_csr_timer = 0;
00029 
00030 
00031 /**
00032 *  The function calculates time from started timer, prints the label as string or as buffer with size and the calulated time.
00033 **/
00034 
00035 void calculate_time(const char *label, size_t size, uint64_t ticks)
00036 {
00037     static double ticks_persecond = 0.0;
00038     static double ticks_permillisecond = 0.0;
00039     static double ticks_permicrosecond = 0.0;
00040 
00041     // Since the tick conversion to time functions on some of the reference platforms give incorrect results,
00042     // we use pal_osDelay() to estimate how many ticks per second. We do this once and then base all
00043     // subsequent calculations on the values that we store in static variables.
00044     // For new platforms the accuracy of pal_osDelay() should be verified before accepting the time results.
00045     if (ticks_persecond == 0.0)
00046     {
00047         // Calculate how many ticks per second
00048         uint64_t tick1 = pal_osKernelSysTick();
00049         // One second delay
00050         pal_osDelay(1000);
00051         uint64_t tick2 = pal_osKernelSysTick();
00052         ticks_persecond = tick2 - tick1;
00053         ticks_permillisecond = ticks_persecond / 1000.0;
00054         ticks_permicrosecond = ticks_persecond / 1000000.0;
00055     }
00056     if (size == 0) {
00057         //Print string
00058         mbed_tracef(TRACE_LEVEL_ERROR, TRACE_GROUP, "%s: %20lu ticks, %10.2lf milli, %10.2lf micro\n", (char*)label, (long unsigned int)ticks, (double)(ticks / ticks_permillisecond), (double)(ticks / ticks_permicrosecond));
00059     }  else {
00060         //Print buffer with size "size"
00061         mbed_tracef(TRACE_LEVEL_ERROR, TRACE_GROUP, "%.*s: %20lu ticks, %10.2lf milli, %10.2lf micro\n",size, label, (long unsigned int)ticks, (double)(ticks / ticks_permillisecond), (double)(ticks / ticks_permicrosecond));
00062     }
00063 
00064 }
00065 
00066 
00067 #endif
00068