Print this page




   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 2013 Gary Mills
  24  *
  25  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  26  * Use is subject to license terms.
  27  *
  28  * Portions Copyright 2009 Chad Mynhier
  29  * Copyright 2012 Joyent, Inc.  All rights reserved.
  30  */
  31 
  32 #include <sys/types.h>
  33 #include <sys/resource.h>
  34 #include <sys/loadavg.h>
  35 #include <sys/time.h>
  36 #include <sys/pset.h>
  37 #include <sys/vm_usage.h>
  38 #include <zone.h>
  39 #include <libzonecfg.h>
  40 
  41 #include <stdio.h>
  42 #include <stdlib.h>
  43 #include <unistd.h>
  44 #include <dirent.h>
  45 #include <string.h>
  46 #include <errno.h>
  47 #include <poll.h>
  48 #include <ctype.h>
  49 #include <fcntl.h>


 247                 *loadavg++ += psetloadavg[0];
 248                 *loadavg++ += psetloadavg[1];
 249                 *loadavg += psetloadavg[2];
 250         }
 251 }
 252 
 253 /*
 254  * Queries the memory virtual and rss size for each member of a list.
 255  * This will override the values computed by /proc aggregation.
 256  */
 257 static void
 258 list_getsize(list_t *list)
 259 {
 260         id_info_t *id;
 261         vmusage_t *results, *next;
 262         vmusage_t *match;
 263         size_t nres = 0;
 264         size_t i;
 265         uint_t flags = 0;
 266         int ret;
 267         size_t physmem;
 268 
 269         if (!(opts.o_outpmode & OPT_VMUSAGE))
 270                 return;
 271 
 272         physmem = sysconf(_SC_PHYS_PAGES) * pagesize;
 273 
 274         /*
 275          * Determine what swap/rss results to calculate.  getvmusage() will
 276          * prune results returned to non-global zones automatically, so
 277          * there is no need to pass different flags when calling from a
 278          * non-global zone.
 279          *
 280          * Currently list_getsize() is only called with a single flag.  This
 281          * is because -Z, -J, -T, and -a are mutually exclusive.  Regardless
 282          * of this, we handle multiple flags.
 283          */
 284         if (opts.o_outpmode & OPT_USERS) {
 285                 /*
 286                  * Gather rss for all users in all zones.  Treat the same
 287                  * uid in different zones as the same user.
 288                  */
 289                 flags |= VMUSAGE_COL_RUSERS;
 290 
 291         } else if (opts.o_outpmode & OPT_TASKS) {
 292                 /* Gather rss for all tasks in all zones */
 293                 flags |= VMUSAGE_ALL_TASKS;


1403 main(int argc, char **argv)
1404 {
1405         DIR *procdir;
1406         char *p;
1407         char *sortk = "cpu";    /* default sort key */
1408         int opt;
1409         int timeout;
1410         struct pollfd pollset;
1411         char key;
1412         char procpath[PATH_MAX];
1413 
1414         (void) setlocale(LC_ALL, "");
1415         (void) textdomain(TEXT_DOMAIN);
1416         Progname(argv[0]);
1417         lwpid_init();
1418         fd_init(Setrlimit());
1419 
1420         pagesize = sysconf(_SC_PAGESIZE);
1421 
1422         while ((opt = getopt(argc, argv,
1423             "vVcd:HmarRLtu:U:n:p:C:P:h:s:S:j:k:TJWz:Z")) != (int)EOF) {
1424                 switch (opt) {
1425                 case 'r':
1426                         opts.o_outpmode |= OPT_NORESOLVE;
1427                         break;
1428                 case 'R':
1429                         opts.o_outpmode |= OPT_REALTIME;
1430                         break;
1431                 case 'c':
1432                         opts.o_outpmode &= ~OPT_TERMCAP;
1433                         opts.o_outpmode &= ~OPT_FULLSCREEN;
1434                         break;
1435                 case 'd':
1436                         if (optarg) {
1437                                 if (*optarg == 'u')
1438                                         opts.o_outpmode |= OPT_UDATE;
1439                                 else if (*optarg == 'd')
1440                                         opts.o_outpmode |= OPT_DDATE;
1441                                 else
1442                                         Usage();
1443                         } else {


1483                         sortk = optarg;
1484                         break;
1485                 case 'S':
1486                         opts.o_sortorder = 1;
1487                         sortk = optarg;
1488                         break;
1489                 case 'u':
1490                         if ((p = strtok(optarg, ", ")) == NULL)
1491                                 Die(gettext("invalid argument for -u\n"));
1492                         add_uid(&euid_tbl, p);
1493                         while (p = strtok(NULL, ", "))
1494                                 add_uid(&euid_tbl, p);
1495                         break;
1496                 case 'U':
1497                         if ((p = strtok(optarg, ", ")) == NULL)
1498                                 Die(gettext("invalid argument for -U\n"));
1499                         add_uid(&ruid_tbl, p);
1500                         while (p = strtok(NULL, ", "))
1501                                 add_uid(&ruid_tbl, p);
1502                         break;
1503                 case 'V':
1504                         opts.o_outpmode |= OPT_VMUSAGE;
1505                         break;
1506                 case 'p':
1507                         fill_table(&pid_tbl, optarg, 'p');
1508                         break;
1509                 case 'C':
1510                         fill_set_table(optarg);
1511                         opts.o_outpmode |= OPT_PSETS;
1512                         break;
1513                 case 'P':
1514                         fill_table(&cpu_tbl, optarg, 'P');
1515                         break;
1516                 case 'k':
1517                         fill_table(&tsk_tbl, optarg, 'k');
1518                         break;
1519                 case 'j':
1520                         fill_prj_table(optarg);
1521                         break;
1522                 case 'L':
1523                         opts.o_outpmode |= OPT_LWPS;
1524                         break;
1525                 case 'W':




   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright (c) 2013 Gary Mills
  24  *
  25  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  26  * Use is subject to license terms.
  27  *
  28  * Portions Copyright 2009 Chad Mynhier

  29  */
  30 
  31 #include <sys/types.h>
  32 #include <sys/resource.h>
  33 #include <sys/loadavg.h>
  34 #include <sys/time.h>
  35 #include <sys/pset.h>
  36 #include <sys/vm_usage.h>
  37 #include <zone.h>
  38 #include <libzonecfg.h>
  39 
  40 #include <stdio.h>
  41 #include <stdlib.h>
  42 #include <unistd.h>
  43 #include <dirent.h>
  44 #include <string.h>
  45 #include <errno.h>
  46 #include <poll.h>
  47 #include <ctype.h>
  48 #include <fcntl.h>


 246                 *loadavg++ += psetloadavg[0];
 247                 *loadavg++ += psetloadavg[1];
 248                 *loadavg += psetloadavg[2];
 249         }
 250 }
 251 
 252 /*
 253  * Queries the memory virtual and rss size for each member of a list.
 254  * This will override the values computed by /proc aggregation.
 255  */
 256 static void
 257 list_getsize(list_t *list)
 258 {
 259         id_info_t *id;
 260         vmusage_t *results, *next;
 261         vmusage_t *match;
 262         size_t nres = 0;
 263         size_t i;
 264         uint_t flags = 0;
 265         int ret;
 266         size_t physmem = sysconf(_SC_PHYS_PAGES) * pagesize;
 267 





 268         /*
 269          * Determine what swap/rss results to calculate.  getvmusage() will
 270          * prune results returned to non-global zones automatically, so
 271          * there is no need to pass different flags when calling from a
 272          * non-global zone.
 273          *
 274          * Currently list_getsize() is only called with a single flag.  This
 275          * is because -Z, -J, -T, and -a are mutually exclusive.  Regardless
 276          * of this, we handle multiple flags.
 277          */
 278         if (opts.o_outpmode & OPT_USERS) {
 279                 /*
 280                  * Gather rss for all users in all zones.  Treat the same
 281                  * uid in different zones as the same user.
 282                  */
 283                 flags |= VMUSAGE_COL_RUSERS;
 284 
 285         } else if (opts.o_outpmode & OPT_TASKS) {
 286                 /* Gather rss for all tasks in all zones */
 287                 flags |= VMUSAGE_ALL_TASKS;


1397 main(int argc, char **argv)
1398 {
1399         DIR *procdir;
1400         char *p;
1401         char *sortk = "cpu";    /* default sort key */
1402         int opt;
1403         int timeout;
1404         struct pollfd pollset;
1405         char key;
1406         char procpath[PATH_MAX];
1407 
1408         (void) setlocale(LC_ALL, "");
1409         (void) textdomain(TEXT_DOMAIN);
1410         Progname(argv[0]);
1411         lwpid_init();
1412         fd_init(Setrlimit());
1413 
1414         pagesize = sysconf(_SC_PAGESIZE);
1415 
1416         while ((opt = getopt(argc, argv,
1417             "vcd:HmarRLtu:U:n:p:C:P:h:s:S:j:k:TJWz:Z")) != (int)EOF) {
1418                 switch (opt) {
1419                 case 'r':
1420                         opts.o_outpmode |= OPT_NORESOLVE;
1421                         break;
1422                 case 'R':
1423                         opts.o_outpmode |= OPT_REALTIME;
1424                         break;
1425                 case 'c':
1426                         opts.o_outpmode &= ~OPT_TERMCAP;
1427                         opts.o_outpmode &= ~OPT_FULLSCREEN;
1428                         break;
1429                 case 'd':
1430                         if (optarg) {
1431                                 if (*optarg == 'u')
1432                                         opts.o_outpmode |= OPT_UDATE;
1433                                 else if (*optarg == 'd')
1434                                         opts.o_outpmode |= OPT_DDATE;
1435                                 else
1436                                         Usage();
1437                         } else {


1477                         sortk = optarg;
1478                         break;
1479                 case 'S':
1480                         opts.o_sortorder = 1;
1481                         sortk = optarg;
1482                         break;
1483                 case 'u':
1484                         if ((p = strtok(optarg, ", ")) == NULL)
1485                                 Die(gettext("invalid argument for -u\n"));
1486                         add_uid(&euid_tbl, p);
1487                         while (p = strtok(NULL, ", "))
1488                                 add_uid(&euid_tbl, p);
1489                         break;
1490                 case 'U':
1491                         if ((p = strtok(optarg, ", ")) == NULL)
1492                                 Die(gettext("invalid argument for -U\n"));
1493                         add_uid(&ruid_tbl, p);
1494                         while (p = strtok(NULL, ", "))
1495                                 add_uid(&ruid_tbl, p);
1496                         break;



1497                 case 'p':
1498                         fill_table(&pid_tbl, optarg, 'p');
1499                         break;
1500                 case 'C':
1501                         fill_set_table(optarg);
1502                         opts.o_outpmode |= OPT_PSETS;
1503                         break;
1504                 case 'P':
1505                         fill_table(&cpu_tbl, optarg, 'P');
1506                         break;
1507                 case 'k':
1508                         fill_table(&tsk_tbl, optarg, 'k');
1509                         break;
1510                 case 'j':
1511                         fill_prj_table(optarg);
1512                         break;
1513                 case 'L':
1514                         opts.o_outpmode |= OPT_LWPS;
1515                         break;
1516                 case 'W':