/* *************************************************************************** * Check system activity datafile contents before displaying stats. * Display file header if option -H has been entered, else call function * corresponding to selected output format. * * IN: * @dfile System activity data file name. *************************************************************************** */ void read_stats_from_file(char dfile[]) { struct file_magic file_magic; struct file_activity *file_actlst = NULL; struct tm rectime, loctime; int ifd, ignore, tab = 0; __nr_t cpu_nr; /* Prepare file for reading and read its headers */ ignore = ACCEPT_BAD_FILE_FORMAT(fmt[f_position]->options); check_file_actlst(&ifd, dfile, act, &file_magic, &file_hdr, &file_actlst, id_seq, ignore); /* Now pick up number of proc for this file */ cpu_nr = act[get_activity_position(act, A_CPU, EXIT_IF_NOT_FOUND)]->nr; if (DISPLAY_HDR_ONLY(flags)) { if (*fmt[f_position]->f_header) { /* Display only data file header then exit */ (*fmt[f_position]->f_header)(&tab, F_BEGIN + F_END, dfile, &file_magic, &file_hdr, cpu_nr, act, id_seq); } exit(0); } /* Perform required allocations */ allocate_structures(act); /* Call function corresponding to selected output format */ if (format == F_SVG_OUTPUT) { logic3_display_loop(ifd, file_actlst, cpu_nr, &rectime, &loctime, dfile, &file_magic); } else if (DISPLAY_GROUPED_STATS(fmt[f_position]->options)) { logic2_display_loop(ifd, file_actlst, cpu_nr, &rectime, &loctime, dfile, &file_magic); } else { logic1_display_loop(ifd, file_actlst, dfile, &file_magic, cpu_nr, &rectime, &loctime); } close(ifd); free(file_actlst); free_structures(act); }
/* *************************************************************************** * Main entry to the sar program. *************************************************************************** */ int main(int argc, char **argv) { int i, rc, opt = 1, args_idx = 2; int fd[2]; int day_offset = 0; char from_file[MAX_FILE_LEN], to_file[MAX_FILE_LEN]; char ltemp[20]; /* Get HZ */ get_HZ(); /* Compute page shift in kB */ get_kb_shift(); from_file[0] = to_file[0] = '\0'; #ifdef USE_NLS /* Init National Language Support */ init_nls(); #endif tm_start.use = tm_end.use = FALSE; /* Allocate and init activity bitmaps */ allocate_bitmaps(act); init_structures(); /* Process options */ while (opt < argc) { if (!strcmp(argv[opt], "-I")) { if (argv[++opt]) { /* Parse -I option */ if (parse_sar_I_opt(argv, &opt, act)) { usage(argv[0]); } } else { usage(argv[0]); } } else if (!strcmp(argv[opt], "-D")) { /* Option to tell sar to write to saYYYYMMDD data files */ flags |= S_F_SA_YYYYMMDD; opt++; } else if (!strcmp(argv[opt], "-P")) { /* Parse -P option */ if (parse_sa_P_opt(argv, &opt, &flags, act)) { usage(argv[0]); } } else if (!strcmp(argv[opt], "-o")) { if (to_file[0]) { /* Output file already specified */ usage(argv[0]); } /* Save stats to a file */ if ((argv[++opt]) && strncmp(argv[opt], "-", 1) && (strspn(argv[opt], DIGITS) != strlen(argv[opt]))) { strncpy(to_file, argv[opt++], MAX_FILE_LEN); to_file[MAX_FILE_LEN - 1] = '\0'; } else { strcpy(to_file, "-"); } } else if (!strcmp(argv[opt], "-f")) { if (from_file[0]) { /* Input file already specified */ usage(argv[0]); } /* Read stats from a file */ if ((argv[++opt]) && strncmp(argv[opt], "-", 1) && (strspn(argv[opt], DIGITS) != strlen(argv[opt]))) { strncpy(from_file, argv[opt++], MAX_FILE_LEN); from_file[MAX_FILE_LEN - 1] = '\0'; /* Check if this is an alternate directory for sa files */ check_alt_sa_dir(from_file, day_offset, -1); } else { set_default_file(from_file, day_offset, -1); } } else if (!strcmp(argv[opt], "-s")) { /* Get time start */ if (parse_timestamp(argv, &opt, &tm_start, DEF_TMSTART)) { usage(argv[0]); } } else if (!strcmp(argv[opt], "-e")) { /* Get time end */ if (parse_timestamp(argv, &opt, &tm_end, DEF_TMEND)) { usage(argv[0]); } } else if (!strcmp(argv[opt], "-h")) { /* Display help message */ display_help(argv[0]); } else if (!strcmp(argv[opt], "-i")) { if (!argv[++opt] || (strspn(argv[opt], DIGITS) != strlen(argv[opt]))) { usage(argv[0]); } interval = atol(argv[opt++]); if (interval < 1) { usage(argv[0]); } flags |= S_F_INTERVAL_SET; } else if (!strcmp(argv[opt], "-m")) { if (argv[++opt]) { /* Parse option -m */ if (parse_sar_m_opt(argv, &opt, act)) { usage(argv[0]); } } else { usage(argv[0]); } } else if (!strcmp(argv[opt], "-n")) { if (argv[++opt]) { /* Parse option -n */ if (parse_sar_n_opt(argv, &opt, act)) { usage(argv[0]); } } else { usage(argv[0]); } } else if ((strlen(argv[opt]) > 1) && (strlen(argv[opt]) < 4) && !strncmp(argv[opt], "-", 1) && (strspn(argv[opt] + 1, DIGITS) == (strlen(argv[opt]) - 1))) { day_offset = atoi(argv[opt++] + 1); } else if (!strncmp(argv[opt], "-", 1)) { /* Other options not previously tested */ if ((rc = parse_sar_opt(argv, &opt, act, &flags, C_SAR)) != 0) { if (rc == 1) { usage(argv[0]); } exit(1); } opt++; } else if (interval < 0) { /* Get interval */ if (strspn(argv[opt], DIGITS) != strlen(argv[opt])) { usage(argv[0]); } interval = atol(argv[opt++]); if (interval < 0) { usage(argv[0]); } } else { /* Get count value */ if ((strspn(argv[opt], DIGITS) != strlen(argv[opt])) || !interval) { usage(argv[0]); } if (count) { /* Count parameter already set */ usage(argv[0]); } count = atol(argv[opt++]); if (count < 1) { usage(argv[0]); } } } /* 'sar' is equivalent to 'sar -f' */ if ((argc == 1) || ((interval < 0) && !from_file[0] && !to_file[0])) { set_default_file(from_file, day_offset, -1); } if (tm_start.use && tm_end.use && (tm_end.tm_hour < tm_start.tm_hour)) { tm_end.tm_hour += 24; } /* * Check option dependencies. */ /* You read from a file OR you write to it... */ if (from_file[0] && to_file[0]) { fprintf(stderr, _("-f and -o options are mutually exclusive\n")); exit(1); } /* Use time start or option -i only when reading stats from a file */ if ((tm_start.use || INTERVAL_SET(flags)) && !from_file[0]) { fprintf(stderr, _("Not reading from a system activity file (use -f option)\n")); exit(1); } /* Don't print stats since boot time if -o or -f options are used */ if (!interval && (from_file[0] || to_file[0])) { usage(argv[0]); } /* Cannot enter a day shift with -o option */ if (to_file[0] && day_offset) { usage(argv[0]); } if (USE_PRETTY_OPTION(flags)) { dm_major = get_devmap_major(); } if (!count) { /* * count parameter not set: Display all the contents of the file * or generate a report continuously. */ count = -1; } /* Default is CPU activity... */ select_default_activity(act); /* Reading stats from file: */ if (from_file[0]) { if (interval < 0) { interval = 1; } /* Read stats from file */ read_stats_from_file(from_file); /* Free stuctures and activity bitmaps */ free_bitmaps(act); free_structures(act); return 0; } /* Reading stats from sadc: */ /* Create anonymous pipe */ if (pipe(fd) == -1) { perror("pipe"); exit(4); } switch (fork()) { case -1: perror("fork"); exit(4); break; case 0: /* Child */ if (dup2(fd[1], STDOUT_FILENO) < 0) { perror("dup2"); exit(4); } CLOSE_ALL(fd); /* * Prepare options for sadc. */ /* Program name */ salloc(0, SADC); /* Interval value */ if (interval < 0) { usage(argv[0]); } else if (!interval) { strcpy(ltemp, "1"); } else { sprintf(ltemp, "%ld", interval); } salloc(1, ltemp); /* Count number */ if (count >= 0) { sprintf(ltemp, "%ld", count + 1); salloc(args_idx++, ltemp); } /* Flags to be passed to sadc */ salloc(args_idx++, "-z"); /* Writing data to a file (option -o) */ if (to_file[0]) { /* Set option -D if entered */ if (USE_SA_YYYYMMDD(flags)) { salloc(args_idx++, "-D"); } /* Collect all possible activities (option -S XALL for sadc) */ salloc(args_idx++, "-S"); salloc(args_idx++, K_XALL); /* Outfile arg */ salloc(args_idx++, to_file); } else { /* * If option -o hasn't been used, then tell sadc * to collect only activities that will be displayed. */ int act_id = 0; for (i = 0; i < NR_ACT; i++) { if (IS_SELECTED(act[i]->options)) { act_id |= act[i]->group; } } if (act_id) { act_id <<= 8; snprintf(ltemp, 19, "%d", act_id); ltemp[19] = '\0'; salloc(args_idx++, "-S"); salloc(args_idx++, ltemp); } } /* Last arg is NULL */ args[args_idx] = NULL; /* Call now the data collector */ execv(SADC_PATH, args); execvp(SADC, args); /* * Note: Don't use execl/execlp since we don't have a fixed number of * args to give to sadc. */ fprintf(stderr, _("Cannot find the data collector (%s)\n"), SADC); perror("exec"); exit(4); break; default: /* Parent */ if (dup2(fd[0], STDIN_FILENO) < 0) { perror("dup2"); exit(4); } CLOSE_ALL(fd); /* Get now the statistics */ read_stats(); break; } /* Free structures and activity bitmaps */ free_bitmaps(act); free_structures(act); return 0; }
int JpegToBmp() { unsigned int aux, mark; int n_restarts, restart_interval, leftover; /* RST check */ int i, j; /*No Need to do the file operation operation*/ #ifdef FILE_IO fi = fopen(file1, "rb"); if (fi == NULL) { return 0; } #else #ifdef INPUT_DMA // wait for input data to arrive //mk_mon_debug_info(0xFF); // read input file DRAM (via my cmem-out) ddr_input = (unsigned int*)(shared_pt_REMOTEADDR + 1024*1024*4); cmem_input_circ_buff = (unsigned int*) (mb1_cmemout0_BASEADDR); hw_dma_receive_addr((int*)(cmem_input_circ_buff + buff_sel * INPUT_READ_SIZE_INT), (void*)(&ddr_input[ddr_input_chunck_offset*INPUT_READ_SIZE_INT]), INPUT_READ_SIZE_INT, (void*)mb1_dma0_BASEADDR); ddr_input_chunck_offset++; buff_sel = CHANGE_BUFFER(buff_sel); for (i = 0 ; i < NUM_OF_INIT_BUFF_LOAD-1; i++) { while(hw_dma_status_addr( (void *) mb1_dma0_BASEADDR)); hw_dma_receive_addr((unsigned int*)(cmem_input_circ_buff + buff_sel * INPUT_READ_SIZE_INT), (void*)(&ddr_input[ddr_input_chunck_offset*INPUT_READ_SIZE_INT]), INPUT_READ_SIZE_INT, (void*)mb1_dma0_BASEADDR); ddr_input_chunck_offset++; buff_sel = CHANGE_BUFFER(buff_sel); } fi = (unsigned char *)(cmem_input_circ_buff); #else fi = (volatile unsigned int *)(shared_pt_REMOTEADDR+1024*1024*4); #endif #endif /* First find the SOI marker: */ aux = get_next_MK(fi); if (aux != SOI_MK) aborted_stream(fi); if (verbose) { #ifdef FILE_IO fprintf(stderr, "%ld:\tINFO:\tFound the SOI marker!\n", ftell(fi)); #else //printf("%d:\tINFO:\tFound the SOI marker!\n", FTELL()); #endif } in_frame = 0; restart_interval = 0; for (i = 0; i < 4; i++) QTvalid[i] = 0; /* Now process segments as they appear: */ do { mark = get_next_MK(fi); //mk_mon_debug_info(0XFFF); //mk_mon_debug_info(mark); //mk_mon_debug_info(bit_counter); //mk_mon_debug_info(0XFFF); switch (mark) { case SOF_MK: if (verbose) { #ifdef FILE_IO fprintf(stderr, "%ld:\tINFO:\tFound the SOF marker!\n", ftell(fi)); #else //printf("%d:\tINFO:\tFound the SOF marker!\n", FTELL()); #endif } in_frame = 1; get_size(fi); /* header size, don't care */ /* load basic image parameters */ #ifdef FILE_IO fgetc(fi); /* precision, 8bit, don't care */ #else FGETC(fi); /* precision, 8bit, don't care */ #endif y_size = get_size(fi); x_size = get_size(fi); if (verbose) { #ifdef FILE_IO fprintf(stderr, "\tINFO:\tImage size is %d by %d\n", x_size, y_size); #else //printf("\tINFO:\tImage size is %d by %d\n", x_size, y_size); #endif } #ifdef FILE_IO n_comp = fgetc(fi); /* # of components */ #else n_comp = FGETC(fi); /* # of components */ #endif if (verbose) { #ifdef FILE_IO fprintf(stderr, "\tINFO:\t"); #else //printf("\tINFO:\t"); #endif switch (n_comp) { #ifdef FILE_IO case 1: fprintf(stderr, "Monochrome"); break; case 3: fprintf(stderr, "Color"); break; default: fprintf(stderr, "Not a"); break; #else case 1: //printf("Monochrome"); break; case 3: //printf("Color"); break; default: //printf("Not a"); break; #endif } #ifdef FILE_IO fprintf(stderr, " JPEG image!\n"); #else //printf(" JPEG image!\n"); #endif } for (i = 0; i < n_comp; i++) { #ifdef FILE_IO /* component specifiers */ comp[i].CID = fgetc(fi); aux = fgetc(fi); comp[i].HS = first_quad(aux); comp[i].VS = second_quad(aux); comp[i].QT = fgetc(fi); #else /* component specifiers */ comp[i].CID = FGETC(fi); aux = FGETC(fi); comp[i].HS = first_quad(aux); comp[i].VS = second_quad(aux); comp[i].QT = FGETC(fi); #endif } if ((n_comp > 1) && verbose) { #ifdef FILE_IO fprintf(stderr, "\tINFO:\tColor format is %d:%d:%d, H=%d\n", comp[0].HS * comp[0].VS, comp[1].HS * comp[1].VS, comp[2].HS * comp[2].VS, comp[1].HS); #else #if 0 //printf("\tINFO:\tColor format is %d:%d:%d, H=%d\n", comp[0].HS * comp[0].VS, comp[1].HS * comp[1].VS, comp[2].HS * comp[2].VS, comp[1].HS); #endif #endif } if (init_MCU() == -1) aborted_stream(fi); /* dimension scan buffer for YUV->RGB conversion */ /* TODO */ #if 0 FrameBuffer = (volatile unsigned char *)mk_malloc((size_t) x_size * y_size * n_comp); #else FrameBuffer = (unsigned int *) mb1_cmemout1_BASEADDR; #endif //ColorBuffer = (volatile unsigned char *)mk_malloc((size_t) MCU_sx * MCU_sy * n_comp); #if 0 FBuff = (FBlock *) mk_malloc(sizeof(FBlock)); #else MY_MK_MALLOC(FBuff,FBlock,1); #endif #if 0 PBuff = (PBlock *) mk_malloc(sizeof(PBlock)); #else MY_MK_MALLOC(PBuff,PBlock,1); #endif if ((FrameBuffer == NULL) /*|| (ColorBuffer == NULL)*/ || (FBuff == NULL) || (PBuff == NULL)) { #ifdef FILE_IO fprintf(stderr, "\tERROR:\tCould not allocate pixel storage!\n"); #else //printf("\tERROR:\tCould not allocate pixel storage!\n"); #endif } break; case DHT_MK: if (verbose) { #ifdef FILE_IO fprintf(stderr, "%ld:\tINFO:\tDefining Huffman Tables\n", ftell(fi)); #else //printf("%d:\tINFO:\tDefining Huffman Tables\n", FTELL()); #endif } if (load_huff_tables(fi) == -1) aborted_stream(fi); break; case DQT_MK: if (verbose) { #ifdef FILE_IO fprintf(stderr, "%ld:\tINFO:\tDefining Quantization Tables\n", ftell(fi)); #else //printf("%d:\tINFO:\tDefining Quantization Tables\n", FTELL()); #endif } if (load_quant_tables(fi) == -1) aborted_stream(fi); break; case DRI_MK: get_size(fi); /* skip size */ restart_interval = get_size(fi); if (verbose) { #ifdef FILE_IO fprintf(stderr, "%ld:\tINFO:\tDefining Restart Interval %d\n", ftell(fi),restart_interval); #else //printf("%d:\tINFO:\tDefining Restart Interval %d\n", FTELL(), restart_interval); #endif } break; case SOS_MK: /* lots of things to do here */ //mk_mon_debug_info(01); //mk_mon_debug_info(bit_counter); //mk_mon_debug_info(02); if (verbose) { #ifdef FILE_IO fprintf(stderr, "%ld:\tINFO:\tFound the SOS marker!\n", ftell(fi)); #else //printf("%d:\tINFO:\tFound the SOS marker!\n", FTELL(fi)); #endif } get_size(fi); /* don't care */ #ifdef FILE_IO aux = fgetc(fi); #else aux = FGETC(fi); #endif if (aux != (unsigned int)n_comp) { #ifdef FILE_IO fprintf(stderr, "\tERROR:\tBad component interleaving!\n"); #else //printf("\tERROR:\tBad component interleaving!\n"); #endif aborted_stream(fi); } for (i = 0; i < n_comp; i++) { #ifdef FILE_IO aux = fgetc(fi); #else aux = FGETC(fi); #endif if (aux != comp[i].CID) { #ifdef FILE_IO fprintf(stderr, "\tERROR:\tBad Component Order!\n"); #else //printf("\tERROR:\tBad Component Order!\n"); #endif aborted_stream(fi); } #ifdef FILE_IO aux = fgetc(fi); #else aux = FGETC(fi); #endif comp[i].DC_HT = first_quad(aux); comp[i].AC_HT = second_quad(aux); } get_size(fi); #ifdef FILE_IO fgetc(fi); /* skip things */ #else FGETC(fi); /* skip things */ #endif MCU_column = 0; MCU_row = 0; clear_bits(); reset_prediction(); /* main MCU processing loop here */ if (restart_interval) { n_restarts = ceil_div(mx_size * my_size, restart_interval) - 1; leftover = mx_size * my_size - n_restarts * restart_interval; /* final interval may be incomplete */ for (i = 0; i < n_restarts; i++) { for (j = 0; j < restart_interval; j++) { process_MCU(fi); } /* proc till all EOB met */ aux = get_next_MK(fi); if (!RST_MK(aux)) { #ifdef FILE_IO fprintf(stderr, "%ld:\tERROR:\tLost Sync after interval!\n", ftell(fi)); #else //printf("%d:\tERROR:\tLost Sync after interval!\n", FTELL()); #endif aborted_stream(fi); } else if (verbose) { //printf("%d:\tINFO:\tFound Restart Marker\n", FTELL()); } reset_prediction(); clear_bits(); } /* intra-interval loop */ } else { leftover = mx_size * my_size; } /* process till end of row without restarts */ for (i = 0; i < leftover; i++) { process_MCU(fi); } in_frame = 0; //mk_mon_debug_info(0XFEFE); //mk_mon_debug_info(0XFEFE); break; case EOI_MK: //mk_mon_debug_info(0XDEADBEE2); if (verbose) { #ifdef FILE_IO fprintf(stderr, "%ld:\tINFO:\tFound the EOI marker!\n", ftell(fi)); #else //printf("%d:\tINFO:\tFound the EOI marker!\n", FTELL()); #endif } if (in_frame) { aborted_stream(fi); } if (verbose) { #ifdef FILE_IO fprintf(stderr, "\tINFO:\tTotal skipped bytes %d, total stuffers %d\n", passed, stuffers); #else //printf("\tINFO:\tTotal skipped bytes %d, total stuffers %d\n", passed, stuffers); #endif } #ifdef FILE_IO fclose(fi); #else /*Check if something has to be done!!*/ #endif #ifdef FILE_IO // write_bmp(file2); #else /*Need to implement the function to write in DDR*/ // write_bmp_to_ddr_1(); //printf_frame_buffer(); #endif #ifdef FILE_IO free_structures(); #else /*No Need to do anything as structures are static*/ //mk_mon_debug_info(0XDEADBEE1); //free_structures(); //mk_mon_debug_info(0XDEADBEE2); #endif /* signal to core 2 that the FIFO is initialized and can be read from. */ while(cheap_is_empty(producer) != 1) { #if 0 mk_mon_debug_info(producer->readc); mk_mon_debug_info(producer->writec); #endif } *fifo_sync_data = 0; DMA_SEND_BLOCKING((void *)fifo_sync, (int*)fifo_sync_data, sizeof(int),(void *)mb1_dma0_BASEADDR,DMA_flag); return 0; break; case COM_MK: if (verbose) { #ifdef FILE_IO fprintf(stderr, "%ld:\tINFO:\tSkipping comments\n", ftell(fi)); #else //printf("%d:\tINFO:\tSkipping comments\n", FTELL()); #endif } skip_segment(fi); break; case 0XD9: //case 0XD9: if (verbose) { #ifdef FILE_IO fprintf(stderr, "%ld:\tERROR:\tRan out of input data!\n", ftell(fi)); #else //printf("%d:\tERROR:\tRan out of input data!\n", FTELL()); #endif } aborted_stream(fi); default: if ((mark & MK_MSK) == APP_MK) { if (verbose) { #ifdef FILE_IO fprintf(stderr, "%ld:\tINFO:\tSkipping application data\n", ftell(fi)); #else //printf("%d:\tINFO:\tSkipping application data\n", FTELL()); #endif } skip_segment(fi); break; } if (RST_MK(mark)) { reset_prediction(); break; } /* if all else has failed ... */ #ifdef FILE_IO fprintf(stderr, "%ld:\tWARNING:\tLost Sync outside scan, %d!\n", ftell(fi), mark); #else //printf("%d:\tWARNING:\tLost Sync outside scan, %d!\n", FTELL(), mark); #endif aborted_stream(fi); break; } /* end switch */ } while (1); return 0; }