Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Jamaica.doc
Скачиваний:
9
Добавлен:
01.03.2025
Размер:
1.89 Mб
Скачать

6.3.2. Example

We can sort the profiling output to find the application methods where most of the execution time is spent. Under Unix, the 25 methods which use the most execution time (in number of bytecode instructions) can be found with the following command:

> grep PROFILE: HelloWorld.prof | sort -rn -k2 | head -n25

In this small example program, it is not surprise that nearly all execution time is spent in methods that are required for writing the output to the screen. The dominant function is java/nio/ByteBufferImpl.put, which is used while converting Java’s unicode characters to the platform’s ISO 8859-1 encoding. Also important is the time spent in StringBuffer.append. Calls to the StringBuffer methods have been generated automatically by the jamaicac compiler for string concatenation expressions using the ’+’-operator.

On systems that support a CPU cycle counter, the profiling data also contains a cumulative count of the number of cycles spent in each method. This information is useful to obtain a more high-level view on where the runtime performance was spent.

The CPU cycle profiling information is contained in lines starting with the tag PROFILE_CYCLES:. A similar command line can be used to find the methods that cumulatively require most of the execution time:

> grep PROFILE_CYCLES: HelloWorld.prof | sort -rn -k2 | head -n25

The cumulative cycle count shows more clearly that the main method is running most of the time during the profiling run, the next dominating methods are print and println of class java.io.PrintStream. The cumulative cycle counts can now be used as a basis for a top-down optimization of the application execution time.

Попытаться извлечь из файла .prof другую дополнительную информацию (например PROFILE_THREAD). Задокументировать полученные данные.

3 Reducing Footprint and Memory

Usage

Открываем мануал по JamaicaVm (Lab/inform/jamaicavm_manual.pdf). Самостоятельно изучаем раздел 7.1. (страница 59), все необходимые программы доступны в каталоге /home/rtj/jamaica/.

На основе изученного материала делаем выводы!! С помощью Eclipse + Jamaica Tools модернизируем программу HelloyRTJava или создаем собственную (на свое усмотрение).

Делаем три варианта исполняемых файлов (для целевой системы - QNX):

  1. Файл полученный с ключом -interpret

  2. Файл полученный с помощью ключа -useProfile и файлом (.prof)

  3. Файл полученный без ключа -interpret

  4. Возможны дополнительные вариации используемых ключей (-optimise, - compile)

Сравниваем полученные исполняемые приложения. Необходимо доказать, что быстродействие их под ОС QNX различается, для этого желательно использовать QNX Momentics + System Profiler (возможны альтернативы средства). Формируем мини отчет.

Пример модернизации HelloyRTJava (не очень хороший):

import java.util.Random;

Import javax.Realtime.AsyncEventHandler;

Import javax.Realtime.PosixSignalHandler;

public class HelloRTJava {

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

POSIXSignalHandler.addHandler(POSIXSignalHandler.SIGUSR1,new AsyncEventHandler(){

public void handleAsyncEvent() {

System.out.println("I'm a POSIX signal handler!");

}

});

POSIXSignalHandler.addHandler(POSIXSignalHandler.SIGUSR2,new AsyncEventHandler(){

public void handleAsyncEvent() {

System.out.println("Good bye!");

System.exit(0);

}

});

int num;

long fact;

double source;

double exp;

double result;

while (true) {

try {

Thread.sleep(500);

} catch (Exception e) {

System.err.println("POSIX signal example error:" + e.getMessage());

e.printStackTrace();

}

System.out.println("Kick me with the QNX command:");

System.out.println("slay -s SIGUSR1 HelloRTJava");

System.out.println();

System.out.println("or kill me with the QNX command:");

System.out.println("slay -s SIGUSR2 HelloRTJava");

System.out.println("");

Random s = new Random();

num = s.nextInt(20);

fact = 1;

for (int i=1; i<=num; i++) {

fact = fact * i;

}

System.out.println("The Factorial; num: "+num +"; result: "+fact+"." );

source = s.nextInt(40);

exp = s.nextInt(10);

result = Math.pow(source,exp);

System.out.println("The Power of a Number; Pow(" + source + ", " + exp + ") = " + result);

source = s.nextDouble();

result = Math.exp(source);

System.out.println("The Exponential; The exponential of " +source +" is " +result);

}

}

}

Изучаем главу 7.2, проводим эксперименты над своей программой. Проанализируйте работу приложений с использованием QNX Momentics. Результаты документируем.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]