Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: ICE-Application/src/AnalyticsLogger/AnalyticsLogger.cpp
- Revision:
- 2:02cb20446785
- Parent:
- 1:b2e90cda7a5a
diff -r b2e90cda7a5a -r 02cb20446785 ICE-Application/src/AnalyticsLogger/AnalyticsLogger.cpp
--- a/ICE-Application/src/AnalyticsLogger/AnalyticsLogger.cpp Tue Jan 24 19:06:45 2017 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,110 +0,0 @@
-/******************************************************************************
- *
- * File: AnalyticsLogger.cpp
- * Desciption: source for the ICE Analytics Logger
- *
- *****************************************************************************/
-#include "global.h"
-#include <stdio.h>
-#include <string>
-#include <sstream>
-#include <iostream>
-#include <vector>
-#include <time.h>
-#include "AnalyticsLogger.h"
-#include "LoggerApi.h"
-//#include "rtc.h"
-
-static void checkStackUsage(void);
-
-/*****************************************************************************
- * Function: AnalyticsLogger
- * Description: entry point for the Analytics Logger
- *
- * @param (IN) args (user-defined arguments)
- * @return none
- *****************************************************************************/
-void AnalyticsLogger(void const *args)
-{
- struct tm *ts;
- time_t curr_sec;
- int last_min=8;
- bool log_sent=false;
-
- printf("\rAnalyticsLogger has started...\n");
-
- while ( true ) {
-
- std::ostringstream log_event;
-
- curr_sec = time(0);
- ts = localtime(&curr_sec);
-// printf("curr_sec=%ld, min=%d (last=%d)\r\n", curr_sec, ts->tm_min, last_min );
- if( ((ts->tm_min%5) == 0) && (ts->tm_min != last_min) ) {
- last_min = ts->tm_min;
-
- int map_count = ModbusRegisterMap.size();
- int collected_count = 0;
-
- log_event << "\"lr\":[";
- std::map<std::string, ModbusRegister>::iterator iter;
- for (iter = ModbusRegisterMap.begin(); iter != ModbusRegisterMap.end(); ++iter) {
-
- collected_count = collected_count + 1;
-
- log_event << "{\"t\":"<< "\"" << iter->first.c_str() << "\"," << "\"v\":"<< "\"" << RegisterValueMap[iter->first].float_value<< "\"},";
- log_sent = false;
- if( log_event.str().size() >= 150 ) {
- std::string str = log_event.str();
- str.erase( str.size() - 1 );
- if( collected_count == map_count ) {
- str.append("],\"seq\":\"0\"");
- } else {
- str.append("],\"seq\":\"1\"");
- }
-// printf("%s:%d: Logging %s : len=%d\r\n", __func__, __LINE__, str.c_str(), str.length() );
- LiveDataLoggerApi( str.c_str() );
- log_event.str("");
- log_event.clear();
- log_event << "\"lr\":[";
- log_sent = true;
- }
- }
- if( log_sent == false ) {
- std::string str = log_event.str();
- str.erase( str.size() - 1 );
- str.append("],\"seq\":\"0\"");
- if( str.length() > 20 ) {
-// printf("%s:%d: Logging %s : len=%d\r\n", __func__, __LINE__, str.c_str(), str.length() );
- LiveDataLoggerApi( str.c_str() );
- }
- }
- }
-
- Thread::wait(5000);
- checkStackUsage();
- }
-}
-
-//
-// For optimizing/debugging purposes only!
-//
-static void checkStackUsage(void)
-{
- const float threshold = .85;
-
- std::vector<std::pair<std::string, Thread*> > taskList;
- taskList.push_back(make_pair((std::string)"AnalyticsLogger", GLOBAL_analyticsLogger_thread));
- taskList.push_back(make_pair((std::string)"DataHandler", GLOBAL_dataHandler_thread));
- taskList.push_back(make_pair((std::string)"ConfigHandler", GLOBAL_configHandler_thread));
- taskList.push_back(make_pair((std::string)"ControlTask", GLOBAL_controlTask_thread));
- taskList.push_back(make_pair((std::string)"ModbusMaster", GLOBAL_modbusMaster_thread));
- taskList.push_back(make_pair((std::string)"OutputTask", GLOBAL_outputTask_thread));
- for ( std::vector<std::pair<std::string, Thread*> >::iterator pos = taskList.begin(); pos != taskList.end(); ++ pos) {
- // do something
- if ( (float) pos->second->max_stack() / (float) pos->second->stack_size() >= threshold ) {
- printf("\rWARNING: %s has used %.2f%% of its stack!\n", pos->first.c_str(),
- (double)((float)pos->second->max_stack() / (float)pos->second->stack_size()) * 100.0);
- }
- }
-}
\ No newline at end of file