Pergunta

I'm writing a program in Java

In this program I'm reading and changing an array of data. This is an example of the code:

public double computation() {
    char c = 0;
    char target = 'a';
    int x = 0, y = 1;

    for (int i = 0; i < data.length; i++) {
        // Read Data
        c = data[index[i]];

        if (c == target)
            x++;
        else
            y++;

        //Change Value
        if (Character.isUpperCase(c))
            Character.toLowerCase(c);
        else
            Character.toUpperCase(c);

        //Write Data
        data[index[i]] = c;
    }
    return (double) x / (double) y;
}

BTW, the INDEX array contains DATA array's indexes in random order to prevent prefetching. I'm forcing all of my cache accesses to be missed by using random indexes in INDEX array.

Now I want to check what is the behavior of the CPU cache by collecting information about its hit ratio.

Is there any developed tool for this purpose? If not is there any technique?

Foi útil?

Solução

On Linux it is possible to collect such information via OProfile. Each CPU has performance event counters. See here for the list of the AMD K15 family events: http://oprofile.sourceforge.net/docs/amd-family15h-events.php

OProfile regularly samples the event counter(s) and together with the program counter. After a program run you can analyze how many events happen and at (statistically) what program position.

OProfile has build in Java support. It interacts with the Java JIT and creates a synthetic symbol table to look up the Java method name for a peace of generated JIT code.

The initial setup is not quite easy. If interested, I can guide you through or write a little more about it.

Outras dicas

I don't think you can reach such low level information from Java but someone might know better. You could write the same program with no cache misses and check the difference. This is what I suggested in this other post for example.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top