int get_outedges_num(CTXTdeclc callnodeptr call1) {
  struct hashtable *h;	
  struct hashtable_itr *itr;

  h=call1->outedges->hasht;
  itr = hashtable1_iterator(h);       
  SQUASH_LINUX_COMPILER_WARN(itr) ;
  
  return hashtable1_count(h);
}
Пример #2
0
/* utility function to destroy a select call */
static void select_destroy(CTXTdeclc char *connection_name)
{
  int i;
  int connectname_found = FALSE;

  SYS_MUTEX_LOCK(MUTEX_SOCKETS);
  for (i=0; i < MAXCONNECT; i++) {
    if(connections[i].empty_flag==FALSE) {
      /* find the matching connection_name to destroy */
      if (strcmp(connection_name, connections[i].connection_name) == 0) {
	connectname_found = TRUE;
	      
	/* destroy the corresponding structure */
	FD_ZERO(&connections[i].readset);
	FD_ZERO(&connections[i].writeset);
	FD_ZERO(&connections[i].exceptionset);

	connections[i].connection_name = NULL;
	connections[i].maximum_fd = 0;

	/* free the fds obtained by mem_alloc() */
	mem_dealloc(connections[i].read_fds,connections[i].sizer,OTHER_SPACE);
	mem_dealloc(connections[i].write_fds,connections[i].sizew,OTHER_SPACE);
	mem_dealloc(connections[i].exception_fds,connections[i].sizee,OTHER_SPACE); 
      
	connections[i].sizer = 0;
	connections[i].sizew = 0 ;
	connections[i].sizee = 0 ;

	connections[i].empty_flag = TRUE; /* set the destroyed slot to empty */
	break;
      }
    }
  }
  SYS_MUTEX_UNLOCK(MUTEX_SOCKETS);
  
  /* if no matching connection_name */
  if (!connectname_found)
    xsb_abort("[SOCKET_SELECT_DESTROY] connection `%s' doesn't exist", 
	      connection_name);
  
  SQUASH_LINUX_COMPILER_WARN(connectname_found) ; 
}
int  get_incr_sccs(CTXTdeclc Cell listterm) {
  Cell orig_listterm, intterm, node;
    long int node_num=0;
    int i = 0, dfn, component = 1;     int * dfn_stack; int dfn_top = 0, ret;
    SCCNode * nodes;
    struct hashtable_itr *itr;     struct hashtable* hasht; 
    XSB_Deref(listterm);
    hasht = create_hashtable1(HASH_TABLE_SIZE, hashid, equalkeys);
    orig_listterm = listterm;
    intterm = get_list_head(listterm);
    XSB_Deref(intterm);
    //    printf("listptr %p @%p\n",listptr,(CPtr) int_val(*listptr));
    insert_some(hasht,(void *) oint_val(intterm),(void *) node_num);
    node_num++; 

    listterm = get_list_tail(listterm);
    XSB_Deref(listterm);
    while (!isnil(listterm)) {
      intterm = get_list_head(listterm);
      XSB_Deref(intterm);
      node = oint_val(intterm);
      if (NULL == search_some(hasht, (void *)node)) {
	insert_some(hasht,(void *)node,(void *)node_num);
	node_num++;
      }
      listterm = get_list_tail(listterm);
      XSB_Deref(listterm);
    }
    nodes = (SCCNode *) mem_calloc(node_num, sizeof(SCCNode),OTHER_SPACE); 
    dfn_stack = (int *) mem_alloc(node_num*sizeof(int),OTHER_SPACE); 
    listterm = orig_listterm;; 
    //printf("listptr %p @%p\n",listptr,(void *)int_val(*(listptr)));
    intterm = get_list_head(listterm);
    XSB_Deref(intterm);
    nodes[0].node = (CPtr) oint_val(intterm);
    listterm = get_list_tail(listterm);
    XSB_Deref(listterm);
    i = 1;
    while (!isnil(listterm)) {
      intterm = get_list_head(listterm);
      XSB_Deref(intterm);
      node = oint_val(intterm);
      nodes[i].node = (CPtr) node;
      listterm = get_list_tail(listterm);
      XSB_Deref(listterm);
      i++;
    }
    itr = hashtable1_iterator(hasht);       
    SQUASH_LINUX_COMPILER_WARN(itr);
    //    do {
    //      printf("k %p val %p\n",hashtable1_iterator_key(itr),hashtable1_iterator_value(itr));
    //    } while (hashtable1_iterator_advance(itr));

    listterm = orig_listterm;
    //    printf("2: k %p v %p\n",(void *) int_val(*listptr),
    //	   search_some(hasht,(void *) int_val(*listptr)));

    //    while (!isnil(*listptr)) {  now all wrong...
    //      listptr = listptr + 1;
    //      node = int_val(*clref_val(listptr));
    //      printf("2: k %p v %p\n",(CPtr) node,search_some(hasht,(void *) node));
    //      listptr = listptr + 1;
    //    }
    dfn = 1;
    for (i = 0; i < node_num; i++) {
      if (nodes[i].dfn == 0) 
	xsb_compute_scc(nodes,dfn_stack,i,&dfn_top,hasht,&dfn,&component);
      //      printf("++component for node %d is %d (high %d)\n",i,nodes[i].component,component);
    }
    ret = return_scc_list(CTXTc  nodes, node_num);
    hashtable1_destroy(hasht,0);
    mem_dealloc(nodes,node_num*sizeof(SCCNode),OTHER_SPACE); 
    mem_dealloc(dfn_stack,node_num*sizeof(int),OTHER_SPACE); 
    return ret;
}
Пример #4
0
/* in order to save builtin numbers, create a single socket function with
 * options socket_request(SockOperation,....)  */
xsbBool xsb_socket_request(CTXTdecl)
{
  int ecode = 0;  /* error code for socket ops */
  int timeout_flag;
  SOCKET sock_handle;
  int domain, portnum;
  SOCKADDR_IN socket_addr;
  struct linger sock_linger_opt;
  int rc;
  char *message_buffer = NULL; /* initialized to keep compiler happy */
  UInteger msg_len = 0;	  /* initialized to keep compiler happy */
  char char_read;

  switch (ptoc_int(CTXTc 1)) {
  case SOCKET_ROOT: /* this is the socket() request */
    /* socket_request(SOCKET_ROOT,+domain,-socket_fd,-Error,_,_,_) 
       Currently only AF_INET domain */
    domain = (int)ptoc_int(CTXTc 2); 
    if (!translate_domain(domain, &domain)) {
      return FALSE;
    }
    
    sock_handle = socket(domain, SOCK_STREAM, IPPROTO_TCP);
	
    /* error handling */
    if (BAD_SOCKET(sock_handle)) {
      ecode = XSB_SOCKET_ERRORCODE;
      perror("SOCKET_REQUEST");
    } else {
      ecode = SOCK_OK;
    }

    ctop_int(CTXTc 3, (SOCKET) sock_handle);
	
    return set_error_code(CTXTc ecode, 4, "SOCKET_REQUEST");

  case SOCKET_BIND:
    /* socket_request(SOCKET_BIND,+domain,+sock_handle,+port,-Error,_,_) 
       Currently only supports AF_INET */
    sock_handle = (SOCKET) ptoc_int(CTXTc 3);
    portnum = (int)ptoc_int(CTXTc 4);
    domain = (int)ptoc_int(CTXTc 2);

    if (!translate_domain(domain, &domain)) {
      return FALSE;
    }
    
    /* Bind server to the agreed upon port number.
    ** See commdef.h for the actual port number. */
    FillWithZeros(socket_addr);
    socket_addr.sin_port = htons((unsigned short)portnum);
    socket_addr.sin_family = AF_INET;
#ifndef WIN_NT
    socket_addr.sin_addr.s_addr = htonl(INADDR_ANY);
#endif
    
    rc = bind(sock_handle, (PSOCKADDR) &socket_addr, sizeof(socket_addr));
	
    /* error handling */
    if (SOCKET_OP_FAILED(rc)) {
      ecode = XSB_SOCKET_ERRORCODE;
      perror("SOCKET_BIND");
    } else
      ecode = SOCK_OK;

    return set_error_code(CTXTc ecode, 5, "SOCKET_BIND");

  case SOCKET_LISTEN: 
    /* socket_request(SOCKET_LISTEN,+sock_handle,+length,-Error,_,_,_) */
    sock_handle = (SOCKET) ptoc_int(CTXTc 2);
    rc = listen(sock_handle, (int)ptoc_int(CTXTc 3));

    /* error handling */
    if (SOCKET_OP_FAILED(rc)) {
      ecode = XSB_SOCKET_ERRORCODE;
      perror("SOCKET_LISTEN");
    } else
      ecode = SOCK_OK;

    return set_error_code(CTXTc ecode, 4, "SOCKET_LISTEN");

  case SOCKET_ACCEPT:
    timeout_flag = socket_accept(CTXTc (SOCKET *)&rc, (int)pflags[SYS_TIMER]);
	  
    if (timeout_flag == TIMED_OUT) {
      return set_error_code(CTXTc TIMEOUT_ERR, 4, "SOCKET_SEND");
    } else {
      /* error handling */ 
      if (BAD_SOCKET(rc)) {
	ecode = XSB_SOCKET_ERRORCODE;
	perror("SOCKET_ACCEPT");
	sock_handle = rc; /* shut up warning */
      } else {
	sock_handle = rc; /* accept() returns sock_out */
	ecode = SOCK_OK;
      }
	       
      ctop_int(CTXTc 3, (SOCKET) sock_handle);
	       
      return set_error_code(CTXTc ecode,  4,  "SOCKET_ACCEPT");	  
    }
  case SOCKET_CONNECT: {
    /* socket_request(SOCKET_CONNECT,+domain,+sock_handle,+port,
       +hostname,-Error) */
    timeout_flag = socket_connect(CTXTc &rc, (int)pflags[SYS_TIMER]);

    if (timeout_flag == TIMED_OUT) {
      return set_error_code(CTXTc TIMEOUT_ERR, 6, "SOCKET_CONNECT");
    } else if (timeout_flag == TIMER_SETUP_ERR) {
      return set_error_code(CTXTc TIMER_SETUP_ERR, 6, "SOCKET_CONNECT");
    } else {
      /* error handling */
      if (SOCKET_OP_FAILED(rc)) {
	ecode = XSB_SOCKET_ERRORCODE;
	perror("SOCKET_CONNECT");
	/* close, because if connect() fails then socket becomes unusable */
	closesocket(ptoc_int(CTXTc 3));
      } else {
	ecode = SOCK_OK;
      }
      return set_error_code(CTXTc ecode,  6,  "SOCKET_CONNECT");
    }
  }

  case SOCKET_CLOSE: 
    /* socket_request(SOCKET_CLOSE,+sock_handle,-Error,_,_,_,_) */
    
    sock_handle = (SOCKET)ptoc_int(CTXTc 2);
    
    /* error handling */
    rc = closesocket(sock_handle);
    if (SOCKET_OP_FAILED(rc)) {
      ecode = XSB_SOCKET_ERRORCODE;
      perror("SOCKET_CLOSE");
    } else
      ecode = SOCK_OK;
    
    return set_error_code(CTXTc ecode, 3, "SOCKET_CLOSE");
    
  case SOCKET_RECV:
    /* socket_request(SOCKET_RECV,+Sockfd, -Msg, -Error,_,_,_) */
    // TODO: consider adding protection against interrupts, EINTR, like
    //       in socket_get0.
    timeout_flag = socket_recv(CTXTc &rc, &message_buffer, &msg_len, (int)pflags[SYS_TIMER]);
	  
    if (timeout_flag == TIMED_OUT) {
      return set_error_code(CTXTc TIMEOUT_ERR, 4, "SOCKET_SEND");
    } else {
      /* error handling */
      switch (rc) {
      case SOCK_OK:
	ecode = SOCK_OK;
	break;
      case SOCK_READMSG_FAILED:
	ecode = XSB_SOCKET_ERRORCODE;
	perror("SOCKET_RECV");
	break;
      case SOCK_READMSG_EOF:
	ecode = SOCK_EOF;
	break;
      case SOCK_HEADER_LEN_MISMATCH:
	ecode = XSB_SOCKET_ERRORCODE;
	break;
      default:
	xsb_abort("XSB bug: [SOCKET_RECV] invalid return code from readmsg");
      }
	       
      if (message_buffer != NULL) {
	/* use message_buffer+XSB_MSG_HEADER_LENGTH because the first
	   XSB_MSG_HEADER_LENGTH bytes are for the message length header */
	ctop_string(CTXTc 3, (char*)message_buffer+XSB_MSG_HEADER_LENGTH);
	mem_dealloc(message_buffer,msg_len,OTHER_SPACE);
      } else {  /* this happens at the end of a file */
	ctop_string(CTXTc 3, (char*)"");
      }
	       
      return set_error_code(CTXTc ecode, 4, "SOCKET_RECV");  
    }
	       
  case SOCKET_SEND:
    /* socket_request(SOCKET_SEND,+Sockfd, +Msg, -Error,_,_,_) */
    timeout_flag = socket_send(CTXTc &rc, (int)pflags[SYS_TIMER]);
    
    if (timeout_flag == TIMED_OUT) {
      return set_error_code(CTXTc TIMEOUT_ERR, 4, "SOCKET_SEND");
    } else {
      /* error handling */
      if (SOCKET_OP_FAILED(rc)) {
	ecode = XSB_SOCKET_ERRORCODE;
	perror("SOCKET_SEND");
      } else {
	ecode = SOCK_OK;
      }
      return set_error_code(CTXTc ecode,  4,  "SOCKET_SEND"); 
    }

  case SOCKET_GET0:
    /* socket_request(SOCKET_GET0,+Sockfd,-C,-Error,_,_,_) */
    message_buffer = &char_read;
    timeout_flag = socket_get0(CTXTc &rc, message_buffer, (int)pflags[SYS_TIMER]);
	  
    if (timeout_flag == TIMED_OUT) {
      return set_error_code(CTXTc TIMEOUT_ERR, 4, "SOCKET_SEND");
    } else {
      /*error handling */ 
      switch (rc) {
      case 1:
	ctop_int(CTXTc 3,(unsigned char)message_buffer[0]);
	ecode = SOCK_OK;
	break;
      case 0:
	ecode = SOCK_EOF;
	break;
      default:
	ctop_int(CTXTc 3,-1);
	perror("SOCKET_GET0");
	ecode = XSB_SOCKET_ERRORCODE;
      }
	       
      return set_error_code(CTXTc ecode,  4,  "SOCKET_GET0");
    }    
  case SOCKET_PUT:
    /* socket_request(SOCKET_PUT,+Sockfd,+C,-Error_,_,_) */
    timeout_flag = socket_put(CTXTc &rc, (int)pflags[SYS_TIMER]);
	       
    if (timeout_flag == TIMED_OUT) {
      return set_error_code(CTXTc TIMEOUT_ERR, 4, "SOCKET_SEND");
    } else {
      /* error handling */
      if (rc == 1) {
	ecode = SOCK_OK;
      } else if (SOCKET_OP_FAILED(rc)) {
	ecode = XSB_SOCKET_ERRORCODE;
	perror("SOCKET_PUT");
      }
	       
      return set_error_code(CTXTc ecode,  4,  "SOCKET_PUT");
    }
  case SOCKET_SET_OPTION: {
    /* socket_request(SOCKET_SET_OPTION,+Sockfd,+OptionName,+Value,_,_,_) */
    
    char *option_name = ptoc_string(CTXTc 3);
    
    sock_handle = (SOCKET)ptoc_int(CTXTc 2);

    /* Set the "linger" parameter to a small number of seconds */
    if (0==strcmp(option_name,"linger")) {
      int  linger_time=(int)ptoc_int(CTXTc 4);
      
      if (linger_time < 0) {
	sock_linger_opt.l_onoff = FALSE;
	sock_linger_opt.l_linger = 0;
      } else {
	sock_linger_opt.l_onoff = TRUE;
	sock_linger_opt.l_linger = linger_time;
      }
      
      if (SETSOCKOPT(sock_handle, SOL_SOCKET, SO_LINGER,
		     &sock_linger_opt, sizeof(sock_linger_opt))
	  < 0) {
	xsb_warn(CTXTc "[SOCKET_SET_OPTION] Cannot set socket linger time");
	return FALSE;
      } 
    }else {
      xsb_warn(CTXTc "[SOCKET_SET_OPTION] Invalid option, `%s'", option_name);
      return FALSE;
    }
    
    return TRUE;
  }

  case SOCKET_SET_SELECT:  {  
    /*socket_request(SOCKET_SET_SELECT,+connection_name,
      +R_sockfd,+W_sockfd,+E_sockfd) */
    prolog_term R_sockfd, W_sockfd, E_sockfd;
    int i, connection_count;
    int rmax_fd=0, wmax_fd=0, emax_fd=0; 
    char *connection_name = ptoc_string(CTXTc 2);
    
    /* bind fds to input arguments */
    R_sockfd = reg_term(CTXTc 3);
    W_sockfd = reg_term(CTXTc 4);
    E_sockfd = reg_term(CTXTc 5);	
    
    /* initialize the array of connect_t structure for select call */	
    init_connections(CTXT); 
    
    SYS_MUTEX_LOCK(MUTEX_SOCKETS);
    /* check whether the same connection name exists */
    for (i=0;i<MAXCONNECT;i++) {
      if ((connections[i].empty_flag==FALSE) &&
	  (strcmp(connection_name,connections[i].connection_name)==0)) 	
	xsb_abort("[SOCKET_SET_SELECT] Connection `%s' already exists!",
		  connection_name);
    }
    
    /* check whether there is empty slot left for connection */	
    if ((connection_count=checkslot())<MAXCONNECT) {
      if (connections[connection_count].connection_name == NULL) {
	connections[connection_count].connection_name = connection_name;
	connections[connection_count].empty_flag = FALSE;
	
	/* call the utility function separately to take the fds in */
	list_sockfd(R_sockfd, &connections[connection_count].readset,
		    &rmax_fd, &connections[connection_count].read_fds,
		    &connections[connection_count].sizer);
	list_sockfd(W_sockfd, &connections[connection_count].writeset,
		    &wmax_fd, &connections[connection_count].write_fds,
		    &connections[connection_count].sizew);
	list_sockfd(E_sockfd, &connections[connection_count].exceptionset, 
		    &emax_fd,&connections[connection_count].exception_fds,
		    &connections[connection_count].sizee);
	
	connections[connection_count].maximum_fd =
	  xsb_max(xsb_max(rmax_fd,wmax_fd), emax_fd);
      } else 
	/* if this one is reached, it is probably a bug */
	xsb_abort("[SOCKET_SET_SELECT] All connections are busy!");
    } else
      xsb_abort("[SOCKET_SET_SELECT] Max number of collections exceeded!");
    SYS_MUTEX_UNLOCK(MUTEX_SOCKETS);
    
    return TRUE;
  }
  
  case SOCKET_SELECT: {
    /* socket_request(SOCKET_SELECT,+connection_name, +timeout
       -avail_rsockfds,-avail_wsockfds,
       -avail_esockfds,-ecode)
       Returns 3 prolog_terms for available socket fds */

    prolog_term Avail_rsockfds, Avail_wsockfds, Avail_esockfds;
    prolog_term Avail_rsockfds_tail, Avail_wsockfds_tail, Avail_esockfds_tail;

    int maxfd;
    int i;       /* index for connection_count */
    char *connection_name = ptoc_string(CTXTc 2);
    struct timeval *tv;
    prolog_term timeout_term;
    int timeout =0;
    int connectname_found = FALSE;
    int count=0;			

    SYS_MUTEX_LOCK(MUTEX_SOCKETS);
    /* specify the time out */
    timeout_term = reg_term(CTXTc 3);
    if (isointeger(timeout_term)) {
      timeout = (int)oint_val(timeout_term);
      /* initialize tv */
      tv = (struct timeval *)mem_alloc(sizeof(struct timeval),LEAK_SPACE);
      tv->tv_sec = timeout;
      tv->tv_usec = 0;
    } else
      tv = NULL; /* no timeouts */

    /* initialize the prolog term */ 
    Avail_rsockfds = p2p_new(CTXT);
    Avail_wsockfds = p2p_new(CTXT);
    Avail_esockfds = p2p_new(CTXT); 

    /* bind to output arguments */
    Avail_rsockfds = reg_term(CTXTc 4);
    Avail_wsockfds = reg_term(CTXTc 5);
    Avail_esockfds = reg_term(CTXTc 6);

    Avail_rsockfds_tail = Avail_rsockfds;
    Avail_wsockfds_tail = Avail_wsockfds;
    Avail_esockfds_tail = Avail_esockfds;

    /*
      // This was wrong. Lists are now made inside test_ready()
      c2p_list(CTXTc Avail_rsockfds_tail);
      c2p_list(CTXTc Avail_wsockfds_tail);	
      c2p_list(CTXTc Avail_esockfds_tail); 
    */
    
    for (i=0; i < MAXCONNECT; i++) {
      /* find the matching connection_name to select */
      if(connections[i].empty_flag==FALSE) {
	if (strcmp(connection_name, connections[i].connection_name) == 0) {
	  connectname_found = TRUE;
	  count = i;
	  break;
	} 
      }
    }
    if( i >= MAXCONNECT )  /* if no matching connection_name */
      xsb_abort("[SOCKET_SELECT] connection `%s' doesn't exist",
		connection_name); 
    
    /* compute maxfd for select call */
    maxfd = connections[count].maximum_fd + 1;

    /* FD_SET all sockets */
    set_sockfd( CTXTc count );

    /* test whether the socket fd is available */
    rc = select(maxfd, &connections[count].readset, 
		&connections[count].writeset,
		&connections[count].exceptionset, tv);
    
    /* error handling */	
    if (rc == 0)     /* timed out */
      ecode = TIMEOUT_ERR;
    else if (SOCKET_OP_FAILED(rc)) {
      perror("SOCKET_SELECT");
      ecode = XSB_SOCKET_ERRORCODE;
    } else {      /* no error */
      ecode = SOCK_OK;
	 
      /* call the utility function to return the available socket fds */
      test_ready(CTXTc &Avail_rsockfds_tail, &connections[count].readset,
		 connections[count].read_fds,connections[count].sizer);

      test_ready(CTXTc &Avail_wsockfds_tail, &connections[count].writeset,
		 connections[count].write_fds,connections[count].sizew);

      test_ready(CTXTc &Avail_esockfds_tail,&connections[count].exceptionset,
		 connections[count].exception_fds,connections[count].sizee);
    }
    SYS_MUTEX_UNLOCK(MUTEX_SOCKETS);

    if (tv) mem_dealloc((struct timeval *)tv,sizeof(struct timeval),LEAK_SPACE);
    SQUASH_LINUX_COMPILER_WARN(connectname_found) ; 
    return set_error_code(CTXTc ecode, 7, "SOCKET_SELECT");
  }

  case SOCKET_SELECT_DESTROY:  { 
    /*socket_request(SOCKET_SELECT_DESTROY, +connection_name) */
    char *connection_name = ptoc_string(CTXTc 2);
    select_destroy(CTXTc connection_name);
    return TRUE;
  }

  default:
    xsb_warn(CTXTc "[SOCKET_REQUEST] Invalid socket request %d", (int) ptoc_int(CTXTc 1));
    return FALSE;
  }

  /* This trick would report a bug, if a newly added case
     doesn't have a return clause */
  xsb_bug("SOCKET_REQUEST case %d has no return clause", ptoc_int(CTXTc 1));
}
Пример #5
0
void print_detailed_tablespace_stats(CTXTdecl) {

  NodeStats
    abtn,		/* Asserted Basic Trie Nodes */
    btn,		/* Basic Trie Nodes */
    aln,		/* Answer List Nodes */
    varsf,		/* Variant Subgoal Frames */
    asi;		/* Answer Subgoal Information */

  HashStats
    abtht,		/* Asserted Basic Trie Hash Tables */
    btht;		/* Basic Trie Hash Tables */

  NodeStats  
    pri_tstn,		/* Private Time Stamp Trie Nodes */
    pri_tsi,		/* Private Time Stamp Indices (Index Entries/Nodes) */
    pri_prodsf,		/* Private Subsumptive Producer Subgoal Frames */
    pri_conssf,		/* Private Subsumptive Consumer Subgoal Frames */
    pri_btn,		/* Private Basic Trie Nodes (Tables) */
    pri_assert_btn,	/* Private Basic Trie Nodes (Asserts) */
    pri_aln,		/* Private Answer List Nodes */
    pri_varsf,		/* Private Variant Subgoal Frames */
    pri_asi;		/* Private Answer Subgoal Information */
  
  HashStats
    pri_btht,		/* Private Basic Trie Hash Tables (Tables) */
    pri_assert_btht,	/* Private Basic Trie Hash Tables (Asserts) */
    pri_tstht;		/* Private Time Stamp Trie Hash Tables */

  size_t
    tablespace_alloc, tablespace_used,
    pri_tablespace_alloc, pri_tablespace_used,
    shared_tablespace_alloc, shared_tablespace_used,
    trieassert_alloc, trieassert_used,
    de_space_alloc, de_space_used,
    dl_space_alloc, dl_space_used,
    pnde_space_alloc, pnde_space_used,
    pri_de_space_alloc, pri_de_space_used,
    pri_dl_space_alloc, pri_dl_space_used,
    pri_pnde_space_alloc, pri_pnde_space_used;

  size_t num_de_blocks, num_dl_blocks, num_pnde_blocks;
  size_t pri_num_de_blocks, pri_num_dl_blocks, pri_num_pnde_blocks;

  SM_Lock(smTableBTN);
  btn = node_statistics(&smTableBTN);
  SM_Unlock(smTableBTN);
  SM_Lock(smTableBTHT);
  btht = hash_statistics(CTXTc &smTableBTHT);
  SM_Unlock(smTableBTHT);
  SM_Lock(smVarSF);
  varsf = subgoal_statistics(CTXTc &smVarSF);
  SM_Unlock(smVarSF);
  SM_Lock(smALN);
  aln = node_statistics(&smALN);
  SM_Unlock(smALN);
  SM_Lock(smASI);
  asi = node_statistics(&smASI);
  SM_Unlock(smASI);

  SYS_MUTEX_LOCK( MUTEX_DELAY );			
  de_space_alloc = allocated_de_space(current_de_block_gl,&num_de_blocks);
  de_space_used = de_space_alloc - unused_de_space();
  dl_space_alloc = allocated_dl_space(current_dl_block_gl,&num_dl_blocks);
  dl_space_used = dl_space_alloc - unused_dl_space();
  pnde_space_alloc = allocated_pnde_space(current_pnde_block_gl,&num_pnde_blocks);
  pnde_space_used = pnde_space_alloc - unused_pnde_space();
  SYS_MUTEX_UNLOCK( MUTEX_DELAY );			

  pri_btn = node_statistics(private_smTableBTN);
  pri_btht = hash_statistics(CTXTc private_smTableBTHT);
  pri_assert_btn = node_statistics(private_smAssertBTN);
  pri_assert_btht = hash_statistics(CTXTc private_smAssertBTHT);
  pri_aln = node_statistics(private_smALN);
  pri_asi = node_statistics(private_smASI);
  pri_varsf = subgoal_statistics(CTXTc private_smVarSF);
  pri_prodsf = subgoal_statistics(CTXTc private_smProdSF);
  pri_conssf = subgoal_statistics(CTXTc private_smConsSF);
  pri_tstn = node_statistics(private_smTSTN);
  pri_tsi = node_statistics(private_smTSIN);
  pri_btht = hash_statistics(CTXTc private_smTableBTHT);
  pri_tstht = hash_statistics(CTXTc private_smTSTHT);

  pri_de_space_alloc = allocated_de_space(private_current_de_block,&pri_num_de_blocks);
  pri_de_space_used = pri_de_space_alloc - unused_de_space_private(CTXT);
  pri_dl_space_alloc = allocated_dl_space(private_current_dl_block,&pri_num_dl_blocks);
  pri_dl_space_used = pri_dl_space_alloc - unused_dl_space_private(CTXT);
  pri_pnde_space_alloc = allocated_pnde_space(private_current_pnde_block,&pri_num_pnde_blocks);
  pri_pnde_space_used = pri_pnde_space_alloc - unused_pnde_space_private(CTXT);

  pri_tablespace_alloc = CurrentPrivateTableSpaceAlloc(pri_btn,pri_btht,pri_varsf,pri_prodsf,
						       pri_conssf,pri_aln,pri_tstn,pri_tstht,pri_tsi,
						       pri_asi);
  pri_tablespace_used = CurrentPrivateTableSpaceUsed(pri_btn,pri_btht,pri_varsf,pri_prodsf,
						     pri_conssf,pri_aln,pri_tstn,pri_tstht,pri_tsi,
						     pri_asi);

  pri_tablespace_alloc = pri_tablespace_alloc + pri_de_space_alloc + 
    pri_dl_space_alloc + pri_pnde_space_alloc;
  pri_tablespace_used = pri_tablespace_used + pri_de_space_used + pri_dl_space_used + pri_pnde_space_used;

  shared_tablespace_alloc = CurrentSharedTableSpaceAlloc(btn,btht,varsf,aln,asi);
  shared_tablespace_used = CurrentSharedTableSpaceUsed(btn,btht,varsf,aln,asi);

  shared_tablespace_alloc = shared_tablespace_alloc + de_space_alloc + dl_space_alloc + pnde_space_alloc;
  shared_tablespace_used = shared_tablespace_used + de_space_used + dl_space_used + pnde_space_used;

  tablespace_alloc = shared_tablespace_alloc + pri_tablespace_alloc;
  tablespace_used =  shared_tablespace_used + pri_tablespace_used;

  abtn = node_statistics(&smAssertBTN);
  abtht = hash_statistics(CTXTc &smAssertBTHT);
  trieassert_alloc = NodeStats_SizeAllocNodes(abtn) + HashStats_SizeAllocTotal(abtht);
  trieassert_used = NodeStats_SizeUsedNodes(abtn) + HashStats_SizeUsedTotal(abtht);
  SQUASH_LINUX_COMPILER_WARN(trieassert_used) ; 

  printf("  Current Total Allocation:   %12"UIntfmt" bytes\n"
  	 "  Current Total Usage:        %12"UIntfmt" bytes\n",
	 pspacesize[TABLE_SPACE]-trieassert_alloc,  
	 pspacesize[TABLE_SPACE]-trieassert_alloc-(tablespace_alloc-tablespace_used));

  //   printf("\n --------------------- Shared tables ---------------------\n");

  printf("\n"
	 "Shared Table Space Usage (exc"UIntfmt"ding asserted and interned tries) \n");
  printf("  Current Total Allocation:   %12"UIntfmt" bytes\n"
  	 "  Current Total Usage:        %12"UIntfmt" bytes\n",
	 shared_tablespace_alloc,shared_tablespace_used);

  // Basic Trie Stuff
  if ( NodeStats_NumBlocks(btn) > 0 || HashStats_NumBlocks(btht) > 0 || NodeStats_NumBlocks(aln) > 0) {
    printf("\n"
	   "  Basic Tries\n");
    if ( NodeStats_NumBlocks(btn) > 0) 
      print_NodeStats(btn,"Basic Trie Nodes");
    if (HashStats_NumBlocks(btht) > 0)
      print_HashStats(btht,"Basic Trie Hash Tables");
    if ( NodeStats_NumBlocks(aln) > 0) 
      print_NodeStats(aln,"Answer List Nodes (for Incomplete Variant Tables)");
  }

  // Subgoal Frames
  if (NodeStats_NumBlocks(varsf) > 0) {
    printf("\n"
	   "  Subgoal Frames\n");
    if (NodeStats_NumBlocks(varsf) > 0)
      print_NodeStats(varsf,"Variant Subgoal Frames");
  }

  // Conditional Answers
  if (dl_space_alloc > 0 || de_space_alloc > 0 || pnde_space_alloc > 0 
      || NodeStats_NumBlocks(asi) > 0) {
    printf("\n"
	   "  Information for Conditional Answers in Variant Tables \n");
    if (dl_space_alloc > 0) 
      print_wfs_usage(dl_space_alloc,dl_space_used,num_dl_blocks,DLS_PER_BLOCK,
		      sizeof(struct delay_list),"Delay Lists");
    if (de_space_alloc > 0) 
      print_wfs_usage(de_space_alloc,de_space_used,num_de_blocks,DES_PER_BLOCK,
		      sizeof(struct delay_element),"Delay Elements");
    if (pnde_space_alloc > 0) 
      print_wfs_usage(pnde_space_alloc,pnde_space_used,num_pnde_blocks,PNDES_PER_BLOCK,
		      sizeof(struct pos_neg_de_list),"Back-pointer Lists");
    if ( NodeStats_NumBlocks(asi) > 0)
      print_NodeStats(asi,"Answer Substitution Frames");
  }

  // Private trie assert space
  if ( NodeStats_NumBlocks(abtn) > 0 || HashStats_NumBlocks(abtht) > 0) {
  printf("\n ---------------- Shared Asserted and Interned Tries  ----------------\n");
    if ( NodeStats_NumBlocks(abtn) > 0) 
      print_NodeStats(abtn,"Basic Trie Nodes (Assert)");
    if (HashStats_NumBlocks(abtht) > 0)
      print_HashStats(abtht,"Basic Trie Hash Tables (Assert)");
  }

  printf("\n --------------------- Private tables ---------------------\n");
  printf("\n"
	 "Private Table Space Usage for Thread %"Intfmt" (exc"UIntfmt"ding asserted and interned tries) \n"
	 "  Current Total Allocation:   %12"UIntfmt" bytes\n"
  	 "  Current Total Usage:        %12"UIntfmt" bytes\n",
	 xsb_thread_id,pri_tablespace_alloc,pri_tablespace_used);

  // Basic Trie Stuff
  if ( NodeStats_NumBlocks(pri_btn) > 0 || HashStats_NumBlocks(pri_btht) > 0 
       || NodeStats_NumBlocks(pri_aln) > 0) {
    printf("\n"
	   "  Basic Tries\n");
    if ( NodeStats_NumBlocks(pri_btn) > 0) 
      print_NodeStats(pri_btn,"Basic Trie Nodes");
    if (HashStats_NumBlocks(pri_btht) > 0)
      print_HashStats(pri_btht,"Basic Trie Hash Tables");
    if ( NodeStats_NumBlocks(pri_aln) > 0) 
      print_NodeStats(pri_aln,"Answer List Nodes (for Incomplete Variant Tables)");
  }

  // Subgoal Frames
  if (NodeStats_NumBlocks(pri_varsf) > 0 || NodeStats_NumBlocks(pri_prodsf) > 0 ||
      NodeStats_NumBlocks(pri_conssf) > 0) {
    printf("\n"
	   "  Subgoal Frames\n");
    if (NodeStats_NumBlocks(pri_varsf) > 0)
      print_NodeStats(pri_varsf,"Variant Subgoal Frames");
    if (NodeStats_NumBlocks(pri_prodsf) > 0)
      print_NodeStats(pri_prodsf,"Producer Subgoal Frames");
    if (NodeStats_NumBlocks(pri_conssf) > 0)
      print_NodeStats(pri_conssf,"Consumer Subgoal Frames");
  }

  // Subsumptive Tables
  if ( NodeStats_NumBlocks(pri_tstn) > 0 || HashStats_NumBlocks(pri_tstht) > 0
       || NodeStats_NumBlocks(pri_tsi) > 0) {
    printf("\n"
	   "  Time Stamp Tries (for Subsumptive Tables) \n");
    if (NodeStats_NumBlocks(pri_tstn) > 0) 
      print_NodeStats(pri_tstn,"Time Stamp Trie Nodes");
    if (HashStats_NumBlocks(pri_tstht) > 0) 
      print_HashStats(pri_tstht,"Time Stamp Trie Hash Tables");
    if (NodeStats_NumBlocks(pri_tsi) > 0) 
      print_NodeStats(pri_tsi,"Time Stamp Trie Index Nodes");
  }

  // Conditional Answers
  if (pri_dl_space_alloc > 0 || pri_de_space_alloc > 0 || pri_pnde_space_alloc > 0 
      || NodeStats_NumBlocks(pri_asi) > 0) {
    printf("\n"
	   "  Information for Conditional Answers in Variant Tables \n");
    if (pri_dl_space_alloc > 0) 
      print_wfs_usage(pri_dl_space_alloc,pri_dl_space_used,pri_num_dl_blocks,DLS_PER_BLOCK,
		      sizeof(struct delay_list),"Delay Lists");
    if (pri_de_space_alloc > 0) 
      print_wfs_usage(pri_de_space_alloc,pri_de_space_used,pri_num_de_blocks,DES_PER_BLOCK,
		      sizeof(struct delay_element),"Delay Elements");
    if (pri_pnde_space_alloc > 0) 
      print_wfs_usage(pri_pnde_space_alloc,pri_pnde_space_used,pri_num_pnde_blocks,PNDES_PER_BLOCK,
		      sizeof(struct pos_neg_de_list),"Back-pointer Lists");
    if ( NodeStats_NumBlocks(pri_asi) > 0)
      print_NodeStats(pri_asi,"Answer Substitution Frames");
  }

  // Private trie assert space
  if ( NodeStats_NumBlocks(pri_assert_btn) > 0 || HashStats_NumBlocks(pri_assert_btht) > 0) {
  printf("\n ---------------- Private Asserted and Interned Tries  ----------------\n");
    if ( NodeStats_NumBlocks(pri_assert_btn) > 0) 
      print_NodeStats(pri_assert_btn,"Basic Trie Nodes (Assert)");
    if (HashStats_NumBlocks(pri_assert_btht) > 0)
      print_HashStats(pri_assert_btht,"Basic Trie Hash Tables (Assert)");
  }

  printf("\n");
}
Пример #6
0
void print_detailed_tablespace_stats(CTXTdecl) {

  NodeStats
    abtn,		/* Asserted Basic Trie Nodes */
    btn,		/* Basic Trie Nodes */
    tstn,		/* Time Stamp Trie Nodes */
    aln,		/* Answer List Nodes */
    tsi,		/* Time Stamp Indices (Index Entries/Nodes) */
    varsf,		/* Variant Subgoal Frames */
    prodsf,		/* Subsumptive Producer Subgoal Frames */
    conssf,		/* Subsumptive Consumer Subgoal Frames */ 
    asi;                /* Answer Subst. Info (for conditional answers) */

  HashStats
    abtht,		/* Asserted Basic Trie Hash Tables */
    btht,		/* Basic Trie Hash Tables */
    tstht;		/* Time Stamp Trie Hash Tables */
  
  size_t
    trieassert_alloc, trieassert_used,
    tablespace_alloc, tablespace_used,
    de_space_alloc, de_space_used,
    dl_space_alloc, dl_space_used,
    pnde_space_alloc, pnde_space_used;

  size_t num_de_blocks, num_dl_blocks, num_pnde_blocks;


  btn = node_statistics(&smTableBTN);
  btht = hash_statistics(CTXTc &smTableBTHT);
  varsf = subgoal_statistics(CTXTc &smVarSF);
  prodsf = subgoal_statistics(CTXTc &smProdSF);
  conssf = subgoal_statistics(CTXTc &smConsSF);
  aln = node_statistics(&smALN);
  tstn = node_statistics(&smTSTN);
  tstht = hash_statistics(CTXTc &smTSTHT);
  tsi = node_statistics(&smTSIN);
  tsi = node_statistics(&smTSIN);
  asi = node_statistics(&smASI);

  de_space_alloc = allocated_de_space(current_de_block_gl,&num_de_blocks);
  de_space_used = de_space_alloc - unused_de_space();
  dl_space_alloc = allocated_dl_space(current_dl_block_gl,& num_dl_blocks);
  dl_space_used = dl_space_alloc - unused_dl_space();
  pnde_space_alloc = allocated_pnde_space(current_pnde_block_gl,&num_pnde_blocks);
  pnde_space_used = pnde_space_alloc - unused_pnde_space();

  tablespace_alloc = CurrentTotalTableSpaceAlloc(btn,btht,varsf,prodsf,conssf,aln,
						 tstn,tstht,tsi,asi);
  tablespace_used =  CurrentTotalTableSpaceUsed(btn,btht,varsf,prodsf,conssf,aln,
						tstn,tstht,tsi,asi);

  tablespace_alloc = tablespace_alloc + de_space_alloc + dl_space_alloc + pnde_space_alloc;

  tablespace_used = tablespace_used + de_space_used + dl_space_used + pnde_space_used;

  abtn = node_statistics(&smAssertBTN);
  abtht = hash_statistics(CTXTc &smAssertBTHT);
  trieassert_alloc =
    NodeStats_SizeAllocNodes(abtn) + HashStats_SizeAllocTotal(abtht);
  trieassert_used =
    NodeStats_SizeUsedNodes(abtn) + HashStats_SizeUsedTotal(abtht);
  SQUASH_LINUX_COMPILER_WARN(trieassert_used) ; 

  printf("\n"
	 "Table Space Usage (excluding asserted and interned tries) \n");
  printf("  Current Total Allocation:   %12" UIntfmt"  bytes\n"
  	 "  Current Total Usage:        %12" UIntfmt" bytes\n",
	 (UInteger) (pspacesize[TABLE_SPACE]-trieassert_alloc),  
	 (UInteger) (pspacesize[TABLE_SPACE]-trieassert_alloc-(tablespace_alloc-tablespace_used)));

  // Basic Trie Stuff
  if ( NodeStats_NumBlocks(btn) > 0 || HashStats_NumBlocks(btht) > 0 || NodeStats_NumBlocks(aln) > 0) {
    printf("\n"
	   "  Basic Tries\n");
    if ( NodeStats_NumBlocks(btn) > 0) 
      print_NodeStats(btn,"Basic Trie Nodes");
    if (HashStats_NumBlocks(btht) > 0)
      print_HashStats(btht,"Basic Trie Hash Tables");
    if ( NodeStats_NumBlocks(aln) > 0) 
      print_NodeStats(aln,"Answer List Nodes (for Incomplete Variant Tables)");
  }

  // Subgoal Frames
  if (NodeStats_NumBlocks(varsf) > 0 || NodeStats_NumBlocks(prodsf) > 0 
      || NodeStats_NumBlocks(conssf) > 0) {
    printf("\n"
	   "  Subgoal Frames\n");
    if (NodeStats_NumBlocks(varsf) > 0)
      print_NodeStats(varsf,"Variant Subgoal Frames");
    if (NodeStats_NumBlocks(prodsf) > 0)
      print_NodeStats(prodsf,"Producer Subgoal Frames");
    if (NodeStats_NumBlocks(conssf) > 0)
      print_NodeStats(conssf,"Consumer Subgoal Frames");
  }

  // Subsumptive Tables
  if (NodeStats_NumBlocks(tstn) > 0 || NodeStats_NumBlocks(tsi) > 0 || HashStats_NumBlocks(tstht) > 0) {
    printf("\n"
	   "  Time Stamp Tries (for Subsumptive Tables) \n");
    if (NodeStats_NumBlocks(tstn) > 0) 
      print_NodeStats(tstn,"Time Stamp Trie Nodes");
    if (HashStats_NumBlocks(tstht) > 0) 
      print_HashStats(tstht,"Time Stamp Trie Hash Tables");
    if (NodeStats_NumBlocks(tsi) > 0) 
      print_NodeStats(tsi,"Time Stamp Trie Index Nodes");
  }

  // Conditional Answers
  if (dl_space_alloc > 0 || de_space_alloc > 0 || pnde_space_alloc > 0 
      || NodeStats_NumBlocks(asi) > 0) {
    printf("\n"
	   "  Information for Conditional Answers in Variant Tables \n");
    if (dl_space_alloc > 0) 
      print_wfs_usage(dl_space_alloc,dl_space_used,num_dl_blocks,DLS_PER_BLOCK,
		      sizeof(struct delay_list),"Delay Lists");
    if (de_space_alloc > 0) 
      print_wfs_usage(de_space_alloc,de_space_used,num_de_blocks,DES_PER_BLOCK,
		      sizeof(struct delay_element),"Delay Elements");
    if (pnde_space_alloc > 0) 
      print_wfs_usage(pnde_space_alloc,pnde_space_used,num_pnde_blocks,PNDES_PER_BLOCK,
		      sizeof(struct pos_neg_de_list),"Back-pointer Lists");
    if ( NodeStats_NumBlocks(asi) > 0)
      print_NodeStats(asi,"Answer Substitution Frames");
  }

  if (total_call_node_count_gl) {
    printf("\nTotal number of incremental subgoals created: %d\n",total_call_node_count_gl);
    printf("   Current number of incremental call nodesd: %d\n",current_call_node_count_gl);
    printf("   Total number of incremental call edges created: %d\n",current_call_edge_count_gl);
  }

  // Private trie assert space
  if ( NodeStats_NumBlocks(abtn) > 0 || HashStats_NumBlocks(abtht) > 0) {
  printf("\n ------------------ Asserted and Interned Tries  ----------------\n");
    if ( NodeStats_NumBlocks(abtn) > 0) 
      print_NodeStats(abtn,"Basic Trie Nodes (Assert)");
    if (HashStats_NumBlocks(abtht) > 0)
      print_HashStats(abtht,"Basic Trie Hash Tables (Assert)");
  }

  if (flags[MAX_USAGE]) {
    /* Report Maximum Usages
       --------------------- */
    update_maximum_tablespace_stats(&btn,&btht,&varsf,&prodsf,&conssf,
				    &aln,&tstn,&tstht,&tsi,&asi);
    printf("\n"
	   "Maximum Total Usage:        %12"UIntfmt" bytes\n",
	   maximum_total_tablespace_usage());
    printf("Maximum Structure Usage:\n"
	   "  ALNs:            %10"UIntfmt"  (%8"UIntfmt" bytes)\n"
	   "  TSINs:           %10"UIntfmt"  (%8"UIntfmt" bytes)\n",
	   maximum_answer_list_nodes(),
	   maximum_answer_list_nodes() * NodeStats_NodeSize(aln),
	   maximum_timestamp_index_nodes(),
	   maximum_timestamp_index_nodes() * NodeStats_NodeSize(tsi));
  }
  printf("\n");
}