Logging.cpp
Go to the documentation of this file.
00001 /* 
00002  * File:   Logging.cpp
00003  * Author: cwioro
00004  * 
00005  * Created on August 8, 2014, 10:35 AM
00006  */
00007 
00008 #include "Logging.h"
00009 #include "RouteRequest.h"
00010 #include "RouteResponse.h"
00011 #include "McTree.h"
00012 #include "EthernetFrame.h"
00013 #include "Packet.h"
00014 #include "defines.h"
00015 #include <boost/algorithm/string.hpp>
00016 
00017 Logging::Logging()
00018 {
00019 
00020 }
00021 
00022 Logging::Logging(const Logging& orig)
00023 {
00024 
00025 }
00026 
00027 Logging::~Logging()
00028 {
00029 
00030 }
00031 
00032 void Logging::periodicLog(unsigned long interval_ms)
00033 {
00034     while (ros::ok())
00035     {
00036         sleepMS(interval_ms);
00037         log();
00038     }
00039 }
00040 
00041 void Logging::init(ros::NodeHandle* n, std::string* robot_n)
00042 {
00043 #ifndef PERFORMANCE_LOGGING
00044     return;
00045 #endif
00046     Logging::n = n;
00047     Logging::robot_name = robot_n;
00048     entries_r_table.push_front("#time,num_cr_entries,num_unicast_entries,num_multicast_entries,size");
00049     entries_rreq_initi.push_front("#time,rreq_id,dst,start_time,end_time,num_rrep_rcvd,num_rreq_sent,route_length,route,multicast");
00050     entries_rreq_recv.push_front("#time,rreq_id,src,counter,route_length,selected,route");
00051     entries_rreq_interm.push_front("#time,rreq_id,src,rcvd_from");
00052     entries_mem_consumption.push_front("#time,size_multicast_packets_complete,size_multicast_packets_incomplete,size_unicast_packets_incomplete,size_unack_relay_frames,running_unicast_link_threads,running_multicast_threads,running_unicast_cr_threads,running_unicast_transport_threads");
00053     entries_link_frames.push_front("#time,src,frame_id,mac_src, mac_dst,time_sent,time_ack,retransmissions");
00054 
00055     /* UNCIAST FRAMES HEADER */
00056     string uc_header = "#time,num_unique_data_frames_sent,num_unique_data_frames_forwarded,num_data_frames_resent,num_data_frames_reforwarded,num_data_frames_relayed,"
00057             "num_acknowledgments_sent,num_acknowledgments_relayed,num_rreq_sent,num_rrep_sent,num_beacons_sent,num_relay_selection_sent,num_relay_detecion_sent,num_total_frames_sent";
00058     uc_header += ",num_unique_data_frames_received_directly,num_unique_data_frames_received_relay,num_data_frames_received_directly,num_data_frames_received_relay,"
00059             "num_acknowledgments_received_directly,num_acknowledgments_received_relay,num_rreq_received,num_rrep_received,num_relay_selection_received,num_relay_detecion_received,num_duplicate_frames_received,num_beacons_received,num_total_frames_received,num_total_bytes_sent,num_total_bytes_received";
00060 
00061     entries_uc_frames.push_front(uc_header);
00062 
00063     /* MULTICAST FRAMES HEADER */
00064     string mc_header = "#time,num_mc_unique_data_frames_sent,num_mc_unique_data_frames_forwarded,num_mc_data_frames_resent,num_mc_data_frames_reforwarded";
00065     mc_header += ",num_mc_data_frames_relayed,num_mc_acknowledgments_sent,num_mc_acknowledgments_relayed,num_mc_rreq_sent";
00066     mc_header += ",num_mc_rrep_sent,num_mc_ract_sent,num_mc_relay_selection_sent,num_mc_total_frames_sent";
00067 
00068     mc_header += ",num_mc_unique_data_frames_received_directly,num_mc_unique_data_frames_received_relay,num_mc_data_frames_received_directly";
00069     mc_header += ",num_mc_data_frames_received_relay,num_mc_acknowledgments_received_directly,num_mc_acknowledgments_received_relay,num_mc_rreq_received";
00070     mc_header += ",num_mc_rrep_received,num_mc_ract_received,num_mc_relay_selection_received,num_mc_duplicate_frames_received,num_mc_total_frames_received";
00071     mc_header += ",num_mc_total_bytes_sent,num_mc_total_bytes_received";
00072 
00073     entries_mc_frames.push_front(mc_header);
00074     entries_service_calls.push_back("#time,service,time_call,time_res,data_size,return");
00075     entries_transport_frames.push_back("#time,id,dst,retransmissions,start_time,end_time,success,route_length,route,multicast");
00076 }
00077 
00078 void Logging::logUcPacketsSummary(unsigned long interval_ms)
00079 {
00080 #ifndef PERFORMANCE_LOGGING
00081     return;
00082 #endif
00083 #ifndef PERFORMANCE_LOGGING_UC_LINK_SUMMARY
00084     return;
00085 #endif
00086 
00087     while (ros::ok())
00088     {
00089         sleepMS(interval_ms);
00090 
00091 
00092 
00093         string entry = getIntAsString(getMillisecondsTime()) + ",";
00094         {
00095             boost::unique_lock<boost::mutex> lock(Logging::mtx_logging);
00096             uint32_properties["num_total_frames_sent"] = 0;
00097             uint32_properties["num_total_frames_received"] = 0;
00098         }
00099 
00100         /* num_unique_data_frames_sent */
00101         entry += getIntAsString(getProperty("num_unique_data_frames_sent")) + ",";
00102         increaseProperty("num_total_frames_sent", getProperty("num_unique_data_frames_sent"));
00103 
00104         /* getProperty("num_unique_data_frames_forwarded*/
00105         entry += getIntAsString(getProperty("num_unique_data_frames_forwarded")) + ",";
00106         increaseProperty("num_total_frames_sent", getProperty("num_unique_data_frames_forwarded"));
00107 
00108         /* num_data_frames_resent*/
00109         entry += getIntAsString(getProperty("num_data_frames_resent")) + ",";
00110         increaseProperty("num_total_frames_sent", getProperty("num_data_frames_resent"));
00111 
00112 
00113         /* num_data_frames_reforwarded*/
00114         entry += getIntAsString(getProperty("num_data_frames_reforwarded")) + ",";
00115         increaseProperty("num_total_frames_sent", getProperty("num_data_frames_reforwarded"));
00116 
00117         /* num_data_frames_relayed*/
00118         entry += getIntAsString(getProperty("num_data_frames_relayed")) + ",";
00119         increaseProperty("num_total_frames_sent", getProperty("num_data_frames_relayed"));
00120 
00121         /*num_acknowledgments_sent */
00122         entry += getIntAsString(getProperty("num_acknowledgments_sent")) + ",";
00123         increaseProperty("num_total_frames_sent", getProperty("num_acknowledgments_sent"));
00124 
00125         /* getProperty("num_acknowledgments_relayed*/
00126         entry += getIntAsString(getProperty("num_acknowledgments_relayed")) + ",";
00127         increaseProperty("num_total_frames_sent", getProperty("num_acknowledgments_relayed"));
00128 
00129         /* num_rreq_sent*/
00130         entry += getIntAsString(getProperty("num_rreq_sent")) + ",";
00131         increaseProperty("num_total_frames_sent", getProperty("num_rreq_sent"));
00132 
00133         /* num_rrep_sent*/
00134         entry += getIntAsString(getProperty("num_rrep_sent")) + ",";
00135         increaseProperty("num_total_frames_sent", getProperty("num_rrep_sent"));
00136 
00137         /*num_beacons_sent */
00138         entry += getIntAsString(getProperty("num_beacons_sent")) + ",";
00139         increaseProperty("num_total_frames_sent", getProperty("num_beacons_sent"));
00140 
00141         /*num_relay_selection_sent */
00142         entry += getIntAsString(getProperty("num_relay_selection_sent")) + ",";
00143         increaseProperty("num_total_frames_sent", getProperty("num_relay_selection_sent"));
00144 
00145         /*num_relay_detection_sent */
00146         entry += getIntAsString(getProperty("num_relay_detection_sent")) + ",";
00147         increaseProperty("num_total_frames_sent", getProperty("num_relay_detection_sent"));
00148 
00149         /*num_total_frames_sent */
00150         entry += getIntAsString(getProperty("num_total_frames_sent")) + ",";
00151 
00152 
00153         //      num_total_frames_received = 0;
00154 
00155 
00156         /*num_unique_data_frames_received_directly */
00157         entry += getIntAsString(getProperty("num_unique_data_frames_received_directly")) + ",";
00158 
00159         /*num_unique_data_frames_received_relay */
00160         increaseProperty("num_total_frames_received", getProperty("num_unique_data_frames_received_relay"));
00161         entry += getIntAsString(getProperty("num_unique_data_frames_received_relay")) + ",";
00162 
00163         /*num_data_frames_received_directly */
00164         increaseProperty("num_total_frames_received", getProperty("num_data_frames_received_directly"));
00165         entry += getIntAsString(getProperty("num_data_frames_received_directly")) + ",";
00166 
00167         /*num_data_frames_received_relay */
00168         increaseProperty("num_total_frames_received", getProperty("num_data_frames_received_relay"));
00169         entry += getIntAsString(getProperty("num_data_frames_received_relay")) + ",";
00170 
00171         /*num_acknowledgments_received_directly */
00172         increaseProperty("num_total_frames_received", getProperty("num_acknowledgments_received_directly"));
00173         entry += getIntAsString(getProperty("num_acknowledgments_received_directly")) + ",";
00174 
00175         /*num_acknowledgments_received_relay */
00176         increaseProperty("num_total_frames_received", getProperty("num_acknowledgments_received_relay"));
00177         entry += getIntAsString(getProperty("num_acknowledgments_received_relay")) + ",";
00178 
00179         /*num_rreq_received */
00180         increaseProperty("num_total_frames_received", getProperty("num_rreq_received"));
00181         entry += getIntAsString(getProperty("num_rreq_received")) + ",";
00182 
00183         /*num_rrep_received */
00184         increaseProperty("num_total_frames_received", getProperty("num_rrep_received"));
00185         entry += getIntAsString(getProperty("num_rrep_received")) + ",";
00186 
00187         /*num_relay_selection_received */
00188         increaseProperty("num_total_frames_received", getProperty("num_relay_selection_received"));
00189         entry += getIntAsString(getProperty("num_relay_selection_received")) + ",";
00190 
00191         /*num_relay_detection_received */
00192         increaseProperty("num_total_frames_received", getProperty("num_relay_detection_received"));
00193         entry += getIntAsString(getProperty("num_relay_detection_received")) + ",";
00194 
00195         /*num_duplicate_frames_received */
00196         increaseProperty("num_total_frames_received", getProperty("num_duplicate_frames_received"));
00197         entry += getIntAsString(getProperty("num_duplicate_frames_received")) + ",";
00198 
00199         /*num_beacons_received */
00200         increaseProperty("num_total_frames_received", getProperty("num_beacons_received"));
00201         entry += getIntAsString(getProperty("num_beacons_received")) + ",";
00202 
00203         /*um_total_frames_received */
00204         entry += getIntAsString(getProperty("num_total_frames_received")) + ",";
00205 
00206         /*num_total_bytes_sent */
00207         entry += getIntAsString(getProperty("num_total_bytes_sent")) + ",";
00208 
00209         /*num_total_bytes_received */
00210         entry += getIntAsString(getProperty("num_total_bytes_received")) + ",";
00211 
00212 
00213         entries_uc_frames.push_back(entry);
00214 
00215     }
00216 }
00217 
00218 void Logging::logMcPacketsSummary(unsigned long interval_ms)
00219 {
00220 #ifndef PERFORMANCE_LOGGING
00221     return;
00222 #endif
00223 
00224 #ifndef PERFORMANCE_LOGGING_MC_LINK_SUMMARY
00225     return;
00226 #endif
00227 
00228 
00229     while (ros::ok())
00230     {
00231         sleepMS(interval_ms);
00232 
00233 
00234 
00235         string entry = getIntAsString(getMillisecondsTime()) + ",";
00236 
00237 
00238         /*num_mc_unique_data_frames_sent */
00239         entry += getIntAsString(getProperty("num_mc_unique_data_frames_sent")) + ",";
00240         increaseProperty("num_mc_total_frames_sent", getProperty("num_mc_unique_data_frames_sent"));
00241 
00242         /* num_mc_unique_data_frames_forwarded*/
00243         entry += getIntAsString(getProperty("num_mc_unique_data_frames_forwarded")) + ",";
00244         increaseProperty("num_mc_total_frames_sent", getProperty("num_mc_unique_data_frames_forwarded"));
00245 
00246         /* num_mc_data_frames_resent*/
00247         entry += getIntAsString(getProperty("num_mc_data_frames_resent")) + ",";
00248         increaseProperty("num_mc_total_frames_sent", getProperty("num_mc_data_frames_resent"));
00249 
00250         /* num_mc_data_frames_reforwarded*/
00251         entry += getIntAsString(getProperty("num_mc_data_frames_reforwarded")) + ",";
00252         increaseProperty("num_mc_total_frames_sent", getProperty("num_mc_data_frames_reforwarded"));
00253 
00254         /* num_mc_data_frames_relayed*/
00255         entry += getIntAsString(getProperty("num_mc_data_frames_relayed")) + ",";
00256         increaseProperty("num_mc_total_frames_sent", getProperty("num_mc_data_frames_relayed"));
00257 
00258         /*num_mc_acknowledgments_sent */
00259         entry += getIntAsString(getProperty("num_mc_acknowledgments_sent")) + ",";
00260         increaseProperty("num_mc_total_frames_sent", getProperty("num_mc_acknowledgments_sent"));
00261 
00262         /* num_mc_acknowledgments_relayed*/
00263         entry += getIntAsString(getProperty("num_mc_acknowledgments_relayed")) + ",";
00264         increaseProperty("num_mc_total_frames_sent", getProperty("num_mc_acknowledgments_relayed"));
00265 
00266         /* num_mc_rreq_sent*/
00267         entry += getIntAsString(getProperty("num_mc_rreq_sent")) + ",";
00268         increaseProperty("num_mc_total_frames_sent", getProperty("num_mc_rreq_sent"));
00269 
00270         /* num_mc_rrep_sent*/
00271         entry += getIntAsString(getProperty("num_mc_rrep_sent")) + ",";
00272         increaseProperty("num_mc_total_frames_sent", getProperty("num_mc_rrep_sent"));
00273 
00274         /*num_mc_ract_sent */
00275         entry += getIntAsString(getProperty("num_mc_ract_sent")) + ",";
00276         increaseProperty("num_mc_total_frames_sent", getProperty("num_mc_ract_sent"));
00277 
00278         /*num_mc_relay_selection_sent */
00279         entry += getIntAsString(getProperty("num_mc_relay_selection_sent")) + ",";
00280         increaseProperty("num_mc_total_frames_sent", getProperty("num_mc_relay_selection_sent"));
00281 
00282         /*num_mc_total_frames_sent */
00283         entry += getIntAsString(getProperty("num_mc_total_frames_sent")) + ",";
00284 
00285 
00286 
00287 
00288 
00289         /*num_mc_unique_data_frames_received_directly */
00290         increaseProperty("num_mc_total_frames_received", getProperty("num_mc_unique_data_frames_received_directly"));
00291         entry += getIntAsString(getProperty("num_mc_unique_data_frames_received_directly")) + ",";
00292 
00293         /*num_mc_unique_data_frames_received_relay */
00294         increaseProperty("num_mc_total_frames_received", getProperty("num_mc_unique_data_frames_received_relay"));
00295         entry += getIntAsString(getProperty("num_mc_unique_data_frames_received_relay")) + ",";
00296 
00297         /*num_mc_data_frames_received_directly */
00298         increaseProperty("num_mc_total_frames_received", getProperty("num_mc_data_frames_received_directly"));
00299         entry += getIntAsString(getProperty("num_mc_data_frames_received_directly")) + ",";
00300 
00301         /*num_mc_data_frames_received_relay */
00302         increaseProperty("num_mc_total_frames_received", getProperty("num_mc_data_frames_received_relay"));
00303         entry += getIntAsString(getProperty("num_mc_data_frames_received_relay")) + ",";
00304 
00305         /*num_mc_acknowledgments_received_directly */
00306         increaseProperty("num_mc_total_frames_received", getProperty("num_mc_acknowledgments_received_directly"));
00307         entry += getIntAsString(getProperty("num_mc_acknowledgments_received_directly")) + ",";
00308 
00309         /*num_mc_acknowledgments_received_relay */
00310         increaseProperty("num_mc_total_frames_received", getProperty("num_mc_acknowledgments_received_relay"));
00311         entry += getIntAsString(getProperty("num_mc_acknowledgments_received_relay")) + ",";
00312 
00313         /*num_mc_rreq_received */
00314         increaseProperty("num_mc_total_frames_received", getProperty("num_mc_rreq_received"));
00315         entry += getIntAsString(getProperty("num_mc_rreq_received")) + ",";
00316 
00317         /*num_mc_rrep_received */
00318         increaseProperty("num_mc_total_frames_received", getProperty("num_mc_rrep_received"));
00319         entry += getIntAsString(getProperty("num_mc_rrep_received")) + ",";
00320 
00321         /*num_mc_ract_received */
00322         increaseProperty("num_mc_total_frames_received", getProperty("num_mc_ract_received"));
00323         entry += getIntAsString(getProperty("num_mc_ract_received")) + ",";
00324 
00325         /*num_mc_relay_selection_received */
00326         increaseProperty("num_mc_total_frames_received", getProperty("num_mc_relay_selection_received"));
00327         entry += getIntAsString(getProperty("num_mc_relay_selection_received")) + ",";
00328 
00329         /*num_mc_duplicate_frames_received */
00330         increaseProperty("num_mc_total_frames_received", getProperty("num_mc_duplicate_frames_received"));
00331         entry += getIntAsString(getProperty("num_mc_duplicate_frames_received")) + ",";
00332 
00333         /*num_mc_total_frames_received */
00334         entry += getIntAsString(getProperty("num_mc_total_frames_received")) + ",";
00335 
00336         /*num_mc_total_frames_received */
00337         entry += getIntAsString(getProperty("num_mc_total_bytes_sent")) + ",";
00338 
00339         /*num_mc_total_frames_received */
00340         entry += getIntAsString(getProperty("num_mc_total_bytes_received")) + ",";
00341 
00342 
00343         entries_mc_frames.push_back(entry);
00344 
00345     }
00346 }
00347 
00348 void Logging::log()
00349 {
00350 #ifndef PERFORMANCE_LOGGING
00351 
00352     return;
00353 #endif
00354     Logging::createLogPath();
00355 
00356     Logging::createLogFile(&Logging::entries_rreq_initi, &Logging::route_req_src_file);
00357     Logging::createLogFile(&Logging::entries_rreq_recv, &Logging::route_req_dst_file);
00358     Logging::createLogFile(&Logging::entries_rreq_interm, &Logging::route_req_iterm_file);
00359     Logging::createLogFile(&Logging::entries_r_table, &Logging::routing_table_file);
00360     Logging::createLogFile(&Logging::entries_mem_consumption, &Logging::mem_consumption_file);
00361     Logging::createLogFile(&Logging::entries_transport_frames, &Logging::transport_frames_file);
00362 
00363 #ifdef PERFORMANCE_LOGGING_UC_LINK_FRAMES
00364     Logging::createLogFile(&Logging::entries_link_frames, &Logging::link_frames_file);
00365 #endif
00366 #ifdef PERFORMANCE_LOGGING_UC_LINK_SUMMARY
00367     Logging::createLogFile(&Logging::entries_uc_frames, &Logging::uc_frames_file);
00368 #endif
00369 
00370 #ifdef PERFORMANCE_LOGGING_MC_LINK_SUMMARY
00371     Logging::createLogFile(&Logging::entries_mc_frames, &Logging::mc_frames_file);
00372 #endif
00373 
00374 
00375     Logging::createLogFile(&Logging::entries_service_calls, &Logging::sercice_calls_file);
00376 
00377 
00378 }
00379 
00380 void Logging::createLogFile(std::list<std::string>* table, std::string* filename)
00381 {
00382 #ifndef PERFORMANCE_LOGGING
00383     return;
00384 #endif
00385     std::ofstream myfile;
00386     std::string file_name = Logging::log_path + *filename;
00387     myfile.open(file_name.c_str());
00388 
00389     //ROS_ERROR("output file %s", file_name.c_str());
00390     for (std::list<std::string>::iterator i = table->begin(); i != table->end(); i++)
00391     {
00392 
00393         std::string line = *i;
00394         myfile << line << "\n";
00395     }
00396     myfile.close();
00397 }
00398 
00399 bool Logging::createLogPath()
00400 {
00401 #ifndef PERFORMANCE_LOGGING
00402     return false;
00403 #endif
00404     Logging::n->param("log_path", Logging::log_path, std::string(""));
00405     Logging::log_path += "/adhoc_communication/" + *robot_name + "/";
00406 
00407     ROS_INFO("Creating log path \"%s\".", Logging::log_path.c_str());
00408     boost::filesystem::path boost_log_path(log_path.c_str());
00409     if (!boost::filesystem::exists(boost_log_path))
00410         try
00411         {
00412             if (!boost::filesystem::create_directories(boost_log_path))
00413                 ROS_ERROR("Cannot create directory \"%s\".", Logging::log_path.c_str());
00414         } catch (const boost::filesystem::filesystem_error& e)
00415         {
00416 
00417             ROS_ERROR("Cannot create path \"%s\".", Logging::log_path.c_str());
00418             return false;
00419         }
00420     return true;
00421 }
00422 //time num_cr_entries, num_unicast_entries, num_multicast_entries, size
00423 
00424 void Logging::logRoutingTable(std::list<routing_entry>* u_entries, std::list<McTree*>* m_entries)
00425 {
00426 #ifndef PERFORMANCE_LOGGING
00427     return;
00428 #endif
00429     uint32_t num_cr_entries = 0, num_unicast_entries = 0, num_multicast_entries = m_entries->size();
00430     std::size_t size = 0;
00431 
00432     for (std::list<routing_entry>::iterator i = u_entries->begin(); i != u_entries->end(); i++)
00433     {
00434 
00435         routing_entry r = *i;
00436         size += sizeof (r);
00437 
00438         if (r.cr_entry)
00439             num_cr_entries++;
00440         else
00441         {
00442 
00443             num_unicast_entries++;
00444 
00445         }
00446 
00447     }
00448 
00449 
00450     for (std::list<McTree*>::iterator i = m_entries->begin(); i != m_entries->end(); i++)
00451     {
00452 
00453         McTree* m = *i;
00454 
00455         size += sizeof (*m);
00456 
00457     }
00458 
00459     entries_r_table.push_back(getIntAsString(getMillisecondsTime()) + "," + getIntAsString(num_cr_entries) + "," + getIntAsString(num_unicast_entries) + "," + getIntAsString(num_multicast_entries) + "," + getIntAsString(size));
00460 }
00461 
00462 void Logging::logServiceCalls(string service_name, unsigned long time_call, unsigned long time_res, unsigned long size, bool ret_val)
00463 {
00464     entries_service_calls.push_back(getIntAsString(getMillisecondsTime()) + "," + service_name.c_str() + "," + getIntAsString(time_call) + "," + getIntAsString(time_res) + "," + getIntAsString(size) + "," + getIntAsString(ret_val));
00465 }
00466 
00467 void Logging::logRRequestInitiater(route_request* req, routing_entry* route)
00468 {
00469 #ifndef PERFORMANCE_LOGGING
00470     return;
00471 #endif
00472     /*rreq_initiater.csv (log upon every initiated route request):
00473     #time,rreq_id,dst,start_time,end_time,num_rrep_rcvd,num_rreq_sent,route_length,route, multicast
00474     time                                    : timestamp (ms)
00475     rreq_id                                 : The unique ID of the route request
00476     dst                                     : destination of the route request
00477     start_time                              : Time the rreq was sent (ms)
00478     end_time                                : Time the rrep was received (if any, otherwise empty/0)
00479     num_rrep_rcvd                               : Number of received routes
00480     num_rreq_sent                           : Number of route request sent, if multiple where unsuccessful
00481     route_length                            : If route received, length of the route
00482     route                                   : The route selected in the form of the mac path 
00483     multicast                           : true if multicast, unicast false*/
00484 
00485     std::string entry = "";
00486 
00487     /* time stamp */
00488     entry += getIntAsString(getMillisecondsTime()) + ",";
00489 
00490     /* rreq_id */
00491     entry += getIntAsString(req->id) + ",";
00492 
00493     /* dst */
00494     entry += req->hostname_destination + ",";
00495 
00496     /* time sent */
00497     entry += getIntAsString(req->ts) + ",";
00498 
00499     /* time recv */
00500     if (route != NULL)
00501         entry += getIntAsString(route->ts) + ",";
00502     else
00503         entry += ",";
00504 
00505     /* num_rrep_rcvd */
00506     entry += "1,";
00507 
00508     /* num_rreq_sent */
00509     entry += getIntAsString(req->retransmitted) + ",";
00510 
00511     /* route len */
00512     if (route != NULL)
00513         entry += getIntAsString(route->hobs) + ",";
00514     else
00515         entry += ",";
00516 
00517     /* path list */
00518     if (route != NULL)
00519     {
00520 
00521         entry += getPathAsStr(route->mac_path_l);
00522     }
00523 
00524 
00525 
00526     /* multicast*/
00527     entry += "," + getIntAsString(req->is_mc);
00528 
00529     entries_rreq_initi.push_back(entry);
00530 }
00531 
00532 void Logging::logRRequestIntermediate(RouteRequest* r)
00533 {
00534 #ifndef PERFORMANCE_LOGGING
00535 
00536     return;
00537 #endif
00538     /*rreq_intermediate.csv (log upon every received route request):
00539     #time,rreq_id,src,rcvd_from
00540     time                                    : timestamp (ms)
00541     rreq_id                                 : ID of the route request
00542     src                                     : source of the route request
00543     rcvd_from                               : robot the route request was received from*/
00544 
00545     std::string entry = "";
00546 
00547     /* time stamp */
00548     entry += getIntAsString(getMillisecondsTime()) + ",";
00549 
00550     /* rreq_id */
00551     entry += getIntAsString(r->header_.id) + ",";
00552 
00553     /* src host */
00554     entry += r->hostname_source_ + ",";
00555 
00556     /* rcvd_from */
00557     entry += getMacAsStr(r->eh_h_.eh_source).c_str();
00558 
00559 
00560 
00561     entries_rreq_interm.push_back(entry);
00562 }
00563 
00564 void Logging::logRRequestReceiver(std::string h_src, uint32_t id, uint16_t counter, uint16_t hobs, bool selected, std::list<mac> path_l)
00565 {
00566 #ifndef PERFORMANCE_LOGGING
00567     return;
00568 #endif
00569     /*rreq_receiver.csv (log upon every received route request):
00570     #time,rreq_id,counter,route_length,selected,route
00571     time                                    : timestamp (ms)
00572     rreq_id                                 : The unique ID of the route request
00573      * src
00574     counter                                 : the 'counter' received route request
00575     route_length                            : If route received, length of the route
00576     selected                                : If this route is selected and returned to the source
00577     route                                   : The route received in the form 'src|robot_A|robot_B|dst'
00578      */
00579 
00580     std::string entry = "";
00581 
00582     /* time stamp */
00583     entry += getIntAsString(getMillisecondsTime()) + ",";
00584 
00585     /* rreq_id */
00586     entry += getIntAsString(id) + ",";
00587 
00588     /* src host */
00589     entry += h_src + ",";
00590 
00591     /* counter */
00592     entry += getIntAsString(counter) + ",";
00593 
00594     /* route_length */
00595     entry += getIntAsString(hobs) + ",";
00596 
00597     /* selected */
00598     if (selected)
00599         entry += "1,";
00600 
00601     else
00602         entry += "0,";
00603 
00604     /* path list */
00605     entry += getPathAsStr(path_l);
00606 
00607     entries_rreq_recv.push_back(entry);
00608 }
00609 
00610 bool Logging::removeRouteRequestReceiver(RouteResponse* res)
00611 {
00612 #ifndef PERFORMANCE_LOGGING
00613     return false;
00614 #endif
00615     for (std::list<std::string>::iterator i = Logging::entries_rreq_recv.begin(); i != Logging::entries_rreq_recv.end();)
00616     {
00617         if (Logging::entries_rreq_recv.size() > 1 && i == Logging::entries_rreq_recv.begin())
00618             i++; // skip header
00619         else
00620             break;
00621 
00622         std::vector<std::string> csv_fields;
00623         boost::split(csv_fields, *i, boost::is_any_of(","));
00624 
00625         std::vector<std::string> hostname_id;
00626         boost::split(hostname_id, csv_fields[1], boost::is_any_of(" "));
00627 
00628         std::string hostname_src = hostname_id[0];
00629 
00630         int req_id = 0;
00631         try
00632         {
00633             req_id = boost::lexical_cast<uint32_t>(std::string(hostname_id[1]));
00634 
00635             if (hostname_src.compare(res->hostname_source_) == 0 && res->request_id_ == req_id)
00636             {
00637                 Logging::entries_rreq_recv.erase(i);
00638                 return true;
00639             }
00640         } catch (boost::bad_lexical_cast const&)
00641         {
00642             //ROS_FATAL("%s %s %s", csv_fields[1].c_str(), hostname_id[0].c_str(), hostname_id[1].c_str());
00643 
00644             ROS_FATAL("In Logging.cpp: Cannot convert [%s] to integer!", hostname_id[1].c_str());
00645         }
00646 
00647 
00648     }
00649     return false;
00650 }
00651 
00652 void Logging::logMemoryConsumptionPackets(unsigned long interval_ms, boost::mutex* mtx_pack, list<Packet>* packets, boost::mutex* mtx_cached_mc, list<Packet>* cached_mc, boost::mutex* mtx_unack_link_frames, list<stc_frame>* unack_link_frames, boost::mutex* mtx_unack_cr_frames, list<ack_cr_info>* unack_cr_frames)
00653 {
00654 #ifndef PERFORMANCE_LOGGING
00655     return;
00656 #endif
00657 
00658 
00659     while (ros::ok())
00660     {
00661         sleepMS(interval_ms);
00662         string entry = getIntAsString(getMillisecondsTime()) + ",";
00663         std::size_t size_uc_pack = 0, size_mc_pack = 0, size_cached_mc_packets = 0, size_unack_l_f = 0, size_unack_cr_f = 0;
00664 
00665 
00666         { /*  size_cached_multicast_packets complete */
00667 
00668             boost::unique_lock<boost::mutex> lock_g(*mtx_cached_mc);
00669 
00670             for (list<Packet>::iterator i = cached_mc->begin(); i != cached_mc->end(); i++)
00671             {
00672 
00673                 size_cached_mc_packets += (*i).getSize();
00674             }
00675 
00676             entry += getIntAsString(size_cached_mc_packets) + ",";
00677         }
00678 
00679         { /*  size_multicast_packets_incomplete  +  size_unicast_packets_incomplete */
00680 
00681             boost::unique_lock<boost::mutex> lock_g(*mtx_pack);
00682             for (list<Packet>::iterator i = packets->begin(); i != packets->end(); i++)
00683             {
00684                 if ((*i).isMcFrame())
00685                     size_mc_pack += (*i).getSize();
00686                 else
00687                     size_uc_pack += (*i).getSize();
00688 
00689             }
00690 
00691             entry += getIntAsString(size_mc_pack) + ",";
00692             entry += getIntAsString(size_uc_pack) + ",";
00693         }
00694 
00695 
00696         { /*  size unack link frames */
00697 
00698             boost::unique_lock<boost::mutex> lock_g(*mtx_unack_link_frames);
00699             for (list<stc_frame>::iterator i = unack_link_frames->begin(); i != unack_link_frames->end(); i++)
00700                 size_unack_l_f += sizeof (*i);
00701 
00702 
00703 
00704 
00705             entry += getIntAsString(size_unack_l_f) + ",";
00706 
00707         }
00708 
00709         { /*  size unack cr frames */
00710 
00711             boost::unique_lock<boost::mutex> lock_g(*mtx_unack_cr_frames);
00712             for (list<ack_cr_info>::iterator i = unack_cr_frames->begin(); i != unack_cr_frames->end(); i++)
00713                 size_unack_cr_f += sizeof (*i);
00714 
00715 
00716 
00717 
00718             entry += getIntAsString(size_unack_cr_f) + ",";
00719 
00720         }
00721 
00722 
00723         entry += getIntAsString(getProperty("running_unicast_link_threads")) + ",";
00724         entry += getIntAsString(getProperty("running_multicast_threads")) + ",";
00725         entry += getIntAsString(getProperty("running_unicast_cr_threads")) + ",";
00726         entry += getIntAsString(getProperty("running_unicast_transport_threads")) + ",";
00727 
00728 
00729 
00730         entries_mem_consumption.push_back(entry);
00731 
00732 
00733     }
00734 
00735 
00736 }
00737 
00738 void Logging::logTransportFrame(stc_RoutedFrame* f, routing_entry* route, unsigned long start_time, unsigned long end_time, bool success)
00739 {
00740    
00741     //  #time,id,dst,retransmissions,start_time,end_time,success,route_length,route,multicast ;
00742     string entry = getIntAsString(getMillisecondsTime()) + ",";
00743 
00744     /* id */
00745     entry += getIntAsString(f->frame.header_.frame_id) + ",";
00746 
00747     /* dst */
00748     entry += route->hostname_destination + ",";
00749 
00750     /* retransmissions */
00751     entry += getIntAsString(f->retransmitted)+",";
00752 
00753     /* start_time */
00754     entry += getIntAsString(start_time) + ",";
00755 
00756     /* end_time */
00757     entry += getIntAsString(end_time) + ",";
00758 
00759     /* success */
00760     entry += getBoolAsString(success) + ",";
00761 
00762     /*route_length*/
00763     entry += getIntAsString(route->hobs) + ",";
00764 
00765     /* route*/
00766     entry += getPathAsStr(route->mac_path_l) + ",";
00767 
00768     /* multicast */
00769     entry += getIntAsString(f->frame.mc_flag) + ",";
00770 
00771 
00772     entries_transport_frames.push_back(entry);
00773 }
00774 
00775 void Logging::logUcLinkTransmission(stc_frame f)
00776 {
00777     //#time,src,frame_id,mac_src, mac_dst,time_sent,time_ack,retransmissions
00778 #ifndef PERFORMANCE_LOGGING_UC_LINK_FRAMES
00779     return;
00780 #endif
00781     string entry = getIntAsString(getMillisecondsTime()) + ",";
00782 
00783     /* src hostname */
00784     entry += f.hostname_source + ",";
00785 
00786     /* frame id */
00787     entry += getIntAsString(f.frame_id) + ",";
00788 
00789     /* mac src */
00790     entry += ",";
00791 
00792     /* mac dst */
00793     entry += getMacAsStr(f.mac) + ",";
00794 
00795     /* time_sent*/
00796     entry += getIntAsString(f.ts) + ",";
00797 
00798     /* time_ack*/
00799     entry += getIntAsString(getMillisecondsTime()) + ",";
00800 
00801     /*retransmissions*/
00802     entry += getIntAsString(f.retransmitted) + ",";
00803 
00804 
00805     entries_link_frames.push_back(entry);
00806 }
00807 
00808 void Logging::increaseProperty(std::string prop_name)
00809 {
00810     increaseProperty(prop_name, 1);
00811 }
00812 
00813 void Logging::increaseProperty(std::string prop_name, uint32_t val)
00814 {
00815     boost::unique_lock<boost::mutex> lock(Logging::mtx_logging);
00816     if (uint32_properties.find(prop_name) == uint32_properties.end())
00817         uint32_properties[prop_name] = 0;
00818     uint32_properties[prop_name] += val;
00819 }
00820 
00821 void Logging::decreaseProperty(std::string prop_name)
00822 {
00823     decreaseProperty(prop_name, 1);
00824 }
00825 
00826 void Logging::decreaseProperty(std::string prop_name, uint32_t val)
00827 {
00828     boost::unique_lock<boost::mutex> lock(Logging::mtx_logging);
00829     if (uint32_properties.find(prop_name) == uint32_properties.end())
00830         uint32_properties[prop_name] = 0;
00831     uint32_properties[prop_name] -= val;
00832 
00833 }
00834 
00835 uint32_t Logging::getProperty(std::string prop_name)
00836 {
00837 
00838     boost::unique_lock<boost::mutex> lock(Logging::mtx_logging);
00839     if (uint32_properties.find(prop_name) == uint32_properties.end())
00840         uint32_properties[prop_name] = 0;
00841 
00842     return uint32_properties[prop_name];
00843 }


adhoc_communication
Author(s): Guenter Cwioro , Torsten Andre
autogenerated on Thu Aug 27 2015 11:56:40