Skip to content

Commit f4431d8

Browse files
author
sawa.huang
committed
feat: add ProcessorProfilerWrapper
1 parent a424c74 commit f4431d8

File tree

2 files changed

+83
-2
lines changed

2 files changed

+83
-2
lines changed

library/src/main/java/com/liulishuo/engzo/lingorecorder/LingoRecorder.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import android.support.annotation.NonNull;
88

99
import com.liulishuo.engzo.lingorecorder.processor.AudioProcessor;
10+
import com.liulishuo.engzo.lingorecorder.processor.ProcessorProfilerWrapper;
1011
import com.liulishuo.engzo.lingorecorder.processor.WavProcessor;
1112
import com.liulishuo.engzo.lingorecorder.recorder.AndroidRecorder;
1213
import com.liulishuo.engzo.lingorecorder.recorder.IRecorder;
@@ -61,7 +62,6 @@ public boolean isProcessing() {
6162
}
6263

6364
/**
64-
*
6565
* @deprecated use {@link #isProcessing()} instead
6666
*/
6767
@Deprecated
@@ -149,7 +149,11 @@ public void setOnVolumeListener(OnVolumeListener onVolumeListener, IVolumeCalcul
149149
}
150150

151151
public void put(String processorId, AudioProcessor processor) {
152-
audioProcessorMap.put(processorId, processor);
152+
if (ProcessorProfilerWrapper.profiler != null) {
153+
audioProcessorMap.put(processorId, new ProcessorProfilerWrapper(processorId, processor));
154+
} else {
155+
audioProcessorMap.put(processorId, processor);
156+
}
153157
}
154158

155159
public AudioProcessor remove(String processorId) {
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package com.liulishuo.engzo.lingorecorder.processor;
2+
3+
public class ProcessorProfilerWrapper implements AudioProcessor {
4+
5+
public static Profiler profiler;
6+
private AudioProcessor processor;
7+
private String name;
8+
9+
public ProcessorProfilerWrapper(String name, AudioProcessor processor) {
10+
this.processor = processor;
11+
this.name = name;
12+
}
13+
14+
@Override
15+
public void start() throws Exception {
16+
long startMethodStartTimeStamp = System.currentTimeMillis();
17+
processor.start();
18+
if (profiler != null) {
19+
profiler.start(
20+
name,
21+
System.currentTimeMillis() - startMethodStartTimeStamp
22+
);
23+
}
24+
}
25+
26+
@Override
27+
public void flow(byte[] bytes, int size) throws Exception {
28+
long flowMethodStartTimeStamp = System.currentTimeMillis();
29+
processor.flow(bytes, size);
30+
if (profiler != null) {
31+
profiler.flow(
32+
name,
33+
System.currentTimeMillis() - flowMethodStartTimeStamp
34+
);
35+
}
36+
}
37+
38+
@Override
39+
public boolean needExit() {
40+
return processor.needExit();
41+
}
42+
43+
@Override
44+
public void end() throws Exception {
45+
long endMethodStartTimeStamp = System.currentTimeMillis();
46+
processor.end();
47+
if (profiler != null) {
48+
profiler.end(
49+
name,
50+
System.currentTimeMillis() - endMethodStartTimeStamp
51+
);
52+
}
53+
}
54+
55+
@Override
56+
public void release() {
57+
long releaseMethodStartTimeStamp = System.currentTimeMillis();
58+
processor.release();
59+
if (profiler != null) {
60+
profiler.release(
61+
name,
62+
System.currentTimeMillis() - releaseMethodStartTimeStamp
63+
);
64+
}
65+
}
66+
67+
public interface Profiler {
68+
69+
void start(String name, long cost);
70+
71+
void flow(String name, long cost);
72+
73+
void end(String name, long cost);
74+
75+
void release(String name, long cost);
76+
}
77+
}

0 commit comments

Comments
 (0)