mirror of
https://github.com/GorgonMeducer/perf_counter.git
synced 2025-01-31 19:33:04 +08:00
Major update
- introduce get_system_ticks() - rework on __cycleof__ - update other macros to support gcc extension: ({;;;;}) - update example
This commit is contained in:
parent
04712e54d8
commit
d3ecc136d1
@ -1,24 +1,24 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Auto generated Run-Time-Environment Configuration File
|
* Auto generated Run-Time-Environment Configuration File
|
||||||
* *** Do not modify ! ***
|
* *** Do not modify ! ***
|
||||||
*
|
*
|
||||||
* Project: 'example'
|
* Project: 'example'
|
||||||
* Target: 'example_arm_compiler_6'
|
* Target: 'example_arm_compiler_6'
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef RTE_COMPONENTS_H
|
#ifndef RTE_COMPONENTS_H
|
||||||
#define RTE_COMPONENTS_H
|
#define RTE_COMPONENTS_H
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Define the Device Header File:
|
* Define the Device Header File:
|
||||||
*/
|
*/
|
||||||
#define CMSIS_device_header "ARMCM3.h"
|
#define CMSIS_device_header "ARMCM3.h"
|
||||||
|
|
||||||
/* Keil.ARM Compiler::Compiler:I/O:STDOUT:User:1.2.0 */
|
/* Keil.ARM Compiler::Compiler:I/O:STDOUT:User:1.2.0 */
|
||||||
#define RTE_Compiler_IO_STDOUT /* Compiler I/O: STDOUT */
|
#define RTE_Compiler_IO_STDOUT /* Compiler I/O: STDOUT */
|
||||||
#define RTE_Compiler_IO_STDOUT_User /* Compiler I/O: STDOUT User */
|
#define RTE_Compiler_IO_STDOUT_User /* Compiler I/O: STDOUT User */
|
||||||
|
|
||||||
|
|
||||||
#endif /* RTE_COMPONENTS_H */
|
#endif /* RTE_COMPONENTS_H */
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Auto generated Run-Time-Environment Configuration File
|
* Auto generated Run-Time-Environment Configuration File
|
||||||
* *** Do not modify ! ***
|
* *** Do not modify ! ***
|
||||||
*
|
*
|
||||||
* Project: 'example'
|
* Project: 'example'
|
||||||
* Target: 'library'
|
* Target: 'library'
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef RTE_COMPONENTS_H
|
#ifndef RTE_COMPONENTS_H
|
||||||
#define RTE_COMPONENTS_H
|
#define RTE_COMPONENTS_H
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Define the Device Header File:
|
* Define the Device Header File:
|
||||||
*/
|
*/
|
||||||
#define CMSIS_device_header "ARMCM0.h"
|
#define CMSIS_device_header "ARMCM0.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* RTE_COMPONENTS_H */
|
#endif /* RTE_COMPONENTS_H */
|
||||||
|
@ -150,27 +150,10 @@
|
|||||||
<SetRegEntry>
|
<SetRegEntry>
|
||||||
<Number>0</Number>
|
<Number>0</Number>
|
||||||
<Key>DLGUARM</Key>
|
<Key>DLGUARM</Key>
|
||||||
<Name></Name>
|
<Name>(105=-1,-1,-1,-1,0)(106=-1,-1,-1,-1,0)(107=-1,-1,-1,-1,0)</Name>
|
||||||
</SetRegEntry>
|
</SetRegEntry>
|
||||||
</TargetDriverDllRegistry>
|
</TargetDriverDllRegistry>
|
||||||
<Breakpoint>
|
<Breakpoint/>
|
||||||
<Bp>
|
|
||||||
<Number>0</Number>
|
|
||||||
<Type>0</Type>
|
|
||||||
<LineNumber>108</LineNumber>
|
|
||||||
<EnabledFlag>1</EnabledFlag>
|
|
||||||
<Address>0</Address>
|
|
||||||
<ByteObject>0</ByteObject>
|
|
||||||
<HtxType>0</HtxType>
|
|
||||||
<ManyObjects>0</ManyObjects>
|
|
||||||
<SizeOfObject>0</SizeOfObject>
|
|
||||||
<BreakByAccess>0</BreakByAccess>
|
|
||||||
<BreakIfRCount>0</BreakIfRCount>
|
|
||||||
<Filename>.\main.c</Filename>
|
|
||||||
<ExecCommand></ExecCommand>
|
|
||||||
<Expression></Expression>
|
|
||||||
</Bp>
|
|
||||||
</Breakpoint>
|
|
||||||
<WatchWindow1>
|
<WatchWindow1>
|
||||||
<Ww>
|
<Ww>
|
||||||
<count>0</count>
|
<count>0</count>
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
<TargetName>example_arm_compiler_6</TargetName>
|
<TargetName>example_arm_compiler_6</TargetName>
|
||||||
<ToolsetNumber>0x4</ToolsetNumber>
|
<ToolsetNumber>0x4</ToolsetNumber>
|
||||||
<ToolsetName>ARM-ADS</ToolsetName>
|
<ToolsetName>ARM-ADS</ToolsetName>
|
||||||
<pCCUsed>6150000::V6.15::ARMCLANG</pCCUsed>
|
<pCCUsed>6160000::V6.16::ARMCLANG</pCCUsed>
|
||||||
<uAC6>1</uAC6>
|
<uAC6>1</uAC6>
|
||||||
<TargetOption>
|
<TargetOption>
|
||||||
<TargetCommonOption>
|
<TargetCommonOption>
|
||||||
@ -328,7 +328,7 @@
|
|||||||
<uC99>1</uC99>
|
<uC99>1</uC99>
|
||||||
<uGnu>1</uGnu>
|
<uGnu>1</uGnu>
|
||||||
<useXO>0</useXO>
|
<useXO>0</useXO>
|
||||||
<v6Lang>3</v6Lang>
|
<v6Lang>4</v6Lang>
|
||||||
<v6LangP>3</v6LangP>
|
<v6LangP>3</v6LangP>
|
||||||
<vShortEn>1</vShortEn>
|
<vShortEn>1</vShortEn>
|
||||||
<vShortWch>1</vShortWch>
|
<vShortWch>1</vShortWch>
|
||||||
@ -529,7 +529,7 @@
|
|||||||
<TargetName>library</TargetName>
|
<TargetName>library</TargetName>
|
||||||
<ToolsetNumber>0x4</ToolsetNumber>
|
<ToolsetNumber>0x4</ToolsetNumber>
|
||||||
<ToolsetName>ARM-ADS</ToolsetName>
|
<ToolsetName>ARM-ADS</ToolsetName>
|
||||||
<pCCUsed>6150000::V6.15::ARMCLANG</pCCUsed>
|
<pCCUsed>6160000::V6.16::ARMCLANG</pCCUsed>
|
||||||
<uAC6>1</uAC6>
|
<uAC6>1</uAC6>
|
||||||
<TargetOption>
|
<TargetOption>
|
||||||
<TargetCommonOption>
|
<TargetCommonOption>
|
||||||
|
@ -80,6 +80,19 @@ int main (void)
|
|||||||
printf("Processing item with ID = %d\r\n", _->chID);
|
printf("Processing item with ID = %d\r\n", _->chID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t iCycleResult = 0;
|
||||||
|
|
||||||
|
/* measure cycles and store it in a dedicated variable without printf */
|
||||||
|
__cycleof__("delay_us(1000ul)",
|
||||||
|
/* insert code to __cycleof__ body, "{}" can be omitted */
|
||||||
|
{
|
||||||
|
iCycleResult = _; /*< "_" stores the result */
|
||||||
|
}) {
|
||||||
|
delay_us(1000ul);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\r\n delay_us(1000ul) takes %d cycles\r\n", (int)iCycleResult);
|
||||||
|
|
||||||
/*! demo of with block */
|
/*! demo of with block */
|
||||||
with(example_lv0_t, &s_tItem[0], pitem) {
|
with(example_lv0_t, &s_tItem[0], pitem) {
|
||||||
@ -96,15 +109,15 @@ int main (void)
|
|||||||
|
|
||||||
//! demo of using clock() in timer.h
|
//! demo of using clock() in timer.h
|
||||||
do {
|
do {
|
||||||
clock_t tStart = clock();
|
int64_t tStart = get_system_ticks();
|
||||||
__IRQ_SAFE {
|
__IRQ_SAFE {
|
||||||
printf("no interrupt \r\n");
|
printf("no interrupt \r\n");
|
||||||
}
|
}
|
||||||
printf("used clock cycle: %d", (int32_t)(clock() - tStart));
|
printf("used clock cycle: %d", (int32_t)(get_system_ticks() - tStart));
|
||||||
} while(0);
|
} while(0);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
printf("hello world\r\n");
|
printf("\r\nhello world\r\n");
|
||||||
delay_us(1000000);
|
delay_us(1000000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,10 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#if defined(__clang__)
|
||||||
|
# pragma clang diagnostic ignored "-Wcompound-token-split-by-macro"
|
||||||
|
#endif
|
||||||
|
|
||||||
/*============================ MACROS ========================================*/
|
/*============================ MACROS ========================================*/
|
||||||
|
|
||||||
#ifndef __PLOOC_VA_NUM_ARGS_IMPL
|
#ifndef __PLOOC_VA_NUM_ARGS_IMPL
|
||||||
@ -103,21 +107,21 @@
|
|||||||
#define __using2(__declare, __on_leave_expr) \
|
#define __using2(__declare, __on_leave_expr) \
|
||||||
for (__declare, *CONNECT3(__using_, __LINE__,_ptr) = NULL; \
|
for (__declare, *CONNECT3(__using_, __LINE__,_ptr) = NULL; \
|
||||||
CONNECT3(__using_, __LINE__,_ptr)++ == NULL; \
|
CONNECT3(__using_, __LINE__,_ptr)++ == NULL; \
|
||||||
__on_leave_expr \
|
(__on_leave_expr) \
|
||||||
)
|
)
|
||||||
|
|
||||||
#define __using3(__declare, __on_enter_expr, __on_leave_expr) \
|
#define __using3(__declare, __on_enter_expr, __on_leave_expr) \
|
||||||
for (__declare, *CONNECT3(__using_, __LINE__,_ptr) = NULL; \
|
for (__declare, *CONNECT3(__using_, __LINE__,_ptr) = NULL; \
|
||||||
CONNECT3(__using_, __LINE__,_ptr)++ == NULL ? \
|
CONNECT3(__using_, __LINE__,_ptr)++ == NULL ? \
|
||||||
((__on_enter_expr),1) : 0; \
|
((__on_enter_expr),1) : 0; \
|
||||||
__on_leave_expr \
|
(__on_leave_expr) \
|
||||||
)
|
)
|
||||||
|
|
||||||
#define __using4(__dcl1, __dcl2, __on_enter_expr, __on_leave_expr) \
|
#define __using4(__dcl1, __dcl2, __on_enter_expr, __on_leave_expr) \
|
||||||
for (__dcl1, __dcl2, *CONNECT3(__using_, __LINE__,_ptr) = NULL; \
|
for (__dcl1, __dcl2, *CONNECT3(__using_, __LINE__,_ptr) = NULL; \
|
||||||
CONNECT3(__using_, __LINE__,_ptr)++ == NULL ? \
|
CONNECT3(__using_, __LINE__,_ptr)++ == NULL ? \
|
||||||
((__on_enter_expr),1) : 0; \
|
((__on_enter_expr),1) : 0; \
|
||||||
__on_leave_expr \
|
(__on_leave_expr) \
|
||||||
)
|
)
|
||||||
|
|
||||||
#define using(...) \
|
#define using(...) \
|
||||||
@ -131,7 +135,7 @@
|
|||||||
#define __with2(__type, __addr) \
|
#define __with2(__type, __addr) \
|
||||||
using(__type *_=(__addr))
|
using(__type *_=(__addr))
|
||||||
#define __with3(__type, __addr, __item) \
|
#define __with3(__type, __addr, __item) \
|
||||||
using(__type *_=(__addr), *__item = _, _=_, )
|
using(__type *_=(__addr), *__item = _, _=_,_=_ )
|
||||||
|
|
||||||
#define with(...) \
|
#define with(...) \
|
||||||
CONNECT2(__with, __PLOOC_VA_NUM_ARGS(__VA_ARGS__))(__VA_ARGS__)
|
CONNECT2(__with, __PLOOC_VA_NUM_ARGS(__VA_ARGS__))(__VA_ARGS__)
|
||||||
@ -179,19 +183,19 @@
|
|||||||
/*============================ MACROFIED FUNCTIONS ===========================*/
|
/*============================ MACROFIED FUNCTIONS ===========================*/
|
||||||
|
|
||||||
|
|
||||||
#define __cycleof__(__STR) \
|
#define __cycleof__(__STR, ...) \
|
||||||
for (int32_t nCycles = 0, \
|
using(int64_t _ = get_system_ticks(), { \
|
||||||
CONNECT2(__cycle_count_s_, __LINE__) = 1; \
|
_ = get_system_ticks() - _; \
|
||||||
CONNECT2(__cycle_count_s_, __LINE__)-- ? \
|
if (__PLOOC_VA_NUM_ARGS(__VA_ARGS__) == 0) { \
|
||||||
(start_cycle_counter(),1) : \
|
printf("\r\n"); \
|
||||||
( \
|
printf("-[Cycle Report]"); \
|
||||||
printf( "\r\n-[Cycle Report]" \
|
printf("--------------------------------------------\r\n"); \
|
||||||
"--------------------------------------------\r\n" \
|
printf(__STR " total cycle count: %d [%08x]\r\n", \
|
||||||
__STR \
|
(int)_, (int)_); \
|
||||||
" total cycle count: %d [%08x]\r\n", nCycles, nCycles) \
|
} else { \
|
||||||
,0); \
|
__VA_ARGS__ \
|
||||||
nCycles = stop_cycle_counter() \
|
}; \
|
||||||
)
|
})
|
||||||
|
|
||||||
/*============================ TYPES =========================================*/
|
/*============================ TYPES =========================================*/
|
||||||
/*============================ GLOBAL VARIABLES ==============================*/
|
/*============================ GLOBAL VARIABLES ==============================*/
|
||||||
@ -245,6 +249,9 @@ __attribute__((nothrow))
|
|||||||
extern int64_t clock(void);
|
extern int64_t clock(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
__attribute__((nothrow))
|
||||||
|
extern int64_t get_system_ticks(void);
|
||||||
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*
|
/*----------------------------------------------------------------------------*
|
||||||
* Please ignore the following APIs unless you have encountered some known *
|
* Please ignore the following APIs unless you have encountered some known *
|
||||||
|
Binary file not shown.
@ -334,7 +334,7 @@ void delay_us(int32_t iUs)
|
|||||||
*! and 2) do not include system header file <time.h>
|
*! and 2) do not include system header file <time.h>
|
||||||
*!
|
*!
|
||||||
*/
|
*/
|
||||||
_ARMABI
|
__attribute__((nothrow))
|
||||||
int64_t clock(void)
|
int64_t clock(void)
|
||||||
{
|
{
|
||||||
int64_t lTemp = 0;
|
int64_t lTemp = 0;
|
||||||
@ -345,3 +345,16 @@ int64_t clock(void)
|
|||||||
|
|
||||||
return lTemp;
|
return lTemp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
__attribute__((nothrow))
|
||||||
|
int64_t get_system_ticks(void)
|
||||||
|
{
|
||||||
|
int64_t lTemp = 0;
|
||||||
|
|
||||||
|
__IRQ_SAFE {
|
||||||
|
lTemp = check_systick() + s_lSystemClockCounts;
|
||||||
|
}
|
||||||
|
|
||||||
|
return lTemp;
|
||||||
|
}
|
||||||
|
@ -24,6 +24,10 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#if defined(__clang__)
|
||||||
|
# pragma clang diagnostic ignored "-Wcompound-token-split-by-macro"
|
||||||
|
#endif
|
||||||
|
|
||||||
/*============================ MACROS ========================================*/
|
/*============================ MACROS ========================================*/
|
||||||
|
|
||||||
#ifndef __PLOOC_VA_NUM_ARGS_IMPL
|
#ifndef __PLOOC_VA_NUM_ARGS_IMPL
|
||||||
@ -103,21 +107,21 @@
|
|||||||
#define __using2(__declare, __on_leave_expr) \
|
#define __using2(__declare, __on_leave_expr) \
|
||||||
for (__declare, *CONNECT3(__using_, __LINE__,_ptr) = NULL; \
|
for (__declare, *CONNECT3(__using_, __LINE__,_ptr) = NULL; \
|
||||||
CONNECT3(__using_, __LINE__,_ptr)++ == NULL; \
|
CONNECT3(__using_, __LINE__,_ptr)++ == NULL; \
|
||||||
__on_leave_expr \
|
(__on_leave_expr) \
|
||||||
)
|
)
|
||||||
|
|
||||||
#define __using3(__declare, __on_enter_expr, __on_leave_expr) \
|
#define __using3(__declare, __on_enter_expr, __on_leave_expr) \
|
||||||
for (__declare, *CONNECT3(__using_, __LINE__,_ptr) = NULL; \
|
for (__declare, *CONNECT3(__using_, __LINE__,_ptr) = NULL; \
|
||||||
CONNECT3(__using_, __LINE__,_ptr)++ == NULL ? \
|
CONNECT3(__using_, __LINE__,_ptr)++ == NULL ? \
|
||||||
((__on_enter_expr),1) : 0; \
|
((__on_enter_expr),1) : 0; \
|
||||||
__on_leave_expr \
|
(__on_leave_expr) \
|
||||||
)
|
)
|
||||||
|
|
||||||
#define __using4(__dcl1, __dcl2, __on_enter_expr, __on_leave_expr) \
|
#define __using4(__dcl1, __dcl2, __on_enter_expr, __on_leave_expr) \
|
||||||
for (__dcl1, __dcl2, *CONNECT3(__using_, __LINE__,_ptr) = NULL; \
|
for (__dcl1, __dcl2, *CONNECT3(__using_, __LINE__,_ptr) = NULL; \
|
||||||
CONNECT3(__using_, __LINE__,_ptr)++ == NULL ? \
|
CONNECT3(__using_, __LINE__,_ptr)++ == NULL ? \
|
||||||
((__on_enter_expr),1) : 0; \
|
((__on_enter_expr),1) : 0; \
|
||||||
__on_leave_expr \
|
(__on_leave_expr) \
|
||||||
)
|
)
|
||||||
|
|
||||||
#define using(...) \
|
#define using(...) \
|
||||||
@ -131,7 +135,7 @@
|
|||||||
#define __with2(__type, __addr) \
|
#define __with2(__type, __addr) \
|
||||||
using(__type *_=(__addr))
|
using(__type *_=(__addr))
|
||||||
#define __with3(__type, __addr, __item) \
|
#define __with3(__type, __addr, __item) \
|
||||||
using(__type *_=(__addr), *__item = _, _=_, )
|
using(__type *_=(__addr), *__item = _, _=_,_=_ )
|
||||||
|
|
||||||
#define with(...) \
|
#define with(...) \
|
||||||
CONNECT2(__with, __PLOOC_VA_NUM_ARGS(__VA_ARGS__))(__VA_ARGS__)
|
CONNECT2(__with, __PLOOC_VA_NUM_ARGS(__VA_ARGS__))(__VA_ARGS__)
|
||||||
@ -179,19 +183,19 @@
|
|||||||
/*============================ MACROFIED FUNCTIONS ===========================*/
|
/*============================ MACROFIED FUNCTIONS ===========================*/
|
||||||
|
|
||||||
|
|
||||||
#define __cycleof__(__STR) \
|
#define __cycleof__(__STR, ...) \
|
||||||
for (int32_t nCycles = 0, \
|
using(int64_t _ = get_system_ticks(), { \
|
||||||
CONNECT2(__cycle_count_s_, __LINE__) = 1; \
|
_ = get_system_ticks() - _; \
|
||||||
CONNECT2(__cycle_count_s_, __LINE__)-- ? \
|
if (__PLOOC_VA_NUM_ARGS(__VA_ARGS__) == 0) { \
|
||||||
(start_cycle_counter(),1) : \
|
printf("\r\n"); \
|
||||||
( \
|
printf("-[Cycle Report]"); \
|
||||||
printf( "\r\n-[Cycle Report]" \
|
printf("--------------------------------------------\r\n"); \
|
||||||
"--------------------------------------------\r\n" \
|
printf(__STR " total cycle count: %d [%08x]\r\n", \
|
||||||
__STR \
|
(int)_, (int)_); \
|
||||||
" total cycle count: %d [%08x]\r\n", nCycles, nCycles) \
|
} else { \
|
||||||
,0); \
|
__VA_ARGS__ \
|
||||||
nCycles = stop_cycle_counter() \
|
}; \
|
||||||
)
|
})
|
||||||
|
|
||||||
/*============================ TYPES =========================================*/
|
/*============================ TYPES =========================================*/
|
||||||
/*============================ GLOBAL VARIABLES ==============================*/
|
/*============================ GLOBAL VARIABLES ==============================*/
|
||||||
@ -245,6 +249,9 @@ __attribute__((nothrow))
|
|||||||
extern int64_t clock(void);
|
extern int64_t clock(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
__attribute__((nothrow))
|
||||||
|
extern int64_t get_system_ticks(void);
|
||||||
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*
|
/*----------------------------------------------------------------------------*
|
||||||
* Please ignore the following APIs unless you have encountered some known *
|
* Please ignore the following APIs unless you have encountered some known *
|
||||||
|
Loading…
x
Reference in New Issue
Block a user