Ejemplo n.º 1
0
    void print() {
      std::map<int, double> totals;
      std::cerr << "Timings: " << std::endl;
      // print out all the entries.

      //std::sort(root_entries.begin(), root_entries.end(), cmp());

      printEntries(std::cerr, root_entries, "   ", -1.0);

      for (EntryList::const_iterator it = entries.begin(); it != entries.end(); ++it) {
        totals[(*it).id] += (*it).time;
      }

      std::cerr << std::endl;
      std::cerr << "Totals: " << std::endl;

      std::vector<std::pair<int, double> > sorted_totals;
      sorted_totals.reserve(totals.size());
      for (std::map<int,double>::iterator it = totals.begin(); it != totals.end(); ++it) {
        sorted_totals.push_back(*it);
      }

      std::sort(sorted_totals.begin(), sorted_totals.end(), cmp());

      for (std::vector<std::pair<int,double> >::iterator it = sorted_totals.begin(); it != sorted_totals.end(); ++it) {
        std::cerr << "  ";
        std::string str = names[it->first];
        if (str.empty()) {
          std::cerr << "(" << it->first << ")";
        } else {
          std::cerr << str;
        }
        std::cerr << " - " << it->second << "s " << std::endl;
      }
    }
Ejemplo n.º 2
0
  void printEntries(std::ostream& o, const std::vector<Entry*>& entries,
                    const std::string& indent, double parent_time) {
    if (parent_time <= 0.0) {
      parent_time = 0.0;
      for (size_t i = 0; i < entries.size(); ++i) {
        parent_time += entries[i]->time;
      }
    }
    double t_tot = 0.0;
    for (size_t i = 0; i < entries.size(); ++i) {
      const Entry* entry = entries[i];

      std::ostringstream r;
      r << indent;
      std::string str = names[entry->id];
      if (str.empty()) {
        r << "(" << entry->id << ")";
      } else {
        r << str;
      }
      r << " ";
      std::string pad(r.str().size(), ' ');
      r << " - exectime: " << entry->time << "s ("
        << (entry->time * 100.0 / parent_time) << "%)" << std::endl;
      if (entry->allocTotal || entry->memoryDiff) {
        r << pad << " - alloc: " << formatMemory(entry->allocTotal)
          << " delta: " << formatMemory(entry->memoryDiff) << std::endl;
        r << pad << " - alloc blks:";
        for (int i = 0; i < 32; i++) {
          if (entry->delta_blk_cnt_total[i])
            r << ' ' << ((1 << (i - 1)) + 1) << '-' << (1 << i) << ':'
              << entry->delta_blk_cnt_total[i];
        }
        r << std::endl;
        r << pad << " - delta blks:";
        for (int i = 0; i < 32; i++) {
          if (entry->delta_blk_cnt_curr[i])
            r << ' ' << ((1 << (i - 1)) + 1) << '-' << (1 << i) << ':'
              << entry->delta_blk_cnt_curr[i];
        }
        r << std::endl;
      }
      o << r.str();
      t_tot += entry->time;
      if (entry->children.size())
        printEntries(o, entry->children, indent + "   ", entry->time);
    }
    if (t_tot < parent_time) {
      o << indent << "*** unaccounted: " << (parent_time - t_tot) << "s   ("
        << (100.0 - t_tot * 100.0 / parent_time) << "%)" << std::endl;
    }
  }
Ejemplo n.º 3
0
/*----------Edit phone book entries----------*/
int editEntries() {

	int iSelect = 0;
	int iCount = 0;

	char lName_2[20] = {0};
	char fName_2[20] = {0};
	char number_2[20] = {0};

	char cStoreRecord[70] = {0};

	FILE *pRead;
	FILE *pWriteTemp;
	pRead = fopen("phone_book.dat", "r");
	pWriteTemp = fopen("temp.dat", "a");
	
	system("clear");
	printEntries();

	printf("\n\nWhich entry would you like to change?");
	printf("\nEdit nr ---> ");
	scanf("%d", &iSelect);

	printf("\nEnter first name: ");
	scanf("%s", fName_2);
	printf("\nEnter last name: ");
	scanf("%s", lName_2);
	printf("\nEnter phone number: ");
	scanf("%s", number_2);

	if ( pWriteTemp != NULL || pRead != NULL) {
		while( !feof(pRead) ) {
			if (iCount == iSelect) {
				fprintf(pWriteTemp, "%s %s %s\n", fName_2, lName_2, number_2);
			}
			else
				fprintf(pWriteTemp, "%s", cStoreRecord);
			iCount += 1;
			fgets(cStoreRecord, 70, pRead);
		}
	}
	else{
		fclose(pRead);
		fclose(pWriteTemp);
		return -1; //there is a file i/o error
	}
	fclose(pRead);
	fclose(pWriteTemp);
	remove("phone_book.dat");
	rename("temp.dat","phone_book.dat");
}
Ejemplo n.º 4
0
int main() {
    // faili lugemine
    FILE *inputFile = fopen(I_FILENAME, "r");
    
    if (inputFile == NULL) {
        printf("Faili avamine ebaõnnestus\n");
        return 0;
    }
    
    int lines = countlines(inputFile) - 1; // loeme read üle, selleks et teada massiivi suurust
    if (DEBUG) printf("Ridade arv: %d\n", lines);
       
    Isik vanemad[lines]; // loeme sisendfailist
    Isik llvanemad[lines]; // lastelastega vanemad
    
    rewind(inputFile); // resetib faili pointer tagasi algusesse. Alternatiiv oleks fail uuesti avada.
    fileInput(inputFile, vanemad);
    fclose(inputFile);

    // väljastame testimiseks
    if (DEBUG) {
       printf("\nLapsed:\n");
       printEntries(vanemad, lines);
    }
    // leiame lapselapsed
    findGrandChildren(vanemad, llvanemad, lines);
    
    // väljastame testimiseks
    if (DEBUG) {
       printf("\n=====================\n");
       printf("\nLapselapsed:\n");
       printEntries(llvanemad, lines);
    }
    
    // TODO: faili kirjutamine
    
    return 0;
}
Ejemplo n.º 5
0
main() {
	int response;
	signed int iStatus = 0;

	FILE *pWrite;
	FILE *pRead;
	
	do{
		printf("\n\tPhone Book\n");
		printf("\n1\tAdd phone book entry\n");
		printf("2\tPrint phone book\n");
		printf("3\tEdit phone book\n");
		printf("4\tDelete entry in phone book\n");
		printf("5\tExit\n\n");
		printf("Select an option: ");
		scanf("%d", &response);

		if ( response == 1 ) {
			addEntry();
		}		
		else if ( response == 2 ) {
			printEntries();
		}
		else if ( response == 3 ) {
			editEntries();
		}
		else if ( response == 4 ) {
			deleteEntries();
		}
		else if (iStatus == -1 ) {
			goto ErrorHandler;
		}
	}while(response != 5);
	system("clear");
	exit(EXIT_SUCCESS); //exit program normally

	ErrorHandler:
		perror("The following error occurred");
		exit(EXIT_FAILURE); //exit program with error
} //end main
Ejemplo n.º 6
0
void readEntryPosition(int position)
{

	pREGISTRO pRegistro;
	pRegistro = (pREGISTRO) malloc(sizeof(Registro));
	/* (pData)->data = (pPARTIDA) malloc(sizeof(PARTIDA)); */

	FILE** ppFile;
	ppFile = (FILE**) malloc(sizeof(FILE*));

	Registro registro;
	/* testeD.data = (pPARTIDA) malloc(sizeof(PARTIDA)); */
	/* printEntries((&testeD)); */
	openFile(ppFile,"r+b");
	fDataReadPosition((*ppFile),&registro,position);
	printEntries((&registro));
	closeFile(ppFile);

	/* free((pData)->data); */
	free((pRegistro));
	free(ppFile);
}
Ejemplo n.º 7
0
/*----------Delete phone book entries----------*/
int deleteEntries() {
	
	int iSelect = 0;
	int iCount = 0;

	char cStoreRecord[70] = {0};

	FILE *pRead;
	FILE *pWriteTemp;
	pRead = fopen("phone_book.dat", "r");
	pWriteTemp = fopen("temp.dat", "a");
	
	system("clear");
	printEntries();

	printf("\n\nWhich entry would you like to delete?");
	printf("\nDelete nr ---> ");
	scanf("%d", &iSelect);

	if ( pWriteTemp != NULL || pRead != NULL) {
		while( !feof(pRead) ) {
			if (iCount != iSelect)
				fprintf(pWriteTemp, "%s", cStoreRecord);
			iCount += 1;
			fgets(cStoreRecord, 70, pRead);
		}
	}
	else{
		fclose(pRead);
		fclose(pWriteTemp);
		return -1; //there is a file i/o error
	}
	fclose(pRead);
	fclose(pWriteTemp);
	remove("phone_book.dat");
	rename("temp.dat","phone_book.dat");
}
Ejemplo n.º 8
0
int main (void)
{   
    void printEntries(struct entry *list_start);
    void printEntriesReverse(struct entry *list_start);
    struct entry *findEntry (struct entry *list_pointer, int match);
    void insertEntry (struct entry *insert_position, struct entry *new_entry);
    void removeEntry(struct entry *entry_to_remove);

    struct entry n1, n2, n3, n4, list_head, new_entry, *insert_position, *entry_to_remove;
    int new_value, insertion_place, value_remove;

    list_head.next = &n1;

    n1.value = 100;
    n1.next = &n2;
    n1.previous = (struct entry *) 0;
    
    n2.value = 200;
    n2.next = &n3;
    n2.previous = &n1;

    n3.value = 300;
    n3.next = &n4;
    n3.previous = &n2;

    n4.value = 400;
    n4.next = (struct entry *) 0;;
    n4.previous = &n3;

    // print entries
    printEntries(&n1);

    // print entries reverse
    printEntriesReverse(&n4);

    // Getting the new value
    printf("Which value to add? ");
    scanf("%i", &new_value);
    new_entry.value = new_value;

    // Getting the insertion location pointer
    printf("After which value to add it? ");
    scanf("%i", &insertion_place);
    insert_position = findEntry(&n1, insertion_place);

    //Inserting the value in the list
    insertEntry(insert_position, &new_entry);

    // printing list
    printEntries(&n1);

    // print entries reverse
    printEntriesReverse(&n4);

    // Selecting a value to remove
    printf("After which value to remove an entry? ");
    scanf("%i", &value_remove);
    entry_to_remove = findEntry(&n1, value_remove);

    // Removing the entry
    removeEntry(entry_to_remove);

    // printing list
    printEntries(&n1);
    printEntriesReverse(&n4);

    return 0;
}
Ejemplo n.º 9
0
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *
 *   MAIN
 */
int
main(int argc, char ** argv)
{
    FILE* outFp;

    optionProcess(&getdefsOptions, argc, argv);
    validateOptions();

    outFp = startAutogen();

    doPreamble(outFp);

    /*
     *  Process each input file
     */
    {
        int    ct  = STACKCT_OPT(INPUT);
        char const ** ppz = STACKLST_OPT(INPUT);

        do  {
            processFile(*ppz++);
        } while (--ct > 0);
    }

    /*
     *  IF we don't have an ordering file, but we do have a "first index",
     *  THEN alphabetize by definition name.
     */
    if ((pzIndexText == NULL) && HAVE_OPT(FIRST_INDEX)) {
        qsort((void*)papzBlocks, blkUseCt, sizeof(char*), compar_defname);
        set_first_idx();
    }

    else if (ENABLED_OPT(ORDERING) && (blkUseCt > 1))
        qsort((void*)papzBlocks, blkUseCt, sizeof(char*), &compar_text);

    printEntries(outFp);
    fclose(outFp);

    /*
     *  IF output is to a file
     *  THEN set the permissions and modification times
     */
    if (  (WHICH_IDX_AUTOGEN == INDEX_OPT_OUTPUT)
       && (outFp != stdout) )  {
        struct utimbuf tbuf;
        tbuf.actime  = time((time_t*)NULL);
        tbuf.modtime = modtime + 1;
        utime(OPT_ARG(OUTPUT), &tbuf);
        chmod(OPT_ARG(OUTPUT), S_IRUSR|S_IRGRP|S_IROTH);
    }

    /*
     *  IF we are keeping a database of indexes
     *     AND we have augmented the contents,
     *  THEN append the new entries to the file.
     */
    if ((pzIndexText != NULL) && (pzEndIndex != pzIndexEOF))
        updateDatabase();

    if (agPid != -1)
        return awaitAutogen();

    return EXIT_SUCCESS;
}