Simulated product dispenser

Dependencies:   HTS221

Fork of mbed-cloud-workshop-connect-HTS221 by Jim Carver

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers esfs_performance.c Source File

esfs_performance.c

00001 /*
00002  * Copyright (c) 2016 ARM Limited. All rights reserved.
00003  * SPDX-License-Identifier: Apache-2.0
00004  * Licensed under the Apache License, Version 2.0 (the License); you may
00005  * 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, WITHOUT
00012  * 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 #include <stdio.h>
00018 #include <string.h>
00019 #include "esfs_performance.h"
00020 
00021 #ifdef  ESFS_PERFOMANCE_TEST // Allow disabling calls to performance
00022 
00023 #include "mbed-trace/mbed_trace.h"
00024 
00025 #define TRACE_GROUP         "esfs"  // Maximum 4 characters
00026 #define TICKS_PER_MICROSEC  120 // FIXME Replace with pal_osKernelSysMilliSecTick when it will work
00027 
00028 static performance_record_t performance_array[PERFORMANCE_ARRAY_SIZE]={{{0}, 0}};
00029 static unsigned long performance_index = 0;
00030 
00031 void print_performance()
00032 {
00033 unsigned long i;
00034 char type_title[10];
00035     for (i=0;i<performance_index;i++)
00036     {
00037         if (performance_array[i].type == ESFS_PERFORMANCE_END)
00038         {
00039             strcpy(type_title,"end  ");
00040             tr_cmdline("\nPerformance %s %s %lu %lu",
00041                 performance_array[i].title,
00042                 type_title,
00043                 performance_array[i].mark,
00044                 performance_array[i].total);
00045         }
00046         else
00047         {
00048             strcpy(type_title,"start  ");
00049             tr_cmdline("\nPerformance %s %s %lu",
00050                 performance_array[i].title,
00051                 type_title,
00052                 performance_array[i].total);
00053         }
00054     }
00055     performance_index = 0;
00056     tr_cmdline("\nIndex=%lu",performance_index);
00057 
00058 }
00059 void add_performance_mark(const char * title, esfs_performance_type_e type)
00060 {
00061     unsigned long mark  = (unsigned long)(pal_osKernelSysTick()/TICKS_PER_MICROSEC);
00062     performance_array[performance_index].mark = mark;
00063     strncpy(performance_array[performance_index].title, title, TITLE_MAX);
00064     performance_array[performance_index].total=0;
00065     performance_array[performance_index].type=type;
00066     if (type == ESFS_PERFORMANCE_END)
00067     {
00068         // find the start mark
00069         for (unsigned long j=performance_index-1;j>=0;j--)
00070         {
00071             if (!strncmp(performance_array[j].title,title,TITLE_MAX))
00072             {
00073                 performance_array[performance_index].total = mark - performance_array[j].mark;
00074                 break;
00075             }
00076         }
00077     }
00078 
00079     if (performance_index++ >= (PERFORMANCE_ARRAY_SIZE-1))
00080     {
00081         print_performance();
00082     }
00083 }
00084 
00085 
00086 #endif  // ESFS_PERFOMANCE_TEST
00087 
00088