perf_ats_logging.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2010-2013 Christian Grothoff (and other contributing authors)
  4. GNUnet is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published
  6. by the Free Software Foundation; either version 3, or (at your
  7. option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNUnet; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  15. Boston, MA 02111-1307, USA.
  16. */
  17. /**
  18. * @file ats/perf_ats_logging.c
  19. * @brief ats benchmark: logging for performance tests
  20. * @author Christian Grothoff
  21. * @author Matthias Wachs
  22. */
  23. #include "platform.h"
  24. #include "gnunet_util_lib.h"
  25. #include "perf_ats.h"
  26. #define THROUGHPUT_TEMPLATE "#!/usr/bin/gnuplot \n" \
  27. "set datafile separator ';' \n" \
  28. "set title \"Throughput between Master and Slaves\" \n" \
  29. "set xlabel \"Time in ms\" \n" \
  30. "set ylabel \"Bytes/s\" \n" \
  31. "set grid \n"
  32. #define RTT_TEMPLATE "#!/usr/bin/gnuplot \n" \
  33. "set datafile separator ';' \n" \
  34. "set title \"Application level roundtrip time between Master and Slaves\" \n" \
  35. "set xlabel \"Time in ms\" \n" \
  36. "set ylabel \"ms\" \n" \
  37. "set grid \n"
  38. #define BW_TEMPLATE "#!/usr/bin/gnuplot \n" \
  39. "set datafile separator ';' \n" \
  40. "set title \"Bandwidth inbound and outbound between Master and Slaves\" \n" \
  41. "set xlabel \"Time in ms\" \n" \
  42. "set ylabel \"Bytes / s \" \n" \
  43. "set grid \n"
  44. #define LOG_ITEMS_TIME 2
  45. #define LOG_ITEMS_PER_PEER 17
  46. #define LOG_ITEM_BYTES_SENT 1
  47. #define LOG_ITEM_MSGS_SENT 2
  48. #define LOG_ITEM_THROUGHPUT_SENT 3
  49. #define LOG_ITEM_BYTES_RECV 4
  50. #define LOG_ITEM_MSGS_RECV 5
  51. #define LOG_ITEM_THROUGHPUT_RECV 6
  52. #define LOG_ITEM_APP_RTT 7
  53. #define LOG_ITEM_ATS_BW_IN 8
  54. #define LOG_ITEM_ATS_BW_OUT 9
  55. #define LOG_ITEM_ATS_COSTS_LAN 10
  56. #define LOG_ITEM_ATS_WAN 11
  57. #define LOG_ITEM_ATS_WLAN 12
  58. #define LOG_ITEM_ATS_DELAY 13
  59. #define LOG_ITEM_ATS_DISTANCE 14
  60. #define LOG_ITEM_ATS_NETWORKTYPE 15
  61. #define LOG_ITEM_ATS_UTIL_UP 16
  62. #define LOG_ITEM_ATS_UTIL_DOWN 17
  63. /**
  64. * Logging task
  65. */
  66. static struct GNUNET_SCHEDULER_Task * log_task;
  67. /**
  68. * Reference to perf_ats' masters
  69. */
  70. static int num_peers;
  71. static int running;
  72. static char *name;
  73. static struct GNUNET_TIME_Relative frequency;
  74. /**
  75. * A single logging time step for a partner
  76. */
  77. struct PartnerLoggingTimestep
  78. {
  79. /**
  80. * Peer
  81. */
  82. struct BenchmarkPeer *slave;
  83. /**
  84. * Total number of messages this peer has sent
  85. */
  86. unsigned int total_messages_sent;
  87. /**
  88. * Total number of bytes this peer has sent
  89. */
  90. unsigned int total_bytes_sent;
  91. /**
  92. * Total number of messages this peer has received
  93. */
  94. unsigned int total_messages_received;
  95. /**
  96. * Total number of bytes this peer has received
  97. */
  98. unsigned int total_bytes_received;
  99. /**
  100. * Total outbound throughput for master in Bytes / s
  101. */
  102. unsigned int throughput_sent;
  103. /**
  104. * Total inbound throughput for master in Bytes / s
  105. */
  106. unsigned int throughput_recv;
  107. /**
  108. * Accumulated RTT for all messages
  109. */
  110. unsigned int total_app_rtt;
  111. /**
  112. * Current application level delay
  113. */
  114. unsigned int app_rtt;
  115. /* Current ATS properties */
  116. uint32_t ats_distance;
  117. uint32_t ats_delay;
  118. uint32_t bandwidth_in;
  119. uint32_t bandwidth_out;
  120. uint32_t ats_utilization_up;
  121. uint32_t ats_utilization_down;
  122. uint32_t ats_network_type;
  123. uint32_t ats_cost_wan;
  124. uint32_t ats_cost_lan;
  125. uint32_t ats_cost_wlan;
  126. };
  127. /**
  128. * A single logging time step for a peer
  129. */
  130. struct PeerLoggingTimestep
  131. {
  132. /**
  133. * Next in DLL
  134. */
  135. struct PeerLoggingTimestep *next;
  136. /**
  137. * Prev in DLL
  138. */
  139. struct PeerLoggingTimestep *prev;
  140. /**
  141. * Logging timestamp
  142. */
  143. struct GNUNET_TIME_Absolute timestamp;
  144. /**
  145. * Total number of messages this peer has sent
  146. */
  147. unsigned int total_messages_sent;
  148. /**
  149. * Total number of bytes this peer has sent
  150. */
  151. unsigned int total_bytes_sent;
  152. /**
  153. * Total number of messages this peer has received
  154. */
  155. unsigned int total_messages_received;
  156. /**
  157. * Total number of bytes this peer has received
  158. */
  159. unsigned int total_bytes_received;
  160. /**
  161. * Total outbound throughput for master in Bytes / s
  162. */
  163. unsigned int total_throughput_send;
  164. /**
  165. * Total inbound throughput for master in Bytes / s
  166. */
  167. unsigned int total_throughput_recv;
  168. /**
  169. * Logs for slaves
  170. */
  171. struct PartnerLoggingTimestep *slaves_log;
  172. };
  173. /**
  174. * Entry for a benchmark peer
  175. */
  176. struct LoggingPeer
  177. {
  178. /**
  179. * Peer
  180. */
  181. struct BenchmarkPeer *peer;
  182. /**
  183. * Start time
  184. */
  185. struct GNUNET_TIME_Absolute start;
  186. /**
  187. * DLL for logging entries: head
  188. */
  189. struct PeerLoggingTimestep *head;
  190. /**
  191. * DLL for logging entries: tail
  192. */
  193. struct PeerLoggingTimestep *tail;
  194. };
  195. /**
  196. * Log structure of length num_peers
  197. */
  198. static struct LoggingPeer *lp;
  199. static void
  200. write_throughput_gnuplot_script (char * fn, struct LoggingPeer *lp)
  201. {
  202. struct GNUNET_DISK_FileHandle *f;
  203. char * gfn;
  204. char *data;
  205. int c_s;
  206. int peer_index;
  207. GNUNET_asprintf (&gfn, "gnuplot_throughput_%s",fn);
  208. f = GNUNET_DISK_file_open (gfn,
  209. GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
  210. GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
  211. if (NULL == f)
  212. {
  213. GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n", gfn);
  214. GNUNET_free (gfn);
  215. return;
  216. }
  217. /* Write header */
  218. if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, THROUGHPUT_TEMPLATE, strlen(THROUGHPUT_TEMPLATE)))
  219. GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn);
  220. /* Write master data */
  221. peer_index = LOG_ITEMS_TIME;
  222. GNUNET_asprintf (&data, "plot '%s' using 2:%u with lines title 'Master %u send total', \\\n" \
  223. "'%s' using 2:%u with lines title 'Master %u receive total', \\\n",
  224. fn, peer_index + LOG_ITEM_THROUGHPUT_SENT, lp->peer->no,
  225. fn, peer_index + LOG_ITEM_THROUGHPUT_RECV, lp->peer->no);
  226. if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data)))
  227. GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn);
  228. GNUNET_free (data);
  229. peer_index = LOG_ITEMS_TIME + LOG_ITEMS_PER_PEER ;
  230. for (c_s = 0; c_s < lp->peer->num_partners; c_s++)
  231. {
  232. GNUNET_asprintf (&data, "'%s' using 2:%u with lines title 'Master %u - Slave %u send', \\\n" \
  233. "'%s' using 2:%u with lines title 'Master %u - Slave %u receive'%s\n",
  234. fn, peer_index + LOG_ITEM_THROUGHPUT_SENT, lp->peer->no, lp->peer->partners[c_s].dest->no,
  235. fn, peer_index + LOG_ITEM_THROUGHPUT_RECV, lp->peer->no, lp->peer->partners[c_s].dest->no,
  236. (c_s < lp->peer->num_partners -1) ? ", \\" : "\n pause -1");
  237. if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data)))
  238. GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn);
  239. GNUNET_free (data);
  240. peer_index += LOG_ITEMS_PER_PEER;
  241. }
  242. if (GNUNET_SYSERR == GNUNET_DISK_file_close(f))
  243. GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot close gnuplot file `%s'\n", gfn);
  244. else
  245. GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Data successfully written to plot file `%s'\n", gfn);
  246. GNUNET_free (gfn);
  247. }
  248. static void
  249. write_rtt_gnuplot_script (char * fn, struct LoggingPeer *lp)
  250. {
  251. struct GNUNET_DISK_FileHandle *f;
  252. char * gfn;
  253. char *data;
  254. int c_s;
  255. int index;
  256. GNUNET_asprintf (&gfn, "gnuplot_rtt_%s",fn);
  257. f = GNUNET_DISK_file_open (gfn,
  258. GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
  259. GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
  260. if (NULL == f)
  261. {
  262. GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n", gfn);
  263. GNUNET_free (gfn);
  264. return;
  265. }
  266. /* Write header */
  267. if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, RTT_TEMPLATE, strlen(RTT_TEMPLATE)))
  268. GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn);
  269. index = LOG_ITEMS_TIME + LOG_ITEMS_PER_PEER;
  270. for (c_s = 0; c_s < lp->peer->num_partners; c_s++)
  271. {
  272. GNUNET_asprintf (&data, "%s'%s' using 2:%u with lines title 'Master %u - Slave %u '%s\n",
  273. (0 == c_s) ? "plot " :"",
  274. fn, index + LOG_ITEM_APP_RTT, lp->peer->no, lp->peer->partners[c_s].dest->no,
  275. (c_s < lp->peer->num_partners -1) ? ", \\" : "\n pause -1");
  276. if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data)))
  277. GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn);
  278. GNUNET_free (data);
  279. index += LOG_ITEMS_PER_PEER;
  280. }
  281. if (GNUNET_SYSERR == GNUNET_DISK_file_close(f))
  282. GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot close gnuplot file `%s'\n", gfn);
  283. else
  284. GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Data successfully written to plot file `%s'\n", gfn);
  285. GNUNET_free (gfn);
  286. }
  287. static void
  288. write_bw_gnuplot_script (char * fn, struct LoggingPeer *lp)
  289. {
  290. struct GNUNET_DISK_FileHandle *f;
  291. char * gfn;
  292. char *data;
  293. int c_s;
  294. int index;
  295. GNUNET_asprintf (&gfn, "gnuplot_bw_%s",fn);
  296. f = GNUNET_DISK_file_open (gfn,
  297. GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
  298. GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
  299. if (NULL == f)
  300. {
  301. GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n", gfn);
  302. GNUNET_free (gfn);
  303. return;
  304. }
  305. /* Write header */
  306. if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, BW_TEMPLATE, strlen(BW_TEMPLATE)))
  307. GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn);
  308. index = LOG_ITEMS_TIME + LOG_ITEMS_PER_PEER;
  309. for (c_s = 0; c_s < lp->peer->num_partners; c_s++)
  310. {
  311. GNUNET_asprintf (&data, "%s"\
  312. "'%s' using 2:%u with lines title 'BW out master %u - Slave %u ', \\\n" \
  313. "'%s' using 2:%u with lines title 'BW in master %u - Slave %u '"\
  314. "%s\n",
  315. (0 == c_s) ? "plot " :"",
  316. fn, index + LOG_ITEM_ATS_BW_OUT, lp->peer->no, lp->peer->partners[c_s].dest->no,
  317. fn, index + LOG_ITEM_ATS_BW_IN, lp->peer->no, lp->peer->partners[c_s].dest->no,
  318. (c_s < lp->peer->num_partners -1) ? ", \\" : "\n pause -1");
  319. if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data)))
  320. GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn);
  321. GNUNET_free (data);
  322. index += LOG_ITEMS_PER_PEER;
  323. }
  324. if (GNUNET_SYSERR == GNUNET_DISK_file_close(f))
  325. GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot close gnuplot file `%s'\n", gfn);
  326. else
  327. GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Data successfully written to plot file `%s'\n", gfn);
  328. GNUNET_free (gfn);
  329. }
  330. static void
  331. write_to_file ()
  332. {
  333. struct GNUNET_DISK_FileHandle *f;
  334. char * filename;
  335. char *data;
  336. char *slave_string;
  337. char *slave_string_tmp;
  338. struct PeerLoggingTimestep *cur_lt;
  339. struct PartnerLoggingTimestep *plt;
  340. int c_m;
  341. int c_s;
  342. for (c_m = 0; c_m < num_peers; c_m++)
  343. {
  344. GNUNET_asprintf (&filename, "%llu_master_%u_%s_%s.data", GNUNET_TIME_absolute_get().abs_value_us,
  345. lp[c_m].peer->no, GNUNET_i2s(&lp[c_m].peer->id), name);
  346. f = GNUNET_DISK_file_open (filename,
  347. GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
  348. GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
  349. if (NULL == f)
  350. {
  351. GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open log file `%s'\n", filename);
  352. GNUNET_free (filename);
  353. return;
  354. }
  355. for (cur_lt = lp[c_m].head; NULL != cur_lt; cur_lt = cur_lt->next)
  356. {
  357. GNUNET_log(GNUNET_ERROR_TYPE_INFO,
  358. "Master [%u]: timestamp %llu %llu ; %u %u %u ; %u %u %u\n", lp[c_m].peer->no,
  359. cur_lt->timestamp, GNUNET_TIME_absolute_get_difference(lp[c_m].start,cur_lt->timestamp).rel_value_us / 1000,
  360. cur_lt->total_messages_sent, cur_lt->total_bytes_sent, cur_lt->total_throughput_send,
  361. cur_lt->total_messages_received, cur_lt->total_bytes_received, cur_lt->total_throughput_recv);
  362. slave_string = GNUNET_strdup (";");
  363. for (c_s = 0; c_s < lp[c_m].peer->num_partners; c_s++)
  364. {
  365. plt = &cur_lt->slaves_log[c_s];
  366. /* Log partners */
  367. /* Assembling slave string */
  368. GNUNET_log(GNUNET_ERROR_TYPE_INFO,
  369. "\t Slave [%u]: %u %u %u ; %u %u %u rtt %u delay %u bw_in %u bw_out %u \n", plt->slave->no,
  370. plt->total_messages_sent, plt->total_bytes_sent, plt->throughput_sent,
  371. plt->total_messages_received, plt->total_bytes_received, plt->throughput_recv,
  372. plt->app_rtt, plt->ats_delay,
  373. plt->bandwidth_in, plt->bandwidth_out);
  374. GNUNET_asprintf(&slave_string_tmp, "%s%u;%u;%u;%u;%u;%u;%.3f;%u;%u;%u;%u;%u;%u;%u;%u;%u;%u;",slave_string,
  375. plt->total_messages_sent, plt->total_bytes_sent, plt->throughput_sent,
  376. plt->total_messages_received, plt->total_bytes_received, plt->throughput_sent,
  377. (double) plt->app_rtt / 1000,
  378. plt->bandwidth_in,plt->bandwidth_out,
  379. plt->ats_cost_lan, plt->ats_cost_wan, plt->ats_cost_wlan,
  380. plt->ats_delay, plt->ats_distance, plt->ats_network_type,
  381. plt->ats_utilization_up, plt->ats_utilization_down);
  382. GNUNET_free (slave_string);
  383. slave_string = slave_string_tmp;
  384. }
  385. /* Assembling master string */
  386. GNUNET_asprintf (&data, "%llu;%llu;%u;%u;%u;%u;%u;%u;;;;;;;;;;;%s\n",
  387. cur_lt->timestamp,
  388. GNUNET_TIME_absolute_get_difference(lp[c_m].start,cur_lt->timestamp).rel_value_us / 1000,
  389. cur_lt->total_messages_sent, cur_lt->total_bytes_sent, cur_lt->total_throughput_send,
  390. cur_lt->total_messages_received, cur_lt->total_bytes_received, cur_lt->total_throughput_recv,
  391. slave_string);
  392. GNUNET_free (slave_string);
  393. if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data)))
  394. GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to log file `%s'\n", filename);
  395. GNUNET_free (data);
  396. }
  397. if (GNUNET_SYSERR == GNUNET_DISK_file_close(f))
  398. {
  399. GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n", filename);
  400. GNUNET_free (filename);
  401. return;
  402. }
  403. write_throughput_gnuplot_script (filename, lp);
  404. write_rtt_gnuplot_script (filename, lp);
  405. write_bw_gnuplot_script (filename, lp);
  406. GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Data file successfully written to log file `%s'\n", filename);
  407. GNUNET_free (filename);
  408. }
  409. }
  410. void
  411. collect_log_now (void)
  412. {
  413. struct LoggingPeer *bp;
  414. struct PeerLoggingTimestep *mlt;
  415. struct PeerLoggingTimestep *prev_log_mlt;
  416. struct PartnerLoggingTimestep *slt;
  417. struct PartnerLoggingTimestep *prev_log_slt;
  418. struct BenchmarkPartner *p;
  419. struct GNUNET_TIME_Relative delta;
  420. int c_s;
  421. int c_m;
  422. unsigned int app_rtt;
  423. double mult;
  424. if (GNUNET_YES != running)
  425. return;
  426. for (c_m = 0; c_m < num_peers; c_m++)
  427. {
  428. bp = &lp[c_m];
  429. mlt = GNUNET_new (struct PeerLoggingTimestep);
  430. GNUNET_CONTAINER_DLL_insert_tail(bp->head, bp->tail, mlt);
  431. prev_log_mlt = mlt->prev;
  432. /* Collect data */
  433. /* Current master state */
  434. mlt->timestamp = GNUNET_TIME_absolute_get();
  435. mlt->total_bytes_sent = bp->peer->total_bytes_sent;
  436. mlt->total_messages_sent = bp->peer->total_messages_sent;
  437. mlt->total_bytes_received = bp->peer->total_bytes_received;
  438. mlt->total_messages_received = bp->peer->total_messages_received;
  439. /* Throughput */
  440. if (NULL == prev_log_mlt)
  441. {
  442. /* Get difference to start */
  443. delta = GNUNET_TIME_absolute_get_difference (lp[c_m].start, mlt->timestamp);
  444. }
  445. else
  446. {
  447. /* Get difference to last timestep */
  448. delta = GNUNET_TIME_absolute_get_difference (mlt->prev->timestamp, mlt->timestamp);
  449. }
  450. /* Multiplication factor for throughput calculation */
  451. mult = (1.0 * 1000 * 1000) / (delta.rel_value_us);
  452. /* Total throughput */
  453. if (NULL != prev_log_mlt)
  454. {
  455. if (mlt->total_bytes_sent - mlt->prev->total_bytes_sent > 0)
  456. mlt->total_throughput_send = mult * (mlt->total_bytes_sent - mlt->prev->total_bytes_sent);
  457. else
  458. mlt->total_throughput_send = prev_log_mlt->total_throughput_send; /* no msgs send */
  459. if (mlt->total_bytes_received - mlt->prev->total_bytes_received > 0)
  460. mlt->total_throughput_recv = mult * (mlt->total_bytes_received - mlt->prev->total_bytes_received);
  461. else
  462. mlt->total_throughput_recv = prev_log_mlt->total_throughput_recv; /* no msgs received */
  463. }
  464. else
  465. {
  466. mlt->total_throughput_send = mult * mlt->total_bytes_sent;
  467. mlt->total_throughput_send = mult * mlt->total_bytes_received;
  468. }
  469. mlt->slaves_log = GNUNET_malloc (bp->peer->num_partners *
  470. sizeof (struct PartnerLoggingTimestep));
  471. for (c_s = 0; c_s < bp->peer->num_partners; c_s++)
  472. {
  473. p = &bp->peer->partners[c_s];
  474. slt = &mlt->slaves_log[c_s];
  475. slt->slave = p->dest;
  476. /* Bytes sent from master to this slave */
  477. slt->total_bytes_sent = p->bytes_sent;
  478. /* Messages sent from master to this slave */
  479. slt->total_messages_sent = p->messages_sent;
  480. /* Bytes master received from this slave */
  481. slt->total_bytes_received = p->bytes_received;
  482. /* Messages master received from this slave */
  483. slt->total_messages_received = p->messages_received;
  484. slt->total_app_rtt = p->total_app_rtt;
  485. /* ats performance information */
  486. slt->ats_cost_lan = p->ats_cost_lan;
  487. slt->ats_cost_wan = p->ats_cost_wan;
  488. slt->ats_cost_wlan = p->ats_cost_wlan;
  489. slt->ats_delay = p->ats_delay;
  490. slt->ats_distance = p->ats_distance;
  491. slt->ats_network_type = p->ats_network_type;
  492. slt->ats_utilization_down = p->ats_utilization_down;
  493. slt->ats_utilization_up = p->ats_utilization_up;
  494. slt->bandwidth_in = p->bandwidth_in;
  495. slt->bandwidth_out = p->bandwidth_out;
  496. /* Total application level rtt */
  497. if (NULL == prev_log_mlt)
  498. {
  499. if (0 != slt->total_messages_sent)
  500. app_rtt = slt->total_app_rtt / slt->total_messages_sent;
  501. else
  502. app_rtt = 0;
  503. }
  504. else
  505. {
  506. prev_log_slt = &prev_log_mlt->slaves_log[c_s];
  507. if ((slt->total_messages_sent - prev_log_slt->total_messages_sent) > 0)
  508. app_rtt = (slt->total_app_rtt - prev_log_slt->total_app_rtt) /
  509. (slt->total_messages_sent - prev_log_slt->total_messages_sent);
  510. else
  511. app_rtt = prev_log_slt->app_rtt; /* No messages were */
  512. }
  513. slt->app_rtt = app_rtt;
  514. /* Partner throughput */
  515. if (NULL != prev_log_mlt)
  516. {
  517. prev_log_slt = &prev_log_mlt->slaves_log[c_s];
  518. if (slt->total_bytes_sent - prev_log_slt->total_bytes_sent > 0)
  519. slt->throughput_sent = mult * (slt->total_bytes_sent - prev_log_slt->total_bytes_sent);
  520. else
  521. slt->throughput_sent = prev_log_slt->throughput_sent; /* no msgs send */
  522. if (slt->total_bytes_received - prev_log_slt->total_bytes_received > 0)
  523. slt->throughput_recv = mult * (slt->total_bytes_received - prev_log_slt->total_bytes_received);
  524. else
  525. slt->throughput_recv = prev_log_slt->throughput_recv; /* no msgs received */
  526. }
  527. else
  528. {
  529. slt->throughput_sent = mult * slt->total_bytes_sent;
  530. slt->throughput_sent = mult * slt->total_bytes_received;
  531. }
  532. GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
  533. "Master [%u]: slave [%u]\n",
  534. bp->peer->no, p->dest->no);
  535. }
  536. }
  537. }
  538. static void
  539. collect_log_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  540. {
  541. log_task = NULL;
  542. collect_log_now();
  543. if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
  544. return;
  545. log_task = GNUNET_SCHEDULER_add_delayed (frequency,
  546. &collect_log_task, NULL);
  547. }
  548. void
  549. perf_logging_stop ()
  550. {
  551. int c_m;
  552. struct GNUNET_SCHEDULER_TaskContext tc;
  553. struct PeerLoggingTimestep *cur;
  554. if (GNUNET_YES!= running)
  555. return;
  556. if (NULL != log_task)
  557. GNUNET_SCHEDULER_cancel (log_task);
  558. log_task = NULL;
  559. tc.reason = GNUNET_SCHEDULER_REASON_SHUTDOWN;
  560. collect_log_task (NULL, &tc);
  561. GNUNET_log(GNUNET_ERROR_TYPE_INFO,
  562. _("Stop logging\n"));
  563. write_to_file ();
  564. for (c_m = 0; c_m < num_peers; c_m++)
  565. {
  566. while (NULL != (cur = lp[c_m].head))
  567. {
  568. GNUNET_CONTAINER_DLL_remove (lp[c_m].head, lp[c_m].tail, cur);
  569. GNUNET_free (cur->slaves_log);
  570. GNUNET_free (cur);
  571. }
  572. }
  573. GNUNET_free (lp);
  574. }
  575. void
  576. perf_logging_start (struct GNUNET_TIME_Relative log_frequency,
  577. char * testname, struct BenchmarkPeer *masters, int num_masters)
  578. {
  579. int c_m;
  580. GNUNET_log(GNUNET_ERROR_TYPE_INFO,
  581. _("Start logging `%s'\n"), testname);
  582. num_peers = num_masters;
  583. name = testname;
  584. frequency = log_frequency;
  585. lp = GNUNET_malloc (num_masters * sizeof (struct LoggingPeer));
  586. for (c_m = 0; c_m < num_masters; c_m ++)
  587. {
  588. lp[c_m].peer = &masters[c_m];
  589. lp[c_m].start = GNUNET_TIME_absolute_get();
  590. }
  591. /* Schedule logging task */
  592. log_task = GNUNET_SCHEDULER_add_now (&collect_log_task, NULL);
  593. running = GNUNET_YES;
  594. }
  595. /* end of file perf_ats_logging.c */