RDK Documentation (Open Sourced RDK Components)
rdk_logger_milestone.cpp
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2016 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <string>
24 #include <time.h>
25 #include <sys/time.h>
26 #include "rdk_logger_milestone.h"
27 
28 #ifdef LOGMILESTONE
29 #define MILESTONE_LOG_FILENAME "/opt/logs/rdk_milestones.log"
30 #else
31 #define MILESTONE_LOG_FILENAME "/rdklogs/logs/rdk_milestones.log"
32 #endif
33 
34 unsigned long long getUptimeMS(void)
35 {
36  struct timespec uptime;
37  unsigned long long uptimems;
38 
39  //Using clock_gettime to get uptime in ms precision
40  clock_gettime(CLOCK_MONOTONIC_RAW, &uptime);
41  uptimems = (unsigned long long)uptime.tv_sec * 1000 + uptime.tv_nsec / 1000000;
42 
43  return uptimems;
44 }
45 
46 void logMilestone(const char *msg_code)
47 {
48  FILE *fp = NULL;
49  fp = fopen(MILESTONE_LOG_FILENAME, "a+");
50  if (fp != NULL)
51  {
52  fprintf(fp, "%s:%llu\n", msg_code, getUptimeMS());
53  fclose(fp);
54  }
55 }