void printKevin(int x, int y) { printK(x,y); printE(x+4*SIZE+GAP,y); printV(x+7*SIZE+2*GAP,y); printI(x+11*SIZE+3*GAP,y); printN(x+12*SIZE+4*GAP,y); }
/*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); }
static int __init test_module_init(void) { printJ(); printH(); printK(); return 0; }
int main() { int n; int N, M, K; //初始化Matrix数组用于查询。 SetNumMatrix(15, 15); int maxNum, tmp; scanf("%d", &n); for(int i = 0; i < n; i++){ scanf("%d %d %d", &N, &M, &K); printK(N, M, K); } return 0; }
/*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); }
int main(int argc, char **argv) { int rflag = 0, sflag = 0, xflag = 0, Fflag = 0; int errflg = 0, Sflag = 0; int rc = 0; int opt; const char *bar8 = "-------"; const char *bar16 = "----------"; const char *bar; struct rlimit rlim; struct stat64 statbuf; char buf[128]; int mapfd; int prg_gflags = PGRAB_RDONLY; int prr_flags = 0; boolean_t use_agent_lwp = B_FALSE; if ((command = strrchr(argv[0], '/')) != NULL) command++; else command = argv[0]; while ((opt = getopt(argc, argv, "arsxSlLFA:")) != EOF) { switch (opt) { case 'a': /* include shared mappings in -[xS] */ aflag = 1; break; case 'r': /* show reserved mappings */ rflag = 1; break; case 's': /* show hardware page sizes */ sflag = 1; break; case 'S': /* show swap reservations */ Sflag = 1; break; case 'x': /* show extended mappings */ xflag = 1; break; case 'l': /* show unresolved link map names */ lflag = 1; break; case 'L': /* show lgroup information */ Lflag = 1; use_agent_lwp = B_TRUE; break; case 'F': /* force grabbing (no O_EXCL) */ Fflag = PGRAB_FORCE; break; case 'A': if (parse_addr_range(optarg, &start_addr, &end_addr) != 0) errflg++; break; default: errflg = 1; break; } } argc -= optind; argv += optind; if ((Sflag && (xflag || rflag || sflag)) || (xflag && rflag) || (aflag && (!xflag && !Sflag)) || (Lflag && (xflag || Sflag))) { errflg = 1; } if (errflg || argc <= 0) { (void) fprintf(stderr, "usage:\t%s [-rslF] [-A start[,end]] { pid | core } ...\n", command); (void) fprintf(stderr, "\t\t(report process address maps)\n"); (void) fprintf(stderr, "\t%s -L [-rslF] [-A start[,end]] pid ...\n", command); (void) fprintf(stderr, "\t\t(report process address maps lgroups mappings)\n"); (void) fprintf(stderr, "\t%s -x [-aslF] [-A start[,end]] pid ...\n", command); (void) fprintf(stderr, "\t\t(show resident/anon/locked mapping details)\n"); (void) fprintf(stderr, "\t%s -S [-alF] [-A start[,end]] { pid | core } ...\n", command); (void) fprintf(stderr, "\t\t(show swap reservations)\n\n"); (void) fprintf(stderr, "\t-a: include shared mappings in -[xS] summary\n"); (void) fprintf(stderr, "\t-r: show reserved address maps\n"); (void) fprintf(stderr, "\t-s: show hardware page sizes\n"); (void) fprintf(stderr, "\t-l: show unresolved dynamic linker map names\n"); (void) fprintf(stderr, "\t-F: force grabbing of the target process\n"); (void) fprintf(stderr, "\t-L: show lgroup mappings\n"); (void) fprintf(stderr, "\t-A start,end: limit output to the specified range\n"); return (2); } /* * Make sure we'll have enough file descriptors to handle a target * that has many many mappings. */ if (getrlimit(RLIMIT_NOFILE, &rlim) == 0) { rlim.rlim_cur = rlim.rlim_max; (void) setrlimit(RLIMIT_NOFILE, &rlim); (void) enable_extended_FILE_stdio(-1, -1); } /* * The implementation of -L option creates an agent LWP in the target * process address space. The agent LWP issues meminfo(2) system calls * on behalf of the target process. If we are interrupted prematurely, * the target process remains in the stopped state with the agent still * attached to it. To prevent such situation we catch signals from * terminal and terminate gracefully. */ if (use_agent_lwp) { /* * Buffer output to stdout, stderr while process is grabbed. * Prevents infamous deadlocks due to pmap `pgrep xterm` and * other variants. */ (void) proc_initstdio(); prg_gflags = PGRAB_RETAIN | Fflag; prr_flags = PRELEASE_RETAIN; if (sigset(SIGHUP, SIG_IGN) == SIG_DFL) (void) sigset(SIGHUP, intr); if (sigset(SIGINT, SIG_IGN) == SIG_DFL) (void) sigset(SIGINT, intr); if (sigset(SIGQUIT, SIG_IGN) == SIG_DFL) (void) sigset(SIGQUIT, intr); (void) sigset(SIGPIPE, intr); (void) sigset(SIGTERM, intr); } while (argc-- > 0) { char *arg; int gcode; psinfo_t psinfo; int tries = 0; if (use_agent_lwp) (void) proc_flushstdio(); if ((Pr = proc_arg_grab(arg = *argv++, PR_ARG_ANY, prg_gflags, &gcode)) == NULL) { (void) fprintf(stderr, "%s: cannot examine %s: %s\n", command, arg, Pgrab_error(gcode)); rc++; continue; } procname = arg; /* for perr() */ addr_width = (Pstatus(Pr)->pr_dmodel == PR_MODEL_LP64) ? 16 : 8; size_width = (Pstatus(Pr)->pr_dmodel == PR_MODEL_LP64) ? 11 : 8; bar = addr_width == 8 ? bar8 : bar16; (void) memcpy(&psinfo, Ppsinfo(Pr), sizeof (psinfo_t)); proc_unctrl_psinfo(&psinfo); if (Pstate(Pr) != PS_DEAD) { (void) snprintf(buf, sizeof (buf), "/proc/%d/map", (int)psinfo.pr_pid); if ((mapfd = open(buf, O_RDONLY)) < 0) { (void) fprintf(stderr, "%s: cannot " "examine %s: lost control of " "process\n", command, arg); rc++; Prelease(Pr, prr_flags); continue; } } else { mapfd = -1; } again: map_count = 0; if (Pstate(Pr) == PS_DEAD) { (void) printf("core '%s' of %d:\t%.70s\n", arg, (int)psinfo.pr_pid, psinfo.pr_psargs); if (rflag || sflag || xflag || Sflag || Lflag) { (void) printf(" -%c option is not compatible " "with core files\n", xflag ? 'x' : sflag ? 's' : rflag ? 'r' : Lflag ? 'L' : 'S'); Prelease(Pr, prr_flags); rc++; continue; } } else { (void) printf("%d:\t%.70s\n", (int)psinfo.pr_pid, psinfo.pr_psargs); } if (!(Pstatus(Pr)->pr_flags & PR_ISSYS)) { struct totals t; /* * Since we're grabbing the process readonly, we need * to make sure the address space doesn't change during * execution. */ if (Pstate(Pr) != PS_DEAD) { if (tries++ == MAX_TRIES) { Prelease(Pr, prr_flags); (void) close(mapfd); (void) fprintf(stderr, "%s: cannot " "examine %s: address space is " "changing\n", command, arg); continue; } if (fstat64(mapfd, &statbuf) != 0) { Prelease(Pr, prr_flags); (void) close(mapfd); (void) fprintf(stderr, "%s: cannot " "examine %s: lost control of " "process\n", command, arg); continue; } } nstacks = psinfo.pr_nlwp * 2; stacks = calloc(nstacks, sizeof (stacks[0])); if (stacks != NULL) { int n = 0; (void) Plwp_iter(Pr, getstack, &n); qsort(stacks, nstacks, sizeof (stacks[0]), cmpstacks); } (void) memset(&t, 0, sizeof (t)); if (Pgetauxval(Pr, AT_BASE) != -1L && Prd_agent(Pr) == NULL) { (void) fprintf(stderr, "%s: warning: " "librtld_db failed to initialize; " "shared library information will not be " "available\n", command); } /* * Gather data */ if (xflag) rc += xmapping_iter(Pr, gather_xmap, NULL, 0); else if (Sflag) rc += xmapping_iter(Pr, gather_xmap, NULL, 1); else { if (rflag) rc += rmapping_iter(Pr, gather_map, NULL); else if (sflag) rc += xmapping_iter(Pr, gather_xmap, NULL, 0); else if (lflag) rc += Pmapping_iter(Pr, gather_map, NULL); else rc += Pmapping_iter_resolved(Pr, gather_map, NULL); } /* * Ensure mappings are consistent. */ if (Pstate(Pr) != PS_DEAD) { struct stat64 newbuf; if (fstat64(mapfd, &newbuf) != 0 || memcmp(&newbuf.st_mtim, &statbuf.st_mtim, sizeof (newbuf.st_mtim)) != 0) { if (stacks != NULL) { free(stacks); stacks = NULL; } goto again; } } /* * Display data. */ if (xflag) { (void) printf("%*s%*s%*s%*s%*s " "%sMode Mapped File\n", addr_width, "Address", size_width, "Kbytes", size_width, "RSS", size_width, "Anon", size_width, "Locked", sflag ? "Pgsz " : ""); rc += iter_xmap(sflag ? look_xmap : look_xmap_nopgsz, &t); (void) printf("%s%s %s %s %s %s\n", addr_width == 8 ? "-" : "------", bar, bar, bar, bar, bar); (void) printf("%stotal Kb", addr_width == 16 ? " " : ""); printK(t.total_size, size_width); printK(t.total_rss, size_width); printK(t.total_anon, size_width); printK(t.total_locked, size_width); (void) printf("\n"); } else if (Sflag) { (void) printf("%*s%*s%*s Mode" " Mapped File\n", addr_width, "Address", size_width, "Kbytes", size_width, "Swap"); rc += iter_xmap(look_xmap_nopgsz, &t); (void) printf("%s%s %s %s\n", addr_width == 8 ? "-" : "------", bar, bar, bar); (void) printf("%stotal Kb", addr_width == 16 ? " " : ""); printK(t.total_size, size_width); printK(t.total_swap, size_width); (void) printf("\n"); } else { if (rflag) { rc += iter_map(look_map, &t); } else if (sflag) { if (Lflag) { (void) printf("%*s %*s %4s" " %-6s %s %s\n", addr_width, "Address", size_width, "Bytes", "Pgsz", "Mode ", "Lgrp", "Mapped File"); rc += iter_xmap(look_smap, &t); } else { (void) printf("%*s %*s %4s" " %-6s %s\n", addr_width, "Address", size_width, "Bytes", "Pgsz", "Mode ", "Mapped File"); rc += iter_xmap(look_smap, &t); } } else { rc += iter_map(look_map, &t); } (void) printf(" %stotal %*luK\n", addr_width == 16 ? " " : "", size_width, t.total_size); } if (stacks != NULL) { free(stacks); stacks = NULL; } } Prelease(Pr, prr_flags); if (mapfd != -1) (void) close(mapfd); } if (use_agent_lwp) (void) proc_finistdio(); return (rc); }
static void __exit lfprng_module_cleanup(void){ remove_proc_entry(lfprng, proc_entry); printK(KERN_INFO "lfprng_module_cleanup called. Module unloaded"); }