예제 #1
0
파일: pmap.c 프로젝트: mikess/illumos-gate
/*ARGSUSED*/
static int
look_xmap(void *data,
          const prxmap_t *pmp,
          const char *object_name,
          int last, int doswap)
{
    struct totals *t = data;
    const pstatus_t *Psp = Pstatus(Pr);
    char mname[PATH_MAX];
    char *lname = NULL;
    char *ln;

    /*
     * If the mapping is not anon or not part of the heap, make a name
     * for it.  We don't want to report the heap as a.out's data.
     */
    if (!(pmp->pr_mflags & MA_ANON) ||
            pmp->pr_vaddr + pmp->pr_size <= Psp->pr_brkbase ||
            pmp->pr_vaddr >= Psp->pr_brkbase + Psp->pr_brksize) {
        lname = make_name(Pr, lflag, pmp->pr_vaddr, pmp->pr_mapname,
                          mname, sizeof (mname));
    }

    if (lname != NULL) {
        if ((ln = strrchr(lname, '/')) != NULL)
            lname = ln + 1;
    } else if ((pmp->pr_mflags & MA_ANON) || Pstate(Pr) == PS_DEAD) {
        lname = anon_name(mname, Psp, stacks, nstacks, pmp->pr_vaddr,
                          pmp->pr_size, pmp->pr_mflags, pmp->pr_shmid, NULL);
    }

    (void) printf("%.*lX", addr_width, (ulong_t)pmp->pr_vaddr);

    printK(ROUNDUP_KB(pmp->pr_size), size_width);
    printK(pmp->pr_rss * (pmp->pr_pagesize / KILOBYTE), size_width);
    printK(ANON(pmp) * (pmp->pr_pagesize / KILOBYTE), size_width);
    printK(pmp->pr_locked * (pmp->pr_pagesize / KILOBYTE), size_width);
    (void) printf(lname ? " %4s %-6s %s\n" : " %4s %s\n",
                  pagesize(pmp), mflags(pmp->pr_mflags), lname);

    t->total_size += ROUNDUP_KB(pmp->pr_size);
    t->total_rss += pmp->pr_rss * (pmp->pr_pagesize / KILOBYTE);
    t->total_anon += ANON(pmp) * (pmp->pr_pagesize / KILOBYTE);
    t->total_locked += (pmp->pr_locked * (pmp->pr_pagesize / KILOBYTE));

    return (0);
}
예제 #2
0
파일: pmap.c 프로젝트: mikess/illumos-gate
/*ARGSUSED*/
static int
look_xmap_nopgsz(void *data,
                 const prxmap_t *pmp,
                 const char *object_name,
                 int last, int doswap)
{
    struct totals *t = data;
    const pstatus_t *Psp = Pstatus(Pr);
    char mname[PATH_MAX];
    char *lname = NULL;
    char *ln;
    static uintptr_t prev_vaddr;
    static size_t prev_size;
    static offset_t prev_offset;
    static int prev_mflags;
    static char *prev_lname;
    static char prev_mname[PATH_MAX];
    static ulong_t prev_rss;
    static ulong_t prev_anon;
    static ulong_t prev_locked;
    static ulong_t prev_swap;
    int merged = 0;
    static int first = 1;
    ulong_t swap = 0;
    int kperpage;

    /*
     * Calculate swap reservations
     */
    if (pmp->pr_mflags & MA_SHARED) {
        if (aflag && (pmp->pr_mflags & MA_NORESERVE) == 0) {
            /* Swap reserved for entire non-ism SHM */
            swap = pmp->pr_size / pmp->pr_pagesize;
        }
    } else if (pmp->pr_mflags & MA_NORESERVE) {
        /* Swap reserved on fault for each anon page */
        swap = pmp->pr_anon;
    } else if (pmp->pr_mflags & MA_WRITE) {
        /* Swap reserve for entire writable segment */
        swap = pmp->pr_size / pmp->pr_pagesize;
    }

    /*
     * If the mapping is not anon or not part of the heap, make a name
     * for it.  We don't want to report the heap as a.out's data.
     */
    if (!(pmp->pr_mflags & MA_ANON) ||
            pmp->pr_vaddr + pmp->pr_size <= Psp->pr_brkbase ||
            pmp->pr_vaddr >= Psp->pr_brkbase + Psp->pr_brksize) {
        lname = make_name(Pr, lflag, pmp->pr_vaddr, pmp->pr_mapname,
                          mname, sizeof (mname));
    }

    if (lname != NULL) {
        if ((ln = strrchr(lname, '/')) != NULL)
            lname = ln + 1;
    } else if ((pmp->pr_mflags & MA_ANON) || Pstate(Pr) == PS_DEAD) {
        lname = anon_name(mname, Psp, stacks, nstacks, pmp->pr_vaddr,
                          pmp->pr_size, pmp->pr_mflags, pmp->pr_shmid, NULL);
    }

    kperpage = pmp->pr_pagesize / KILOBYTE;

    t->total_size += ROUNDUP_KB(pmp->pr_size);
    t->total_rss += pmp->pr_rss * kperpage;
    t->total_anon += ANON(pmp) * kperpage;
    t->total_locked += pmp->pr_locked * kperpage;
    t->total_swap += swap * kperpage;

    if (first == 1) {
        first = 0;
        prev_vaddr = pmp->pr_vaddr;
        prev_size = pmp->pr_size;
        prev_offset = pmp->pr_offset;
        prev_mflags = pmp->pr_mflags;
        if (lname == NULL) {
            prev_lname = NULL;
        } else {
            (void) strcpy(prev_mname, lname);
            prev_lname = prev_mname;
        }
        prev_rss = pmp->pr_rss * kperpage;
        prev_anon = ANON(pmp) * kperpage;
        prev_locked = pmp->pr_locked * kperpage;
        prev_swap = swap * kperpage;
        if (last == 0) {
            return (0);
        }
        merged = 1;
    } else if (prev_vaddr + prev_size == pmp->pr_vaddr &&
               prev_mflags == pmp->pr_mflags &&
               ((prev_mflags & MA_ISM) ||
                prev_offset + prev_size == pmp->pr_offset) &&
               ((lname == NULL && prev_lname == NULL) ||
                (lname != NULL && prev_lname != NULL &&
                 strcmp(lname, prev_lname) == 0))) {
        prev_size += pmp->pr_size;
        prev_rss += pmp->pr_rss * kperpage;
        prev_anon += ANON(pmp) * kperpage;
        prev_locked += pmp->pr_locked * kperpage;
        prev_swap += swap * kperpage;
        if (last == 0) {
            return (0);
        }
        merged = 1;
    }

    (void) printf("%.*lX", addr_width, (ulong_t)prev_vaddr);
    printK(ROUNDUP_KB(prev_size), size_width);

    if (doswap)
        printK(prev_swap, size_width);
    else {
        printK(prev_rss, size_width);
        printK(prev_anon, size_width);
        printK(prev_locked, size_width);
    }
    (void) printf(prev_lname ? " %-6s %s\n" : "%s\n",
                  mflags(prev_mflags), prev_lname);

    if (last == 0) {
        prev_vaddr = pmp->pr_vaddr;
        prev_size = pmp->pr_size;
        prev_offset = pmp->pr_offset;
        prev_mflags = pmp->pr_mflags;
        if (lname == NULL) {
            prev_lname = NULL;
        } else {
            (void) strcpy(prev_mname, lname);
            prev_lname = prev_mname;
        }
        prev_rss = pmp->pr_rss * kperpage;
        prev_anon = ANON(pmp) * kperpage;
        prev_locked = pmp->pr_locked * kperpage;
        prev_swap = swap * kperpage;
    } else if (merged == 0) {
        (void) printf("%.*lX", addr_width, (ulong_t)pmp->pr_vaddr);
        printK(ROUNDUP_KB(pmp->pr_size), size_width);
        if (doswap)
            printK(swap * kperpage, size_width);
        else {
            printK(pmp->pr_rss * kperpage, size_width);
            printK(ANON(pmp) * kperpage, size_width);
            printK(pmp->pr_locked * kperpage, size_width);
        }
        (void) printf(lname ? " %-6s %s\n" : " %s\n",
                      mflags(pmp->pr_mflags), lname);
    }

    if (last != 0)
        first = 1;

    return (0);
}
예제 #3
0
파일: main.c 프로젝트: enukane/netbsd-src
/* control multiple files */
int
main(int argc, char *argv[])
{
	int ch;

#ifdef TIMING
	struct timeval t1, t2;

	(void)gettimeofday(&t1, NULL);
#endif

	prgname = argv[0];

	while ((ch = getopt(argc, argv, "OT:VW:X:Z:f:gkm:psvwx:")) != -1) {
		switch (ch) {
#if !defined(MULTIPASS) || defined(PASS1)
		case 'X':	/* pass1 debugging */
			while (*optarg)
				switch (*optarg++) {
				case 'b': ++bdebug; break; /* buildtree */
				case 'd': ++ddebug; break; /* declarations */
				case 'e': ++edebug; break; /* pass1 exit */
				case 'i': ++idebug; break; /* initializations */
				case 'n': ++ndebug; break; /* node allocation */
				case 'o': ++odebug; break; /* optim */
				case 'p': ++pdebug; break; /* prototype */
				case 's': ++sdebug; break; /* inline */
				case 't': ++tdebug; break; /* type match */
				case 'x': ++xdebug; break; /* MD code */
				default:
					fprintf(stderr, "unknown -X flag '%c'\n",
					    optarg[-1]);
					exit(1);
				}
			break;
#endif
#if !defined(MULTIPASS) || defined(PASS2)
		case 'Z':	/* pass2 debugging */
			while (*optarg)
				switch (*optarg++) {
				case 'b': /* basic block and SSA building */
					++b2debug;
					break;
				case 'c': /* code printout */
					++c2debug;
					break;
				case 'e': /* print tree upon pass2 enter */
					++e2debug;
					break;
				case 'f': /* instruction matching */
					++f2debug;
					break;
				case 'g': /* print flow graphs */
					++g2debug;
					break;
				case 'n': /* node allocation */
					++ndebug;
					break;
				case 'o': /* instruction generator */
					++o2debug;
					break;
				case 'r': /* register alloc/graph coloring */
					++r2debug;
					break;
				case 's': /* shape matching */
					++s2debug;
					break;
				case 't': /* type matching */
					++t2debug;
					break;
				case 'u': /* Sethi-Ullman debugging */
					++u2debug;
					break;
				case 'x': /* target specific */
					++x2debug;
					break;
				default:
					fprintf(stderr, "unknown -Z flag '%c'\n",
					    optarg[-1]);
					exit(1);
				}
			break;
#endif
		case 'f': /* Language */
			fflags(optarg);
			break;

		case 'g': /* Debugging */
			++gflag;
			break;

		case 'k': /* PIC code */
			++kflag;
			break;

		case 'm': /* Target-specific */
			mflags(optarg);
			break;

		case 'p': /* Profiling */
			++pflag;
			break;

		case 's': /* Statistics */
			++sflag;
			break;

		case 'W': /* Enable different warnings */
			Wflags(optarg);
			break;

		case 'x': /* Different settings */
			xopt(optarg);
			break;

		case 'v':
			printf("ccom: %s\n", VERSSTR);
			break;

		case '?':
		default:
			usage();
		}
	}
	argc -= optind;
	argv += optind;

	if (argc > 0 && strcmp(argv[0], "-") != 0) {
		if (freopen(argv[0], "r", stdin) == NULL) {
			fprintf(stderr, "open input file '%s':",
			    argv[0]);
			perror(NULL);
			exit(1);
		}
	}
	if (argc > 1 && strcmp(argv[1], "-") != 0) {
		if (freopen(argv[1], "w", stdout) == NULL) {
			fprintf(stderr, "open output file '%s':",
			    argv[1]);
			perror(NULL);
			exit(1);
		}
	}

	mkdope();
	signal(SIGSEGV, segvcatch);
#ifdef SIGBUS
	signal(SIGBUS, segvcatch);
#endif
	fregs = FREGS;	/* number of free registers */
	lineno = 1;
#ifdef GCC_COMPAT
	gcc_init();
#endif

	/* starts past any of the above */
	reached = 1;

	bjobcode();
#ifndef TARGET_VALIST
	{
		NODE *p = block(NAME, NIL, NIL, PTR|CHAR, NULL, 0);
		struct symtab *sp = lookup(addname("__builtin_va_list"), 0);
		p->n_sp = sp;
		defid(p, TYPEDEF);
		nfree(p);
	}
#endif
	complinit();

#ifdef STABS
	if (gflag) {
		stabs_file(argc ? argv[0] : "");
		stabs_init();
	}
#endif

	if (sspflag)
		sspinit();

	(void) yyparse();
	yyaccpt();

	if (!nerrors)
		lcommprint();

#ifdef STABS
	if (gflag)
		stabs_efile(argc ? argv[0] : "");
#endif

	ejobcode( nerrors ? 1 : 0 );

#ifdef TIMING
	(void)gettimeofday(&t2, NULL);
	t2.tv_sec -= t1.tv_sec;
	t2.tv_usec -= t1.tv_usec;
	if (t2.tv_usec < 0) {
		t2.tv_usec += 1000000;
		t2.tv_sec -= 1;
	}
	fprintf(stderr, "ccom total time: %ld s %ld us\n",
	    t2.tv_sec, t2.tv_usec);
#endif

	if (sflag)
		prtstats();

	return(nerrors?1:0);
}
예제 #4
0
파일: pmap.c 프로젝트: mikess/illumos-gate
/*ARGSUSED*/
static int
look_smap(void *data,
          const prxmap_t *pmp,
          const char *object_name,
          int last, int doswap)
{
    struct totals *t = data;
    const pstatus_t *Psp = Pstatus(Pr);
    size_t size;
    char mname[PATH_MAX];
    char *lname = NULL;
    const char *format;
    size_t	psz = pmp->pr_pagesize;
    uintptr_t vaddr = pmp->pr_vaddr;
    uintptr_t segment_end = vaddr + pmp->pr_size;
    lgrp_id_t lgrp;
    memory_chunk_t mchunk;

    /*
     * If the mapping is not anon or not part of the heap, make a name
     * for it.  We don't want to report the heap as a.out's data.
     */
    if (!(pmp->pr_mflags & MA_ANON) ||
            pmp->pr_vaddr + pmp->pr_size <= Psp->pr_brkbase ||
            pmp->pr_vaddr >= Psp->pr_brkbase + Psp->pr_brksize) {
        lname = make_name(Pr, lflag, pmp->pr_vaddr, pmp->pr_mapname,
                          mname, sizeof (mname));
    }

    if (lname == NULL &&
            ((pmp->pr_mflags & MA_ANON) || Pstate(Pr) == PS_DEAD)) {
        lname = anon_name(mname, Psp, stacks, nstacks, pmp->pr_vaddr,
                          pmp->pr_size, pmp->pr_mflags, pmp->pr_shmid, NULL);
    }

    /*
     * Adjust the address range if -A is specified.
     */
    size = adjust_addr_range(pmp->pr_vaddr, segment_end, psz,
                             &vaddr, &segment_end);

    if (size == 0)
        return (0);

    if (!Lflag) {
        /*
         * Display the whole mapping
         */
        if (lname != NULL)
            format = "%.*lX %*luK %4s %-6s %s\n";
        else
            format = "%.*lX %*luK %4s %s\n";

        size = ROUNDUP_KB(size);

        (void) printf(format, addr_width, vaddr, size_width - 1, size,
                      pagesize(pmp), mflags(pmp->pr_mflags), lname);

        t->total_size += size;
        return (0);
    }

    if (lname != NULL)
        format = "%.*lX %*luK %4s %-6s%s %s\n";
    else
        format = "%.*lX %*luK %4s%s %s\n";

    /*
     * We need to display lgroups backing physical memory, so we break the
     * segment into individual pages and coalesce pages with the same lgroup
     * into one "segment".
     */

    /*
     * Initialize address descriptions for the mapping.
     */
    mem_chunk_init(&mchunk, segment_end, psz);
    size = 0;

    /*
     * Walk mapping (page by page) and display contiguous ranges of memory
     * allocated to same lgroup.
     */
    do {
        size_t		size_contig;

        /*
         * Get contiguous region of memory starting from vaddr allocated
         * from the same lgroup.
         */
        size_contig = get_contiguous_region(&mchunk, vaddr,
                                            segment_end, pmp->pr_pagesize, &lgrp);

        (void) printf(format, addr_width, vaddr,
                      size_width - 1, size_contig / KILOBYTE,
                      pagesize(pmp), mflags(pmp->pr_mflags),
                      lgrp2str(lgrp), lname);

        vaddr += size_contig;
        size += size_contig;
    } while (vaddr < segment_end && !interrupt);

    t->total_size += ROUNDUP_KB(size);
    return (0);
}
예제 #5
0
/* control multiple files */
int
main(int argc, char *argv[])
{

	int ch;

	prgname = argv[0];

	while ((ch = getopt(argc, argv, "OT:VW:X:Z:f:gklm:psvwx:")) != -1)
		switch (ch) {
#if !defined(MULTIPASS) || defined(PASS1)
		case 'X':
			while (*optarg)
				switch (*optarg++) {
				case 'd': ++ddebug; break; /* declarations */
				case 'i': ++idebug; break; /* initializations */
				case 'b': ++bdebug; break;
				case 't': ++tdebug; break;
				case 'e': ++edebug; break; /* pass1 exit */
				case 'x': ++xdebug; break; /* MD code */
				case 's': ++sdebug; break;
				case 'n': ++nflag; break;
				case 'o': ++oflag; break;
				case 'p': ++pdebug; break; /* prototype */
				default:
					fprintf(stderr, "unknown X flag '%c'\n",
					    optarg[-1]);
					exit(1);
				}
#endif
			break;
#if !defined(MULTIPASS) || defined(PASST)
		case 'T':
			while (*optarg)
				switch (*optarg++) {
				case 'i': ++iTflag; break;
				case 'o': ++oTflag; break;
				case 'n': ++nflag; break;
				default:
					fprintf(stderr, "unknown T flag '%c'\n",
					    optarg[-1]);
					exit(1);
				}
#endif
			break;
#if !defined(MULTIPASS) || defined(PASS2)
		case 'Z':
			while (*optarg)
				switch (*optarg++) {
				case 'f': /* instruction matching */
					++f2debug;
					break;
				case 'e': /* print tree upon pass2 enter */
					++e2debug;
					break;
				case 'o': ++odebug; break;
				case 'r': /* register alloc/graph coloring */
					++rdebug;
					break;
				case 'b': /* basic block and SSA building */
					++b2debug;
					break;
				case 'c': /* code printout */
					++c2debug;
					break;
				case 't': ++t2debug; break;
				case 's': /* shape matching */
					++s2debug;
					break;
				case 'u': /* Sethi-Ullman debugging */
					++udebug;
					break;
				case 'x': ++x2debug; break;
				case 'n': ++nflag; break;
				default:
					fprintf(stderr, "unknown Z flag '%c'\n",
					    optarg[-1]);
					exit(1);
				}
#endif
			break;

		case 'f': /* Language */
			fflags(optarg);
			break;

		case 'g': /* Debugging */
			gflag = 1;
			break;

		case 'k': /* PIC code */
			++kflag;
			break;

		case 'l': /* Linenos */
			++lflag;
			break;

		case 'm': /* Target-specific */
			mflags(optarg);
			break;

		case 'p': /* Profiling */
			pflag = 1;
			break;

		case 's': /* Statistics */
			++sflag;
			break;

		case 'W': /* Enable different warnings */
			Wflags(optarg);
			break;

		case 'x': /* Different optimizations */
			if (strcmp(optarg, "ssa") == 0)
				xssaflag++;
			else if (strcmp(optarg, "tailcall") == 0)
				xtailcallflag++;
			else if (strcmp(optarg, "temps") == 0)
				xtemps++;
			else if (strcmp(optarg, "deljumps") == 0)
				xdeljumps++;
			else
				usage();
			break;
		case 'v':
			printf("ccom: %s\n", VERSSTR);
			break;

		case '?':
		default:
			usage();
		}
		argc -= optind;
		argv += optind;

		if (argc > 0 && strcmp(argv[0], "-") != 0) {
			if (freopen(argv[0], "r", stdin) == NULL) {
				fprintf(stderr, "open input file '%s':",
				    argv[0]);
				perror(NULL);
				exit(1);
			}
		}
		if (argc > 1 && strcmp(argv[1], "-") != 0) {
			if (freopen(argv[1], "w", stdout) == NULL) {
				fprintf(stderr, "open output file '%s':",
				    argv[1]);
				perror(NULL);
				exit(1);
			}
		}

	mkdope();
	signal(SIGSEGV, segvcatch);
	fregs = FREGS;	/* number of free registers */
	lineno = 1;
#ifdef GCC_COMPAT
	gcc_init();
#endif

	/* dimension table initialization */

	btdims[VOID].suesize = 0;
	btdims[BOOL].suesize = SZBOOL;
	btdims[CHAR].suesize = SZCHAR;
	btdims[INT].suesize = SZINT;
	btdims[FLOAT].suesize = SZFLOAT;
	btdims[DOUBLE].suesize = SZDOUBLE;
	btdims[LDOUBLE].suesize = SZLDOUBLE;
	btdims[LONG].suesize = SZLONG;
	btdims[LONGLONG].suesize = SZLONGLONG;
	btdims[SHORT].suesize = SZSHORT;
	btdims[UCHAR].suesize = SZCHAR;
	btdims[USHORT].suesize = SZSHORT;
	btdims[UNSIGNED].suesize = SZINT;
	btdims[ULONG].suesize = SZLONG;
	btdims[ULONGLONG].suesize = SZLONGLONG;
	btdims[FCOMPLEX].suesize = SZFLOAT * 2;
	btdims[COMPLEX].suesize = SZDOUBLE * 2;
	btdims[LCOMPLEX].suesize = SZLDOUBLE * 2;
	/* starts past any of the above */
	reached = 1;

	bjobcode();

#ifdef STABS
	if (gflag) {
		stabs_file(argc ? argv[0] : "");
		stabs_init();
	}
#endif

	if (sspflag)
		sspinit();

	(void) yyparse();
	yyaccpt();

	if (!nerrors)
		lcommprint();

	ejobcode( nerrors ? 1 : 0 );

	if (sflag)
		prtstats();
	return(nerrors?1:0);

}