Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unable to open trace file

Tags:

android

I want to test the performance of my app . I have started it with simple application and try to put traceview but its suddenly fail on my android phone with force to close. Please guide me how can i set my code propley for simple android app to get hands dirt with Trace view

Here is the code package test.check;

import android.app.Activity;
import android.os.Bundle;
import android.os.Debug;

public class tracev extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Debug.startMethodTracing("traceview");
        setContentView(R.layout.main);
    }
    @Override
    protected void onStop() {
        Debug.stopMethodTracing();
        super.onStop();
    }
}

Here is the manifest file

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="test.check"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="4" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".tracev"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>

I have also added

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

but its not working . I think its becasue of this line in the logcat but i am not sure how to deal with it

05-20 23:39:43.913: ERROR/dalvikvm(11673): Unable to open trace file '/sdcard/traceview.trace': Permission denied

Logcat

05-20 23:39:43.903: DEBUG/dalvikvm(11673): +++ active profiler count now 1
05-20 23:39:43.913: INFO/dalvikvm(11673): TRACE STARTED: '/sdcard/traceview.trace' 8192KB
05-20 23:39:43.913: ERROR/dalvikvm(11673): Unable to open trace file '/sdcard/traceview.trace': Permission denied
05-20 23:39:43.913: DEBUG/dalvikvm(11673): +++ active profiler count now 0
05-20 23:39:43.913: DEBUG/AndroidRuntime(11673): Shutting down VM
05-20 23:39:43.913: WARN/dalvikvm(11673): threadid=3: thread exiting with uncaught exception (group=0x4001e390)
05-20 23:39:43.913: ERROR/AndroidRuntime(11673): Uncaught handler: thread main exiting due to uncaught exception
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): java.lang.RuntimeException: Unable to start activity ComponentInfo{test.check/test.check.tracev}: java.lang.RuntimeException: file open failed
05-20 23:39:43.983: ERROR/AndroidRuntime(11673):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2596)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2621)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673):     at android.app.ActivityThread.access$2200(ActivityThread.java:126)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1932)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673):     at android.os.Looper.loop(Looper.java:123)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673):     at android.app.ActivityThread.main(ActivityThread.java:4595)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673):     at java.lang.reflect.Method.invokeNative(Native Method)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673):     at java.lang.reflect.Method.invoke(Method.java:521)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673):     at dalvik.system.NativeStart.main(Native Method)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673): Caused by: java.lang.RuntimeException: file open failed
05-20 23:39:43.983: ERROR/AndroidRuntime(11673):     at dalvik.system.VMDebug.startMethodTracing(Native Method)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673):     at dalvik.system.VMDebug.startMethodTracing(VMDebug.java:156)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673):     at android.os.Debug.startMethodTracing(Debug.java:443)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673):     at android.os.Debug.startMethodTracing(Debug.java:391)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673):     at test.check.tracev.onCreate(tracev.java:12)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2544)
05-20 23:39:43.983: ERROR/AndroidRuntime(11673):     ... 11 more
05-20 23:39:44.013: INFO/Process(94): Sending signal. PID: 11673 SIG: 3
05-20 23:39:44.013: INFO/dalvikvm(11673): threadid=7: reacting to signal 3
05-20 23:39:44.023: INFO/dalvikvm(11673): Wrote stack trace to '/data/anr/traces.txt'
05-20 23:39:51.213: DEBUG/KeyguardViewMediator(94): pokeWakelock(15000)
05-20 23:39:51.213: INFO/HtcLockScreen(94): Press Menu key to unlock screen

I am wondering about one point there is nothing in the sdcard and in front of it there is no device selected . May be it can be the cause of error , here is the picture enter image description here

like image 375
user667340 Avatar asked May 20 '11 21:05

user667340


People also ask

What is a trace file?

A trace file is a file containing a trace of certain events that happen (or will happen) during some process. In the context of dinero simulations, the trace file contains a trace of all the addresses used in memory references by the program from which the trace is generated.


1 Answers

If this is an emulator, make sure that emulator has an SDCard attached to it.

Also, best practice is to use getExternalStorageDirectory().

Try putting the permissions line right under the uses-sdk line.

Use a different file name than traceview to make sure no other app has lock on it.

Your SD Card appears to be empty. Have you been able to access it before? It may be corrupt.

like image 83
Haphazard Avatar answered Oct 16 '22 18:10

Haphazard