当前位置: 首页>>代码示例>>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;未经允许,请勿转载。