]> git.pond.sub.org Git - empserver/blobdiff - src/lib/update/finish.c
Remove dodistribute() parameter path
[empserver] / src / lib / update / finish.c
index 738e9daf6af0cb70f11a37340b529231c531c270..43e035557f40008ec7eddf9bd2ec6d28675e5474 100644 (file)
 #include <config.h>
 
 #include <stdlib.h>
+#include <sys/resource.h>
 #include "distribute.h"
 #include "path.h"
 #include "update.h"
 
 /* Used for building up distribution info */
 struct distinfo {
-    char *path;                        /* path to take */
     double imcost;             /* import cost */
     double excost;             /* export cost */
 };
@@ -52,17 +52,6 @@ struct distinfo {
  * of course :) ) We do clear it each and every time. */
 static struct distinfo *g_distptrs;
 
-/* Note that even though we malloc and save the path, it is never
- * used.  Thus, this option.  If you want to malloc and save every
- * path and then free when done, just enable this.  Or, if the
- * dodistribute ever uses the path for something other than checking
- * to see that a path exists, enable this */
-/* #define SAVE_FINISH_PATHS */
-
-#ifndef SAVE_FINISH_PATHS
-static char *finish_path = "h";        /* Placeholder indicating path exists */
-#endif /* SAVE_FINISH_PATHS */
-
 static void assemble_dist_paths(struct distinfo *distptrs);
 static char *ReversePath(char *path);
 
@@ -72,6 +61,7 @@ finish_sects(int etu)
     struct sctstr *sp;
     struct natstr *np;
     int n;
+    struct rusage rus1, rus2;
     struct distinfo *infptr;
 
     if (g_distptrs == NULL) {
@@ -102,6 +92,7 @@ finish_sects(int etu)
     logerror("done delivering\n");
 
     logerror("assembling paths...\n");
+    getrusage(RUSAGE_SELF, &rus1);
 
     /* First, enable the best_path cacheing */
     bp_enable_cachepath();
@@ -115,7 +106,12 @@ finish_sects(int etu)
     /* Now, clear the best_path cache that may have been created */
     bp_clear_cachepath();
 
-    logerror("done assembling paths\n");
+    getrusage(RUSAGE_SELF, &rus2);
+    logerror("done assembling paths %g user %g system",
+            rus2.ru_utime.tv_sec + rus2.ru_utime.tv_usec / 1e6
+            - (rus1.ru_utime.tv_sec + rus1.ru_utime.tv_usec / 1e6),
+            rus2.ru_stime.tv_sec + rus2.ru_stime.tv_usec / 1e6
+            - (rus1.ru_stime.tv_sec + rus1.ru_stime.tv_usec / 1e6));
 
     logerror("exporting...");
     for (n = 0; NULL != (sp = getsectid(n)); n++) {
@@ -126,38 +122,20 @@ finish_sects(int etu)
            continue;
        /* Get the pointer */
        infptr = &g_distptrs[sp->sct_uid];
-       dodistribute(sp, EXPORT,
-                    infptr->path, infptr->imcost, infptr->excost);
+       dodistribute(sp, EXPORT, infptr->imcost, infptr->excost);
     }
     logerror("done exporting\n");
 
-    /* Note that we free the paths (if allocated) as we loop here */
     logerror("importing...");
     for (n = 0; NULL != (sp = getsectid(n)); n++) {
        /* Get the pointer (we do it first so we can free if needed) */
        infptr = &g_distptrs[sp->sct_uid];
-       if (sp->sct_type == SCT_WATER || sp->sct_own == 0) {
-#ifdef SAVE_FINISH_PATHS
-           if (infptr->path)
-               free(infptr->path);
-#endif /* SAVE_FINISH_PATHS */
+       if (sp->sct_type == SCT_WATER || sp->sct_own == 0)
            continue;
-       }
        np = getnatp(sp->sct_own);
-       if (np->nat_money < 0) {
-#ifdef SAVE_FINISH_PATHS
-           if (infptr->path)
-               free(infptr->path);
-#endif /* SAVE_FINISH_PATHS */
+       if (np->nat_money < 0)
            continue;
-       }
-       dodistribute(sp, IMPORT,
-                    infptr->path, infptr->imcost, infptr->excost);
-#ifdef SAVE_FINISH_PATHS
-       if (infptr->path)
-           free(infptr->path);
-#endif /* SAVE_FINISH_PATHS */
-
+       dodistribute(sp, IMPORT, infptr->imcost, infptr->excost);
        sp->sct_off = 0;
     }
     logerror("done importing\n");
@@ -194,17 +172,9 @@ assemble_dist_paths(struct distinfo *distptrs)
        path = BestDistPath(buf, dist, sp, &d);
 
        /* Now, we have a path */
-       if (path != NULL) {
-#ifdef SAVE_FINISH_PATHS
-           int len;
-           /* Here we malloc a buffer and save it */
-           len = strlen(path);
-           infptr->path = malloc(len);
-           if (infptr->path == NULL) {
-               logerror("malloc failed in assemble_dist_path!\n");
-               return;
-           }
-#endif /* SAVE_FINISH_PATHS */
+       if (!path)
+           infptr->imcost = infptr->excost = -1.0;
+       else {
            /* Save the import cost */
            infptr->imcost = d;
            /* Now, reverse the path */
@@ -212,11 +182,6 @@ assemble_dist_paths(struct distinfo *distptrs)
            /* And walk the path back to the dist center to get the export
               cost */
            infptr->excost = pathcost(sp, p, MOB_MOVE);
-#ifdef SAVE_FINISH_PATHS
-           memcpy(infptr->path, p, len);
-#else
-           infptr->path = finish_path;
-#endif /* SAVE_FINISH_PATHS */
        }
     }
 }