當前位置: 首頁>>代碼示例>>Java>>正文


Java Debug.threadCpuTimeNanos方法代碼示例

本文整理匯總了Java中android.os.Debug.threadCpuTimeNanos方法的典型用法代碼示例。如果您正苦於以下問題:Java Debug.threadCpuTimeNanos方法的具體用法?Java Debug.threadCpuTimeNanos怎麽用?Java Debug.threadCpuTimeNanos使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.os.Debug的用法示例。


在下文中一共展示了Debug.threadCpuTimeNanos方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: avgTimeEnd

import android.os.Debug; //導入方法依賴的package包/類
/**
 * 統計平均時常
 *
 * @param tag
 * @param msg
 */
public static void avgTimeEnd(String tag, Object... msg) {
    if (LuaViewConfig.isDebug()) {
        Map map = mAvgTime.get(tag);
        if (map != null) {//已經開始
            long lastTime = Long.valueOf(String.valueOf(map.get(LAST_TIME)));
            long totalTime = Long.valueOf(String.valueOf(map.get(TOTAL_TIME))) + Debug.threadCpuTimeNanos() - lastTime;
            map.put(TOTAL_TIME, totalTime);//總時間
            long printInterval = Long.valueOf(String.valueOf(map.get(PRINT_INTERVAL)));
            long times = Long.valueOf(String.valueOf(map.get(TIMES))) + 1;//總次數
            if (times >= printInterval) {//可以打印
                Log.d(DEFAULT_PREFIX, tag + " end " + (double) totalTime / printInterval + " " + getMsg(msg));
                mAvgTime.put(tag, null);
            } else {
                map.put(TIMES, times);//總次數
            }
        }
    }
}
 
開發者ID:alibaba,項目名稱:LuaViewPlayground,代碼行數:25,代碼來源:LogUtil.java

示例2: stopAndCollectExecutionInfoTracking

import android.os.Debug; //導入方法依賴的package包/類
public void stopAndCollectExecutionInfoTracking() {
	profilersRunning--;
	mIcount.stopInstructionCounting();
	instructionCount = mIcount.instructionsExecuted;
	methodInvocationCount = mIcount.methodsExecuted;
	threadAllocSize = Debug.getThreadAllocSize() - mStartThreadAllocSize;
	gcThreadInvocationCount = Debug.getThreadGcInvocationCount() - mStartThreadGcInvocationCount;
	gcGlobalInvocationCount = Debug.getGlobalGcInvocationCount() - mStartGlobalGcInvocationCount;
	
	if (profilersRunning == 0) {
		Debug.stopAllocCounting();
		memAllocTrackerRunning = false;
	}

	threadCpuTime = Debug.threadCpuTimeNanos() - mStartThreadCpuTime;
	execTime = System.nanoTime() - mStartTime;

	Log.d(TAG, methodName + ": Thread Alloc Size - "
			+ (Debug.getThreadAllocSize() - mStartThreadAllocSize));
	Log.d(TAG, methodName
			+ "Total instructions executed: " + instructionCount
			+ " Method invocations: " + methodInvocationCount + "in "
			+ execTime / 1000000 + "ms");
}
 
開發者ID:RapidProjectH2020,項目名稱:offloading-framework-android,代碼行數:25,代碼來源:ProgramProfiler.java

示例3: run

import android.os.Debug; //導入方法依賴的package包/類
@Override
public void run() {
    while (!mIsFinished && count < COUNT) {
        Canvas canvas = getHolder().lockCanvas();
        if (canvas == null) {
            return;
        }

        long start = Debug.threadCpuTimeNanos();

        canvas.drawBitmap(mBitmap, 0, 0, PAINT);

        long elapsed = Debug.threadCpuTimeNanos() - start;
        elapsedTime += elapsed;

        getHolder().unlockCanvasAndPost(canvas);

        count++;
    }

    Log.d(TAG, String.format(Locale.US, "elapsedTime:%d, avg:%.2f (ns)", elapsedTime, ((float) elapsedTime / count)));

}
 
開發者ID:keiji,項目名稱:adventcalendar_2015_mincomi,代碼行數:24,代碼來源:SurfaceBitmapView.java

示例4: onDraw

import android.os.Debug; //導入方法依賴的package包/類
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    long start = Debug.threadCpuTimeNanos();

    canvas.drawBitmap(mBitmap, 0, 0, PAINT);

    long elapsed = Debug.threadCpuTimeNanos() - start;
    elapsedTime += elapsed;

    count++;

    if (count < COUNT) {
        invalidate();
    } else {
        Log.d(TAG, String.format(Locale.US, "elapsedTime:%d, avg:%.2f (ns)", elapsedTime, ((float) elapsedTime / count)));

    }
}
 
開發者ID:keiji,項目名稱:adventcalendar_2015_mincomi,代碼行數:21,代碼來源:BitmapView.java

示例5: timeStart

import android.os.Debug; //導入方法依賴的package包/類
/**
 * log time start, must used with timeEnd
 */
public static void timeStart(Object... msg) {
    if (LuaViewConfig.isDebug()) {
        time = Debug.threadCpuTimeNanos();
        Log.d(DEFAULT_PREFIX, "[start] " + getMsg(msg));
    }
}
 
開發者ID:alibaba,項目名稱:LuaViewPlayground,代碼行數:10,代碼來源:LogUtil.java

示例6: startExecutionInfoTracking

import android.os.Debug; //導入方法依賴的package包/類
public void startExecutionInfoTracking() {
	mStartTime = System.nanoTime();
	mStartThreadCpuTime = Debug.threadCpuTimeNanos();

	if (memAllocTrackerRunning == false) {
		Debug.startAllocCounting();
		memAllocTrackerRunning = true;
	}
	mStartThreadAllocSize = Debug.getThreadAllocSize();
	mStartThreadGcInvocationCount = Debug.getThreadGcInvocationCount();
	mStartGlobalGcInvocationCount = Debug.getGlobalGcInvocationCount();

	mIcount.startInstructionCounting();
	profilersRunning++;
}
 
開發者ID:RapidProjectH2020,項目名稱:offloading-framework-android,代碼行數:16,代碼來源:ProgramProfiler.java

示例7: measureTimerResolution

import android.os.Debug; //導入方法依賴的package包/類
/**
 * Measure the resolution of the timer.
 * Any measurements close to this value is unreliable.
 */
private void measureTimerResolution(File outputFolder) {
    // see http://gamasutra.com/view/feature/171774/getting_high_precision_timing_on_.php?print=1
    long diff = 50000; // very large value
    for (int i = 0; i < 100; i++) {
        long end;
        long start = Debug.threadCpuTimeNanos();
        while (true) {
            end = Debug.threadCpuTimeNanos();
            if (end != start) {
                if (diff > (end - start)) {
                    diff = end - start;
                }
                break;
            }
        }
    }
    try {
        File file = new File(outputFolder, "timer");
        FileOutputStream fileOutputStream = new FileOutputStream(file, false);
        fileOutputStream.write(String.format(Locale.US, "%d\n", NUMBER_OF_ITERATIONS).getBytes());
        fileOutputStream.write(String.format(Locale.US, "%d\n", NUMBER_OF_OBJECTS).getBytes());
        fileOutputStream.write(String.format(Locale.US, "%d\n", diff).getBytes());
        fileOutputStream.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:realm,項目名稱:realm-java-benchmarks,代碼行數:32,代碼來源:MainActivity.java

示例8: runWithTiming

import android.os.Debug; //導入方法依賴的package包/類
private static void runWithTiming(TaggedRunnable taggedRunnable) {
    long nanoTime;
    long j = 0;
    boolean isDebug = true;
    if (isDebug) {
        nanoTime = System.nanoTime();
        j = Debug.threadCpuTimeNanos();
    } else {
        nanoTime = 0;
    }
    try {
        taggedRunnable.run();
        if (isDebug) {
            System.out.println("Timing - "
                    + Thread.currentThread().getName() + " "
                    + taggedRunnable.tag + ": "
                    + ((Debug.threadCpuTimeNanos() - j) / 1000000)
                    + "ms (cpu) / "
                    + ((System.nanoTime() - nanoTime) / 1000000)
                    + "ms (real)");

        }
    } catch (RuntimeException e) {
        System.out.println("Exception in " + taggedRunnable.tag);
        if (isDebug) {
            System.out.println("Timing - "
                    + Thread.currentThread().getName() + " "
                    + taggedRunnable.tag + " (failed): "
                    + ((Debug.threadCpuTimeNanos() - j) / 1000000)
                    + "ms (cpu) / "
                    + ((System.nanoTime() - nanoTime) / 1000000)
                    + "ms (real)");
        }
    } catch (Throwable th) {
        th.printStackTrace();
        int i = 1;
        if (isDebug) {
            System.out.println("Timing - "
                    + Thread.currentThread().getName() + " "
                    + taggedRunnable.tag + (i != 0 ? " (failed): " : ": ")
                    + ((Debug.threadCpuTimeNanos() - j) / 1000000)
                    + "ms (cpu) / "
                    + ((System.nanoTime() - nanoTime) / 1000000)
                    + "ms (real)");
        }
    }
}
 
開發者ID:bunnyblue,項目名稱:ACDD,代碼行數:48,代碼來源:Coordinator.java

示例9: startTimer

import android.os.Debug; //導入方法依賴的package包/類
/**
 * Starts the timer
 */
public void startTimer() {
    timeStart = Debug.threadCpuTimeNanos();
}
 
開發者ID:realm,項目名稱:realm-java-benchmarks,代碼行數:7,代碼來源:Benchmark.java

示例10: stopTimer

import android.os.Debug; //導入方法依賴的package包/類
/**
 * Stops the timer
 */
public void stopTimer() {
    long timeStop = Debug.threadCpuTimeNanos();
    long duration = timeStop - timeStart; // may report 0
    timings.add(duration);
}
 
開發者ID:realm,項目名稱:realm-java-benchmarks,代碼行數:9,代碼來源:Benchmark.java

示例11: checkCpuTimeNanos

import android.os.Debug; //導入方法依賴的package包/類
/**
 * Verify that the timer mechanism is available.
 */
private void checkCpuTimeNanos() {
    if (Debug.threadCpuTimeNanos() == -1) {
        throw new RuntimeException("Debug.threadCpuTimeNanos() doesn't work.");
    }
}
 
開發者ID:realm,項目名稱:realm-java-benchmarks,代碼行數:9,代碼來源:MainActivity.java

示例12: run

import android.os.Debug; //導入方法依賴的package包/類
@Override
public void run() {
    while (!mIsFinished && count < COUNT) {

        Canvas canvas = lockCanvas();
        if (canvas == null) {
            return;
        }

        long start = Debug.threadCpuTimeNanos();

        canvas.drawBitmap(mBitmap, 0, 0, PAINT);

        long elapsed = Debug.threadCpuTimeNanos() - start;
        elapsedTime += elapsed;

        unlockCanvasAndPost(canvas);

        count++;
    }

    Log.d(TAG, String.format(Locale.US, "elapsedTime:%d, avg:%.2f (ns)", elapsedTime, ((float) elapsedTime / count)));

}
 
開發者ID:keiji,項目名稱:adventcalendar_2015_mincomi,代碼行數:25,代碼來源:TextureBitmapView.java


注:本文中的android.os.Debug.threadCpuTimeNanos方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。