public static Pair<Point, Double> getBestMatched(Mat tmResult, int matchMethod, float threshold) { TimingLogger logger = new TimingLogger(LOG_TAG, "best_matched_point"); // FIXME: 2017/11/26 正交化? // Core.normalize(tmResult, tmResult, 0, 1, Core.NORM_MINMAX, -1, new Mat()); Core.MinMaxLocResult mmr = Core.minMaxLoc(tmResult); logger.addSplit("minMaxLoc"); double value; Point pos; if (matchMethod == Imgproc.TM_SQDIFF || matchMethod == Imgproc.TM_SQDIFF_NORMED) { pos = mmr.minLoc; value = -mmr.minVal; } else { pos = mmr.maxLoc; value = mmr.maxVal; } logger.addSplit("value:" + value); logger.dumpToLog(); return new Pair<>(pos, value); }
/** * Saves nodes to disk */ public void save() throws IOException { TimingLogger timing = new TimingLogger(TAG, "save"); // yes, parcels are not meant for persisting to disk, but they are convenient and fast // we are only serializing "simple" data (no binders etc) // + losing serialized data here would not be a problem as users can almost always refresh node data Parcel parcel = Parcel.obtain(); parcel.writeTypedList(this.nodes); File f = getFile(); FileOutputStream fileOutputStream = new FileOutputStream(f); byte[] buffer = parcel.marshall(); parcel.recycle(); fileOutputStream.write(buffer); fileOutputStream.close(); timing.dumpToLog(); }
public static <T extends ISubject> T create (Class<T> type) { if (type == null) { return null; } return (T) Proxy.newProxyInstance(type.getClassLoader(), new Class[]{type}, new InvocationHandler() { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { String tag = method.getName(); String label = method.getName(); TimingLogger timings = new TimingLogger(tag, label); // method.invoke(proxy, args); timings.dumpToLog(); return proxy; } }); }
@Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { float amount = (float)progress / seekBar.getMax(); TimingLogger timings = new TimingLogger(TAG, "makeup"); applyCosmestic(MakeupActivity.this, makeup, region, textures, colors, amount); timings.addSplit("applyCosmestic"); timings.dumpToLog(); iv_image.setImageBitmap(makeup.getIntermediateImage()); }
private void refreshNodes() { boolean mapNotInitialized = clusterManager == null; if (mapNotInitialized) return; TimingLogger timing = new TimingLogger(TAG, "refreshNodes"); // refresh screen clusterManager.onCameraChange(googleMap.getCameraPosition()); timing.addSplit("update map"); timing.dumpToLog(); }
/** * Fetches a node list from the server * * @return The parsed nodes * @throws IOException * @throws HttpException */ public static List<Node> fetchNodeList() throws IOException, HttpException { TimingLogger timing = new TimingLogger(TAG, "fetchNodeList"); HttpURLConnection conn = (HttpURLConnection) new URL("http://freifunk.inmotion-sst.de/cache/result_routers.json").openConnection(); conn.setRequestMethod("GET"); conn.setAllowUserInteraction(false); conn.setConnectTimeout(3000); conn.connect(); if (conn.getResponseCode() != HttpURLConnection.HTTP_OK) { throw new HttpException("GET did not return 200-OK"); } timing.addSplit("connect"); InputStream inputStream = conn.getInputStream(); ObjectMapper mapper = new ObjectMapper(); List<Node> result = mapper.readValue(inputStream, new TypeReference<ArrayList<Node>>() { }); timing.addSplit("parsed " + result.size()); timing.dumpToLog(); return result; }
/** * Loads nodes from disk */ public static List<Node> load(Context context) { TimingLogger timing = new TimingLogger(TAG, "load"); ArrayList<Node> nodes = new ArrayList<>(); try { Parcel parcel = Parcel.obtain(); File f = getFile(context); FileInputStream fileInputStream = new FileInputStream(f); byte[] buffer = new byte[(int) f.length()]; fileInputStream.read(buffer, 0, buffer.length); fileInputStream.close(); parcel.unmarshall(buffer, 0, buffer.length); parcel.setDataPosition(0); parcel.readTypedList(nodes, Node.CREATOR); parcel.recycle(); timing.addSplit("loaded " + nodes.size()); // trim nodes.removeAll(Collections.singleton(null)); timing.addSplit("trimmed nulls" + nodes.size()); } catch (Exception e) { Log.d(TAG, "load encountered exception, this is not a problem", e); } timing.dumpToLog(); return nodes; }
public List<PreferenceIndex> doCrawl() { final TimingLogger logger = new TimingLogger(TAG, "doCrawl"); List<PreferenceIndex> indexablePreferences = new ArrayList<>(); List<BaseIndexableFragment> indexableFragments = IndexableFragments.values(); for (BaseIndexableFragment indexableFragment : indexableFragments) { indexablePreferences.addAll(indexableFragment.index(mContext)); logger.addSplit("processed " + indexableFragment.fragmentName); } logger.addSplit("Finish crawling"); logger.dumpToLog(); return indexablePreferences; }
public void writeJson(User user) throws JSONException { TimingLogger timingLogger = new TimingLogger("TIMER", "fetchCommodities"); Dhis2Endpoint service = dhis2EndPointFactory.getEndPoint(user); DataSetSearchResponse response = service.searchDataSets("LMIS", "id,name,periodType,description,dataElements[name,id,attributeValues[value,attribute[id,name]],dataElementGroups[id,name,dataElementGroupSet[id,name],attributeValues[value,attribute[id,name]]"); timingLogger.addSplit("fetch data"); timingLogger.dumpToLog(); List<DataElementGroupSet> dataElementGroupSets = getGroupSets(response.getDataSets()); writeDataElementGroupSets(dataElementGroupSets); }
@Override public List<Category> fetchCategories(User user) { TimingLogger timingLogger = new TimingLogger("TIMER", "fetchCommodities"); Dhis2Endpoint service = dhis2EndPointFactory.getEndPoint(user); DataElementGroupSetSearchResponse response = service.getDataElementGroupSets("id,name, dataElementGroups[id,name, attributeValues[value,attribute[id,name]], dataElements[name,id,attributeValues[value,attribute[id,name]]]"); timingLogger.addSplit("fetch data"); timingLogger.dumpToLog(); List<DataSet> dataSets = fetchDataSets(user); List<DataElementGroupSet> androidDataElementGroupSets = getAndroidDataElementGroupSets(response.getDataElementGroupSets()); List<Category> categories = getCategoriesFromDataElementGroupSets(androidDataElementGroupSets, dataSets); categories = addIndicatorCommodityActions(categories, user); return categories; }
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { super.onUpdate(context, appWidgetManager, appWidgetIds); TimingLogger logger = new TimingLogger(TAG, "onUpdate"); logger.addSplit("method start"); RemoteViews remoteView = null; Intent intent = new Intent(context, MainActivity.class); intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); // Get data from database here SentCountDataManager dataManager = SentCountDataManager.newInstance(); logger.addSplit("get data from database"); SentCountDetailsVo detailsVo = dataManager.getSentCountData(context); logger.addSplit("read done, updating widgets"); // If not set in the settings, cycleLimit would be -1 int cycleLimit = (detailsVo.getCycleLimit() > 0) ? detailsVo.getCycleLimit() : 0; // update all the app widgets for (int i = 0; i < appWidgetIds.length; i++) { remoteView = new RemoteViews(context.getPackageName(), R.layout.widget_layout); // update data here remoteView.setCharSequence(R.id.widgetSentTodayText, METHOD_SET_TEXT, "" + detailsVo.getSentToday()); remoteView.setCharSequence(R.id.widgetSentInCycleText, METHOD_SET_TEXT, detailsVo.getSentCycle() + " / " + cycleLimit); remoteView.setOnClickPendingIntent(R.id.appWidget, pendingIntent); appWidgetManager.updateAppWidget(appWidgetIds[i], remoteView); } // Logging for debug purposes logger.addSplit("complete"); logger.dumpToLog(); }
public void processKMean(ClusterPoint[] points) { TimingLogger timings = new TimingLogger(TAG, "processKMean()"); // create random cluster centers initKMeanProcess(points, numOfCluster); timings.addSplit("initKMeanProcess(): values=" + points.length); int count = 1; while(count < maxRound) { updateClusters(points, mCenters); timings.addSplit("updateClusters() count " + count); calcClusterCenters(points, mNewCenters); count++; timings.addSplit("reCalcClusterCenters() count " + count); if (isStop(mCenters, mNewCenters, deviation)) break; else udpateClusterCenter(mCenters, mNewCenters); } // find out the nearest center point for each cluster findNearestPoint(points, mCenters); timings.addSplit("findNearestPoint()"); timings.addSplit("processKMean done"); timings.dumpToLog(); }
/** * If the surface changes, reset the view. * @see Renderer#onSurfaceChanged(GL10, int, int) */ public void onSurfaceChanged(GL10 gl, int width, int height) { ((GameActivity) this.context).showProgressDialog(); if(height == 0) { //Prevent A Divide By Zero By height = 1; //Making Height Equal One } Log.d(GlRenderer.class.getSimpleName(), "Screen size: " + Integer.toString(width) + "x" + Integer.toString(height)); // write to log GlRenderer.surfaceWidth = width; GlRenderer.surfaceHeight = height; gl.glViewport(0, 0, width, height); //Reset The Current Viewport gl.glMatrixMode(GL10.GL_PROJECTION); //Select The Projection Matrix gl.glLoadIdentity(); //Reset The Projection Matrix //Create the game perspective GLU.gluPerspective(gl, GlRenderer.FIELD_OF_VIEW_ANGLE, (float)width / (float)height, GlRenderer.NEAR_CLIPPING_PLANE_DEPTH, GlRenderer.FAR_CLIPPING_PLANE_DEPTH); gl.glMatrixMode(GL10.GL_MODELVIEW); //Select The Modelview Matrix gl.glLoadIdentity(); //Reset The Modelview Matrix TimingLogger timingLogger = new TimingLogger(GlRenderer.class.getSimpleName(), "onSurfaceChanged"); this.gameDrawer.initiaslise(context); //(Re)initialise this.gameDrawer.loadGame(); //Load all texture timingLogger.addSplit("loaded all textures"); timingLogger.dumpToLog(); ((GameActivity) this.context).dismissProgressDialog(); }
@Override public void loadDataOnBackground() { super.loadDataOnBackground(); if (DEBUG) timings = new TimingLogger(TAG.substring(0, 21), "loadDataOnBackground"); if (mainView == null) { return; } final boolean isFirst; if (uiUpdater != null) { isFirst = false; uiUpdater.setKilled(true); ChatSDKAbstractConversationsFragmentChatSDKThreadPool.getInstance().removeSchedule(uiUpdater); } else { isFirst = true; } final boolean hasItems = adapter != null && adapter.getThreadItems().size() > 0; if (isFirst && !hasItems) { loadData(); } uiUpdater = new UIUpdater() { @Override public void run() { if (isKilled() && !isFirst && hasItems) { return; } if (DEBUG) { timings.addSplit("Loading threads"); } List list = BNetworkManager.sharedManager().getNetworkAdapter().threadItemsWithType(BThread.Type.Private, adapter.getItemMaker()); if (DEBUG) { timings.addSplit("Loading threads"); } uiUpdater = null; Message message = new Message(); message.obj = list; message.what = 1; handler.sendMessageAtFrontOfQueue(message); if (DEBUG) timings.addSplit("Sending message to handler."); } }; ChatSDKAbstractConversationsFragmentChatSDKThreadPool.getInstance().scheduleExecute(uiUpdater,isFirst ? 1 : 0); }
@SuppressLint("NewApi") public static Bitmap NV21ToRGBABitmap(byte []nv21, int width, int height, Context context) { TimingLogger timings = new TimingLogger(TIMING_LOG_TAG, "NV21ToRGBABitmap"); Rect rect = new Rect(0, 0, width, height); try { Class.forName("android.renderscript.Element$DataKind").getField("PIXEL_YUV"); Class.forName("android.renderscript.ScriptIntrinsicYuvToRGB"); byte[] imageData = nv21; if (mRS == null) { mRS = RenderScript.create(context); mYuvToRgb = ScriptIntrinsicYuvToRGB.create(mRS, Element.U8_4(mRS)); Type.Builder tb = new Type.Builder(mRS, Element.createPixel(mRS, Element.DataType.UNSIGNED_8, Element.DataKind.PIXEL_YUV)); tb.setX(width); tb.setY(height); tb.setMipmaps(false); tb.setYuvFormat(ImageFormat.NV21); ain = Allocation.createTyped(mRS, tb.create(), Allocation.USAGE_SCRIPT); timings.addSplit("Prepare for ain"); Type.Builder tb2 = new Type.Builder(mRS, Element.RGBA_8888(mRS)); tb2.setX(width); tb2.setY(height); tb2.setMipmaps(false); aOut = Allocation.createTyped(mRS, tb2.create(), Allocation.USAGE_SCRIPT & Allocation.USAGE_SHARED); timings.addSplit("Prepare for aOut"); bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); timings.addSplit("Create Bitmap"); } ain.copyFrom(imageData); timings.addSplit("ain copyFrom"); mYuvToRgb.setInput(ain); timings.addSplit("setInput ain"); mYuvToRgb.forEach(aOut); timings.addSplit("NV21 to ARGB forEach"); aOut.copyTo(bitmap); timings.addSplit("Allocation to Bitmap"); } catch (Exception e) { YuvImage yuvImage = new YuvImage(nv21, ImageFormat.NV21, width, height, null); timings.addSplit("NV21 bytes to YuvImage"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); yuvImage.compressToJpeg(rect, 90, baos); byte[] cur = baos.toByteArray(); timings.addSplit("YuvImage crop and compress to Jpeg Bytes"); bitmap = BitmapFactory.decodeByteArray(cur, 0, cur.length); timings.addSplit("Jpeg Bytes to Bitmap"); } timings.dumpToLog(); return bitmap; }
/** * Generate and return the {@link ActionPalette} synchronously. */ public ActionPalette generate() { final TimingLogger logger = LOG_TIMINGS ? new TimingLogger(LOG_TAG, "Generation") : null; List<Swatch> swatches; if (mBitmap != null) { // We have a Bitmap so we need to quantization to reduce the number of colors if (mResizeMaxDimension <= 0) { throw new IllegalArgumentException( "Minimum dimension size for resizing should should be >= 1"); } // First we'll scale down the bitmap so it's largest dimension is as specified final Bitmap scaledBitmap = scaleBitmapDown(mBitmap, mResizeMaxDimension); if (logger != null) { logger.addSplit("Processed Bitmap"); } // Now generate a quantizer from the Bitmap ColorCutQuantizer quantizer = ColorCutQuantizer .fromBitmap(scaledBitmap, mMaxColors); // If created a new bitmap, recycle it if (scaledBitmap != mBitmap) { scaledBitmap.recycle(); } swatches = quantizer.getQuantizedColors(); if (logger != null) { logger.addSplit("Color quantization completed"); } } else { // Else we're using the provided swatches swatches = mSwatches; } // If we haven't been provided with a generator, use the default if (mGenerator == null) { mGenerator = new DefaultGenerator(); } // Now call let the Generator do it's thing mGenerator.generate(swatches); if (logger != null) { logger.addSplit("Generator.generate() completed"); } // Now create a ActionPalette instance ActionPalette p = new ActionPalette(swatches, mGenerator); if (logger != null) { logger.addSplit("Created ActionPalette"); logger.dumpToLog(); } return p; }
public void initialise(User user) { TimingLogger timingLogger = new TimingLogger("TIMER", "initialise"); List<Category> categories = lmisServer.fetchCategories(user); timingLogger.addSplit("fetch all cats"); saveToDatabase(categories); timingLogger.addSplit("save all Cats"); categoryService.clearCache(); syncConstants(user); timingLogger.addSplit("sync constants"); timingLogger.addSplit("all"); Log.i("Inital sync:", "<========== syncing Commodity Action Values"); commodityActionService.syncCommodityActionValues(user); timingLogger.addSplit("actionValues"); categoryService.clearCache(); updateStockValues(all()); categoryService.clearCache(); createInitialStockItemSnapShots(all()); timingLogger.addSplit("updateStockValues"); List<CommodityAction> allocationId = commodityActionService.getAllocationIds(); if (allocationId != null && allocationId.size() > 0) { Log.e("AllocationId Found", allocationId.get(0).toString()); timingLogger.addSplit("sync allocations"); allocationService.syncAllocations(user); } else { Log.e("AllocationId", "Not found"); } categoryService.clearCache(); timingLogger.addSplit("clearCache"); timingLogger.addSplit("sync indicator values"); commodityActionService.syncIndicatorValues(user, all()); timingLogger.dumpToLog(); }