Delete DataLog abstraction, which was almost unused.

Configuration with rtc_enable_data_logging = true was broken in cl
https://codereview.webrtc.org/2054373002/ (which deleted the
FileWrapper::WriteText method), and apparently noone noticed.

BUG=None

Review-Url: https://codereview.webrtc.org/2439473002
Cr-Commit-Position: refs/heads/master@{#14719}
This commit is contained in:
nisse 2016-10-21 01:52:55 -07:00 committed by Commit bot
parent dda1e60153
commit c4d2dc4e02
16 changed files with 0 additions and 1681 deletions

View File

@ -107,10 +107,6 @@
# Selects fixed-point code where possible.
'prefer_fixed_point%': 0,
# Enable data logging. Produces text files with data logged within engines
# which can be easily parsed for offline processing.
'enable_data_logging%': 0,
# Enables the use of protocol buffers for debug recordings.
'enable_protobuf%': 1,

View File

@ -31,10 +31,6 @@ declare_args() {
# Selects fixed-point code where possible.
rtc_prefer_fixed_point = false
# Enable data logging. Produces text files with data logged within engines
# which can be easily parsed for offline processing.
rtc_enable_data_logging = false
# Enables the use of protocol buffers for debug recordings.
rtc_enable_protobuf = true

View File

@ -32,7 +32,6 @@
#include "webrtc/modules/audio_coding/codecs/pcm16b/audio_decoder_pcm16b.h"
#include "webrtc/modules/audio_coding/codecs/pcm16b/audio_encoder_pcm16b.h"
#include "webrtc/modules/audio_coding/neteq/tools/resample_input_audio_file.h"
#include "webrtc/system_wrappers/include/data_log.h"
#include "webrtc/test/gtest.h"
#include "webrtc/test/testsupport/fileutils.h"
@ -53,9 +52,6 @@ void CompareInputOutput(const std::vector<int16_t>& input,
for (unsigned int n = 0; n < num_samples - delay; ++n) {
ASSERT_NEAR(input[n], output[channels * n + delay], tolerance)
<< "Exit test on first diff; n = " << n;
DataLog::InsertCell("CodecTest", "input", input[n]);
DataLog::InsertCell("CodecTest", "output", output[channels * n]);
DataLog::NextRow("CodecTest");
}
}
@ -113,19 +109,11 @@ class AudioDecoderTest : public ::testing::Test {
codec_input_rate_hz_ = audio_encoder_->SampleRateHz();
// Create arrays.
ASSERT_GT(data_length_, 0u) << "The test must set data_length_ > 0";
// Logging to view input and output in Matlab.
// Use 'gyp -Denable_data_logging=1' to enable logging.
DataLog::CreateLog();
DataLog::AddTable("CodecTest");
DataLog::AddColumn("CodecTest", "input", 1);
DataLog::AddColumn("CodecTest", "output", 1);
}
virtual void TearDown() {
delete decoder_;
decoder_ = NULL;
// Close log.
DataLog::ReturnLog();
}
virtual void InitEncoder() { }

View File

@ -21,9 +21,6 @@ rtc_static_library("system_wrappers") {
"include/cpu_features_wrapper.h",
"include/cpu_info.h",
"include/critical_section_wrapper.h",
"include/data_log.h",
"include/data_log_c.h",
"include/data_log_impl.h",
"include/event_wrapper.h",
"include/field_trial.h",
"include/file_wrapper.h",
@ -48,7 +45,6 @@ rtc_static_library("system_wrappers") {
"source/condition_variable_event_win.h",
"source/cpu_features.cc",
"source/cpu_info.cc",
"source/data_log_c.cc",
"source/event.cc",
"source/event_timer_posix.cc",
"source/event_timer_posix.h",
@ -75,12 +71,6 @@ rtc_static_library("system_wrappers") {
"source/trace_win.h",
]
if (rtc_enable_data_logging) {
sources += [ "source/data_log.cc" ]
} else {
sources += [ "source/data_log_no_op.cc" ]
}
defines = []
libs = []
deps = [
@ -187,9 +177,6 @@ if (rtc_include_tests) {
"source/clock_unittest.cc",
"source/condition_variable_unittest.cc",
"source/critical_section_unittest.cc",
"source/data_log_c_helpers_unittest.c",
"source/data_log_c_helpers_unittest.h",
"source/data_log_helpers_unittest.cc",
"source/event_timer_posix_unittest.cc",
"source/logging_unittest.cc",
"source/metrics_default_unittest.cc",
@ -199,13 +186,6 @@ if (rtc_include_tests) {
"source/stl_util_unittest.cc",
"source/stringize_macros_unittest.cc",
]
if (rtc_enable_data_logging) {
sources += [
"source/data_log_unittest.cc",
"source/data_log_unittest_disabled.cc",
]
}
configs += [ "//build/config/compiler:no_size_t_to_int_warning" ]
if (!build_with_chromium && is_clang) {

View File

@ -1,119 +0,0 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
// This singleton can be used for logging data for offline processing. Data
// logged with it can conveniently be parsed and processed with e.g. Matlab.
//
// Following is an example of the log file format, starting with the header
// row at line 1, and the data rows following.
// col1,col2,col3,multi-value-col4[3],,,col5
// 123,10.2,-243,1,2,3,100
// 241,12.3,233,1,2,3,200
// 13,16.4,-13,1,2,3,300
//
// As can be seen in the example, a multi-value-column is specified with the
// name followed the number of elements it contains. This followed by
// number of elements - 1 empty columns.
//
// Without multi-value-columns this format can be natively by Matlab. With
// multi-value-columns a small Matlab script is needed, available at
// trunk/tools/matlab/parseLog.m.
//
// Table names and column names are case sensitive.
#ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_DATA_LOG_H_
#define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_DATA_LOG_H_
#include <string>
#include "webrtc/system_wrappers/include/data_log_impl.h"
namespace webrtc {
class DataLog {
public:
// Creates a log which uses a separate thread (referred to as the file
// writer thread) for writing log rows to file.
//
// Calls to this function after the log object has been created will only
// increment the reference counter.
static int CreateLog();
// Decrements the reference counter and deletes the log when the counter
// reaches 0. Should be called equal number of times as successful calls to
// CreateLog or memory leak will occur.
static void ReturnLog();
// Combines the string table_name and the integer table_id into a new string
// table_name + _ + table_id. The new string will be lower-case.
static std::string Combine(const std::string& table_name, int table_id);
// Adds a new table, with the name table_name, and creates the file, with the
// name table_name + ".txt", to which the table will be written.
// table_name is treated in a case sensitive way.
static int AddTable(const std::string& table_name);
// Adds a new column to a table. The column will be a multi-value-column
// if multi_value_length is greater than 1.
// table_name and column_name are treated in a case sensitive way.
static int AddColumn(const std::string& table_name,
const std::string& column_name,
int multi_value_length);
// Inserts a single value into a table with name table_name at the column with
// name column_name.
// Note that the ValueContainer makes use of the copy constructor,
// operator= and operator<< of the type T, and that the template type must
// implement a deep copy copy constructor and operator=.
// Copy constructor and operator= must not be disabled for the type T.
// table_name and column_name are treated in a case sensitive way.
template<class T>
static int InsertCell(const std::string& table_name,
const std::string& column_name,
T value) {
DataLogImpl* data_log = DataLogImpl::StaticInstance();
if (data_log == NULL)
return -1;
return data_log->InsertCell(
table_name,
column_name,
new ValueContainer<T>(value));
}
// Inserts an array of values into a table with name table_name at the
// column specified by column_name, which must be a multi-value-column.
// Note that the MultiValueContainer makes use of the copy constructor,
// operator= and operator<< of the type T, and that the template type
// must implement a deep copy copy constructor and operator=.
// Copy constructor and operator= must not be disabled for the type T.
// table_name and column_name are treated in a case sensitive way.
template<class T>
static int InsertCell(const std::string& table_name,
const std::string& column_name,
const T* array,
int length) {
DataLogImpl* data_log = DataLogImpl::StaticInstance();
if (data_log == NULL)
return -1;
return data_log->InsertCell(
table_name,
column_name,
new MultiValueContainer<T>(array, length));
}
// For the table with name table_name: Writes the current row to file.
// Starts a new empty row.
// table_name is treated in a case-sensitive way.
static int NextRow(const std::string& table_name);
};
} // namespace webrtc
#endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_DATA_LOG_H_

View File

@ -1,85 +0,0 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
// This is a pure C wrapper of the DataLog class. The functions are directly
// mapped here except for InsertCell as C does not support templates.
// See data_log.h for a description of the functions.
#ifndef SRC_SYSTEM_WRAPPERS_INCLUDE_DATA_LOG_C_H_
#define SRC_SYSTEM_WRAPPERS_INCLUDE_DATA_LOG_C_H_
#include <stddef.h> // size_t
#include "webrtc/typedefs.h"
#ifdef __cplusplus
extern "C" {
#endif
// All char* parameters in this file are expected to be null-terminated
// character sequences.
int WebRtcDataLog_CreateLog();
void WebRtcDataLog_ReturnLog();
char* WebRtcDataLog_Combine(char* combined_name, size_t combined_len,
const char* table_name, int table_id);
int WebRtcDataLog_AddTable(const char* table_name);
int WebRtcDataLog_AddColumn(const char* table_name, const char* column_name,
int multi_value_length);
int WebRtcDataLog_InsertCell_int(const char* table_name,
const char* column_name,
int value);
int WebRtcDataLog_InsertArray_int(const char* table_name,
const char* column_name,
const int* values,
int length);
int WebRtcDataLog_InsertCell_float(const char* table_name,
const char* column_name,
float value);
int WebRtcDataLog_InsertArray_float(const char* table_name,
const char* column_name,
const float* values,
int length);
int WebRtcDataLog_InsertCell_double(const char* table_name,
const char* column_name,
double value);
int WebRtcDataLog_InsertArray_double(const char* table_name,
const char* column_name,
const double* values,
int length);
int WebRtcDataLog_InsertCell_int32(const char* table_name,
const char* column_name,
int32_t value);
int WebRtcDataLog_InsertArray_int32(const char* table_name,
const char* column_name,
const int32_t* values,
int length);
int WebRtcDataLog_InsertCell_uint32(const char* table_name,
const char* column_name,
uint32_t value);
int WebRtcDataLog_InsertArray_uint32(const char* table_name,
const char* column_name,
const uint32_t* values,
int length);
int WebRtcDataLog_InsertCell_int64(const char* table_name,
const char* column_name,
int64_t value);
int WebRtcDataLog_InsertArray_int64(const char* table_name,
const char* column_name,
const int64_t* values,
int length);
int WebRtcDataLog_NextRow(const char* table_name);
#ifdef __cplusplus
} // end of extern "C"
#endif
#endif // SRC_SYSTEM_WRAPPERS_INCLUDE_DATA_LOG_C_H_ // NOLINT

View File

@ -1,157 +0,0 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
// This file contains the helper classes for the DataLog APIs. See data_log.h
// for the APIs.
//
// These classes are helper classes used for logging data for offline
// processing. Data logged with these classes can conveniently be parsed and
// processed with e.g. Matlab.
#ifndef WEBRTC_SYSTEM_WRAPPERS_INCLUDE_DATA_LOG_IMPL_H_
#define WEBRTC_SYSTEM_WRAPPERS_INCLUDE_DATA_LOG_IMPL_H_
#include <map>
#include <memory>
#include <sstream>
#include <string>
#include <vector>
#include "webrtc/base/platform_thread.h"
#include "webrtc/typedefs.h"
namespace webrtc {
class CriticalSectionWrapper;
class EventWrapper;
class LogTable;
class RWLockWrapper;
// All container classes need to implement a ToString-function to be
// writable to file. Enforce this via the Container interface.
class Container {
public:
virtual ~Container() {}
virtual void ToString(std::string* container_string) const = 0;
};
template<class T>
class ValueContainer : public Container {
public:
explicit ValueContainer(T data) : data_(data) {}
virtual void ToString(std::string* container_string) const {
*container_string = "";
std::stringstream ss;
ss << data_ << ",";
ss >> *container_string;
}
private:
T data_;
};
template<class T>
class MultiValueContainer : public Container {
public:
MultiValueContainer(const T* data, int length)
: data_(data, data + length) {
}
virtual void ToString(std::string* container_string) const {
*container_string = "";
std::stringstream ss;
for (size_t i = 0; i < data_.size(); ++i)
ss << data_[i] << ",";
*container_string += ss.str();
}
private:
std::vector<T> data_;
};
class DataLogImpl {
public:
~DataLogImpl();
// The implementation of the CreateLog() method declared in data_log.h.
// See data_log.h for a description.
static int CreateLog();
// The implementation of the StaticInstance() method declared in data_log.h.
// See data_log.h for a description.
static DataLogImpl* StaticInstance();
// The implementation of the ReturnLog() method declared in data_log.h. See
// data_log.h for a description.
static void ReturnLog();
// The implementation of the AddTable() method declared in data_log.h. See
// data_log.h for a description.
int AddTable(const std::string& table_name);
// The implementation of the AddColumn() method declared in data_log.h. See
// data_log.h for a description.
int AddColumn(const std::string& table_name,
const std::string& column_name,
int multi_value_length);
// Inserts a Container into a table with name table_name at the column
// with name column_name.
// column_name is treated in a case sensitive way.
int InsertCell(const std::string& table_name,
const std::string& column_name,
const Container* value_container);
// The implementation of the NextRow() method declared in data_log.h. See
// data_log.h for a description.
int NextRow(const std::string& table_name);
private:
DataLogImpl();
// Initializes the DataLogImpl object, allocates and starts the
// thread file_writer_thread_.
int Init();
// Write all complete rows in every table to file.
// This function should only be called by the file_writer_thread_ if that
// thread is running to avoid race conditions.
void Flush();
// Run() is called by the thread file_writer_thread_.
static bool Run(void* obj);
// This function writes data to file. Note, it blocks if there is no data
// that should be written to file availble. Flush is the non-blocking
// version of this function.
void Process();
// Stops the continuous calling of Process().
void StopThread();
// Collection of tables indexed by the table name as std::string.
typedef std::map<std::string, LogTable*> TableMap;
typedef std::unique_ptr<CriticalSectionWrapper> CritSectScopedPtr;
static CritSectScopedPtr crit_sect_;
static DataLogImpl* instance_;
int counter_;
TableMap tables_;
EventWrapper* flush_event_;
// This is a unique_ptr so that we don't have to create threads in the no-op
// impl.
std::unique_ptr<rtc::PlatformThread> file_writer_thread_;
RWLockWrapper* tables_lock_;
};
} // namespace webrtc
#endif // WEBRTC_SYSTEM_WRAPPERS_INCLUDE_DATA_LOG_IMPL_H_

View File

@ -1,428 +0,0 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/system_wrappers/include/data_log.h"
#include <assert.h>
#include <algorithm>
#include <list>
#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
#include "webrtc/system_wrappers/include/event_wrapper.h"
#include "webrtc/system_wrappers/include/file_wrapper.h"
#include "webrtc/system_wrappers/include/rw_lock_wrapper.h"
namespace webrtc {
DataLogImpl::CritSectScopedPtr DataLogImpl::crit_sect_(
CriticalSectionWrapper::CreateCriticalSection());
DataLogImpl* DataLogImpl::instance_ = NULL;
// A Row contains cells, which are indexed by the column names as std::string.
// The string index is treated in a case sensitive way.
class Row {
public:
Row();
~Row();
// Inserts a Container into the cell of the column specified with
// column_name.
// column_name is treated in a case sensitive way.
int InsertCell(const std::string& column_name,
const Container* value_container);
// Converts the value at the column specified by column_name to a string
// stored in value_string.
// column_name is treated in a case sensitive way.
void ToString(const std::string& column_name, std::string* value_string);
private:
// Collection of containers indexed by column name as std::string
typedef std::map<std::string, const Container*> CellMap;
CellMap cells_;
CriticalSectionWrapper* cells_lock_;
};
// A LogTable contains multiple rows, where only the latest row is active for
// editing. The rows are defined by the ColumnMap, which contains the name of
// each column and the length of the column (1 for one-value-columns and greater
// than 1 for multi-value-columns).
class LogTable {
public:
LogTable();
~LogTable();
// Adds the column with name column_name to the table. The column will be a
// multi-value-column if multi_value_length is greater than 1.
// column_name is treated in a case sensitive way.
int AddColumn(const std::string& column_name, int multi_value_length);
// Buffers the current row while it is waiting to be written to file,
// which is done by a call to Flush(). A new row is available when the
// function returns
void NextRow();
// Inserts a Container into the cell of the column specified with
// column_name.
// column_name is treated in a case sensitive way.
int InsertCell(const std::string& column_name,
const Container* value_container);
// Creates a log file, named as specified in the string file_name, to
// where the table will be written when calling Flush().
int CreateLogFile(const std::string& file_name);
// Write all complete rows to file.
// May not be called by two threads simultaneously (doing so may result in
// a race condition). Will be called by the file_writer_thread_ when that
// thread is running.
void Flush();
private:
// Collection of multi_value_lengths indexed by column name as std::string
typedef std::map<std::string, int> ColumnMap;
typedef std::list<Row*> RowList;
ColumnMap columns_;
RowList rows_[2];
RowList* rows_history_;
RowList* rows_flush_;
Row* current_row_;
FileWrapper* file_;
bool write_header_;
CriticalSectionWrapper* table_lock_;
};
Row::Row()
: cells_(),
cells_lock_(CriticalSectionWrapper::CreateCriticalSection()) {
}
Row::~Row() {
for (CellMap::iterator it = cells_.begin(); it != cells_.end();) {
delete it->second;
// For maps all iterators (except the erased) are valid after an erase
cells_.erase(it++);
}
delete cells_lock_;
}
int Row::InsertCell(const std::string& column_name,
const Container* value_container) {
CriticalSectionScoped synchronize(cells_lock_);
assert(cells_.count(column_name) == 0);
if (cells_.count(column_name) > 0)
return -1;
cells_[column_name] = value_container;
return 0;
}
void Row::ToString(const std::string& column_name,
std::string* value_string) {
CriticalSectionScoped synchronize(cells_lock_);
const Container* container = cells_[column_name];
if (container == NULL) {
*value_string = "NaN,";
return;
}
container->ToString(value_string);
}
LogTable::LogTable()
: columns_(),
rows_(),
rows_history_(&rows_[0]),
rows_flush_(&rows_[1]),
current_row_(new Row),
file_(FileWrapper::Create()),
write_header_(true),
table_lock_(CriticalSectionWrapper::CreateCriticalSection()) {
}
LogTable::~LogTable() {
for (RowList::iterator row_it = rows_history_->begin();
row_it != rows_history_->end();) {
delete *row_it;
row_it = rows_history_->erase(row_it);
}
for (ColumnMap::iterator col_it = columns_.begin();
col_it != columns_.end();) {
// For maps all iterators (except the erased) are valid after an erase
columns_.erase(col_it++);
}
if (file_ != NULL) {
file_->Flush();
file_->CloseFile();
delete file_;
}
delete current_row_;
delete table_lock_;
}
int LogTable::AddColumn(const std::string& column_name,
int multi_value_length) {
assert(multi_value_length > 0);
if (!write_header_) {
// It's not allowed to add new columns after the header
// has been written.
assert(false);
return -1;
} else {
CriticalSectionScoped synchronize(table_lock_);
if (write_header_)
columns_[column_name] = multi_value_length;
else
return -1;
}
return 0;
}
void LogTable::NextRow() {
CriticalSectionScoped sync_rows(table_lock_);
rows_history_->push_back(current_row_);
current_row_ = new Row;
}
int LogTable::InsertCell(const std::string& column_name,
const Container* value_container) {
CriticalSectionScoped synchronize(table_lock_);
assert(columns_.count(column_name) > 0);
if (columns_.count(column_name) == 0)
return -1;
return current_row_->InsertCell(column_name, value_container);
}
int LogTable::CreateLogFile(const std::string& file_name) {
if (file_name.length() == 0)
return -1;
if (file_->is_open())
return -1;
// Open with read/write permissions
return file_->OpenFile(file_name.c_str(), false) ? 0 : -1;
}
void LogTable::Flush() {
ColumnMap::iterator column_it;
bool commit_header = false;
if (write_header_) {
CriticalSectionScoped synchronize(table_lock_);
if (write_header_) {
commit_header = true;
write_header_ = false;
}
}
if (commit_header) {
for (column_it = columns_.begin();
column_it != columns_.end(); ++column_it) {
if (column_it->second > 1) {
file_->WriteText("%s[%u],", column_it->first.c_str(),
column_it->second);
for (int i = 1; i < column_it->second; ++i)
file_->WriteText(",");
} else {
file_->WriteText("%s,", column_it->first.c_str());
}
}
if (columns_.size() > 0)
file_->WriteText("\n");
}
// Swap the list used for flushing with the list containing the row history
// and clear the history. We also create a local pointer to the new
// list used for flushing to avoid race conditions if another thread
// calls this function while we are writing.
// We don't want to block the list while we're writing to file.
{
CriticalSectionScoped synchronize(table_lock_);
RowList* tmp = rows_flush_;
rows_flush_ = rows_history_;
rows_history_ = tmp;
rows_history_->clear();
}
// Write all complete rows to file and delete them
for (RowList::iterator row_it = rows_flush_->begin();
row_it != rows_flush_->end();) {
for (column_it = columns_.begin();
column_it != columns_.end(); ++column_it) {
std::string row_string;
(*row_it)->ToString(column_it->first, &row_string);
file_->WriteText("%s", row_string.c_str());
}
if (columns_.size() > 0)
file_->WriteText("\n");
delete *row_it;
row_it = rows_flush_->erase(row_it);
}
}
int DataLog::CreateLog() {
return DataLogImpl::CreateLog();
}
void DataLog::ReturnLog() {
return DataLogImpl::ReturnLog();
}
std::string DataLog::Combine(const std::string& table_name, int table_id) {
std::stringstream ss;
std::string combined_id = table_name;
std::string number_suffix;
ss << "_" << table_id;
ss >> number_suffix;
combined_id += number_suffix;
std::transform(combined_id.begin(), combined_id.end(), combined_id.begin(),
::tolower);
return combined_id;
}
int DataLog::AddTable(const std::string& table_name) {
DataLogImpl* data_log = DataLogImpl::StaticInstance();
if (data_log == NULL)
return -1;
return data_log->AddTable(table_name);
}
int DataLog::AddColumn(const std::string& table_name,
const std::string& column_name,
int multi_value_length) {
DataLogImpl* data_log = DataLogImpl::StaticInstance();
if (data_log == NULL)
return -1;
return data_log->DataLogImpl::StaticInstance()->AddColumn(table_name,
column_name,
multi_value_length);
}
int DataLog::NextRow(const std::string& table_name) {
DataLogImpl* data_log = DataLogImpl::StaticInstance();
if (data_log == NULL)
return -1;
return data_log->DataLogImpl::StaticInstance()->NextRow(table_name);
}
DataLogImpl::DataLogImpl()
: counter_(1),
tables_(),
flush_event_(EventWrapper::Create()),
file_writer_thread_(
new rtc::PlatformThread(DataLogImpl::Run, instance_, "DataLog")),
tables_lock_(RWLockWrapper::CreateRWLock()) {}
DataLogImpl::~DataLogImpl() {
StopThread();
Flush(); // Write any remaining rows
delete flush_event_;
for (TableMap::iterator it = tables_.begin(); it != tables_.end();) {
delete static_cast<LogTable*>(it->second);
// For maps all iterators (except the erased) are valid after an erase
tables_.erase(it++);
}
delete tables_lock_;
}
int DataLogImpl::CreateLog() {
CriticalSectionScoped synchronize(crit_sect_.get());
if (instance_ == NULL) {
instance_ = new DataLogImpl();
return instance_->Init();
} else {
++instance_->counter_;
}
return 0;
}
int DataLogImpl::Init() {
file_writer_thread_->Start();
file_writer_thread_->SetPriority(rtc::kHighestPriority);
return 0;
}
DataLogImpl* DataLogImpl::StaticInstance() {
return instance_;
}
void DataLogImpl::ReturnLog() {
CriticalSectionScoped synchronize(crit_sect_.get());
if (instance_ && instance_->counter_ > 1) {
--instance_->counter_;
return;
}
delete instance_;
instance_ = NULL;
}
int DataLogImpl::AddTable(const std::string& table_name) {
WriteLockScoped synchronize(*tables_lock_);
// Make sure we don't add a table which already exists
if (tables_.count(table_name) > 0)
return -1;
tables_[table_name] = new LogTable();
if (tables_[table_name]->CreateLogFile(table_name + ".txt") == -1)
return -1;
return 0;
}
int DataLogImpl::AddColumn(const std::string& table_name,
const std::string& column_name,
int multi_value_length) {
ReadLockScoped synchronize(*tables_lock_);
if (tables_.count(table_name) == 0)
return -1;
return tables_[table_name]->AddColumn(column_name, multi_value_length);
}
int DataLogImpl::InsertCell(const std::string& table_name,
const std::string& column_name,
const Container* value_container) {
ReadLockScoped synchronize(*tables_lock_);
assert(tables_.count(table_name) > 0);
if (tables_.count(table_name) == 0)
return -1;
return tables_[table_name]->InsertCell(column_name, value_container);
}
int DataLogImpl::NextRow(const std::string& table_name) {
ReadLockScoped synchronize(*tables_lock_);
if (tables_.count(table_name) == 0)
return -1;
tables_[table_name]->NextRow();
// Signal a complete row
flush_event_->Set();
return 0;
}
void DataLogImpl::Flush() {
ReadLockScoped synchronize(*tables_lock_);
for (TableMap::iterator it = tables_.begin(); it != tables_.end(); ++it) {
it->second->Flush();
}
}
bool DataLogImpl::Run(void* obj) {
static_cast<DataLogImpl*>(obj)->Process();
return true;
}
void DataLogImpl::Process() {
// Wait for a row to be complete
flush_event_->Wait(WEBRTC_EVENT_INFINITE);
Flush();
}
void DataLogImpl::StopThread() {
flush_event_->Set();
file_writer_thread_->Stop();
}
} // namespace webrtc

View File

@ -1,143 +0,0 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
// This is the pure C wrapper of the DataLog class.
#include "webrtc/system_wrappers/include/data_log_c.h"
#include <string>
#include "webrtc/system_wrappers/include/data_log.h"
extern "C" int WebRtcDataLog_CreateLog() {
return webrtc::DataLog::CreateLog();
}
extern "C" void WebRtcDataLog_ReturnLog() {
return webrtc::DataLog::ReturnLog();
}
extern "C" char* WebRtcDataLog_Combine(char* combined_name, size_t combined_len,
const char* table_name, int table_id) {
if (!table_name) return NULL;
std::string combined = webrtc::DataLog::Combine(table_name, table_id);
if (combined.size() >= combined_len) return NULL;
std::copy(combined.begin(), combined.end(), combined_name);
combined_name[combined.size()] = '\0';
return combined_name;
}
extern "C" int WebRtcDataLog_AddTable(const char* table_name) {
if (!table_name) return -1;
return webrtc::DataLog::AddTable(table_name);
}
extern "C" int WebRtcDataLog_AddColumn(const char* table_name,
const char* column_name,
int multi_value_length) {
if (!table_name || !column_name) return -1;
return webrtc::DataLog::AddColumn(table_name, column_name,
multi_value_length);
}
extern "C" int WebRtcDataLog_InsertCell_int(const char* table_name,
const char* column_name,
int value) {
if (!table_name || !column_name) return -1;
return webrtc::DataLog::InsertCell(table_name, column_name, value);
}
extern "C" int WebRtcDataLog_InsertArray_int(const char* table_name,
const char* column_name,
const int* values,
int length) {
if (!table_name || !column_name) return -1;
return webrtc::DataLog::InsertCell(table_name, column_name, values, length);
}
extern "C" int WebRtcDataLog_InsertCell_float(const char* table_name,
const char* column_name,
float value) {
if (!table_name || !column_name) return -1;
return webrtc::DataLog::InsertCell(table_name, column_name, value);
}
extern "C" int WebRtcDataLog_InsertArray_float(const char* table_name,
const char* column_name,
const float* values,
int length) {
if (!table_name || !column_name) return -1;
return webrtc::DataLog::InsertCell(table_name, column_name, values, length);
}
extern "C" int WebRtcDataLog_InsertCell_double(const char* table_name,
const char* column_name,
double value) {
if (!table_name || !column_name) return -1;
return webrtc::DataLog::InsertCell(table_name, column_name, value);
}
extern "C" int WebRtcDataLog_InsertArray_double(const char* table_name,
const char* column_name,
const double* values,
int length) {
if (!table_name || !column_name) return -1;
return webrtc::DataLog::InsertCell(table_name, column_name, values, length);
}
extern "C" int WebRtcDataLog_InsertCell_int32(const char* table_name,
const char* column_name,
int32_t value) {
if (!table_name || !column_name) return -1;
return webrtc::DataLog::InsertCell(table_name, column_name, value);
}
extern "C" int WebRtcDataLog_InsertArray_int32(const char* table_name,
const char* column_name,
const int32_t* values,
int length) {
if (!table_name || !column_name) return -1;
return webrtc::DataLog::InsertCell(table_name, column_name, values, length);
}
extern "C" int WebRtcDataLog_InsertCell_uint32(const char* table_name,
const char* column_name,
uint32_t value) {
if (!table_name || !column_name) return -1;
return webrtc::DataLog::InsertCell(table_name, column_name, value);
}
extern "C" int WebRtcDataLog_InsertArray_uint32(const char* table_name,
const char* column_name,
const uint32_t* values,
int length) {
if (!table_name || !column_name) return -1;
return webrtc::DataLog::InsertCell(table_name, column_name, values, length);
}
extern "C" int WebRtcDataLog_InsertCell_int64(const char* table_name,
const char* column_name,
int64_t value) {
if (!table_name || !column_name) return -1;
return webrtc::DataLog::InsertCell(table_name, column_name, value);
}
extern "C" int WebRtcDataLog_InsertArray_int64(const char* table_name,
const char* column_name,
const int64_t* values,
int length) {
if (!table_name || !column_name) return -1;
return webrtc::DataLog::InsertCell(table_name, column_name, values, length);
}
extern "C" int WebRtcDataLog_NextRow(const char* table_name) {
if (!table_name) return -1;
return webrtc::DataLog::NextRow(table_name);
}

View File

@ -1,123 +0,0 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/system_wrappers/source/data_log_c_helpers_unittest.h"
#include <stdlib.h>
#include <string.h>
#include "webrtc/system_wrappers/include/data_log_c.h"
enum { kTestArrayLen = 4 };
static const char kTableName[] = "c_wrapper_table";
static const char kColumnName1[] = "Scalar";
static const char kColumnName2[] = "Vector";
int WebRtcDataLogCHelper_TestCreateLog() {
return WebRtcDataLog_CreateLog();
}
int WebRtcDataLogCHelper_TestReturnLog() {
WebRtcDataLog_ReturnLog();
return 0;
}
int WebRtcDataLogCHelper_TestCombine() {
const int kOutLen = strlen(kTableName) + 4; // Room for "_17" + '\0'
char* combined_name = malloc(kOutLen * sizeof(char));
char* out_ptr = WebRtcDataLog_Combine(combined_name, kOutLen, kTableName, 17);
int return_code = 0;
if (!out_ptr) {
return_code = -1;
}
if (strcmp(combined_name, "c_wrapper_table_17") != 0) {
return_code = -2;
}
free(combined_name);
return return_code;
}
int WebRtcDataLogCHelper_TestAddTable() {
return WebRtcDataLog_AddTable(kTableName);
}
int WebRtcDataLogCHelper_TestAddColumn() {
if (WebRtcDataLog_AddColumn(kTableName, kColumnName1, 1) != 0) {
return -1;
}
if (WebRtcDataLog_AddColumn(kTableName, kColumnName2, kTestArrayLen) != 0) {
return -2;
}
return 0;
}
int WebRtcDataLogCHelper_TestNextRow() {
return WebRtcDataLog_NextRow(kTableName);
}
int WebRtcDataLogCHelper_TestInsertCell_int() {
return WebRtcDataLog_InsertCell_int(kTableName, kColumnName1, 17);
}
int WebRtcDataLogCHelper_TestInsertArray_int() {
int values[kTestArrayLen] = {1, 2, 3, 4};
return WebRtcDataLog_InsertArray_int(kTableName, kColumnName2, values,
kTestArrayLen);
}
int WebRtcDataLogCHelper_TestInsertCell_float() {
return WebRtcDataLog_InsertCell_float(kTableName, kColumnName1, 17.0f);
}
int WebRtcDataLogCHelper_TestInsertArray_float() {
float values[kTestArrayLen] = {1.0f, 2.0f, 3.0f, 4.0f};
return WebRtcDataLog_InsertArray_float(kTableName, kColumnName2, values,
kTestArrayLen);
}
int WebRtcDataLogCHelper_TestInsertCell_double() {
return WebRtcDataLog_InsertCell_int(kTableName, kColumnName1, 17.0);
}
int WebRtcDataLogCHelper_TestInsertArray_double() {
double values[kTestArrayLen] = {1.0, 2.0, 3.0, 4.0};
return WebRtcDataLog_InsertArray_double(kTableName, kColumnName2, values,
kTestArrayLen);
}
int WebRtcDataLogCHelper_TestInsertCell_int32() {
return WebRtcDataLog_InsertCell_int32(kTableName, kColumnName1, 17);
}
int WebRtcDataLogCHelper_TestInsertArray_int32() {
int32_t values[kTestArrayLen] = {1, 2, 3, 4};
return WebRtcDataLog_InsertArray_int32(kTableName, kColumnName2, values,
kTestArrayLen);
}
int WebRtcDataLogCHelper_TestInsertCell_uint32() {
return WebRtcDataLog_InsertCell_uint32(kTableName, kColumnName1, 17);
}
int WebRtcDataLogCHelper_TestInsertArray_uint32() {
uint32_t values[kTestArrayLen] = {1, 2, 3, 4};
return WebRtcDataLog_InsertArray_uint32(kTableName, kColumnName2, values,
kTestArrayLen);
}
int WebRtcDataLogCHelper_TestInsertCell_int64() {
return WebRtcDataLog_InsertCell_int64(kTableName, kColumnName1, 17);
}
int WebRtcDataLogCHelper_TestInsertArray_int64() {
int64_t values[kTestArrayLen] = {1, 2, 3, 4};
return WebRtcDataLog_InsertArray_int64(kTableName, kColumnName2, values,
kTestArrayLen);
}

View File

@ -1,58 +0,0 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef SRC_SYSTEM_WRAPPERS_SOURCE_DATA_LOG_C_HELPERS_UNITTEST_H_
#define SRC_SYSTEM_WRAPPERS_SOURCE_DATA_LOG_C_HELPERS_UNITTEST_H_
#ifdef __cplusplus
extern "C" {
#endif
int WebRtcDataLogCHelper_TestCreateLog();
int WebRtcDataLogCHelper_TestReturnLog();
int WebRtcDataLogCHelper_TestCombine();
int WebRtcDataLogCHelper_TestAddTable();
int WebRtcDataLogCHelper_TestAddColumn();
int WebRtcDataLogCHelper_TestNextRow();
int WebRtcDataLogCHelper_TestInsertCell_int();
int WebRtcDataLogCHelper_TestInsertArray_int();
int WebRtcDataLogCHelper_TestInsertCell_float();
int WebRtcDataLogCHelper_TestInsertArray_float();
int WebRtcDataLogCHelper_TestInsertCell_double();
int WebRtcDataLogCHelper_TestInsertArray_double();
int WebRtcDataLogCHelper_TestInsertCell_int32();
int WebRtcDataLogCHelper_TestInsertArray_int32();
int WebRtcDataLogCHelper_TestInsertCell_uint32();
int WebRtcDataLogCHelper_TestInsertArray_uint32();
int WebRtcDataLogCHelper_TestInsertCell_int64();
int WebRtcDataLogCHelper_TestInsertArray_int64();
#ifdef __cplusplus
} // end of extern "C"
#endif
#endif // SRC_SYSTEM_WRAPPERS_SOURCE_DATA_LOG_C_HELPERS_UNITTEST_H_

View File

@ -1,65 +0,0 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/system_wrappers/include/data_log.h"
#include <string>
#include "webrtc/test/gtest.h"
using ::webrtc::DataLog;
TEST(TestDataLog, IntContainers) {
int c = 5;
webrtc::ValueContainer<int> v1(c);
c = 10;
webrtc::ValueContainer<int> v2(c);
std::string s1, s2;
v1.ToString(&s1);
v2.ToString(&s2);
ASSERT_EQ(s1, "5,");
ASSERT_EQ(s2, "10,");
v1 = v2;
v1.ToString(&s1);
ASSERT_EQ(s1, s2);
}
TEST(TestDataLog, DoubleContainers) {
double c = 3.5;
webrtc::ValueContainer<double> v1(c);
c = 10.3;
webrtc::ValueContainer<double> v2(c);
std::string s1, s2;
v1.ToString(&s1);
v2.ToString(&s2);
ASSERT_EQ(s1, "3.5,");
ASSERT_EQ(s2, "10.3,");
v1 = v2;
v1.ToString(&s1);
ASSERT_EQ(s1, s2);
}
TEST(TestDataLog, MultiValueContainers) {
int a[3] = {1, 2, 3};
int b[3] = {4, 5, 6};
webrtc::MultiValueContainer<int> m1(a, 3);
webrtc::MultiValueContainer<int> m2(b, 3);
webrtc::MultiValueContainer<int> m3(a, 3);
std::string s1, s2, s3;
m1.ToString(&s1);
m2.ToString(&s2);
ASSERT_EQ(s1, "1,2,3,");
ASSERT_EQ(s2, "4,5,6,");
m1 = m2;
m1.ToString(&s1);
ASSERT_EQ(s1, s2);
m3.ToString(&s3);
ASSERT_EQ(s3, "1,2,3,");
}

View File

@ -1,88 +0,0 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/system_wrappers/include/data_log.h"
#include <string>
namespace webrtc {
int DataLog::CreateLog() {
return 0;
}
void DataLog::ReturnLog() {
}
std::string DataLog::Combine(const std::string& table_name, int table_id) {
return std::string();
}
int DataLog::AddTable(const std::string& /*table_name*/) {
return 0;
}
int DataLog::AddColumn(const std::string& /*table_name*/,
const std::string& /*column_name*/,
int /*multi_value_length*/) {
return 0;
}
int DataLog::NextRow(const std::string& /*table_name*/) {
return 0;
}
DataLogImpl::DataLogImpl() {
}
DataLogImpl::~DataLogImpl() {
}
DataLogImpl* DataLogImpl::StaticInstance() {
return NULL;
}
void DataLogImpl::ReturnLog() {
}
int DataLogImpl::AddTable(const std::string& /*table_name*/) {
return 0;
}
int DataLogImpl::AddColumn(const std::string& /*table_name*/,
const std::string& /*column_name*/,
int /*multi_value_length*/) {
return 0;
}
int DataLogImpl::InsertCell(const std::string& /*table_name*/,
const std::string& /*column_name*/,
const Container* /*value_container*/) {
return 0;
}
int DataLogImpl::NextRow(const std::string& /*table_name*/) {
return 0;
}
void DataLogImpl::Flush() {
}
bool DataLogImpl::Run(void* /*obj*/) {
return true;
}
void DataLogImpl::Process() {
}
void DataLogImpl::StopThread() {
}
} // namespace webrtc

View File

@ -1,311 +0,0 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/system_wrappers/include/data_log.h"
#include <map>
#include <string>
#include "webrtc/system_wrappers/include/data_log_c.h"
#include "webrtc/system_wrappers/source/data_log_c_helpers_unittest.h"
#include "webrtc/test/gtest.h"
using ::webrtc::DataLog;
// A class for storing the values expected from a log table column when
// verifying a log table file.
struct ExpectedValues {
public:
ExpectedValues()
: values(),
multi_value_length(1) {
}
ExpectedValues(std::vector<std::string> expected_values,
int expected_multi_value_length)
: values(expected_values),
multi_value_length(expected_multi_value_length) {
}
std::vector<std::string> values;
int multi_value_length;
};
typedef std::map<std::string, ExpectedValues> ExpectedValuesMap;
// A static class used for parsing and verifying data log files.
class DataLogParser {
public:
// Verifies that the log table stored in the file "log_file" corresponds to
// the cells and columns specified in "columns".
static int VerifyTable(FILE* log_file, const ExpectedValuesMap& columns) {
int row = 0;
char line_buffer[kMaxLineLength];
char* ret = fgets(line_buffer, kMaxLineLength, log_file);
EXPECT_FALSE(ret == NULL);
if (ret == NULL)
return -1;
std::string line(line_buffer, kMaxLineLength);
VerifyHeader(line, columns);
while (fgets(line_buffer, kMaxLineLength, log_file) != NULL) {
line = std::string(line_buffer, kMaxLineLength);
size_t line_position = 0;
for (ExpectedValuesMap::const_iterator it = columns.begin();
it != columns.end(); ++it) {
std::string str = ParseElement(line, &line_position,
it->second.multi_value_length);
EXPECT_EQ(str, it->second.values[row]);
if (str != it->second.values[row])
return -1;
}
++row;
}
return 0;
}
// Verifies the table header stored in "line" to correspond with the header
// specified in "columns".
static int VerifyHeader(const std::string& line,
const ExpectedValuesMap& columns) {
size_t line_position = 0;
for (ExpectedValuesMap::const_iterator it = columns.begin();
it != columns.end(); ++it) {
std::string str = ParseElement(line, &line_position,
it->second.multi_value_length);
EXPECT_EQ(str, it->first);
if (str != it->first)
return -1;
}
return 0;
}
// Parses out and returns one element from the string "line", which contains
// one line read from a log table file. An element can either be a column
// header or a cell of a row.
static std::string ParseElement(const std::string& line,
size_t* line_position,
int multi_value_length) {
std::string parsed_cell;
parsed_cell = "";
for (int i = 0; i < multi_value_length; ++i) {
size_t next_separator = line.find(',', *line_position);
EXPECT_NE(next_separator, std::string::npos);
if (next_separator == std::string::npos)
break;
parsed_cell += line.substr(*line_position,
next_separator - *line_position + 1);
*line_position = next_separator + 1;
}
return parsed_cell;
}
// This constant defines the maximum line length the DataLogParser can
// parse.
enum { kMaxLineLength = 100 };
};
TEST(TestDataLog, CreateReturnTest) {
for (int i = 0; i < 10; ++i)
ASSERT_EQ(DataLog::CreateLog(), 0);
ASSERT_EQ(DataLog::AddTable(DataLog::Combine("a proper table", 1)), 0);
for (int i = 0; i < 10; ++i)
DataLog::ReturnLog();
ASSERT_LT(DataLog::AddTable(DataLog::Combine("table failure", 1)), 0);
}
TEST(TestDataLog, VerifyCombineMethod) {
EXPECT_EQ(std::string("a proper table_1"),
DataLog::Combine("a proper table", 1));
}
TEST(TestDataLog, VerifySingleTable) {
DataLog::CreateLog();
DataLog::AddTable(DataLog::Combine("table", 1));
DataLog::AddColumn(DataLog::Combine("table", 1), "arrival", 1);
DataLog::AddColumn(DataLog::Combine("table", 1), "timestamp", 1);
DataLog::AddColumn(DataLog::Combine("table", 1), "size", 5);
uint32_t sizes[5] = {1400, 1500, 1600, 1700, 1800};
for (int i = 0; i < 10; ++i) {
DataLog::InsertCell(DataLog::Combine("table", 1), "arrival",
static_cast<double>(i));
DataLog::InsertCell(DataLog::Combine("table", 1), "timestamp",
static_cast<int64_t>(4354 + i));
DataLog::InsertCell(DataLog::Combine("table", 1), "size", sizes, 5);
DataLog::NextRow(DataLog::Combine("table", 1));
}
DataLog::ReturnLog();
// Verify file
FILE* table = fopen("table_1.txt", "r");
ASSERT_FALSE(table == NULL);
// Read the column names and verify with the expected columns.
// Note that the columns are written to file in alphabetical order.
// Data expected from parsing the file
const int kNumberOfRows = 10;
std::string string_arrival[kNumberOfRows] = {
"0,", "1,", "2,", "3,", "4,",
"5,", "6,", "7,", "8,", "9,"
};
std::string string_timestamp[kNumberOfRows] = {
"4354,", "4355,", "4356,", "4357,",
"4358,", "4359,", "4360,", "4361,",
"4362,", "4363,"
};
std::string string_sizes = "1400,1500,1600,1700,1800,";
ExpectedValuesMap expected;
expected["arrival,"] = ExpectedValues(
std::vector<std::string>(string_arrival,
string_arrival +
kNumberOfRows),
1);
expected["size[5],,,,,"] = ExpectedValues(
std::vector<std::string>(10, string_sizes), 5);
expected["timestamp,"] = ExpectedValues(
std::vector<std::string>(string_timestamp,
string_timestamp +
kNumberOfRows),
1);
ASSERT_EQ(DataLogParser::VerifyTable(table, expected), 0);
fclose(table);
}
TEST(TestDataLog, VerifyMultipleTables) {
DataLog::CreateLog();
DataLog::AddTable(DataLog::Combine("table", 2));
DataLog::AddTable(DataLog::Combine("table", 3));
DataLog::AddColumn(DataLog::Combine("table", 2), "arrival", 1);
DataLog::AddColumn(DataLog::Combine("table", 2), "timestamp", 1);
DataLog::AddColumn(DataLog::Combine("table", 2), "size", 1);
DataLog::AddTable(DataLog::Combine("table", 4));
DataLog::AddColumn(DataLog::Combine("table", 3), "timestamp", 1);
DataLog::AddColumn(DataLog::Combine("table", 3), "arrival", 1);
DataLog::AddColumn(DataLog::Combine("table", 4), "size", 1);
for (int32_t i = 0; i < 10; ++i) {
DataLog::InsertCell(DataLog::Combine("table", 2), "arrival",
static_cast<int32_t>(i));
DataLog::InsertCell(DataLog::Combine("table", 2), "timestamp",
static_cast<int32_t>(4354 + i));
DataLog::InsertCell(DataLog::Combine("table", 2), "size",
static_cast<int32_t>(1200 + 10 * i));
DataLog::InsertCell(DataLog::Combine("table", 3), "timestamp",
static_cast<int32_t>(4354 + i));
DataLog::InsertCell(DataLog::Combine("table", 3), "arrival",
static_cast<int32_t>(i));
DataLog::InsertCell(DataLog::Combine("table", 4), "size",
static_cast<int32_t>(1200 + 10 * i));
DataLog::NextRow(DataLog::Combine("table", 4));
DataLog::NextRow(DataLog::Combine("table", 2));
DataLog::NextRow(DataLog::Combine("table", 3));
}
DataLog::ReturnLog();
// Data expected from parsing the file
const int kNumberOfRows = 10;
std::string string_arrival[kNumberOfRows] = {
"0,", "1,", "2,", "3,", "4,",
"5,", "6,", "7,", "8,", "9,"
};
std::string string_timestamp[kNumberOfRows] = {
"4354,", "4355,", "4356,", "4357,",
"4358,", "4359,", "4360,", "4361,",
"4362,", "4363,"
};
std::string string_size[kNumberOfRows] = {
"1200,", "1210,", "1220,", "1230,",
"1240,", "1250,", "1260,", "1270,",
"1280,", "1290,"
};
// Verify table 2
{
FILE* table = fopen("table_2.txt", "r");
ASSERT_FALSE(table == NULL);
ExpectedValuesMap expected;
expected["arrival,"] = ExpectedValues(
std::vector<std::string>(string_arrival,
string_arrival +
kNumberOfRows),
1);
expected["size,"] = ExpectedValues(
std::vector<std::string>(string_size,
string_size + kNumberOfRows),
1);
expected["timestamp,"] = ExpectedValues(
std::vector<std::string>(string_timestamp,
string_timestamp +
kNumberOfRows),
1);
ASSERT_EQ(DataLogParser::VerifyTable(table, expected), 0);
fclose(table);
}
// Verify table 3
{
FILE* table = fopen("table_3.txt", "r");
ASSERT_FALSE(table == NULL);
ExpectedValuesMap expected;
expected["arrival,"] = ExpectedValues(
std::vector<std::string>(string_arrival,
string_arrival +
kNumberOfRows),
1);
expected["timestamp,"] = ExpectedValues(
std::vector<std::string>(string_timestamp,
string_timestamp +
kNumberOfRows),
1);
ASSERT_EQ(DataLogParser::VerifyTable(table, expected), 0);
fclose(table);
}
// Verify table 4
{
FILE* table = fopen("table_4.txt", "r");
ASSERT_FALSE(table == NULL);
ExpectedValuesMap expected;
expected["size,"] = ExpectedValues(
std::vector<std::string>(string_size,
string_size +
kNumberOfRows),
1);
ASSERT_EQ(DataLogParser::VerifyTable(table, expected), 0);
fclose(table);
}
}
TEST(TestDataLogCWrapper, VerifyCWrapper) {
// Simply call all C wrapper log functions through the C helper unittests.
// Main purpose is to make sure that the linkage is correct.
EXPECT_EQ(0, WebRtcDataLogCHelper_TestCreateLog());
EXPECT_EQ(0, WebRtcDataLogCHelper_TestCombine());
EXPECT_EQ(0, WebRtcDataLogCHelper_TestAddTable());
EXPECT_EQ(0, WebRtcDataLogCHelper_TestAddColumn());
EXPECT_EQ(0, WebRtcDataLogCHelper_TestInsertCell_int());
EXPECT_EQ(0, WebRtcDataLogCHelper_TestInsertArray_int());
EXPECT_EQ(0, WebRtcDataLogCHelper_TestNextRow());
EXPECT_EQ(0, WebRtcDataLogCHelper_TestInsertCell_float());
EXPECT_EQ(0, WebRtcDataLogCHelper_TestInsertArray_float());
EXPECT_EQ(0, WebRtcDataLogCHelper_TestNextRow());
EXPECT_EQ(0, WebRtcDataLogCHelper_TestInsertCell_double());
EXPECT_EQ(0, WebRtcDataLogCHelper_TestInsertArray_double());
EXPECT_EQ(0, WebRtcDataLogCHelper_TestNextRow());
EXPECT_EQ(0, WebRtcDataLogCHelper_TestInsertCell_int32());
EXPECT_EQ(0, WebRtcDataLogCHelper_TestInsertArray_int32());
EXPECT_EQ(0, WebRtcDataLogCHelper_TestNextRow());
EXPECT_EQ(0, WebRtcDataLogCHelper_TestInsertCell_uint32());
EXPECT_EQ(0, WebRtcDataLogCHelper_TestInsertArray_uint32());
EXPECT_EQ(0, WebRtcDataLogCHelper_TestNextRow());
EXPECT_EQ(0, WebRtcDataLogCHelper_TestInsertCell_int64());
EXPECT_EQ(0, WebRtcDataLogCHelper_TestInsertArray_int64());
EXPECT_EQ(0, WebRtcDataLogCHelper_TestNextRow());
EXPECT_EQ(0, WebRtcDataLogCHelper_TestReturnLog());
}

View File

@ -1,55 +0,0 @@
/*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/system_wrappers/include/data_log.h"
#include <stdio.h>
#include "webrtc/test/gtest.h"
using ::webrtc::DataLog;
const char* kDataLogFileName = "table_1.txt";
void PerformLogging(const std::string& table_name) {
// Simulate normal DataTable logging behavior using this table name.
ASSERT_EQ(0, DataLog::AddTable(table_name));
ASSERT_EQ(0, DataLog::AddColumn(table_name, "test", 1));
for (int i = 0; i < 10; ++i) {
// TODO(kjellander): Check InsertCell result when the DataLog dummy is
// fixed.
DataLog::InsertCell(table_name, "test", static_cast<double>(i));
ASSERT_EQ(0, DataLog::NextRow(table_name));
}
}
// Simple test to verify DataLog is still working when the GYP variable
// enable_data_logging==0 (the default case).
TEST(TestDataLogDisabled, VerifyLoggingWorks) {
ASSERT_EQ(0, DataLog::CreateLog());
// Generate a table_name name and assure it's an empty string
// (dummy behavior).
std::string table_name = DataLog::Combine("table", 1);
ASSERT_EQ("", table_name);
PerformLogging(table_name);
DataLog::ReturnLog();
}
TEST(TestDataLogDisabled, EnsureNoFileIsWritten) {
// Remove any previous data files on disk:
remove(kDataLogFileName);
ASSERT_EQ(0, DataLog::CreateLog());
// Don't use the table name we would get from Combine on a disabled DataLog.
// Use "table_1" instead (which is what an enabled DataLog would give us).
PerformLogging("table_1");
DataLog::ReturnLog();
// Verify no data log file have been written:
ASSERT_EQ(NULL, fopen(kDataLogFileName, "r"));
}

View File

@ -24,9 +24,6 @@
'include/cpu_features_wrapper.h',
'include/cpu_info.h',
'include/critical_section_wrapper.h',
'include/data_log.h',
'include/data_log_c.h',
'include/data_log_impl.h',
'include/event_wrapper.h',
'include/field_trial.h',
'include/file_wrapper.h',
@ -51,7 +48,6 @@
'source/condition_variable_event_win.h',
'source/cpu_features.cc',
'source/cpu_info.cc',
'source/data_log_c.cc',
'source/event.cc',
'source/event_timer_posix.cc',
'source/event_timer_posix.h',
@ -78,11 +74,6 @@
'source/trace_win.h',
],
'conditions': [
['enable_data_logging==1', {
'sources': [ 'source/data_log.cc', ],
}, {
'sources': [ 'source/data_log_no_op.cc', ],
},],
['OS=="android"', {
'defines': [
'WEBRTC_THREAD_RR',