给所有线程增加线程名,以便排查哪些线程占用资源较高
This commit is contained in:
parent
3b588cbfdc
commit
141bcbcaa3
27
main.c
27
main.c
@ -3,6 +3,7 @@
|
|||||||
#define DBG_TAG "main"
|
#define DBG_TAG "main"
|
||||||
#define DBG_LVL DBG_INFO
|
#define DBG_LVL DBG_INFO
|
||||||
#include "debug_print.h"
|
#include "debug_print.h"
|
||||||
|
#include <sys/prctl.h>
|
||||||
#if 0
|
#if 0
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
@ -1163,30 +1164,37 @@ error:
|
|||||||
|
|
||||||
/*================================================================================*/
|
/*================================================================================*/
|
||||||
void *thread_ota(void *arg){
|
void *thread_ota(void *arg){
|
||||||
|
prctl(PR_SET_NAME, "ota");
|
||||||
checkOtaKey();
|
checkOtaKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
void *thread_mqtt(void *arg){
|
void *thread_mqtt(void *arg){
|
||||||
|
prctl(PR_SET_NAME, "mqtt");
|
||||||
mqtt_init();
|
mqtt_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void *thread_removelog(void *arg){
|
void *thread_removelog(void *arg){
|
||||||
|
prctl(PR_SET_NAME, "removelog");
|
||||||
removeLog();
|
removeLog();
|
||||||
}
|
}
|
||||||
|
|
||||||
void *thread_reboot(void *arg){
|
void *thread_reboot(void *arg){
|
||||||
|
prctl(PR_SET_NAME, "reboot");
|
||||||
rebootSystem();
|
rebootSystem();
|
||||||
}
|
}
|
||||||
|
|
||||||
void *thread_feed_watchdog(void *arg){
|
void *thread_feed_watchdog(void *arg){
|
||||||
|
prctl(PR_SET_NAME, "watchdog");
|
||||||
feedWatchDog();
|
feedWatchDog();
|
||||||
}
|
}
|
||||||
|
|
||||||
void *thread_readqr(void *arg){
|
void *thread_readqr(void *arg){
|
||||||
|
prctl(PR_SET_NAME, "readqr");
|
||||||
readQrcode();
|
readQrcode();
|
||||||
}
|
}
|
||||||
|
|
||||||
void *thread_tag_search_send(void *arg){
|
void *thread_tag_search_send(void *arg){
|
||||||
|
prctl(PR_SET_NAME, "tag_search");
|
||||||
while(1){
|
while(1){
|
||||||
if(isSearchLabelOn){
|
if(isSearchLabelOn){
|
||||||
//uart_data_send_head_search(&uartSend,5);
|
//uart_data_send_head_search(&uartSend,5);
|
||||||
@ -1204,6 +1212,7 @@ void *thread_tag_search_send(void *arg){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void *thread_do_ota(void *arg){
|
void *thread_do_ota(void *arg){
|
||||||
|
prctl(PR_SET_NAME, "do_ota");
|
||||||
while(1){
|
while(1){
|
||||||
if(isOtaEnable && isSendComEnd && !isLEDOtaSuccess){
|
if(isOtaEnable && isSendComEnd && !isLEDOtaSuccess){
|
||||||
sleep(1);
|
sleep(1);
|
||||||
@ -1221,6 +1230,7 @@ void *thread_do_ota(void *arg){
|
|||||||
//char *tag_4="00A04C11";
|
//char *tag_4="00A04C11";
|
||||||
//char *tag_5="00A04CD0";
|
//char *tag_5="00A04CD0";
|
||||||
void *thread_uart_recv_ack(void *arg){
|
void *thread_uart_recv_ack(void *arg){
|
||||||
|
prctl(PR_SET_NAME, "uart_ack");
|
||||||
uint16_t parm_ack;
|
uint16_t parm_ack;
|
||||||
int ret=0;
|
int ret=0;
|
||||||
while(1){
|
while(1){
|
||||||
@ -1376,6 +1386,7 @@ void *thread_uart_recv_ack(void *arg){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void *thread_uart_recv_data(void *arg){
|
void *thread_uart_recv_data(void *arg){
|
||||||
|
prctl(PR_SET_NAME, "uart_data");
|
||||||
uint16_t parmAck;
|
uint16_t parmAck;
|
||||||
uint32_t tagCode;
|
uint32_t tagCode;
|
||||||
uint8_t tagSignal;
|
uint8_t tagSignal;
|
||||||
@ -1398,6 +1409,7 @@ void *thread_uart_recv_data(void *arg){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void *thread_uart_recv_back(void *arg){
|
void *thread_uart_recv_back(void *arg){
|
||||||
|
prctl(PR_SET_NAME, "uart_back");
|
||||||
uint16_t parmAck;
|
uint16_t parmAck;
|
||||||
uint32_t tagCode;
|
uint32_t tagCode;
|
||||||
uint8_t tagSignal;
|
uint8_t tagSignal;
|
||||||
@ -1552,6 +1564,7 @@ void addOnlyTag(uint32_t tagname,uint16_t battery){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void *thread_remove_duplicate_tag(void *arg){
|
void *thread_remove_duplicate_tag(void *arg){
|
||||||
|
prctl(PR_SET_NAME, "rm_dup_tag");
|
||||||
uint32_t tagname=0;
|
uint32_t tagname=0;
|
||||||
uint16_t battery=0;
|
uint16_t battery=0;
|
||||||
while(1){
|
while(1){
|
||||||
@ -1565,6 +1578,7 @@ void *thread_remove_duplicate_tag(void *arg){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void *thread_mqtt_recv(void *arg){
|
void *thread_mqtt_recv(void *arg){
|
||||||
|
prctl(PR_SET_NAME, "mqtt_recv");
|
||||||
char payload[1024]={0};
|
char payload[1024]={0};
|
||||||
char msg_body_value[1024] ={0};
|
char msg_body_value[1024] ={0};
|
||||||
char msg_body[1024] = {0};
|
char msg_body[1024] = {0};
|
||||||
@ -1578,7 +1592,7 @@ void *thread_mqtt_recv(void *arg){
|
|||||||
if(isSendComEnd){
|
if(isSendComEnd){
|
||||||
if(GetDataFromMQueue(payload)==0){
|
if(GetDataFromMQueue(payload)==0){
|
||||||
//getPayloadTime=120*1000;
|
//getPayloadTime=120*1000;
|
||||||
//LOG_I("payload:%s\n",payload);
|
LOG_I("payload:%s\n",payload);
|
||||||
get_string_from_json_string_by_key_unescape(payload,"messageId",mqtt_parm.msg_messageId,sizeof(mqtt_parm.msg_messageId));
|
get_string_from_json_string_by_key_unescape(payload,"messageId",mqtt_parm.msg_messageId,sizeof(mqtt_parm.msg_messageId));
|
||||||
//LOG_I("messageId:%s\n",mqtt_parm.msg_messageId);
|
//LOG_I("messageId:%s\n",mqtt_parm.msg_messageId);
|
||||||
if(isSearchLabelOn){
|
if(isSearchLabelOn){
|
||||||
@ -1658,7 +1672,7 @@ void *thread_mqtt_recv(void *arg){
|
|||||||
searchTimeOld=getCurrentTime();
|
searchTimeOld=getCurrentTime();
|
||||||
LOG_I("searchTimeOld:%d\n",searchTimeOld);
|
LOG_I("searchTimeOld:%d\n",searchTimeOld);
|
||||||
isSearchLabelOn=true;
|
isSearchLabelOn=true;
|
||||||
}else if(strcmp(mqtt_parm.msg_type,"3016")==0){
|
}else if(strcmp(mqtt_parm.msg_type,"3015")==0){
|
||||||
LOG_I("3015 light on\n");
|
LOG_I("3015 light on\n");
|
||||||
get_string_from_json_string_by_key_unescape(msg_data, "scene", mqtt_parm.msg_scene, sizeof(mqtt_parm.msg_scene));
|
get_string_from_json_string_by_key_unescape(msg_data, "scene", mqtt_parm.msg_scene, sizeof(mqtt_parm.msg_scene));
|
||||||
LOG_I("scene:%s\n",mqtt_parm.msg_scene);
|
LOG_I("scene:%s\n",mqtt_parm.msg_scene);
|
||||||
@ -1781,26 +1795,25 @@ void *thread_mqtt_recv(void *arg){
|
|||||||
}else{
|
}else{
|
||||||
mqtt_service_reply(stationsn,mqtt_parm.msg_messageId,"labelconfig is empty",0,productid);
|
mqtt_service_reply(stationsn,mqtt_parm.msg_messageId,"labelconfig is empty",0,productid);
|
||||||
}
|
}
|
||||||
}else if(strcmp(mqtt_parm.msg_type,"3015")==0){
|
}else if(strcmp(mqtt_parm.msg_type,"3027")==0){
|
||||||
LOG_I("3027 All light on/off 广播点亮\n");
|
LOG_I("3027 All light on/off 广播点亮\n");
|
||||||
|
|
||||||
get_string_from_json_string_by_key_unescape(msg_data, "color", mqtt_parm.msg_color, sizeof(mqtt_parm.msg_color));
|
get_string_from_json_string_by_key_unescape(msg_data, "color", mqtt_parm.msg_color, sizeof(mqtt_parm.msg_color));
|
||||||
strcpy(mqtt_parm.msg_color, "1"); // 默认关闭颜色
|
//strcpy(mqtt_parm.msg_color, "1"); // 默认关闭颜色
|
||||||
LOG_I("color:%s\n",mqtt_parm.msg_color);
|
LOG_I("color:%s\n",mqtt_parm.msg_color);
|
||||||
|
|
||||||
get_string_from_json_string_by_key_unescape(msg_data, "sound", mqtt_parm.msg_sound, sizeof(mqtt_parm.msg_sound));
|
get_string_from_json_string_by_key_unescape(msg_data, "sound", mqtt_parm.msg_sound, sizeof(mqtt_parm.msg_sound));
|
||||||
strcpy(mqtt_parm.msg_sound, "0"); // 默认关闭声音
|
//strcpy(mqtt_parm.msg_sound, "0"); // 默认关闭声音
|
||||||
LOG_I("sound:%s\n",mqtt_parm.msg_sound);
|
LOG_I("sound:%s\n",mqtt_parm.msg_sound);
|
||||||
|
|
||||||
get_string_from_json_string_by_key_unescape(msg_data, "flash", mqtt_parm.msg_flash, sizeof(mqtt_parm.msg_flash));
|
get_string_from_json_string_by_key_unescape(msg_data, "flash", mqtt_parm.msg_flash, sizeof(mqtt_parm.msg_flash));
|
||||||
strcpy(mqtt_parm.msg_flash, "0"); // 默认关闭闪烁
|
//strcpy(mqtt_parm.msg_flash, "0"); // 默认关闭闪烁
|
||||||
LOG_I("flash:%s\n",mqtt_parm.msg_flash);
|
LOG_I("flash:%s\n",mqtt_parm.msg_flash);
|
||||||
|
|
||||||
get_string_from_json_string_by_key_unescape(msg_data, "flashInterval", mqtt_parm.msg_flashInterval, sizeof(mqtt_parm.msg_flashInterval));
|
get_string_from_json_string_by_key_unescape(msg_data, "flashInterval", mqtt_parm.msg_flashInterval, sizeof(mqtt_parm.msg_flashInterval));
|
||||||
LOG_I("flashInterval:%s\n",mqtt_parm.msg_flashInterval);
|
LOG_I("flashInterval:%s\n",mqtt_parm.msg_flashInterval);
|
||||||
|
|
||||||
get_string_from_json_string_by_key_unescape(msg_data, "lightDuration", mqtt_parm.msg_lightDuration, sizeof(mqtt_parm.msg_lightDuration));
|
get_string_from_json_string_by_key_unescape(msg_data, "lightDuration", mqtt_parm.msg_lightDuration, sizeof(mqtt_parm.msg_lightDuration));
|
||||||
strcpy(mqtt_parm.msg_lightDuration, "300"); // 点亮300秒
|
|
||||||
LOG_I("lightDuration:%s\n",mqtt_parm.msg_lightDuration);
|
LOG_I("lightDuration:%s\n",mqtt_parm.msg_lightDuration);
|
||||||
|
|
||||||
if(isLightEnable){
|
if(isLightEnable){
|
||||||
|
|||||||
@ -19,6 +19,8 @@
|
|||||||
#include <OsWrapper.h>
|
#include <OsWrapper.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <sys/prctl.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <semaphore.h>
|
#include <semaphore.h>
|
||||||
@ -248,6 +250,28 @@ void mqtt_utils_delivery_complete(void *context, MQTTAsync_token token){
|
|||||||
//LOG_I("%s\n",__func__);
|
//LOG_I("%s\n",__func__);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int led_running = 1;
|
||||||
|
static pthread_t led_thread;
|
||||||
|
|
||||||
|
void* led_blink_thread(void* arg) {
|
||||||
|
prctl(PR_SET_NAME, "led_blink");
|
||||||
|
int fd = open("/sys/class/gpio/gpio113/value", O_WRONLY);
|
||||||
|
if (fd < 0) {
|
||||||
|
LOG_I("Failed to open GPIO\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
while(led_running) {
|
||||||
|
write(fd, "1", 1);
|
||||||
|
usleep(500000);
|
||||||
|
write(fd, "0", 1);
|
||||||
|
usleep(500000);
|
||||||
|
}
|
||||||
|
|
||||||
|
close(fd);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
void mqtt_utils_connected(void *context, char *cause){
|
void mqtt_utils_connected(void *context, char *cause){
|
||||||
if (cause != NULL) {
|
if (cause != NULL) {
|
||||||
LOG_I("%s cause:%s\n",__func__, cause);
|
LOG_I("%s cause:%s\n",__func__, cause);
|
||||||
@ -256,7 +280,9 @@ void mqtt_utils_connected(void *context, char *cause){
|
|||||||
}
|
}
|
||||||
connect_failure_times=0;
|
connect_failure_times=0;
|
||||||
mqtt_utils_subscribe(mqtt_conf,nativeInvokTopicName,2);
|
mqtt_utils_subscribe(mqtt_conf,nativeInvokTopicName,2);
|
||||||
system("echo 1 > /sys/class/gpio/gpio113/value");//yellow ok
|
//system("echo 1 > /sys/class/gpio/gpio113/value");//yellow ok
|
||||||
|
led_running = 1;
|
||||||
|
pthread_create(&led_thread, NULL, led_blink_thread, NULL);
|
||||||
char myid[32]={0};
|
char myid[32]={0};
|
||||||
myrand(myid,19);
|
myrand(myid,19);
|
||||||
updateStationInfo(myid);
|
updateStationInfo(myid);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user