Initial Alloy implementation.
This is a regression in functionality and performance, but a much better foundation for the future of the project (I think). It can run basic apps under an SSA interpreter but doesn't support some of the features required to do real 360 apps yet.
This commit is contained in:
20
src/alloy/tracing/channel.cc
Normal file
20
src/alloy/tracing/channel.cc
Normal file
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* Xenia : Xbox 360 Emulator Research Project *
|
||||
******************************************************************************
|
||||
* Copyright 2013 Ben Vanik. All rights reserved. *
|
||||
* Released under the BSD license - see LICENSE in the root for more details. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include <alloy/tracing/channel.h>
|
||||
|
||||
using namespace alloy;
|
||||
using namespace alloy::tracing;
|
||||
|
||||
|
||||
Channel::Channel() {
|
||||
}
|
||||
|
||||
Channel::~Channel() {
|
||||
}
|
||||
36
src/alloy/tracing/channel.h
Normal file
36
src/alloy/tracing/channel.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* Xenia : Xbox 360 Emulator Research Project *
|
||||
******************************************************************************
|
||||
* Copyright 2013 Ben Vanik. All rights reserved. *
|
||||
* Released under the BSD license - see LICENSE in the root for more details. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef ALLOY_TRACING_CHANNEL_H_
|
||||
#define ALLOY_TRACING_CHANNEL_H_
|
||||
|
||||
#include <alloy/core.h>
|
||||
|
||||
|
||||
namespace alloy {
|
||||
namespace tracing {
|
||||
|
||||
|
||||
class Channel {
|
||||
public:
|
||||
Channel();
|
||||
virtual ~Channel();
|
||||
|
||||
virtual void Write(
|
||||
size_t buffer_count,
|
||||
size_t buffer_lengths[], const uint8_t* buffers[]) = 0;
|
||||
virtual void Flush() = 0;
|
||||
};
|
||||
|
||||
|
||||
} // namespace tracing
|
||||
} // namespace alloy
|
||||
|
||||
|
||||
#endif // ALLOY_TRACING_CHANNEL_H_
|
||||
51
src/alloy/tracing/channels/file_channel.cc
Normal file
51
src/alloy/tracing/channels/file_channel.cc
Normal file
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* Xenia : Xbox 360 Emulator Research Project *
|
||||
******************************************************************************
|
||||
* Copyright 2013 Ben Vanik. All rights reserved. *
|
||||
* Released under the BSD license - see LICENSE in the root for more details. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include <alloy/tracing/channels/file_channel.h>
|
||||
|
||||
using namespace alloy;
|
||||
using namespace alloy::tracing;
|
||||
using namespace alloy::tracing::channels;
|
||||
|
||||
|
||||
FileChannel::FileChannel(const char* path) {
|
||||
lock_ = AllocMutex(10000);
|
||||
path_ = xestrdupa(path);
|
||||
file_ = fopen(path, "wb");
|
||||
}
|
||||
|
||||
FileChannel::~FileChannel() {
|
||||
LockMutex(lock_);
|
||||
fclose(file_);
|
||||
file_ = 0;
|
||||
free(path_);
|
||||
path_ = 0;
|
||||
UnlockMutex(lock_);
|
||||
FreeMutex(lock_);
|
||||
}
|
||||
|
||||
void FileChannel::Write(
|
||||
size_t buffer_count,
|
||||
size_t buffer_lengths[], const uint8_t* buffers[]) {
|
||||
LockMutex(lock_);
|
||||
if (file_) {
|
||||
for (size_t n = 0; n < buffer_count; n++) {
|
||||
fwrite(buffers[n], buffer_lengths[n], 1, file_);
|
||||
}
|
||||
}
|
||||
UnlockMutex(lock_);
|
||||
}
|
||||
|
||||
void FileChannel::Flush() {
|
||||
LockMutex(lock_);
|
||||
if (file_) {
|
||||
fflush(file_);
|
||||
}
|
||||
UnlockMutex(lock_);
|
||||
}
|
||||
46
src/alloy/tracing/channels/file_channel.h
Normal file
46
src/alloy/tracing/channels/file_channel.h
Normal file
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* Xenia : Xbox 360 Emulator Research Project *
|
||||
******************************************************************************
|
||||
* Copyright 2013 Ben Vanik. All rights reserved. *
|
||||
* Released under the BSD license - see LICENSE in the root for more details. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef ALLOY_TRACING_CHANNELS_FILE_CHANNEL_H_
|
||||
#define ALLOY_TRACING_CHANNELS_FILE_CHANNEL_H_
|
||||
|
||||
#include <alloy/core.h>
|
||||
|
||||
#include <alloy/tracing/channel.h>
|
||||
|
||||
|
||||
namespace alloy {
|
||||
namespace tracing {
|
||||
namespace channels {
|
||||
|
||||
|
||||
class FileChannel : public Channel {
|
||||
public:
|
||||
FileChannel(const char* path);
|
||||
virtual ~FileChannel();
|
||||
|
||||
virtual void Write(
|
||||
size_t buffer_count,
|
||||
size_t buffer_lengths[], const uint8_t* buffers[]);
|
||||
|
||||
virtual void Flush();
|
||||
|
||||
private:
|
||||
char* path_;
|
||||
FILE* file_;
|
||||
Mutex* lock_;
|
||||
};
|
||||
|
||||
|
||||
} // namespace channels
|
||||
} // namespace tracing
|
||||
} // namespace alloy
|
||||
|
||||
|
||||
#endif // ALLOY_TRACING_CHANNELS_FILE_CHANNEL_H_
|
||||
7
src/alloy/tracing/channels/sources.gypi
Normal file
7
src/alloy/tracing/channels/sources.gypi
Normal file
@@ -0,0 +1,7 @@
|
||||
# Copyright 2013 Ben Vanik. All Rights Reserved.
|
||||
{
|
||||
'sources': [
|
||||
'file_channel.cc',
|
||||
'file_channel.h',
|
||||
],
|
||||
}
|
||||
49
src/alloy/tracing/event_type.h
Normal file
49
src/alloy/tracing/event_type.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* Xenia : Xbox 360 Emulator Research Project *
|
||||
******************************************************************************
|
||||
* Copyright 2013 Ben Vanik. All rights reserved. *
|
||||
* Released under the BSD license - see LICENSE in the root for more details. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef ALLOY_TRACING_EVENT_TYPES_H_
|
||||
#define ALLOY_TRACING_EVENT_TYPES_H_
|
||||
|
||||
#include <alloy/core.h>
|
||||
|
||||
|
||||
namespace alloy {
|
||||
namespace tracing {
|
||||
|
||||
|
||||
class EventType {
|
||||
public:
|
||||
enum {
|
||||
ALLOY = (0 << 31),
|
||||
ALLOY_TRACE_INIT = ALLOY | (1),
|
||||
ALLOY_TRACE_EOF = ALLOY | (2),
|
||||
|
||||
ALLOY_BACKEND = ALLOY | (1 << 26),
|
||||
ALLOY_COMPILER = ALLOY | (2 << 26),
|
||||
ALLOY_HIR = ALLOY | (3 << 26),
|
||||
ALLOY_FRONTEND = ALLOY | (4 << 26),
|
||||
ALLOY_RUNTIME = ALLOY | (5 << 26),
|
||||
|
||||
USER = (1 << 31),
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
static const uint32_t event_type = ALLOY_TRACE_INIT;
|
||||
} TraceInit;
|
||||
typedef struct {
|
||||
static const uint32_t event_type = ALLOY_TRACE_EOF;
|
||||
} TraceEOF;
|
||||
};
|
||||
|
||||
|
||||
} // namespace tracing
|
||||
} // namespace alloy
|
||||
|
||||
|
||||
#endif // ALLOY_TRACING_EVENT_TYPES_H_
|
||||
16
src/alloy/tracing/sources.gypi
Normal file
16
src/alloy/tracing/sources.gypi
Normal file
@@ -0,0 +1,16 @@
|
||||
# Copyright 2013 Ben Vanik. All Rights Reserved.
|
||||
{
|
||||
'sources': [
|
||||
'channel.cc',
|
||||
'channel.h',
|
||||
'event_type.h',
|
||||
'tracer.cc',
|
||||
'tracer.h',
|
||||
'tracing.cc',
|
||||
'tracing.h',
|
||||
],
|
||||
|
||||
'includes': [
|
||||
'channels/sources.gypi',
|
||||
],
|
||||
}
|
||||
51
src/alloy/tracing/tracer.cc
Normal file
51
src/alloy/tracing/tracer.cc
Normal file
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* Xenia : Xbox 360 Emulator Research Project *
|
||||
******************************************************************************
|
||||
* Copyright 2013 Ben Vanik. All rights reserved. *
|
||||
* Released under the BSD license - see LICENSE in the root for more details. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include <alloy/tracing/tracer.h>
|
||||
|
||||
#include <alloy/tracing/channel.h>
|
||||
|
||||
using namespace alloy;
|
||||
using namespace alloy::tracing;
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
volatile int next_thread_id_ = 0x10000000;
|
||||
|
||||
};
|
||||
|
||||
|
||||
Tracer::Tracer(Channel* channel) :
|
||||
channel_(channel) {
|
||||
thread_id_ = xe_atomic_inc_32(&next_thread_id_);
|
||||
}
|
||||
|
||||
Tracer::~Tracer() {
|
||||
}
|
||||
|
||||
void Tracer::WriteEvent(
|
||||
uint32_t event_type, size_t size, const uint8_t* data) {
|
||||
uint32_t header[] = {
|
||||
event_type,
|
||||
(uint32_t)thread_id_,
|
||||
0, // time in us
|
||||
(uint32_t)size,
|
||||
};
|
||||
size_t buffer_count = size ? 2 : 1;
|
||||
size_t buffer_lengths[] = {
|
||||
sizeof(header),
|
||||
size,
|
||||
};
|
||||
const uint8_t* buffers[] = {
|
||||
(const uint8_t*)header,
|
||||
data,
|
||||
};
|
||||
channel_->Write(buffer_count, buffer_lengths, buffers);
|
||||
}
|
||||
43
src/alloy/tracing/tracer.h
Normal file
43
src/alloy/tracing/tracer.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* Xenia : Xbox 360 Emulator Research Project *
|
||||
******************************************************************************
|
||||
* Copyright 2013 Ben Vanik. All rights reserved. *
|
||||
* Released under the BSD license - see LICENSE in the root for more details. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef ALLOY_TRACING_TRACER_H_
|
||||
#define ALLOY_TRACING_TRACER_H_
|
||||
|
||||
#include <alloy/core.h>
|
||||
|
||||
|
||||
namespace alloy {
|
||||
namespace tracing {
|
||||
|
||||
class Channel;
|
||||
|
||||
|
||||
class Tracer {
|
||||
public:
|
||||
Tracer(Channel* channel);
|
||||
~Tracer();
|
||||
|
||||
int thread_id() const { return thread_id_; }
|
||||
void set_thread_id(int value) { thread_id_ = value; }
|
||||
|
||||
void WriteEvent(
|
||||
uint32_t event_type, size_t size = 0, const uint8_t* data = 0);
|
||||
|
||||
private:
|
||||
Channel* channel_;
|
||||
int thread_id_;
|
||||
};
|
||||
|
||||
|
||||
} // namespace tracing
|
||||
} // namespace alloy
|
||||
|
||||
|
||||
#endif // ALLOY_TRACING_TRACER_H_
|
||||
94
src/alloy/tracing/tracing.cc
Normal file
94
src/alloy/tracing/tracing.cc
Normal file
@@ -0,0 +1,94 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* Xenia : Xbox 360 Emulator Research Project *
|
||||
******************************************************************************
|
||||
* Copyright 2013 Ben Vanik. All rights reserved. *
|
||||
* Released under the BSD license - see LICENSE in the root for more details. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include <alloy/tracing/tracing.h>
|
||||
|
||||
#include <thread>
|
||||
#include <gflags/gflags.h>
|
||||
|
||||
#include <alloy/tracing/channel.h>
|
||||
#include <alloy/tracing/event_type.h>
|
||||
#include <alloy/tracing/tracer.h>
|
||||
#include <alloy/tracing/channels/file_channel.h>
|
||||
|
||||
using namespace alloy;
|
||||
using namespace alloy::tracing;
|
||||
|
||||
|
||||
DEFINE_string(trace_file, "",
|
||||
"Traces to the given file path.");
|
||||
// trace shared memory
|
||||
// trace socket
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
static Channel* shared_channel = NULL;
|
||||
__declspec(thread) Tracer* thread_tracer = NULL;
|
||||
|
||||
void CleanupTracing() {
|
||||
if (shared_channel) {
|
||||
alloy::tracing::WriteEvent(EventType::TraceEOF({
|
||||
}));
|
||||
shared_channel->Flush();
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
bool alloy::tracing::Initialize(Channel* channel) {
|
||||
if (shared_channel) {
|
||||
return false;
|
||||
}
|
||||
if (!channel) {
|
||||
// Create from flags.
|
||||
if (FLAGS_trace_file.size()) {
|
||||
channel = new channels::FileChannel(FLAGS_trace_file.c_str());
|
||||
}
|
||||
if (!channel) {
|
||||
// Tracing disabled.
|
||||
return true;
|
||||
}
|
||||
}
|
||||
shared_channel = channel;
|
||||
alloy::tracing::WriteEvent(EventType::TraceInit({
|
||||
}));
|
||||
channel->Flush();
|
||||
atexit(CleanupTracing);
|
||||
return true;
|
||||
}
|
||||
|
||||
void alloy::tracing::Shutdown() {
|
||||
// ?
|
||||
}
|
||||
|
||||
void alloy::tracing::Flush() {
|
||||
if (shared_channel) {
|
||||
shared_channel->Flush();
|
||||
}
|
||||
}
|
||||
|
||||
Tracer* alloy::tracing::GetThreadTracer() {
|
||||
if (!shared_channel) {
|
||||
return NULL;
|
||||
}
|
||||
if (!thread_tracer) {
|
||||
thread_tracer = new Tracer(shared_channel);
|
||||
}
|
||||
return thread_tracer;
|
||||
}
|
||||
|
||||
void alloy::tracing::WriteEvent(
|
||||
uint32_t event_type, size_t size, const void* data) {
|
||||
Tracer* t = GetThreadTracer();
|
||||
if (t) {
|
||||
t->WriteEvent(event_type, size, (const uint8_t*)data);
|
||||
}
|
||||
}
|
||||
46
src/alloy/tracing/tracing.h
Normal file
46
src/alloy/tracing/tracing.h
Normal file
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* Xenia : Xbox 360 Emulator Research Project *
|
||||
******************************************************************************
|
||||
* Copyright 2013 Ben Vanik. All rights reserved. *
|
||||
* Released under the BSD license - see LICENSE in the root for more details. *
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef ALLOY_TRACING_TRACING_H_
|
||||
#define ALLOY_TRACING_TRACING_H_
|
||||
|
||||
#include <alloy/core.h>
|
||||
|
||||
#include <alloy/tracing/event_type.h>
|
||||
|
||||
|
||||
namespace alloy {
|
||||
namespace tracing {
|
||||
|
||||
class Channel;
|
||||
class Tracer;
|
||||
|
||||
|
||||
bool Initialize(Channel* channel = 0);
|
||||
void Shutdown();
|
||||
void Flush();
|
||||
|
||||
Tracer* GetThreadTracer();
|
||||
|
||||
void WriteEvent(uint32_t event_type, size_t size = 0, const void* data = 0);
|
||||
|
||||
template<typename T> void WriteEvent(T& ev) {
|
||||
if (sizeof(T) > 1) {
|
||||
alloy::tracing::WriteEvent(T::event_type, sizeof(T), &ev);
|
||||
} else {
|
||||
alloy::tracing::WriteEvent(T::event_type);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} // namespace tracing
|
||||
} // namespace alloy
|
||||
|
||||
|
||||
#endif // ALLOY_TRACING_TRACING_H_
|
||||
Reference in New Issue
Block a user