Search in sources :

Example 11 with Sample._Fields

use of edu.berkeley.cs.amplab.carat.thrift.Sample._Fields in project carat by amplab.

the class CommunicationManager method uploadSamples.

public int uploadSamples(Collection<Sample> samples) {
    CaratService.Client instance = null;
    int succeeded = 0;
    ArrayList<Sample> samplesLeft = new ArrayList<Sample>();
    registerLocal();
    try {
        instance = ProtocolClient.open(a.getApplicationContext());
        registerOnFirstRun(instance);
        for (Sample s : samples) {
            boolean success = false;
            try {
                success = instance.uploadSample(s);
            } catch (Throwable th) {
                Log.e(TAG, "Error uploading sample.", th);
            }
            if (success)
                succeeded++;
            else
                samplesLeft.add(s);
        }
        safeClose(instance);
    } catch (Throwable th) {
        Log.e(TAG, "Error refreshing main reports.", th);
        safeClose(instance);
    }
    // Do not try again. It can cause a massive sample attack on the server.
    return succeeded;
}
Also used : CaratService(edu.berkeley.cs.amplab.carat.thrift.CaratService) Sample(edu.berkeley.cs.amplab.carat.thrift.Sample) ArrayList(java.util.ArrayList)

Example 12 with Sample._Fields

use of edu.berkeley.cs.amplab.carat.thrift.Sample._Fields in project carat by amplab.

the class CaratSampleDB method queryOldestSamples.

public SortedMap<Long, Sample> queryOldestSamples(int howmany) {
    SortedMap<Long, Sample> results = new TreeMap<Long, Sample>();
    try {
        synchronized (dbLock) {
            if (db == null || !db.isOpen()) {
                try {
                    db = helper.getWritableDatabase();
                } catch (android.database.sqlite.SQLiteException ex) {
                    Log.e(TAG, "Could not open database", ex);
                    return results;
                }
            }
            String[] columns = mColumnMap.keySet().toArray(new String[mColumnMap.size()]);
            Cursor cursor = query(null, null, columns, null, null, COLUMN_TIMESTAMP + " ASC LIMIT " + howmany);
            if (cursor == null) {
                // There are no results
                return results;
            } else {
                // Log.d("CaratSampleDB", "query is successfull!");
                cursor.moveToFirst();
                while (!cursor.isAfterLast()) {
                    Sample s = fillSample(cursor);
                    if (s != null) {
                        results.put(cursor.getLong(cursor.getColumnIndex(BaseColumns._ID)), s);
                        cursor.moveToNext();
                    }
                }
                cursor.close();
            }
        }
    } catch (Throwable th) {
        Log.e(TAG, "Failed to query oldest samples!", th);
    }
    return results;
}
Also used : Sample(edu.berkeley.cs.amplab.carat.thrift.Sample) TreeMap(java.util.TreeMap) Cursor(android.database.Cursor)

Example 13 with Sample._Fields

use of edu.berkeley.cs.amplab.carat.thrift.Sample._Fields in project carat by amplab.

the class CaratSampleDB method fillSample.

/*
     * Read a sample from the current position of the cursor. TODO: Needs to be
     * updated when fields update.
     */
private Sample fillSample(Cursor cursor) {
    Sample s = null;
    byte[] sampleB = cursor.getBlob(cursor.getColumnIndex(CaratSampleDB.COLUMN_SAMPLE));
    if (sampleB != null) {
        ObjectInputStream oi;
        try {
            oi = new ObjectInputStream(new ByteArrayInputStream(sampleB));
            Object o = oi.readObject();
            if (o != null)
                s = SampleReader.readSample(o);
        } catch (StreamCorruptedException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
    return s;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Sample(edu.berkeley.cs.amplab.carat.thrift.Sample) StreamCorruptedException(java.io.StreamCorruptedException) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

Sample (edu.berkeley.cs.amplab.carat.thrift.Sample)9 Feature (edu.berkeley.cs.amplab.carat.thrift.Feature)3 ProcessInfo (edu.berkeley.cs.amplab.carat.thrift.ProcessInfo)3 HashMap (java.util.HashMap)3 ColumnStatisticsData._Fields (org.apache.hadoop.hive.metastore.api.ColumnStatisticsData._Fields)3 SharedPreferences (android.content.SharedPreferences)2 Cursor (android.database.Cursor)2 CaratSampleDB (edu.berkeley.cs.amplab.carat.android.storage.CaratSampleDB)2 BatteryDetails (edu.berkeley.cs.amplab.carat.thrift.BatteryDetails)2 CpuStatus (edu.berkeley.cs.amplab.carat.thrift.CpuStatus)2 NetworkDetails (edu.berkeley.cs.amplab.carat.thrift.NetworkDetails)2 Sample._Fields (edu.berkeley.cs.amplab.carat.thrift.Sample._Fields)2 FieldMetaData (org.apache.thrift.meta_data.FieldMetaData)2 RunningAppProcessInfo (android.app.ActivityManager.RunningAppProcessInfo)1 Context (android.content.Context)1 CaratService (edu.berkeley.cs.amplab.carat.thrift.CaratService)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 ObjectInputStream (java.io.ObjectInputStream)1 StreamCorruptedException (java.io.StreamCorruptedException)1