1. AC Question's Avatar
    I need to calculate the time taken to execute the sorting program given
    below. I am new to android programming and I just found an article to
    use TimingLogger but in the prompt when I type

    adb logcat -v time SortTag:V *:E
    to know the time of execution it gives me the following error.

    Errors displayed

    C:\Users\Dell\AndroidStudioProjects\Sort>adb shell setprop log.tag.SortTag
    VERBOSE

    C:\Users\Dell\AndroidStudioProjects\Sort>adb logcat -v time SortTag:V *:E

    --------- beginning of main
    --------- beginning of system
    06-09 12:51:55.725 E/memtrack(11184): Couldn't load memtrack module
    (No such file or directory)
    06-09 12:51:55.725 E/android.os.Debug(11184): failed to load memtrack
    module: -2
    06-09 12:51:56.160 E/JavaBinder( 1232): !!! FAILED BINDER TRANSACTION !!!
    06-09 12:51:56.183 E/InputDispatcher( 1232): channel '3bf07b77
    com.example.android.sort/com.example.android.
    sort.MainActivity (server)' ~ Channel is unrecoverably broken and will be
    disposed!
    06-09 12:52:05.459 E/memtrack(11290): Couldn't load memtrack module
    (No such file or directory)
    06-09 12:52:05.459 E/android.os.Debug(11290): failed to load
    memtrack module: -2
    06-09 12:52:05.527 E/art (11290): Thread attaching while runtime
    is shutting down: Binder_1

    Can anyone help me with this or let me know if any other method
    can be used. I had used emulator for execution of the program

    Program

    MainActivity.java

    package com.example.android.sort;

    public class MainActivity extends ActionBarActivity {

    TextView txtResult;
    Button BRand;
    EditText editTextName;

    public double n;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    editTextName = (EditText) findViewById(R.id.editTextName);

    txtResult = (TextView) findViewById(R.id.txtResult);
    BRand = (Button) findViewById(R.id.BRand);

    BRand.setOnClickListener(new View.OnClickListener() {

    public void onClick(View v) {
    String res="";
    int n=0;

    TimingLogger timings = new TimingLogger("SortTag","Sort");

    n=Integer.parseInt(editTextName.getText().toString());
    Random rand = new Random();
    int[] array = new int[n];
    for (int i = 0; i < n; i++){
    array[i]=i;
    }

    Collections.shuffle(Arrays.asList(array));

    for (int i = 0; i < ( n - 1 ); i++)
    {
    for (int j = 0; j < n - i - 1; j++) {
    if (array[j] < array[j+1]) {
    int temp = array[j];
    array[j] = array[j+1];
    array[j+1] = temp;
    }
    }
    }

    for(int i=0;i<n;i++)
    {
    res+=String.valueOf(array[i])+"\n";
    }
    txtResult.setMovementMethod(new ScrollingMovementMethod());
    txtResult.setText(res);
    timings.dumpToLog();
    };
    });

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
    return true;
    }

    return super.onOptionsItemSelected(item);
    }
    }
    06-09-2016 03:22 AM
  2. Rukbat's Avatar
    Just have your program log the exact time at the start of the sort and at the end of the sort. Make the calls as single-line as you can, so you can comment them out once you've gotten the sort as short as possible.
    06-10-2016 04:19 PM

Similar Threads

  1. Help me decide which case to use.
    By Blues Fan in forum Samsung Galaxy S7 Cases & Accessories
    Replies: 12
    Last Post: 06-11-2016, 06:51 PM
  2. Please help me pinpoint the cause of my battery drain
    By Cakefish in forum Samsung Galaxy S7
    Replies: 7
    Last Post: 06-10-2016, 04:23 PM
  3. Android auto wont connect w/note 5
    By AC Question in forum Android Auto
    Replies: 1
    Last Post: 06-09-2016, 08:32 PM
  4. my phone has a mind of its own..
    By AC Question in forum Ask a Question
    Replies: 2
    Last Post: 06-09-2016, 06:53 AM
  5. Replies: 1
    Last Post: 06-09-2016, 06:25 AM
LINK TO POST COPIED TO CLIPBOARD