LCOV - code coverage report
Current view: top level - runtime - main.c (source / functions) Hit Total Coverage
Test: unnamed Lines: 0 50 0.0 %
Date: 2018-01-11 Functions: 0 1 0.0 %

          Line data    Source code
       1             : /*
       2             : START OF LICENSE STUB
       3             :     DeDOS: Declarative Dispersion-Oriented Software
       4             :     Copyright (C) 2017 University of Pennsylvania, Georgetown University
       5             : 
       6             :     This program is free software: you can redistribute it and/or modify
       7             :     it under the terms of the GNU General Public License as published by
       8             :     the Free Software Foundation, either version 3 of the License, or
       9             :     (at your option) any later version.
      10             : 
      11             :     This program is distributed in the hope that it will be useful,
      12             :     but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :     GNU General Public License for more details.
      15             : 
      16             :     You should have received a copy of the GNU General Public License
      17             :     along with this program.  If not, see <http://www.gnu.org/licenses/>.
      18             : END OF LICENSE STUB
      19             : */
      20             : /**
      21             :  * @file runtime/main.c
      22             :  * Main executable file to start the runtime
      23             :  */
      24             : #include "worker_thread.h"
      25             : #include "local_files.h"
      26             : #include "rt_stats.h"
      27             : #include "logging.h"
      28             : #include "runtime_dfg.h"
      29             : #include "controller_communication.h"
      30             : #include "output_thread.h"
      31             : #include "socket_monitor.h"
      32             : #include "profiler.h"
      33             : #include "runtime_dfg.h"
      34             : 
      35             : #include <stdlib.h>
      36             : #include <unistd.h>
      37             : #include <stdbool.h>
      38             : #include <getopt.h>
      39             : #include <libgen.h>
      40             : #include <stdio.h>
      41             : 
      42             : /** The command-line arguments */
      43             : #define USAGE_ARGS \
      44             :     " -j dfg.json -i runtime_id [-l statlog] [-p profiling_prob]"
      45             : 
      46             : /**
      47             :  * Entry point to start the runtime
      48             :  */
      49           0 : int main(int argc, char **argv) {
      50             : 
      51           0 :     char *dfg_json = NULL;
      52           0 :     char *statlog = NULL;
      53           0 :     int runtime_id = -1;
      54           0 :     float prof_prob = 0;
      55             : 
      56           0 :     struct option long_options[] = {
      57             :         {NULL, 0, 0, 0}
      58             :     };
      59             : 
      60             :     while (1) {
      61           0 :         int option_index = 0;
      62           0 :         int c = getopt_long(argc, argv, "j:i:l:p:", long_options, &option_index);
      63             : 
      64           0 :         if (c == -1) {
      65           0 :             break;
      66             :         }
      67           0 :         switch (c) {
      68             :             case 'j':
      69           0 :                 dfg_json = optarg;
      70           0 :                 break;
      71             :             case 'i':
      72           0 :                 runtime_id = atoi(optarg);
      73           0 :                 break;
      74             :             case 'l':
      75           0 :                 statlog = optarg;
      76           0 :                 break;
      77             :             case 'p':
      78           0 :                 prof_prob = atof(optarg);
      79           0 :                 break;
      80             :             default:
      81           0 :                 printf("Unknown option provided: %c. Exiting\n", c);
      82           0 :                 exit(-1);
      83             :         }
      84           0 :     }
      85             : 
      86           0 :     if (dfg_json == NULL || runtime_id == -1) {
      87           0 :         printf("%s " USAGE_ARGS "\n", argv[0]);
      88           0 :         exit(-1);
      89             :     }
      90           0 :     set_local_directory(dirname(argv[0]));
      91             : 
      92           0 :     if (init_statistics() != 0) {
      93           0 :         log_warn("Error initializing runtime statistics");
      94             :     }
      95           0 :     INIT_PROFILER(prof_prob);
      96             : 
      97           0 :     if (init_runtime_dfg(dfg_json, runtime_id) != 0) {
      98           0 :         log_critical("Error initializing runtime %d  from json file %s. Exiting",
      99             :                   runtime_id, dfg_json);
     100           0 :         exit(-1);
     101             :     }
     102             : 
     103             :     struct sockaddr_in ctrl_addr;
     104           0 :     int rtn = controller_address(&ctrl_addr);
     105           0 :     if (rtn < 0) {
     106           0 :         log_critical("Could not get controller address from DFG");
     107           0 :         exit(-1);
     108             :     }
     109             : 
     110           0 :     struct dedos_thread *output_thread = start_output_monitor_thread();
     111           0 :     if (output_thread == NULL) {
     112           0 :         log_critical("Error starting output thread!");
     113           0 :         exit(-1);
     114             :     }
     115             : 
     116             :     // This will block until the socket monitor exits
     117           0 :     rtn = run_socket_monitor(local_runtime_port(), &ctrl_addr);
     118           0 :     if (rtn < 0) {
     119           0 :         log_critical("Error running socket monitor. Runtime will exit");
     120             :     }
     121             : 
     122           0 :     stop_output_monitor();
     123           0 :     stop_all_worker_threads();
     124           0 :     join_output_thread();
     125             : 
     126           0 :     finalize_statistics(statlog);
     127           0 :     free_runtime_dfg();
     128           0 :     log_info("Exiting runtime...");
     129           0 :     return 0;
     130             : }

Generated by: LCOV version 1.10