alsa_conformance_test: Show the run time of snd_pcm_prepare

Compute and show the run time of snd_pcm_prepare.

BUG=None
TEST=Show the run time of snd_pcm_prepare on Zork

Change-Id: Ifbb978f6fe8ddc058793053ad4128cbd7ba9f5e0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/audiotest/+/2359321
Reviewed-by: Cheng-Yi Chiang <cychiang@chromium.org>
Tested-by: Yu-Hsuan Hsu <yuhsuan@chromium.org>
Commit-Queue: Yu-Hsuan Hsu <yuhsuan@chromium.org>
diff --git a/alsa_conformance_test.md b/alsa_conformance_test.md
index d501faf..b4600a6 100644
--- a/alsa_conformance_test.md
+++ b/alsa_conformance_test.md
@@ -212,6 +212,7 @@
 snd_pcm_hw_params                  0.039304997                    1             0.039305
 snd_pcm_hw_params_any              0.000055113                    1             0.000055
 snd_pcm_sw_params                  0.000017586                    1             0.000018
+snd_pcm_prepare                    0.000007613                    1             0.000008
 snd_pcm_start                      0.000774880                    1             0.000775
 snd_pcm_avail                      0.807074662               246177             0.000003
 precision: 0.000000001
diff --git a/alsa_conformance_test/alsa_conformance_helper.c b/alsa_conformance_test/alsa_conformance_helper.c
index 45cfbdb..28e0d82 100644
--- a/alsa_conformance_test/alsa_conformance_helper.c
+++ b/alsa_conformance_test/alsa_conformance_helper.c
@@ -420,10 +420,12 @@
 	return 0;
 }
 
-int alsa_helper_prepare(snd_pcm_t *handle)
+int alsa_helper_prepare(struct alsa_conformance_timer *timer, snd_pcm_t *handle)
 {
 	int rc;
+	conformance_timer_start(timer, SND_PCM_PREPARE);
 	rc = snd_pcm_prepare(handle);
+	conformance_timer_stop(timer, SND_PCM_PREPARE);
 	if (rc < 0) {
 		fprintf(stderr, "snd_pcm_prepare: %s\n", snd_strerror(rc));
 		return rc;
diff --git a/alsa_conformance_test/alsa_conformance_helper.h b/alsa_conformance_test/alsa_conformance_helper.h
index ba7ca55..523183d 100644
--- a/alsa_conformance_test/alsa_conformance_helper.h
+++ b/alsa_conformance_test/alsa_conformance_helper.h
@@ -125,11 +125,13 @@
 
 /* Prepare an alsa device. A thin wrapper to snd_pcm_prepare.
  * Args:
+ *    timer - A pointer to timer which records the runtime of ALSA APIs.
  *    handle - The open PCM to configure.
  * Returns:
  *    0 on success, negative error on failure.
  */
-int alsa_helper_prepare(snd_pcm_t *handle);
+int alsa_helper_prepare(struct alsa_conformance_timer *timer,
+			snd_pcm_t *handle);
 
 /* Starts an alsa device. A thin wrapper to snd_pcm_start.
  * Args:
diff --git a/alsa_conformance_test/alsa_conformance_thread.c b/alsa_conformance_test/alsa_conformance_thread.c
index 79bef76..9eaa3db 100644
--- a/alsa_conformance_test/alsa_conformance_thread.c
+++ b/alsa_conformance_test/alsa_conformance_thread.c
@@ -254,7 +254,7 @@
 	timer = thread->timer;
 	block_size = (snd_pcm_uframes_t)thread->block_size;
 
-	if (alsa_helper_prepare(handle) < 0)
+	if (alsa_helper_prepare(timer, handle) < 0)
 		exit(EXIT_FAILURE);
 
 	/* Get device buffer size. */
@@ -408,7 +408,7 @@
 	handle = thread->handle;
 	timer = thread->timer;
 	block_size = (snd_pcm_uframes_t)thread->block_size;
-	if (alsa_helper_prepare(handle) < 0)
+	if (alsa_helper_prepare(timer, handle) < 0)
 		exit(EXIT_FAILURE);
 
 	/* Get device buffer size. */
diff --git a/alsa_conformance_test/alsa_conformance_timer.h b/alsa_conformance_test/alsa_conformance_timer.h
index 566ce61..fb42fdf 100644
--- a/alsa_conformance_test/alsa_conformance_timer.h
+++ b/alsa_conformance_test/alsa_conformance_timer.h
@@ -16,6 +16,7 @@
 	SND_PCM_HW_PARAMS,
 	SND_PCM_HW_PARAMS_ANY,
 	SND_PCM_SW_PARAMS,
+	SND_PCM_PREPARE,
 	SND_PCM_START,
 	SND_PCM_AVAIL,
 	ALSA_API_COUNT /* Keep it in the last line to count total amounts. */
@@ -32,6 +33,7 @@
 		ENUM_STR(SND_PCM_HW_PARAMS)
 		ENUM_STR(SND_PCM_HW_PARAMS_ANY)
 		ENUM_STR(SND_PCM_SW_PARAMS)
+		ENUM_STR(SND_PCM_PREPARE)
 		ENUM_STR(SND_PCM_START)
 		ENUM_STR(SND_PCM_AVAIL)
 	default: