]> granicus.if.org Git - sysstat/commitdiff
Added two new metrics (amount of active and inactive memory) to sar -r.
authorSebastien Godard <sysstat@orange.fr>
Sat, 18 Dec 2010 15:17:15 +0000 (16:17 +0100)
committerSebastien Godard <sysstat@orange.fr>
Sat, 18 Dec 2010 15:17:15 +0000 (16:17 +0100)
This patch adds two new metrics (kbactive and kbinact) to sar -r.
Also update sar manual page and DTD and XSD documents.

CHANGES
activity.c
man/sar.in
pr_stats.c
rd_stats.c
rd_stats.h
rndr_stats.c
xml/sysstat.dtd
xml/sysstat.xsd
xml_stats.c

diff --git a/CHANGES b/CHANGES
index bc7cc872c6ff21b315b4c9bf78d83bbcbeb3c220..8506ce9ce71204f7ad93694ace193374f9409391 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -7,6 +7,8 @@ xxxx/xx/xx: Version 9.1.7 - Sebastien Godard (sysstat <at> orange.fr)
          activities.
        * Added a new metric (number of tasks waiting for I/O) to
          sar -q.
+       * Added two new metrics (amount of active and inactive
+         memory) to sar -r.
        * [Ivana Varekova]: Fix segfaults on bogus localtime input.
        * Fixed bogus CPU statistics output, which happened when
          CPU user value from /proc/stat wasn't incremented whereas
index ac4d0b104b06730c7e091b597e74a9084b7412c5..e622e9676e7dfd5fb683e6181c4b54fa3ddc448e 100644 (file)
@@ -264,7 +264,7 @@ struct activity memory_act = {
        .f_render       = render_memory_stats,
        .f_xml_print    = xml_print_memory_stats,
        .hdr_line       = "frmpg/s;bufpg/s;campg/s|"
-                         "kbmemfree;kbmemused;%memused;kbbuffers;kbcached;kbcommit;%commit|"
+                         "kbmemfree;kbmemused;%memused;kbbuffers;kbcached;kbcommit;%commit;kbactive;kbinact|"
                          "kbswpfree;kbswpused;%swpused;kbswpcad;%swpcad",
        .name           = "A_MEMORY",
 #endif
index 08e23a9ed12bff09e3be23cc14684c195b0f5fbe..8eee9de0b316c2907cc0f2f445c213f4ccf66a33 100644 (file)
@@ -1688,7 +1688,18 @@ RAM/swap is needed to guarantee that there never is out of memory.
 .RS
 Percentage of memory needed for current workload in relation to the total amount of memory (RAM+swap).
 This number may be greater than 100% because the kernel usually overcommits memory.
+.RE
 
+.B kbactive
+.RS
+Amount of active memory in kilobytes (memory that has been used more recently
+and usually not reclaimed unless absolutely necessary).
+.RE
+
+.B kbinact
+.RS
+Amount of inactive memory in kilobytes (memory which has been less recently
+used. It is more eligible to be reclaimed for other purposes).
 .RE
 .RE
 .IP -R
index 73f708542ce53d79a77f49e2b306612478dddf60..28b55a9de67f7db303e4fe43be08bf37ff1c2869 100644 (file)
@@ -390,10 +390,12 @@ void stub_print_memory_stats(struct activity *a, int prev, int curr,
                *smc = (struct stats_memory *) a->buf[curr],
                *smp = (struct stats_memory *) a->buf[prev];
        static unsigned long long
-               avg_frmkb = 0,
-               avg_bufkb = 0,
-               avg_camkb = 0,
-               avg_comkb = 0;
+               avg_frmkb    = 0,
+               avg_bufkb    = 0,
+               avg_camkb    = 0,
+               avg_comkb    = 0,
+               avg_activekb = 0,
+               avg_inactkb  = 0;
        static unsigned long long
                avg_frskb = 0,
                avg_tlskb = 0,
@@ -414,12 +416,12 @@ void stub_print_memory_stats(struct activity *a, int prev, int curr,
        if (DISPLAY_MEM_AMT(a->opt_flags)) {
                if (dis) {
                        printf("\n%-11s kbmemfree kbmemused  %%memused kbbuffers  kbcached"
-                              "  kbcommit   %%commit\n", timestamp[!curr]);
+                              "  kbcommit   %%commit  kbactive   kbinact\n", timestamp[!curr]);
                }
 
                if (!dispavg) {
                        /* Display instantaneous values */
-                       printf("%-11s %9lu %9lu    %6.2f %9lu %9lu %9lu   %7.2f\n",
+                       printf("%-11s %9lu %9lu    %6.2f %9lu %9lu %9lu   %7.2f %9lu %9lu\n",
                               timestamp[curr],
                               smc->frmkb,
                               smc->tlmkb - smc->frmkb,
@@ -429,21 +431,25 @@ void stub_print_memory_stats(struct activity *a, int prev, int curr,
                               smc->camkb,
                               smc->comkb,
                               (smc->tlmkb + smc->tlskb) ?
-                              SP_VALUE(0, smc->comkb, smc->tlmkb + smc->tlskb) : 0.0);
+                              SP_VALUE(0, smc->comkb, smc->tlmkb + smc->tlskb) : 0.0,
+                              smc->activekb,
+                              smc->inactkb);
 
                        /*
                         * Will be used to compute the average.
                         * We assume that the total amount of memory installed can not vary
                         * during the interval given on the command line.
                         */
-                       avg_frmkb += smc->frmkb;
-                       avg_bufkb += smc->bufkb;
-                       avg_camkb += smc->camkb;
-                       avg_comkb += smc->comkb;
+                       avg_frmkb    += smc->frmkb;
+                       avg_bufkb    += smc->bufkb;
+                       avg_camkb    += smc->camkb;
+                       avg_comkb    += smc->comkb;
+                       avg_activekb += smc->activekb;
+                       avg_inactkb  += smc->inactkb;
                }
                else {
                        /* Display average values */
-                       printf("%-11s %9.0f %9.0f    %6.2f %9.0f %9.0f %9.0f   %7.2f\n",
+                       printf("%-11s %9.0f %9.0f    %6.2f %9.0f %9.0f %9.0f   %7.2f %9.0f %9.0f\n",
                               timestamp[curr],
                               (double) avg_frmkb / avg_count,
                               (double) smc->tlmkb - ((double) avg_frmkb / avg_count),
@@ -456,11 +462,13 @@ void stub_print_memory_stats(struct activity *a, int prev, int curr,
                               (double) avg_comkb / avg_count,
                               (smc->tlmkb + smc->tlskb) ?
                               SP_VALUE(0.0, (double) (avg_comkb / avg_count),
-                                       smc->tlmkb + smc->tlskb) :
-                              0.0);
+                                       smc->tlmkb + smc->tlskb) : 0.0,
+                              (double) avg_activekb / avg_count,
+                              (double) avg_inactkb / avg_count);
                        
                        /* Reset average counters */
                        avg_frmkb = avg_bufkb = avg_camkb = avg_comkb = 0;
+                       avg_activekb = avg_inactkb = 0;
                }
        }
        
index 9d78c631359748e14fbbb425ef2a37f4fb58c933..9a1ad5ff3574b792bb3439e7b4a7b46b3b1f5944 100644 (file)
@@ -335,6 +335,14 @@ void read_meminfo(struct stats_memory *st_memory)
                        /* Read the amount of cached swap in kB */
                        sscanf(line + 11, "%lu", &st_memory->caskb);
                }
+               else if (!strncmp(line, "Active:", 7)) {
+                       /* Read the amount of active memory in kB */
+                       sscanf(line + 7, "%lu", &st_memory->activekb);
+               }
+               else if (!strncmp(line, "Inactive:", 9)) {
+                       /* Read the amount of inactive memory in kB */
+                       sscanf(line + 9, "%lu", &st_memory->inactkb);
+               }
                else if (!strncmp(line, "SwapTotal:", 10)) {
                        /* Read the total amount of swap memory in kB */
                        sscanf(line + 10, "%lu", &st_memory->tlskb);
index 90c224a8fc5a9593577fe3052eeb45f3e73e52f8..ff34359a8ea60901ee9efe824d35eab7277a1d02 100644 (file)
@@ -152,6 +152,8 @@ struct stats_memory {
        unsigned long tlskb     __attribute__ ((aligned (8)));
        unsigned long caskb     __attribute__ ((aligned (8)));
        unsigned long comkb     __attribute__ ((aligned (8)));
+       unsigned long activekb  __attribute__ ((aligned (8)));
+       unsigned long inactkb   __attribute__ ((aligned (8)));
 };
 
 #define STATS_MEMORY_SIZE      (sizeof(struct stats_memory))
index 33e8e585901b3aba30b2415018512ed91e620c2a..866eff79333f8c12c4fb6be80e0a54dac9d0a66a 100644 (file)
@@ -688,11 +688,19 @@ __print_funct_t render_memory_stats(struct activity *a, int isdb, char *pre,
                       "-\tkbcommit", NULL, NULL,
                       smc->comkb, DNOVAL);
 
-               render(isdb, pre, pt_newlin,
+               render(isdb, pre, PT_NOFLAG,
                       "-\t%%commit", NULL, NULL, NOVAL,
                       (smc->tlmkb + smc->tlskb) ?
                       SP_VALUE(0, smc->comkb, smc->tlmkb + smc->tlskb) :
                       0.0);
+
+               render(isdb, pre, PT_USEINT,
+                      "-\tkbactive", NULL, NULL,
+                      smc->activekb, DNOVAL);
+
+               render(isdb, pre, PT_USEINT | pt_newlin,
+                      "-\tkbinact", NULL, NULL,
+                      smc->inactkb, DNOVAL);
        }
        
        if (DISPLAY_SWAP(a->opt_flags)) {
index ad21c5683f114aa81141cff881ae25374a139c07..db1e44c0fec0953e77db6bafe75e54690d606309 100644 (file)
@@ -17,6 +17,8 @@
 <!ELEMENT campg (#PCDATA)>
 <!ELEMENT commit (#PCDATA)>
 <!ELEMENT commit-percent (#PCDATA)>
+<!ELEMENT active (#PCDATA)>
+<!ELEMENT inactive (#PCDATA)>
 <!ELEMENT cpu EMPTY>
 <!ATTLIST cpu
        number CDATA #REQUIRED
        pty-nr CDATA #REQUIRED
 >
 <!ELEMENT memfree (#PCDATA)>
-<!ELEMENT memory (memfree, memused, memused-percent, buffers, cached, commit, commit-percent, swpfree, swpused, swpused-percent, swpcad, swpcad-percent, frmpg, bufpg, campg)>
+<!ELEMENT memory (memfree, memused, memused-percent, buffers, cached, commit, commit-percent, active, inactive, swpfree, swpused, swpused-percent, swpcad, swpcad-percent, frmpg, bufpg, campg)>
 <!ATTLIST memory
        per CDATA #REQUIRED
        unit CDATA #REQUIRED
index 60e40fc92c17ed586028fcaa83bb088586b5d844..9d5c3c98a389bad695223cc83fc3e384e899ea0a 100644 (file)
@@ -42,6 +42,8 @@
                <xs:element name="cached" type="xs:nonNegativeInteger"></xs:element>
                <xs:element name="commit" type="xs:nonNegativeInteger"></xs:element>
                <xs:element name="commit-percent" type="hundredth-type"></xs:element>
+               <xs:element name="active" type="xs:nonNegativeInteger"></xs:element>
+               <xs:element name="inactive" type="xs:nonNegativeInteger"></xs:element>
                <xs:element name="swpfree" type="xs:nonNegativeInteger"></xs:element>
                <xs:element name="swpused" type="xs:nonNegativeInteger"></xs:element>
                <xs:element name="swpused-percent" type="hundredth-type"></xs:element>
index 2b6dc9b3fc39efff08f0d9995464bb1e9b31cf47..dade9c855e987a0f3c05c398dfb70e7889927d99 100644 (file)
@@ -507,10 +507,16 @@ __print_funct_t xml_print_memory_stats(struct activity *a, int curr, int tab,
                xprintf(tab, "<commit>%lu</commit>",
                        smc->comkb);
 
-               xprintf(tab--, "<commit-percent>%.2f</commit-percent>",
+               xprintf(tab, "<commit-percent>%.2f</commit-percent>",
                        (smc->tlmkb + smc->tlskb) ?
                        SP_VALUE(0, smc->comkb, smc->tlmkb + smc->tlskb) :
                        0.0);
+
+               xprintf(tab, "<active>%lu</active>",
+                       smc->activekb);
+                       
+               xprintf(tab--, "<inactive>%lu</inactive>",
+                       smc->inactkb);
        }
 
        if (DISPLAY_SWAP(a->opt_flags)) {