1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #define LOG_TAG "oslo_get_stats"
18 
19 #include <errno.h>
20 #include <log/log.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <sys/ioctl.h>
24 
25 #include "oslo_iaxxx_sensor_control.h"
26 
main(int argc,char * argv[])27 int main(int argc, char *argv[]) {
28     (void)(argc);
29     (void)(argv);
30     int rc = 0;
31     struct ia_sensor_mgr *smd;
32     struct iaxxx_sensor_mode_stats sensor_stats[SENSOR_NUM_MODE];
33     int i;
34 
35     smd = iaxxx_sensor_mgr_init();
36     if (NULL == smd) {
37         fprintf(stderr, "%s: ERROR Failed to init ia_sensor_mgr\n", __func__);
38         ALOGE("%s: ERROR Failed to init ia_sensor_mgr\n", __func__);
39         rc = -ENOMEM;
40         goto out;
41     }
42 
43     oslo_driver_set_param(smd, SENSOR_PARAM_DUMP_STATS, 1);
44     rc = oslo_driver_get_stats(smd, sensor_stats);
45     if (rc != 0) {
46         fprintf(stderr, "%s: ERROR Failed to get stats\n", __func__);
47         ALOGE("%s: ERROR Failed to get stats\n", __func__);
48         goto out_err_get_stats;
49     }
50 
51     for (i = 0; i < SENSOR_NUM_MODE; i++) {
52         fprintf(stdout, "Stats for Sensor Mode %d\n", i);
53         ALOGI("Stats for Sensor Mode %d\n", i);
54 
55         fprintf(stdout, "--------------------------\n");
56         ALOGI("--------------------------\n");
57 
58         fprintf(stdout, "Total Number of Entries is %" PRIu64 "\n",
59                 sensor_stats[i].totalNumEntries);
60         ALOGI("Total Number of Entries is %" PRIu64 "\n", sensor_stats[i].totalNumEntries);
61 
62         fprintf(stdout, "Total time spent (in Ms) is %" PRIu64 "\n",
63                 sensor_stats[i].totalTimeSpentMs);
64         ALOGI("Total time spent (in Ms) is %" PRIu64 "\n", sensor_stats[i].totalTimeSpentMs);
65 
66         fprintf(stdout, "Time stamp for Last Entry is %" PRIu64 "\n",
67                 sensor_stats[i].lastEntryTimeStampMs);
68         ALOGI("Time stamp for Last Entry is %" PRIu64 "\n", sensor_stats[i].lastEntryTimeStampMs);
69 
70         fprintf(stdout, "Time stamp for Last Exit is %" PRIu64 "\n",
71                 sensor_stats[i].lastExitTimeStampMs);
72         ALOGI("Time stamp for Last Exit is %" PRIu64 "\n", sensor_stats[i].lastExitTimeStampMs);
73 
74         fprintf(stdout, "\n");
75         ALOGD("\n");
76     }
77 
78 out_err_get_stats:
79     iaxxx_sensor_mgr_deinit(smd);
80 out:
81 
82     return rc;
83 }
84