}
if (column == 0) {
// print time if at start of column
- char timeinfo[32];
- audio_utils_ns_to_string(time, timeinfo, array_size(timeinfo));
if (!first) {
ss << "\n";
}
- ss << prefix << " " << timeinfo << (start ? ": [ ": ": ");
+ ss << prefix << " " << audio_utils_time_string_from_ns(time).time
+ << (start ? ": [ ": ": ");
first = false;
start = false;
} else {
for (; offset >= 0; --offset) {
const auto &entry =
mEntries[(mIdx + numberOfEntries - offset) % numberOfEntries];
- char firstTime[32];
- char lastTime[32];
- audio_utils_ns_to_string(entry.mFirstTime, firstTime, sizeof(firstTime));
- audio_utils_ns_to_string(entry.mLastTime, lastTime, sizeof(lastTime));
+
ss << prefix << std::setw(5) << entry.mCode
<< " " << std::setw(5) << entry.mCount
- << " " << firstTime
- << " " << lastTime << "\n";
+ << " " << audio_utils_time_string_from_ns(entry.mFirstTime).time
+ << " " << audio_utils_time_string_from_ns(entry.mLastTime).time << "\n";
}
}
return ss.str();
for (; it != mLog.end(); ++it) {
const int64_t time = it->first;
if (time < limitNs) continue; // too old
- char timeinfo[32];
- audio_utils_ns_to_string(time, timeinfo, sizeof(timeinfo));
- ss << prefix << timeinfo << " " << it->second.c_str() << "\n";
+ ss << prefix << audio_utils_time_string_from_ns(time).time
+ << " " << it->second.c_str() << "\n";
}
return ss.str();
}
}
/**
+ * An object that contains the formatted time string.
+ *
+ * The time string is 19 characters (including null termination).
+ * Example: "03-27 16:47:06.187"
+ * MM DD HH MM SS MS
+ */
+typedef struct audio_utils_time_string {
+ char time[19]; /* minimum size buffer */
+} audio_utils_time_string_t;
+
+/**
+ * \brief Converts time in ns to a time string object, with format similar to logcat.
+ * \param ns input time in nanoseconds to convert.
+ */
+static inline audio_utils_time_string_t audio_utils_time_string_from_ns(int64_t ns)
+{
+ audio_utils_time_string_t ts;
+
+ audio_utils_ns_to_string(ns, ts.time, sizeof(ts.time));
+ return ts;
+}
+
+/**
* \brief Converts a timespec to nanoseconds.
* \param ts input timespec to convert.
* \return timespec converted to nanoseconds.