aboutsummaryrefslogtreecommitdiff
path: root/src/ats
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-04-17 11:19:14 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-04-17 11:19:14 +0000
commit4fbe3a77a2353a5f4a6074ca56106f285147b68d (patch)
tree1d640c104550d7dae1e2f1a85539eb8acc6236e9 /src/ats
parent716899950996602e7bc249b2a752032272b5ec00 (diff)
downloadgnunet-4fbe3a77a2353a5f4a6074ca56106f285147b68d.tar.gz
gnunet-4fbe3a77a2353a5f4a6074ca56106f285147b68d.zip
- changes
Diffstat (limited to 'src/ats')
-rw-r--r--src/ats/perf_ats_mlp.c97
1 files changed, 79 insertions, 18 deletions
diff --git a/src/ats/perf_ats_mlp.c b/src/ats/perf_ats_mlp.c
index f536419a7..a025a0a91 100644
--- a/src/ats/perf_ats_mlp.c
+++ b/src/ats/perf_ats_mlp.c
@@ -41,6 +41,9 @@
41static unsigned int peers; 41static unsigned int peers;
42static unsigned int addresses; 42static unsigned int addresses;
43 43
44struct PeerContext *p;
45struct ATS_Address *a;
46
44static int ret; 47static int ret;
45 48
46struct GNUNET_STATISTICS_Handle * stats; 49struct GNUNET_STATISTICS_Handle * stats;
@@ -49,6 +52,12 @@ struct GNUNET_CONTAINER_MultiHashMap * amap;
49 52
50struct GAS_MLP_Handle *mlp; 53struct GAS_MLP_Handle *mlp;
51 54
55struct GNUNET_STATISTICS_Handle * stats;
56
57struct GNUNET_OS_Process *stats_proc;
58
59GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
60
52struct PeerContext 61struct PeerContext
53{ 62{
54 struct GNUNET_PeerIdentity id; 63 struct GNUNET_PeerIdentity id;
@@ -70,6 +79,50 @@ struct Address
70 void *session; 79 void *session;
71}; 80};
72 81
82void
83do_shutdown (void *cls,
84 const struct GNUNET_SCHEDULER_TaskContext *tc)
85{
86 unsigned int ca;
87 for (ca=0; ca < (peers * addresses); ca++)
88 {
89 GNUNET_free (a[ca].plugin);
90 GNUNET_free (a[ca].ats);
91 }
92 GNUNET_CONTAINER_multihashmap_destroy(amap);
93 GNUNET_free (a);
94 GNUNET_free (p);
95 GNUNET_STATISTICS_destroy(stats,GNUNET_NO);
96
97 if (NULL != stats_proc)
98 {
99 if (0 != GNUNET_OS_process_kill (stats_proc, SIGTERM))
100 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
101 if (GNUNET_OS_process_wait (stats_proc) != GNUNET_OK)
102 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
103 GNUNET_OS_process_close (stats_proc);
104 stats_proc = NULL;
105 }
106 ret = 0;
107}
108
109int stat_it (void *cls, const char *subsystem,
110 const char *name, uint64_t value,
111 int is_persistent)
112{
113 static int calls;
114 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s : %llu\n", name, value);
115 calls ++;
116
117 if (2 == calls)
118 {
119 if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
120 GNUNET_SCHEDULER_cancel(shutdown_task);
121 shutdown_task = GNUNET_SCHEDULER_add_now(&do_shutdown, NULL);
122 }
123 return GNUNET_OK;
124}
125
73static void 126static void
74check (void *cls, char *const *args, const char *cfgfile, 127check (void *cls, char *const *args, const char *cfgfile,
75 const struct GNUNET_CONFIGURATION_Handle *cfg) 128 const struct GNUNET_CONFIGURATION_Handle *cfg)
@@ -83,19 +136,33 @@ check (void *cls, char *const *args, const char *cfgfile,
83 unsigned int c2 = 0; 136 unsigned int c2 = 0;
84 unsigned int ca = 0; 137 unsigned int ca = 0;
85 138
139 stats_proc = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-statistics",
140 "gnunet-service-statistics", NULL);
141
142 if (NULL == stats_proc)
143 {
144 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start statistics service \n");
145 ret = 1;
146 return;
147 }
148
149 shutdown_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_HOURS, &do_shutdown, NULL);
150
86 if (peers == 0) 151 if (peers == 0)
87 peers = DEF_PEERS; 152 peers = DEF_PEERS;
88 if (addresses == 0) 153 if (addresses == 0)
89 addresses = DEF_ADDRESSES_PER_PEER; 154 addresses = DEF_ADDRESSES_PER_PEER;
90 155
91 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting up %u peers with %u addresses per peer\n", peers, addresses); 156 p = GNUNET_malloc (peers * sizeof (struct ATS_Peer));
157 a = GNUNET_malloc (peers * addresses * sizeof (struct ATS_Address));
92 158
93 struct PeerContext p[peers]; 159 stats = GNUNET_STATISTICS_create("ats", cfg);
94 struct ATS_Address a[addresses * peers]; 160
161 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting up %u peers with %u addresses per peer\n", peers, addresses);
95 162
96 amap = GNUNET_CONTAINER_multihashmap_create(addresses * peers); 163 amap = GNUNET_CONTAINER_multihashmap_create(addresses * peers);
97 164
98 mlp = GAS_mlp_init (cfg, NULL, MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS); 165 mlp = GAS_mlp_init (cfg, stats, MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS);
99 mlp->auto_solve = GNUNET_NO; 166 mlp->auto_solve = GNUNET_NO;
100 for (c=0; c < peers; c++) 167 for (c=0; c < peers; c++)
101 { 168 {
@@ -115,8 +182,6 @@ check (void *cls, char *const *args, const char *cfgfile,
115 a[ca].plugin = strdup("test"); 182 a[ca].plugin = strdup("test");
116 a[ca].atsp_network_type = GNUNET_ATS_NET_LOOPBACK; 183 a[ca].atsp_network_type = GNUNET_ATS_NET_LOOPBACK;
117 184
118 //a[ca].addr = GNUNET_HELLO_address_allocate(&a[ca].peer, a[ca].plugin, NULL, 0);
119 //a[ca].addr_len = GNUNET_HELLO_address_get_size(a[ca].addr);
120 a[ca].ats = GNUNET_malloc (2 * sizeof (struct GNUNET_ATS_Information)); 185 a[ca].ats = GNUNET_malloc (2 * sizeof (struct GNUNET_ATS_Information));
121 a[ca].ats[0].type = GNUNET_ATS_QUALITY_NET_DELAY; 186 a[ca].ats[0].type = GNUNET_ATS_QUALITY_NET_DELAY;
122 a[ca].ats[0].value = 20; 187 a[ca].ats[0].value = 20;
@@ -129,7 +194,10 @@ check (void *cls, char *const *args, const char *cfgfile,
129 ca++; 194 ca++;
130 } 195 }
131 } 196 }
132 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Problem contains %u peers and %u adresses\n", mlp->c_p, mlp->addr_in_problem); 197 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Problem contains %u peers and %u adresses\n", mlp->c_p, mlp->addr_in_problem);
198
199 GNUNET_assert (peers == mlp->c_p);
200 GNUNET_assert (peers * addresses == mlp->addr_in_problem);
133 201
134 /* Solving the problem */ 202 /* Solving the problem */
135 if (GNUNET_OK == GAS_mlp_solve_problem(mlp)) 203 if (GNUNET_OK == GAS_mlp_solve_problem(mlp))
@@ -137,20 +205,12 @@ check (void *cls, char *const *args, const char *cfgfile,
137 else 205 else
138 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Problem solved failed \n"); 206 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Problem solved failed \n");
139 207
140 GAS_mlp_done (mlp);
141
142 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Execution duration %llu\n", mlp->max_exec_duration);
143 208
144 209
145 for (ca=0; ca < (peers * addresses); ca++) 210 GAS_mlp_done (mlp);
146 {
147 GNUNET_free (a[ca].plugin);
148 GNUNET_free (a[ca].ats);
149 // GNUNET_free ((void *) a[c2].addr);
150 }
151 GNUNET_CONTAINER_multihashmap_destroy(amap);
152 211
153 ret = 0; 212 GNUNET_STATISTICS_get (stats, "ats", "# LP execution time (ms)", GNUNET_TIME_UNIT_MINUTES, NULL, &stat_it, NULL);
213 GNUNET_STATISTICS_get (stats, "ats", "# MLP execution time (ms)", GNUNET_TIME_UNIT_MINUTES, NULL, &stat_it, NULL);
154 return; 214 return;
155} 215}
156 216
@@ -169,6 +229,7 @@ main (int argc, char *argv[])
169 GNUNET_GETOPT_OPTION_END 229 GNUNET_GETOPT_OPTION_END
170 }; 230 };
171 231
232
172 GNUNET_PROGRAM_run (argc, argv, 233 GNUNET_PROGRAM_run (argc, argv,
173 "perf_ats_mlp", "nohelp", options, 234 "perf_ats_mlp", "nohelp", options,
174 &check, NULL); 235 &check, NULL);