blob: 5b20865370a9c57c9ec5be69aeb01080c800614c [file] [log] [blame]
// Copyright 2017 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <zircon/syscalls.h>
#include <stdio.h>
#include <zircon/assert.h>
#include <async/loop.h>
#include <async/task.h>
#include <fbl/array.h>
#include <trace/handler.h>
#include "benchmarks.h"
namespace {
// Trace buffer size.
// Should be sized so it does not overflow during the test.
static constexpr size_t kBufferSizeBytes = 16 * 1024 * 1024;
class BenchmarkHandler : public trace::TraceHandler {
public:
BenchmarkHandler(async::Loop* loop)
: loop_(loop), buffer_(new uint8_t[kBufferSizeBytes], kBufferSizeBytes) {
}
void Start() {
zx_status_t status = trace_start_engine(loop_->async(), this,
buffer_.get(), buffer_.size());
ZX_DEBUG_ASSERT(status == ZX_OK);
puts("\nTrace started\n");
}
private:
bool IsCategoryEnabled(const char* category) override {
// Any category beginning with "+" is enabled.
return category[0] == '+';
}
void TraceStopped(async_t* async,
zx_status_t disposition,
size_t buffer_bytes_written) override {
puts("\nTrace stopped");
ZX_DEBUG_ASSERT(disposition == ZX_OK);
loop_->Quit();
}
async::Loop* loop_;
fbl::Array<uint8_t> buffer_;
};
} // namespace
int main(int argc, char** argv) {
async::Loop loop;
BenchmarkHandler handler(&loop);
RunTracingDisabledBenchmarks();
handler.Start();
async::Task task(0u);
task.set_handler([](async_t* async, zx_status_t status) {
RunTracingEnabledBenchmarks();
RunNoTraceBenchmarks();
trace_stop_engine(ZX_OK);
return ASYNC_TASK_FINISHED;
});
task.Post(loop.async());
loop.Run(); // run until quit
return 0;
}