NuMaker Pelion Device Management example

Fork of mbed-os-example-pelion by cc li

Committer:
SHLIU1@OANBE02333.nuvoton.com
Date:
Thu Feb 25 11:51:01 2021 +0800
Revision:
16:75a4830fc40a
Parent:
5:ae686808e015
Support the both V5.X and V6.X for mbed-os

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ccli8 5:ae686808e015 1 /*
ccli8 5:ae686808e015 2 * Copyright (c) 2019 Nuvoton Technology Corporation
ccli8 5:ae686808e015 3 *
ccli8 5:ae686808e015 4 * SPDX-License-Identifier: Apache-2.0
ccli8 5:ae686808e015 5 *
ccli8 5:ae686808e015 6 * Licensed under the Apache License, Version 2.0 (the "License");
ccli8 5:ae686808e015 7 * you may not use this file except in compliance with the License.
ccli8 5:ae686808e015 8 * You may obtain a copy of the License at
ccli8 5:ae686808e015 9 *
ccli8 5:ae686808e015 10 * http://www.apache.org/licenses/LICENSE-2.0
ccli8 5:ae686808e015 11 *
ccli8 5:ae686808e015 12 * Unless required by applicable law or agreed to in writing, software
ccli8 5:ae686808e015 13 * distributed under the License is distributed on an "AS IS" BASIS,
ccli8 5:ae686808e015 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ccli8 5:ae686808e015 15 * See the License for the specific language governing permissions and
ccli8 5:ae686808e015 16 * limitations under the License.
ccli8 5:ae686808e015 17 */
ccli8 5:ae686808e015 18
ccli8 5:ae686808e015 19 #include "mbed.h"
ccli8 5:ae686808e015 20
ccli8 5:ae686808e015 21 #if (MBED_HEAP_STATS_ENABLED) || (MBED_STACK_STATS_ENABLED)
ccli8 5:ae686808e015 22 /* Measure memory footprint */
ccli8 5:ae686808e015 23 #include "mbed_stats.h"
ccli8 5:ae686808e015 24 /* Fix up the compilation on AMRCC for PRIu32 */
ccli8 5:ae686808e015 25 #define __STDC_FORMAT_MACROS
ccli8 5:ae686808e015 26 #include <inttypes.h>
ccli8 5:ae686808e015 27 #endif
ccli8 5:ae686808e015 28
ccli8 5:ae686808e015 29 /* Support memory footprint */
ccli8 5:ae686808e015 30
ccli8 5:ae686808e015 31 /* Check weak reference/definition at the link:
ccli8 5:ae686808e015 32 * http://www.keil.com/support/man/docs/ARMLINK/armlink_pge1362065917715.htm */
ccli8 5:ae686808e015 33
ccli8 5:ae686808e015 34 extern "C" {
ccli8 5:ae686808e015 35 #if (MBED_HEAP_STATS_ENABLED)
ccli8 5:ae686808e015 36 MBED_USED void print_heap_stats(void);
ccli8 5:ae686808e015 37 #endif
ccli8 5:ae686808e015 38 #if (MBED_STACK_STATS_ENABLED)
ccli8 5:ae686808e015 39 MBED_USED void print_stack_statistics();
ccli8 5:ae686808e015 40 #endif
ccli8 5:ae686808e015 41 }
ccli8 5:ae686808e015 42
ccli8 5:ae686808e015 43 #if (MBED_HEAP_STATS_ENABLED)
ccli8 5:ae686808e015 44 void print_heap_stats(void)
ccli8 5:ae686808e015 45 {
ccli8 5:ae686808e015 46 mbed_stats_heap_t stats;
ccli8 5:ae686808e015 47 mbed_stats_heap_get(&stats);
ccli8 5:ae686808e015 48 printf("** MBED HEAP STATS **\n");
ccli8 5:ae686808e015 49 printf("**** current_size: %" PRIu32 "\n", stats.current_size);
ccli8 5:ae686808e015 50 printf("**** max_size : %" PRIu32 "\n", stats.max_size);
ccli8 5:ae686808e015 51 printf("*****************************\n\n");
ccli8 5:ae686808e015 52 }
ccli8 5:ae686808e015 53 #endif // MBED_HEAP_STATS_ENABLED
ccli8 5:ae686808e015 54
ccli8 5:ae686808e015 55 #if (MBED_STACK_STATS_ENABLED)
ccli8 5:ae686808e015 56 void print_stack_statistics()
ccli8 5:ae686808e015 57 {
ccli8 5:ae686808e015 58 printf("** MBED THREAD STACK STATS **\n");
ccli8 5:ae686808e015 59 int cnt = osThreadGetCount();
ccli8 5:ae686808e015 60 mbed_stats_stack_t *stats = (mbed_stats_stack_t*) malloc(cnt * sizeof(mbed_stats_stack_t));
ccli8 5:ae686808e015 61
ccli8 5:ae686808e015 62 if (stats) {
ccli8 5:ae686808e015 63 cnt = mbed_stats_stack_get_each(stats, cnt);
ccli8 5:ae686808e015 64 for (int i = 0; i < cnt; i++) {
ccli8 5:ae686808e015 65 printf("Thread: 0x%" PRIx32 ", Stack size: %" PRIu32 ", Max stack: %" PRIu32 "\r\n", stats[i].thread_id, stats[i].reserved_size, stats[i].max_size);
ccli8 5:ae686808e015 66 }
ccli8 5:ae686808e015 67
ccli8 5:ae686808e015 68 free(stats);
ccli8 5:ae686808e015 69 }
ccli8 5:ae686808e015 70 printf("*****************************\n\n");
ccli8 5:ae686808e015 71 }
ccli8 5:ae686808e015 72 #endif // MBED_STACK_STATS_ENABLED