All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hyperic.sigar.win32.test.TestPdh Maven / Gradle / Ivy

There is a newer version: 1.6.6-rev002
Show newest version
/*
 * Copyright (c) 2006-2007 Hyperic, Inc.
 * Copyright (c) 2009-2010 VMware, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.hyperic.sigar.win32.test;

import java.util.Iterator;
import java.util.Map;

import org.hyperic.sigar.test.SigarTestCase;
import org.hyperic.sigar.win32.Pdh;

public class TestPdh extends SigarTestCase {

    public TestPdh(String name) {
        super(name);
    }

    private static boolean isCounter(long type) {
        return (type & Pdh.PERF_TYPE_COUNTER) == Pdh.PERF_TYPE_COUNTER;
    }

    private void getValue(String key) throws Exception {
        Pdh pdh = new Pdh();

        traceln(key + ": " + pdh.getDescription(key));
        traceln("counter=" + isCounter(pdh.getCounterType(key)));
        assertGtEqZeroTrace("raw",
                            (long)pdh.getRawValue(key));
        assertGtEqZeroTrace("fmt",
                            (long)pdh.getFormattedValue(key));
    }

    public void testGetValue() throws Exception {
        Pdh.enableTranslation();
        final String DL = "\\";
        String[][] keys = {
            { "System", "System Up Time" },
            { "Memory", "Available Bytes" },
            { "Memory", "Pages/sec" },
            { "Processor(_Total)", "% User Time" },
        };

        for (int i=0; i" + trans);
            }
            traceln(path + " validate: " + Pdh.validate(path));
            getValue(path);
        }
    }

    public void testCounterMap() throws Exception {
        Map counters = Pdh.getEnglishPerflibCounterMap();

        assertGtZeroTrace("counters", counters.size());
        int dups = 0;
        for (Iterator it=counters.entrySet().iterator(); it.hasNext();) {
            Map.Entry entry = (Map.Entry)it.next();
            String name = (String)entry.getKey();
            int[] ix = (int[])entry.getValue();
            if (ix.length > 1) {
                dups++;
                //traceln(name + " has dups: " + ix.length);
            }
        }
        traceln(dups + " names have dups");

        String[] keys = {
            "System", "System Up Time"
        };
        int last = -1;
        for (int i=0; i" +
                        Integer.toHexString(status).toUpperCase() +
                        " != " +
                        Integer.toHexString(expect).toUpperCase());
            }

            assertTrue(expectedResult);
        }
    }

    public void testPdh() throws Exception {

        String[] iface = Pdh.getKeys("Thread");
        
        assertTrue(iface.length > 0);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy