repo
string | commit
string | message
string | diff
string |
---|---|---|---|
jhasse/jntetri
|
5288c37c3ebb4668f81d09e2f1f4b5189516c5a0
|
Login as anonymous user when not using a username
|
diff --git a/server/Client.cpp b/server/Client.cpp
index 2182354..b0ab0d9 100644
--- a/server/Client.cpp
+++ b/server/Client.cpp
@@ -1,216 +1,227 @@
#include "Client.hpp"
#include "Server.hpp"
#include "NetworkConstants.hpp"
#include <boost/array.hpp>
#include <boost/bind.hpp>
#include <iostream>
#include <nlohmann/json.hpp>
#include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/spdlog.h>
#include <thread>
+using nlohmann::json;
+
Client::Client(Server& server, boost::asio::ip::tcp::socket socket)
: socket(std::move(socket)), server(server) {
commands["login"] = {false, std::bind(&Client::login, this, std::placeholders::_1, std::placeholders::_2)};
+ commands["login_anonymous"] = {false, std::bind(&Client::login_anonymous, this, std::placeholders::_1, std::placeholders::_2)};
commands["chat"] = {true, std::bind(&Client::chat, this, std::placeholders::_1, std::placeholders::_2)};
commands["game"] = {true, std::bind(&Client::game, this, std::placeholders::_1, std::placeholders::_2)};
commands["play"] = {true, std::bind(&Client::play, this, std::placeholders::_1, std::placeholders::_2)};
commands["register"] = {false, std::bind(&Client::register_user, this, std::placeholders::_1, std::placeholders::_2)};
commands["quit"] = {true, std::bind(&Client::quit, this, std::placeholders::_1, std::placeholders::_2)};
}
void Client::login(boost::asio::yield_context yield, nlohmann::json data) {
std::string user = data["name"];
std::string password = data["password"];
spdlog::info("login attempt from '{}' with password of length {}", user, password.size());
switch(server.checkLogin(user, password)) {
case LoginState::UserDoesNotExist:
errAndDisconnect(yield, "unknown name", "", false);
break;
case LoginState::PasswordOK: {
- createLogger("client " + user);
- log().info("accepted password, sending \"ok\" ...");
- username = user;
- const auto msg = server.loginAndGetWelcomeMessage(yield, user);
- okMsg(yield);
- sendChatLine(yield, msg);
+ loginAs(yield, std::move(user));
break;
}
case LoginState::PasswordWrong:
errAndDisconnect(yield, "wrong password", "", false);
break;
}
}
+void Client::login_anonymous(boost::asio::yield_context yield, nlohmann::json data) {
+ loginAs(yield, server.createAnonymousUser());
+}
+
void Client::register_user(boost::asio::yield_context yield, nlohmann::json data) {
std::string user = data["name"];
std::string pw = data["password"];
std::string validChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-_";
for (char c : user) {
if (validChars.find(c) == std::string::npos) {
errAndDisconnect(yield, "error",
"You're username may only contain latin letters, numbers or hypens.");
return;
}
}
if(server.registerUser(user, pw)) {
username = user;
const auto msg = server.loginAndGetWelcomeMessage(yield, user);
okMsg(yield);
sendChatLine(yield, msg);
} else {
errAndDisconnect(yield, "error", "Something went wrong during register!");
}
}
void Client::chat(boost::asio::yield_context yield, nlohmann::json data) {
std::string newChatLine = *username + ": " + data["text"].get<std::string>();
server.addChatLine(yield, newChatLine);
log().trace("chat: {}", data["text"]);
}
void Client::play(boost::asio::yield_context yield, nlohmann::json data) {
server.startMatchmaking(yield, shared_from_this());
}
void Client::quit(boost::asio::yield_context yield, nlohmann::json) {
if (opponent) {
opponent->sendOpponentQuit(yield);
opponent.reset();
}
}
void Client::sendStartGame(boost::asio::yield_context yield, const int32_t seed) {
socket.send(yield, fmt::format("{{\"type\": \"play\", \"seed\": {} }}", seed));
}
void Client::sendChatLine(boost::asio::yield_context yield, std::string line) {
if (!isLoggedIn()) {
return;
}
auto j = nlohmann::json { {"type", "chat"}, {"text", line} };
socket.send(yield, j.dump());
}
void Client::sendOpponentQuit(boost::asio::yield_context yield) {
auto j = nlohmann::json { {"type", "opponentQuit"} };
socket.send(yield, j.dump());
}
void Client::game(boost::asio::yield_context yield, nlohmann::json data) {
if (!opponent) {
spdlog::error("Can't process \"game\" without opponent!");
return;
}
try {
opponent->forward(yield, data["time"].get<uint8_t>(), data["control"].get<uint8_t>());
} catch(boost::system::system_error& e) {
log().warn("opponent {} disconnected: {}", opponent->getUsername(), e.what());
opponent.reset();
socket.send(yield, "{\"type\": \"disconnected\"}");
}
}
+void Client::loginAs(boost::asio::yield_context yield, std::string name) {
+ createLogger("client " + name);
+ log().info("logged in, sending \"ok\" ...");
+ username = std::move(name);
+ const auto msg = server.loginAndGetWelcomeMessage(yield, *username);
+ okMsg(yield);
+ sendChatLine(yield, msg);
+}
+
void Client::okMsg(boost::asio::yield_context yield) {
- socket.send(yield, "{\"type\": \"ok\"}");
+ socket.send(yield, json{ { "type", "ok" }, { "name", *username } }.dump());
log().trace("sent \"ok\"");
}
void Client::errAndDisconnect(boost::asio::yield_context yield, std::string type, std::string msg,
bool really_disconnect) {
auto j = nlohmann::json { {"type", type }};
if(msg != "") {
j["msg"] = msg;
}
socket.send(yield, j.dump());
log().trace("sent {}", j.dump());
if(really_disconnect) {
running = false;
}
}
void Client::run(boost::asio::yield_context yield) {
uint32_t protocolVersion;
std::istringstream is(socket.receive(yield));
is >> protocolVersion;
if (protocolVersion != PROTOCOL_VERSION) {
log().error("protocol version: ", protocolVersion);
errAndDisconnect(yield, "error", "Protocol version mismatch!");
return;
}
okMsg(yield);
while (running) {
try {
std::string line = socket.receive(yield);
auto data = nlohmann::json::parse(line);
log().trace("got data {}", data.dump());
auto current_cmd = commands.find(data["type"]);
if (current_cmd == commands.end()) {
errAndDisconnect(yield, "error", "Unknown command!");
} else if (current_cmd->second.first && !isLoggedIn()) {
errAndDisconnect(yield, "error", "You need to be logged in to use this command!");
} else {
current_cmd->second.second(yield, data);
}
} catch (const boost::system::system_error& e) {
if (e.code() == boost::asio::error::operation_aborted) {
if (kickReason) {
errAndDisconnect(yield, "error", *kickReason);
break;
}
} else {
throw e;
}
}
}
if (username) {
std::cout << "Client " << *username << " exiting." << std::endl;
}
}
void Client::setOpponent(std::shared_ptr<Client> opponent) {
this->opponent = std::move(opponent);
}
bool Client::isLoggedIn() const {
return username.has_value() && !kickReason;
}
std::string Client::getUsername() const {
return username ? *username : "<invalid>";
}
void Client::forward(boost::asio::yield_context yield, uint8_t time, uint8_t command) {
nlohmann::json j = {
{ "type", "game" },
{ "control", command },
{ "time", time },
};
socket.send(yield, j.dump());
}
void Client::createLogger(const std::string& name) {
try {
logger = spdlog::stdout_color_mt(name, spdlog::color_mode::always);
} catch (spdlog::spdlog_ex&) {
logger = spdlog::get(name);
}
}
spdlog::logger& Client::log() {
if (!logger) {
createLogger("unnamed client " + std::to_string(ptrdiff_t(this)));
}
return *logger;
}
void Client::kick(std::string reason) {
socket.cancel();
kickReason = reason;
}
diff --git a/server/Client.hpp b/server/Client.hpp
index 457426b..6962e04 100644
--- a/server/Client.hpp
+++ b/server/Client.hpp
@@ -1,55 +1,57 @@
#pragma once
#include "Socket.hpp"
#include <boost/asio.hpp>
#include <boost/asio/spawn.hpp>
#include <memory>
#include <optional>
#include <nlohmann/json.hpp>
#include <spdlog/logger.h>
class Server;
class Client : public std::enable_shared_from_this<Client> {
public:
Client(Server&, boost::asio::ip::tcp::socket);
void run(boost::asio::yield_context);
void setOpponent(std::shared_ptr<Client>);
void sendStartGame(boost::asio::yield_context, int32_t seed);
void sendChatLine(boost::asio::yield_context, std::string line);
void sendOpponentQuit(boost::asio::yield_context);
bool isLoggedIn() const;
std::string getUsername() const;
void forward(boost::asio::yield_context, uint8_t time, uint8_t command);
spdlog::logger& log();
void kick(std::string reason);
private:
void handleRecv(std::string);
void handleData(const boost::system::error_code& e, std::size_t size);
void login(boost::asio::yield_context, nlohmann::json data);
+ void login_anonymous(boost::asio::yield_context, nlohmann::json data);
void chat(boost::asio::yield_context, nlohmann::json data);
void play(boost::asio::yield_context, nlohmann::json data);
void quit(boost::asio::yield_context, nlohmann::json);
void game(boost::asio::yield_context, nlohmann::json data);
void register_user(boost::asio::yield_context, nlohmann::json data);
+ void loginAs(boost::asio::yield_context, std::string name);
void okMsg(boost::asio::yield_context);
void errAndDisconnect(boost::asio::yield_context, std::string type, std::string msg, bool really_disconnect = true);
bool running = true;
/// <name, <needsLogin, callback>>
std::map<std::string, std::pair<bool, std::function<void(boost::asio::yield_context, nlohmann::json)>>> commands;
Socket socket;
Server& server;
std::shared_ptr<Client> opponent;
std::optional<std::string> username;
void createLogger(const std::string& name);
std::shared_ptr<spdlog::logger> logger;
std::optional<std::string> kickReason;
};
diff --git a/server/NetworkConstants.hpp b/server/NetworkConstants.hpp
index 714310a..5fd4522 100644
--- a/server/NetworkConstants.hpp
+++ b/server/NetworkConstants.hpp
@@ -1,3 +1,3 @@
#pragma once
-const int PROTOCOL_VERSION = 2;
+const int PROTOCOL_VERSION = 3;
diff --git a/server/Server.cpp b/server/Server.cpp
index 3e61dc2..9af6299 100644
--- a/server/Server.cpp
+++ b/server/Server.cpp
@@ -1,140 +1,160 @@
#include "Server.hpp"
#include "Client.hpp"
#include "NetworkConstants.hpp"
#include <boost/bind/bind.hpp>
#include <iostream>
#include <soci/sqlite3/soci-sqlite3.h>
#include <spdlog/spdlog.h>
#include <optional>
using boost::asio::ip::tcp;
Server::Server()
: socket(context), acceptor(context, tcp::endpoint(tcp::v4(), JNTETRI_PORT)),
timer(context, boost::posix_time::seconds(15)), sql(soci::sqlite3, "jntetri.sqlite") {
sql << "CREATE TABLE IF NOT EXISTS users ("
"username VARCHAR(80) UNIQUE NOT NULL,"
"password VARCHAR(256) NOT NULL)";
timer.async_wait([this](const auto& e) { printStats(e); });
}
Server::~Server() {
socket.close();
}
void Server::run() {
boost::asio::spawn(context, [this](boost::asio::yield_context yield) { doAccept(yield); });
spdlog::info("start");
context.run();
}
void Server::doAccept(boost::asio::yield_context yield) {
while (true) {
boost::asio::ip::tcp::socket socket(context);
acceptor.async_accept(socket, yield);
auto client = std::make_shared<Client>(*this, std::move(socket));
spdlog::info("new connection");
clients.emplace_back(client);
boost::asio::spawn(context, [this, client](boost::asio::yield_context yield) {
try {
client->run(yield);
} catch (std::exception& e) {
client->log().error(e.what());
}
client->log().info("disconnected");
{
std::lock_guard<std::mutex> lock(matchmakingMutex);
if (const auto it = std::find(matchmaking.begin(), matchmaking.end(), client);
it != matchmaking.end()) {
matchmaking.erase(it);
}
}
const auto username = client->getUsername();
clients.erase(std::find(clients.begin(), clients.end(), client));
if (!username.empty()) {
addChatLine(yield, fmt::format("{} left.", username));
}
});
}
}
void Server::addChatLine(boost::asio::yield_context yield, std::string line) {
chatText += line;
for (const auto& client : clients) {
if (client->isLoggedIn()) {
client->sendChatLine(yield, line);
}
}
}
LoginState Server::checkLogin(std::string username, std::string password) {
soci::rowset<soci::row> rs =
(sql.prepare << "select password from users where username = :username",
soci::use(username, "username"));
std::optional<std::string> realPassword;
for (const auto& row : rs) {
assert(!realPassword);
realPassword = row.get<std::string>(0);
}
if (realPassword) {
if (*realPassword == password) {
// kick all other devices of this user:
for (const auto& client : clients) {
if (client->isLoggedIn() && client->getUsername() == username) {
client->kick("Someone logged in from another device.");
}
}
return LoginState::PasswordOK;
}
return LoginState::PasswordWrong;
}
return LoginState::UserDoesNotExist;
}
bool Server::registerUser(std::string username, std::string password) {
try {
sql << "insert into users (username, password) values(:username, :password)",
soci::use(username), soci::use(password);
} catch (soci::soci_error& e) {
spdlog::error(e.what());
return false;
}
return true;
}
+std::string Server::createAnonymousUser() {
+ for (int i = 0; i < 10; ++i) {
+ std::string name = "user" + std::to_string(rand() % 999999);
+ if (registerUser(name, "")) {
+ return name;
+ }
+ // already exists? Maybe we can login without a password:
+ switch (checkLogin(name, "")) {
+ case LoginState::PasswordWrong:
+ break;
+ case LoginState::UserDoesNotExist:
+ assert(false);
+ break;
+ case LoginState::PasswordOK:
+ return name;
+ }
+ }
+ throw std::runtime_error("Couldn't generate a random username!");
+}
+
void Server::startMatchmaking(boost::asio::yield_context yield, std::shared_ptr<Client> client) {
std::lock_guard<std::mutex> lock(matchmakingMutex);
if (matchmaking.empty()) {
matchmaking.emplace_back(client);
addChatLine(yield, client->getUsername() + " started matchmaking.");
} else {
for (const auto& existingClient : matchmaking) {
if (existingClient == client) {
return; // somehow matchmaking was requested twice
}
}
// Found opponent. Let's send p back to both clients so that the game starts.
matchmaking.back()->setOpponent(client);
client->setOpponent(matchmaking.back());
spdlog::info("matching '{}' and '{}'", matchmaking.back()->getUsername(), client->getUsername());
const int32_t seed = rand();
matchmaking.back()->sendStartGame(yield, seed);
client->sendStartGame(yield, seed);
matchmaking.pop_back();
}
}
std::string Server::loginAndGetWelcomeMessage(boost::asio::yield_context yield, const std::string& username) {
addChatLine(yield, fmt::format("{} joined.", username));
size_t loggedIn = std::count_if(clients.begin(), clients.end(),
[](const auto& client) { return client->isLoggedIn(); });
return fmt::format("{} user{} online.", loggedIn, loggedIn == 1 ? "" : "s");
}
void Server::printStats(const boost::system::error_code&) {
spdlog::trace("connected clients: {}", clients.size());
timer.expires_from_now(boost::posix_time::seconds(15));
timer.async_wait([this](const auto& e) { printStats(e); });
}
diff --git a/server/Server.hpp b/server/Server.hpp
index 39f265c..62f1b12 100644
--- a/server/Server.hpp
+++ b/server/Server.hpp
@@ -1,45 +1,48 @@
#pragma once
#include "LoginState.hpp"
#include <boost/asio.hpp>
#include <boost/asio/spawn.hpp>
#include <map>
#include <mutex>
#include <soci/soci.h>
#include <thread>
class Client;
class Server {
public:
Server();
~Server();
void run();
void handleAccept(std::shared_ptr<Client> client, const boost::system::error_code& error);
void doAccept(boost::asio::yield_context);
void addChatLine(boost::asio::yield_context, std::string);
void startMatchmaking(boost::asio::yield_context, std::shared_ptr<Client>);
std::string loginAndGetWelcomeMessage(boost::asio::yield_context yield, const std::string& username);
LoginState checkLogin(std::string username, std::string password);
bool registerUser(std::string username, std::string password);
+ /// creates a new user with a random name with no password
+ std::string createAnonymousUser();
+
private:
void printStats(const boost::system::error_code&);
constexpr static auto JNTETRI_PORT = 7070;
boost::asio::io_service context;
boost::asio::ip::tcp::socket socket;
boost::asio::ip::tcp::acceptor acceptor;
boost::asio::deadline_timer timer;
std::vector<std::shared_ptr<Client>> clients;
std::string chatText;
std::mutex matchmakingMutex;
std::vector<std::shared_ptr<Client>> matchmaking;
soci::session sql;
};
diff --git a/server/main.cpp b/server/main.cpp
index df6ea8c..399372f 100644
--- a/server/main.cpp
+++ b/server/main.cpp
@@ -1,14 +1,15 @@
#include "Server.hpp"
#include <spdlog/cfg/argv.h>
#include <spdlog/cfg/env.h>
#include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/spdlog.h>
int main(int argc, char** argv) {
+ srand(time(nullptr));
spdlog::cfg::load_env_levels();
spdlog::cfg::load_argv_levels(argc, argv);
spdlog::set_default_logger(spdlog::stdout_color_mt("server", spdlog::color_mode::always));
Server server;
server.run();
}
diff --git a/src/Login.cpp b/src/Login.cpp
index 404bab5..84c3ef4 100644
--- a/src/Login.cpp
+++ b/src/Login.cpp
@@ -1,168 +1,179 @@
#include "Login.hpp"
#include "../server/NetworkConstants.hpp"
#include "engine/screen.hpp"
#include "engine/procedure.hpp"
#include "engine/fade.hpp"
#include "engine/options.hpp"
#include "gui/Button.hpp"
#include "lobby.hpp"
#include <jngl.hpp>
#include <boost/bind/bind.hpp>
#include <boost/lexical_cast.hpp>
#include <sstream>
#include <spdlog/spdlog.h>
#ifdef __EMSCRIPTEN__
const std::string Login::server_("89.58.48.219"); // boomshine.de
const int Login::port_ = 9999;
#else
// const std::string Login::server_("127.0.0.1");
const std::string Login::server_("89.58.48.219"); // boomshine.de
// const std::string Login::server_("85.214.187.23"); // babynamensuche.de
const int Login::port_ = 7070;
#endif
Login::Login(std::shared_ptr<MultiplayerMenu> multiplayerMenu)
: menu_(multiplayerMenu), text_("connecting ..."), cancel_("Cancel", [this]() { OnCancel(); }),
socket_(new Socket) {
spdlog::info("Connecting to {}:{}", server_, port_);
try {
socket_->connect(server_, port_, [this]() { HandleConnect(); });
} catch(std::exception& e) {
text_ = "Exception: ";
text_ += e.what();
OnError();
}
cancel_.setCenter(0, 200);
}
void Login::HandleConnect() {
text_ = "sending ...";
spdlog::info("Sending protocol version {}", PROTOCOL_VERSION);
socket_->send(std::to_string(PROTOCOL_VERSION), [this]() { ProtocolCheck1(); });
}
void Login::ProtocolCheck1() {
text_ = "receiving ...";
spdlog::info("Waiting for server accept connection");
socket_->receive([this](json data) { ProtocolCheck2(std::move(data)); });
}
void Login::ProtocolCheck2(json temp) {
if (temp["type"] != "ok") {
text_ = "Error: ";
text_ += temp;
OnError();
} else {
- socket_->send(json{ { "type", "login" },
- { "name", menu_->GetName() },
- { "password", menu_->GetPassword() } },
- [this]() { HandleLogin1(); });
+ if (menu_->GetName().empty()) {
+ if (!menu_->GetPassword().empty()) {
+ text_ = "Name must not be empty!";
+ return OnError();
+ }
+ socket_->send(json{ { "type", "login_anonymous" } }, [this]() {
+ socket_->receive([this](json temp) { HandleLogin2(std::move(temp)); });
+ text_ = "waiting for authentification ...";
+ });
+ } else {
+ socket_->send(json{ { "type", "login" },
+ { "name", menu_->GetName() },
+ { "password", menu_->GetPassword() } },
+ [this]() { HandleLogin1(); });
+ }
}
}
void Login::HandleLogin1() {
socket_->receive([this](json temp) { HandleLogin2(std::move(temp)); });
text_ = "waiting for authentification ...";
}
void Login::HandleLogin2(json temp) {
if (temp["type"] == "ok") {
- GoToLobby();
+ GoToLobby(temp["name"]);
} else if (temp["type"] == "unknown name") {
text_ = "No user with this name found.\nDo you want to register yourself?";
cancel_.setCenter(-350, 280);
cancel_.SetText("No");
Button* yes = new Button("Yes", boost::bind(&Login::Register, this));
yes->setCenter(350, 280);
addWidget(std::shared_ptr<Widget>(yes));
} else if (temp["type"] == "wrong password") {
text_ = "The password you've entered\nis wrong. Please try again.";
OnError();
} else {
text_ = "Error: ";
text_ += temp.dump();
OnError();
}
}
void Login::Register() {
json j{ { "type", "register" },
{ "name", menu_->GetName() },
{ "password", menu_->GetPassword() } };
spdlog::info("Sending: {}", j.dump());
socket_->send(j, boost::bind(&Login::HandleRegister1, this));
cancel_.setCenter(0, 200);
cancel_.SetText("Cancel");
widgets_.clear(); // FIXME: Implement RemoveWidget function
}
void Login::HandleRegister1() {
socket_->receive([this](json temp) { HandleRegister2(std::move(temp)); });
text_ = "please wait ...";
}
void Login::HandleRegister2(json temp) {
spdlog::debug("HandleRegister2");
if (temp["type"] == "ok") {
- GoToLobby();
+ GoToLobby(temp["name"]);
} else {
text_ = "Error: ";
text_ += temp.dump();
OnError();
}
}
void Login::step() {
try {
socket_->step();
} catch(std::exception& e) {
text_ = "Exception: ";
text_ += e.what();
OnError();
}
cancel_.step();
StepWidgets();
}
-void Login::GoToLobby() {
- getOptions().lastLoginName = menu_->GetName();
+void Login::GoToLobby(std::string username) {
+ getOptions().lastLoginName = std::move(username);
jngl::setWork(std::make_shared<Fade>(std::make_shared<Lobby>(socket_)));
}
void Login::draw() const {
menu_->draw();
jngl::setColor(255, 255, 255, 220);
jngl::drawRect(-jngl::getScreenWidth() / 2, -jngl::getScreenHeight() / 2,
jngl::getScreenWidth(), jngl::getScreenHeight());
jngl::setFontColor(0, 0, 0);
GetScreen().printCentered(text_, { 0, -150 });
cancel_.draw();
DrawWidgets();
}
void Login::OnCancel() {
jngl::setWork(menu_);
}
void Login::OnError() {
// hacked together algorithm to word wrap long error messages:
size_t pos = 42;
while (jngl::getTextWidth(text_) > jngl::getScreenWidth() && pos < text_.size()) {
size_t i = pos;
while (i > 0 && text_[i - 1] != ' ') {
if (text_[i] == '\n') {
i = pos;
break;
}
--i;
}
text_.insert(text_.begin() + i, '\n');
pos += 42;
}
cancel_.SetText("OK");
cancel_.setFocus(true);
}
diff --git a/src/Login.hpp b/src/Login.hpp
index 7d150ca..e25559f 100644
--- a/src/Login.hpp
+++ b/src/Login.hpp
@@ -1,35 +1,35 @@
#pragma once
#include "engine/work.hpp"
#include "engine/socket.hpp"
#include "gui/Button.hpp"
#include "multiplayermenu.hpp"
#include <boost/asio.hpp>
class Login : public Work {
public:
Login(std::shared_ptr<MultiplayerMenu>);
void step();
void draw() const;
void HandleConnect();
void ProtocolCheck1();
void ProtocolCheck2(json);
void HandleLogin1();
void HandleLogin2(json);
void OnCancel();
void OnError();
void Register();
void HandleRegister1();
void HandleRegister2(json);
- void GoToLobby();
+ void GoToLobby(std::string username);
private:
std::shared_ptr<MultiplayerMenu> menu_;
std::string text_;
const static std::string server_;
const static int port_;
const static std::string protocolVersion_;
Button cancel_;
std::shared_ptr<Socket> socket_;
};
|
ssm/puppet_modules
|
ffc5960431b98919baeaab3a5765e0c0424ad009
|
Initial import of logrotate::conf definition for log rotation
|
diff --git a/logrotate/README b/logrotate/README
new file mode 100644
index 0000000..78208ff
--- /dev/null
+++ b/logrotate/README
@@ -0,0 +1,22 @@
+A custom definition for log rotation with logrotate:
+
+Parameters:
+ logfiles
+ interval: "daily", "weekly" or "monthly". Default: "daily"
+ dateext: true or false, default: true
+ compress: true or false: default: true
+ delaycompress: true or false, default: true
+ sharedscripts: true or false, default: true
+ rotate: a postitive integer, default:7
+ postrotate: false, or a string refering to a command to run: default: false
+ customlines: an array containing any other configuration lines for logrotate, or comments
+
+Example:
+
+# logrotate::conf { "foo":
+# logfiles => "/var/log/foo.log",
+# postrotate => "/etc/init.d/foo reload",
+# sharedscripts => false,
+#
+# customlines => ["# foo", "# bar"]
+# }
diff --git a/logrotate/manifests/conf.pp b/logrotate/manifests/conf.pp
new file mode 100644
index 0000000..758b988
--- /dev/null
+++ b/logrotate/manifests/conf.pp
@@ -0,0 +1,26 @@
+# Example:
+# (creates /etc/logrotate.d/foo.conf)
+# logrotate::conf { "foo":
+# logfiles => ["/var/log/foo.log", "/var/log/foo-debug.log", "/var/log/foo/*.log"],
+# interval => "daily",
+# dateext => true,
+# rotate => 5,
+# compress => true,
+# delaycompress => true,
+# sharedscripts => true,
+# postrotate => "/etc/init.d/foo reload";
+# }
+define logrotate::conf ($logfiles, $interval="daily", $dateext=true, $compress=true, $delaycompress=true, $sharedscripts=true, $rotate=7, $postrotate=false, $customlines=[]) {
+
+ case $interval {
+ "daily",
+ "weekly",
+ "monthly": {}
+ default: { fail("Unknown interval: $interval")}
+ }
+
+ file {"/etc/logrotate.d/$name":
+ content => template("logrotate/logrotate.erb")
+ }
+}
+
diff --git a/logrotate/templates/logrotate.erb b/logrotate/templates/logrotate.erb
new file mode 100644
index 0000000..733b586
--- /dev/null
+++ b/logrotate/templates/logrotate.erb
@@ -0,0 +1,17 @@
+# Logrotate script for <%= name %>
+<%= logfiles %>
+ <%= interval %>
+ rotate <%= rotate %>
+ <%= compress ? "compress" : "" %>
+ <%= delaycompress ? "delaycompress" : "" %>
+ <%= sharedscripts ? "sharedscripts" : "" %>
+
+<% unless postrotate == false -%>
+ postrotate
+ <%= postrotate %>
+ endscript
+<% end -%>
+
+<% customlines.flatten.each do |line| -%>
+ <%= line %>
+<% end -%>
|
ssm/puppet_modules
|
de469379b9b94e750473b8cbac00dc358bb21ca1
|
Fix paths, remove whitespace at eol
|
diff --git a/keepalived/README b/keepalived/README
index 2996ff3..d5285fa 100644
--- a/keepalived/README
+++ b/keepalived/README
@@ -1,39 +1,39 @@
==============================
Puppet module for keepalived
==============================
This is a module to install and control keepalived.
Limited functionality
=====================
For the moment, it will just control VRRP instances. That'll give you IP
address and routing failover between nodes. No IPVS support is added yet.
Requirements
============
This module requires keepalived version 1.1.14 or higher, to support the
"include" statement.
Example
=======
include keepalived
-keepalived::vrrp_instance {
+keepalived::vrrp_instance {
"vlan101":
virtual_ipaddress => "192.0.2.1/32";
"vlan101-foo":
ensure => absent,
interface => "vlan101",
virtual_ipaddress => ["192.0.2.2/32",
"192.0.2.3/32"];
"vlan102":
virtual_ipaddress => ["192.0.2.4/32"],
virtual_routes => ["192.0.2.128/30",
"192.0.2.132/30 via 102.0.2.130"
"unreachable 192.0.2.192/26"];
}
diff --git a/keepalived/manifests/init.pp b/keepalived/manifests/init.pp
index 03fdb8c..e3df004 100644
--- a/keepalived/manifests/init.pp
+++ b/keepalived/manifests/init.pp
@@ -1,31 +1,32 @@
# Module: keepalived
# Class: keepalived
# Install keepalived, handle service and global configuration
-#
+#
# Note: You need keepalived >= 1.1.14. Older versions do not support the
# "include" statement.
#
class keepalived {
package {"keepalived":
ensure => installed,
}
service {"keepalived":
- ensure => running,
- enable => true,
+ ensure => running,
+ enable => true,
+ require => Package["keepalived"],
}
exec {"/etc/init.d/keepalived reload":
refreshonly => true,
}
file {
"/etc/keepalived/keepalived.d":
ensure => directory;
- "/etc/keepalived/keepalived.conf":
- content => template("/root/keepalived.conf.erb"),
+ "/etc/keepalived/keepalived.conf":
+ content => template("keepalived/keepalived.conf.erb"),
require => Package["keepalived"],
notify => Service["keepalived"],
}
}
diff --git a/keepalived/manifests/vrrp_instance.pp b/keepalived/manifests/vrrp_instance.pp
index a79ef6b..ba46c49 100644
--- a/keepalived/manifests/vrrp_instance.pp
+++ b/keepalived/manifests/vrrp_instance.pp
@@ -1,43 +1,43 @@
# Module: keepalived
# Define: keepalived::vrrp_instance
# Control keepalived VRRP instances (failover IP addresses and routes) between servers.
#
# Example code:
# (begin code)
# include keepalived
-# keepalived::vrrp_instance {
-#
+# keepalived::vrrp_instance {
+#
# "vlan101":
# virtual_ipaddress => "192.0.2.1/32";
-#
+#
# "vlan101-foo":
# ensure => absent,
# interface => "vlan101",
# virtual_ipaddress => ["192.0.2.2/32",
# "192.0.2.3/32"];
-#
+#
# "vlan102":
# virtual_ipaddress => ["192.0.2.4/32"],
# virtual_routes => ["192.0.2.128/30",
# "192.0.2.132/30 via 102.0.2.130"
# "unreachable 192.0.2.192/26"];
-#
+#
# }
# (end)
define keepalived::vrrp_instance($ensure=present,
$interface=undef,
$virtual_ipaddress,
$virtual_routes=undef,
$virtual_router_id=1,
$mcast_src_ip=undef,
$priority=100) {
file {"/etc/keepalived/keepalived.d/keepalived_$name.conf":
ensure => $ensure,
- content => template("/root/vrrp_instance.conf.erb"),
+ content => template("keepalived/vrrp_instance.conf.erb"),
require => Package["keepalived"],
notify => Exec["/etc/init.d/keepalived reload"],
}
}
|
ssm/puppet_modules
|
120e08ae90f112e5ff129517ea1531ae07dfc834
|
Add a README file
|
diff --git a/keepalived/README b/keepalived/README
new file mode 100644
index 0000000..6e13122
--- /dev/null
+++ b/keepalived/README
@@ -0,0 +1,40 @@
+==============================
+ Puppet module for keepalived
+==============================
+
+This is a module to install and control keepalived.
+
+Limited functionality
+=====================
+
+For the moment, it will just control VRRP instances. That'll give you IP
+address and routing failover between nodes. No IPVS support is added yet.
+
+Requirements
+============
+
+This module requires keepalived version 1.1.14 or higher, to support the
+"include" statement.
+
+Example
+=======
+
+include keepalived
+keepalived::vrrp_instance {
+
+ "eth0":
+ virtual_ipaddress => "192.0.2.1/32";
+
+ "eth0-foo":
+ ensure => absent,
+ interface => "eth0",
+ virtual_ipaddress => ["192.0.2.2/32",
+ "192.0.2.3/32"];
+
+ "eth0-bar":
+ interface => "eth0",
+ virtual_ipaddress => ["192.0.2.4/32"],
+ virtual_routes => ["192.0.2.128/30",
+ "192.0.2.132/30 via 102.0.2.130"
+ "unreachable 192.0.2.192/26"];
+}
|
ssm/puppet_modules
|
7c621b0c67be921ee519c59a88fa0437f788115a
|
Move comments to right file
|
diff --git a/keepalived/manifests/init.pp b/keepalived/manifests/init.pp
index fba1c54..03fdb8c 100644
--- a/keepalived/manifests/init.pp
+++ b/keepalived/manifests/init.pp
@@ -1,51 +1,31 @@
# Module: keepalived
# Class: keepalived
-# Control keepalived VRRP instances (failover IP addresses and routes) between servers.
+# Install keepalived, handle service and global configuration
#
-# Example code:
-# (begin code)
-# include keepalived
-# keepalived::vrrp_instance {
-#
-# "eth0":
-# virtual_ipaddress => "192.0.2.1/32";
-#
-# "eth0-foo":
-# ensure => absent,
-# interface => "eth0",
-# virtual_ipaddress => ["192.0.2.2/32",
-# "192.0.2.3/32"];
-#
-# "eth0-bar":
-# interface => "eth0",
-# virtual_ipaddress => ["192.0.2.4/32"],
-# virtual_routes => ["192.0.2.128/30",
-# "192.0.2.132/30 via 102.0.2.130"
-# "unreachable 192.0.2.192/26"];
-#
-# }
-# (end)
+# Note: You need keepalived >= 1.1.14. Older versions do not support the
+# "include" statement.
+#
class keepalived {
package {"keepalived":
ensure => installed,
}
service {"keepalived":
ensure => running,
enable => true,
}
exec {"/etc/init.d/keepalived reload":
refreshonly => true,
}
file {
"/etc/keepalived/keepalived.d":
ensure => directory;
"/etc/keepalived/keepalived.conf":
content => template("/root/keepalived.conf.erb"),
require => Package["keepalived"],
notify => Service["keepalived"],
}
}
diff --git a/keepalived/manifests/vrrp_instance.pp b/keepalived/manifests/vrrp_instance.pp
index 27f8d58..5d9132f 100644
--- a/keepalived/manifests/vrrp_instance.pp
+++ b/keepalived/manifests/vrrp_instance.pp
@@ -1,20 +1,44 @@
# Module: keepalived
# Define: keepalived::vrrp_instance
# Control keepalived VRRP instances (failover IP addresses and routes) between servers.
+#
+# Example code:
+# (begin code)
+# include keepalived
+# keepalived::vrrp_instance {
+#
+# "eth0":
+# virtual_ipaddress => "192.0.2.1/32";
+#
+# "eth0-foo":
+# ensure => absent,
+# interface => "eth0",
+# virtual_ipaddress => ["192.0.2.2/32",
+# "192.0.2.3/32"];
+#
+# "eth0-bar":
+# interface => "eth0",
+# virtual_ipaddress => ["192.0.2.4/32"],
+# virtual_routes => ["192.0.2.128/30",
+# "192.0.2.132/30 via 102.0.2.130"
+# "unreachable 192.0.2.192/26"];
+#
+# }
+# (end)
define keepalived::vrrp_instance($ensure=present,
$interface=undef,
$virtual_ipaddress,
$virtual_routes=undef,
$virtual_router_id=1,
$mcast_src_ip=undef,
$priority=100) {
file {"/etc/keepalived/keepalived.d/keepalived_$name.conf":
ensure => $ensure,
content => template("/root/vrrp_instance.conf.erb"),
require => Package["keepalived"],
notify => Exec["/etc/init.d/keepalived reload"],
}
}
|
ssm/puppet_modules
|
85b1ec9751f84f8a578ee8b79f764dc50fe9bc17
|
Initial import of the keepalived module
|
diff --git a/keepalived/manifests/init.pp b/keepalived/manifests/init.pp
new file mode 100644
index 0000000..fba1c54
--- /dev/null
+++ b/keepalived/manifests/init.pp
@@ -0,0 +1,51 @@
+# Module: keepalived
+# Class: keepalived
+# Control keepalived VRRP instances (failover IP addresses and routes) between servers.
+#
+# Example code:
+# (begin code)
+# include keepalived
+# keepalived::vrrp_instance {
+#
+# "eth0":
+# virtual_ipaddress => "192.0.2.1/32";
+#
+# "eth0-foo":
+# ensure => absent,
+# interface => "eth0",
+# virtual_ipaddress => ["192.0.2.2/32",
+# "192.0.2.3/32"];
+#
+# "eth0-bar":
+# interface => "eth0",
+# virtual_ipaddress => ["192.0.2.4/32"],
+# virtual_routes => ["192.0.2.128/30",
+# "192.0.2.132/30 via 102.0.2.130"
+# "unreachable 192.0.2.192/26"];
+#
+# }
+# (end)
+class keepalived {
+ package {"keepalived":
+ ensure => installed,
+ }
+
+ service {"keepalived":
+ ensure => running,
+ enable => true,
+ }
+
+ exec {"/etc/init.d/keepalived reload":
+ refreshonly => true,
+ }
+
+ file {
+ "/etc/keepalived/keepalived.d":
+ ensure => directory;
+ "/etc/keepalived/keepalived.conf":
+ content => template("/root/keepalived.conf.erb"),
+ require => Package["keepalived"],
+ notify => Service["keepalived"],
+ }
+}
+
diff --git a/keepalived/manifests/vrrp_instance.pp b/keepalived/manifests/vrrp_instance.pp
new file mode 100644
index 0000000..27f8d58
--- /dev/null
+++ b/keepalived/manifests/vrrp_instance.pp
@@ -0,0 +1,20 @@
+# Module: keepalived
+# Define: keepalived::vrrp_instance
+# Control keepalived VRRP instances (failover IP addresses and routes) between servers.
+define keepalived::vrrp_instance($ensure=present,
+ $interface=undef,
+ $virtual_ipaddress,
+ $virtual_routes=undef,
+ $virtual_router_id=1,
+ $mcast_src_ip=undef,
+ $priority=100) {
+
+ file {"/etc/keepalived/keepalived.d/keepalived_$name.conf":
+ ensure => $ensure,
+ content => template("/root/vrrp_instance.conf.erb"),
+ require => Package["keepalived"],
+ notify => Exec["/etc/init.d/keepalived reload"],
+ }
+
+}
+
diff --git a/keepalived/templates/keepalived.conf.erb b/keepalived/templates/keepalived.conf.erb
new file mode 100644
index 0000000..3f20f37
--- /dev/null
+++ b/keepalived/templates/keepalived.conf.erb
@@ -0,0 +1,11 @@
+global_defs {
+ notification_email {
+ root@<%= fqdn %>
+ }
+ notification_email_from root@<%= fqdn %>
+ smtp_server localhost
+ smtp_connect_timeout 30
+ lvs_id <%= fqdn %>
+}
+
+include keepalived.d/*.conf
diff --git a/keepalived/templates/vrrp_instance.conf.erb b/keepalived/templates/vrrp_instance.conf.erb
new file mode 100644
index 0000000..b2337b7
--- /dev/null
+++ b/keepalived/templates/vrrp_instance.conf.erb
@@ -0,0 +1,56 @@
+<%
+ def virtual_ipaddress_lines
+ lines = []
+ lines << " virtual_ipaddress {"
+ virtual_ipaddress.to_a.flatten.each { |line|
+ ## Syntax check lines here
+ lines << " %s" % line
+ }
+ lines << " }"
+
+ return lines.join("\n")
+ end
+
+ def virtual_routes_lines
+ lines = []
+ unless virtual_routes == :undef
+ lines << " virtual_routes {"
+ virtual_routes.to_a.flatten.each { |line|
+ ## Syntax check lines here
+ lines << " %s" % line
+ }
+ lines << " }"
+ end
+ return lines.join("\n")
+ end
+
+ def interface_name
+ if interface == :undef
+ return name
+ else
+ return interface
+ end
+ end
+
+%>
+
+vrrp_instance <%= name %> {
+ state BACKUP
+ interface <%= interface_name %>
+ lvs_sync_daemon_interface <%= interface_name %>
+ virtual_router_id <%= virtual_router_id %>
+ priority <%= priority %>
+ advert_int 1
+ smtp_alert
+<% unless mcast_src_ip == :undef %>
+ mcast_src_ip <%= mcast_src_ip %>
+<% end %>
+
+ authentication {
+ auth_type AH
+ }
+
+<%= virtual_ipaddress_lines %>
+<%= virtual_routes_lines %>
+
+}
|
ssm/puppet_modules
|
36770a41c2f5cc4feaf4c2e5de51cd62ff5b4d74
|
Split defined types into their own files
|
diff --git a/monit/manifests/check/process.pp b/monit/manifests/check/process.pp
new file mode 100644
index 0000000..9bc15b9
--- /dev/null
+++ b/monit/manifests/check/process.pp
@@ -0,0 +1,43 @@
+# Define: monit::check::process
+# Creates a monit process check,
+#
+# Parameters:
+# namevar - the name of this resource will be the process name
+# pidfile - the pidfile monit will check
+# start - the command used by monit to start the service
+# stop - the command used by monit to stop the service
+# customlines - lets you inject custom lines into the monitrc snippet, just pass an array, and it will appear in the configuration file
+#
+# Actions:
+# The following actions gets taken by this defined type:
+# - creates /etc/monit/conf.d/namevar.monitrc as root:root mode 0400 based on _template_
+#
+# Requires:
+# - Package["monit"]
+#
+# Sample usage:
+# (start code)
+# monit::check::process{"openssh":
+# pidfile => "/var/run/sshd.pid",
+# start => "/etc/init.d/ssh start",
+# stop => "/etc/init.d/ssh stop",
+# customlines => ["if failed port 22 then restart",
+# "if 2 restarts within 3 cycles then timeout"]
+# }
+# (end)
+
+define monit::check::process($ensure=present, $process=$name,
+ $pidfile="/var/run/$name.pid",
+ $start="/etc/init.d/$name start",
+ $stop="/etc/init.d/$name stop",
+ $customlines="") {
+ file {"/etc/monit/conf.d/$name.monitrc":
+ ensure => $ensure,
+ owner => "root",
+ group => "root",
+ mode => 0400,
+ content => template("monit/check_process.monitrc.erb"),
+ notify => Service["monit"],
+ }
+}
+
diff --git a/monit/manifests/init.pp b/monit/manifests/init.pp
index 1ba870f..c1ebb8a 100644
--- a/monit/manifests/init.pp
+++ b/monit/manifests/init.pp
@@ -1,176 +1,79 @@
# Module: monit
#
# A puppet module to configure the monit service, and add definitions to be
# used from other classes and modules.
#
# Stig Sandbeck Mathisen <ssm@fnord.no>
#
-#
-# Define: monit::check::process
-# Creates a monit process check,
-#
-# Parameters:
-# namevar - the name of this resource will be the process name
-# pidfile - the pidfile monit will check
-# start - the command used by monit to start the service
-# stop - the command used by monit to stop the service
-# customlines - lets you inject custom lines into the monitrc snippet, just pass an array, and it will appear in the configuration file
-#
-# Actions:
-# The following actions gets taken by this defined type:
-# - creates /etc/monit/conf.d/namevar.monitrc as root:root mode 0400 based on _template_
-#
-# Requires:
-# - Package["monit"]
-#
-# Sample usage:
-# (start code)
-# monit::check::process{"openssh":
-# pidfile => "/var/run/sshd.pid",
-# start => "/etc/init.d/ssh start",
-# stop => "/etc/init.d/ssh stop",
-# customlines => ["if failed port 22 then restart",
-# "if 2 restarts within 3 cycles then timeout"]
-# }
-# (end)
-
-define monit::check::process($ensure=present, $process=$name,
- $pidfile="/var/run/$name.pid",
- $start="/etc/init.d/$name start",
- $stop="/etc/init.d/$name stop",
- $customlines="") {
- file {"/etc/monit/conf.d/$name.monitrc":
- ensure => $ensure,
- owner => "root",
- group => "root",
- mode => 0400,
- content => template("monit/check_process.monitrc.erb"),
- notify => Service["monit"],
- }
-}
-
-# Define: monit::snippet
-# Creates a monit configuration snippet in /etc/monit/conf.d/
-#
-# Parameters:
-# namevar - the name of this resource will be used for the configuration file name
-# ensure - present or absent
-# content - as for the "file" type
-# source - as for the "file" type
-# target - as for the "file' type
-#
-# Requires:
-# Package["monit"]
-#
-#
-# Sample usage:
-# (start code)
-# monit::check::process{"openssh":
-# pidfile => "/var/run/sshd.pid",
-# start => "/etc/init.d/ssh start",
-# stop => "/etc/init.d/ssh stop",
-# customlines => ["if failed port 22 then restart"]
-# }
-# (end)
-define monit::snippet($ensure=present,$target="",$source="",$content="") {
- file {"/etc/monit/conf.d/$name.monitrc":
- ensure => $ensure,
- owner => "root",
- group => "root",
- mode => 0400,
- notify => Service["monit"],
- content => $content ? {
- "" => undef,
- default => $content
- },
- source => $source ? {
- "" => undef,
- default => $source
- },
- target => $target ? {
- "" => undef,
- default => $target
- },
- }
-}
-
-# Class monit
-#
-# - Installs Package["monit"]
-# - Looks after Service["monit"]
-# - Installs a default configuration
-# - Activates monit on debian/ubuntu, by replacing /etc/default/monit
-# - Creates a directory /etc/monit/conf.d where other packages can drop configuration snippets. See monit::snippet and monit::check::process
-#
class monit {
# The monit_secret is used with the fqdn of the host to make a
# password for the monit http server.
$monit_default_secret="This is not very secret, is it?"
# The default alert recipient. You can override this by setting the
# variable "$monit_alert" in your node specification.
$monit_default_alert="root@localhost"
# The package
package { "monit":
ensure => installed,
}
# The service
service { "monit":
ensure => running,
require => Package["monit"],
}
# How to tell monit to reload its configuration
exec { "monit reload":
command => "/usr/sbin/monit reload",
refreshonly => true,
}
# Default values for all file resources
File {
owner => "root",
group => "root",
mode => 0400,
notify => Exec["monit reload"],
require => Package["monit"],
}
# The main configuration directory, this should have been provided by
# the "monit" package, but we include it just to be sure.
file { "/etc/monit":
ensure => directory,
mode => 0700,
}
# The configuration snippet directory. Other packages can put
# *.monitrc files into this directory, and monit will include them.
file { "/etc/monit/conf.d":
ensure => directory,
mode => 0700,
}
# The main configuration file
file { "/etc/monit/monitrc":
content => template("monit/monitrc.erb"),
}
# Monit is disabled by default on debian / ubuntu
case $operatingsystem {
"debian": {
file { "/etc/default/monit":
content => "startup=1\n",
before => Service["monit"]
}
}
}
# A template configuration snippet. It would need to be included,
# since monit's "include" statement cannot handle an empty directory.
monit::snippet{ "monit_template":
source => "puppet:///monit/template.monitrc",
}
}
diff --git a/monit/manifests/snippet.pp b/monit/manifests/snippet.pp
new file mode 100644
index 0000000..4ffede4
--- /dev/null
+++ b/monit/manifests/snippet.pp
@@ -0,0 +1,44 @@
+# Define: monit::snippet
+# Creates a monit configuration snippet in /etc/monit/conf.d/
+#
+# Parameters:
+# namevar - the name of this resource will be used for the configuration file name
+# ensure - present or absent
+# content - as for the "file" type
+# source - as for the "file" type
+# target - as for the "file' type
+#
+# Requires:
+# Package["monit"]
+#
+#
+# Sample usage:
+# (start code)
+# monit::check::process{"openssh":
+# pidfile => "/var/run/sshd.pid",
+# start => "/etc/init.d/ssh start",
+# stop => "/etc/init.d/ssh stop",
+# customlines => ["if failed port 22 then restart"]
+# }
+# (end)
+define monit::snippet($ensure=present,$target="",$source="",$content="") {
+ file {"/etc/monit/conf.d/$name.monitrc":
+ ensure => $ensure,
+ owner => "root",
+ group => "root",
+ mode => 0400,
+ notify => Service["monit"],
+ content => $content ? {
+ "" => undef,
+ default => $content
+ },
+ source => $source ? {
+ "" => undef,
+ default => $source
+ },
+ target => $target ? {
+ "" => undef,
+ default => $target
+ },
+ }
+}
|
ssm/puppet_modules
|
75cbddf4f8c73857b341331aef6297d3ce33de2f
|
Just use "localhost" as mailserver in the monit template
|
diff --git a/monit/templates/monitrc.erb b/monit/templates/monitrc.erb
index 8197cb3..466db89 100644
--- a/monit/templates/monitrc.erb
+++ b/monit/templates/monitrc.erb
@@ -1,48 +1,48 @@
# /etc/monit/monitrc - Monit Configuration file
#
# This file is handled by puppet, any local changes will be lost
#
<%# BEGIN functions %>
<%
require 'digest/sha1'
def password
if defined?(monit_secret)
s = monit_secret
else
s = monit_default_secret
end
return Digest::SHA1.hexdigest(s + Digest::SHA1.hexdigest(s + fqdn))
end
def monit_set_alert
if defined?(monit_alert)
return monit_alert
else
return monit_default_alert
end
end
%>
<%# END functions %>
set daemon 120
set logfile syslog facility log_daemon
-set mailserver localhost, mailhost.linpro.no
+set mailserver localhost
set alert <%= monit_set_alert %>
set httpd port 2812 and use address localhost
allow localhost
allow monit:<%= password %>
check system <%= fqdn %>
if loadavg (1min) > 4 then alert
if loadavg (5min) > 2 then alert
if memory usage > 75% then alert
if cpu usage (user) > 70% then alert
if cpu usage (system) > 30% then alert
if cpu usage (wait) > 20% then alert
# Include settings from other files
include /etc/monit/conf.d/*.monitrc
|
ssm/puppet_modules
|
8399ee57be962345deae6f46ca77e3710106cbfb
|
The config definition can accept ensure, and target, source or content
|
diff --git a/monit/manifests/init.pp b/monit/manifests/init.pp
index 7a6282d..83177a7 100644
--- a/monit/manifests/init.pp
+++ b/monit/manifests/init.pp
@@ -1,88 +1,99 @@
# Monit class
#
# Stig Sandbeck Mathisen <ssm@fnord.no>
#
# See README for details
class monit {
# The monit_secret is used with the fqdn of the host to make a
# password for the monit http server.
$monit_default_secret="This is not very secret, is it?"
# The default alert recipient. You can override this by setting the
# variable "$monit_alert" in your node specification.
$monit_default_alert="nobody@example.com"
# The package
package { "monit":
ensure => installed,
}
# The service
service { "monit":
ensure => running,
require => Package["monit"],
}
# How to tell monit to reload its configuration
exec { "monit reload":
command => "/usr/sbin/monit reload",
refreshonly => true,
}
# Default values for all file resources
File {
owner => "root",
group => "root",
mode => 0400,
notify => Exec["monit reload"],
require => Package["monit"],
}
# The main configuration directory, this should have been provided by
# the "monit" package, but we include it just to be sure.
file { "/etc/monit":
ensure => directory,
mode => 0700,
}
# The configuration snippet directory. Other packages can put
# *.monitrc files into this directory, and monit will include them.
file { "/etc/monit/conf.d":
ensure => directory,
mode => 0700,
}
# The main configuration file
file { "/etc/monit/monitrc":
content => template("monit/monitrc.erb"),
}
file { "/etc/monit/conf.d/template.monitrc":
}
# Monit is disabled by default on debian / ubuntu
case $operatingsystem {
"debian": {
file { "/etc/default/monit":
- content => "startup=1",
+ content => "startup=1\n",
}
}
}
# A definition used by other modules and classes to include monitrc
# snippets.
- define config($name,$source=undef,$content=undef) {
+ define config($ensure=present,$target="",$source="",$content="") {
file {"/etc/monit/conf.d/$name.monitrc":
- source => $source,
- content => $content,
- }
+ ensure => $ensure,
+ content => $content ? {
+ "" => undef,
+ default => $content
+ },
+ source => $source ? {
+ "" => undef,
+ default => $source
+ },
+ target => $target ? {
+ "" => undef,
+ default => $target
+ },
+ }
}
# A template configuration snippet. It would need to be included,
# since monit's "include" statement cannot handle an empty directory.
monit::config{ "monit_template":
source => "puppet:///monit/template.monitrc",
}
}
|
ssm/puppet_modules
|
46e868d8cec006d89b12d6a01f87a8f8ee81f4f8
|
Enable the monit daemon on Debian/Ubuntu
|
diff --git a/monit/manifests/init.pp b/monit/manifests/init.pp
index f1cd5d8..7a6282d 100644
--- a/monit/manifests/init.pp
+++ b/monit/manifests/init.pp
@@ -1,80 +1,88 @@
# Monit class
#
# Stig Sandbeck Mathisen <ssm@fnord.no>
#
# See README for details
class monit {
# The monit_secret is used with the fqdn of the host to make a
# password for the monit http server.
$monit_default_secret="This is not very secret, is it?"
# The default alert recipient. You can override this by setting the
# variable "$monit_alert" in your node specification.
$monit_default_alert="nobody@example.com"
# The package
package { "monit":
ensure => installed,
}
# The service
service { "monit":
ensure => running,
require => Package["monit"],
}
# How to tell monit to reload its configuration
exec { "monit reload":
command => "/usr/sbin/monit reload",
refreshonly => true,
}
# Default values for all file resources
File {
owner => "root",
group => "root",
mode => 0400,
notify => Exec["monit reload"],
require => Package["monit"],
}
# The main configuration directory, this should have been provided by
# the "monit" package, but we include it just to be sure.
file { "/etc/monit":
ensure => directory,
mode => 0700,
}
# The configuration snippet directory. Other packages can put
# *.monitrc files into this directory, and monit will include them.
file { "/etc/monit/conf.d":
ensure => directory,
mode => 0700,
}
# The main configuration file
file { "/etc/monit/monitrc":
content => template("monit/monitrc.erb"),
}
file { "/etc/monit/conf.d/template.monitrc":
}
+ # Monit is disabled by default on debian / ubuntu
+ case $operatingsystem {
+ "debian": {
+ file { "/etc/default/monit":
+ content => "startup=1",
+ }
+ }
+ }
# A definition used by other modules and classes to include monitrc
# snippets.
define config($name,$source=undef,$content=undef) {
file {"/etc/monit/conf.d/$name.monitrc":
source => $source,
content => $content,
}
}
# A template configuration snippet. It would need to be included,
# since monit's "include" statement cannot handle an empty directory.
monit::config{ "monit_template":
source => "puppet:///monit/template.monitrc",
}
}
|
ssm/puppet_modules
|
14e0fddc65789ddeb8935538133783eecaf75bd5
|
Monit module changes
|
diff --git a/monit/README b/monit/README
index 8637d09..70c2a41 100644
--- a/monit/README
+++ b/monit/README
@@ -1,42 +1,43 @@
=========================
Puppet module for monit
=========================
This is a puppet module for monit. It provides a simple way to install the
package, run the service, and handle the configuration. It also provides a
separate directory for other packages to install monit snippets.
Usage
=====
How to use the module
---------------------
Add the following to your node manifest::
$monit_secret="something secret, something safe"
+ $monit_alert="someone@example.org"
include monit
This will add a host-only "/etc/monit/monitrc" configuration file, which in
turn will include any file ending with ".monitrc" in the "/etc/monit/conf.d/"
directory.
Making passwords
----------------
The $monit_secret variable is used to construct a password for your monit
instance.
If you do not set a monit secret, it will use a default "secret" to make
passwords.
How to provide monit configuration snippets?
--------------------------------------------
This monit module provides a way for other modules and classes to include
configuration for monit to read. Add the following to your manifest for the
example customer "acme", with the Acme Daemon "acmed":
monit::config { "acmed":
source => "puppet:///acme/acmed/acmed.monitrc",
}
diff --git a/monit/manifests/init.pp b/monit/manifests/init.pp
index ec358b0..f1cd5d8 100644
--- a/monit/manifests/init.pp
+++ b/monit/manifests/init.pp
@@ -1,80 +1,80 @@
# Monit class
#
# Stig Sandbeck Mathisen <ssm@fnord.no>
#
# See README for details
class monit {
# The monit_secret is used with the fqdn of the host to make a
# password for the monit http server.
- $monit_secret="Change this to something local"
+ $monit_default_secret="This is not very secret, is it?"
# The default alert recipient. You can override this by setting the
# variable "$monit_alert" in your node specification.
$monit_default_alert="nobody@example.com"
# The package
package { "monit":
ensure => installed,
}
# The service
service { "monit":
ensure => running,
require => Package["monit"],
}
# How to tell monit to reload its configuration
exec { "monit reload":
command => "/usr/sbin/monit reload",
refreshonly => true,
}
# Default values for all file resources
File {
owner => "root",
group => "root",
mode => 0400,
notify => Exec["monit reload"],
require => Package["monit"],
}
# The main configuration directory, this should have been provided by
# the "monit" package, but we include it just to be sure.
file { "/etc/monit":
ensure => directory,
mode => 0700,
}
# The configuration snippet directory. Other packages can put
# *.monitrc files into this directory, and monit will include them.
file { "/etc/monit/conf.d":
ensure => directory,
mode => 0700,
}
# The main configuration file
file { "/etc/monit/monitrc":
content => template("monit/monitrc.erb"),
}
file { "/etc/monit/conf.d/template.monitrc":
}
# A definition used by other modules and classes to include monitrc
# snippets.
define config($name,$source=undef,$content=undef) {
file {"/etc/monit/conf.d/$name.monitrc":
source => $source,
content => $content,
}
}
# A template configuration snippet. It would need to be included,
# since monit's "include" statement cannot handle an empty directory.
monit::config{ "monit_template":
source => "puppet:///monit/template.monitrc",
}
}
diff --git a/monit/templates/monitrc.erb b/monit/templates/monitrc.erb
index 6c11545..8197cb3 100644
--- a/monit/templates/monitrc.erb
+++ b/monit/templates/monitrc.erb
@@ -1,41 +1,48 @@
# /etc/monit/monitrc - Monit Configuration file
#
# This file is handled by puppet, any local changes will be lost
#
<%# BEGIN functions %>
<%
-def password(s,h)
- require 'digest/sha1'
- return Digest::SHA1.hexdigest(s + Digest::SHA1.hexdigest(s + h))
+require 'digest/sha1'
+
+def password
+ if defined?(monit_secret)
+ s = monit_secret
+ else
+ s = monit_default_secret
+ end
+
+ return Digest::SHA1.hexdigest(s + Digest::SHA1.hexdigest(s + fqdn))
end
def monit_set_alert
if defined?(monit_alert)
return monit_alert
else
return monit_default_alert
end
end
%>
<%# END functions %>
set daemon 120
set logfile syslog facility log_daemon
set mailserver localhost, mailhost.linpro.no
set alert <%= monit_set_alert %>
set httpd port 2812 and use address localhost
allow localhost
- allow monit:<%= password(monit_secret, fqdn) %>
+ allow monit:<%= password %>
check system <%= fqdn %>
if loadavg (1min) > 4 then alert
if loadavg (5min) > 2 then alert
if memory usage > 75% then alert
if cpu usage (user) > 70% then alert
if cpu usage (system) > 30% then alert
if cpu usage (wait) > 20% then alert
# Include settings from other files
include /etc/monit/conf.d/*.monitrc
|
ssm/puppet_modules
|
b27c5a6b949da757fd3705abfc9347f420fb86ff
|
First checkin of the monit module
|
diff --git a/monit/README b/monit/README
new file mode 100644
index 0000000..8637d09
--- /dev/null
+++ b/monit/README
@@ -0,0 +1,42 @@
+=========================
+ Puppet module for monit
+=========================
+
+This is a puppet module for monit. It provides a simple way to install the
+package, run the service, and handle the configuration. It also provides a
+separate directory for other packages to install monit snippets.
+
+Usage
+=====
+
+How to use the module
+---------------------
+
+Add the following to your node manifest::
+
+ $monit_secret="something secret, something safe"
+ include monit
+
+This will add a host-only "/etc/monit/monitrc" configuration file, which in
+turn will include any file ending with ".monitrc" in the "/etc/monit/conf.d/"
+directory.
+
+Making passwords
+----------------
+
+The $monit_secret variable is used to construct a password for your monit
+instance.
+
+If you do not set a monit secret, it will use a default "secret" to make
+passwords.
+
+How to provide monit configuration snippets?
+--------------------------------------------
+
+This monit module provides a way for other modules and classes to include
+configuration for monit to read. Add the following to your manifest for the
+example customer "acme", with the Acme Daemon "acmed":
+
+ monit::config { "acmed":
+ source => "puppet:///acme/acmed/acmed.monitrc",
+ }
diff --git a/monit/files/template.monitrc b/monit/files/template.monitrc
new file mode 100644
index 0000000..1a4fd27
--- /dev/null
+++ b/monit/files/template.monitrc
@@ -0,0 +1,6 @@
+# Template for *.monitrc-filer
+#
+# check process templated
+# with pidfile "/var/run/templated.pid"
+# start program = "/etc/init.d/templated start"
+# stop program = "/etc/init.d/templated stop"
diff --git a/monit/manifests/init.pp b/monit/manifests/init.pp
new file mode 100644
index 0000000..ec358b0
--- /dev/null
+++ b/monit/manifests/init.pp
@@ -0,0 +1,80 @@
+# Monit class
+#
+# Stig Sandbeck Mathisen <ssm@fnord.no>
+#
+# See README for details
+
+class monit {
+
+ # The monit_secret is used with the fqdn of the host to make a
+ # password for the monit http server.
+ $monit_secret="Change this to something local"
+
+ # The default alert recipient. You can override this by setting the
+ # variable "$monit_alert" in your node specification.
+ $monit_default_alert="nobody@example.com"
+
+ # The package
+ package { "monit":
+ ensure => installed,
+ }
+
+ # The service
+ service { "monit":
+ ensure => running,
+ require => Package["monit"],
+ }
+
+ # How to tell monit to reload its configuration
+ exec { "monit reload":
+ command => "/usr/sbin/monit reload",
+ refreshonly => true,
+ }
+
+ # Default values for all file resources
+ File {
+ owner => "root",
+ group => "root",
+ mode => 0400,
+ notify => Exec["monit reload"],
+ require => Package["monit"],
+ }
+
+ # The main configuration directory, this should have been provided by
+ # the "monit" package, but we include it just to be sure.
+ file { "/etc/monit":
+ ensure => directory,
+ mode => 0700,
+ }
+
+ # The configuration snippet directory. Other packages can put
+ # *.monitrc files into this directory, and monit will include them.
+ file { "/etc/monit/conf.d":
+ ensure => directory,
+ mode => 0700,
+ }
+
+ # The main configuration file
+ file { "/etc/monit/monitrc":
+ content => template("monit/monitrc.erb"),
+ }
+
+ file { "/etc/monit/conf.d/template.monitrc":
+ }
+
+
+ # A definition used by other modules and classes to include monitrc
+ # snippets.
+ define config($name,$source=undef,$content=undef) {
+ file {"/etc/monit/conf.d/$name.monitrc":
+ source => $source,
+ content => $content,
+ }
+ }
+
+ # A template configuration snippet. It would need to be included,
+ # since monit's "include" statement cannot handle an empty directory.
+ monit::config{ "monit_template":
+ source => "puppet:///monit/template.monitrc",
+ }
+}
diff --git a/monit/templates/monitrc.erb b/monit/templates/monitrc.erb
new file mode 100644
index 0000000..6c11545
--- /dev/null
+++ b/monit/templates/monitrc.erb
@@ -0,0 +1,41 @@
+# /etc/monit/monitrc - Monit Configuration file
+#
+# This file is handled by puppet, any local changes will be lost
+#
+
+<%# BEGIN functions %>
+<%
+def password(s,h)
+ require 'digest/sha1'
+ return Digest::SHA1.hexdigest(s + Digest::SHA1.hexdigest(s + h))
+end
+
+def monit_set_alert
+ if defined?(monit_alert)
+ return monit_alert
+ else
+ return monit_default_alert
+ end
+end
+%>
+<%# END functions %>
+
+
+set daemon 120
+set logfile syslog facility log_daemon
+set mailserver localhost, mailhost.linpro.no
+set alert <%= monit_set_alert %>
+set httpd port 2812 and use address localhost
+ allow localhost
+ allow monit:<%= password(monit_secret, fqdn) %>
+
+check system <%= fqdn %>
+ if loadavg (1min) > 4 then alert
+ if loadavg (5min) > 2 then alert
+ if memory usage > 75% then alert
+ if cpu usage (user) > 70% then alert
+ if cpu usage (system) > 30% then alert
+ if cpu usage (wait) > 20% then alert
+
+# Include settings from other files
+include /etc/monit/conf.d/*.monitrc
|
ssm/puppet_modules
|
41b81db4b02859e1f56d750deccaee1b8e32ccad
|
Added some text to the readme file
|
diff --git a/README b/README
index e69de29..2fd7f24 100644
--- a/README
+++ b/README
@@ -0,0 +1,7 @@
+Stig's puppet modules
+=====================
+
+This is a repo for my puppet modules. You can find the latest version at
+http://github.com/ssm/puppet_modules/tree/master
+
+Stig Sandbeck Mathisen <ssm@fnord.no>
|
olle/sortable
|
98cbe1e5f88b68ef159c6265e2534b19f78da4ca
|
Added minified version of the javascript
|
diff --git a/js/jquery.sortable.min.js b/js/jquery.sortable.min.js
new file mode 100644
index 0000000..cbd9cad
--- /dev/null
+++ b/js/jquery.sortable.min.js
@@ -0,0 +1,29 @@
+/*
+ * The MIT License
+ *
+ * Copyright (c) 2008-2009 Olle Törnström studiomediatech.com
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * @author Olle Törnström olle[at]studiomediatech[dot]com
+ * @since 2009-09-24
+ */
+
+(function($){$.fn.sortable=function(options){$(this).get(0).settings=$.extend({},{handler:'php/jquery.sortable.php',upClass:'up',downClass:'down',sorterClass:'sorting'},options);return this.each(function(){$.fn.sortable.init(this);});};$.fn.sortable.init=function(list){$(list).find('li').each(function(){$(this).append('<span class="'+list.settings.sorterClass+'"><button class="'+list.settings.upClass+'" /><button class="'+list.settings.downClass+'" /></span>');$.fn.sortable.bind(this,list);});};$.fn.sortable.bind=function(listItem,list){$(listItem).find('button.up').click(function(ev){$.fn.sortable.sort(ev,listItem,'up',list);}).parent().find('button.down').click(function(ev){$.fn.sortable.sort(ev,listItem,'down',list);}).parent().parent().hover(function(){$('button',this).css({opacity:1});},function(){$('button',this).css({opacity:0});}).find('button').css({opacity:0});};$.fn.sortable.sort=function(ev,el,direction,list){ev.stopPropagation();$.ajax({type:'POST',url:list.settings.handler,data:{id:$(el).attr('id'),direction:direction},success:function(){if(direction==='up'){$(el).prev('li').before(el);}else{$(el).next('li').after(el);}
+$(el).find('button').css({opacity:0});}});};})(jQuery);
\ No newline at end of file
|
olle/sortable
|
a9da01700eea9aa72be6f68bb380b221584a0eab
|
Scoped options per plugin, enabling multi sortables on same page.
|
diff --git a/js/jquery.sortable.js b/js/jquery.sortable.js
index 35b87e0..1d4c2d8 100644
--- a/js/jquery.sortable.js
+++ b/js/jquery.sortable.js
@@ -1,82 +1,81 @@
/*
* The MIT License
*
* Copyright (c) 2008-2009 Olle Törnström studiomediatech.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author Olle Törnström olle[at]studiomediatech[dot]com
* @since 2009-09-24
*/
(function ($) {
- var settings = {};
$.fn.sortable = function (options) {
- settings = $.extend({}, {
+ $(this).get(0).settings = $.extend({}, {
handler : 'php/jquery.sortable.php',
upClass : 'up',
downClass : 'down',
sorterClass : 'sorting'
}, options);
return this.each(function () {
$.fn.sortable.init(this);
});
};
$.fn.sortable.init = function (list) {
$(list).find('li').each(function () {
- $(this).append('<span class="' + settings.sorterClass + '"><button class="' + settings.upClass + '" /><button class="' + settings.downClass + '" /></span>');
- $.fn.sortable.bind(this);
+ $(this).append('<span class="' + list.settings.sorterClass + '"><button class="' + list.settings.upClass + '" /><button class="' + list.settings.downClass + '" /></span>');
+ $.fn.sortable.bind(this, list);
});
};
- $.fn.sortable.bind = function (listItem) {
+ $.fn.sortable.bind = function (listItem, list) {
$(listItem)
.find('button.up')
.click(function (ev) {
- $.fn.sortable.sort(ev, listItem, 'up');
+ $.fn.sortable.sort(ev, listItem, 'up', list);
})
.parent()
.find('button.down')
.click(function (ev) {
- $.fn.sortable.sort(ev, listItem, 'down');
+ $.fn.sortable.sort(ev, listItem, 'down', list);
})
.parent()
.parent()
.hover(
function () { $('button', this).css({opacity : 1}); },
function () { $('button', this).css({opacity : 0}); }
)
.find('button')
.css({opacity : 0});
};
- $.fn.sortable.sort = function (ev, el, direction) {
+ $.fn.sortable.sort = function (ev, el, direction, list) {
ev.stopPropagation();
$.ajax({
type : 'POST',
- url : settings.handler,
+ url : list.settings.handler,
data : {id : $(el).attr('id'), direction : direction},
success : function () {
if (direction === 'up') {
$(el).prev('li').before(el);
} else {
$(el).next('li').after(el);
}
$(el).find('button').css({opacity : 0});
}
});
};
})(jQuery);
\ No newline at end of file
|
olle/sortable
|
8eff4910e7798d4183f20349ff839aa67d3345eb
|
Stopped propagation of sorting click.
|
diff --git a/js/jquery.sortable.js b/js/jquery.sortable.js
index e0992ae..35b87e0 100644
--- a/js/jquery.sortable.js
+++ b/js/jquery.sortable.js
@@ -1,82 +1,82 @@
/*
* The MIT License
*
* Copyright (c) 2008-2009 Olle Törnström studiomediatech.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author Olle Törnström olle[at]studiomediatech[dot]com
* @since 2009-09-24
*/
(function ($) {
var settings = {};
$.fn.sortable = function (options) {
settings = $.extend({}, {
handler : 'php/jquery.sortable.php',
upClass : 'up',
downClass : 'down',
sorterClass : 'sorting'
}, options);
return this.each(function () {
$.fn.sortable.init(this);
});
};
$.fn.sortable.init = function (list) {
$(list).find('li').each(function () {
$(this).append('<span class="' + settings.sorterClass + '"><button class="' + settings.upClass + '" /><button class="' + settings.downClass + '" /></span>');
$.fn.sortable.bind(this);
});
};
$.fn.sortable.bind = function (listItem) {
$(listItem)
.find('button.up')
.click(function (ev) {
$.fn.sortable.sort(ev, listItem, 'up');
})
.parent()
.find('button.down')
.click(function (ev) {
$.fn.sortable.sort(ev, listItem, 'down');
})
.parent()
.parent()
.hover(
function () { $('button', this).css({opacity : 1}); },
function () { $('button', this).css({opacity : 0}); }
)
.find('button')
.css({opacity : 0});
};
$.fn.sortable.sort = function (ev, el, direction) {
- ev.preventDefault();
+ ev.stopPropagation();
$.ajax({
type : 'POST',
url : settings.handler,
data : {id : $(el).attr('id'), direction : direction},
success : function () {
if (direction === 'up') {
$(el).prev('li').before(el);
} else {
$(el).next('li').after(el);
}
$(el).find('button').css({opacity : 0});
}
});
};
})(jQuery);
\ No newline at end of file
|
olle/sortable
|
2d953d2a285f4feb006286979bd0e8d580a18af6
|
Adding sprite image.
|
diff --git a/img/jquery.sortable.png b/img/jquery.sortable.png
new file mode 100644
index 0000000..d9b8a83
Binary files /dev/null and b/img/jquery.sortable.png differ
|
olle/sortable
|
077c98f26676c6fbe2fd4b20fef3305bba165b1f
|
Combined button images into single sprite background.
|
diff --git a/css/jquery.sortable.css b/css/jquery.sortable.css
index cd614f4..1d556a7 100644
--- a/css/jquery.sortable.css
+++ b/css/jquery.sortable.css
@@ -1,34 +1,34 @@
.sortable {
width: auto;
}
.sortable li {
padding: 3px 0;
}
.sorting {
float: right;
}
button.up, button.down {
margin: 0;
padding: 0;
width: 23px;
height: 20px;
border: none;
vertical-align: middle;
}
button.up {
- background: url(../img/up_passive.png) left top no-repeat;
+ background: url(../img/jquery.sortable.png) 0px 0px no-repeat;
}
button.up:hover {
- background: url(../img/up_normal.png) left top no-repeat;
+ background: url(../img/jquery.sortable.png) 0px -20px no-repeat;
}
button.down {
- background: url(../img/down_passive.png) left top no-repeat;
+ background: url(../img/jquery.sortable.png) 0px -40px no-repeat;
}
button.down:hover {
- background: url(../img/down_normal.png) left top no-repeat;
+ background: url(../img/jquery.sortable.png) 0px -60px no-repeat;
}
diff --git a/img/down_normal.png b/img/down_normal.png
deleted file mode 100644
index ec0f158..0000000
Binary files a/img/down_normal.png and /dev/null differ
diff --git a/img/down_passive.png b/img/down_passive.png
deleted file mode 100644
index bdb79f8..0000000
Binary files a/img/down_passive.png and /dev/null differ
diff --git a/img/up_normal.png b/img/up_normal.png
deleted file mode 100644
index 997adb7..0000000
Binary files a/img/up_normal.png and /dev/null differ
diff --git a/img/up_passive.png b/img/up_passive.png
deleted file mode 100644
index 97ba1d2..0000000
Binary files a/img/up_passive.png and /dev/null differ
|
olle/sortable
|
26504a11a0fb1b8777571521d56bd857b88a16fc
|
Added readme text.
|
diff --git a/.gitignore b/.gitignore
index 3a4edf6..f4160f4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
.project
+php/db.json
diff --git a/README b/README
index e69de29..5ec6667 100644
--- a/README
+++ b/README
@@ -0,0 +1,36 @@
+ * The MIT License
+ *
+ * Copyright (c) 2009 Olle Törnström studiomediatech.com
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * @author Olle Törnström olle[at]studiomediatech[dot]com
+ * @created 2009-09-24
+ * @file README sortable
+- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+ Sortable is a jQuery plugin that enables sorting for UL and OL elements. It
+ adds sorting buttons to the list elements and integrates to a server backend
+ by using Ajax POST.
+
+ To try out the built in example, simply get the project source code and put it
+ in a PHP-enabled web root, or point to the project folder with your LAMP/MAMP
+ program, and you're ready to go.
+
+ Made with the hope of being of use to someone out there!
\ No newline at end of file
diff --git a/index.php b/index.php
index a350e57..dc221f5 100644
--- a/index.php
+++ b/index.php
@@ -1,130 +1,131 @@
<?php
/*
* The MIT License
*
* Copyright (c) 2008-2009 Olle Törnström studiomediatech.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author Olle Törnström olle[at]studiomediatech[dot]com
* @since 2009-09-24
*/
require_once 'php/db.php';
$items = loadDb();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>sortable</title>
<link rel="stylesheet" href="css/style.css" />
<link rel="stylesheet" href="css/jquery.sortable.css" />
</head>
<body>
<div class="page">
<h1>Sortable lists with jQuery!</h1>
<p>
This plugin provides Ajax sorting of <code>UL</code> and
<code>OL</code> HTML lists by adding sorting buttons to the list
element.
</p>
<p>
Try out the example below by hovering any row in the list.
</p>
<div class="example">
<ul class="sortable">
<?php foreach ($items as $id => $name): ?>
<li id="<?php echo $id ?>"><?php echo $name ?></li>
<?php endforeach ?>
</ul>
</div>
<p>
You can get sorted yourself, the code is <b>free</b> and
- available on GitHub at <a href="#"></a>
+ available on GitHub at
+ <a href="http://github.com/olle/sortable">http://github.com/olle/sortable</a>.
</p>
<h2>How it works</h2>
<p>
The Sortable plugin degrades completely so we always assume the
list is built up as a valid list, ordered from the server.
</p>
<h3>1. Build lists with valid and unique <code>id</code>s.</h3>
<pre>
<ul class="sortable">
<?php foreach ($items as $id => $name): ?>
<li id="<code>item-</code><?php echo $id ?>">
<?php echo $name ?>
</li>
<?php endforeach ?>
</ul>
</pre>
<p>
<em>The <code>item-</code> prefix will ensure valid (X)HTML.</em>
</p>
<h3>2. Attach the plugin with an Ajax handler for sorting.</h3>
<p>
Using a jQuery selector you attach the plugin to the list element
and it inserts the sorting buttons bound to an Ajax handler.
</p>
<pre>
<script type="text/javascript">
$('ul.sortable').sortable({
handler : 'php/jquery.sortable.php'
});
</script>
</pre>
<p>
The handler will receive the posted parameters <code>id</code>,
with the element id, and <code>direction</code> with either the
value <code>up</code> or <code>down</code>.
</p>
<h3>3. Build an Ajax handler</h3>
<p>
The handler only needs to respond with a regular <code>HTTP/1.1 200 OK</code>,
or in the case that sorting couldn't be done
<code>HTTP/1.1 405 Method Not Allowed</code>. Don't forget to
do the actual sorting and storing of the results on the server.
</p>
<h2>Customization</h2>
<p>
Options to the Sorting plugin can be easily passed in the call.
The current options and their default values are:
<pre>
<code>handler</code> : <em>'php/jquery.sortable.php'</em>
<code>upClass</code> : <em>'up'</em>
<code>downClass</code> : <em>'down'</em>
<code>sorterClass</code> : <em>'sorting'</em>
</pre>
</p>
<div>
<p>
<a href="http://validator.w3.org/check?uri=referer"><img
src="http://www.w3.org/Icons/valid-xhtml10-blue"
alt="Valid XHTML 1.0 Strict" height="31" width="88" /></a>
</p>
</div>
</div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.sortable.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('.sortable').sortable();
});
</script>
</body>
</html>
\ No newline at end of file
|
olle/sortable
|
56c2856cf702f87988a41a3740e22d166f26292f
|
Adding initial project resources.
|
diff --git a/css/jquery.sortable.css b/css/jquery.sortable.css
new file mode 100644
index 0000000..cd614f4
--- /dev/null
+++ b/css/jquery.sortable.css
@@ -0,0 +1,34 @@
+.sortable {
+ width: auto;
+}
+
+.sortable li {
+ padding: 3px 0;
+}
+
+.sorting {
+ float: right;
+}
+
+button.up, button.down {
+ margin: 0;
+ padding: 0;
+ width: 23px;
+ height: 20px;
+ border: none;
+ vertical-align: middle;
+}
+
+button.up {
+ background: url(../img/up_passive.png) left top no-repeat;
+}
+button.up:hover {
+ background: url(../img/up_normal.png) left top no-repeat;
+}
+
+button.down {
+ background: url(../img/down_passive.png) left top no-repeat;
+}
+button.down:hover {
+ background: url(../img/down_normal.png) left top no-repeat;
+}
diff --git a/css/style.css b/css/style.css
new file mode 100644
index 0000000..0507efb
--- /dev/null
+++ b/css/style.css
@@ -0,0 +1,57 @@
+a img {
+ border: none;
+}
+
+body {
+ background: #ccc url(../img/bg_radial_top.png) 50% 0 no-repeat;
+ font-family: Helvetica, Arial, sans-serif;
+ font-size: 16px;
+ color: #444;
+}
+
+code, pre {
+ font-family: Andale Mono, Monaco, Courier, monospace;
+ font-size: .9em;
+ color: #ab3f0c;
+}
+
+pre {
+ font-size: 13px;
+ color: #000;
+ white-space: pre-wrap; /* css-3 */
+ white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
+ white-space: -pre-wrap; /* Opera 4-6 */
+ white-space: -o-pre-wrap; /* Opera 7 */
+ word-wrap: break-word; /* Internet Explorer 5.5+ */
+}
+
+h1, h2, h3 {
+ text-shadow: #fff 0px 1px 1px;
+}
+
+em {
+ color: #666;
+}
+
+.page {
+ width: 600px;
+ margin: 0 auto;
+}
+
+.example {
+ font-family: Times;
+ color: #000;
+ background: #fff;
+ width: 300px;
+ margin: 0 auto;
+ padding: 0;
+ -webkit-border-radius: 5px;
+ -moz-border-radius: 5px;
+ border-radius: 5px;
+}
+
+.example ul {
+ list-style-position: inside;
+ margin: 0;
+ padding: 10px;
+}
\ No newline at end of file
diff --git a/img/bg_radial_top.png b/img/bg_radial_top.png
new file mode 100644
index 0000000..74ec06f
Binary files /dev/null and b/img/bg_radial_top.png differ
diff --git a/img/down_normal.png b/img/down_normal.png
new file mode 100644
index 0000000..ec0f158
Binary files /dev/null and b/img/down_normal.png differ
diff --git a/img/down_passive.png b/img/down_passive.png
new file mode 100644
index 0000000..bdb79f8
Binary files /dev/null and b/img/down_passive.png differ
diff --git a/img/up_normal.png b/img/up_normal.png
new file mode 100644
index 0000000..997adb7
Binary files /dev/null and b/img/up_normal.png differ
diff --git a/img/up_passive.png b/img/up_passive.png
new file mode 100644
index 0000000..97ba1d2
Binary files /dev/null and b/img/up_passive.png differ
diff --git a/index.php b/index.php
new file mode 100644
index 0000000..a350e57
--- /dev/null
+++ b/index.php
@@ -0,0 +1,130 @@
+<?php
+/*
+ * The MIT License
+ *
+ * Copyright (c) 2008-2009 Olle Törnström studiomediatech.com
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * @author Olle Törnström olle[at]studiomediatech[dot]com
+ * @since 2009-09-24
+ */
+require_once 'php/db.php';
+$items = loadDb();
+?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
+ <head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
+ <title>sortable</title>
+ <link rel="stylesheet" href="css/style.css" />
+ <link rel="stylesheet" href="css/jquery.sortable.css" />
+ </head>
+ <body>
+ <div class="page">
+ <h1>Sortable lists with jQuery!</h1>
+ <p>
+ This plugin provides Ajax sorting of <code>UL</code> and
+ <code>OL</code> HTML lists by adding sorting buttons to the list
+ element.
+ </p>
+ <p>
+ Try out the example below by hovering any row in the list.
+ </p>
+ <div class="example">
+ <ul class="sortable">
+ <?php foreach ($items as $id => $name): ?>
+ <li id="<?php echo $id ?>"><?php echo $name ?></li>
+ <?php endforeach ?>
+ </ul>
+ </div>
+ <p>
+ You can get sorted yourself, the code is <b>free</b> and
+ available on GitHub at <a href="#"></a>
+ </p>
+ <h2>How it works</h2>
+ <p>
+ The Sortable plugin degrades completely so we always assume the
+ list is built up as a valid list, ordered from the server.
+ </p>
+ <h3>1. Build lists with valid and unique <code>id</code>s.</h3>
+ <pre>
+<ul class="sortable">
+ <?php foreach ($items as $id => $name): ?>
+ <li id="<code>item-</code><?php echo $id ?>">
+ <?php echo $name ?>
+ </li>
+ <?php endforeach ?>
+</ul>
+ </pre>
+ <p>
+ <em>The <code>item-</code> prefix will ensure valid (X)HTML.</em>
+ </p>
+ <h3>2. Attach the plugin with an Ajax handler for sorting.</h3>
+ <p>
+ Using a jQuery selector you attach the plugin to the list element
+ and it inserts the sorting buttons bound to an Ajax handler.
+ </p>
+ <pre>
+<script type="text/javascript">
+ $('ul.sortable').sortable({
+ handler : 'php/jquery.sortable.php'
+ });
+</script>
+ </pre>
+ <p>
+ The handler will receive the posted parameters <code>id</code>,
+ with the element id, and <code>direction</code> with either the
+ value <code>up</code> or <code>down</code>.
+ </p>
+ <h3>3. Build an Ajax handler</h3>
+ <p>
+ The handler only needs to respond with a regular <code>HTTP/1.1 200 OK</code>,
+ or in the case that sorting couldn't be done
+ <code>HTTP/1.1 405 Method Not Allowed</code>. Don't forget to
+ do the actual sorting and storing of the results on the server.
+ </p>
+ <h2>Customization</h2>
+ <p>
+ Options to the Sorting plugin can be easily passed in the call.
+ The current options and their default values are:
+ <pre>
+<code>handler</code> : <em>'php/jquery.sortable.php'</em>
+<code>upClass</code> : <em>'up'</em>
+<code>downClass</code> : <em>'down'</em>
+<code>sorterClass</code> : <em>'sorting'</em>
+ </pre>
+ </p>
+ <div>
+ <p>
+ <a href="http://validator.w3.org/check?uri=referer"><img
+ src="http://www.w3.org/Icons/valid-xhtml10-blue"
+ alt="Valid XHTML 1.0 Strict" height="31" width="88" /></a>
+ </p>
+ </div>
+ </div>
+ <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
+ <script type="text/javascript" src="js/jquery.sortable.js"></script>
+ <script type="text/javascript">
+ $(document).ready(function () {
+ $('.sortable').sortable();
+ });
+ </script>
+ </body>
+</html>
\ No newline at end of file
diff --git a/js/jquery.sortable.js b/js/jquery.sortable.js
new file mode 100644
index 0000000..e0992ae
--- /dev/null
+++ b/js/jquery.sortable.js
@@ -0,0 +1,82 @@
+/*
+ * The MIT License
+ *
+ * Copyright (c) 2008-2009 Olle Törnström studiomediatech.com
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * @author Olle Törnström olle[at]studiomediatech[dot]com
+ * @since 2009-09-24
+ */
+(function ($) {
+ var settings = {};
+ $.fn.sortable = function (options) {
+ settings = $.extend({}, {
+ handler : 'php/jquery.sortable.php',
+ upClass : 'up',
+ downClass : 'down',
+ sorterClass : 'sorting'
+ }, options);
+ return this.each(function () {
+ $.fn.sortable.init(this);
+ });
+ };
+ $.fn.sortable.init = function (list) {
+ $(list).find('li').each(function () {
+ $(this).append('<span class="' + settings.sorterClass + '"><button class="' + settings.upClass + '" /><button class="' + settings.downClass + '" /></span>');
+ $.fn.sortable.bind(this);
+ });
+ };
+ $.fn.sortable.bind = function (listItem) {
+ $(listItem)
+ .find('button.up')
+ .click(function (ev) {
+ $.fn.sortable.sort(ev, listItem, 'up');
+ })
+ .parent()
+ .find('button.down')
+ .click(function (ev) {
+ $.fn.sortable.sort(ev, listItem, 'down');
+ })
+ .parent()
+ .parent()
+ .hover(
+ function () { $('button', this).css({opacity : 1}); },
+ function () { $('button', this).css({opacity : 0}); }
+ )
+ .find('button')
+ .css({opacity : 0});
+ };
+ $.fn.sortable.sort = function (ev, el, direction) {
+ ev.preventDefault();
+ $.ajax({
+ type : 'POST',
+ url : settings.handler,
+ data : {id : $(el).attr('id'), direction : direction},
+ success : function () {
+ if (direction === 'up') {
+ $(el).prev('li').before(el);
+ } else {
+ $(el).next('li').after(el);
+ }
+ $(el).find('button').css({opacity : 0});
+ }
+ });
+ };
+})(jQuery);
\ No newline at end of file
diff --git a/php/db.php b/php/db.php
new file mode 100644
index 0000000..a9b313f
--- /dev/null
+++ b/php/db.php
@@ -0,0 +1,59 @@
+<?php
+/*
+ * The MIT License
+ *
+ * Copyright (c) 2008-2009 Olle Törnström studiomediatech.com
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * @author Olle Törnström olle[at]studiomediatech[dot]com
+ * @since 2009-09-24
+ */
+define('DB_FILE', dirname(__FILE__) . '/db.json');
+
+function initDb() {
+ $db = array(
+ 'item-0' => 'Ripley',
+ 'item-1' => 'Hicks',
+ 'item-2' => 'Hudson',
+ 'item-3' => 'Newt',
+ );
+ $dbData = json_encode($db);
+ $file = fopen(DB_FILE, 'w');
+ fwrite($file, $dbData, strlen($dbData));
+ fclose($file);
+ return $db;
+}
+
+function loadDb() {
+ if (!file_exists(DB_FILE))
+ return initDb();
+ $file = fopen(DB_FILE, 'r');
+ $dbData = fread($file, 96);
+ fclose($file);
+ $db = json_decode($dbData, true);
+ return $db;
+}
+
+function saveDb($db) {
+ $file = fopen(DB_FILE, 'w');
+ $dbData = json_encode($db);
+ fwrite($file, $dbData, strlen($dbData));
+ fclose($file);
+}
\ No newline at end of file
diff --git a/php/jquery.sortable.php b/php/jquery.sortable.php
new file mode 100644
index 0000000..9956eb6
--- /dev/null
+++ b/php/jquery.sortable.php
@@ -0,0 +1,54 @@
+<?php
+/*
+ * The MIT License
+ *
+ * Copyright (c) 2008-2009 Olle Törnström studiomediatech.com
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ *
+ * @author Olle Törnström olle[at]studiomediatech[dot]com
+ * @since 2009-09-24
+ */
+require_once ('db.php');
+
+$db = loadDb();
+
+$id = strval($_POST['id']);
+$direction = strval($_POST['direction']);
+$index = array_search($id, array_keys($db));
+
+if (($direction === 'up' && $index == 0)
+ || ($direction === 'down' && $index == count($db) - 1)) {
+ header('HTTP/1.1 405 Not allowed');
+ exit;
+}
+
+if ($direction === 'up') {
+ $head = $index - 2 >= 0 ? array_slice($db, 0, $index - 1, true) : array();
+ $pair = array_reverse(array_slice($db, $index - 1, 2, true), true);
+ $tail = $index + 1 < count($db) ? array_slice($db, $index + 1, count($db), true) : array();
+} else {
+ $head = $index > 0 ? array_slice($db, 0, $index, true) : array();
+ $pair = array_reverse(array_slice($db, $index, 2, true), true);
+ $tail = $index + 2 < count($db) ? array_slice($db, $index + 2, count($db), true) : array();
+}
+
+$db = array_merge($head, $pair, $tail);
+
+saveDb($db);
\ No newline at end of file
|
olle/sortable
|
0b71cb935a2cc31eea5f8b6911d3438c63e2176f
|
Added ignore for Aptana project files
|
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..3a4edf6
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+.project
|
apocalypse/perl-poe-benchmarker
|
7c4fc43648decc2629a0cfa91a1adf0865e9ced3
|
mailmap
|
diff --git a/.mailmap b/.mailmap
new file mode 100644
index 0000000..1b06641
--- /dev/null
+++ b/.mailmap
@@ -0,0 +1,4 @@
+Apocalypse <APOCAL@cpan.org> <apocalypse@users.noreply.github.com>
+Apocalypse <APOCAL@cpan.org> <perl@0ne.us>
+Apocalypse <APOCAL@cpan.org> <apoc@blackhole.(none)>
+Apocalypse <APOCAL@cpan.org> <apoc@satellite.(none)>
|
apocalypse/perl-poe-benchmarker
|
892360ac2e64a798caff46445189936ab9d987e9
|
add docs about queue benchmarking, thanks TonyC
|
diff --git a/MANIFEST b/MANIFEST
index 72e5e5a..bbde230 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -1,22 +1,23 @@
Build.PL
MANIFEST
MANIFEST.SKIP
README
Makefile.PL
META.yml
Changes
LICENSE
lib/POE/Devel/Benchmarker.pm
lib/POE/Devel/Benchmarker/GetInstalledLoops.pm
lib/POE/Devel/Benchmarker/GetInstalledLoops/SubProcess.pm
lib/POE/Devel/Benchmarker/GetPOEdists.pm
lib/POE/Devel/Benchmarker/SubProcess.pm
lib/POE/Devel/Benchmarker/Utils.pm
lib/POE/Devel/Benchmarker/Imager.pm
lib/POE/Devel/Benchmarker/Imager/BasicStatistics.pm
+lib/POE/Devel/Benchmarker/Imager/BenchmarkOutput.pm
examples/test.pl
t/1_load.t
t/apocalypse.t
diff --git a/lib/POE/Devel/Benchmarker.pm b/lib/POE/Devel/Benchmarker.pm
index c5c83d5..64456a9 100644
--- a/lib/POE/Devel/Benchmarker.pm
+++ b/lib/POE/Devel/Benchmarker.pm
@@ -615,601 +615,610 @@ sub wrapup_test : State {
'poe' => {
'v' => $_[HEAP]->{'current_version'}->stringify, # YAML::Tiny doesn't like version objects :(
'loop' => $_[HEAP]->{'current_loop'},
},
't' => {
's_ts' => $_[HEAP]->{'current_starttime'},
'e_ts' => $_[HEAP]->{'current_endtime'},
'd' => $_[HEAP]->{'current_endtime'} - $_[HEAP]->{'current_starttime'},
's_t' => [ @{ $_[HEAP]->{'current_starttimes'} } ],
'e_t' => [ @{ $_[HEAP]->{'current_endtimes'} } ],
},
'raw' => $_[HEAP]->{'current_data'},
'test' => $file,
'x_bench' => currentTestVersion(),
( $_[HEAP]->{'test_timedout'} ? ( 'timedout' => 1 ) : () ),
( $_[HEAP]->{'lite_tests'} ? ( 'litetests' => 1 ) : () ),
( $_[HEAP]->{'current_assertions'} ? ( 'asserts' => 1 ) : () ),
( $_[HEAP]->{'current_noxsqueue'} ? ( 'noxsqueue' => 1 ) : () ),
} );
# process the next test
$_[KERNEL]->yield( 'bench_xsqueue' );
return;
}
sub analyze_output : State {
# get the data
my $test = $_[ARG0];
## no critic ( ProhibitAccessOfPrivateData )
# clean up the times() stuff
$test->{'t'}->{'t'} = beautify_times(
join( " ", @{ delete $test->{'t'}->{'s_t'} } ) .
" " .
join( " ", @{ delete $test->{'t'}->{'e_t'} } )
);
# Okay, break it down into our data struct
$test->{'metrics'} = {};
my $d = $test->{'metrics'};
my @unknown;
foreach my $l ( split( /(?:\n|\r)/, $test->{'raw'} ) ) {
# skip empty lines
if ( $l eq '' ) { next }
# usual test benchmark output
# 10 startups in 0.885 seconds ( 11.302 per second)
# 10000 posts in 0.497 seconds ( 20101.112 per second)
if ( $l =~ /^\s+\d+\s+(\w+)\s+in\s+([\d\.]+)\s+seconds\s+\(\s+([\d\.]+)\s+per\s+second\)$/ ) {
$d->{ $1 }->{'d'} = $2; # duration in seconds
$d->{ $1 }->{'i'} = $3; # iterations per second
# usual test benchmark times output
# startup times: 0.1 0 0 0 0.1 0 0.76 0.09
} elsif ( $l =~ /^(\w+)\s+times:\s+(.+)$/ ) {
$d->{ $1 }->{'t'} = beautify_times( $2 ); # the times hash
# usual test SKIP output
# SKIPPING br0ken $metric because ...
} elsif ( $l =~ /^SKIPPING\s+br0ken\s+(\w+)\s+because/ ) {
# don't build their data struct
# parse the memory footprint stuff
} elsif ( $l =~ /^pidinfo:\s+(.+)$/ ) {
# what should we analyze?
my $pidinfo = $1;
# VmPeak: 16172 kB
if ( $pidinfo =~ /^VmPeak:\s+(.+)$/ ) {
$test->{'pid'}->{'vmpeak'} = $1;
# voluntary_ctxt_switches: 10
} elsif ( $pidinfo =~ /^voluntary_ctxt_switches:\s+(.+)$/ ) {
$test->{'pid'}->{'vol_ctxt'} = $1;
# nonvoluntary_ctxt_switches: 1221
} elsif ( $pidinfo =~ /^nonvoluntary_ctxt_switches:\s+(.+)$/ ) {
$test->{'pid'}->{'nonvol_ctxt'} = $1;
} else {
# ignore the rest of the fluff
}
# parse the perl binary stuff
} elsif ( $l =~ /^perlconfig:\s+(.+)$/ ) {
# what should we analyze?
my $perlconfig = $1;
# ignore the fluff ( not needed now... )
# parse the CPU info
} elsif ( $l =~ /^cpuinfo:\s+(.+)$/ ) {
# what should we analyze?
my $cpuinfo = $1;
# if this is on a multiproc system, we will overwrite the data per processor ( harmless... )
# cpu MHz : 1201.000
if ( $cpuinfo =~ /^cpu\s+MHz\s+:\s+(.+)$/ ) {
$test->{'cpu'}->{'mhz'} = $1;
# model name : Intel(R) Core(TM)2 Duo CPU L7100 @ 1.20GHz
} elsif ( $cpuinfo =~ /^model\s+name\s+:\s+(.+)$/ ) {
$test->{'cpu'}->{'name'} = $1;
# bogomips : 2397.58
} elsif ( $cpuinfo =~ /^bogomips\s+:\s+(.+)$/ ) {
$test->{'cpu'}->{'bogo'} = $1;
} else {
# ignore the rest of the fluff
}
# ignore any Devel::Hide stuff
# $l eq '!STDERR: Devel::Hide hides POE/XS/Queue/Array.pm'
} elsif ( $l =~ /^\!STDERR:\s+Devel\:\:Hide\s+hides/ ) {
# ignore them
# data that we can safely throw away
} elsif ( $l eq 'Using NO Assertions!' or
$l eq 'Using FULL Assertions!' or
$l eq 'Using the LITE tests' or
$l eq 'Using the HEAVY tests' or
$l eq 'DISABLING POE::XS::Queue::Array' or
$l eq 'LETTING POE find POE::XS::Queue::Array' or
$l eq 'UNABLE TO GET /proc/self/status' or
$l eq 'UNABLE TO GET /proc/cpuinfo' or
$l eq '!STDERR: POE::Kernel\'s run() method was never called.' or # to ignore old POEs that threw this warning
$l eq 'TEST TERMINATED DUE TO TIMEOUT' ) {
# ignore them
# parse the perl binary stuff
} elsif ( $l =~ /^Running\s+under\s+perl\s+binary:\s+\'([^\']+)\'\s+v([\d\.]+)$/ ) {
$test->{'perl'}->{'binary'} = $1;
# setup the perl version
$test->{'perl'}->{'v'} = $2;
# the master loop version ( what the POE::Loop::XYZ actually uses )
# Using loop: EV-3.49
} elsif ( $l =~ /^Using\s+master\s+loop:\s+(.+)$/ ) {
$test->{'poe'}->{'loop_m'} = $1;
# the real POE version that was loaded
# Using POE-1.001
} elsif ( $l =~ /^Using\s+POE-(.+)$/ ) {
$test->{'poe'}->{'v_real'} = $1;
# the various queue/loop modules we loaded
# POE is using: POE::XS::Queue::Array v0.005
# POE is using: POE::Queue v1.2328
# POE is using: POE::Loop::EV v0.06
} elsif ( $l =~ /^POE\s+is\s+using:\s+([^\s]+)\s+v(.+)$/ ) {
$test->{'poe'}->{'modules'}->{ $1 } = $2;
# get the uname info
# Running under machine: Linux apoc-x300 2.6.24-21-generic #1 SMP Tue Oct 21 23:43:45 UTC 2008 i686 GNU/Linux
} elsif ( $l =~ /^Running\s+under\s+machine:\s+(.+)$/ ) {
$test->{'uname'} = $1;
# parse any STDERR output
# !STDERR: unable to foo
} elsif ( $l =~ /^\!STDERR:\s+(.+)$/ ) {
push( @{ $test->{'stderr'} }, $1 );
} else {
# unknown line :(
push( @unknown, $l );
}
}
# Get rid of the rawdata
delete $test->{'raw'};
# Dump the unknowns
if ( @unknown ) {
print "\n[ANALYZER] Unknown output from benchmark -> " . Dump( \@unknown );
}
# Dump the data struct we have to the file.yml
my $yaml_file = File::Spec->catfile( 'results', ( delete $test->{'test'} ) . '.yml' );
my $ret = open( my $fh, '>', $yaml_file );
if ( defined $ret ) {
print $fh Dump( $test );
if ( ! close( $fh ) ) {
print "\n[ANALYZER] Unable to close $yaml_file -> " . $! . "\n";
}
} else {
print "\n[ANALYZER] Unable to open $yaml_file for writing -> " . $! . "\n";
}
# now that we've dumped the stuff, we can do some sanity checks
# the POE we "think" we loaded should match reality!
if ( exists $test->{'poe'}->{'v_real'} ) { # if this exists, then we successfully loaded POE
if ( $test->{'poe'}->{'v'} ne $test->{'poe'}->{'v_real'} ) {
print "\n[ANALYZER] The subprocess loaded a different version of POE than we thought -> $yaml_file\n";
}
# The loop we loaded should match what we wanted!
if ( exists $test->{'poe'}->{'modules'} ) {
if ( ! exists $test->{'poe'}->{'modules'}->{ poeloop2dist( $test->{'poe'}->{'loop'} ) } ) {
# gaah special-case for IO_Poll ( POE 0.21 to POE 0.29 introduced POE::Loop::Poll which later became POE::Loop::IO_Poll )
if ( $test->{'poe'}->{'loop'} eq 'IO_Poll' and exists $test->{'poe'}->{'modules'}->{'POE::Loop::Poll'} ) {
# ah, ignore this
} else {
print "\n[ANALYZER] The subprocess loaded a different Loop than we thought -> $yaml_file\n";
}
}
}
}
# the perl binary should be the same!
if ( exists $test->{'perl'} ) { # if this exists, we successfully fired up the app ( no compile error )
if ( $test->{'perl'}->{'binary'} ne $^X ) {
print "\n[ANALYZER] The subprocess booted up on a different perl binary -> $yaml_file\n";
}
if ( $test->{'perl'}->{'v'} ne sprintf( "%vd", $^V ) ) {
print "\n[ANALYZER] The subprocess booted up on a different perl version -> $yaml_file\n";
}
}
# Did we successfully run the entire testsuite?
if ( ! exists $test->{'pid'} ) {
print "\n[ANALYZER] The testsuite failed to run to completion -> $yaml_file\n";
}
# all done!
return;
}
1;
__END__
=for stopwords AnnoCPAN CPAN Caputo EV Eventloop Gtk HTTP Kqueue MYFH poe Prima RT SQLite STDIN SocketFactory TODO Tapout Wx XS YAML autoprobing backend benchmarker csv db dngor er freshstart hardcode litetests noasserts noxsqueue poedists pong svn untarred yml
=head1 NAME
POE::Devel::Benchmarker - Benchmarking POE's performance ( acts more like a smoker )
=head1 SYNOPSIS
use POE::Devel::Benchmarker;
benchmark();
=head1 ABSTRACT
This package of tools is designed to benchmark POE's performance across different
configurations. The current "tests" are:
=over 4
=item Events
posts: This tests how long it takes to post() N times
dispatches: This tests how long it took to dispatch/deliver all the posts enqueued in the "posts" test
single_posts: This tests how long it took to yield() between 2 states for N times
calls: This tests how long it took to call() N times
=item Alarms
alarms: This tests how long it took to add N alarms via alarm(), overwriting each other
alarm_adds: This tests how long it took to add N alarms via alarm_add()
alarm_clears: This tests how long it took to clear all alarms set in the "alarm_adds" test
NOTE: alarm_add is not available on all versions of POE!
=item Sessions
session_creates: This tests how long it took to create N sessions
session_destroys: This tests how long it took to destroy all sessions created in the "session_creates" test
=item Filehandles
select_read_STDIN: This tests how long it took to toggle select_read N times on STDIN
select_write_STDIN: This tests how long it took to toggle select_write N times on STDIN
select_read_MYFH: This tests how long it took to toggle select_read N times on a real filehandle
select_write_MYFH: This tests how long it took to toggle select_write N times on a real filehandle
NOTE: The MYFH tests don't include the time it took to open()/close() the file :)
=item Sockets
socket_connects: This tests how long it took to connect+disconnect to a SocketFactory server via localhost
socket_stream: This tests how long it took to send N chunks of data in a "ping-pong" fashion between the server and client
=item POE startup time
startups: This tests how long it took to start + close N instances of POE+Loop without any sessions/etc via system()
=item POE Loops
This is actually a "super" test where all of the specific tests is ran against various POE::Loop::XYZ/FOO for comparison
NOTE: Not all versions of POE support all Loops!
=item POE Assertions
This is actually a "super" test where all of the specific tests is ran against POE with/without assertions enabled
NOTE: Not all versions of POE support assertions!
=item POE::XS::Queue::Array
This is actually a "super" test where all of the specific tests is ran against POE with XS goodness enabled/disabled
NOTE: Not all versions of POE support XS::Queue::Array!
=back
=head1 DESCRIPTION
This module is poorly documented now. Please give me some time to properly document it over time :)
=head2 INSTALLATION
Here's a simple outline to get you up to speed quickly. ( and smoking! )
=over 4
=item Install CPAN package + dependencies
Download+install the POE::Devel::Benchmarker package from CPAN
apoc@apoc-x300:~$ cpanp -i POE::Devel::Benchmarker
=item Setup initial directories
Go anywhere, and create the "parent" directory where you'll be storing test results + stuff. For this example,
I have chosen to use ~/poe-benchmarker:
apoc@apoc-x300:~$ mkdir poe-benchmarker
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ mkdir poedists results images
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker::GetPOEdists -e 'getPOEdists( 1 )'
( go get a coffee while it downloads if you're on a slow link, ha! )
=item Let 'er rip!
At this point you can start running the benchmark!
NOTE: the Benchmarker expects everything to be in the "local" directory!
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker -e 'benchmark()'
( go sleep or something, this will take a while! )
=back
=head2 BENCHMARKING
On startup the Benchmarker will look in the "poedists" directory and load all the distributions it sees untarred there. Once
that is done it will begin autoprobing for available POE::Loop packages. Once it determines what's available, it will begin
the benchmarks.
As the Benchmarker goes through the combinations of POE + Eventloop + Assertions + XS::Queue it will dump data into
the results directory. The module also dumps YAML output in the same place, with the suffix of ".yml"
This module exposes only one subroutine, the benchmark() one. You can pass a hashref to it to set various options. Here is
a list of the valid options:
=over 4
=item freshstart => boolean
This will tell the Benchmarker to ignore any previous test runs stored in the 'results' directory. This will not delete
data from previous runs, only overwrite them. So be careful if you're mixing test runs from different versions!
benchmark( { freshstart => 1 } );
default: false
=item noxsqueue => boolean
This will tell the Benchmarker to force the unavailability of POE::XS::Queue::Array and skip those tests.
NOTE: The Benchmarker will set this automatically if it cannot load the module!
benchmark( { noxsqueue => 1 } );
default: false
=item noasserts => boolean
This will tell the Benchmarker to not run the ASSERT tests.
benchmark( { noasserts => 1 } );
default: false
=item litetests => boolean
This enables the "lite" tests which will not take up too much time.
benchmark( { litetests => 0 } );
default: true
=item quiet => boolean
This enables quiet mode which will not print anything to the console except for errors.
benchmark( { 'quiet' => 1 } );
default: false
=item loop => csv list or array
This overrides the built-in loop detection algorithm which searches for all known loops.
There is some "magic" here where you can put a negative sign in front of a loop and we will NOT run that.
NOTE: Capitalization is important!
benchmark( { 'loop' => 'IO_Poll,Select' } ); # runs only IO::Poll and Select
benchmark( { 'loop' => [ qw( Tk Gtk ) ] } ); # runs only Tk and Gtk
benchmark( { 'loop' => '-Tk' } ); # runs all available loops EXCEPT for TK
Known loops: Event_Lib EV Glib Prima Gtk Kqueue Tk Select IO_Poll
=item poe => csv list or array
This overrides the built-in POE version detection algorithm which pulls the POE versions from the 'poedists' directory.
There is some "magic" here where you can put a negative sign in front of a version and we will NOT run that.
NOTE: The Benchmarker will ignore versions that wasn't found in the directory!
benchmark( { 'poe' => '0.35,1.003' } ); # runs on 0.35 and 1.003
benchmark( { 'poe' => [ qw( 0.3009 0.12 ) ] } ); # runs on 0.3009 and 0.12
benchmark( { 'poe' => '-0.35' } ); # runs ALL tests except 0.35
=back
=head2 ANALYZING RESULTS
Please look at the pretty charts generated by the L<POE::Devel::Benchmarker::Imager> module.
=head1 EXPORT
Automatically exports the benchmark() subroutine.
=head1 TODO
=over 4
=item Perl version smoking
We should be able to run the benchmark over different Perl versions. This would require some fiddling with our
layout + logic. It's not that urgent because the workaround is to simply execute the benchmarker under a different
perl binary. It's smart enough to use $^X to be consistent across tests/subprocesses :)
=item Select the EV backend
<Khisanth> and if you are benchmarking, try it with POE using EV with EV using Glib? :P
<Apocalypse> I'm not sure how to configure the EV "backend" yet
<Apocalypse> too much docs for me to read hah
<Khisanth> Apocalypse: use EV::Glib; use Glib; use POE; :)
=item Be smarter in smoking timeouts
Currently we depend on the litetests option and hardcode some values including the timeout. If your machine is incredibly
slow, there's a chance that it could timeout unnecessarily. Please look at the outputs and check to see if there are unusual
failures, and inform me.
Also, some loops perform badly and take almost forever! /me glares at Gtk...
=item More benchmarks!
As usual, me and the crowd in #poe have plenty of ideas for tests. We'll be adding them over time, but if you have an idea please
drop me a line and let me know!
dngor said there was some benchmarks in the POE svn under trunk/queue...
<dngor> Apocalypse: Check out the old benchmarks in the queue directory in POE's repot.
They profile queue performance at various sizes, which is a better indication of scalability.
Tapout contributed a script that tests HTTP performance, let's see if it deserves to be in the suite :)
I added the preliminary socket tests, we definitely should expand it seeing how many people use POE for networking...
=item Add SQLite/DBI/etc support to the Analyzer
It would be nice if we could have a local SQLite db to dump our stats into. This would make arbitrary reports much easier than
loading raw YAML files and trying to make sense of them, ha! Also, this means somebody can do the smoking and send the SQLite
db to another person to generate the graphs, cool!
=item Wx loop support
I have Wx installed, but it doesn't work. I suspect the module is broken... Here's the error:
Can't call method "MainLoop" on an undefined value at /usr/local/share/perl/5.8.8/POE/Loop/Wx.pm line 91.
=item Multiple run support
I would like the benchmarker to run the testsuite N times, and summing up the data into an average so we have more sane data...
<dngor> Apocalypse: You could start with 5 runs, then continue running until the standard deviation reaches some sane level?
-=item Event loop support
-
-<Apocalypse> ascent_: Yeah, but unfortunately trying to use Loop::Event here with latest POE blows up :(
-<Apocalypse> apoc@blackhole:~$ POE_EVENT_LOOP="Event" perl -MPOE -e 1
-<Apocalypse> Can't locate object method "timer" via package "Event" at /usr/local/share/perl/5.10.0/POE/Loop/Event.pm line 47.
-<Apocalypse> Event.pm 1.13, POE::Loop::Event 1.302, POE 1.287
-<Apocalypse> ascent_: Patches welcome :)
-<ascent_> Apocalypse: POE_EVENT_LOOP="Event" perl -MEvent -MPOE -e 1 <- works fine... so patch is one-liner: use Event; ;)
+dngor also mentioned something about running 7 times, and removing the highest+lowest benchs...
+
+=item Queue benchmarking
+
+<Apocalypse> Allright, if you have the time could you please look at the benchmark "metrics" and let me know if I could add more metrics regarding the queue - I believe your POD stated that it could choke on excessively large queues?
+<@TonyC> one problem with the queue is that anything that uses a filter can make multiple callbacks into perl functions, and I suspect that's slower than perl's entersub
+<Apocalypse> filter? Sorry if I'm not that expert with XS stuff :(
+<@TonyC> the queue (XS or non-XS) remove method (for example) take a filter callback, that needs to be called for any candidate for removal
+<@TonyC> urr remove_items()
+<Apocalypse> TonyC: Aha, looking at the POE::Queue I understand what you mean
+<Apocalypse> I'll add that to my todo and see if I can't whip up a bench for that :)
+<@TonyC> I guess a sort of real test would be to run the queue test script
+<Apocalypse> Where is that script?
+<@TonyC> in the POE distribution, in the POE::XS::Queue::Array distribution
+<@TonyC> I think the XS one is slightly modified - me looks
+<@TonyC> looks like the core POE version has also been modified
+<@TonyC> t/10_units/06_queues/01_array.t if you're wondering
=back
=head1 SEE ALSO
L<POE>
=head1 SUPPORT
You can find documentation for this module with the perldoc command.
perldoc POE::Devel::Benchmarker
=head2 Websites
=over 4
=item * Search CPAN
L<http://search.cpan.org/dist/POE-Devel-Benchmarker>
=item * AnnoCPAN: Annotated CPAN documentation
L<http://annocpan.org/dist/POE-Devel-Benchmarker>
=item * CPAN Ratings
L<http://cpanratings.perl.org/d/POE-Devel-Benchmarker>
=item * CPAN Forum
L<http://cpanforum.com/dist/POE-Devel-Benchmarker>
=item * RT: CPAN's request tracker
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=POE-Devel-Benchmarker>
=item * CPANTS Kwalitee
L<http://cpants.perl.org/dist/overview/POE-Devel-Benchmarker>
=item * CPAN Testers Results
L<http://cpantesters.org/distro/P/POE-Devel-Benchmarker.html>
=item * CPAN Testers Matrix
L<http://matrix.cpantesters.org/?dist=POE-Devel-Benchmarker>
=item * Git Source Code Repository
This code is currently hosted on github.com under the account "apocalypse". Please feel free to browse it
and pull from it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull
from your repository :)
L<http://github.com/apocalypse/perl-poe-benchmarker>
=back
=head2 Bugs
Please report any bugs or feature requests to C<bug-poe-devel-benchmarker at rt.cpan.org>, or through
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=POE-Devel-Benchmarker>. I will be
notified, and then you'll automatically be notified of progress on your bug as I make changes.
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
BIG THANKS goes to Rocco Caputo E<lt>rcaputo@cpan.orgE<gt> for the first benchmarks!
=head1 COPYRIGHT AND LICENSE
Copyright 2010 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
=cut
|
apocalypse/perl-poe-benchmarker
|
75f24fb77b38b0064120622ab48a4353df195998
|
more work on tidying up the output
|
diff --git a/lib/POE/Devel/Benchmarker.pm b/lib/POE/Devel/Benchmarker.pm
index 8d6ea97..c5c83d5 100644
--- a/lib/POE/Devel/Benchmarker.pm
+++ b/lib/POE/Devel/Benchmarker.pm
@@ -615,592 +615,601 @@ sub wrapup_test : State {
'poe' => {
'v' => $_[HEAP]->{'current_version'}->stringify, # YAML::Tiny doesn't like version objects :(
'loop' => $_[HEAP]->{'current_loop'},
},
't' => {
's_ts' => $_[HEAP]->{'current_starttime'},
'e_ts' => $_[HEAP]->{'current_endtime'},
'd' => $_[HEAP]->{'current_endtime'} - $_[HEAP]->{'current_starttime'},
's_t' => [ @{ $_[HEAP]->{'current_starttimes'} } ],
'e_t' => [ @{ $_[HEAP]->{'current_endtimes'} } ],
},
'raw' => $_[HEAP]->{'current_data'},
'test' => $file,
'x_bench' => currentTestVersion(),
( $_[HEAP]->{'test_timedout'} ? ( 'timedout' => 1 ) : () ),
( $_[HEAP]->{'lite_tests'} ? ( 'litetests' => 1 ) : () ),
( $_[HEAP]->{'current_assertions'} ? ( 'asserts' => 1 ) : () ),
( $_[HEAP]->{'current_noxsqueue'} ? ( 'noxsqueue' => 1 ) : () ),
} );
# process the next test
$_[KERNEL]->yield( 'bench_xsqueue' );
return;
}
sub analyze_output : State {
# get the data
my $test = $_[ARG0];
## no critic ( ProhibitAccessOfPrivateData )
# clean up the times() stuff
$test->{'t'}->{'t'} = beautify_times(
join( " ", @{ delete $test->{'t'}->{'s_t'} } ) .
" " .
join( " ", @{ delete $test->{'t'}->{'e_t'} } )
);
# Okay, break it down into our data struct
$test->{'metrics'} = {};
my $d = $test->{'metrics'};
my @unknown;
foreach my $l ( split( /(?:\n|\r)/, $test->{'raw'} ) ) {
# skip empty lines
if ( $l eq '' ) { next }
# usual test benchmark output
# 10 startups in 0.885 seconds ( 11.302 per second)
# 10000 posts in 0.497 seconds ( 20101.112 per second)
if ( $l =~ /^\s+\d+\s+(\w+)\s+in\s+([\d\.]+)\s+seconds\s+\(\s+([\d\.]+)\s+per\s+second\)$/ ) {
$d->{ $1 }->{'d'} = $2; # duration in seconds
$d->{ $1 }->{'i'} = $3; # iterations per second
# usual test benchmark times output
# startup times: 0.1 0 0 0 0.1 0 0.76 0.09
} elsif ( $l =~ /^(\w+)\s+times:\s+(.+)$/ ) {
$d->{ $1 }->{'t'} = beautify_times( $2 ); # the times hash
# usual test SKIP output
# SKIPPING br0ken $metric because ...
} elsif ( $l =~ /^SKIPPING\s+br0ken\s+(\w+)\s+because/ ) {
# don't build their data struct
# parse the memory footprint stuff
} elsif ( $l =~ /^pidinfo:\s+(.+)$/ ) {
# what should we analyze?
my $pidinfo = $1;
# VmPeak: 16172 kB
if ( $pidinfo =~ /^VmPeak:\s+(.+)$/ ) {
$test->{'pid'}->{'vmpeak'} = $1;
# voluntary_ctxt_switches: 10
} elsif ( $pidinfo =~ /^voluntary_ctxt_switches:\s+(.+)$/ ) {
$test->{'pid'}->{'vol_ctxt'} = $1;
# nonvoluntary_ctxt_switches: 1221
} elsif ( $pidinfo =~ /^nonvoluntary_ctxt_switches:\s+(.+)$/ ) {
$test->{'pid'}->{'nonvol_ctxt'} = $1;
} else {
# ignore the rest of the fluff
}
# parse the perl binary stuff
} elsif ( $l =~ /^perlconfig:\s+(.+)$/ ) {
# what should we analyze?
my $perlconfig = $1;
# ignore the fluff ( not needed now... )
# parse the CPU info
} elsif ( $l =~ /^cpuinfo:\s+(.+)$/ ) {
# what should we analyze?
my $cpuinfo = $1;
# if this is on a multiproc system, we will overwrite the data per processor ( harmless... )
# cpu MHz : 1201.000
if ( $cpuinfo =~ /^cpu\s+MHz\s+:\s+(.+)$/ ) {
$test->{'cpu'}->{'mhz'} = $1;
# model name : Intel(R) Core(TM)2 Duo CPU L7100 @ 1.20GHz
} elsif ( $cpuinfo =~ /^model\s+name\s+:\s+(.+)$/ ) {
$test->{'cpu'}->{'name'} = $1;
# bogomips : 2397.58
} elsif ( $cpuinfo =~ /^bogomips\s+:\s+(.+)$/ ) {
$test->{'cpu'}->{'bogo'} = $1;
} else {
# ignore the rest of the fluff
}
# ignore any Devel::Hide stuff
# $l eq '!STDERR: Devel::Hide hides POE/XS/Queue/Array.pm'
} elsif ( $l =~ /^\!STDERR:\s+Devel\:\:Hide\s+hides/ ) {
# ignore them
# data that we can safely throw away
} elsif ( $l eq 'Using NO Assertions!' or
$l eq 'Using FULL Assertions!' or
$l eq 'Using the LITE tests' or
$l eq 'Using the HEAVY tests' or
$l eq 'DISABLING POE::XS::Queue::Array' or
$l eq 'LETTING POE find POE::XS::Queue::Array' or
$l eq 'UNABLE TO GET /proc/self/status' or
$l eq 'UNABLE TO GET /proc/cpuinfo' or
$l eq '!STDERR: POE::Kernel\'s run() method was never called.' or # to ignore old POEs that threw this warning
$l eq 'TEST TERMINATED DUE TO TIMEOUT' ) {
# ignore them
# parse the perl binary stuff
} elsif ( $l =~ /^Running\s+under\s+perl\s+binary:\s+\'([^\']+)\'\s+v([\d\.]+)$/ ) {
$test->{'perl'}->{'binary'} = $1;
# setup the perl version
$test->{'perl'}->{'v'} = $2;
# the master loop version ( what the POE::Loop::XYZ actually uses )
# Using loop: EV-3.49
} elsif ( $l =~ /^Using\s+master\s+loop:\s+(.+)$/ ) {
$test->{'poe'}->{'loop_m'} = $1;
# the real POE version that was loaded
# Using POE-1.001
} elsif ( $l =~ /^Using\s+POE-(.+)$/ ) {
$test->{'poe'}->{'v_real'} = $1;
# the various queue/loop modules we loaded
# POE is using: POE::XS::Queue::Array v0.005
# POE is using: POE::Queue v1.2328
# POE is using: POE::Loop::EV v0.06
} elsif ( $l =~ /^POE\s+is\s+using:\s+([^\s]+)\s+v(.+)$/ ) {
$test->{'poe'}->{'modules'}->{ $1 } = $2;
# get the uname info
# Running under machine: Linux apoc-x300 2.6.24-21-generic #1 SMP Tue Oct 21 23:43:45 UTC 2008 i686 GNU/Linux
} elsif ( $l =~ /^Running\s+under\s+machine:\s+(.+)$/ ) {
$test->{'uname'} = $1;
# parse any STDERR output
# !STDERR: unable to foo
} elsif ( $l =~ /^\!STDERR:\s+(.+)$/ ) {
push( @{ $test->{'stderr'} }, $1 );
} else {
# unknown line :(
push( @unknown, $l );
}
}
# Get rid of the rawdata
delete $test->{'raw'};
# Dump the unknowns
if ( @unknown ) {
print "\n[ANALYZER] Unknown output from benchmark -> " . Dump( \@unknown );
}
# Dump the data struct we have to the file.yml
my $yaml_file = File::Spec->catfile( 'results', ( delete $test->{'test'} ) . '.yml' );
my $ret = open( my $fh, '>', $yaml_file );
if ( defined $ret ) {
print $fh Dump( $test );
if ( ! close( $fh ) ) {
print "\n[ANALYZER] Unable to close $yaml_file -> " . $! . "\n";
}
} else {
print "\n[ANALYZER] Unable to open $yaml_file for writing -> " . $! . "\n";
}
# now that we've dumped the stuff, we can do some sanity checks
# the POE we "think" we loaded should match reality!
if ( exists $test->{'poe'}->{'v_real'} ) { # if this exists, then we successfully loaded POE
if ( $test->{'poe'}->{'v'} ne $test->{'poe'}->{'v_real'} ) {
print "\n[ANALYZER] The subprocess loaded a different version of POE than we thought -> $yaml_file\n";
}
# The loop we loaded should match what we wanted!
if ( exists $test->{'poe'}->{'modules'} ) {
if ( ! exists $test->{'poe'}->{'modules'}->{ poeloop2dist( $test->{'poe'}->{'loop'} ) } ) {
# gaah special-case for IO_Poll ( POE 0.21 to POE 0.29 introduced POE::Loop::Poll which later became POE::Loop::IO_Poll )
if ( $test->{'poe'}->{'loop'} eq 'IO_Poll' and exists $test->{'poe'}->{'modules'}->{'POE::Loop::Poll'} ) {
# ah, ignore this
} else {
print "\n[ANALYZER] The subprocess loaded a different Loop than we thought -> $yaml_file\n";
}
}
}
}
# the perl binary should be the same!
if ( exists $test->{'perl'} ) { # if this exists, we successfully fired up the app ( no compile error )
if ( $test->{'perl'}->{'binary'} ne $^X ) {
print "\n[ANALYZER] The subprocess booted up on a different perl binary -> $yaml_file\n";
}
if ( $test->{'perl'}->{'v'} ne sprintf( "%vd", $^V ) ) {
print "\n[ANALYZER] The subprocess booted up on a different perl version -> $yaml_file\n";
}
}
# Did we successfully run the entire testsuite?
if ( ! exists $test->{'pid'} ) {
print "\n[ANALYZER] The testsuite failed to run to completion -> $yaml_file\n";
}
# all done!
return;
}
1;
__END__
=for stopwords AnnoCPAN CPAN Caputo EV Eventloop Gtk HTTP Kqueue MYFH poe Prima RT SQLite STDIN SocketFactory TODO Tapout Wx XS YAML autoprobing backend benchmarker csv db dngor er freshstart hardcode litetests noasserts noxsqueue poedists pong svn untarred yml
=head1 NAME
POE::Devel::Benchmarker - Benchmarking POE's performance ( acts more like a smoker )
=head1 SYNOPSIS
use POE::Devel::Benchmarker;
benchmark();
=head1 ABSTRACT
This package of tools is designed to benchmark POE's performance across different
configurations. The current "tests" are:
=over 4
=item Events
posts: This tests how long it takes to post() N times
dispatches: This tests how long it took to dispatch/deliver all the posts enqueued in the "posts" test
single_posts: This tests how long it took to yield() between 2 states for N times
calls: This tests how long it took to call() N times
=item Alarms
alarms: This tests how long it took to add N alarms via alarm(), overwriting each other
alarm_adds: This tests how long it took to add N alarms via alarm_add()
alarm_clears: This tests how long it took to clear all alarms set in the "alarm_adds" test
NOTE: alarm_add is not available on all versions of POE!
=item Sessions
session_creates: This tests how long it took to create N sessions
session_destroys: This tests how long it took to destroy all sessions created in the "session_creates" test
=item Filehandles
select_read_STDIN: This tests how long it took to toggle select_read N times on STDIN
select_write_STDIN: This tests how long it took to toggle select_write N times on STDIN
select_read_MYFH: This tests how long it took to toggle select_read N times on a real filehandle
select_write_MYFH: This tests how long it took to toggle select_write N times on a real filehandle
NOTE: The MYFH tests don't include the time it took to open()/close() the file :)
=item Sockets
socket_connects: This tests how long it took to connect+disconnect to a SocketFactory server via localhost
socket_stream: This tests how long it took to send N chunks of data in a "ping-pong" fashion between the server and client
=item POE startup time
startups: This tests how long it took to start + close N instances of POE+Loop without any sessions/etc via system()
=item POE Loops
This is actually a "super" test where all of the specific tests is ran against various POE::Loop::XYZ/FOO for comparison
NOTE: Not all versions of POE support all Loops!
=item POE Assertions
This is actually a "super" test where all of the specific tests is ran against POE with/without assertions enabled
NOTE: Not all versions of POE support assertions!
=item POE::XS::Queue::Array
This is actually a "super" test where all of the specific tests is ran against POE with XS goodness enabled/disabled
NOTE: Not all versions of POE support XS::Queue::Array!
=back
=head1 DESCRIPTION
This module is poorly documented now. Please give me some time to properly document it over time :)
=head2 INSTALLATION
Here's a simple outline to get you up to speed quickly. ( and smoking! )
=over 4
=item Install CPAN package + dependencies
Download+install the POE::Devel::Benchmarker package from CPAN
apoc@apoc-x300:~$ cpanp -i POE::Devel::Benchmarker
=item Setup initial directories
Go anywhere, and create the "parent" directory where you'll be storing test results + stuff. For this example,
I have chosen to use ~/poe-benchmarker:
apoc@apoc-x300:~$ mkdir poe-benchmarker
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ mkdir poedists results images
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker::GetPOEdists -e 'getPOEdists( 1 )'
( go get a coffee while it downloads if you're on a slow link, ha! )
=item Let 'er rip!
At this point you can start running the benchmark!
NOTE: the Benchmarker expects everything to be in the "local" directory!
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker -e 'benchmark()'
( go sleep or something, this will take a while! )
=back
=head2 BENCHMARKING
On startup the Benchmarker will look in the "poedists" directory and load all the distributions it sees untarred there. Once
that is done it will begin autoprobing for available POE::Loop packages. Once it determines what's available, it will begin
the benchmarks.
As the Benchmarker goes through the combinations of POE + Eventloop + Assertions + XS::Queue it will dump data into
the results directory. The module also dumps YAML output in the same place, with the suffix of ".yml"
This module exposes only one subroutine, the benchmark() one. You can pass a hashref to it to set various options. Here is
a list of the valid options:
=over 4
=item freshstart => boolean
This will tell the Benchmarker to ignore any previous test runs stored in the 'results' directory. This will not delete
data from previous runs, only overwrite them. So be careful if you're mixing test runs from different versions!
benchmark( { freshstart => 1 } );
default: false
=item noxsqueue => boolean
This will tell the Benchmarker to force the unavailability of POE::XS::Queue::Array and skip those tests.
NOTE: The Benchmarker will set this automatically if it cannot load the module!
benchmark( { noxsqueue => 1 } );
default: false
=item noasserts => boolean
This will tell the Benchmarker to not run the ASSERT tests.
benchmark( { noasserts => 1 } );
default: false
=item litetests => boolean
This enables the "lite" tests which will not take up too much time.
benchmark( { litetests => 0 } );
default: true
=item quiet => boolean
This enables quiet mode which will not print anything to the console except for errors.
benchmark( { 'quiet' => 1 } );
default: false
=item loop => csv list or array
This overrides the built-in loop detection algorithm which searches for all known loops.
There is some "magic" here where you can put a negative sign in front of a loop and we will NOT run that.
NOTE: Capitalization is important!
benchmark( { 'loop' => 'IO_Poll,Select' } ); # runs only IO::Poll and Select
benchmark( { 'loop' => [ qw( Tk Gtk ) ] } ); # runs only Tk and Gtk
benchmark( { 'loop' => '-Tk' } ); # runs all available loops EXCEPT for TK
Known loops: Event_Lib EV Glib Prima Gtk Kqueue Tk Select IO_Poll
=item poe => csv list or array
This overrides the built-in POE version detection algorithm which pulls the POE versions from the 'poedists' directory.
There is some "magic" here where you can put a negative sign in front of a version and we will NOT run that.
NOTE: The Benchmarker will ignore versions that wasn't found in the directory!
benchmark( { 'poe' => '0.35,1.003' } ); # runs on 0.35 and 1.003
benchmark( { 'poe' => [ qw( 0.3009 0.12 ) ] } ); # runs on 0.3009 and 0.12
benchmark( { 'poe' => '-0.35' } ); # runs ALL tests except 0.35
=back
=head2 ANALYZING RESULTS
Please look at the pretty charts generated by the L<POE::Devel::Benchmarker::Imager> module.
=head1 EXPORT
Automatically exports the benchmark() subroutine.
=head1 TODO
=over 4
=item Perl version smoking
We should be able to run the benchmark over different Perl versions. This would require some fiddling with our
layout + logic. It's not that urgent because the workaround is to simply execute the benchmarker under a different
perl binary. It's smart enough to use $^X to be consistent across tests/subprocesses :)
=item Select the EV backend
<Khisanth> and if you are benchmarking, try it with POE using EV with EV using Glib? :P
<Apocalypse> I'm not sure how to configure the EV "backend" yet
<Apocalypse> too much docs for me to read hah
<Khisanth> Apocalypse: use EV::Glib; use Glib; use POE; :)
=item Be smarter in smoking timeouts
Currently we depend on the litetests option and hardcode some values including the timeout. If your machine is incredibly
slow, there's a chance that it could timeout unnecessarily. Please look at the outputs and check to see if there are unusual
failures, and inform me.
Also, some loops perform badly and take almost forever! /me glares at Gtk...
=item More benchmarks!
As usual, me and the crowd in #poe have plenty of ideas for tests. We'll be adding them over time, but if you have an idea please
drop me a line and let me know!
dngor said there was some benchmarks in the POE svn under trunk/queue...
<dngor> Apocalypse: Check out the old benchmarks in the queue directory in POE's repot.
They profile queue performance at various sizes, which is a better indication of scalability.
Tapout contributed a script that tests HTTP performance, let's see if it deserves to be in the suite :)
I added the preliminary socket tests, we definitely should expand it seeing how many people use POE for networking...
=item Add SQLite/DBI/etc support to the Analyzer
It would be nice if we could have a local SQLite db to dump our stats into. This would make arbitrary reports much easier than
loading raw YAML files and trying to make sense of them, ha! Also, this means somebody can do the smoking and send the SQLite
db to another person to generate the graphs, cool!
=item Wx loop support
I have Wx installed, but it doesn't work. I suspect the module is broken... Here's the error:
Can't call method "MainLoop" on an undefined value at /usr/local/share/perl/5.8.8/POE/Loop/Wx.pm line 91.
=item Multiple run support
I would like the benchmarker to run the testsuite N times, and summing up the data into an average so we have more sane data...
<dngor> Apocalypse: You could start with 5 runs, then continue running until the standard deviation reaches some sane level?
+=item Event loop support
+
+<Apocalypse> ascent_: Yeah, but unfortunately trying to use Loop::Event here with latest POE blows up :(
+<Apocalypse> apoc@blackhole:~$ POE_EVENT_LOOP="Event" perl -MPOE -e 1
+<Apocalypse> Can't locate object method "timer" via package "Event" at /usr/local/share/perl/5.10.0/POE/Loop/Event.pm line 47.
+<Apocalypse> Event.pm 1.13, POE::Loop::Event 1.302, POE 1.287
+<Apocalypse> ascent_: Patches welcome :)
+<ascent_> Apocalypse: POE_EVENT_LOOP="Event" perl -MEvent -MPOE -e 1 <- works fine... so patch is one-liner: use Event; ;)
+
=back
=head1 SEE ALSO
L<POE>
=head1 SUPPORT
You can find documentation for this module with the perldoc command.
perldoc POE::Devel::Benchmarker
=head2 Websites
=over 4
=item * Search CPAN
L<http://search.cpan.org/dist/POE-Devel-Benchmarker>
=item * AnnoCPAN: Annotated CPAN documentation
L<http://annocpan.org/dist/POE-Devel-Benchmarker>
=item * CPAN Ratings
L<http://cpanratings.perl.org/d/POE-Devel-Benchmarker>
=item * CPAN Forum
L<http://cpanforum.com/dist/POE-Devel-Benchmarker>
=item * RT: CPAN's request tracker
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=POE-Devel-Benchmarker>
=item * CPANTS Kwalitee
L<http://cpants.perl.org/dist/overview/POE-Devel-Benchmarker>
=item * CPAN Testers Results
L<http://cpantesters.org/distro/P/POE-Devel-Benchmarker.html>
=item * CPAN Testers Matrix
L<http://matrix.cpantesters.org/?dist=POE-Devel-Benchmarker>
=item * Git Source Code Repository
This code is currently hosted on github.com under the account "apocalypse". Please feel free to browse it
and pull from it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull
from your repository :)
L<http://github.com/apocalypse/perl-poe-benchmarker>
=back
=head2 Bugs
Please report any bugs or feature requests to C<bug-poe-devel-benchmarker at rt.cpan.org>, or through
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=POE-Devel-Benchmarker>. I will be
notified, and then you'll automatically be notified of progress on your bug as I make changes.
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
BIG THANKS goes to Rocco Caputo E<lt>rcaputo@cpan.orgE<gt> for the first benchmarks!
=head1 COPYRIGHT AND LICENSE
Copyright 2010 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
=cut
diff --git a/lib/POE/Devel/Benchmarker/Imager/BasicStatistics.pm b/lib/POE/Devel/Benchmarker/Imager/BasicStatistics.pm
index 4883ffb..2eb4f89 100644
--- a/lib/POE/Devel/Benchmarker/Imager/BasicStatistics.pm
+++ b/lib/POE/Devel/Benchmarker/Imager/BasicStatistics.pm
@@ -1,365 +1,365 @@
# Declare our package
package POE::Devel::Benchmarker::Imager::BasicStatistics;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.06';
# the GD stuff
use GD::Graph::lines;
use GD::Graph::colour qw( :lists );
use File::Spec;
# import some stuff
use POE::Devel::Benchmarker::Utils qw( currentMetrics );
# to silence Perl::Critic - # Three-argument form of open used at line 541, column 3. Three-argument open is not available until perl 5.6. (Severity: 5)
use 5.008;
# creates a new instance
sub new {
my $class = shift;
my $opts = shift;
# instantitate ourself
my $self = {
'opts' => $opts,
};
return bless $self, $class;
}
# actually generates the graphs!
sub imager {
my $self = shift;
$self->{'imager'} = shift;
# generate the loops vs each other graphs
$self->generate_loopwars;
# generate the single loop performance
$self->generate_loopperf;
# generate the loop assert/xsqueue ( 4 lines ) per metric
$self->generate_loopoptions;
return;
}
# charts a single loop's progress over POE versions
sub generate_loopoptions {
my $self = shift;
if ( ! $self->{'imager'}->quiet ) {
print "[BasicStatistics] Generating the Loop-Options graphs...\n";
}
# go through all the loops we want
foreach my $loop ( keys %{ $self->{'imager'}->poe_loops } ) {
foreach my $metric ( @{ currentMetrics() } ) {
my %data;
# organize data by POE version
foreach my $poe ( @{ $self->{'imager'}->poe_versions_sorted } ) {
# go through the combo of assert/xsqueue
foreach my $assert ( qw( assert noassert ) ) {
if ( ! exists $self->{'imager'}->data->{ $assert } ) {
next;
}
foreach my $xsqueue ( qw( xsqueue noxsqueue ) ) {
if ( ! exists $self->{'imager'}->data->{ $assert }->{ $xsqueue } ) {
next;
}
# sometimes we cannot test a metric
if ( exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }
and exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
and defined $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
) {
push( @{ $data{ $assert . '_' . $xsqueue } }, $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'} );
} else {
push( @{ $data{ $assert . '_' . $xsqueue } }, 0 );
}
}
}
}
# it's possible for us to do runs without assert/xsqueue
if ( scalar keys %data > 0 ) {
# transform %data into something GD likes
my @data_for_gd;
foreach my $m ( sort keys %data ) {
push( @data_for_gd, $data{ $m } );
}
# send it to GD!
$self->make_gdgraph( 'Options_' . $loop . '_' . $metric,
[ sort keys %data ],
\@data_for_gd,
);
}
}
}
return;
}
# charts a single loop's progress over POE versions
sub generate_loopperf {
my $self = shift;
if ( ! $self->{'imager'}->quiet ) {
print "[BasicStatistics] Generating the Loop-Performance graphs...\n";
}
# go through all the loops we want
foreach my $loop ( keys %{ $self->{'imager'}->poe_loops } ) {
# go through the combo of assert/xsqueue
foreach my $assert ( qw( assert noassert ) ) {
if ( ! exists $self->{'imager'}->data->{ $assert } ) {
next;
}
foreach my $xsqueue ( qw( xsqueue noxsqueue ) ) {
if ( ! exists $self->{'imager'}->data->{ $assert }->{ $xsqueue } ) {
next;
}
my %data;
# organize data by POE version
foreach my $poe ( @{ $self->{'imager'}->poe_versions_sorted } ) {
foreach my $metric ( @{ currentMetrics() } ) {
# sometimes we cannot test a metric
if ( exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }
and exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
and defined $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
) {
push( @{ $data{ $metric } }, $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'} );
} else {
push( @{ $data{ $metric } }, 0 );
}
}
}
# transform %data into something GD likes
my @data_for_gd;
foreach my $m ( sort keys %data ) {
push( @data_for_gd, $data{ $m } );
}
# send it to GD!
$self->make_gdgraph( 'Bench_' . $loop,
[ sort keys %data ],
\@data_for_gd,
$assert,
$xsqueue,
);
}
}
}
return;
}
# loop wars!
sub generate_loopwars {
my $self = shift;
if ( ! $self->{'imager'}->quiet ) {
print "[BasicStatistics] Generating the LoopWars graphs...\n";
}
# go through all the metrics we want
foreach my $metric ( @{ currentMetrics() } ) {
# go through the combo of assert/xsqueue
foreach my $assert ( qw( assert noassert ) ) {
if ( ! exists $self->{'imager'}->data->{ $assert } ) {
next;
}
foreach my $xsqueue ( qw( xsqueue noxsqueue ) ) {
if ( ! exists $self->{'imager'}->data->{ $assert }->{ $xsqueue } ) {
next;
}
my %data;
# organize data by POE version
foreach my $poe ( @{ $self->{'imager'}->poe_versions_sorted } ) {
foreach my $loop ( keys %{ $self->{'imager'}->poe_loops } ) {
# sometimes we cannot test a metric
if ( exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }
and exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
and defined $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
) {
push( @{ $data{ $loop } }, $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'} );
} else {
push( @{ $data{ $loop } }, 0 );
}
}
}
# transform %data into something GD likes
my @data_for_gd;
foreach my $m ( sort keys %data ) {
push( @data_for_gd, $data{ $m } );
}
# send it to GD!
$self->make_gdgraph( "LoopWar_$metric",
[ sort keys %{ $self->{'imager'}->poe_loops } ],
\@data_for_gd,
$assert,
$xsqueue,
);
}
}
}
return;
}
sub make_gdgraph {
my $self = shift;
my $metric = shift;
my $legend = shift;
my $data = shift;
my $assert = shift;
my $xsqueue = shift;
# build the title
my $title = $metric;
if ( defined $assert ) {
$title .= ' (';
if ( defined $xsqueue ) {
$title .= $assert . ' ' . $xsqueue;
} else {
$title .= $assert;
}
$title .= ')';
} else {
if ( defined $xsqueue ) {
$title .= ' (' . $xsqueue . ')';
}
}
# Get the graph object
my $graph = new GD::Graph::lines( 800, 600 );
# Set some stuff
$graph->set(
'title' => $title,
'line_width' => 1,
'boxclr' => 'black',
'overwrite' => 0,
'x_labels_vertical' => 1,
'x_all_ticks' => 1,
'legend_placement' => 'BL',
'y_label' => 'iterations/sec',
'transparent' => 0,
'long_ticks' => 1,
) or die $graph->error;
# Set the legend
$graph->set_legend( @$legend );
# Set Font stuff
$graph->set_legend_font( GD::gdMediumBoldFont );
$graph->set_x_axis_font( GD::gdMediumBoldFont );
$graph->set_y_axis_font( GD::gdMediumBoldFont );
$graph->set_y_label_font( GD::gdMediumBoldFont );
$graph->set_title_font( GD::gdGiantFont );
# set the line colors
# I don't like what this results in...
$graph->set( 'dclrs' => [ grep { $_ ne 'black' and $_ ne 'white' and substr( $_, 0, 1 ) eq 'd' } sorted_colour_list() ] );
# Manufacture the data
my $readydata = [
[ map { 'POE-' . $_ } @{ $self->{'imager'}->poe_versions_sorted } ],
@$data,
];
# Plot it!
$graph->plot( $readydata ) or die $graph->error;
# Print it!
my $filename = File::Spec->catfile( $self->{'opts'}->{'dir'}, $metric . '_' .
( $self->{'imager'}->litetests ? 'lite' : 'heavy' ) .
( defined $xsqueue ? '_' . $assert . '_' . $xsqueue : '' ) .
'.png' );
- open( my $fh, '>', $filename ) or die 'Cannot open graph file!';
+ open( my $fh, '>', $filename ) or die "Cannot open graph file: $!";
binmode( $fh );
print $fh $graph->gd->png();
- close( $fh );
+ close( $fh ) or die "Unable to close graph file: $!";
return;
}
1;
__END__
=for stopwords backend
=head1 NAME
POE::Devel::Benchmarker::Imager::BasicStatistics - Plugin to generate basic statistics graphs
=head1 SYNOPSIS
use POE::Devel::Benchmarker::Imager;
imager( { type => 'BasicStatistics' } );
=head1 ABSTRACT
This plugin for Imager generates some kinds of graphs from the benchmark tests.
=head1 DESCRIPTION
This package generates some basic graphs from the statistics output. Since the POE::Loop::* modules really are responsible
for the backend logic of POE, it makes sense to graph all related metrics of a single loop across POE versions to see if
it performs differently.
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker::Imager -e 'imager( { type => "BasicStatistics" } )'
This will generate some types of graphs:
=over 4
=item Loops against each other
Each metric will have a picture for itself, showing how each loop compare against each other with the POE versions.
file: BasicStatistics/LoopWar_$metric_$lite_$assert_$xsqueue.png
=item Single Loop over POE versions
Each Loop will have a picture for itself, showing how each metric performs over POE versions.
file: BasicStatistics/Bench_$loop_$lite_$assert_$xsqueue.png
=item Single Loop over POE versions with assert/xsqueue
Each Loop will have a picture for itself, showing how each metric is affected by the assert/xsqueue options.
file: BasicStatistics/Options_$loop_$metric_$lite.png
=back
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
L<POE::Devel::Benchmarker::Imager>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2010 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/Imager/BenchmarkOutput.pm b/lib/POE/Devel/Benchmarker/Imager/BenchmarkOutput.pm
index 8016ea1..65e66ba 100644
--- a/lib/POE/Devel/Benchmarker/Imager/BenchmarkOutput.pm
+++ b/lib/POE/Devel/Benchmarker/Imager/BenchmarkOutput.pm
@@ -1,354 +1,446 @@
# Declare our package
package POE::Devel::Benchmarker::Imager::BenchmarkOutput;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.06';
# import some stuff
use File::Spec;
use POE::Devel::Benchmarker::Utils qw( currentMetrics metricSorting );
use Text::Table;
# to silence Perl::Critic - # Three-argument form of open used at line 541, column 3. Three-argument open is not available until perl 5.6. (Severity: 5)
use 5.008;
# creates a new instance
sub new {
my $class = shift;
my $opts = shift;
# instantitate ourself
my $self = {
'opts' => $opts,
};
return bless $self, $class;
}
-# actually generates the graphs!
+# actually generates the tables!
sub imager {
my $self = shift;
$self->{'imager'} = shift;
# generate the loops vs each other graphs
$self->generate_loopwars;
# generate the single loop performance
- #$self->generate_loopperf;
+ $self->generate_loopperf;
# generate the loop assert/xsqueue ( 4 lines ) per metric
#$self->generate_loopoptions;
return;
}
# charts a single loop's progress over POE versions
sub generate_loopoptions {
my $self = shift;
if ( ! $self->{'imager'}->quiet ) {
print "[BenchmarkOutput] Generating the Loop-Options tables...\n";
}
# go through all the loops we want
foreach my $loop ( keys %{ $self->{'imager'}->poe_loops } ) {
foreach my $metric ( @{ currentMetrics() } ) {
my %data;
# organize data by POE version
foreach my $poe ( @{ $self->{'imager'}->poe_versions_sorted } ) {
# go through the combo of assert/xsqueue
foreach my $assert ( qw( assert noassert ) ) {
if ( ! exists $self->{'imager'}->data->{ $assert } ) {
next;
}
foreach my $xsqueue ( qw( xsqueue noxsqueue ) ) {
if ( ! exists $self->{'imager'}->data->{ $assert }->{ $xsqueue } ) {
next;
}
# sometimes we cannot test a metric
if ( exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }
and exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
and defined $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
) {
push( @{ $data{ $assert . '_' . $xsqueue } }, $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'} );
} else {
push( @{ $data{ $assert . '_' . $xsqueue } }, 0 );
}
}
}
}
use Data::Dumper;
print Dumper( \%data );
exit;
# it's possible for us to do runs without assert/xsqueue
if ( scalar keys %data > 0 ) {
# transform %data into something GD likes
my @data_for_gd;
foreach my $m ( sort keys %data ) {
push( @data_for_gd, $data{ $m } );
}
# send it to GD!
$self->make_gdgraph( 'Options_' . $loop . '_' . $metric,
[ sort keys %data ],
\@data_for_gd,
);
}
}
}
return;
}
# charts a single loop's progress over POE versions
sub generate_loopperf {
my $self = shift;
if ( ! $self->{'imager'}->quiet ) {
print "[BenchmarkOutput] Generating the Loop-Performance tables...\n";
}
# go through all the loops we want
foreach my $loop ( keys %{ $self->{'imager'}->poe_loops } ) {
+ # The entire document...
+ my $text;
+
# go through the combo of assert/xsqueue
foreach my $assert ( qw( assert noassert ) ) {
if ( ! exists $self->{'imager'}->data->{ $assert } ) {
next;
}
foreach my $xsqueue ( qw( xsqueue noxsqueue ) ) {
if ( ! exists $self->{'imager'}->data->{ $assert }->{ $xsqueue } ) {
next;
}
my %data;
# organize data by POE version
foreach my $poe ( @{ $self->{'imager'}->poe_versions_sorted } ) {
foreach my $metric ( @{ currentMetrics() } ) {
# sometimes we cannot test a metric
if ( exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }
and exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
and defined $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
) {
push( @{ $data{ $metric } }, $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'} );
} else {
push( @{ $data{ $metric } }, 0 );
}
}
}
- use Data::Dumper;
- print Dumper( $loop, $self->{'imager'}->poe_versions_sorted, \%data );
-
# Actually make the table!
- $self->make_table( "Loop Performance",
- $loop,
- $assert,
- $xsqueue,
- $self->{'imager'}->poe_versions_sorted,
- \%data,
- );
+ $text .= $self->make_loopperf_table( $loop, $assert, $xsqueue, $self->{'imager'}->poe_versions_sorted, \%data );
}
}
+
+ # Save it!
+ my $filename = File::Spec->catfile( $self->{'opts'}->{'dir'}, 'Benchmark_' . $loop . '.txt' );
+ open( my $fh, '>', $filename ) or die "Cannot open output file: $!";
+ print $fh $text;
+ close( $fh ) or die "Unable to close output file: $!";
}
return;
}
+sub make_loopperf_table {
+ my( $self, $loop, $assert, $xsqueue, $poeversions, $data ) = @_;
+
+ # Start the text with a header
+ my $text = "\tLoop Benchmarking ( $loop ) ";
+
+ if ( $assert eq 'assert' ) {
+ $text .= "ASSERT ";
+ } else {
+ $text .= "NO-ASSERT ";
+ }
+
+ if ( $xsqueue eq 'xsqueue' ) {
+ $text .= "XSQUEUE";
+ } else {
+ $text .= "NO-XSQUEUE";
+ }
+
+ $text .= "\n\n";
+
+ # Create the grid
+ my @metrics = sort keys %$data;
+ my $tbl = Text::Table->new(
+ # The POE version column
+ { title => "POE Version", align => 'center', align_title => 'center' },
+
+ # The vertical separator
+ \' | ',
+
+ # The rest of the columns
+ map { \' | ', { title => $_, align => 'center', align_title => 'center' } } @metrics
+ );
+
+ # put << 234 >> around cells that are the "winner" of that metric
+ foreach my $m ( keys %$data ) {
+ my $best = undef;
+ my $metric_sorting = metricSorting( $m );
+ foreach my $i ( 0 .. ( scalar @{ $data->{ $m } } - 1 ) ) {
+ if ( ! defined $best ) {
+ $best = $i;
+ } else {
+ # What is the sort order?
+ if ( $metric_sorting eq 'B' ) {
+ if ( $data->{ $m }->[ $i ] > $data->{ $m }->[ $best ] ) {
+ $best = $i;
+ }
+ } elsif ( $metric_sorting eq 'S' ) {
+ if ( $data->{ $m }->[ $i ] < $data->{ $m }->[ $best ] ) {
+ $best = $i;
+ }
+ } else {
+ die "Unknown metric sorting method: $metric_sorting";
+ }
+ }
+ }
+
+ # We found the best one...
+ $data->{ $m }->[ $best ] = "<< " . $data->{ $m }->[ $best ] . " >>";
+ }
+
+ # Fill in the data!
+ foreach my $i ( 0 .. ( scalar @$poeversions - 1 ) ) {
+ my @tmp = ( $poeversions->[ $i ] );
+
+ foreach my $l ( 0 .. ( scalar @metrics - 1 ) ) {
+ push( @tmp, $data->{ $metrics[ $l ] }->[ $i ] );
+ }
+
+ $tbl->add( @tmp );
+ }
+
+ # Get the table, insert the horizontal divider, then print it out!
+ $text .= $tbl->table( 0 );
+ $text .= $tbl->rule( '-' );
+ $text .= $tbl->table( 1, $tbl->n_cols() - 1 );
+ $text .= $tbl->rule( '-' );
+ $text .= "\n\n";
+
+ # All done!
+ return $text;
+}
+
# loop wars!
sub generate_loopwars {
my $self = shift;
if ( ! $self->{'imager'}->quiet ) {
print "[BenchmarkOutput] Generating the LoopWars tables...\n";
}
+ # The entire document...
+ my $text;
+
# go through all the metrics we want
foreach my $metric ( @{ currentMetrics() } ) {
# go through the combo of assert/xsqueue
foreach my $assert ( qw( assert noassert ) ) {
if ( ! exists $self->{'imager'}->data->{ $assert } ) {
next;
}
foreach my $xsqueue ( qw( xsqueue noxsqueue ) ) {
if ( ! exists $self->{'imager'}->data->{ $assert }->{ $xsqueue } ) {
next;
}
my %data;
# organize data by POE version
foreach my $poe ( @{ $self->{'imager'}->poe_versions_sorted } ) {
foreach my $loop ( keys %{ $self->{'imager'}->poe_loops } ) {
# sometimes we cannot test a metric
if ( exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }
and exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
and defined $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
) {
push( @{ $data{ $loop } }, $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'} );
} else {
push( @{ $data{ $loop } }, 0 );
}
}
}
# Actually make the table!
- $self->make_loopwar_table( $metric, $assert, $xsqueue, $self->{'imager'}->poe_versions_sorted, \%data );
+ $text .= $self->make_loopwar_table( $metric, $assert, $xsqueue, $self->{'imager'}->poe_versions_sorted, \%data );
}
}
}
+ # Save it!
+ my $filename = File::Spec->catfile( $self->{'opts'}->{'dir'}, 'LoopWars.txt' );
+ open( my $fh, '>', $filename ) or die "Cannot open output file: $!";
+ print $fh $text;
+ close( $fh ) or die "Unable to close output file: $!";
+
return;
}
sub make_loopwar_table {
my( $self, $metric, $assert, $xsqueue, $poeversions, $data ) = @_;
my $metric_sorting = metricSorting( $metric );
# Start the text with a header
- my $text = " LoopWars - Metric ( $metric/sec ) ";
+ my $text = "\tLoopWars - Metric ( $metric/sec ) ";
if ( $assert eq 'assert' ) {
$text .= "ASSERT ";
} else {
$text .= "NO-ASSERT ";
}
if ( $xsqueue eq 'xsqueue' ) {
$text .= "XSQUEUE";
} else {
$text .= "NO-XSQUEUE";
}
$text .= "\n\n";
# Create the grid
my @loops = sort keys %$data;
my $tbl = Text::Table->new(
# The POE version column
{ title => "POE Version", align => 'center', align_title => 'center' },
# The vertical separator
\' | ',
# The rest of the columns
map { \' | ', { title => $_, align => 'center', align_title => 'center' } } @loops
);
# Fill in the data!
foreach my $i ( 0 .. ( scalar @$poeversions - 1 ) ) {
my @tmp = ( $poeversions->[ $i ] );
# put << 234 >> around cells that are the "winner" of that metric
my $best = undef;
foreach my $l ( 0 .. ( scalar @loops - 1 ) ) {
if ( ! defined $best ) {
$best = $l;
} else {
# What is the sort order?
if ( $metric_sorting eq 'B' ) {
if ( $data->{ $loops[ $l ] }->[ $i ] > $data->{ $loops[ $best ] }->[ $i ] ) {
$best = $l;
}
} elsif ( $metric_sorting eq 'S' ) {
if ( $data->{ $loops[ $l ] }->[ $i ] < $data->{ $loops[ $best ] }->[ $i ] ) {
$best = $l;
}
} else {
die "Unknown metric sorting method: $metric_sorting";
}
}
push( @tmp, $data->{ $loops[ $l ] }->[ $i ] );
}
# We found the best one...
$tmp[ $best + 1 ] = "<< " . $tmp[ $best + 1 ] . " >>";
$tbl->add( @tmp );
}
# Get the table, insert the horizontal divider, then print it out!
$text .= $tbl->table( 0 );
$text .= $tbl->rule( '-' );
$text .= $tbl->table( 1, $tbl->n_cols() - 1 );
$text .= $tbl->rule( '-' );
+ $text .= "\n\n";
# All done!
- print $text;
+ return $text;
}
1;
__END__
=for stopwords backend
=head1 NAME
POE::Devel::Benchmarker::Imager::BenchmarkOutput - Plugin to generate output similar to Benchmark.pm
=head1 SYNOPSIS
use POE::Devel::Benchmarker::Imager;
imager( { type => 'BenchmarkOutput' } );
=head1 ABSTRACT
This plugin for Imager generates Benchmark.pm-alike output from the benchmark tests.
=head1 DESCRIPTION
This package generates some basic text tables from the statistics output. Since the POE::Loop::* modules really are responsible
for the backend logic of POE, it makes sense to measure all related metrics of a single loop across POE versions to see if
it performs differently.
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker::Imager -e 'imager( { type => "BenchmarkOutput" } )'
This will generate some types of tables:
=over 4
=item Loops against each other
Each metric will have a table for itself, showing how each loop compare against each other with the POE versions.
-file: BenchmarkOutput/LoopWar_$metric_$lite_$assert_$xsqueue.txt
+file: BenchmarkOutput/LoopWars.txt
=item Single Loop over POE versions
Each Loop will have a table for itself, showing how each metric performs over POE versions.
-file: BenchmarkOutput/Bench_$loop_$lite_$assert_$xsqueue.txt
+file: BenchmarkOutput/Bench_$loop.txt
=item Single Loop over POE versions with assert/xsqueue
Each Loop will have a table for itself, showing how each metric is affected by the assert/xsqueue options.
-file: BenchmarkOutput/Options_$loop_$metric_$lite.txt
+file: BenchmarkOutput/Options_$loop.txt
=back
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
L<POE::Devel::Benchmarker::Imager>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2010 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
|
apocalypse/perl-poe-benchmarker
|
2a86113bae50c2e4fafb213d83e15ec5263b24d8
|
start of work on benchmark output and multirun
|
diff --git a/Build.PL b/Build.PL
index c4ef2d3..c54d3f4 100644
--- a/Build.PL
+++ b/Build.PL
@@ -1,100 +1,92 @@
# Build.PL
use strict; use warnings;
use Module::Build;
my $build = Module::Build->new(
# look up Module::Build::API for the info!
'dynamic_config' => 0,
'module_name' => 'POE::Devel::Benchmarker',
'license' => 'perl',
'dist_abstract' => "Benchmarking POE's performance ( acts more like a smoker )",
'dist_author' => 'Apocalypse <APOCAL@cpan.org>',
'create_packlist' => 1,
'create_makefile_pl' => 'traditional',
'create_readme' => 1,
'create_license' => 1,
'sign' => 0,
'test_files' => 't/*.t',
'add_to_cleanup' => [ 'META.yml', 'Makefile.PL', 'README', 'Makefile', 'LICENSE' ], # automatically generated
'requires' => {
# POE Stuff
- 'POE' => 0,
+ 'POE' => '1.001', # for the POE_EVENT_LOOP env var which is so handy!
'POE::Session::AttributeBased' => 0,
# misc perl stuff
'Time::HiRes' => 0,
'version' => 0,
'Devel::Hide' => 0,
'File::Spec' => 0,
# Analyzer reqs
'YAML::Tiny' => 0,
# GetPOEdists reqs
'LWP::UserAgent' => 0,
'HTML::LinkExtor' => 0,
'URI::URL' => 0,
'Archive::Tar' => 0,
# Imager reqs
'GD::Graph::lines' => 0,
'GD::Graph::colour' => 0,
'Class::Accessor::Fast' => 0,
'Module::Pluggable' => 0,
+ 'Text::Table' => 0,
# Test stuff
'Test::More' => 0,
# we need a recent perl
'perl' => '5.008',
},
'recommends' => {
# our POE loops!
'POE::Loop::Event' => 0,
'POE::Loop::Event_Lib' => 0,
'POE::Loop::EV' => 0,
'POE::Loop::Glib' => 0,
'POE::Loop::Prima' => 0,
'POE::Loop::Gtk' => 0,
'POE::Loop::Wx' => 0,
'POE::Loop::Kqueue' => 0,
+ 'POE::Loop::Tk' => 0,
+ 'POE::XS::Loop::Poll' => 0,
+ 'POE::XS::Loop::EPoll' => 0,
# included in POE ( listed here for completeness )
- #'POE::Loop::Tk' => 0,
#'POE::Loop::Select' => 0,
#'POE::Loop::IO_Poll' => 0,
- # the loops' dependencies
- 'Event' => 0,
- 'Event::Lib' => 0,
- 'EV' => 0,
- 'Glib' => 0,
- 'Prima' => 0,
- 'Wx' => 0,
- 'Tk' => 0,
-
- # the XS stuff
+ # our XS queue
'POE::XS::Queue::Array' => 0,
- 'POE::XS::Loop::Poll' => 0,
- 'POE::XS::Loop::EPoll' => 0,
},
# include the standard stuff in META.yml
'meta_merge' => {
'resources' => {
'license' => 'http://dev.perl.org/licenses/',
'homepage' => 'http://search.cpan.org/dist/POE-Devel-Benchmarker',
'bugtracker' => 'http://rt.cpan.org/NoAuth/Bugs.html?Dist=POE-Devel-Benchmarker',
'repository' => 'http://github.com/apocalypse/perl-poe-benchmarker',
},
},
);
# all done!
$build->create_build_script;
diff --git a/Changes b/Changes
index 1dfa118..05a249a 100644
--- a/Changes
+++ b/Changes
@@ -1,51 +1,56 @@
Revision history for Perl extension POE::Devel::Benchmarker
* 0.06
POD tweaks and typo fixes
Cleanup Build.PL and remove a lot of tests in favor of Test::Apocalypse
Fixed a bug where the Benchmarker wouldn't recognize old test runs and skip them
Add File::Spec so we are more portable, yay!
POE::Loop::Event wasn't benchmarked - added to the list
- Wx/POE::Loop::Wx works now - added to the list
+ Probing for Wx enabled but it still doesn't work :(
Finally fired up a FreeBSD VM and confirmed that POE::Loop::Kqueue works - added to the list
+ Tweaked the loop loader routines to take advantage of the POE_EVENT_LOOP env var
+ Finally enabled the XS loops, yay!
+ Bumped YAML output version to ensure sanity
+ Added the BenchmarkOutput plugin to the Imager for output similar to Benchmark.pm
+ Added the type option to imager()
* 0.05
Minor tweaks on the YAML output ( nothing new, hah! )
Added the socket tests, yay! ( still need more work so we test various methods of socket creation )
Some more tweaks to the BasicStatistics plugin for prettier graphs
Lots of refactoring to get things cleaned up :)
Added test versioning, so we make sure we're processing the right version :)
added examples/test.pl to satisfy kwalitee requirements, ha!
* 0.04
Started work on the image generator ( Imager ) and added the BasicStatistics plugin, yay!
Added automatic "pick up where we left off" to the benchmarker
Added the freshstart option to benchmark()
Tweaked the GetPOEdists sub so it will work in the "work directory" and in the poedists dir
Tweaked the YAML output so it's smaller
Removed POE::Loop::Wx from autoprobing ( I'm unable to get it to work )
Removed POE::Loop::Kqueue from autoprobing ( I'm unable to get it to work )
Hardcoded the Benchmarker routines to skip POE < 0.13 ( I'm unable to get it to work )
* 0.03
Added the loop option to benchmark(), thanks dngor!
Added the poe option to benchmark(), thanks dngor!
Added the noxsqueue option to benchmark()
Added the noasserts option to benchmark()
Automatically enable noxsqueue option if we cannot load POE::XS::Queue::Array, saving time
Bump Test::More version requirement because some people reported failures with note()
Fixed bug in SubProcess where it crashed on old POEs that didn't load IO::Handle
More documentation additions/tweaks
* 0.02
Added the Analyzer module ( and dump YAML files, yay! )
A lot of minor changes+tweaks to get a better dump format
* 0.01
initial release
diff --git a/MANIFEST b/MANIFEST
index fed286c..72e5e5a 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -1,21 +1,22 @@
Build.PL
MANIFEST
MANIFEST.SKIP
README
Makefile.PL
META.yml
Changes
LICENSE
lib/POE/Devel/Benchmarker.pm
lib/POE/Devel/Benchmarker/GetInstalledLoops.pm
+lib/POE/Devel/Benchmarker/GetInstalledLoops/SubProcess.pm
lib/POE/Devel/Benchmarker/GetPOEdists.pm
lib/POE/Devel/Benchmarker/SubProcess.pm
lib/POE/Devel/Benchmarker/Utils.pm
lib/POE/Devel/Benchmarker/Imager.pm
lib/POE/Devel/Benchmarker/Imager/BasicStatistics.pm
examples/test.pl
t/1_load.t
t/apocalypse.t
diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP
index 86794f1..358b982 100644
--- a/MANIFEST.SKIP
+++ b/MANIFEST.SKIP
@@ -1,30 +1,32 @@
+# skip Eclipse IDE stuff
\.includepath$
\.project$
\.settings/
# Avoid version control files.
\B\.svn\b
\B\.git\b
# Avoid Makemaker generated and utility files.
\bMakefile$
\bblib/
\bMakeMaker-\d
\bpm_to_blib$
# Avoid Module::Build generated and utility files.
\bBuild$
\b_build/
+^MYMETA.yml$
# Avoid temp and backup files.
~$
\.old$
\#$
\b\.#
\.bak$
# our tarballs
\.tar\.gz$
# skip the local scripts directory where I store snippets of benchmarks
scripts/
diff --git a/POE-Devel-Benchmarker-0.06.tar.gz b/POE-Devel-Benchmarker-0.06.tar.gz
index 5067e8a..17b1d73 100644
Binary files a/POE-Devel-Benchmarker-0.06.tar.gz and b/POE-Devel-Benchmarker-0.06.tar.gz differ
diff --git a/lib/POE/Devel/Benchmarker.pm b/lib/POE/Devel/Benchmarker.pm
index f86dafa..8d6ea97 100644
--- a/lib/POE/Devel/Benchmarker.pm
+++ b/lib/POE/Devel/Benchmarker.pm
@@ -1,1165 +1,1206 @@
# Declare our package
package POE::Devel::Benchmarker;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.06';
# auto-export the only sub we have
use base qw( Exporter );
our @EXPORT = qw( benchmark );
# load needed modules
use Time::HiRes qw( time );
use version;
use YAML::Tiny qw( Dump );
use File::Spec;
+# to silence Perl::Critic - # Three-argument form of open used at line 541, column 3. Three-argument open is not available until perl 5.6. (Severity: 5)
+use 5.008;
+
# Import what we need from the POE namespace
use POE qw( Session Filter::Line Wheel::Run );
use base 'POE::Session::AttributeBased';
# Load our stuff
use POE::Devel::Benchmarker::GetInstalledLoops;
-use POE::Devel::Benchmarker::Utils qw( poeloop2load knownloops generateTestfile beautify_times currentTestVersion );
+use POE::Devel::Benchmarker::Utils qw( poeloop2load poeloop2dist knownloops generateTestfile beautify_times currentTestVersion );
# Actually run the tests!
sub benchmark {
my $options = shift;
# set default options
my $lite_tests = 1;
my $quiet_mode = 0;
my $forceloops = undef; # default to autoprobe all
my $forcepoe = undef; # default to all found POE versions in poedists/
my $forcenoxsqueue = 0; # default to try and load it
my $forcenoasserts = 0; # default is to run it
my $freshstart = 0; # always resume where we left off
# process our options
if ( defined $options and ref $options and ref( $options ) eq 'HASH' ) {
+ ## no critic ( ProhibitAccessOfPrivateData )
+
# process YES for freshstart
if ( exists $options->{'freshstart'} ) {
if ( $options->{'freshstart'} ) {
$freshstart = 1;
}
delete $options->{'freshstart'};
}
# process NO for XS::Queue::Array
if ( exists $options->{'noxsqueue'} ) {
if ( $options->{'noxsqueue'} ) {
$forcenoxsqueue = 1;
}
delete $options->{'noxsqueue'};
}
# process NO for ASSERT
if ( exists $options->{'noasserts'} ) {
if ( $options->{'noasserts'} ) {
$forcenoasserts = 1;
}
delete $options->{'noasserts'};
}
# process LITE tests
if ( exists $options->{'litetests'} ) {
if ( $options->{'litetests'} ) {
$lite_tests = 1;
} else {
$lite_tests = 0;
}
delete $options->{'litetests'};
}
# process quiet mode
if ( exists $options->{'quiet'} ) {
if ( $options->{'quiet'} ) {
$quiet_mode = 1;
} else {
$quiet_mode = 0;
}
delete $options->{'quiet'};
}
# process forceloops
if ( exists $options->{'loop'} and defined $options->{'loop'} ) {
if ( ! ref $options->{'loop'} ) {
# split it via CSV
$forceloops = [ split( /,/, $options->{'loop'} ) ];
foreach ( @$forceloops ) {
$_ =~ s/^\s+//; $_ =~ s/\s+$//;
}
} else {
# treat it as array
$forceloops = $options->{'loop'};
}
# check for !loop modules
my @noloops;
foreach my $l ( @$forceloops ) {
if ( $l =~ /^\!/ ) {
push( @noloops, substr( $l, 1 ) );
}
}
if ( scalar @noloops ) {
# replace the forceloops with ALL known, then subtract noloops from it
my %bad;
@bad{@noloops} = () x @noloops;
@$forceloops = grep { !exists $bad{$_} } @{ knownloops() };
}
delete $options->{'loop'};
}
# process the poe versions
if ( exists $options->{'poe'} and defined $options->{'poe'} ) {
if ( ! ref $options->{'poe'} ) {
# split it via CSV
$forcepoe = [ split( /,/, $options->{'poe'} ) ];
foreach ( @$forcepoe ) {
$_ =~ s/^\s+//; $_ =~ s/\s+$//;
}
} else {
# treat it as array
$forcepoe = $options->{'poe'};
}
delete $options->{'poe'};
}
# unknown options!
if ( scalar keys %$options ) {
warn "[BENCHMARKER] Unknown options present in arguments: " . keys %$options;
}
}
# do some sanity checks
if ( ! -d 'poedists' ) {
die "The 'poedists' directory is not found in the working directory!";
}
if ( ! -d 'results' ) {
die "The 'results' directory is not found in the working directory!";
}
if ( ! $quiet_mode ) {
print "[BENCHMARKER] Starting up...\n";
}
# Create our session
POE::Session->create(
__PACKAGE__->inline_states(),
'heap' => {
# misc stuff
'quiet_mode' => $quiet_mode,
# override our testing behavior
'lite_tests' => $lite_tests,
'forceloops' => $forceloops,
'forcepoe' => $forcepoe,
'forcenoxsqueue' => $forcenoxsqueue,
'forcenoasserts' => $forcenoasserts,
'freshstart' => $freshstart,
},
);
# Fire 'er up!
POE::Kernel->run();
return;
}
# Starts up our session
sub _start : State {
# okay, get all the dists we can!
my @versions;
if ( opendir( DISTS, 'poedists' ) ) {
foreach my $d ( readdir( DISTS ) ) {
if ( $d =~ /^POE\-(.+)$/ and $d !~ /\.tar\.gz$/ ) {
# FIXME skip POE < 0.13 because I can't get it to work
my $ver = version->new( $1 );
if ( $ver > version->new( '0.12' ) ) {
push( @versions, $ver );
}
}
}
closedir( DISTS ) or die $!;
} else {
print "[BENCHMARKER] Unable to open 'poedists' for reading: $!\n";
return;
}
# should we munge the versions list?
if ( defined $_[HEAP]->{'forcepoe'} ) {
# check for !poe versions
my @nopoe;
foreach my $p ( @{ $_[HEAP]->{'forcepoe'} } ) {
if ( $p =~ /^\!/ ) {
push( @nopoe, substr( $p, 1 ) );
}
}
if ( scalar @nopoe ) {
# remove the nopoe versions from the found
my %bad;
@bad{@nopoe} = () x @nopoe;
@versions = grep { !exists $bad{$_->stringify} } @versions;
} else {
# make sure the @versions contains only what we specified
my %good;
@good{ @{ $_[HEAP]->{'forcepoe'} } } = () x @{ $_[HEAP]->{'forcepoe'} };
@versions = grep { exists $good{$_->stringify} } @versions;
}
}
# sanity
if ( ! scalar @versions ) {
print "[BENCHMARKER] Unable to find any POE version in the 'poedists' directory!\n";
return;
}
# set our alias
$_[KERNEL]->alias_set( 'Benchmarker' );
# sanely handle some signals
$_[KERNEL]->sig( 'INT', 'handle_kill' );
$_[KERNEL]->sig( 'TERM', 'handle_kill' );
# okay, go through all the dists in version order ( from newest to oldest )
@versions = sort { $b <=> $a } @versions;
# Store the versions in our heap
$_[HEAP]->{'VERSIONS'} = \@versions;
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Detected available POE versions -> " . join( " ", @versions ) . "\n";
}
# First of all, we need to find out what loop libraries are installed
getPOEloops( $_[HEAP]->{'quiet_mode'}, $_[HEAP]->{'forceloops'} );
return;
}
sub _stop : State {
# tell the wheel to kill itself
if ( defined $_[HEAP]->{'WHEEL'} ) {
$_[HEAP]->{'WHEEL'}->kill( 9 );
undef $_[HEAP]->{'WHEEL'};
}
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "\n[BENCHMARKER] Shutting down...\n";
}
return;
}
# misc POE handlers
sub _child : State {
return;
}
sub handle_kill : State {
return;
}
# we received list of loops from GetInstalledLoops
sub found_loops : State {
$_[HEAP]->{'installed_loops'} = [ sort { $a cmp $b } @{ $_[ARG0] } ];
# sanity check
if ( scalar @{ $_[HEAP]->{'installed_loops'} } == 0 ) {
- print "[BENCHMARKER] Detected no available POE::Loop, check your configuration?!?\n";
+ print "[BENCHMARKER] Detected no available POE::Loop dists, check your configuration?!?\n";
return;
}
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Detected available POE::Loops -> " . join( " ", @{ $_[HEAP]->{'installed_loops'} } ) . "\n";
}
# Okay, do we have XS::Queue installed?
if ( ! $_[HEAP]->{'forcenoxsqueue'} ) {
eval { require POE::XS::Queue::Array };
if ( $@ ) {
$_[HEAP]->{'forcenoxsqueue'} = 1;
}
}
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Starting the benchmarks!" .
( $_[HEAP]->{'forcenoxsqueue'} ? ' Skipping XS::Queue Tests!' : '' ) .
( $_[HEAP]->{'forcenoasserts'} ? ' Skipping ASSERT Tests!' : '' ) .
"\n";
}
# start the benchmark!
$_[KERNEL]->yield( 'run_benchmark' );
return;
}
# Runs one benchmark
sub run_benchmark : State {
# Grab the version from the top of the array
$_[HEAP]->{'current_version'} = shift @{ $_[HEAP]->{'VERSIONS'} };
# did we run out of versions?
if ( ! defined $_[HEAP]->{'current_version'} ) {
# We're done, let POE die...
$_[KERNEL]->alias_remove( 'Benchmarker' );
} else {
$_[HEAP]->{'loops'} = [ @{ $_[HEAP]->{'installed_loops'} } ];
# okay, fire off the first loop
$_[KERNEL]->yield( 'bench_loop' );
}
return;
}
# runs one loop
sub bench_loop : State {
# select our current loop
$_[HEAP]->{'current_loop'} = shift @{ $_[HEAP]->{'loops'} };
# are we done with all loops?
if ( ! defined $_[HEAP]->{'current_loop'} ) {
# yay, go back to the main handler
$_[KERNEL]->yield( 'run_benchmark' );
} else {
# Start the assert test
if ( $_[HEAP]->{'forcenoasserts'} ) {
$_[HEAP]->{'assertions'} = [ qw( 0 ) ];
} else {
$_[HEAP]->{'assertions'} = [ qw( 0 1 ) ];
}
$_[KERNEL]->yield( 'bench_asserts' );
}
return;
}
# runs an assertion
sub bench_asserts : State {
# select our current assert state
$_[HEAP]->{'current_assertions'} = shift @{ $_[HEAP]->{'assertions'} };
# are we done?
if ( ! defined $_[HEAP]->{'current_assertions'} ) {
# yay, go back to the loop handler
$_[KERNEL]->yield( 'bench_loop' );
} else {
# Start the xsqueue test
if ( $_[HEAP]->{'forcenoxsqueue'} ) {
$_[HEAP]->{'noxsqueue'} = [ qw( 1 ) ];
} else {
$_[HEAP]->{'noxsqueue'} = [ qw( 0 1 ) ];
}
$_[KERNEL]->yield( 'bench_xsqueue' );
}
return;
}
# runs test with or without xsqueue
sub bench_xsqueue : State {
# select our current noxsqueue state
$_[HEAP]->{'current_noxsqueue'} = shift @{ $_[HEAP]->{'noxsqueue'} };
# are we done?
if ( ! defined $_[HEAP]->{'current_noxsqueue'} ) {
# yay, go back to the assert handler
$_[KERNEL]->yield( 'bench_asserts' );
} else {
# do some careful analysis
$_[KERNEL]->yield( 'bench_checkprevioustest' );
}
return;
}
# Checks to see if this test was run in the past
sub bench_checkprevioustest : State {
# okay, do we need to check and see if we already did this test?
if ( ! $_[HEAP]->{'freshstart'} ) {
# determine the file used
my $file = File::Spec->catfile( 'results', generateTestfile( $_[HEAP] ) . '.yml' );
# does it exist?
if ( -e $file and -f _ and -s _ ) {
# okay, sanity check it
my $yaml = YAML::Tiny->read( $file );
if ( defined $yaml ) {
# inrospect it!
my $isvalid = 0;
eval {
+ ## no critic ( ProhibitAccessOfPrivateData )
+
# simple sanity check: the "x_bench" param is at the end of the YML, so if it loads fine we know it's there
if ( exists $yaml->[0]->{'x_bench'} ) {
# version must at least match us
$isvalid = ( $yaml->[0]->{'x_bench'} eq currentTestVersion() ? 1 : 0 );
} else {
$isvalid = undef;
}
};
if ( $isvalid ) {
# yay, this test is A-OK!
$_[HEAP]->{'SKIPPED_TESTS'}++;
$_[KERNEL]->yield( 'bench_xsqueue' );
return;
} else {
# was it truncated?
if ( ! defined $isvalid ) {
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "\n[BENCHMARKER] YAML file($file) from previous test was corrupt!\n";
}
}
}
} else {
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "\n[BENCHMARKER] Unable to load YAML file($file) from previous test run: " . YAML::Tiny->errstr . "\n";
}
}
}
}
# could not find previous file or FRESHSTART, proceed normally
$_[KERNEL]->yield( 'create_subprocess' );
return;
}
# actually runs the subprocess
sub create_subprocess : State {
if ( exists $_[HEAP]->{'SKIPPED_TESTS'} ) {
print "\n Skipping $_[HEAP]->{'SKIPPED_TESTS'} old test runs...";
delete $_[HEAP]->{'SKIPPED_TESTS'};
}
# Okay, start testing this specific combo!
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "\n Testing " . generateTestfile( $_[HEAP] ) . "...";
}
+ # POE in 1.001 added POE_EVENT_LOOP env var, yay!
+ my $looploader;
+ if ( $_[HEAP]->{'current_version'} >= 1.001 ) {
+ $looploader = poeloop2dist( $_[HEAP]->{'current_loop'} );
+ } else {
+ # Add the eventloop?
+ $looploader = poeloop2load( $_[HEAP]->{'current_loop'} );
+ }
+
+ local $ENV{POE_EVENT_LOOP} = $looploader if defined $looploader and $looploader =~ /^POE::/;
+ undef $looploader if defined $looploader and $looploader =~ /^POE::/;
+
# save the starttime
$_[HEAP]->{'current_starttime'} = time();
$_[HEAP]->{'current_starttimes'} = [ times() ];
# Okay, create the wheel::run to handle this
- my $looploader = poeloop2load( $_[HEAP]->{'current_loop'} );
$_[HEAP]->{'WHEEL'} = POE::Wheel::Run->new(
'Program' => $^X,
'ProgramArgs' => [ '-Ipoedists/POE-' . $_[HEAP]->{'current_version'},
'-Ipoedists/POE-' . $_[HEAP]->{'current_version'} . '/lib',
( defined $looploader ? "-M$looploader" : () ),
'-MPOE::Devel::Benchmarker::SubProcess',
'-e',
'POE::Devel::Benchmarker::SubProcess::benchmark',
$_[HEAP]->{'current_loop'},
$_[HEAP]->{'current_assertions'},
$_[HEAP]->{'lite_tests'},
$_[HEAP]->{'current_noxsqueue'},
],
# Kill off existing FD's
'CloseOnCall' => 1,
# setup our data handlers
'StdoutEvent' => 'Got_STDOUT',
'StderrEvent' => 'Got_STDERR',
# the error handler
'ErrorEvent' => 'Got_ERROR',
'CloseEvent' => 'Got_CLOSED',
# set our filters
'StderrFilter' => POE::Filter::Line->new(),
'StdoutFilter' => POE::Filter::Line->new(),
);
if ( ! defined $_[HEAP]->{'WHEEL'} ) {
die 'Unable to create a new wheel!';
} else {
# smart CHLD handling
if ( $_[KERNEL]->can( "sig_child" ) ) {
$_[KERNEL]->sig_child( $_[HEAP]->{'WHEEL'}->PID => 'Got_CHLD' );
} else {
$_[KERNEL]->sig( 'CHLD', 'Got_CHLD' );
}
}
# setup our data we received from the subprocess
$_[HEAP]->{'current_data'} = '';
# Okay, we timeout this test after some time for sanity
$_[HEAP]->{'test_timedout'} = 0;
if ( $_[HEAP]->{'lite_tests'} ) {
# 5min timeout is 5x my average runs on a 1.2ghz core2duo so it should be good enough
$_[HEAP]->{'TIMER'} = $_[KERNEL]->delay_set( 'test_timedout' => 60 * 5 );
} else {
# 30min timeout is 2x my average runs on a 1.2ghz core2duo so it should be good enough
$_[HEAP]->{'TIMER'} = $_[KERNEL]->delay_set( 'test_timedout' => 60 * 30 );
}
return;
}
# Got a CHLD event!
sub Got_CHLD : State {
$_[KERNEL]->sig_handled();
return;
}
# Handles child STDERR output
sub Got_STDERR : State {
my $input = $_[ARG0];
# skip empty lines
if ( $input ne '' ) {
# save it!
$_[HEAP]->{'current_data'} .= '!STDERR: ' . $input . "\n";
}
return;
}
# Handles child STDOUT output
sub Got_STDOUT : State {
my $input = $_[ARG0];
# save it!
$_[HEAP]->{'current_data'} .= $input . "\n";
return;
}
# Handles child error
sub Got_ERROR : State {
# Copied from POE::Wheel::Run manpage
my ( $operation, $errnum, $errstr ) = @_[ ARG0 .. ARG2 ];
# ignore exit 0 errors
if ( $errnum != 0 ) {
print "\n[BENCHMARKER] Wheel::Run got an $operation error $errnum: $errstr\n";
}
return;
}
# Handles child DIE'ing
sub Got_CLOSED : State {
# Get rid of the wheel
undef $_[HEAP]->{'WHEEL'};
# get rid of the delay
$_[KERNEL]->alarm_remove( $_[HEAP]->{'TIMER'} );
undef $_[HEAP]->{'TIMER'};
# wrap up this test
$_[KERNEL]->yield( 'wrapup_test' );
return;
}
# a test timed out, unfortunately!
sub test_timedout : State {
# tell the wheel to kill itself
$_[HEAP]->{'WHEEL'}->kill( 9 );
undef $_[HEAP]->{'WHEEL'};
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print " Test Timed Out!";
}
$_[HEAP]->{'test_timedout'} = 1;
# wrap up this test
$_[KERNEL]->yield( 'wrapup_test' );
return;
}
# finalizes a test
sub wrapup_test : State {
# we're done with this benchmark!
$_[HEAP]->{'current_endtime'} = time();
$_[HEAP]->{'current_endtimes'} = [ times() ];
# store the data
my $file = generateTestfile( $_[HEAP] );
if ( open( my $fh, '>', File::Spec->catfile( 'results', $file ) ) ) {
print $fh "STARTTIME: " . $_[HEAP]->{'current_starttime'} . " -> TIMES " . join( " ", @{ $_[HEAP]->{'current_starttimes'} } ) . "\n";
print $fh "$file\n";
print $fh $_[HEAP]->{'current_data'} . "\n";
if ( $_[HEAP]->{'test_timedout'} ) {
print $fh "\nTEST TERMINATED DUE TO TIMEOUT\n";
}
print $fh "ENDTIME: " . $_[HEAP]->{'current_endtime'} . " -> TIMES " . join( " ", @{ $_[HEAP]->{'current_endtimes'} } ) . "\n";
close( $fh ) or die $!;
} else {
print "\n[BENCHMARKER] Unable to open '$file' for writing -> $!\n";
}
# Send the data to the Analyzer to process
$_[KERNEL]->yield( 'analyze_output', {
'poe' => {
'v' => $_[HEAP]->{'current_version'}->stringify, # YAML::Tiny doesn't like version objects :(
- 'loop' => 'POE::Loop::' . $_[HEAP]->{'current_loop'},
+ 'loop' => $_[HEAP]->{'current_loop'},
},
't' => {
's_ts' => $_[HEAP]->{'current_starttime'},
'e_ts' => $_[HEAP]->{'current_endtime'},
'd' => $_[HEAP]->{'current_endtime'} - $_[HEAP]->{'current_starttime'},
's_t' => [ @{ $_[HEAP]->{'current_starttimes'} } ],
'e_t' => [ @{ $_[HEAP]->{'current_endtimes'} } ],
},
'raw' => $_[HEAP]->{'current_data'},
'test' => $file,
'x_bench' => currentTestVersion(),
( $_[HEAP]->{'test_timedout'} ? ( 'timedout' => 1 ) : () ),
( $_[HEAP]->{'lite_tests'} ? ( 'litetests' => 1 ) : () ),
( $_[HEAP]->{'current_assertions'} ? ( 'asserts' => 1 ) : () ),
( $_[HEAP]->{'current_noxsqueue'} ? ( 'noxsqueue' => 1 ) : () ),
} );
# process the next test
$_[KERNEL]->yield( 'bench_xsqueue' );
return;
}
sub analyze_output : State {
# get the data
my $test = $_[ARG0];
+ ## no critic ( ProhibitAccessOfPrivateData )
+
# clean up the times() stuff
$test->{'t'}->{'t'} = beautify_times(
join( " ", @{ delete $test->{'t'}->{'s_t'} } ) .
" " .
join( " ", @{ delete $test->{'t'}->{'e_t'} } )
);
# Okay, break it down into our data struct
$test->{'metrics'} = {};
my $d = $test->{'metrics'};
my @unknown;
foreach my $l ( split( /(?:\n|\r)/, $test->{'raw'} ) ) {
# skip empty lines
if ( $l eq '' ) { next }
# usual test benchmark output
# 10 startups in 0.885 seconds ( 11.302 per second)
# 10000 posts in 0.497 seconds ( 20101.112 per second)
if ( $l =~ /^\s+\d+\s+(\w+)\s+in\s+([\d\.]+)\s+seconds\s+\(\s+([\d\.]+)\s+per\s+second\)$/ ) {
$d->{ $1 }->{'d'} = $2; # duration in seconds
$d->{ $1 }->{'i'} = $3; # iterations per second
# usual test benchmark times output
# startup times: 0.1 0 0 0 0.1 0 0.76 0.09
} elsif ( $l =~ /^(\w+)\s+times:\s+(.+)$/ ) {
$d->{ $1 }->{'t'} = beautify_times( $2 ); # the times hash
# usual test SKIP output
# SKIPPING br0ken $metric because ...
} elsif ( $l =~ /^SKIPPING\s+br0ken\s+(\w+)\s+because/ ) {
# don't build their data struct
# parse the memory footprint stuff
} elsif ( $l =~ /^pidinfo:\s+(.+)$/ ) {
# what should we analyze?
my $pidinfo = $1;
# VmPeak: 16172 kB
if ( $pidinfo =~ /^VmPeak:\s+(.+)$/ ) {
$test->{'pid'}->{'vmpeak'} = $1;
# voluntary_ctxt_switches: 10
} elsif ( $pidinfo =~ /^voluntary_ctxt_switches:\s+(.+)$/ ) {
$test->{'pid'}->{'vol_ctxt'} = $1;
# nonvoluntary_ctxt_switches: 1221
} elsif ( $pidinfo =~ /^nonvoluntary_ctxt_switches:\s+(.+)$/ ) {
$test->{'pid'}->{'nonvol_ctxt'} = $1;
} else {
# ignore the rest of the fluff
}
# parse the perl binary stuff
} elsif ( $l =~ /^perlconfig:\s+(.+)$/ ) {
# what should we analyze?
my $perlconfig = $1;
# ignore the fluff ( not needed now... )
# parse the CPU info
} elsif ( $l =~ /^cpuinfo:\s+(.+)$/ ) {
# what should we analyze?
my $cpuinfo = $1;
# if this is on a multiproc system, we will overwrite the data per processor ( harmless... )
# cpu MHz : 1201.000
if ( $cpuinfo =~ /^cpu\s+MHz\s+:\s+(.+)$/ ) {
$test->{'cpu'}->{'mhz'} = $1;
# model name : Intel(R) Core(TM)2 Duo CPU L7100 @ 1.20GHz
} elsif ( $cpuinfo =~ /^model\s+name\s+:\s+(.+)$/ ) {
$test->{'cpu'}->{'name'} = $1;
# bogomips : 2397.58
} elsif ( $cpuinfo =~ /^bogomips\s+:\s+(.+)$/ ) {
$test->{'cpu'}->{'bogo'} = $1;
} else {
# ignore the rest of the fluff
}
# ignore any Devel::Hide stuff
# $l eq '!STDERR: Devel::Hide hides POE/XS/Queue/Array.pm'
} elsif ( $l =~ /^\!STDERR:\s+Devel\:\:Hide\s+hides/ ) {
# ignore them
# data that we can safely throw away
} elsif ( $l eq 'Using NO Assertions!' or
$l eq 'Using FULL Assertions!' or
$l eq 'Using the LITE tests' or
$l eq 'Using the HEAVY tests' or
$l eq 'DISABLING POE::XS::Queue::Array' or
$l eq 'LETTING POE find POE::XS::Queue::Array' or
$l eq 'UNABLE TO GET /proc/self/status' or
$l eq 'UNABLE TO GET /proc/cpuinfo' or
$l eq '!STDERR: POE::Kernel\'s run() method was never called.' or # to ignore old POEs that threw this warning
$l eq 'TEST TERMINATED DUE TO TIMEOUT' ) {
# ignore them
# parse the perl binary stuff
} elsif ( $l =~ /^Running\s+under\s+perl\s+binary:\s+\'([^\']+)\'\s+v([\d\.]+)$/ ) {
$test->{'perl'}->{'binary'} = $1;
# setup the perl version
$test->{'perl'}->{'v'} = $2;
# the master loop version ( what the POE::Loop::XYZ actually uses )
# Using loop: EV-3.49
} elsif ( $l =~ /^Using\s+master\s+loop:\s+(.+)$/ ) {
$test->{'poe'}->{'loop_m'} = $1;
# the real POE version that was loaded
# Using POE-1.001
} elsif ( $l =~ /^Using\s+POE-(.+)$/ ) {
$test->{'poe'}->{'v_real'} = $1;
# the various queue/loop modules we loaded
# POE is using: POE::XS::Queue::Array v0.005
# POE is using: POE::Queue v1.2328
# POE is using: POE::Loop::EV v0.06
} elsif ( $l =~ /^POE\s+is\s+using:\s+([^\s]+)\s+v(.+)$/ ) {
$test->{'poe'}->{'modules'}->{ $1 } = $2;
# get the uname info
# Running under machine: Linux apoc-x300 2.6.24-21-generic #1 SMP Tue Oct 21 23:43:45 UTC 2008 i686 GNU/Linux
} elsif ( $l =~ /^Running\s+under\s+machine:\s+(.+)$/ ) {
$test->{'uname'} = $1;
# parse any STDERR output
# !STDERR: unable to foo
} elsif ( $l =~ /^\!STDERR:\s+(.+)$/ ) {
push( @{ $test->{'stderr'} }, $1 );
} else {
# unknown line :(
push( @unknown, $l );
}
}
# Get rid of the rawdata
delete $test->{'raw'};
# Dump the unknowns
if ( @unknown ) {
print "\n[ANALYZER] Unknown output from benchmark -> " . Dump( \@unknown );
}
# Dump the data struct we have to the file.yml
my $yaml_file = File::Spec->catfile( 'results', ( delete $test->{'test'} ) . '.yml' );
my $ret = open( my $fh, '>', $yaml_file );
if ( defined $ret ) {
print $fh Dump( $test );
if ( ! close( $fh ) ) {
print "\n[ANALYZER] Unable to close $yaml_file -> " . $! . "\n";
}
} else {
print "\n[ANALYZER] Unable to open $yaml_file for writing -> " . $! . "\n";
}
# now that we've dumped the stuff, we can do some sanity checks
# the POE we "think" we loaded should match reality!
if ( exists $test->{'poe'}->{'v_real'} ) { # if this exists, then we successfully loaded POE
if ( $test->{'poe'}->{'v'} ne $test->{'poe'}->{'v_real'} ) {
print "\n[ANALYZER] The subprocess loaded a different version of POE than we thought -> $yaml_file\n";
}
# The loop we loaded should match what we wanted!
if ( exists $test->{'poe'}->{'modules'} ) {
- if ( ! exists $test->{'poe'}->{'modules'}->{ $test->{'poe'}->{'loop'} } ) {
+ if ( ! exists $test->{'poe'}->{'modules'}->{ poeloop2dist( $test->{'poe'}->{'loop'} ) } ) {
# gaah special-case for IO_Poll ( POE 0.21 to POE 0.29 introduced POE::Loop::Poll which later became POE::Loop::IO_Poll )
- if ( $test->{'poe'}->{'loop'} eq 'POE::Loop::IO_Poll' and exists $test->{'poe'}->{'modules'}->{'POE::Loop::Poll'} ) {
+ if ( $test->{'poe'}->{'loop'} eq 'IO_Poll' and exists $test->{'poe'}->{'modules'}->{'POE::Loop::Poll'} ) {
# ah, ignore this
} else {
print "\n[ANALYZER] The subprocess loaded a different Loop than we thought -> $yaml_file\n";
}
}
}
}
# the perl binary should be the same!
if ( exists $test->{'perl'} ) { # if this exists, we successfully fired up the app ( no compile error )
if ( $test->{'perl'}->{'binary'} ne $^X ) {
print "\n[ANALYZER] The subprocess booted up on a different perl binary -> $yaml_file\n";
}
if ( $test->{'perl'}->{'v'} ne sprintf( "%vd", $^V ) ) {
print "\n[ANALYZER] The subprocess booted up on a different perl version -> $yaml_file\n";
}
}
+ # Did we successfully run the entire testsuite?
+ if ( ! exists $test->{'pid'} ) {
+ print "\n[ANALYZER] The testsuite failed to run to completion -> $yaml_file\n";
+ }
+
# all done!
return;
}
1;
__END__
=for stopwords AnnoCPAN CPAN Caputo EV Eventloop Gtk HTTP Kqueue MYFH poe Prima RT SQLite STDIN SocketFactory TODO Tapout Wx XS YAML autoprobing backend benchmarker csv db dngor er freshstart hardcode litetests noasserts noxsqueue poedists pong svn untarred yml
=head1 NAME
POE::Devel::Benchmarker - Benchmarking POE's performance ( acts more like a smoker )
=head1 SYNOPSIS
use POE::Devel::Benchmarker;
benchmark();
=head1 ABSTRACT
This package of tools is designed to benchmark POE's performance across different
configurations. The current "tests" are:
=over 4
=item Events
posts: This tests how long it takes to post() N times
dispatches: This tests how long it took to dispatch/deliver all the posts enqueued in the "posts" test
single_posts: This tests how long it took to yield() between 2 states for N times
calls: This tests how long it took to call() N times
=item Alarms
alarms: This tests how long it took to add N alarms via alarm(), overwriting each other
alarm_adds: This tests how long it took to add N alarms via alarm_add()
alarm_clears: This tests how long it took to clear all alarms set in the "alarm_adds" test
NOTE: alarm_add is not available on all versions of POE!
=item Sessions
session_creates: This tests how long it took to create N sessions
session_destroys: This tests how long it took to destroy all sessions created in the "session_creates" test
=item Filehandles
select_read_STDIN: This tests how long it took to toggle select_read N times on STDIN
select_write_STDIN: This tests how long it took to toggle select_write N times on STDIN
select_read_MYFH: This tests how long it took to toggle select_read N times on a real filehandle
select_write_MYFH: This tests how long it took to toggle select_write N times on a real filehandle
NOTE: The MYFH tests don't include the time it took to open()/close() the file :)
=item Sockets
socket_connects: This tests how long it took to connect+disconnect to a SocketFactory server via localhost
socket_stream: This tests how long it took to send N chunks of data in a "ping-pong" fashion between the server and client
=item POE startup time
startups: This tests how long it took to start + close N instances of POE+Loop without any sessions/etc via system()
=item POE Loops
This is actually a "super" test where all of the specific tests is ran against various POE::Loop::XYZ/FOO for comparison
NOTE: Not all versions of POE support all Loops!
=item POE Assertions
This is actually a "super" test where all of the specific tests is ran against POE with/without assertions enabled
NOTE: Not all versions of POE support assertions!
=item POE::XS::Queue::Array
This is actually a "super" test where all of the specific tests is ran against POE with XS goodness enabled/disabled
NOTE: Not all versions of POE support XS::Queue::Array!
=back
=head1 DESCRIPTION
This module is poorly documented now. Please give me some time to properly document it over time :)
=head2 INSTALLATION
Here's a simple outline to get you up to speed quickly. ( and smoking! )
=over 4
=item Install CPAN package + dependencies
Download+install the POE::Devel::Benchmarker package from CPAN
apoc@apoc-x300:~$ cpanp -i POE::Devel::Benchmarker
=item Setup initial directories
Go anywhere, and create the "parent" directory where you'll be storing test results + stuff. For this example,
I have chosen to use ~/poe-benchmarker:
apoc@apoc-x300:~$ mkdir poe-benchmarker
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ mkdir poedists results images
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker::GetPOEdists -e 'getPOEdists( 1 )'
( go get a coffee while it downloads if you're on a slow link, ha! )
=item Let 'er rip!
At this point you can start running the benchmark!
NOTE: the Benchmarker expects everything to be in the "local" directory!
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker -e 'benchmark()'
( go sleep or something, this will take a while! )
=back
=head2 BENCHMARKING
On startup the Benchmarker will look in the "poedists" directory and load all the distributions it sees untarred there. Once
that is done it will begin autoprobing for available POE::Loop packages. Once it determines what's available, it will begin
the benchmarks.
As the Benchmarker goes through the combinations of POE + Eventloop + Assertions + XS::Queue it will dump data into
the results directory. The module also dumps YAML output in the same place, with the suffix of ".yml"
This module exposes only one subroutine, the benchmark() one. You can pass a hashref to it to set various options. Here is
a list of the valid options:
=over 4
=item freshstart => boolean
This will tell the Benchmarker to ignore any previous test runs stored in the 'results' directory. This will not delete
data from previous runs, only overwrite them. So be careful if you're mixing test runs from different versions!
benchmark( { freshstart => 1 } );
default: false
=item noxsqueue => boolean
This will tell the Benchmarker to force the unavailability of POE::XS::Queue::Array and skip those tests.
NOTE: The Benchmarker will set this automatically if it cannot load the module!
benchmark( { noxsqueue => 1 } );
default: false
=item noasserts => boolean
This will tell the Benchmarker to not run the ASSERT tests.
benchmark( { noasserts => 1 } );
default: false
=item litetests => boolean
This enables the "lite" tests which will not take up too much time.
benchmark( { litetests => 0 } );
default: true
=item quiet => boolean
This enables quiet mode which will not print anything to the console except for errors.
benchmark( { 'quiet' => 1 } );
default: false
=item loop => csv list or array
This overrides the built-in loop detection algorithm which searches for all known loops.
There is some "magic" here where you can put a negative sign in front of a loop and we will NOT run that.
NOTE: Capitalization is important!
benchmark( { 'loop' => 'IO_Poll,Select' } ); # runs only IO::Poll and Select
benchmark( { 'loop' => [ qw( Tk Gtk ) ] } ); # runs only Tk and Gtk
benchmark( { 'loop' => '-Tk' } ); # runs all available loops EXCEPT for TK
Known loops: Event_Lib EV Glib Prima Gtk Kqueue Tk Select IO_Poll
=item poe => csv list or array
This overrides the built-in POE version detection algorithm which pulls the POE versions from the 'poedists' directory.
There is some "magic" here where you can put a negative sign in front of a version and we will NOT run that.
NOTE: The Benchmarker will ignore versions that wasn't found in the directory!
benchmark( { 'poe' => '0.35,1.003' } ); # runs on 0.35 and 1.003
benchmark( { 'poe' => [ qw( 0.3009 0.12 ) ] } ); # runs on 0.3009 and 0.12
benchmark( { 'poe' => '-0.35' } ); # runs ALL tests except 0.35
=back
=head2 ANALYZING RESULTS
Please look at the pretty charts generated by the L<POE::Devel::Benchmarker::Imager> module.
=head1 EXPORT
Automatically exports the benchmark() subroutine.
=head1 TODO
=over 4
=item Perl version smoking
We should be able to run the benchmark over different Perl versions. This would require some fiddling with our
layout + logic. It's not that urgent because the workaround is to simply execute the benchmarker under a different
perl binary. It's smart enough to use $^X to be consistent across tests/subprocesses :)
=item Select the EV backend
<Khisanth> and if you are benchmarking, try it with POE using EV with EV using Glib? :P
<Apocalypse> I'm not sure how to configure the EV "backend" yet
<Apocalypse> too much docs for me to read hah
<Khisanth> Apocalypse: use EV::Glib; use Glib; use POE; :)
=item Be smarter in smoking timeouts
Currently we depend on the litetests option and hardcode some values including the timeout. If your machine is incredibly
slow, there's a chance that it could timeout unnecessarily. Please look at the outputs and check to see if there are unusual
failures, and inform me.
Also, some loops perform badly and take almost forever! /me glares at Gtk...
=item More benchmarks!
As usual, me and the crowd in #poe have plenty of ideas for tests. We'll be adding them over time, but if you have an idea please
drop me a line and let me know!
dngor said there was some benchmarks in the POE svn under trunk/queue...
<dngor> Apocalypse: Check out the old benchmarks in the queue directory in POE's repot.
They profile queue performance at various sizes, which is a better indication of scalability.
Tapout contributed a script that tests HTTP performance, let's see if it deserves to be in the suite :)
I added the preliminary socket tests, we definitely should expand it seeing how many people use POE for networking...
=item Add SQLite/DBI/etc support to the Analyzer
It would be nice if we could have a local SQLite db to dump our stats into. This would make arbitrary reports much easier than
loading raw YAML files and trying to make sense of them, ha! Also, this means somebody can do the smoking and send the SQLite
db to another person to generate the graphs, cool!
-=item Kqueue loop support
-
-As I don't have access to a *BSD box, I cannot really test this. Furthermore, it isn't clear on how I can force/unload this
-module from POE...
-
=item Wx loop support
-I have Wx installed, but it doesn't work. Obviously I don't know how to use Wx ;)
-
-If you have experience, please drop me a line on how to do the "right" thing to get Wx loaded under POE. Here's the error:
+I have Wx installed, but it doesn't work. I suspect the module is broken... Here's the error:
Can't call method "MainLoop" on an undefined value at /usr/local/share/perl/5.8.8/POE/Loop/Wx.pm line 91.
-=item XS::Loop support
+=item Multiple run support
+
+I would like the benchmarker to run the testsuite N times, and summing up the data into an average so we have more sane data...
-The POE::XS::Loop::* modules theoretically could be tested too. However, they will only work in POE >= 1.003! This renders
-the concept somewhat moot. Maybe, after POE has progressed some versions we can implement this...
+<dngor> Apocalypse: You could start with 5 runs, then continue running until the standard deviation reaches some sane level?
=back
=head1 SEE ALSO
L<POE>
=head1 SUPPORT
You can find documentation for this module with the perldoc command.
perldoc POE::Devel::Benchmarker
=head2 Websites
=over 4
+=item * Search CPAN
+
+L<http://search.cpan.org/dist/POE-Devel-Benchmarker>
+
=item * AnnoCPAN: Annotated CPAN documentation
L<http://annocpan.org/dist/POE-Devel-Benchmarker>
=item * CPAN Ratings
L<http://cpanratings.perl.org/d/POE-Devel-Benchmarker>
+=item * CPAN Forum
+
+L<http://cpanforum.com/dist/POE-Devel-Benchmarker>
+
=item * RT: CPAN's request tracker
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=POE-Devel-Benchmarker>
-=item * Search CPAN
+=item * CPANTS Kwalitee
-L<http://search.cpan.org/dist/POE-Devel-Benchmarker>
+L<http://cpants.perl.org/dist/overview/POE-Devel-Benchmarker>
-=item * CPAN Testing Service
+=item * CPAN Testers Results
-L<http://cpants.perl.org/dist/overview/POE-Devel-Benchmarker>
+L<http://cpantesters.org/distro/P/POE-Devel-Benchmarker.html>
+
+=item * CPAN Testers Matrix
+
+L<http://matrix.cpantesters.org/?dist=POE-Devel-Benchmarker>
+
+=item * Git Source Code Repository
+
+This code is currently hosted on github.com under the account "apocalypse". Please feel free to browse it
+and pull from it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull
+from your repository :)
+
+L<http://github.com/apocalypse/perl-poe-benchmarker>
=back
=head2 Bugs
Please report any bugs or feature requests to C<bug-poe-devel-benchmarker at rt.cpan.org>, or through
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=POE-Devel-Benchmarker>. I will be
notified, and then you'll automatically be notified of progress on your bug as I make changes.
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
BIG THANKS goes to Rocco Caputo E<lt>rcaputo@cpan.orgE<gt> for the first benchmarks!
=head1 COPYRIGHT AND LICENSE
Copyright 2010 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
+The full text of the license can be found in the LICENSE file included with this module.
+
=cut
diff --git a/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm b/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm
index ab2c154..686ce02 100644
--- a/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm
+++ b/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm
@@ -1,207 +1,220 @@
# Declare our package
package POE::Devel::Benchmarker::GetInstalledLoops;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.06';
# auto-export the only sub we have
use base qw( Exporter );
our @EXPORT = qw( getPOEloops );
# Import what we need from the POE namespace
use POE qw( Session Filter::Line Wheel::Run );
use base 'POE::Session::AttributeBased';
# Get the utils
-use POE::Devel::Benchmarker::Utils qw ( knownloops );
+use POE::Devel::Benchmarker::Utils qw ( knownloops poeloop2dist );
# analyzes the installed perl directory for available loops
sub getPOEloops {
my $quiet_mode = shift;
my $forceloops = shift;
# load our known list of loops
- # known impossible loops:
- # XS::EPoll ( must be POE > 1.003 and weird way of loading )
- # XS::Poll ( must be POE > 1.003 and weird way of loading )
if ( ! defined $forceloops ) {
$forceloops = knownloops();
}
# create our session!
POE::Session->create(
__PACKAGE__->inline_states(),
'heap' => {
'quiet_mode' => $quiet_mode,
'loops' => $forceloops,
},
);
}
# Starts up our session
sub _start : State {
# set our alias
$_[KERNEL]->alias_set( 'Benchmarker::GetInstalledLoops' );
# First of all, we need to find out what loop libraries are installed
$_[HEAP]->{'found_loops'} = [];
$_[KERNEL]->yield( 'find_loops' );
return;
}
sub _stop : State {
# tell the wheel to kill itself
if ( defined $_[HEAP]->{'WHEEL'} ) {
$_[HEAP]->{'WHEEL'}->kill( 9 );
undef $_[HEAP]->{'WHEEL'};
}
return;
}
# loops over the "known" loops and sees if they are installed
sub find_loops : State {
# get the loop to test
$_[HEAP]->{'current_loop'} = shift @{ $_[HEAP]->{'loops'} };
# do we have something to test?
if ( ! defined $_[HEAP]->{'current_loop'} ) {
# we're done!
$_[KERNEL]->alias_remove( 'Benchmarker::GetInstalledLoops' );
$_[KERNEL]->post( 'Benchmarker', 'found_loops', $_[HEAP]->{'found_loops'} );
return;
} else {
if ( ! $_[HEAP]->{'quiet_mode'} ) {
- print "[LOOPSEARCH] Trying to find if POE::Loop::" . $_[HEAP]->{'current_loop'} . " is installed...\n";
+ print "[LOOPSEARCH] Trying to find if " . poeloop2dist( $_[HEAP]->{'current_loop'} ) . " is installed...\n";
}
# set the flag
$_[HEAP]->{'test_failure'} = 0;
}
# Okay, create the wheel::run to handle this
+ local $ENV{POE_EVENT_LOOP} = poeloop2dist( $_[HEAP]->{'current_loop'} );
+
+ # ARGH, I tried to do: $^X -MPOE -e POE::Kernel->run but the shell blew up!
$_[HEAP]->{'WHEEL'} = POE::Wheel::Run->new(
- 'Program' => $^X,
- 'ProgramArgs' => [ '-MPOE',
- '-MPOE::Loop::' . $_[HEAP]->{'current_loop'},
- '-e',
- '1',
- ],
+ 'Program' => $^X,
+ 'ProgramArgs' => [
+ '-MPOE::Devel::Benchmarker::GetInstalledLoops::SubProcess',
+ '-e',
+ '1',
+ ],
# Kill off existing FD's
'CloseOnCall' => 1,
# setup our data handlers
'StdoutEvent' => 'Got_STDOUT',
'StderrEvent' => 'Got_STDERR',
# the error handler
'ErrorEvent' => 'Got_ERROR',
'CloseEvent' => 'Got_CLOSED',
# set our filters
'StderrFilter' => POE::Filter::Line->new(),
'StdoutFilter' => POE::Filter::Line->new(),
);
if ( ! defined $_[HEAP]->{'WHEEL'} ) {
die '[LOOPSEARCH] Unable to create a new wheel!';
} else {
# smart CHLD handling
if ( $_[KERNEL]->can( "sig_child" ) ) {
$_[KERNEL]->sig_child( $_[HEAP]->{'WHEEL'}->PID => 'Got_CHLD' );
} else {
$_[KERNEL]->sig( 'CHLD', 'Got_CHLD' );
}
+
+ # We need to time it out because EV will hang...
+ $_[KERNEL]->delay( 'timeout' => 5 );
}
return;
}
+sub timeout : State {
+# print "Probing timed out\n";
+
+ $_[HEAP]->{'WHEEL'}->kill;
+ return;
+}
+
# Got a CHLD event!
sub Got_CHLD : State {
$_[KERNEL]->sig_handled();
return;
}
# Handles child STDERR output
sub Got_STDERR : State {
my $input = $_[ARG0];
+# print "STDERR: $input\n";
# since we got an error, must be a failure
$_[HEAP]->{'test_failure'} = 1;
return;
}
# Handles child STDOUT output
sub Got_STDOUT : State {
my $input = $_[ARG0];
+# print "STDOUT: $input\n";
return;
}
# Handles child error
sub Got_ERROR : State {
# Copied from POE::Wheel::Run manpage
my ( $operation, $errnum, $errstr ) = @_[ ARG0 .. ARG2 ];
# ignore exit 0 errors
if ( $errnum != 0 ) {
warn "Wheel::Run got an $operation error $errnum: $errstr\n";
}
return;
}
# Handles child DIE'ing
sub Got_CLOSED : State {
# Get rid of the wheel
undef $_[HEAP]->{'WHEEL'};
+ $_[KERNEL]->delay( 'timeout' ); # disable delay
# Did we pass this test or not?
if ( ! $_[HEAP]->{'test_failure'} ) {
push( @{ $_[HEAP]->{'found_loops'} }, $_[HEAP]->{'current_loop'} );
}
# move on to the next loop
$_[KERNEL]->yield( 'find_loops' );
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::GetInstalledLoops - Automatically detects the installed POE loops
=head1 SYNOPSIS
die "Don't use this module directly. Please use POE::Devel::Benchmarker instead.";
=head1 ABSTRACT
This package implements the guts of searching for POE loops via fork/exec.
=head1 EXPORT
Automatically exports the getPOEloops() sub
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2010 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/GetInstalledLoops/SubProcess.pm b/lib/POE/Devel/Benchmarker/GetInstalledLoops/SubProcess.pm
new file mode 100644
index 0000000..a7ab4d4
--- /dev/null
+++ b/lib/POE/Devel/Benchmarker/GetInstalledLoops/SubProcess.pm
@@ -0,0 +1,42 @@
+# Declare our package
+package POE::Devel::Benchmarker::GetInstalledLoops::SubProcess;
+use strict; use warnings;
+
+# Initialize our version
+use vars qw( $VERSION );
+$VERSION = '0.06';
+
+# Do some dummy things
+use POE;
+POE::Kernel->run;
+
+1;
+__END__
+=head1 NAME
+
+POE::Devel::Benchmarker::GetInstalledLoops::SubProcess - Automatically detects the installed POE loops
+
+=head1 SYNOPSIS
+
+ die "Don't use this module directly. Please use POE::Devel::Benchmarker instead.";
+
+=head1 ABSTRACT
+
+This package implements the guts of searching for POE loops via fork/exec.
+
+=head1 SEE ALSO
+
+L<POE::Devel::Benchmarker>
+
+=head1 AUTHOR
+
+Apocalypse E<lt>apocal@cpan.orgE<gt>
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright 2010 by Apocalypse
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
diff --git a/lib/POE/Devel/Benchmarker/GetPOEdists.pm b/lib/POE/Devel/Benchmarker/GetPOEdists.pm
index b3fdff4..e5e50ef 100644
--- a/lib/POE/Devel/Benchmarker/GetPOEdists.pm
+++ b/lib/POE/Devel/Benchmarker/GetPOEdists.pm
@@ -1,150 +1,152 @@
# Declare our package
package POE::Devel::Benchmarker::GetPOEdists;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.06';
# auto-export the only sub we have
use base qw( Exporter );
our @EXPORT = qw( getPOEdists );
# import the helper modules
use LWP::UserAgent;
use HTML::LinkExtor;
use URI::URL;
use Archive::Tar;
# autoflush, please!
use IO::Handle;
STDOUT->autoflush( 1 );
# actually retrieves the dists!
sub getPOEdists {
# should we debug?
my $debug = shift;
# okay, should we change directory?
if ( -d 'poedists' ) {
if ( $debug ) {
print "[GETPOEDISTS] chdir( 'poedists' )\n";
}
if ( ! chdir( 'poedists' ) ) {
die "Unable to chdir to 'poedists' dir: $!";
}
} else {
if ( $debug ) {
print "[GETPOEDISTS] downloading to current directory\n";
}
}
# set the default URL
my $url = "http://backpan.cpan.org/authors/id/R/RC/RCAPUTO/";
# create our objects
my $ua = LWP::UserAgent->new;
my $p = HTML::LinkExtor->new;
my $tar = Archive::Tar->new;
# Request document and parse it as it arrives
print "Getting $url via LWP\n" if $debug;
my $res = $ua->request( HTTP::Request->new( GET => $url ),
sub { $p->parse( $_[0] ) },
);
# did we successfully download?
if ( $res->is_error ) {
die "unable to download directory index on BACKPAN: " . $res->status_line;
}
# Download every one!
foreach my $link ( $p->links ) {
+ ## no critic ( ProhibitAccessOfPrivateData )
+
# skip IMG stuff
if ( $link->[0] eq 'a' and $link->[1] eq 'href' ) {
# get the actual POE dists!
if ( $link->[2] =~ /^POE\-\d.+\.tar\.gz$/ ) {
# download the tarball!
print "Mirroring $link->[2] via LWP\n" if $debug;
my $mirror_result = $ua->mirror( $url . $link->[2], $link->[2] );
if ( $mirror_result->is_error ) {
warn "unable to mirror $link->[2]: " . $mirror_result->status_line;
next;
}
# did we already untar this one?
my $dir = $link->[2];
$dir =~ s/\.tar\.gz$//;
if ( ! -d $dir ) {
# extract it!
print "Extracting $link->[2] via Tar\n" if $debug;
my $files = $tar->read( $link->[2], undef, { 'extract' => 'true' } );
if ( $files == 0 ) {
warn "unable to extract $link->[2]";
}
}
}
}
}
return;
}
1;
__END__
=for stopwords BACKPAN LWP getPOEdists
=head1 NAME
POE::Devel::Benchmarker::GetPOEdists - Automatically download all POE tarballs
=head1 SYNOPSIS
use POE::Devel::Benchmarker::GetPOEdists;
getPOEdists();
=head1 ABSTRACT
This package automatically downloads all the POE tarballs from BACKPAN.
=head1 DESCRIPTION
This uses LWP + HTML::LinkExtor to retrieve POE tarballs from BACKPAN.
The tarballs are automatically downloaded to the current directory. Then, we use Archive::Tar to extract them all!
NOTE: we use LWP's useful mirror() sub which doesn't re-download files if they already exist!
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker::GetPOEdists -e 'getPOEdists()'
=head2 getPOEdists
Normally you should pass nothing to this sub. However, if you want to debug the downloads+extractions you should pass
a true value as the first argument.
perl -MPOE::Devel::Benchmarker::GetPOEdists -e 'getPOEdists( 1 )'
=head1 EXPORT
Automatically exports the getPOEdists() sub
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2010 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/Imager.pm b/lib/POE/Devel/Benchmarker/Imager.pm
index 367ecd2..f7a74b8 100644
--- a/lib/POE/Devel/Benchmarker/Imager.pm
+++ b/lib/POE/Devel/Benchmarker/Imager.pm
@@ -1,458 +1,513 @@
# Declare our package
package POE::Devel::Benchmarker::Imager;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.06';
# auto-export the only sub we have
use base qw( Exporter );
our @EXPORT = qw( imager );
# import the helper modules
use YAML::Tiny;
use File::Spec;
+# to silence Perl::Critic - # Three-argument form of open used at line 541, column 3. Three-argument open is not available until perl 5.6. (Severity: 5)
+use 5.008;
+
# load our plugins!
use Module::Pluggable search_path => [ __PACKAGE__ ];
# load comparison stuff
use version;
# Get some stuff from Utils
use POE::Devel::Benchmarker::Utils qw( currentTestVersion );
# generate some accessors
use base qw( Class::Accessor::Fast );
__PACKAGE__->mk_ro_accessors( qw( poe_versions poe_versions_sorted poe_loops data
- noxsqueue noasserts litetests quiet
+ noxsqueue noasserts litetests quiet type
) );
# autoflush, please!
use IO::Handle;
STDOUT->autoflush( 1 );
# starts the work of converting our data to images
sub imager {
my $options = shift;
# instantitate ourself
my $self = __PACKAGE__->new( $options );
# parse all of our YAML modules!
$self->loadtests;
# process some stats
$self->process_data;
# generate the images!
$self->generate_images;
return;
}
# creates a new instance
sub new {
my $class = shift;
my $opts = shift;
# instantitate ourself
my $self = {};
bless $self, $class;
# init the options
$self->init_options( $opts );
if ( ! $self->{'options'}->{'quiet'} ) {
print "[IMAGER] Starting up...\n";
}
return $self;
}
sub init_options {
my $self = shift;
my $options = shift;
# set defaults
$self->{'quiet'} = 0;
$self->{'litetests'} = 1;
$self->{'noasserts'} = undef;
$self->{'noxsqueue'} = undef;
# process our options
if ( defined $options and ref $options and ref( $options ) eq 'HASH' ) {
+ ## no critic ( ProhibitAccessOfPrivateData )
+
# process quiet mode
if ( exists $options->{'quiet'} ) {
if ( $options->{'quiet'} ) {
$self->{'quiet'} = 1;
} else {
$self->{'quiet'} = 0;
}
}
# process the LITE/HEAVY
if ( exists $options->{'litetests'} ) {
if ( $options->{'litetests'} ) {
$self->{'litetests'} = 1;
} else {
$self->{'litetests'} = 0;
}
}
# process the noasserts to load
if ( exists $options->{'noasserts'} ) {
if ( $options->{'noasserts'} ) {
$self->{'noasserts'} = 1;
} else {
$self->{'noasserts'} = 0;
}
}
# process the noxsqueue to load
if ( exists $options->{'noxsqueue'} ) {
if ( $options->{'noxsqueue'} ) {
$self->{'noxsqueue'} = 1;
} else {
$self->{'noxsqueue'} = 0;
}
}
- # FIXME process the plugins to load -> "types"
+ # process the plugins to load -> "type"
+ if ( exists $options->{'type'} ) {
+ my $forcetypes;
+ if ( ! ref $options->{'type'} ) {
+ # split it via CSV
+ $forcetypes = [ split( /,/, $options->{'type'} ) ];
+ foreach ( @$forcetypes ) {
+ $_ =~ s/^\s+//; $_ =~ s/\s+$//;
+ }
+ } else {
+ # treat it as array
+ $forcetypes = $options->{'type'};
+ }
+
+ # check for !type modules
+ my @notype;
+ foreach my $l ( @$forcetypes ) {
+ if ( $l =~ /^\!/ ) {
+ push( @notype, __PACKAGE__ . '::' . substr( $l, 1 ) );
+ }
+ }
+ if ( scalar @notype ) {
+ # replace the forcetype with ALL known, then subtract notype from it
+ my %bad;
+ @bad{@notype} = () x @notype;
+ @$forcetypes = grep { !exists $bad{$_} } $self->plugins;
+ } else {
+ # Add our package to the type
+ @$forcetypes = map { __PACKAGE__ . '::' . $_ } @$forcetypes;
+ }
+
+ $self->{'type'} = $forcetypes;
+ }
# FIXME process the versions to load
# FIXME process the loops to load
}
# some sanity tests
if ( ! -d 'results' ) {
die "The 'results' directory is not found in the working directory!";
}
if ( ! -d 'images' ) {
die "The 'images' directory is not found in the working directory!";
}
return;
}
# starts the process of loading all of our YAML images
sub loadtests {
my $self = shift;
# gather all the YAML dumps
if ( opendir( DUMPS, 'results' ) ) {
foreach my $d ( readdir( DUMPS ) ) {
# parse the file structure
# POE-1.0002-IO_Poll-LITE-assert-noxsqueue.yml
if ( $d =~ /^POE\-([\d\.\_]+)\-(\w+?)\-(LITE|HEAVY)\-(noassert|assert)\-(noxsqueue|xsqueue)\.yml$/ ) {
my( $ver, $loop, $lite, $assert, $xsqueue ) = ( $1, $2, $3, $4, $5 );
# skip this file?
if ( $self->noxsqueue ) {
if ( $xsqueue eq 'xsqueue' ) { next }
} else {
if ( defined $self->noxsqueue ) {
if ( $xsqueue eq 'noxsqueue' ) { next }
}
}
if ( $self->noasserts ) {
if ( $assert eq 'assert' ) { next }
} else {
if ( defined $self->noasserts ) {
if ( $assert eq 'noassert' ) { next }
}
}
if ( $self->litetests ) {
if ( $lite eq 'HEAVY' ) { next }
} else {
if ( $lite eq 'LITE' ) { next }
}
# FIXME allow selective loading of tests, so we can control what to image, etc
# actually load this file!
$self->load_yaml( $d, $ver, $loop, $lite, $assert, $xsqueue );
}
}
closedir( DUMPS ) or die "[IMAGER] Unable to read from 'results' -> " . $!;
} else {
die "[IMAGER] Unable to open 'results' for reading -> " . $!;
}
# sanity
if ( ! exists $self->{'data'} ) {
die "[IMAGER] Unable to find valid POE test result(s) in the 'results' directory!\n";
}
if ( ! $self->quiet ) {
print "[IMAGER] Done with parsing the YAML files...\n";
}
return;
}
# loads the yaml of a specific file
sub load_yaml {
my ( $self, $file, $ver, $loop, $lite, $assert, $xsqueue ) = @_;
+ ## no critic ( ProhibitAccessOfPrivateData )
+
my $yaml = YAML::Tiny->read( File::Spec->catfile( 'results', $file ) );
if ( ! defined $yaml ) {
print "[IMAGER] Unable to load YAML file $file -> " . YAML::Tiny->errstr . "\n";
return;
} else {
# inrospect it!
my $isvalid = 0;
eval {
# simple sanity check: the "x_bench" param is at the end of the YML, so if it loads fine we know it's there
if ( defined $yaml->[0] and exists $yaml->[0]->{'x_bench'} ) {
# version must at least match us
$isvalid = ( $yaml->[0]->{'x_bench'} eq currentTestVersion() ? 1 : 0 );
} else {
$isvalid = undef;
}
};
if ( ! $isvalid or $@ ) {
print "[IMAGER] Detected outdated/corrupt benchmark result: $file";
return;
} else {
# reduce indirection
$yaml = $yaml->[0];
}
}
# store the POE version
$self->{'poe_versions'}->{ $ver } = 1;
# sanity check the loop master version ( which should always be our "installed" version, not per-POE )
if ( exists $yaml->{'poe'}->{'loop_m'} ) {
if ( ! defined $self->{'poe_loops'}->{ $loop } ) {
$self->{'poe_loops'}->{ $loop } = $yaml->{'poe'}->{'loop_m'};
} else {
if ( $self->{'poe_loops'}->{ $loop } ne $yaml->{'poe'}->{'loop_m'} ) {
die "[IMAGER] Detected POE::Loop master version inconsistency! $file reported '" . $yaml->{'poe'}->{'loop_m'} .
"' while others had '" . $self->{'poe_loops'}->{ $loop } . "'";
}
}
}
# get the info we're interested in
$self->{'data'}->{ $assert }->{ $xsqueue }->{ $ver }->{ $loop }->{'metrics'} = $yaml->{'metrics'};
$self->{'data'}->{ $assert }->{ $xsqueue }->{ $ver }->{ $loop }->{'time'} = $yaml->{'t'};
if ( exists $yaml->{'pid'} ) {
$self->{'data'}->{ $assert }->{ $xsqueue }->{ $ver }->{ $loop }->{'pid'} = $yaml->{'pid'};
}
if ( exists $yaml->{'poe'}->{'modules'} ) {
$self->{'data'}->{ $assert }->{ $xsqueue }->{ $ver }->{ $loop }->{'poe_modules'} = $yaml->{'poe'}->{'modules'};
}
# sanity check the perl stuff
if ( exists $yaml->{'perl'}->{'binary'} ) {
if ( ! exists $self->{'data'}->{'perlconfig'} ) {
$self->{'data'}->{'perlconfig'}->{'binary'} = $yaml->{'perl'}->{'binary'};
$self->{'data'}->{'perlconfig'}->{'version'} = $yaml->{'perl'}->{'v'};
} else {
if ( $self->{'data'}->{'perlconfig'}->{'binary'} ne $yaml->{'perl'}->{'binary'} ) {
die "[IMAGER] Detected perl binary inconsistency! $file reported '" . $yaml->{'perl'}->{'binary'} .
"' while others had '" . $self->{'data'}->{'perlconfig'}->{'binary'} . "'";
}
if ( $self->{'data'}->{'perlconfig'}->{'version'} ne $yaml->{'perl'}->{'v'} ) {
die "[IMAGER] Detected perl version inconsistency! $file reported '" . $yaml->{'perl'}->{'v'} .
"' while others had '" . $self->{'data'}->{'perlconfig'}->{'version'} . "'";
}
}
}
# sanity check the uname
if ( exists $yaml->{'uname'} ) {
if ( ! exists $self->{'data'}->{'uname'} ) {
$self->{'data'}->{'uname'} = $yaml->{'uname'};
} else {
if ( $self->{'data'}->{'uname'} ne $yaml->{'uname'} ) {
die "[IMAGER] Detected system inconsistency! $file reported '" . $yaml->{'uname'} .
"' while others had '" . $self->{'data'}->{'uname'} . "'";
}
}
}
# sanity check the cpu name
if ( exists $yaml->{'cpu'} ) {
if ( ! exists $self->{'data'}->{'cpu'} ) {
$self->{'data'}->{'cpu'} = $yaml->{'cpu'};
} else {
if ( $self->{'data'}->{'cpu'}->{'name'} ne $yaml->{'cpu'}->{'name'} ) {
die "[IMAGER] Detected system/cpu inconsistency! $file reported '" . $yaml->{'cpu'}->{'name'} .
"' while others had '" . $self->{'data'}->{'cpu'}->{'name'} . "'";
}
}
}
return;
}
sub process_data {
my $self = shift;
# sanitize the versions in an ordered loop
$self->{'poe_versions_sorted'} = [ map { $_->stringify }
- sort { $a <=> $b }
+ sort { $b <=> $a }
map { version->new($_) } keys %{ $self->poe_versions }
];
if ( ! $self->quiet ) {
print "[IMAGER] Done with processing the benchmark statistics...\n";
}
return;
}
sub generate_images {
my $self = shift;
# load our plugins and let them have fun :)
foreach my $plugin ( $self->plugins ) {
+ # Do we want this plugin?
+ if ( exists $self->{'type'} and ! grep { $_ eq $plugin } @{ $self->{'type'} } ) {
+ if ( ! $self->quiet ) {
+ print "[IMAGER] Skipping plugin $plugin\n";
+ }
+
+ next;
+ }
+
# actually load it!
- ## no critic
- eval "require $plugin";
- ## use critic
+ eval "require $plugin"; ## no critic ( ProhibitStringyEval )
if ( $@ ) {
if ( ! $self->quiet ) {
print "[IMAGER] Unable to load plugin $plugin -> $@\n";
next;
}
}
# sanity checks
if ( $plugin->can( 'new' ) and $plugin->can( 'imager' ) ) {
- # FIXME did we want this plugin?
-
# create the plugin's home dir
my $homedir = $plugin;
if ( $homedir =~ /\:\:(\w+)$/ ) {
$homedir = $1;
} else {
- die "barf";
+ die "Unable to figure out plugin's homedir - $plugin";
}
$homedir = File::Spec->catdir( 'images', $homedir );
if ( ! -d $homedir ) {
# create it!
if ( ! mkdir( $homedir ) ) {
die "[IMAGER] Unable to create plugin directory: $homedir";
}
}
# Okay, get this plugin!
my $obj = $plugin->new( { 'dir' => $homedir } );
if ( ! $self->quiet ) {
print "[IMAGER] Processing the $plugin plugin...\n";
}
$obj->imager( $self );
}
}
if ( ! $self->quiet ) {
print "[IMAGER] Done with generating images...\n";
}
return;
}
1;
__END__
=for stopwords YAML litetests namespace noassert noxsqueue plugin xsqueue
=head1 NAME
POE::Devel::Benchmarker::Imager - Automatically converts the benchmark data into images
=head1 SYNOPSIS
use POE::Devel::Benchmarker::Imager;
imager();
=head1 ABSTRACT
This package automatically parses the benchmark data and generates pretty charts.
=head1 DESCRIPTION
It will parse the YAML output from the benchmark data and calls it's plugins to generate any charts necessary
and place them in the 'images' directory under the plugin's name. This module only does the high-level stuff, and leaves
the actual chart generation to the plugins.
Furthermore, we use Module::Pluggable to search all modules in the POE::Devel::Benchmarker::Imager::* namespace and
let them handle the generation of images. That way virtually unlimited combinations of images can be generated on the fly
from the data this module parses.
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker::Imager -e 'imager'
The way to use this module is by calling the imager() subroutine and let it do it's job. You can pass a hashref to it to
set various options. Here is a list of the valid options:
=over 4
=item quiet => boolean
This enables quiet mode which will not print anything to the console except for errors.
imager( { 'quiet' => 1 } );
default: false
=item noxsqueue => boolean / undef
This will tell the Imager to not consider those tests for the output.
imager( { noxsqueue => 1 } );
default: undef ( load both xsqueue and noxsqueue tests )
=item noasserts => boolean / undef
This will tell the Imager to not consider those tests for the output
imager( { noasserts => 1 } );
default: undef ( load both assert and noassert tests )
=item litetests => boolean
This will tell the Imager to not consider those tests for the output
imager( { litetests => 0 } );
default: true
+=item type => csv list or array
+
+This will tell the Imager to only process a specific plugin. Takes the same argument format as the main Benchmarker's poe + loop options.
+
+There is some "magic" here where you can put a negative sign in front of a plugin and we will NOT run that.
+
+ imager( { type => 'BasicStatistics' } ); # runs only the BasicStatistics plugin
+ imager( { type => [ qw( BasicStatistics BenchmarkOutput ) ] } ); # runs those 2 plugins
+ imager( { type => '-BasicStatistics' } ); # runs ALL plugins except BasicStatistics
+
=back
=head1 PLUGIN INTERFACE
-For now, this is undocumented. Please look at BasicStatistics for the general concept on how it interacts with this module.
+For now, this is undocumented. Please look at L<POE::Devel::Benchmarker::Imager::BasicStatistics> for the general
+concept on how it interacts with this module.
=head1 EXPORT
Automatically exports the imager() sub
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2010 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/Imager/BasicStatistics.pm b/lib/POE/Devel/Benchmarker/Imager/BasicStatistics.pm
index 512e10c..4883ffb 100644
--- a/lib/POE/Devel/Benchmarker/Imager/BasicStatistics.pm
+++ b/lib/POE/Devel/Benchmarker/Imager/BasicStatistics.pm
@@ -1,360 +1,365 @@
# Declare our package
package POE::Devel::Benchmarker::Imager::BasicStatistics;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.06';
# the GD stuff
use GD::Graph::lines;
use GD::Graph::colour qw( :lists );
+use File::Spec;
# import some stuff
use POE::Devel::Benchmarker::Utils qw( currentMetrics );
+# to silence Perl::Critic - # Three-argument form of open used at line 541, column 3. Three-argument open is not available until perl 5.6. (Severity: 5)
+use 5.008;
+
# creates a new instance
sub new {
my $class = shift;
my $opts = shift;
# instantitate ourself
my $self = {
'opts' => $opts,
};
return bless $self, $class;
}
# actually generates the graphs!
sub imager {
my $self = shift;
$self->{'imager'} = shift;
# generate the loops vs each other graphs
$self->generate_loopwars;
# generate the single loop performance
$self->generate_loopperf;
# generate the loop assert/xsqueue ( 4 lines ) per metric
$self->generate_loopoptions;
return;
}
# charts a single loop's progress over POE versions
sub generate_loopoptions {
my $self = shift;
if ( ! $self->{'imager'}->quiet ) {
print "[BasicStatistics] Generating the Loop-Options graphs...\n";
}
# go through all the loops we want
foreach my $loop ( keys %{ $self->{'imager'}->poe_loops } ) {
foreach my $metric ( @{ currentMetrics() } ) {
my %data;
# organize data by POE version
foreach my $poe ( @{ $self->{'imager'}->poe_versions_sorted } ) {
# go through the combo of assert/xsqueue
foreach my $assert ( qw( assert noassert ) ) {
if ( ! exists $self->{'imager'}->data->{ $assert } ) {
next;
}
foreach my $xsqueue ( qw( xsqueue noxsqueue ) ) {
if ( ! exists $self->{'imager'}->data->{ $assert }->{ $xsqueue } ) {
next;
}
# sometimes we cannot test a metric
if ( exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }
and exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
and defined $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
) {
push( @{ $data{ $assert . '_' . $xsqueue } }, $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'} );
} else {
push( @{ $data{ $assert . '_' . $xsqueue } }, 0 );
}
}
}
}
# it's possible for us to do runs without assert/xsqueue
if ( scalar keys %data > 0 ) {
# transform %data into something GD likes
my @data_for_gd;
foreach my $m ( sort keys %data ) {
push( @data_for_gd, $data{ $m } );
}
# send it to GD!
$self->make_gdgraph( 'Options_' . $loop . '_' . $metric,
[ sort keys %data ],
\@data_for_gd,
);
}
}
}
return;
}
# charts a single loop's progress over POE versions
sub generate_loopperf {
my $self = shift;
if ( ! $self->{'imager'}->quiet ) {
print "[BasicStatistics] Generating the Loop-Performance graphs...\n";
}
# go through all the loops we want
foreach my $loop ( keys %{ $self->{'imager'}->poe_loops } ) {
# go through the combo of assert/xsqueue
foreach my $assert ( qw( assert noassert ) ) {
if ( ! exists $self->{'imager'}->data->{ $assert } ) {
next;
}
foreach my $xsqueue ( qw( xsqueue noxsqueue ) ) {
if ( ! exists $self->{'imager'}->data->{ $assert }->{ $xsqueue } ) {
next;
}
my %data;
# organize data by POE version
foreach my $poe ( @{ $self->{'imager'}->poe_versions_sorted } ) {
foreach my $metric ( @{ currentMetrics() } ) {
# sometimes we cannot test a metric
if ( exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }
and exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
and defined $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
) {
push( @{ $data{ $metric } }, $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'} );
} else {
push( @{ $data{ $metric } }, 0 );
}
}
}
# transform %data into something GD likes
my @data_for_gd;
foreach my $m ( sort keys %data ) {
push( @data_for_gd, $data{ $m } );
}
# send it to GD!
$self->make_gdgraph( 'Bench_' . $loop,
[ sort keys %data ],
\@data_for_gd,
$assert,
$xsqueue,
);
}
}
}
return;
}
# loop wars!
sub generate_loopwars {
my $self = shift;
if ( ! $self->{'imager'}->quiet ) {
print "[BasicStatistics] Generating the LoopWars graphs...\n";
}
# go through all the metrics we want
foreach my $metric ( @{ currentMetrics() } ) {
# go through the combo of assert/xsqueue
foreach my $assert ( qw( assert noassert ) ) {
if ( ! exists $self->{'imager'}->data->{ $assert } ) {
next;
}
foreach my $xsqueue ( qw( xsqueue noxsqueue ) ) {
if ( ! exists $self->{'imager'}->data->{ $assert }->{ $xsqueue } ) {
next;
}
my %data;
# organize data by POE version
foreach my $poe ( @{ $self->{'imager'}->poe_versions_sorted } ) {
foreach my $loop ( keys %{ $self->{'imager'}->poe_loops } ) {
# sometimes we cannot test a metric
if ( exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }
and exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
and defined $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
) {
push( @{ $data{ $loop } }, $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'} );
} else {
push( @{ $data{ $loop } }, 0 );
}
}
}
# transform %data into something GD likes
my @data_for_gd;
foreach my $m ( sort keys %data ) {
push( @data_for_gd, $data{ $m } );
}
# send it to GD!
$self->make_gdgraph( "LoopWar_$metric",
[ sort keys %{ $self->{'imager'}->poe_loops } ],
\@data_for_gd,
$assert,
$xsqueue,
);
}
}
}
return;
}
sub make_gdgraph {
my $self = shift;
my $metric = shift;
my $legend = shift;
my $data = shift;
my $assert = shift;
my $xsqueue = shift;
# build the title
my $title = $metric;
if ( defined $assert ) {
$title .= ' (';
if ( defined $xsqueue ) {
$title .= $assert . ' ' . $xsqueue;
} else {
$title .= $assert;
}
$title .= ')';
} else {
if ( defined $xsqueue ) {
$title .= ' (' . $xsqueue . ')';
}
}
# Get the graph object
my $graph = new GD::Graph::lines( 800, 600 );
# Set some stuff
$graph->set(
'title' => $title,
'line_width' => 1,
'boxclr' => 'black',
'overwrite' => 0,
'x_labels_vertical' => 1,
'x_all_ticks' => 1,
'legend_placement' => 'BL',
'y_label' => 'iterations/sec',
'transparent' => 0,
'long_ticks' => 1,
) or die $graph->error;
# Set the legend
$graph->set_legend( @$legend );
# Set Font stuff
$graph->set_legend_font( GD::gdMediumBoldFont );
$graph->set_x_axis_font( GD::gdMediumBoldFont );
$graph->set_y_axis_font( GD::gdMediumBoldFont );
$graph->set_y_label_font( GD::gdMediumBoldFont );
$graph->set_title_font( GD::gdGiantFont );
# set the line colors
- $graph->set( 'dclrs' => [ grep { $_ ne 'black' and $_ ne 'white' } sorted_colour_list() ] );
+ # I don't like what this results in...
+ $graph->set( 'dclrs' => [ grep { $_ ne 'black' and $_ ne 'white' and substr( $_, 0, 1 ) eq 'd' } sorted_colour_list() ] );
# Manufacture the data
my $readydata = [
[ map { 'POE-' . $_ } @{ $self->{'imager'}->poe_versions_sorted } ],
@$data,
];
# Plot it!
$graph->plot( $readydata ) or die $graph->error;
# Print it!
- my $filename = $self->{'opts'}->{'dir'} . $metric . '_' .
+ my $filename = File::Spec->catfile( $self->{'opts'}->{'dir'}, $metric . '_' .
( $self->{'imager'}->litetests ? 'lite' : 'heavy' ) .
( defined $xsqueue ? '_' . $assert . '_' . $xsqueue : '' ) .
- '.png';
+ '.png' );
open( my $fh, '>', $filename ) or die 'Cannot open graph file!';
binmode( $fh );
print $fh $graph->gd->png();
close( $fh );
return;
}
1;
__END__
=for stopwords backend
=head1 NAME
-POE::Devel::Benchmarker::Imager::BasicStatistics - Plugin to generates basic statistics graphs
+POE::Devel::Benchmarker::Imager::BasicStatistics - Plugin to generate basic statistics graphs
=head1 SYNOPSIS
use POE::Devel::Benchmarker::Imager;
imager( { type => 'BasicStatistics' } );
=head1 ABSTRACT
This plugin for Imager generates some kinds of graphs from the benchmark tests.
=head1 DESCRIPTION
This package generates some basic graphs from the statistics output. Since the POE::Loop::* modules really are responsible
for the backend logic of POE, it makes sense to graph all related metrics of a single loop across POE versions to see if
it performs differently.
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker::Imager -e 'imager( { type => "BasicStatistics" } )'
This will generate some types of graphs:
=over 4
=item Loops against each other
Each metric will have a picture for itself, showing how each loop compare against each other with the POE versions.
file: BasicStatistics/LoopWar_$metric_$lite_$assert_$xsqueue.png
=item Single Loop over POE versions
Each Loop will have a picture for itself, showing how each metric performs over POE versions.
file: BasicStatistics/Bench_$loop_$lite_$assert_$xsqueue.png
=item Single Loop over POE versions with assert/xsqueue
Each Loop will have a picture for itself, showing how each metric is affected by the assert/xsqueue options.
file: BasicStatistics/Options_$loop_$metric_$lite.png
=back
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
L<POE::Devel::Benchmarker::Imager>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2010 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/Imager/BenchmarkOutput.pm b/lib/POE/Devel/Benchmarker/Imager/BenchmarkOutput.pm
new file mode 100644
index 0000000..8016ea1
--- /dev/null
+++ b/lib/POE/Devel/Benchmarker/Imager/BenchmarkOutput.pm
@@ -0,0 +1,354 @@
+# Declare our package
+package POE::Devel::Benchmarker::Imager::BenchmarkOutput;
+use strict; use warnings;
+
+# Initialize our version
+use vars qw( $VERSION );
+$VERSION = '0.06';
+
+# import some stuff
+use File::Spec;
+use POE::Devel::Benchmarker::Utils qw( currentMetrics metricSorting );
+use Text::Table;
+
+# to silence Perl::Critic - # Three-argument form of open used at line 541, column 3. Three-argument open is not available until perl 5.6. (Severity: 5)
+use 5.008;
+
+# creates a new instance
+sub new {
+ my $class = shift;
+ my $opts = shift;
+
+ # instantitate ourself
+ my $self = {
+ 'opts' => $opts,
+ };
+ return bless $self, $class;
+}
+
+# actually generates the graphs!
+sub imager {
+ my $self = shift;
+ $self->{'imager'} = shift;
+
+ # generate the loops vs each other graphs
+ $self->generate_loopwars;
+
+ # generate the single loop performance
+ #$self->generate_loopperf;
+
+ # generate the loop assert/xsqueue ( 4 lines ) per metric
+ #$self->generate_loopoptions;
+
+ return;
+}
+
+# charts a single loop's progress over POE versions
+sub generate_loopoptions {
+ my $self = shift;
+
+ if ( ! $self->{'imager'}->quiet ) {
+ print "[BenchmarkOutput] Generating the Loop-Options tables...\n";
+ }
+
+ # go through all the loops we want
+ foreach my $loop ( keys %{ $self->{'imager'}->poe_loops } ) {
+ foreach my $metric ( @{ currentMetrics() } ) {
+ my %data;
+
+ # organize data by POE version
+ foreach my $poe ( @{ $self->{'imager'}->poe_versions_sorted } ) {
+ # go through the combo of assert/xsqueue
+ foreach my $assert ( qw( assert noassert ) ) {
+ if ( ! exists $self->{'imager'}->data->{ $assert } ) {
+ next;
+ }
+ foreach my $xsqueue ( qw( xsqueue noxsqueue ) ) {
+ if ( ! exists $self->{'imager'}->data->{ $assert }->{ $xsqueue } ) {
+ next;
+ }
+
+ # sometimes we cannot test a metric
+ if ( exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }
+ and exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
+ and defined $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
+ ) {
+ push( @{ $data{ $assert . '_' . $xsqueue } }, $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'} );
+ } else {
+ push( @{ $data{ $assert . '_' . $xsqueue } }, 0 );
+ }
+ }
+ }
+ }
+
+ use Data::Dumper;
+ print Dumper( \%data );
+ exit;
+
+
+ # it's possible for us to do runs without assert/xsqueue
+ if ( scalar keys %data > 0 ) {
+ # transform %data into something GD likes
+ my @data_for_gd;
+ foreach my $m ( sort keys %data ) {
+ push( @data_for_gd, $data{ $m } );
+ }
+
+ # send it to GD!
+ $self->make_gdgraph( 'Options_' . $loop . '_' . $metric,
+ [ sort keys %data ],
+ \@data_for_gd,
+ );
+ }
+ }
+ }
+
+ return;
+}
+
+# charts a single loop's progress over POE versions
+sub generate_loopperf {
+ my $self = shift;
+
+ if ( ! $self->{'imager'}->quiet ) {
+ print "[BenchmarkOutput] Generating the Loop-Performance tables...\n";
+ }
+
+ # go through all the loops we want
+ foreach my $loop ( keys %{ $self->{'imager'}->poe_loops } ) {
+ # go through the combo of assert/xsqueue
+ foreach my $assert ( qw( assert noassert ) ) {
+ if ( ! exists $self->{'imager'}->data->{ $assert } ) {
+ next;
+ }
+ foreach my $xsqueue ( qw( xsqueue noxsqueue ) ) {
+ if ( ! exists $self->{'imager'}->data->{ $assert }->{ $xsqueue } ) {
+ next;
+ }
+ my %data;
+
+ # organize data by POE version
+ foreach my $poe ( @{ $self->{'imager'}->poe_versions_sorted } ) {
+ foreach my $metric ( @{ currentMetrics() } ) {
+ # sometimes we cannot test a metric
+ if ( exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }
+ and exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
+ and defined $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
+ ) {
+ push( @{ $data{ $metric } }, $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'} );
+ } else {
+ push( @{ $data{ $metric } }, 0 );
+ }
+ }
+ }
+
+ use Data::Dumper;
+ print Dumper( $loop, $self->{'imager'}->poe_versions_sorted, \%data );
+
+ # Actually make the table!
+ $self->make_table( "Loop Performance",
+ $loop,
+ $assert,
+ $xsqueue,
+ $self->{'imager'}->poe_versions_sorted,
+ \%data,
+ );
+ }
+ }
+ }
+
+ return;
+}
+
+# loop wars!
+sub generate_loopwars {
+ my $self = shift;
+
+ if ( ! $self->{'imager'}->quiet ) {
+ print "[BenchmarkOutput] Generating the LoopWars tables...\n";
+ }
+
+ # go through all the metrics we want
+ foreach my $metric ( @{ currentMetrics() } ) {
+ # go through the combo of assert/xsqueue
+ foreach my $assert ( qw( assert noassert ) ) {
+ if ( ! exists $self->{'imager'}->data->{ $assert } ) {
+ next;
+ }
+ foreach my $xsqueue ( qw( xsqueue noxsqueue ) ) {
+ if ( ! exists $self->{'imager'}->data->{ $assert }->{ $xsqueue } ) {
+ next;
+ }
+ my %data;
+
+ # organize data by POE version
+ foreach my $poe ( @{ $self->{'imager'}->poe_versions_sorted } ) {
+ foreach my $loop ( keys %{ $self->{'imager'}->poe_loops } ) {
+ # sometimes we cannot test a metric
+ if ( exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }
+ and exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
+ and defined $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
+ ) {
+ push( @{ $data{ $loop } }, $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'} );
+ } else {
+ push( @{ $data{ $loop } }, 0 );
+ }
+ }
+ }
+
+ # Actually make the table!
+ $self->make_loopwar_table( $metric, $assert, $xsqueue, $self->{'imager'}->poe_versions_sorted, \%data );
+ }
+ }
+ }
+
+ return;
+}
+
+sub make_loopwar_table {
+ my( $self, $metric, $assert, $xsqueue, $poeversions, $data ) = @_;
+ my $metric_sorting = metricSorting( $metric );
+
+ # Start the text with a header
+ my $text = " LoopWars - Metric ( $metric/sec ) ";
+
+ if ( $assert eq 'assert' ) {
+ $text .= "ASSERT ";
+ } else {
+ $text .= "NO-ASSERT ";
+ }
+
+ if ( $xsqueue eq 'xsqueue' ) {
+ $text .= "XSQUEUE";
+ } else {
+ $text .= "NO-XSQUEUE";
+ }
+
+ $text .= "\n\n";
+
+ # Create the grid
+ my @loops = sort keys %$data;
+ my $tbl = Text::Table->new(
+ # The POE version column
+ { title => "POE Version", align => 'center', align_title => 'center' },
+
+ # The vertical separator
+ \' | ',
+
+ # The rest of the columns
+ map { \' | ', { title => $_, align => 'center', align_title => 'center' } } @loops
+ );
+
+ # Fill in the data!
+ foreach my $i ( 0 .. ( scalar @$poeversions - 1 ) ) {
+ my @tmp = ( $poeversions->[ $i ] );
+
+ # put << 234 >> around cells that are the "winner" of that metric
+ my $best = undef;
+ foreach my $l ( 0 .. ( scalar @loops - 1 ) ) {
+ if ( ! defined $best ) {
+ $best = $l;
+ } else {
+ # What is the sort order?
+ if ( $metric_sorting eq 'B' ) {
+ if ( $data->{ $loops[ $l ] }->[ $i ] > $data->{ $loops[ $best ] }->[ $i ] ) {
+ $best = $l;
+ }
+ } elsif ( $metric_sorting eq 'S' ) {
+ if ( $data->{ $loops[ $l ] }->[ $i ] < $data->{ $loops[ $best ] }->[ $i ] ) {
+ $best = $l;
+ }
+ } else {
+ die "Unknown metric sorting method: $metric_sorting";
+ }
+ }
+
+ push( @tmp, $data->{ $loops[ $l ] }->[ $i ] );
+ }
+
+ # We found the best one...
+ $tmp[ $best + 1 ] = "<< " . $tmp[ $best + 1 ] . " >>";
+
+ $tbl->add( @tmp );
+ }
+
+ # Get the table, insert the horizontal divider, then print it out!
+ $text .= $tbl->table( 0 );
+ $text .= $tbl->rule( '-' );
+ $text .= $tbl->table( 1, $tbl->n_cols() - 1 );
+ $text .= $tbl->rule( '-' );
+
+ # All done!
+ print $text;
+}
+
+1;
+__END__
+
+=for stopwords backend
+
+=head1 NAME
+
+POE::Devel::Benchmarker::Imager::BenchmarkOutput - Plugin to generate output similar to Benchmark.pm
+
+=head1 SYNOPSIS
+
+ use POE::Devel::Benchmarker::Imager;
+ imager( { type => 'BenchmarkOutput' } );
+
+=head1 ABSTRACT
+
+This plugin for Imager generates Benchmark.pm-alike output from the benchmark tests.
+
+=head1 DESCRIPTION
+
+This package generates some basic text tables from the statistics output. Since the POE::Loop::* modules really are responsible
+for the backend logic of POE, it makes sense to measure all related metrics of a single loop across POE versions to see if
+it performs differently.
+
+ apoc@apoc-x300:~$ cd poe-benchmarker
+ apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker::Imager -e 'imager( { type => "BenchmarkOutput" } )'
+
+This will generate some types of tables:
+
+=over 4
+
+=item Loops against each other
+
+Each metric will have a table for itself, showing how each loop compare against each other with the POE versions.
+
+file: BenchmarkOutput/LoopWar_$metric_$lite_$assert_$xsqueue.txt
+
+=item Single Loop over POE versions
+
+Each Loop will have a table for itself, showing how each metric performs over POE versions.
+
+file: BenchmarkOutput/Bench_$loop_$lite_$assert_$xsqueue.txt
+
+=item Single Loop over POE versions with assert/xsqueue
+
+Each Loop will have a table for itself, showing how each metric is affected by the assert/xsqueue options.
+
+file: BenchmarkOutput/Options_$loop_$metric_$lite.txt
+
+=back
+
+=head1 SEE ALSO
+
+L<POE::Devel::Benchmarker>
+
+L<POE::Devel::Benchmarker::Imager>
+
+=head1 AUTHOR
+
+Apocalypse E<lt>apocal@cpan.orgE<gt>
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright 2010 by Apocalypse
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
+
diff --git a/lib/POE/Devel/Benchmarker/SubProcess.pm b/lib/POE/Devel/Benchmarker/SubProcess.pm
index a795a92..7f1a5f6 100644
--- a/lib/POE/Devel/Benchmarker/SubProcess.pm
+++ b/lib/POE/Devel/Benchmarker/SubProcess.pm
@@ -1,761 +1,773 @@
# Declare our package
package POE::Devel::Benchmarker::SubProcess;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.06';
# set our compile-time stuff
BEGIN {
# should we enable assertions?
if ( defined $ARGV[1] and $ARGV[1] ) {
- ## no critic
+ ## no critic ( ProhibitStringyEval )
eval "sub POE::Kernel::ASSERT_DEFAULT () { 1 }";
eval "sub POE::Session::ASSERT_STATES () { 1 }";
- ## use critic
}
# Compile a list of modules to hide
my $hide = '';
- if ( defined $ARGV[0] ) {
- if ( $ARGV[0] ne 'XSPoll' ) {
- $hide .= ' POE/XS/Loop/Poll.pm';
- }
- if ( $ARGV[0] ne 'XSEPoll' ) {
- $hide .= ' POE/XS/Loop/EPoll.pm';
- }
- }
# should we "hide" XS::Queue::Array?
if ( defined $ARGV[3] and $ARGV[3] ) {
$hide .= ' POE/XS/Queue/Array.pm';
}
# actually hide the modules!
- {
- ## no critic
- eval "use Devel::Hide qw( $hide )";
- ## use critic
+ if ( length $hide ) {
+ eval "use Devel::Hide qw( $hide )"; ## no critic ( ProhibitStringyEval )
}
}
# Import Time::HiRes's time()
use Time::HiRes qw( time );
# load POE
use POE;
use POE::Session;
use POE::Wheel::SocketFactory;
use POE::Wheel::ReadWrite;
use POE::Filter::Line;
use POE::Driver::SysRW;
+# to silence Perl::Critic - # Three-argument form of open used at line 541, column 3. Three-argument open is not available until perl 5.6. (Severity: 5)
+use 5.008;
+
# autoflush, please!
use IO::Handle;
STDOUT->autoflush( 1 );
# import some stuff
use Socket qw( INADDR_ANY sockaddr_in );
# we need to compare versions
use version;
# load our utility stuff
-use POE::Devel::Benchmarker::Utils qw( loop2realversion poeloop2load currentMetrics );
+use POE::Devel::Benchmarker::Utils qw( loop2realversion poeloop2load poeloop2dist currentMetrics );
# init our global variables ( bad, haha )
my( $eventloop, $asserts, $lite_tests, $pocosession );
# setup our metrics and their data
my %metrics = map { $_ => undef } @{ currentMetrics() };
# the main routine which will load everything + start
sub benchmark {
# process the eventloop
process_eventloop();
# process the assertions
process_assertions();
# process the test mode
process_testmode();
# process the XS::Queue hiding
process_xsqueue();
# actually import POE!
process_POE();
# actually run the benchmarks!
run_benchmarks();
# all done!
return;
}
sub process_eventloop {
# Get the desired mode
$eventloop = $ARGV[0];
# print out the loop info
if ( ! defined $eventloop ) {
die "Please supply an event loop!";
} else {
my $loop = poeloop2load( $eventloop );
if ( ! defined $loop ) {
$loop = $eventloop;
}
my $v = loop2realversion( $eventloop );
if ( ! defined $v ) {
$v = 'UNKNOWN';
}
print "Using master loop: $loop-$v\n";
}
return;
}
sub process_assertions {
# Get the desired assert mode
$asserts = $ARGV[1];
if ( defined $asserts and $asserts ) {
- print "Using FULL Assertions!\n";
+ # verify POE enabled assertions
+ if ( POE::Kernel::ASSERT_DEFAULT() ) {
+ print "Using FULL Assertions!\n";
+ } else {
+ die "Using FULL Assertions but POE didn't enable it!";
+ }
} else {
- print "Using NO Assertions!\n";
+ # verify POE disabled assertions
+ if ( ! POE::Kernel::ASSERT_DEFAULT() ) {
+ print "Using NO Assertions!\n";
+ } else {
+ die "Using NO Assertions but POE enabled it!";
+ }
}
return;
}
sub process_testmode {
# get the desired test mode
$lite_tests = $ARGV[2];
# setup most of the metrics
- $metrics{'startups'} = 10;
+ $metrics{'startups'} = 10;
# event tests
foreach my $s ( qw( posts dispatches calls single_posts ) ) {
$metrics{ $s } = 10_000;
}
# session tests
foreach my $s ( qw( session_creates session_destroys ) ) {
$metrics{ $s } = 500;
}
# alarm tests
foreach my $s ( qw( alarms alarm_adds alarm_clears ) ) {
$metrics{ $s } = 10_000;
}
# select tests
foreach my $s ( qw( select_read_STDIN select_write_STDIN select_read_MYFH select_write_MYFH ) ) {
$metrics{ $s } = 10_000;
}
# socket tests
foreach my $s ( qw( socket_connects socket_stream ) ) {
$metrics{ $s } = 1_000;
}
if ( defined $lite_tests and $lite_tests ) {
print "Using the LITE tests\n";
} else {
print "Using the HEAVY tests\n";
# we simply multiply each metric by 10x
foreach my $s ( @{ currentMetrics() } ) {
$metrics{ $s } = $metrics{ $s } * 10;
}
}
return;
}
sub process_xsqueue {
# should we "hide" XS::Queue::Array?
if ( defined $ARGV[3] and $ARGV[3] ) {
print "DISABLING POE::XS::Queue::Array\n";
} else {
print "LETTING POE find POE::XS::Queue::Array\n";
}
return;
}
sub process_POE {
# Print the POE info
print "Using POE-" . $POE::VERSION . "\n";
# Actually print what loop POE is using
foreach my $m ( keys %INC ) {
if ( $m =~ /^POE\/(?:Loop|XS|Queue)/ ) {
# try to be smart and get version?
my $module = $m;
$module =~ s|/|::|g;
$module =~ s/\.pm$//g;
print "POE is using: $module ";
if ( defined $module->VERSION ) {
print "v" . $module->VERSION . "\n";
} else {
print "vUNKNOWN\n";
}
}
}
return;
}
sub run_benchmarks {
# dump some misc info
dump_perlinfo();
dump_sysinfo();
# run the startup test before we actually run POE
bench_startup();
# load the POE session + do the tests there
bench_poe();
# okay, dump our memory usage
dump_pidinfo();
# all done!
return;
}
sub bench_startup {
- # Add the eventloop?
- my $looploader = poeloop2load( $eventloop );
+ # We do not care about xsqueue for startups, so we don't include them here...
+
+ # POE in 1.001 added POE_EVENT_LOOP env var, yay!
+ my $looploader;
+ if ( $POE::VERSION >= 1.001 ) {
+ $looploader = poeloop2dist( $eventloop );
+ } else {
+ # Add the eventloop?
+ $looploader = poeloop2load( $eventloop );
+ }
+
+ local $ENV{POE_EVENT_LOOP} = $looploader if defined $looploader and $looploader =~ /^POE::/;
+ undef $looploader if defined $looploader and $looploader =~ /^POE::/;
my @start_times = times();
my $start = time();
for (my $i = 0; $i < $metrics{'startups'}; $i++) {
- # We do not care about xsqueue for startups, so we don't include them here...
- # TODO fix the "strange" loop loader - i.e. Kqueue
-
# finally, fire it up!
CORE::system(
$^X,
'-Ipoedists/POE-' . $POE::VERSION,
'-Ipoedists/POE-' . $POE::VERSION . '/lib',
( defined $looploader ? "-M$looploader" : () ),
'-e',
$asserts ? 'sub POE::Kernel::ASSERT_DEFAULT () { 1 } sub POE::Session::ASSERT_STATES () { 1 } use POE; 1;' : 'use POE; 1;',
);
}
+
+ # process the result
my @end_times = times();
my $elapsed = time() - $start;
printf( "\n\n% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'startups'}, 'startups', $elapsed, $metrics{'startups'}/$elapsed );
print "startups times: @start_times @end_times\n";
return;
}
sub bench_poe {
# figure out POE::Session->create or POE::Session->new or what?
$pocosession = POE::Session->can( 'create' );
if ( defined $pocosession ) {
$pocosession = 'create';
} else {
$pocosession = POE::Session->can( 'spawn' );
if ( defined $pocosession ) {
$pocosession = 'spawn';
} else {
$pocosession = 'new';
}
}
# create the master sesssion + run POE!
POE::Session->$pocosession(
'inline_states' => {
# basic POE states
'_start' => \&poe__start,
'_default' => \&poe__default,
'_stop' => \&poe__stop,
'null' => \&poe_null,
# our test states
'posts' => \&poe_posts,
'posts_start' => \&poe_posts_start,
'posts_end' => \&poe_posts_end,
'alarms' => \&poe_alarms,
'manyalarms' => \&poe_manyalarms,
'sessions' => \&poe_sessions,
'sessions_end' => \&poe_sessions_end,
'stdin_read' => \&poe_stdin_read,
'stdin_write' => \&poe_stdin_write,
'myfh_read' => \&poe_myfh_read,
'myfh_write' => \&poe_myfh_write,
'calls' => \&poe_calls,
'eventsquirt' => \&poe_eventsquirt,
'eventsquirt_done' => \&poe_eventsquirt_done,
'socketfactory' => \&poe_socketfactory,
'socketfactory_start' => \&poe_socketfactory_start,
'socketfactory_connects' => \&poe_socketfactory_connects,
'socketfactory_stream' => \&poe_socketfactory_stream,
'socketfactory_cleanup' => \&poe_socketfactory_cleanup,
# misc states for test stuff
'server_sf_connect' => \&poe_server_sf_connect,
'server_sf_failure' => \&poe_server_sf_failure,
'server_rw_input' => \&poe_server_rw_input,
'server_rw_error' => \&poe_server_rw_error,
'client_sf_connect' => \&poe_client_sf_connect,
'client_sf_failure' => \&poe_client_sf_failure,
'client_rw_input' => \&poe_client_rw_input,
'client_rw_error' => \&poe_client_rw_error,
},
);
# start the kernel!
POE::Kernel->run();
return;
}
# inits our session
sub poe__start {
# fire off the first test!
$_[KERNEL]->yield( 'posts' );
return;
}
sub poe__stop {
}
sub poe__default {
return 0;
}
# a state that does nothing
sub poe_null {
return 1;
}
# How many posts per second? Post a bunch of events, keeping track of the time it takes.
sub poe_posts {
$_[KERNEL]->yield( 'posts_start' );
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $metrics{'posts'}; $i++) {
$_[KERNEL]->yield( 'null' );
}
my @end_times = times();
my $elapsed = time() - $start;
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'posts'}, 'posts', $elapsed, $metrics{'posts'}/$elapsed );
print "posts times: @start_times @end_times\n";
$_[KERNEL]->yield( 'posts_end' );
return;
}
sub poe_posts_start {
$_[HEAP]->{start} = time();
$_[HEAP]->{starttimes} = [ times() ];
return;
}
sub poe_posts_end {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'dispatches'}, 'dispatches', $elapsed, $metrics{'dispatches'}/$elapsed );
print "dispatches times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
$_[KERNEL]->yield( 'alarms' );
return;
}
# How many alarms per second? Set a bunch of alarms and find out.
sub poe_alarms {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $metrics{'alarms'}; $i++) {
$_[KERNEL]->alarm( whee => rand(1_000_000) );
}
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'alarms'}, 'alarms', $elapsed, $metrics{'alarms'}/$elapsed );
print "alarms times: @start_times @end_times\n";
$_[KERNEL]->alarm( 'whee' => undef );
$_[KERNEL]->yield( 'manyalarms' );
return;
}
# How many repetitive alarms per second? Set a bunch of
# additional alarms and find out. Also see how quickly they can
# be cleared.
sub poe_manyalarms {
# can this POE::Kernel support this?
if ( $_[KERNEL]->can( 'alarm_add' ) ) {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $metrics{'alarm_adds'}; $i++) {
$_[KERNEL]->alarm_add( whee => rand(1_000_000) );
}
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'alarm_adds'}, 'alarm_adds', $elapsed, $metrics{'alarm_adds'}/$elapsed );
print "alarm_adds times: @start_times @end_times\n";
$start = time();
@start_times = times();
$_[KERNEL]->alarm( whee => undef );
$elapsed = time() - $start;
@end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'alarm_adds'}, 'alarm_clears', $elapsed, $metrics{'alarm_adds'}/$elapsed );
print "alarm_clears times: @start_times @end_times\n";
} else {
print "SKIPPING br0ken alarm_adds because alarm_add() NOT SUPPORTED on this version of POE\n";
print "SKIPPING br0ken alarm_clears because alarm_add() NOT SUPPORTED on this version of POE\n";
}
$_[KERNEL]->yield( 'sessions' );
return;
}
# How many sessions can we create and destroy per second?
# Create a bunch of sessions, and track that time. Let them
# self-destruct, and track that as well.
sub poe_sessions {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $metrics{'session_creates'}; $i++) {
POE::Session->$pocosession( 'inline_states' => { _start => sub {}, _stop => sub {}, _default => sub { return 0 } } );
}
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'session_creates'}, 'session_creates', $elapsed, $metrics{'session_creates'}/$elapsed );
print "session_creates times: @start_times @end_times\n";
$_[KERNEL]->yield( 'sessions_end' );
$_[HEAP]->{start} = time();
$_[HEAP]->{starttimes} = [ times() ];
return;
}
sub poe_sessions_end {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'session_creates'}, 'session_destroys', $elapsed, $metrics{'session_creates'}/$elapsed );
print "session_destroys times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
$_[KERNEL]->yield( 'stdin_read' );
return;
}
# How many times can we select/unselect READ a from STDIN filehandle per second?
sub poe_stdin_read {
# stupid, but we have to skip those tests
if ( $eventloop eq 'Tk' or $eventloop eq 'Prima' ) {
print "SKIPPING br0ken select_read_STDIN because eventloop doesn't work: $eventloop\n";
print "SKIPPING br0ken select_write_STDIN because eventloop doesn't work: $eventloop\n";
$_[KERNEL]->yield( 'myfh_read' );
return;
}
my $start = time();
my @start_times = times();
eval {
for (my $i = 0; $i < $metrics{'select_read_STDIN'}; $i++) {
$_[KERNEL]->select_read( *STDIN, 'whee' );
$_[KERNEL]->select_read( *STDIN );
}
};
if ( $@ ) {
print "SKIPPING br0ken select_read_STDIN because FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'select_read_STDIN'}, 'select_read_STDIN', $elapsed, $metrics{'select_read_STDIN'}/$elapsed );
print "select_read_STDIN times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'stdin_write' );
return;
}
# How many times can we select/unselect WRITE a from STDIN filehandle per second?
sub poe_stdin_write {
my $start = time();
my @start_times = times();
eval {
for (my $i = 0; $i < $metrics{'select_write_STDIN'}; $i++) {
$_[KERNEL]->select_write( *STDIN, 'whee' );
$_[KERNEL]->select_write( *STDIN );
}
};
if ( $@ ) {
print "SKIPPING br0ken select_write_STDIN because FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'select_write_STDIN'}, 'select_write_STDIN', $elapsed, $metrics{'select_write_STDIN'}/$elapsed );
print "select_write_STDIN times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'myfh_read' );
return;
}
# How many times can we select/unselect READ a real filehandle?
sub poe_myfh_read {
# stupid, but we have to skip those tests
if ( $eventloop eq 'Event_Lib' or $eventloop eq 'Tk' or $eventloop eq 'Prima' ) {
print "SKIPPING br0ken select_read_MYFH because eventloop doesn't work: $eventloop\n";
print "SKIPPING br0ken select_write_MYFH because eventloop doesn't work: $eventloop\n";
$_[KERNEL]->yield( 'calls' );
return;
}
my $start = time();
my @start_times = times();
eval {
open( my $fh, '+>', 'poebench' ) or die $!;
for (my $i = 0; $i < $metrics{'select_read_MYFH'}; $i++) {
$_[KERNEL]->select_read( $fh, 'whee' );
$_[KERNEL]->select_read( $fh );
}
close( $fh ) or die $!;
unlink( 'poebench' ) or die $!;
};
if ( $@ ) {
print "SKIPPING br0ken select_read_MYFH because FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'select_read_MYFH'}, 'select_read_MYFH', $elapsed, $metrics{'select_read_MYFH'}/$elapsed );
print "select_read_MYFH times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'myfh_write' );
return;
}
# How many times can we select/unselect WRITE a real filehandle?
sub poe_myfh_write {
my $start = time();
my @start_times = times();
eval {
open( my $fh, '+>', 'poebench' ) or die $!;
for (my $i = 0; $i < $metrics{'select_write_MYFH'}; $i++) {
$_[KERNEL]->select_write( $fh, 'whee' );
$_[KERNEL]->select_write( $fh );
}
close( $fh ) or die $!;
unlink( 'poebench' ) or die $!;
};
if ( $@ ) {
print "SKIPPING br0ken select_write_MYFH because FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'select_write_MYFH'}, 'select_write_MYFH', $elapsed, $metrics{'select_write_MYFH'}/$elapsed );
print "select_write_MYFH times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'calls' );
return;
}
# How many times can we call a state?
sub poe_calls {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $metrics{'calls'}; $i++) {
$_[KERNEL]->call( $_[SESSION], 'null' );
}
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'calls'}, 'calls', $elapsed, $metrics{'calls'}/$elapsed );
print "calls times: @start_times @end_times\n";
$_[KERNEL]->yield( 'eventsquirt' );
return;
}
# How many events can we squirt through POE, one at a time?
sub poe_eventsquirt {
$_[HEAP]->{start} = time();
$_[HEAP]->{starttimes} = [ times() ];
$_[HEAP]->{yield_count} = $metrics{'single_posts'};
$_[KERNEL]->yield( 'eventsquirt_done' );
return;
}
sub poe_eventsquirt_done {
if (--$_[HEAP]->{yield_count}) {
$_[KERNEL]->yield( 'eventsquirt_done' );
} else {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'single_posts'}, 'single_posts', $elapsed, $metrics{'single_posts'}/$elapsed );
print "single_posts times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
$_[KERNEL]->yield( 'socketfactory' );
}
return;
}
# tests socketfactory interactions
sub poe_socketfactory {
# POE transitioned between Event to State on 0.19 for SocketFactory/ReadWrite
# 0.20+ throws deprecation error :(
$_[HEAP]->{'POE_naming'} = 'Event';
if ( version->new( $POE::VERSION ) < version->new( '0.20' ) ) {
$_[HEAP]->{'POE_naming'} = 'State';
}
# create the socketfactory server
$_[HEAP]->{'SF'} = POE::Wheel::SocketFactory->new(
'Port' => INADDR_ANY,
'Address' => 'localhost',
'Reuse' => 'yes',
'Success' . $_[HEAP]->{'POE_naming'} => 'server_sf_connect',
'Failure' . $_[HEAP]->{'POE_naming'} => 'server_sf_failure',
);
# be evil, and get the port for the client to connect to
( $_[HEAP]->{'SF_port'}, undef ) = sockaddr_in( getsockname( $_[HEAP]->{'SF'}->[ POE::Wheel::SocketFactory::MY_SOCKET_HANDLE() ] ) );
# start the connect tests
$_[HEAP]->{'SF_counter'} = $metrics{'socket_connects'};
$_[HEAP]->{'SF_mode'} = 'socket_connects';
$_[HEAP]->{'start'} = time();
$_[HEAP]->{'starttimes'} = [ times() ];
$_[KERNEL]->yield( 'socketfactory_connects' );
return;
}
# handles SocketFactory connection
sub poe_server_sf_connect {
# what test mode?
if ( $_[HEAP]->{'SF_mode'} eq 'socket_connects' ) {
# simply discard this socket
} elsif ( $_[HEAP]->{'SF_mode'} eq 'socket_stream' ) {
# convert it to ReadWrite
my $wheel = POE::Wheel::ReadWrite->new(
'Handle' => $_[ARG0],
'Filter' => POE::Filter::Line->new,
'Driver' => POE::Driver::SysRW->new,
'Input' . $_[HEAP]->{'POE_naming'} => 'server_rw_input',
'Error' . $_[HEAP]->{'POE_naming'} => 'server_rw_error',
);
# save it in our heap
$_[HEAP]->{'RW'}->{ $wheel->ID } = $wheel;
} else {
die "unknown test mode";
}
return;
}
# handles SocketFactory errors
sub poe_server_sf_failure {
# ARGH, we couldnt create listening socket
print "SKIPPING br0ken socket_connects because we were unable to setup listening socket\n";
print "SKIPPING br0ken socket_stream because we were unable to setup listening socket\n";
$_[KERNEL]->yield( 'socketfactory_cleanup' );
return;
}
# handles ReadWrite input
sub poe_server_rw_input {
# what test mode?
if ( $_[HEAP]->{'SF_mode'} eq 'socket_connects' ) {
# simply discard this data
} elsif ( $_[HEAP]->{'SF_mode'} eq 'socket_stream' ) {
# send it back to the client!
$_[HEAP]->{'RW'}->{ $_[ARG1] }->put( $_[ARG0] );
} else {
die "unknown test mode";
}
return;
}
# handles ReadWrite disconnects
sub poe_server_rw_error {
# simply get rid of the wheel
if ( exists $_[HEAP]->{'RW'}->{ $_[ARG3] } ) {
# shutdown everything, so we don't have any lingering sockets
eval {
$_[HEAP]->{'RW'}->{ $_[ARG3] }->shutdown_input;
$_[HEAP]->{'RW'}->{ $_[ARG3] }->shutdown_output;
};
delete $_[HEAP]->{'RW'}->{ $_[ARG3] };
}
return;
}
# starts the client connect tests
sub poe_socketfactory_connects {
if (--$_[HEAP]->{'SF_counter'}) {
# open a new client connection!
$_[HEAP]->{'client_SF'} = POE::Wheel::SocketFactory->new(
'RemoteAddress' => 'localhost',
'RemotePort' => $_[HEAP]->{'SF_port'},
'Success' . $_[HEAP]->{'POE_naming'} => 'client_sf_connect',
'Failure' . $_[HEAP]->{'POE_naming'} => 'client_sf_failure',
);
} else {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'socket_connects'}, 'socket_connects', $elapsed, $metrics{'socket_connects'}/$elapsed );
print "socket_connects times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
$_[KERNEL]->yield( 'socketfactory_stream' );
}
return;
}
# starts the client stream tests
sub poe_socketfactory_stream {
# set the proper test mode
$_[HEAP]->{'SF_mode'} = 'socket_stream';
# open a new client connection!
$_[HEAP]->{'client_SF'} = POE::Wheel::SocketFactory->new(
'RemoteAddress' => 'localhost',
'RemotePort' => $_[HEAP]->{'SF_port'},
'Success' . $_[HEAP]->{'POE_naming'} => 'client_sf_connect',
'Failure' . $_[HEAP]->{'POE_naming'} => 'client_sf_failure',
);
return;
}
diff --git a/lib/POE/Devel/Benchmarker/Utils.pm b/lib/POE/Devel/Benchmarker/Utils.pm
index 79e8e8c..0d51a6a 100644
--- a/lib/POE/Devel/Benchmarker/Utils.pm
+++ b/lib/POE/Devel/Benchmarker/Utils.pm
@@ -1,241 +1,309 @@
# Declare our package
package POE::Devel::Benchmarker::Utils;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.06';
# set ourself up for exporting
use base qw( Exporter );
-our @EXPORT_OK = qw( poeloop2load load2poeloop loop2realversion beautify_times knownloops generateTestfile
- currentMetrics currentTestVersion
+our @EXPORT_OK = qw( poeloop2load poeloop2dist loop2realversion knownloops
+ beautify_times generateTestfile
+ currentMetrics metricSorting currentTestVersion
);
# returns the current test output version
sub currentTestVersion {
- return '1';
+ return '2';
}
+# List our metrics
+# TODO add metrics for pid, total testsuite wallclock, times, etc
+my %metrics = (
+ 'startups' => 'B',
+ 'alarms' => 'B',
+ 'alarm_adds' => 'B',
+ 'alarm_clears' => 'B',
+ 'dispatches' => 'B',
+ 'posts' => 'B',
+ 'single_posts' => 'B',
+ 'session_creates' => 'B',
+ 'session_destroys' => 'B',
+ 'select_read_MYFH' => 'B',
+ 'select_write_MYFH' => 'B',
+ 'select_read_STDIN' => 'B',
+ 'select_write_STDIN' => 'B',
+ 'socket_connects' => 'B',
+ 'socket_stream' => 'B',
+);
+
# returns the list of current metrics
sub currentMetrics {
- return [ qw(
- startups
- alarms alarm_adds alarm_clears
- dispatches posts single_posts
- session_creates session_destroys
- select_read_MYFH select_write_MYFH select_read_STDIN select_write_STDIN
- socket_connects socket_stream
- ) ];
+ return [ sort keys %metrics ];
+}
+
+# Returns the sorting method for a metric
+sub metricSorting {
+ my $metric = shift;
+ if ( exists $metrics{ $metric } ) {
+ return $metrics{ $metric };
+ } else {
+ die "Unknown metric $metric";
+ }
}
# returns the filename for a particular test
sub generateTestfile {
my $heap = shift;
+ ## no critic ( ProhibitAccessOfPrivateData )
+
return 'POE-' . $heap->{'current_version'} .
'-' . $heap->{'current_loop'} .
'-' . ( $heap->{'lite_tests'} ? 'LITE' : 'HEAVY' ) .
'-' . ( $heap->{'current_assertions'} ? 'assert' : 'noassert' ) .
'-' . ( $heap->{'current_noxsqueue'} ? 'noxsqueue' : 'xsqueue' );
}
# maintains the mapping of the loop <-> real module
my %poe2load = (
'Event' => 'Event',
'IO_Poll' => 'IO::Poll',
'Event_Lib' => 'Event::Lib',
'EV' => 'EV',
'Glib' => 'Glib',
'Tk' => 'Tk',
'Gtk' => 'Gtk',
'Prima' => 'Prima',
'Wx' => 'Wx',
'Kqueue' => undef,
'Select' => undef,
+ 'XSPoll' => undef,
+ 'XSEPoll' => undef,
+);
+
+# maintains the mapping of the loop <-> actual dist name
+my %loop2dist = (
+ 'Event' => 'POE::Loop::Event',
+ 'IO_Poll' => 'POE::Loop::IO_Poll',
+ 'Event_Lib' => 'POE::Loop::Event_Lib',
+ 'EV' => 'POE::Loop::EV',
+ 'Glib' => 'POE::Loop::Glib',
+ 'Tk' => 'POE::Loop::Tk',
+ 'Gtk' => 'POE::Loop::Gtk',
+ 'Prima' => 'POE::Loop::Prima',
+ 'Wx' => 'POE::Loop::Wx',
+ 'Kqueue' => 'POE::Loop::Kqueue',
+ 'Select' => 'POE::Loop::Select',
+ 'XSPoll' => 'POE::XS::Loop::Poll',
+ 'XSEPoll' => 'POE::XS::Loop::EPoll',
);
# returns the proper "load" stuff for a specific loop
sub poeloop2load {
my $eventloop = shift;
if ( exists $poe2load{ $eventloop } ) {
return $poe2load{ $eventloop };
} else {
die "Unknown event loop!";
}
}
+# returns the full module name - useful to load a loop via POE_EVENT_LOOP
+sub poeloop2dist {
+ my $eventloop = shift;
+
+ if ( exists $loop2dist{ $eventloop } ) {
+ return $loop2dist{ $eventloop };
+ } else {
+ die "Unknown event loop!";
+ }
+}
+
# returns the version of the "real" installed module that the loop uses
sub loop2realversion {
my $eventloop = shift;
# Decide which event loop to use
if ( ! defined $eventloop ) {
return;
} elsif ( $eventloop eq 'Event' ) {
return $Event::VERSION;
} elsif ( $eventloop eq 'IO_Poll' ) {
return $IO::Poll::VERSION;
} elsif ( $eventloop eq 'Event_Lib' ) {
return $Event::Lib::VERSION;
} elsif ( $eventloop eq 'EV' ) {
return $EV::VERSION;
} elsif ( $eventloop eq 'Glib' ) {
return $Glib::VERSION;
} elsif ( $eventloop eq 'Tk' ) {
return $Tk::VERSION;
} elsif ( $eventloop eq 'Gtk' ) {
return $Gtk::VERSION;
} elsif ( $eventloop eq 'Prima' ) {
return $Prima::VERSION;
} elsif ( $eventloop eq 'Wx' ) {
return $Wx::VERSION;
} elsif ( $eventloop eq 'Kqueue' ) {
# POE::Loop::Kqueue doesn't rely on an external module...
return $POE::Loop::Kqueue::VERSION;
} elsif ( $eventloop eq 'Select' ) {
return 'BUILTIN';
-
- # FIXME figure the XS stuff out!
-# } elsif ( $eventloop eq 'XSPoll' ) {
-# return $POE::XS::Loop::Poll::VERSION;
-# } elsif ( $eventloop eq 'XSEpoll' ) {
-# return $POE::XS::Loop::EPoll::VERSION;
+ } elsif ( $eventloop eq 'XSPoll' ) {
+ return $POE::XS::Loop::Poll::VERSION;
+ } elsif ( $eventloop eq 'XSEPoll' ) {
+ return $POE::XS::Loop::EPoll::VERSION;
} else {
die "Unknown event loop!";
}
}
# helper routine to parse times() output
sub beautify_times {
my $string = shift;
my $origdata = shift;
# split it up
$string =~ s/^\s+//; $string =~ s/\s+$//;
my @times = split( /\s+/, $string );
# make the data struct
# ($user,$system,$cuser,$csystem) = times;
my $data = {
'u' => $times[4] - $times[0],
's' => $times[5] - $times[1],
'cu' => $times[6] - $times[2],
'cs' => $times[7] - $times[3],
};
# add original data?
if ( $origdata ) {
+ ## no critic ( ProhibitAccessOfPrivateData )
+
$data->{'s_user'} = $times[0];
$data->{'s_sys'} = $times[1];
$data->{'s_cuser'} = $times[2];
$data->{'s_csys'} = $times[3];
$data->{'e_user'} = $times[4];
$data->{'e_sys'} = $times[5];
$data->{'e_cuser'} = $times[6];
$data->{'e_csys'} = $times[7];
}
# send it back!
return $data;
}
# returns a list of "known" POE loops
sub knownloops {
- # FIXME figure out the XS stuff! XSPoll XSEPoll
- return [ sort qw( Event Event_Lib EV Glib Prima Gtk Tk Select IO_Poll Wx Kqueue ) ];
+ return [ sort qw( Event Event_Lib EV Glib Prima Gtk Tk Select IO_Poll Wx Kqueue XSPoll XSEPoll ) ];
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::Utils - Various utility routines for POE::Devel::Benchmarker
=head1 SYNOPSIS
use POE::Devel::Benchmarker::Utils qw( poeloop2load );
print poeloop2load( "IO_Poll" );
=head1 ABSTRACT
This package contains the utility routines and constants that POE::Devel::Benchmarker needs.
=head1 EXPORT
This package exports those subs via @EXPORT_OK:
=over 4
=item currentTestVersion()
Returns the current test version, used to identify different versions of the test output
=item currentMetrics()
Returns an arrayref of the current benchmark "metrics" that we process
+=item metricSorting( $metric )
+
+Returns the sorting method for $metric. Current sorting methods:
+
+ B -> Biggest number
+ S -> Smallest number
+
=item knownloops()
Returns an arrayref of the "known" POE loops as of this version of the Benchmarker
-=item poeloop2load()
+=item poeloop2load( $loop )
Returns the "parent" class to load for a specific loop. An example is:
$real = poeloop2load( 'IO_Poll' ); # $real now contains "IO::Poll"
-=item loop2realversion()
+=item poeloop2dist( $loop )
+
+Returns the proper name of the loop to use in loading POE via $ENV{POE_EVENT_LOOP}. An example is:
+
+ $real = poeloop2dist( 'XSPoll' ); # $real now contains "POE::XS::Loop::Poll"
+
+=item loop2realversion( $loop )
Returns the version of the "parent" class for a specific loop. An example is:
$ver = loop2realversion( 'IO_Poll' ); # $ver now contains $IO::Poll::VERSION
-=item beautify_times()
+=item beautify_times( @times, @times2 )
Returns a hashref of data from parsing 2 consecutive times() structures in a string. You can pass an additional parameter
( boolean ) to include the original data. An example is:
print Data::Dumper::Dumper( beautify_times( '0.1 0 0 0 0.1 0 0.76 0.09', 1 ) );
{
"sys" => 0, # total system time
"user" => 0, # total user time
"csys" => 0.76 # total children system time
"cuser" => 0.08 # total children user time
"e_csys" => "0.09", # end children system time ( optional )
"e_cuser" => "0.76", # end children user time ( optional )
"e_sys" => 0, # end system time ( optional )
"e_user" => "0.1", # end user time ( optional )
"s_csys" => 0, # start children system time ( optional )
"s_cuser" => 0, # start children user time ( optional )
"s_sys" => 0, # start system time ( optional )
"s_user" => "0.1" # start user time ( optional )
}
=item generateTestfile()
Internal method, accepts the POE HEAP as an argument and returns the filename of the test.
my $file = generateTestfile( $_[HEAP] );
=back
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2010 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/t/apocalypse.t b/t/apocalypse.t
index 256a1c5..8246c92 100644
--- a/t/apocalypse.t
+++ b/t/apocalypse.t
@@ -1,11 +1,13 @@
#!/usr/bin/perl
use strict; use warnings;
use Test::More;
eval "use Test::Apocalypse";
if ( $@ ) {
plan skip_all => 'Test::Apocalypse required for validating the distribution';
} else {
require Test::NoWarnings; require Test::Pod; require Test::Pod::Coverage; # lousy hack for kwalitee
- is_apocalypse_here();
+ is_apocalypse_here( {
+ deny => qr/^(?:(?:OutdatedPrereq|Dependencie)s|ModuleUsed|Strict|Fixme|Pod_(?:Coverage|Spelling))$/,
+ } );
}
|
apocalypse/perl-poe-benchmarker
|
ce77e055b685f892fb176c47fd36fbb0627592c1
|
minor tweaks
|
diff --git a/Changes b/Changes
index ad0964c..1dfa118 100644
--- a/Changes
+++ b/Changes
@@ -1,50 +1,51 @@
Revision history for Perl extension POE::Devel::Benchmarker
* 0.06
POD tweaks and typo fixes
Cleanup Build.PL and remove a lot of tests in favor of Test::Apocalypse
Fixed a bug where the Benchmarker wouldn't recognize old test runs and skip them
Add File::Spec so we are more portable, yay!
POE::Loop::Event wasn't benchmarked - added to the list
Wx/POE::Loop::Wx works now - added to the list
+ Finally fired up a FreeBSD VM and confirmed that POE::Loop::Kqueue works - added to the list
* 0.05
Minor tweaks on the YAML output ( nothing new, hah! )
Added the socket tests, yay! ( still need more work so we test various methods of socket creation )
Some more tweaks to the BasicStatistics plugin for prettier graphs
Lots of refactoring to get things cleaned up :)
Added test versioning, so we make sure we're processing the right version :)
added examples/test.pl to satisfy kwalitee requirements, ha!
* 0.04
Started work on the image generator ( Imager ) and added the BasicStatistics plugin, yay!
Added automatic "pick up where we left off" to the benchmarker
Added the freshstart option to benchmark()
Tweaked the GetPOEdists sub so it will work in the "work directory" and in the poedists dir
Tweaked the YAML output so it's smaller
Removed POE::Loop::Wx from autoprobing ( I'm unable to get it to work )
Removed POE::Loop::Kqueue from autoprobing ( I'm unable to get it to work )
Hardcoded the Benchmarker routines to skip POE < 0.13 ( I'm unable to get it to work )
* 0.03
Added the loop option to benchmark(), thanks dngor!
Added the poe option to benchmark(), thanks dngor!
Added the noxsqueue option to benchmark()
Added the noasserts option to benchmark()
Automatically enable noxsqueue option if we cannot load POE::XS::Queue::Array, saving time
Bump Test::More version requirement because some people reported failures with note()
Fixed bug in SubProcess where it crashed on old POEs that didn't load IO::Handle
More documentation additions/tweaks
* 0.02
Added the Analyzer module ( and dump YAML files, yay! )
A lot of minor changes+tweaks to get a better dump format
* 0.01
initial release
diff --git a/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm b/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm
index 60a66fa..ab2c154 100644
--- a/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm
+++ b/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm
@@ -1,207 +1,207 @@
# Declare our package
package POE::Devel::Benchmarker::GetInstalledLoops;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.06';
# auto-export the only sub we have
use base qw( Exporter );
our @EXPORT = qw( getPOEloops );
# Import what we need from the POE namespace
use POE qw( Session Filter::Line Wheel::Run );
use base 'POE::Session::AttributeBased';
# Get the utils
use POE::Devel::Benchmarker::Utils qw ( knownloops );
# analyzes the installed perl directory for available loops
sub getPOEloops {
my $quiet_mode = shift;
my $forceloops = shift;
+ # load our known list of loops
+ # known impossible loops:
+ # XS::EPoll ( must be POE > 1.003 and weird way of loading )
+ # XS::Poll ( must be POE > 1.003 and weird way of loading )
+ if ( ! defined $forceloops ) {
+ $forceloops = knownloops();
+ }
+
# create our session!
POE::Session->create(
- POE::Devel::Benchmarker::GetInstalledLoops->inline_states(),
+ __PACKAGE__->inline_states(),
'heap' => {
'quiet_mode' => $quiet_mode,
'loops' => $forceloops,
},
);
}
# Starts up our session
sub _start : State {
# set our alias
$_[KERNEL]->alias_set( 'Benchmarker::GetInstalledLoops' );
- # load our known list of loops
- # known impossible loops:
- # XS::EPoll ( must be POE > 1.003 and weird way of loading )
- # XS::Poll ( must be POE > 1.003 and weird way of loading )
- if ( ! defined $_[HEAP]->{'loops'} ) {
- $_[HEAP]->{'loops'} = knownloops();
- }
-
# First of all, we need to find out what loop libraries are installed
$_[HEAP]->{'found_loops'} = [];
$_[KERNEL]->yield( 'find_loops' );
return;
}
sub _stop : State {
# tell the wheel to kill itself
if ( defined $_[HEAP]->{'WHEEL'} ) {
$_[HEAP]->{'WHEEL'}->kill( 9 );
undef $_[HEAP]->{'WHEEL'};
}
return;
}
# loops over the "known" loops and sees if they are installed
sub find_loops : State {
# get the loop to test
$_[HEAP]->{'current_loop'} = shift @{ $_[HEAP]->{'loops'} };
# do we have something to test?
if ( ! defined $_[HEAP]->{'current_loop'} ) {
# we're done!
$_[KERNEL]->alias_remove( 'Benchmarker::GetInstalledLoops' );
$_[KERNEL]->post( 'Benchmarker', 'found_loops', $_[HEAP]->{'found_loops'} );
return;
} else {
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[LOOPSEARCH] Trying to find if POE::Loop::" . $_[HEAP]->{'current_loop'} . " is installed...\n";
}
# set the flag
$_[HEAP]->{'test_failure'} = 0;
}
# Okay, create the wheel::run to handle this
$_[HEAP]->{'WHEEL'} = POE::Wheel::Run->new(
'Program' => $^X,
'ProgramArgs' => [ '-MPOE',
'-MPOE::Loop::' . $_[HEAP]->{'current_loop'},
'-e',
'1',
],
# Kill off existing FD's
'CloseOnCall' => 1,
# setup our data handlers
'StdoutEvent' => 'Got_STDOUT',
'StderrEvent' => 'Got_STDERR',
# the error handler
'ErrorEvent' => 'Got_ERROR',
'CloseEvent' => 'Got_CLOSED',
# set our filters
'StderrFilter' => POE::Filter::Line->new(),
'StdoutFilter' => POE::Filter::Line->new(),
);
if ( ! defined $_[HEAP]->{'WHEEL'} ) {
die '[LOOPSEARCH] Unable to create a new wheel!';
} else {
# smart CHLD handling
if ( $_[KERNEL]->can( "sig_child" ) ) {
$_[KERNEL]->sig_child( $_[HEAP]->{'WHEEL'}->PID => 'Got_CHLD' );
} else {
$_[KERNEL]->sig( 'CHLD', 'Got_CHLD' );
}
}
return;
}
# Got a CHLD event!
sub Got_CHLD : State {
$_[KERNEL]->sig_handled();
return;
}
# Handles child STDERR output
sub Got_STDERR : State {
my $input = $_[ARG0];
# since we got an error, must be a failure
$_[HEAP]->{'test_failure'} = 1;
return;
}
# Handles child STDOUT output
sub Got_STDOUT : State {
my $input = $_[ARG0];
return;
}
# Handles child error
sub Got_ERROR : State {
# Copied from POE::Wheel::Run manpage
my ( $operation, $errnum, $errstr ) = @_[ ARG0 .. ARG2 ];
# ignore exit 0 errors
if ( $errnum != 0 ) {
warn "Wheel::Run got an $operation error $errnum: $errstr\n";
}
return;
}
# Handles child DIE'ing
sub Got_CLOSED : State {
# Get rid of the wheel
undef $_[HEAP]->{'WHEEL'};
# Did we pass this test or not?
if ( ! $_[HEAP]->{'test_failure'} ) {
push( @{ $_[HEAP]->{'found_loops'} }, $_[HEAP]->{'current_loop'} );
}
# move on to the next loop
$_[KERNEL]->yield( 'find_loops' );
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::GetInstalledLoops - Automatically detects the installed POE loops
=head1 SYNOPSIS
die "Don't use this module directly. Please use POE::Devel::Benchmarker instead.";
=head1 ABSTRACT
This package implements the guts of searching for POE loops via fork/exec.
=head1 EXPORT
Automatically exports the getPOEloops() sub
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2010 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/SubProcess.pm b/lib/POE/Devel/Benchmarker/SubProcess.pm
index b26c909..a795a92 100644
--- a/lib/POE/Devel/Benchmarker/SubProcess.pm
+++ b/lib/POE/Devel/Benchmarker/SubProcess.pm
@@ -1,749 +1,750 @@
# Declare our package
package POE::Devel::Benchmarker::SubProcess;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.06';
# set our compile-time stuff
BEGIN {
# should we enable assertions?
if ( defined $ARGV[1] and $ARGV[1] ) {
## no critic
eval "sub POE::Kernel::ASSERT_DEFAULT () { 1 }";
eval "sub POE::Session::ASSERT_STATES () { 1 }";
## use critic
}
# Compile a list of modules to hide
my $hide = '';
if ( defined $ARGV[0] ) {
if ( $ARGV[0] ne 'XSPoll' ) {
$hide .= ' POE/XS/Loop/Poll.pm';
}
if ( $ARGV[0] ne 'XSEPoll' ) {
$hide .= ' POE/XS/Loop/EPoll.pm';
}
}
# should we "hide" XS::Queue::Array?
if ( defined $ARGV[3] and $ARGV[3] ) {
$hide .= ' POE/XS/Queue/Array.pm';
}
# actually hide the modules!
{
## no critic
eval "use Devel::Hide qw( $hide )";
## use critic
}
}
# Import Time::HiRes's time()
use Time::HiRes qw( time );
# load POE
use POE;
use POE::Session;
use POE::Wheel::SocketFactory;
use POE::Wheel::ReadWrite;
use POE::Filter::Line;
use POE::Driver::SysRW;
# autoflush, please!
use IO::Handle;
STDOUT->autoflush( 1 );
# import some stuff
use Socket qw( INADDR_ANY sockaddr_in );
# we need to compare versions
use version;
# load our utility stuff
use POE::Devel::Benchmarker::Utils qw( loop2realversion poeloop2load currentMetrics );
# init our global variables ( bad, haha )
my( $eventloop, $asserts, $lite_tests, $pocosession );
# setup our metrics and their data
my %metrics = map { $_ => undef } @{ currentMetrics() };
# the main routine which will load everything + start
sub benchmark {
# process the eventloop
process_eventloop();
# process the assertions
process_assertions();
# process the test mode
process_testmode();
# process the XS::Queue hiding
process_xsqueue();
# actually import POE!
process_POE();
# actually run the benchmarks!
run_benchmarks();
# all done!
return;
}
sub process_eventloop {
# Get the desired mode
$eventloop = $ARGV[0];
# print out the loop info
if ( ! defined $eventloop ) {
die "Please supply an event loop!";
} else {
my $loop = poeloop2load( $eventloop );
if ( ! defined $loop ) {
$loop = $eventloop;
}
my $v = loop2realversion( $eventloop );
if ( ! defined $v ) {
$v = 'UNKNOWN';
}
print "Using master loop: $loop-$v\n";
}
return;
}
sub process_assertions {
# Get the desired assert mode
$asserts = $ARGV[1];
if ( defined $asserts and $asserts ) {
print "Using FULL Assertions!\n";
} else {
print "Using NO Assertions!\n";
}
return;
}
sub process_testmode {
# get the desired test mode
$lite_tests = $ARGV[2];
# setup most of the metrics
$metrics{'startups'} = 10;
# event tests
foreach my $s ( qw( posts dispatches calls single_posts ) ) {
$metrics{ $s } = 10_000;
}
# session tests
foreach my $s ( qw( session_creates session_destroys ) ) {
$metrics{ $s } = 500;
}
# alarm tests
foreach my $s ( qw( alarms alarm_adds alarm_clears ) ) {
$metrics{ $s } = 10_000;
}
# select tests
foreach my $s ( qw( select_read_STDIN select_write_STDIN select_read_MYFH select_write_MYFH ) ) {
$metrics{ $s } = 10_000;
}
# socket tests
foreach my $s ( qw( socket_connects socket_stream ) ) {
$metrics{ $s } = 1_000;
}
if ( defined $lite_tests and $lite_tests ) {
print "Using the LITE tests\n";
} else {
print "Using the HEAVY tests\n";
# we simply multiply each metric by 10x
foreach my $s ( @{ currentMetrics() } ) {
$metrics{ $s } = $metrics{ $s } * 10;
}
}
return;
}
sub process_xsqueue {
# should we "hide" XS::Queue::Array?
if ( defined $ARGV[3] and $ARGV[3] ) {
print "DISABLING POE::XS::Queue::Array\n";
} else {
print "LETTING POE find POE::XS::Queue::Array\n";
}
return;
}
sub process_POE {
# Print the POE info
print "Using POE-" . $POE::VERSION . "\n";
# Actually print what loop POE is using
foreach my $m ( keys %INC ) {
if ( $m =~ /^POE\/(?:Loop|XS|Queue)/ ) {
# try to be smart and get version?
my $module = $m;
$module =~ s|/|::|g;
$module =~ s/\.pm$//g;
print "POE is using: $module ";
if ( defined $module->VERSION ) {
print "v" . $module->VERSION . "\n";
} else {
print "vUNKNOWN\n";
}
}
}
return;
}
sub run_benchmarks {
# dump some misc info
dump_perlinfo();
dump_sysinfo();
# run the startup test before we actually run POE
bench_startup();
# load the POE session + do the tests there
bench_poe();
# okay, dump our memory usage
dump_pidinfo();
# all done!
return;
}
sub bench_startup {
# Add the eventloop?
my $looploader = poeloop2load( $eventloop );
my @start_times = times();
my $start = time();
for (my $i = 0; $i < $metrics{'startups'}; $i++) {
- # We do not care about assert/xsqueue for startups, so we don't include them here...
+ # We do not care about xsqueue for startups, so we don't include them here...
+ # TODO fix the "strange" loop loader - i.e. Kqueue
# finally, fire it up!
CORE::system(
$^X,
'-Ipoedists/POE-' . $POE::VERSION,
'-Ipoedists/POE-' . $POE::VERSION . '/lib',
( defined $looploader ? "-M$looploader" : () ),
'-e',
$asserts ? 'sub POE::Kernel::ASSERT_DEFAULT () { 1 } sub POE::Session::ASSERT_STATES () { 1 } use POE; 1;' : 'use POE; 1;',
);
}
my @end_times = times();
my $elapsed = time() - $start;
printf( "\n\n% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'startups'}, 'startups', $elapsed, $metrics{'startups'}/$elapsed );
print "startups times: @start_times @end_times\n";
return;
}
sub bench_poe {
# figure out POE::Session->create or POE::Session->new or what?
$pocosession = POE::Session->can( 'create' );
if ( defined $pocosession ) {
$pocosession = 'create';
} else {
$pocosession = POE::Session->can( 'spawn' );
if ( defined $pocosession ) {
$pocosession = 'spawn';
} else {
$pocosession = 'new';
}
}
# create the master sesssion + run POE!
POE::Session->$pocosession(
'inline_states' => {
# basic POE states
'_start' => \&poe__start,
'_default' => \&poe__default,
'_stop' => \&poe__stop,
'null' => \&poe_null,
# our test states
'posts' => \&poe_posts,
'posts_start' => \&poe_posts_start,
'posts_end' => \&poe_posts_end,
'alarms' => \&poe_alarms,
'manyalarms' => \&poe_manyalarms,
'sessions' => \&poe_sessions,
'sessions_end' => \&poe_sessions_end,
'stdin_read' => \&poe_stdin_read,
'stdin_write' => \&poe_stdin_write,
'myfh_read' => \&poe_myfh_read,
'myfh_write' => \&poe_myfh_write,
'calls' => \&poe_calls,
'eventsquirt' => \&poe_eventsquirt,
'eventsquirt_done' => \&poe_eventsquirt_done,
'socketfactory' => \&poe_socketfactory,
'socketfactory_start' => \&poe_socketfactory_start,
'socketfactory_connects' => \&poe_socketfactory_connects,
'socketfactory_stream' => \&poe_socketfactory_stream,
'socketfactory_cleanup' => \&poe_socketfactory_cleanup,
# misc states for test stuff
'server_sf_connect' => \&poe_server_sf_connect,
'server_sf_failure' => \&poe_server_sf_failure,
'server_rw_input' => \&poe_server_rw_input,
'server_rw_error' => \&poe_server_rw_error,
'client_sf_connect' => \&poe_client_sf_connect,
'client_sf_failure' => \&poe_client_sf_failure,
'client_rw_input' => \&poe_client_rw_input,
'client_rw_error' => \&poe_client_rw_error,
},
);
# start the kernel!
POE::Kernel->run();
return;
}
# inits our session
sub poe__start {
# fire off the first test!
$_[KERNEL]->yield( 'posts' );
return;
}
sub poe__stop {
}
sub poe__default {
return 0;
}
# a state that does nothing
sub poe_null {
return 1;
}
# How many posts per second? Post a bunch of events, keeping track of the time it takes.
sub poe_posts {
$_[KERNEL]->yield( 'posts_start' );
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $metrics{'posts'}; $i++) {
$_[KERNEL]->yield( 'null' );
}
my @end_times = times();
my $elapsed = time() - $start;
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'posts'}, 'posts', $elapsed, $metrics{'posts'}/$elapsed );
print "posts times: @start_times @end_times\n";
$_[KERNEL]->yield( 'posts_end' );
return;
}
sub poe_posts_start {
$_[HEAP]->{start} = time();
$_[HEAP]->{starttimes} = [ times() ];
return;
}
sub poe_posts_end {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'dispatches'}, 'dispatches', $elapsed, $metrics{'dispatches'}/$elapsed );
print "dispatches times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
$_[KERNEL]->yield( 'alarms' );
return;
}
# How many alarms per second? Set a bunch of alarms and find out.
sub poe_alarms {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $metrics{'alarms'}; $i++) {
$_[KERNEL]->alarm( whee => rand(1_000_000) );
}
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'alarms'}, 'alarms', $elapsed, $metrics{'alarms'}/$elapsed );
print "alarms times: @start_times @end_times\n";
$_[KERNEL]->alarm( 'whee' => undef );
$_[KERNEL]->yield( 'manyalarms' );
return;
}
# How many repetitive alarms per second? Set a bunch of
# additional alarms and find out. Also see how quickly they can
# be cleared.
sub poe_manyalarms {
# can this POE::Kernel support this?
if ( $_[KERNEL]->can( 'alarm_add' ) ) {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $metrics{'alarm_adds'}; $i++) {
$_[KERNEL]->alarm_add( whee => rand(1_000_000) );
}
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'alarm_adds'}, 'alarm_adds', $elapsed, $metrics{'alarm_adds'}/$elapsed );
print "alarm_adds times: @start_times @end_times\n";
$start = time();
@start_times = times();
$_[KERNEL]->alarm( whee => undef );
$elapsed = time() - $start;
@end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'alarm_adds'}, 'alarm_clears', $elapsed, $metrics{'alarm_adds'}/$elapsed );
print "alarm_clears times: @start_times @end_times\n";
} else {
print "SKIPPING br0ken alarm_adds because alarm_add() NOT SUPPORTED on this version of POE\n";
print "SKIPPING br0ken alarm_clears because alarm_add() NOT SUPPORTED on this version of POE\n";
}
$_[KERNEL]->yield( 'sessions' );
return;
}
# How many sessions can we create and destroy per second?
# Create a bunch of sessions, and track that time. Let them
# self-destruct, and track that as well.
sub poe_sessions {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $metrics{'session_creates'}; $i++) {
POE::Session->$pocosession( 'inline_states' => { _start => sub {}, _stop => sub {}, _default => sub { return 0 } } );
}
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'session_creates'}, 'session_creates', $elapsed, $metrics{'session_creates'}/$elapsed );
print "session_creates times: @start_times @end_times\n";
$_[KERNEL]->yield( 'sessions_end' );
$_[HEAP]->{start} = time();
$_[HEAP]->{starttimes} = [ times() ];
return;
}
sub poe_sessions_end {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'session_creates'}, 'session_destroys', $elapsed, $metrics{'session_creates'}/$elapsed );
print "session_destroys times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
$_[KERNEL]->yield( 'stdin_read' );
return;
}
# How many times can we select/unselect READ a from STDIN filehandle per second?
sub poe_stdin_read {
# stupid, but we have to skip those tests
if ( $eventloop eq 'Tk' or $eventloop eq 'Prima' ) {
print "SKIPPING br0ken select_read_STDIN because eventloop doesn't work: $eventloop\n";
print "SKIPPING br0ken select_write_STDIN because eventloop doesn't work: $eventloop\n";
$_[KERNEL]->yield( 'myfh_read' );
return;
}
my $start = time();
my @start_times = times();
eval {
for (my $i = 0; $i < $metrics{'select_read_STDIN'}; $i++) {
$_[KERNEL]->select_read( *STDIN, 'whee' );
$_[KERNEL]->select_read( *STDIN );
}
};
if ( $@ ) {
print "SKIPPING br0ken select_read_STDIN because FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'select_read_STDIN'}, 'select_read_STDIN', $elapsed, $metrics{'select_read_STDIN'}/$elapsed );
print "select_read_STDIN times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'stdin_write' );
return;
}
# How many times can we select/unselect WRITE a from STDIN filehandle per second?
sub poe_stdin_write {
my $start = time();
my @start_times = times();
eval {
for (my $i = 0; $i < $metrics{'select_write_STDIN'}; $i++) {
$_[KERNEL]->select_write( *STDIN, 'whee' );
$_[KERNEL]->select_write( *STDIN );
}
};
if ( $@ ) {
print "SKIPPING br0ken select_write_STDIN because FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'select_write_STDIN'}, 'select_write_STDIN', $elapsed, $metrics{'select_write_STDIN'}/$elapsed );
print "select_write_STDIN times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'myfh_read' );
return;
}
# How many times can we select/unselect READ a real filehandle?
sub poe_myfh_read {
# stupid, but we have to skip those tests
if ( $eventloop eq 'Event_Lib' or $eventloop eq 'Tk' or $eventloop eq 'Prima' ) {
print "SKIPPING br0ken select_read_MYFH because eventloop doesn't work: $eventloop\n";
print "SKIPPING br0ken select_write_MYFH because eventloop doesn't work: $eventloop\n";
$_[KERNEL]->yield( 'calls' );
return;
}
my $start = time();
my @start_times = times();
eval {
open( my $fh, '+>', 'poebench' ) or die $!;
for (my $i = 0; $i < $metrics{'select_read_MYFH'}; $i++) {
$_[KERNEL]->select_read( $fh, 'whee' );
$_[KERNEL]->select_read( $fh );
}
close( $fh ) or die $!;
unlink( 'poebench' ) or die $!;
};
if ( $@ ) {
print "SKIPPING br0ken select_read_MYFH because FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'select_read_MYFH'}, 'select_read_MYFH', $elapsed, $metrics{'select_read_MYFH'}/$elapsed );
print "select_read_MYFH times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'myfh_write' );
return;
}
# How many times can we select/unselect WRITE a real filehandle?
sub poe_myfh_write {
my $start = time();
my @start_times = times();
eval {
open( my $fh, '+>', 'poebench' ) or die $!;
for (my $i = 0; $i < $metrics{'select_write_MYFH'}; $i++) {
$_[KERNEL]->select_write( $fh, 'whee' );
$_[KERNEL]->select_write( $fh );
}
close( $fh ) or die $!;
unlink( 'poebench' ) or die $!;
};
if ( $@ ) {
print "SKIPPING br0ken select_write_MYFH because FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'select_write_MYFH'}, 'select_write_MYFH', $elapsed, $metrics{'select_write_MYFH'}/$elapsed );
print "select_write_MYFH times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'calls' );
return;
}
# How many times can we call a state?
sub poe_calls {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $metrics{'calls'}; $i++) {
$_[KERNEL]->call( $_[SESSION], 'null' );
}
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'calls'}, 'calls', $elapsed, $metrics{'calls'}/$elapsed );
print "calls times: @start_times @end_times\n";
$_[KERNEL]->yield( 'eventsquirt' );
return;
}
# How many events can we squirt through POE, one at a time?
sub poe_eventsquirt {
$_[HEAP]->{start} = time();
$_[HEAP]->{starttimes} = [ times() ];
$_[HEAP]->{yield_count} = $metrics{'single_posts'};
$_[KERNEL]->yield( 'eventsquirt_done' );
return;
}
sub poe_eventsquirt_done {
if (--$_[HEAP]->{yield_count}) {
$_[KERNEL]->yield( 'eventsquirt_done' );
} else {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'single_posts'}, 'single_posts', $elapsed, $metrics{'single_posts'}/$elapsed );
print "single_posts times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
$_[KERNEL]->yield( 'socketfactory' );
}
return;
}
# tests socketfactory interactions
sub poe_socketfactory {
# POE transitioned between Event to State on 0.19 for SocketFactory/ReadWrite
# 0.20+ throws deprecation error :(
$_[HEAP]->{'POE_naming'} = 'Event';
if ( version->new( $POE::VERSION ) < version->new( '0.20' ) ) {
$_[HEAP]->{'POE_naming'} = 'State';
}
# create the socketfactory server
$_[HEAP]->{'SF'} = POE::Wheel::SocketFactory->new(
'Port' => INADDR_ANY,
'Address' => 'localhost',
'Reuse' => 'yes',
'Success' . $_[HEAP]->{'POE_naming'} => 'server_sf_connect',
'Failure' . $_[HEAP]->{'POE_naming'} => 'server_sf_failure',
);
# be evil, and get the port for the client to connect to
( $_[HEAP]->{'SF_port'}, undef ) = sockaddr_in( getsockname( $_[HEAP]->{'SF'}->[ POE::Wheel::SocketFactory::MY_SOCKET_HANDLE() ] ) );
# start the connect tests
$_[HEAP]->{'SF_counter'} = $metrics{'socket_connects'};
$_[HEAP]->{'SF_mode'} = 'socket_connects';
$_[HEAP]->{'start'} = time();
$_[HEAP]->{'starttimes'} = [ times() ];
$_[KERNEL]->yield( 'socketfactory_connects' );
return;
}
# handles SocketFactory connection
sub poe_server_sf_connect {
# what test mode?
if ( $_[HEAP]->{'SF_mode'} eq 'socket_connects' ) {
# simply discard this socket
} elsif ( $_[HEAP]->{'SF_mode'} eq 'socket_stream' ) {
# convert it to ReadWrite
my $wheel = POE::Wheel::ReadWrite->new(
'Handle' => $_[ARG0],
'Filter' => POE::Filter::Line->new,
'Driver' => POE::Driver::SysRW->new,
'Input' . $_[HEAP]->{'POE_naming'} => 'server_rw_input',
'Error' . $_[HEAP]->{'POE_naming'} => 'server_rw_error',
);
# save it in our heap
$_[HEAP]->{'RW'}->{ $wheel->ID } = $wheel;
} else {
die "unknown test mode";
}
return;
}
# handles SocketFactory errors
sub poe_server_sf_failure {
# ARGH, we couldnt create listening socket
print "SKIPPING br0ken socket_connects because we were unable to setup listening socket\n";
print "SKIPPING br0ken socket_stream because we were unable to setup listening socket\n";
$_[KERNEL]->yield( 'socketfactory_cleanup' );
return;
}
# handles ReadWrite input
sub poe_server_rw_input {
# what test mode?
if ( $_[HEAP]->{'SF_mode'} eq 'socket_connects' ) {
# simply discard this data
} elsif ( $_[HEAP]->{'SF_mode'} eq 'socket_stream' ) {
# send it back to the client!
$_[HEAP]->{'RW'}->{ $_[ARG1] }->put( $_[ARG0] );
} else {
die "unknown test mode";
}
return;
}
# handles ReadWrite disconnects
sub poe_server_rw_error {
# simply get rid of the wheel
if ( exists $_[HEAP]->{'RW'}->{ $_[ARG3] } ) {
# shutdown everything, so we don't have any lingering sockets
eval {
$_[HEAP]->{'RW'}->{ $_[ARG3] }->shutdown_input;
$_[HEAP]->{'RW'}->{ $_[ARG3] }->shutdown_output;
};
delete $_[HEAP]->{'RW'}->{ $_[ARG3] };
}
return;
}
# starts the client connect tests
sub poe_socketfactory_connects {
if (--$_[HEAP]->{'SF_counter'}) {
# open a new client connection!
$_[HEAP]->{'client_SF'} = POE::Wheel::SocketFactory->new(
'RemoteAddress' => 'localhost',
'RemotePort' => $_[HEAP]->{'SF_port'},
'Success' . $_[HEAP]->{'POE_naming'} => 'client_sf_connect',
'Failure' . $_[HEAP]->{'POE_naming'} => 'client_sf_failure',
);
} else {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'socket_connects'}, 'socket_connects', $elapsed, $metrics{'socket_connects'}/$elapsed );
print "socket_connects times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
$_[KERNEL]->yield( 'socketfactory_stream' );
}
return;
}
# starts the client stream tests
sub poe_socketfactory_stream {
# set the proper test mode
$_[HEAP]->{'SF_mode'} = 'socket_stream';
# open a new client connection!
|
apocalypse/perl-poe-benchmarker
|
172ee21850637ccac38917a9bc063f9c6ba704e0
|
fixes to get Wx/Kqueue working
|
diff --git a/Changes b/Changes
index 5dae389..ad0964c 100644
--- a/Changes
+++ b/Changes
@@ -1,48 +1,50 @@
Revision history for Perl extension POE::Devel::Benchmarker
* 0.06
POD tweaks and typo fixes
Cleanup Build.PL and remove a lot of tests in favor of Test::Apocalypse
Fixed a bug where the Benchmarker wouldn't recognize old test runs and skip them
Add File::Spec so we are more portable, yay!
+ POE::Loop::Event wasn't benchmarked - added to the list
+ Wx/POE::Loop::Wx works now - added to the list
* 0.05
Minor tweaks on the YAML output ( nothing new, hah! )
Added the socket tests, yay! ( still need more work so we test various methods of socket creation )
Some more tweaks to the BasicStatistics plugin for prettier graphs
Lots of refactoring to get things cleaned up :)
Added test versioning, so we make sure we're processing the right version :)
added examples/test.pl to satisfy kwalitee requirements, ha!
* 0.04
Started work on the image generator ( Imager ) and added the BasicStatistics plugin, yay!
Added automatic "pick up where we left off" to the benchmarker
Added the freshstart option to benchmark()
Tweaked the GetPOEdists sub so it will work in the "work directory" and in the poedists dir
Tweaked the YAML output so it's smaller
Removed POE::Loop::Wx from autoprobing ( I'm unable to get it to work )
Removed POE::Loop::Kqueue from autoprobing ( I'm unable to get it to work )
Hardcoded the Benchmarker routines to skip POE < 0.13 ( I'm unable to get it to work )
* 0.03
Added the loop option to benchmark(), thanks dngor!
Added the poe option to benchmark(), thanks dngor!
Added the noxsqueue option to benchmark()
Added the noasserts option to benchmark()
Automatically enable noxsqueue option if we cannot load POE::XS::Queue::Array, saving time
Bump Test::More version requirement because some people reported failures with note()
Fixed bug in SubProcess where it crashed on old POEs that didn't load IO::Handle
More documentation additions/tweaks
* 0.02
Added the Analyzer module ( and dump YAML files, yay! )
A lot of minor changes+tweaks to get a better dump format
* 0.01
initial release
diff --git a/lib/POE/Devel/Benchmarker.pm b/lib/POE/Devel/Benchmarker.pm
index 00f3b44..f86dafa 100644
--- a/lib/POE/Devel/Benchmarker.pm
+++ b/lib/POE/Devel/Benchmarker.pm
@@ -1,1162 +1,1165 @@
# Declare our package
package POE::Devel::Benchmarker;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.06';
# auto-export the only sub we have
use base qw( Exporter );
our @EXPORT = qw( benchmark );
# load needed modules
use Time::HiRes qw( time );
use version;
use YAML::Tiny qw( Dump );
use File::Spec;
# Import what we need from the POE namespace
use POE qw( Session Filter::Line Wheel::Run );
use base 'POE::Session::AttributeBased';
# Load our stuff
use POE::Devel::Benchmarker::GetInstalledLoops;
use POE::Devel::Benchmarker::Utils qw( poeloop2load knownloops generateTestfile beautify_times currentTestVersion );
# Actually run the tests!
sub benchmark {
my $options = shift;
# set default options
my $lite_tests = 1;
my $quiet_mode = 0;
my $forceloops = undef; # default to autoprobe all
my $forcepoe = undef; # default to all found POE versions in poedists/
my $forcenoxsqueue = 0; # default to try and load it
my $forcenoasserts = 0; # default is to run it
my $freshstart = 0; # always resume where we left off
# process our options
if ( defined $options and ref $options and ref( $options ) eq 'HASH' ) {
# process YES for freshstart
if ( exists $options->{'freshstart'} ) {
if ( $options->{'freshstart'} ) {
$freshstart = 1;
}
delete $options->{'freshstart'};
}
# process NO for XS::Queue::Array
if ( exists $options->{'noxsqueue'} ) {
if ( $options->{'noxsqueue'} ) {
$forcenoxsqueue = 1;
}
delete $options->{'noxsqueue'};
}
# process NO for ASSERT
if ( exists $options->{'noasserts'} ) {
if ( $options->{'noasserts'} ) {
$forcenoasserts = 1;
}
delete $options->{'noasserts'};
}
# process LITE tests
if ( exists $options->{'litetests'} ) {
if ( $options->{'litetests'} ) {
$lite_tests = 1;
} else {
$lite_tests = 0;
}
delete $options->{'litetests'};
}
# process quiet mode
if ( exists $options->{'quiet'} ) {
if ( $options->{'quiet'} ) {
$quiet_mode = 1;
} else {
$quiet_mode = 0;
}
delete $options->{'quiet'};
}
# process forceloops
if ( exists $options->{'loop'} and defined $options->{'loop'} ) {
if ( ! ref $options->{'loop'} ) {
# split it via CSV
$forceloops = [ split( /,/, $options->{'loop'} ) ];
foreach ( @$forceloops ) {
$_ =~ s/^\s+//; $_ =~ s/\s+$//;
}
} else {
# treat it as array
$forceloops = $options->{'loop'};
}
# check for !loop modules
my @noloops;
foreach my $l ( @$forceloops ) {
if ( $l =~ /^\!/ ) {
push( @noloops, substr( $l, 1 ) );
}
}
if ( scalar @noloops ) {
# replace the forceloops with ALL known, then subtract noloops from it
my %bad;
@bad{@noloops} = () x @noloops;
@$forceloops = grep { !exists $bad{$_} } @{ knownloops() };
}
delete $options->{'loop'};
}
# process the poe versions
if ( exists $options->{'poe'} and defined $options->{'poe'} ) {
if ( ! ref $options->{'poe'} ) {
# split it via CSV
$forcepoe = [ split( /,/, $options->{'poe'} ) ];
foreach ( @$forcepoe ) {
$_ =~ s/^\s+//; $_ =~ s/\s+$//;
}
} else {
# treat it as array
$forcepoe = $options->{'poe'};
}
delete $options->{'poe'};
}
# unknown options!
if ( scalar keys %$options ) {
warn "[BENCHMARKER] Unknown options present in arguments: " . keys %$options;
}
}
# do some sanity checks
if ( ! -d 'poedists' ) {
die "The 'poedists' directory is not found in the working directory!";
}
if ( ! -d 'results' ) {
die "The 'results' directory is not found in the working directory!";
}
if ( ! $quiet_mode ) {
print "[BENCHMARKER] Starting up...\n";
}
# Create our session
POE::Session->create(
__PACKAGE__->inline_states(),
'heap' => {
# misc stuff
'quiet_mode' => $quiet_mode,
# override our testing behavior
'lite_tests' => $lite_tests,
'forceloops' => $forceloops,
'forcepoe' => $forcepoe,
'forcenoxsqueue' => $forcenoxsqueue,
'forcenoasserts' => $forcenoasserts,
'freshstart' => $freshstart,
},
);
# Fire 'er up!
POE::Kernel->run();
return;
}
# Starts up our session
sub _start : State {
# okay, get all the dists we can!
my @versions;
if ( opendir( DISTS, 'poedists' ) ) {
foreach my $d ( readdir( DISTS ) ) {
if ( $d =~ /^POE\-(.+)$/ and $d !~ /\.tar\.gz$/ ) {
# FIXME skip POE < 0.13 because I can't get it to work
my $ver = version->new( $1 );
if ( $ver > version->new( '0.12' ) ) {
push( @versions, $ver );
}
}
}
closedir( DISTS ) or die $!;
} else {
print "[BENCHMARKER] Unable to open 'poedists' for reading: $!\n";
return;
}
# should we munge the versions list?
if ( defined $_[HEAP]->{'forcepoe'} ) {
# check for !poe versions
my @nopoe;
foreach my $p ( @{ $_[HEAP]->{'forcepoe'} } ) {
if ( $p =~ /^\!/ ) {
push( @nopoe, substr( $p, 1 ) );
}
}
if ( scalar @nopoe ) {
# remove the nopoe versions from the found
my %bad;
@bad{@nopoe} = () x @nopoe;
@versions = grep { !exists $bad{$_->stringify} } @versions;
} else {
# make sure the @versions contains only what we specified
my %good;
@good{ @{ $_[HEAP]->{'forcepoe'} } } = () x @{ $_[HEAP]->{'forcepoe'} };
@versions = grep { exists $good{$_->stringify} } @versions;
}
}
# sanity
if ( ! scalar @versions ) {
print "[BENCHMARKER] Unable to find any POE version in the 'poedists' directory!\n";
return;
}
# set our alias
$_[KERNEL]->alias_set( 'Benchmarker' );
# sanely handle some signals
$_[KERNEL]->sig( 'INT', 'handle_kill' );
$_[KERNEL]->sig( 'TERM', 'handle_kill' );
# okay, go through all the dists in version order ( from newest to oldest )
@versions = sort { $b <=> $a } @versions;
# Store the versions in our heap
$_[HEAP]->{'VERSIONS'} = \@versions;
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Detected available POE versions -> " . join( " ", @versions ) . "\n";
}
# First of all, we need to find out what loop libraries are installed
getPOEloops( $_[HEAP]->{'quiet_mode'}, $_[HEAP]->{'forceloops'} );
return;
}
sub _stop : State {
# tell the wheel to kill itself
if ( defined $_[HEAP]->{'WHEEL'} ) {
$_[HEAP]->{'WHEEL'}->kill( 9 );
undef $_[HEAP]->{'WHEEL'};
}
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "\n[BENCHMARKER] Shutting down...\n";
}
return;
}
# misc POE handlers
sub _child : State {
return;
}
sub handle_kill : State {
return;
}
# we received list of loops from GetInstalledLoops
sub found_loops : State {
$_[HEAP]->{'installed_loops'} = [ sort { $a cmp $b } @{ $_[ARG0] } ];
# sanity check
if ( scalar @{ $_[HEAP]->{'installed_loops'} } == 0 ) {
print "[BENCHMARKER] Detected no available POE::Loop, check your configuration?!?\n";
return;
}
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Detected available POE::Loops -> " . join( " ", @{ $_[HEAP]->{'installed_loops'} } ) . "\n";
}
# Okay, do we have XS::Queue installed?
if ( ! $_[HEAP]->{'forcenoxsqueue'} ) {
eval { require POE::XS::Queue::Array };
if ( $@ ) {
$_[HEAP]->{'forcenoxsqueue'} = 1;
}
}
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Starting the benchmarks!" .
( $_[HEAP]->{'forcenoxsqueue'} ? ' Skipping XS::Queue Tests!' : '' ) .
( $_[HEAP]->{'forcenoasserts'} ? ' Skipping ASSERT Tests!' : '' ) .
"\n";
}
# start the benchmark!
$_[KERNEL]->yield( 'run_benchmark' );
return;
}
# Runs one benchmark
sub run_benchmark : State {
# Grab the version from the top of the array
$_[HEAP]->{'current_version'} = shift @{ $_[HEAP]->{'VERSIONS'} };
# did we run out of versions?
if ( ! defined $_[HEAP]->{'current_version'} ) {
# We're done, let POE die...
$_[KERNEL]->alias_remove( 'Benchmarker' );
} else {
$_[HEAP]->{'loops'} = [ @{ $_[HEAP]->{'installed_loops'} } ];
# okay, fire off the first loop
$_[KERNEL]->yield( 'bench_loop' );
}
return;
}
# runs one loop
sub bench_loop : State {
# select our current loop
$_[HEAP]->{'current_loop'} = shift @{ $_[HEAP]->{'loops'} };
# are we done with all loops?
if ( ! defined $_[HEAP]->{'current_loop'} ) {
# yay, go back to the main handler
$_[KERNEL]->yield( 'run_benchmark' );
} else {
# Start the assert test
if ( $_[HEAP]->{'forcenoasserts'} ) {
$_[HEAP]->{'assertions'} = [ qw( 0 ) ];
} else {
$_[HEAP]->{'assertions'} = [ qw( 0 1 ) ];
}
$_[KERNEL]->yield( 'bench_asserts' );
}
return;
}
# runs an assertion
sub bench_asserts : State {
# select our current assert state
$_[HEAP]->{'current_assertions'} = shift @{ $_[HEAP]->{'assertions'} };
# are we done?
if ( ! defined $_[HEAP]->{'current_assertions'} ) {
# yay, go back to the loop handler
$_[KERNEL]->yield( 'bench_loop' );
} else {
# Start the xsqueue test
if ( $_[HEAP]->{'forcenoxsqueue'} ) {
$_[HEAP]->{'noxsqueue'} = [ qw( 1 ) ];
} else {
$_[HEAP]->{'noxsqueue'} = [ qw( 0 1 ) ];
}
$_[KERNEL]->yield( 'bench_xsqueue' );
}
return;
}
# runs test with or without xsqueue
sub bench_xsqueue : State {
# select our current noxsqueue state
$_[HEAP]->{'current_noxsqueue'} = shift @{ $_[HEAP]->{'noxsqueue'} };
# are we done?
if ( ! defined $_[HEAP]->{'current_noxsqueue'} ) {
# yay, go back to the assert handler
$_[KERNEL]->yield( 'bench_asserts' );
} else {
# do some careful analysis
$_[KERNEL]->yield( 'bench_checkprevioustest' );
}
return;
}
# Checks to see if this test was run in the past
sub bench_checkprevioustest : State {
# okay, do we need to check and see if we already did this test?
if ( ! $_[HEAP]->{'freshstart'} ) {
# determine the file used
my $file = File::Spec->catfile( 'results', generateTestfile( $_[HEAP] ) . '.yml' );
# does it exist?
if ( -e $file and -f _ and -s _ ) {
# okay, sanity check it
my $yaml = YAML::Tiny->read( $file );
if ( defined $yaml ) {
# inrospect it!
my $isvalid = 0;
eval {
# simple sanity check: the "x_bench" param is at the end of the YML, so if it loads fine we know it's there
if ( exists $yaml->[0]->{'x_bench'} ) {
# version must at least match us
$isvalid = ( $yaml->[0]->{'x_bench'} eq currentTestVersion() ? 1 : 0 );
} else {
$isvalid = undef;
}
};
if ( $isvalid ) {
# yay, this test is A-OK!
- if ( ! $_[HEAP]->{'quiet_mode'} ) {
- print " SKIPPING ( found old test run )";
- }
+ $_[HEAP]->{'SKIPPED_TESTS'}++;
$_[KERNEL]->yield( 'bench_xsqueue' );
return;
} else {
# was it truncated?
if ( ! defined $isvalid ) {
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "\n[BENCHMARKER] YAML file($file) from previous test was corrupt!\n";
}
}
}
} else {
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "\n[BENCHMARKER] Unable to load YAML file($file) from previous test run: " . YAML::Tiny->errstr . "\n";
}
}
}
}
# could not find previous file or FRESHSTART, proceed normally
$_[KERNEL]->yield( 'create_subprocess' );
return;
}
# actually runs the subprocess
sub create_subprocess : State {
+ if ( exists $_[HEAP]->{'SKIPPED_TESTS'} ) {
+ print "\n Skipping $_[HEAP]->{'SKIPPED_TESTS'} old test runs...";
+ delete $_[HEAP]->{'SKIPPED_TESTS'};
+ }
+
# Okay, start testing this specific combo!
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "\n Testing " . generateTestfile( $_[HEAP] ) . "...";
}
# save the starttime
$_[HEAP]->{'current_starttime'} = time();
$_[HEAP]->{'current_starttimes'} = [ times() ];
# Okay, create the wheel::run to handle this
my $looploader = poeloop2load( $_[HEAP]->{'current_loop'} );
$_[HEAP]->{'WHEEL'} = POE::Wheel::Run->new(
'Program' => $^X,
'ProgramArgs' => [ '-Ipoedists/POE-' . $_[HEAP]->{'current_version'},
'-Ipoedists/POE-' . $_[HEAP]->{'current_version'} . '/lib',
( defined $looploader ? "-M$looploader" : () ),
'-MPOE::Devel::Benchmarker::SubProcess',
'-e',
'POE::Devel::Benchmarker::SubProcess::benchmark',
$_[HEAP]->{'current_loop'},
$_[HEAP]->{'current_assertions'},
$_[HEAP]->{'lite_tests'},
$_[HEAP]->{'current_noxsqueue'},
],
# Kill off existing FD's
'CloseOnCall' => 1,
# setup our data handlers
'StdoutEvent' => 'Got_STDOUT',
'StderrEvent' => 'Got_STDERR',
# the error handler
'ErrorEvent' => 'Got_ERROR',
'CloseEvent' => 'Got_CLOSED',
# set our filters
'StderrFilter' => POE::Filter::Line->new(),
'StdoutFilter' => POE::Filter::Line->new(),
);
if ( ! defined $_[HEAP]->{'WHEEL'} ) {
die 'Unable to create a new wheel!';
} else {
# smart CHLD handling
if ( $_[KERNEL]->can( "sig_child" ) ) {
$_[KERNEL]->sig_child( $_[HEAP]->{'WHEEL'}->PID => 'Got_CHLD' );
} else {
$_[KERNEL]->sig( 'CHLD', 'Got_CHLD' );
}
}
# setup our data we received from the subprocess
$_[HEAP]->{'current_data'} = '';
# Okay, we timeout this test after some time for sanity
$_[HEAP]->{'test_timedout'} = 0;
if ( $_[HEAP]->{'lite_tests'} ) {
# 5min timeout is 5x my average runs on a 1.2ghz core2duo so it should be good enough
$_[HEAP]->{'TIMER'} = $_[KERNEL]->delay_set( 'test_timedout' => 60 * 5 );
} else {
# 30min timeout is 2x my average runs on a 1.2ghz core2duo so it should be good enough
$_[HEAP]->{'TIMER'} = $_[KERNEL]->delay_set( 'test_timedout' => 60 * 30 );
}
return;
}
# Got a CHLD event!
sub Got_CHLD : State {
$_[KERNEL]->sig_handled();
return;
}
# Handles child STDERR output
sub Got_STDERR : State {
my $input = $_[ARG0];
# skip empty lines
if ( $input ne '' ) {
# save it!
$_[HEAP]->{'current_data'} .= '!STDERR: ' . $input . "\n";
}
return;
}
# Handles child STDOUT output
sub Got_STDOUT : State {
my $input = $_[ARG0];
# save it!
$_[HEAP]->{'current_data'} .= $input . "\n";
return;
}
# Handles child error
sub Got_ERROR : State {
# Copied from POE::Wheel::Run manpage
my ( $operation, $errnum, $errstr ) = @_[ ARG0 .. ARG2 ];
# ignore exit 0 errors
if ( $errnum != 0 ) {
print "\n[BENCHMARKER] Wheel::Run got an $operation error $errnum: $errstr\n";
}
return;
}
# Handles child DIE'ing
sub Got_CLOSED : State {
# Get rid of the wheel
undef $_[HEAP]->{'WHEEL'};
# get rid of the delay
$_[KERNEL]->alarm_remove( $_[HEAP]->{'TIMER'} );
undef $_[HEAP]->{'TIMER'};
# wrap up this test
$_[KERNEL]->yield( 'wrapup_test' );
return;
}
# a test timed out, unfortunately!
sub test_timedout : State {
# tell the wheel to kill itself
$_[HEAP]->{'WHEEL'}->kill( 9 );
undef $_[HEAP]->{'WHEEL'};
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print " Test Timed Out!";
}
$_[HEAP]->{'test_timedout'} = 1;
# wrap up this test
$_[KERNEL]->yield( 'wrapup_test' );
return;
}
# finalizes a test
sub wrapup_test : State {
# we're done with this benchmark!
$_[HEAP]->{'current_endtime'} = time();
$_[HEAP]->{'current_endtimes'} = [ times() ];
# store the data
my $file = generateTestfile( $_[HEAP] );
if ( open( my $fh, '>', File::Spec->catfile( 'results', $file ) ) ) {
print $fh "STARTTIME: " . $_[HEAP]->{'current_starttime'} . " -> TIMES " . join( " ", @{ $_[HEAP]->{'current_starttimes'} } ) . "\n";
print $fh "$file\n";
print $fh $_[HEAP]->{'current_data'} . "\n";
if ( $_[HEAP]->{'test_timedout'} ) {
print $fh "\nTEST TERMINATED DUE TO TIMEOUT\n";
}
print $fh "ENDTIME: " . $_[HEAP]->{'current_endtime'} . " -> TIMES " . join( " ", @{ $_[HEAP]->{'current_endtimes'} } ) . "\n";
close( $fh ) or die $!;
} else {
print "\n[BENCHMARKER] Unable to open '$file' for writing -> $!\n";
}
# Send the data to the Analyzer to process
$_[KERNEL]->yield( 'analyze_output', {
'poe' => {
'v' => $_[HEAP]->{'current_version'}->stringify, # YAML::Tiny doesn't like version objects :(
'loop' => 'POE::Loop::' . $_[HEAP]->{'current_loop'},
},
't' => {
's_ts' => $_[HEAP]->{'current_starttime'},
'e_ts' => $_[HEAP]->{'current_endtime'},
'd' => $_[HEAP]->{'current_endtime'} - $_[HEAP]->{'current_starttime'},
's_t' => [ @{ $_[HEAP]->{'current_starttimes'} } ],
'e_t' => [ @{ $_[HEAP]->{'current_endtimes'} } ],
},
'raw' => $_[HEAP]->{'current_data'},
'test' => $file,
'x_bench' => currentTestVersion(),
( $_[HEAP]->{'test_timedout'} ? ( 'timedout' => 1 ) : () ),
( $_[HEAP]->{'lite_tests'} ? ( 'litetests' => 1 ) : () ),
( $_[HEAP]->{'current_assertions'} ? ( 'asserts' => 1 ) : () ),
( $_[HEAP]->{'current_noxsqueue'} ? ( 'noxsqueue' => 1 ) : () ),
} );
# process the next test
$_[KERNEL]->yield( 'bench_xsqueue' );
return;
}
sub analyze_output : State {
# get the data
my $test = $_[ARG0];
# clean up the times() stuff
$test->{'t'}->{'t'} = beautify_times(
join( " ", @{ delete $test->{'t'}->{'s_t'} } ) .
" " .
join( " ", @{ delete $test->{'t'}->{'e_t'} } )
);
# Okay, break it down into our data struct
$test->{'metrics'} = {};
my $d = $test->{'metrics'};
my @unknown;
foreach my $l ( split( /(?:\n|\r)/, $test->{'raw'} ) ) {
# skip empty lines
if ( $l eq '' ) { next }
# usual test benchmark output
# 10 startups in 0.885 seconds ( 11.302 per second)
# 10000 posts in 0.497 seconds ( 20101.112 per second)
if ( $l =~ /^\s+\d+\s+(\w+)\s+in\s+([\d\.]+)\s+seconds\s+\(\s+([\d\.]+)\s+per\s+second\)$/ ) {
$d->{ $1 }->{'d'} = $2; # duration in seconds
$d->{ $1 }->{'i'} = $3; # iterations per second
# usual test benchmark times output
# startup times: 0.1 0 0 0 0.1 0 0.76 0.09
} elsif ( $l =~ /^(\w+)\s+times:\s+(.+)$/ ) {
$d->{ $1 }->{'t'} = beautify_times( $2 ); # the times hash
# usual test SKIP output
# SKIPPING br0ken $metric because ...
} elsif ( $l =~ /^SKIPPING\s+br0ken\s+(\w+)\s+because/ ) {
# don't build their data struct
# parse the memory footprint stuff
} elsif ( $l =~ /^pidinfo:\s+(.+)$/ ) {
# what should we analyze?
my $pidinfo = $1;
# VmPeak: 16172 kB
if ( $pidinfo =~ /^VmPeak:\s+(.+)$/ ) {
$test->{'pid'}->{'vmpeak'} = $1;
# voluntary_ctxt_switches: 10
} elsif ( $pidinfo =~ /^voluntary_ctxt_switches:\s+(.+)$/ ) {
$test->{'pid'}->{'vol_ctxt'} = $1;
# nonvoluntary_ctxt_switches: 1221
} elsif ( $pidinfo =~ /^nonvoluntary_ctxt_switches:\s+(.+)$/ ) {
$test->{'pid'}->{'nonvol_ctxt'} = $1;
} else {
# ignore the rest of the fluff
}
# parse the perl binary stuff
} elsif ( $l =~ /^perlconfig:\s+(.+)$/ ) {
# what should we analyze?
my $perlconfig = $1;
# ignore the fluff ( not needed now... )
# parse the CPU info
} elsif ( $l =~ /^cpuinfo:\s+(.+)$/ ) {
# what should we analyze?
my $cpuinfo = $1;
# if this is on a multiproc system, we will overwrite the data per processor ( harmless... )
# cpu MHz : 1201.000
if ( $cpuinfo =~ /^cpu\s+MHz\s+:\s+(.+)$/ ) {
$test->{'cpu'}->{'mhz'} = $1;
# model name : Intel(R) Core(TM)2 Duo CPU L7100 @ 1.20GHz
} elsif ( $cpuinfo =~ /^model\s+name\s+:\s+(.+)$/ ) {
$test->{'cpu'}->{'name'} = $1;
# bogomips : 2397.58
} elsif ( $cpuinfo =~ /^bogomips\s+:\s+(.+)$/ ) {
$test->{'cpu'}->{'bogo'} = $1;
} else {
# ignore the rest of the fluff
}
# ignore any Devel::Hide stuff
# $l eq '!STDERR: Devel::Hide hides POE/XS/Queue/Array.pm'
} elsif ( $l =~ /^\!STDERR:\s+Devel\:\:Hide\s+hides/ ) {
# ignore them
# data that we can safely throw away
} elsif ( $l eq 'Using NO Assertions!' or
$l eq 'Using FULL Assertions!' or
$l eq 'Using the LITE tests' or
$l eq 'Using the HEAVY tests' or
$l eq 'DISABLING POE::XS::Queue::Array' or
$l eq 'LETTING POE find POE::XS::Queue::Array' or
$l eq 'UNABLE TO GET /proc/self/status' or
$l eq 'UNABLE TO GET /proc/cpuinfo' or
$l eq '!STDERR: POE::Kernel\'s run() method was never called.' or # to ignore old POEs that threw this warning
$l eq 'TEST TERMINATED DUE TO TIMEOUT' ) {
# ignore them
# parse the perl binary stuff
} elsif ( $l =~ /^Running\s+under\s+perl\s+binary:\s+\'([^\']+)\'\s+v([\d\.]+)$/ ) {
$test->{'perl'}->{'binary'} = $1;
# setup the perl version
$test->{'perl'}->{'v'} = $2;
# the master loop version ( what the POE::Loop::XYZ actually uses )
# Using loop: EV-3.49
} elsif ( $l =~ /^Using\s+master\s+loop:\s+(.+)$/ ) {
$test->{'poe'}->{'loop_m'} = $1;
# the real POE version that was loaded
# Using POE-1.001
} elsif ( $l =~ /^Using\s+POE-(.+)$/ ) {
$test->{'poe'}->{'v_real'} = $1;
# the various queue/loop modules we loaded
# POE is using: POE::XS::Queue::Array v0.005
# POE is using: POE::Queue v1.2328
# POE is using: POE::Loop::EV v0.06
} elsif ( $l =~ /^POE\s+is\s+using:\s+([^\s]+)\s+v(.+)$/ ) {
$test->{'poe'}->{'modules'}->{ $1 } = $2;
# get the uname info
# Running under machine: Linux apoc-x300 2.6.24-21-generic #1 SMP Tue Oct 21 23:43:45 UTC 2008 i686 GNU/Linux
} elsif ( $l =~ /^Running\s+under\s+machine:\s+(.+)$/ ) {
$test->{'uname'} = $1;
# parse any STDERR output
# !STDERR: unable to foo
} elsif ( $l =~ /^\!STDERR:\s+(.+)$/ ) {
push( @{ $test->{'stderr'} }, $1 );
} else {
# unknown line :(
push( @unknown, $l );
}
}
# Get rid of the rawdata
delete $test->{'raw'};
# Dump the unknowns
if ( @unknown ) {
print "\n[ANALYZER] Unknown output from benchmark -> " . Dump( \@unknown );
}
# Dump the data struct we have to the file.yml
my $yaml_file = File::Spec->catfile( 'results', ( delete $test->{'test'} ) . '.yml' );
my $ret = open( my $fh, '>', $yaml_file );
if ( defined $ret ) {
print $fh Dump( $test );
if ( ! close( $fh ) ) {
print "\n[ANALYZER] Unable to close $yaml_file -> " . $! . "\n";
}
} else {
print "\n[ANALYZER] Unable to open $yaml_file for writing -> " . $! . "\n";
}
# now that we've dumped the stuff, we can do some sanity checks
# the POE we "think" we loaded should match reality!
if ( exists $test->{'poe'}->{'v_real'} ) { # if this exists, then we successfully loaded POE
if ( $test->{'poe'}->{'v'} ne $test->{'poe'}->{'v_real'} ) {
print "\n[ANALYZER] The subprocess loaded a different version of POE than we thought -> $yaml_file\n";
}
# The loop we loaded should match what we wanted!
if ( exists $test->{'poe'}->{'modules'} ) {
if ( ! exists $test->{'poe'}->{'modules'}->{ $test->{'poe'}->{'loop'} } ) {
- # gaah special-case for IO_Poll
+ # gaah special-case for IO_Poll ( POE 0.21 to POE 0.29 introduced POE::Loop::Poll which later became POE::Loop::IO_Poll )
if ( $test->{'poe'}->{'loop'} eq 'POE::Loop::IO_Poll' and exists $test->{'poe'}->{'modules'}->{'POE::Loop::Poll'} ) {
# ah, ignore this
} else {
print "\n[ANALYZER] The subprocess loaded a different Loop than we thought -> $yaml_file\n";
}
}
}
}
# the perl binary should be the same!
if ( exists $test->{'perl'} ) { # if this exists, we successfully fired up the app ( no compile error )
if ( $test->{'perl'}->{'binary'} ne $^X ) {
print "\n[ANALYZER] The subprocess booted up on a different perl binary -> $yaml_file\n";
}
if ( $test->{'perl'}->{'v'} ne sprintf( "%vd", $^V ) ) {
print "\n[ANALYZER] The subprocess booted up on a different perl version -> $yaml_file\n";
}
}
# all done!
return;
}
1;
__END__
=for stopwords AnnoCPAN CPAN Caputo EV Eventloop Gtk HTTP Kqueue MYFH poe Prima RT SQLite STDIN SocketFactory TODO Tapout Wx XS YAML autoprobing backend benchmarker csv db dngor er freshstart hardcode litetests noasserts noxsqueue poedists pong svn untarred yml
=head1 NAME
POE::Devel::Benchmarker - Benchmarking POE's performance ( acts more like a smoker )
=head1 SYNOPSIS
use POE::Devel::Benchmarker;
benchmark();
=head1 ABSTRACT
This package of tools is designed to benchmark POE's performance across different
configurations. The current "tests" are:
=over 4
=item Events
posts: This tests how long it takes to post() N times
dispatches: This tests how long it took to dispatch/deliver all the posts enqueued in the "posts" test
single_posts: This tests how long it took to yield() between 2 states for N times
calls: This tests how long it took to call() N times
=item Alarms
alarms: This tests how long it took to add N alarms via alarm(), overwriting each other
alarm_adds: This tests how long it took to add N alarms via alarm_add()
alarm_clears: This tests how long it took to clear all alarms set in the "alarm_adds" test
NOTE: alarm_add is not available on all versions of POE!
=item Sessions
session_creates: This tests how long it took to create N sessions
session_destroys: This tests how long it took to destroy all sessions created in the "session_creates" test
=item Filehandles
select_read_STDIN: This tests how long it took to toggle select_read N times on STDIN
select_write_STDIN: This tests how long it took to toggle select_write N times on STDIN
select_read_MYFH: This tests how long it took to toggle select_read N times on a real filehandle
select_write_MYFH: This tests how long it took to toggle select_write N times on a real filehandle
NOTE: The MYFH tests don't include the time it took to open()/close() the file :)
=item Sockets
socket_connects: This tests how long it took to connect+disconnect to a SocketFactory server via localhost
socket_stream: This tests how long it took to send N chunks of data in a "ping-pong" fashion between the server and client
=item POE startup time
startups: This tests how long it took to start + close N instances of POE+Loop without any sessions/etc via system()
=item POE Loops
This is actually a "super" test where all of the specific tests is ran against various POE::Loop::XYZ/FOO for comparison
NOTE: Not all versions of POE support all Loops!
=item POE Assertions
This is actually a "super" test where all of the specific tests is ran against POE with/without assertions enabled
NOTE: Not all versions of POE support assertions!
=item POE::XS::Queue::Array
This is actually a "super" test where all of the specific tests is ran against POE with XS goodness enabled/disabled
NOTE: Not all versions of POE support XS::Queue::Array!
=back
=head1 DESCRIPTION
This module is poorly documented now. Please give me some time to properly document it over time :)
=head2 INSTALLATION
Here's a simple outline to get you up to speed quickly. ( and smoking! )
=over 4
=item Install CPAN package + dependencies
Download+install the POE::Devel::Benchmarker package from CPAN
apoc@apoc-x300:~$ cpanp -i POE::Devel::Benchmarker
=item Setup initial directories
Go anywhere, and create the "parent" directory where you'll be storing test results + stuff. For this example,
I have chosen to use ~/poe-benchmarker:
apoc@apoc-x300:~$ mkdir poe-benchmarker
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ mkdir poedists results images
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker::GetPOEdists -e 'getPOEdists( 1 )'
( go get a coffee while it downloads if you're on a slow link, ha! )
=item Let 'er rip!
At this point you can start running the benchmark!
NOTE: the Benchmarker expects everything to be in the "local" directory!
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker -e 'benchmark()'
( go sleep or something, this will take a while! )
=back
=head2 BENCHMARKING
On startup the Benchmarker will look in the "poedists" directory and load all the distributions it sees untarred there. Once
that is done it will begin autoprobing for available POE::Loop packages. Once it determines what's available, it will begin
the benchmarks.
As the Benchmarker goes through the combinations of POE + Eventloop + Assertions + XS::Queue it will dump data into
the results directory. The module also dumps YAML output in the same place, with the suffix of ".yml"
This module exposes only one subroutine, the benchmark() one. You can pass a hashref to it to set various options. Here is
a list of the valid options:
=over 4
=item freshstart => boolean
This will tell the Benchmarker to ignore any previous test runs stored in the 'results' directory. This will not delete
data from previous runs, only overwrite them. So be careful if you're mixing test runs from different versions!
benchmark( { freshstart => 1 } );
default: false
=item noxsqueue => boolean
This will tell the Benchmarker to force the unavailability of POE::XS::Queue::Array and skip those tests.
NOTE: The Benchmarker will set this automatically if it cannot load the module!
benchmark( { noxsqueue => 1 } );
default: false
=item noasserts => boolean
This will tell the Benchmarker to not run the ASSERT tests.
benchmark( { noasserts => 1 } );
default: false
=item litetests => boolean
This enables the "lite" tests which will not take up too much time.
benchmark( { litetests => 0 } );
default: true
=item quiet => boolean
This enables quiet mode which will not print anything to the console except for errors.
benchmark( { 'quiet' => 1 } );
default: false
=item loop => csv list or array
This overrides the built-in loop detection algorithm which searches for all known loops.
There is some "magic" here where you can put a negative sign in front of a loop and we will NOT run that.
NOTE: Capitalization is important!
benchmark( { 'loop' => 'IO_Poll,Select' } ); # runs only IO::Poll and Select
benchmark( { 'loop' => [ qw( Tk Gtk ) ] } ); # runs only Tk and Gtk
benchmark( { 'loop' => '-Tk' } ); # runs all available loops EXCEPT for TK
Known loops: Event_Lib EV Glib Prima Gtk Kqueue Tk Select IO_Poll
=item poe => csv list or array
This overrides the built-in POE version detection algorithm which pulls the POE versions from the 'poedists' directory.
There is some "magic" here where you can put a negative sign in front of a version and we will NOT run that.
NOTE: The Benchmarker will ignore versions that wasn't found in the directory!
benchmark( { 'poe' => '0.35,1.003' } ); # runs on 0.35 and 1.003
benchmark( { 'poe' => [ qw( 0.3009 0.12 ) ] } ); # runs on 0.3009 and 0.12
benchmark( { 'poe' => '-0.35' } ); # runs ALL tests except 0.35
=back
=head2 ANALYZING RESULTS
Please look at the pretty charts generated by the L<POE::Devel::Benchmarker::Imager> module.
=head1 EXPORT
Automatically exports the benchmark() subroutine.
=head1 TODO
=over 4
=item Perl version smoking
We should be able to run the benchmark over different Perl versions. This would require some fiddling with our
layout + logic. It's not that urgent because the workaround is to simply execute the benchmarker under a different
perl binary. It's smart enough to use $^X to be consistent across tests/subprocesses :)
=item Select the EV backend
<Khisanth> and if you are benchmarking, try it with POE using EV with EV using Glib? :P
<Apocalypse> I'm not sure how to configure the EV "backend" yet
<Apocalypse> too much docs for me to read hah
<Khisanth> Apocalypse: use EV::Glib; use Glib; use POE; :)
=item Be smarter in smoking timeouts
Currently we depend on the litetests option and hardcode some values including the timeout. If your machine is incredibly
slow, there's a chance that it could timeout unnecessarily. Please look at the outputs and check to see if there are unusual
failures, and inform me.
Also, some loops perform badly and take almost forever! /me glares at Gtk...
=item More benchmarks!
As usual, me and the crowd in #poe have plenty of ideas for tests. We'll be adding them over time, but if you have an idea please
drop me a line and let me know!
dngor said there was some benchmarks in the POE svn under trunk/queue...
<dngor> Apocalypse: Check out the old benchmarks in the queue directory in POE's repot.
They profile queue performance at various sizes, which is a better indication of scalability.
Tapout contributed a script that tests HTTP performance, let's see if it deserves to be in the suite :)
I added the preliminary socket tests, we definitely should expand it seeing how many people use POE for networking...
=item Add SQLite/DBI/etc support to the Analyzer
It would be nice if we could have a local SQLite db to dump our stats into. This would make arbitrary reports much easier than
loading raw YAML files and trying to make sense of them, ha! Also, this means somebody can do the smoking and send the SQLite
db to another person to generate the graphs, cool!
=item Kqueue loop support
As I don't have access to a *BSD box, I cannot really test this. Furthermore, it isn't clear on how I can force/unload this
module from POE...
=item Wx loop support
I have Wx installed, but it doesn't work. Obviously I don't know how to use Wx ;)
If you have experience, please drop me a line on how to do the "right" thing to get Wx loaded under POE. Here's the error:
Can't call method "MainLoop" on an undefined value at /usr/local/share/perl/5.8.8/POE/Loop/Wx.pm line 91.
=item XS::Loop support
The POE::XS::Loop::* modules theoretically could be tested too. However, they will only work in POE >= 1.003! This renders
the concept somewhat moot. Maybe, after POE has progressed some versions we can implement this...
=back
=head1 SEE ALSO
L<POE>
=head1 SUPPORT
You can find documentation for this module with the perldoc command.
perldoc POE::Devel::Benchmarker
=head2 Websites
=over 4
=item * AnnoCPAN: Annotated CPAN documentation
L<http://annocpan.org/dist/POE-Devel-Benchmarker>
=item * CPAN Ratings
L<http://cpanratings.perl.org/d/POE-Devel-Benchmarker>
=item * RT: CPAN's request tracker
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=POE-Devel-Benchmarker>
=item * Search CPAN
L<http://search.cpan.org/dist/POE-Devel-Benchmarker>
=item * CPAN Testing Service
L<http://cpants.perl.org/dist/overview/POE-Devel-Benchmarker>
=back
=head2 Bugs
Please report any bugs or feature requests to C<bug-poe-devel-benchmarker at rt.cpan.org>, or through
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=POE-Devel-Benchmarker>. I will be
notified, and then you'll automatically be notified of progress on your bug as I make changes.
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
BIG THANKS goes to Rocco Caputo E<lt>rcaputo@cpan.orgE<gt> for the first benchmarks!
=head1 COPYRIGHT AND LICENSE
Copyright 2010 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/Utils.pm b/lib/POE/Devel/Benchmarker/Utils.pm
index 7e19f22..79e8e8c 100644
--- a/lib/POE/Devel/Benchmarker/Utils.pm
+++ b/lib/POE/Devel/Benchmarker/Utils.pm
@@ -1,243 +1,241 @@
# Declare our package
package POE::Devel::Benchmarker::Utils;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.06';
# set ourself up for exporting
use base qw( Exporter );
our @EXPORT_OK = qw( poeloop2load load2poeloop loop2realversion beautify_times knownloops generateTestfile
currentMetrics currentTestVersion
);
# returns the current test output version
sub currentTestVersion {
return '1';
}
# returns the list of current metrics
sub currentMetrics {
return [ qw(
startups
alarms alarm_adds alarm_clears
dispatches posts single_posts
session_creates session_destroys
select_read_MYFH select_write_MYFH select_read_STDIN select_write_STDIN
socket_connects socket_stream
) ];
}
# returns the filename for a particular test
sub generateTestfile {
my $heap = shift;
return 'POE-' . $heap->{'current_version'} .
'-' . $heap->{'current_loop'} .
'-' . ( $heap->{'lite_tests'} ? 'LITE' : 'HEAVY' ) .
'-' . ( $heap->{'current_assertions'} ? 'assert' : 'noassert' ) .
'-' . ( $heap->{'current_noxsqueue'} ? 'noxsqueue' : 'xsqueue' );
}
# maintains the mapping of the loop <-> real module
my %poe2load = (
'Event' => 'Event',
'IO_Poll' => 'IO::Poll',
'Event_Lib' => 'Event::Lib',
'EV' => 'EV',
'Glib' => 'Glib',
'Tk' => 'Tk',
'Gtk' => 'Gtk',
'Prima' => 'Prima',
'Wx' => 'Wx',
'Kqueue' => undef,
'Select' => undef,
);
# returns the proper "load" stuff for a specific loop
sub poeloop2load {
my $eventloop = shift;
if ( exists $poe2load{ $eventloop } ) {
return $poe2load{ $eventloop };
} else {
die "Unknown event loop!";
}
}
# returns the version of the "real" installed module that the loop uses
sub loop2realversion {
my $eventloop = shift;
# Decide which event loop to use
if ( ! defined $eventloop ) {
return;
} elsif ( $eventloop eq 'Event' ) {
return $Event::VERSION;
} elsif ( $eventloop eq 'IO_Poll' ) {
return $IO::Poll::VERSION;
} elsif ( $eventloop eq 'Event_Lib' ) {
return $Event::Lib::VERSION;
} elsif ( $eventloop eq 'EV' ) {
return $EV::VERSION;
} elsif ( $eventloop eq 'Glib' ) {
return $Glib::VERSION;
} elsif ( $eventloop eq 'Tk' ) {
return $Tk::VERSION;
} elsif ( $eventloop eq 'Gtk' ) {
return $Gtk::VERSION;
} elsif ( $eventloop eq 'Prima' ) {
return $Prima::VERSION;
} elsif ( $eventloop eq 'Wx' ) {
return $Wx::VERSION;
} elsif ( $eventloop eq 'Kqueue' ) {
- # FIXME how do I do this?
- return;
+ # POE::Loop::Kqueue doesn't rely on an external module...
+ return $POE::Loop::Kqueue::VERSION;
} elsif ( $eventloop eq 'Select' ) {
return 'BUILTIN';
# FIXME figure the XS stuff out!
# } elsif ( $eventloop eq 'XSPoll' ) {
# return $POE::XS::Loop::Poll::VERSION;
# } elsif ( $eventloop eq 'XSEpoll' ) {
# return $POE::XS::Loop::EPoll::VERSION;
} else {
die "Unknown event loop!";
}
}
# helper routine to parse times() output
sub beautify_times {
my $string = shift;
my $origdata = shift;
# split it up
$string =~ s/^\s+//; $string =~ s/\s+$//;
my @times = split( /\s+/, $string );
# make the data struct
# ($user,$system,$cuser,$csystem) = times;
my $data = {
'u' => $times[4] - $times[0],
's' => $times[5] - $times[1],
'cu' => $times[6] - $times[2],
'cs' => $times[7] - $times[3],
};
# add original data?
if ( $origdata ) {
$data->{'s_user'} = $times[0];
$data->{'s_sys'} = $times[1];
$data->{'s_cuser'} = $times[2];
$data->{'s_csys'} = $times[3];
$data->{'e_user'} = $times[4];
$data->{'e_sys'} = $times[5];
$data->{'e_cuser'} = $times[6];
$data->{'e_csys'} = $times[7];
}
# send it back!
return $data;
}
# returns a list of "known" POE loops
sub knownloops {
- # FIXME we remove Wx because I suck.
- # FIXME I have no idea how to load/unload Kqueue...
# FIXME figure out the XS stuff! XSPoll XSEPoll
- return [ qw( Event_Lib EV Glib Prima Gtk Tk Select IO_Poll ) ];
+ return [ sort qw( Event Event_Lib EV Glib Prima Gtk Tk Select IO_Poll Wx Kqueue ) ];
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::Utils - Various utility routines for POE::Devel::Benchmarker
=head1 SYNOPSIS
use POE::Devel::Benchmarker::Utils qw( poeloop2load );
print poeloop2load( "IO_Poll" );
=head1 ABSTRACT
This package contains the utility routines and constants that POE::Devel::Benchmarker needs.
=head1 EXPORT
This package exports those subs via @EXPORT_OK:
=over 4
=item currentTestVersion()
Returns the current test version, used to identify different versions of the test output
=item currentMetrics()
Returns an arrayref of the current benchmark "metrics" that we process
=item knownloops()
Returns an arrayref of the "known" POE loops as of this version of the Benchmarker
=item poeloop2load()
Returns the "parent" class to load for a specific loop. An example is:
$real = poeloop2load( 'IO_Poll' ); # $real now contains "IO::Poll"
=item loop2realversion()
Returns the version of the "parent" class for a specific loop. An example is:
$ver = loop2realversion( 'IO_Poll' ); # $ver now contains $IO::Poll::VERSION
=item beautify_times()
Returns a hashref of data from parsing 2 consecutive times() structures in a string. You can pass an additional parameter
( boolean ) to include the original data. An example is:
print Data::Dumper::Dumper( beautify_times( '0.1 0 0 0 0.1 0 0.76 0.09', 1 ) );
{
"sys" => 0, # total system time
"user" => 0, # total user time
"csys" => 0.76 # total children system time
"cuser" => 0.08 # total children user time
"e_csys" => "0.09", # end children system time ( optional )
"e_cuser" => "0.76", # end children user time ( optional )
"e_sys" => 0, # end system time ( optional )
"e_user" => "0.1", # end user time ( optional )
"s_csys" => 0, # start children system time ( optional )
"s_cuser" => 0, # start children user time ( optional )
"s_sys" => 0, # start system time ( optional )
"s_user" => "0.1" # start user time ( optional )
}
=item generateTestfile()
Internal method, accepts the POE HEAP as an argument and returns the filename of the test.
my $file = generateTestfile( $_[HEAP] );
=back
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2010 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/scripts/installing_loops_ubuntu b/scripts/installing_loops_ubuntu
new file mode 100644
index 0000000..4eff943
--- /dev/null
+++ b/scripts/installing_loops_ubuntu
@@ -0,0 +1,40 @@
+To install POE + all loops on ubuntu 9.10:
+
+1. cpanp i XML::Writer # needed for stupid Gtk
+
+2. apt-get install libgtk2.0-dev libglib2.0-dev libpango1.0-dev tk tk-dev libaudiofile-dev libesd0-dev libgnomeui-dev
+
+3. install older gtk1.2 package from ubuntu 9.04
+ # download all debs into one dir, then do this "dpkg --force-all -i *.deb"
+ # The problem is that libgnome-dev deps on libgnome32 which deps on gnome-libs-data which deps on 100 old packages...
+
+ http://packages.ubuntu.com/jaunty/libdevel/libglib1.2-dev
+ http://packages.ubuntu.com/jaunty/libdevel/libgtk1.2-dev
+ http://packages.ubuntu.com/jaunty/libs/libgtk1.2
+ http://packages.ubuntu.com/jaunty/imlib-base
+ http://packages.ubuntu.com/jaunty/imlib11
+ http://packages.ubuntu.com/jaunty/libdevel/imlib11-dev
+ http://packages.ubuntu.com/jaunty/libgnome-dev
+ http://packages.ubuntu.com/jaunty/gdk-imlib11
+ http://packages.ubuntu.com/jaunty/gdk-imlib11-dev
+ http://packages.ubuntu.com/jaunty/libart2
+ http://packages.ubuntu.com/jaunty/libart-dev
+ http://packages.ubuntu.com/jaunty/libgtkxmhtml1
+ http://packages.ubuntu.com/jaunty/libgtkxmhtml-dev
+ http://packages.ubuntu.com/jaunty/libgdk-pixbuf-dev
+ http://packages.ubuntu.com/jaunty/gnome-bin
+ http://packages.ubuntu.com/jaunty/gnome-libs-data
+ http://packages.ubuntu.com/jaunty/libgnome32
+ http://packages.ubuntu.com/jaunty/libzvt-dev
+ http://packages.ubuntu.com/jaunty/libzvt2
+
+3. cpanp i POE::Loop::EV POE::Loop::Prima POE::Loop::Tk POE::Loop::Glib POE::Loop::Event POE::Loop::Wx
+
+4. cpanp z Gtk
+ # Gtk for some reason is *hard* to compile!
+ # in my case, I needed to perl Makefile.PL && make
+ # and type 'make' like 50 times before it compiled everything!!!
+ # finally, install it then do "cpanp i POE::Loop::Gtk"
+
+4. apt-get remove libgnome32 gnome-bin gnome-libs-data libgnome-dev
+ # this is because those stupid packages will "hang" the system with unmet dependency error...
|
apocalypse/perl-poe-benchmarker
|
8f3edf63752571db077f2c956aefcf623940c2b1
|
cleanups in preparation of CPAN release
|
diff --git a/Build.PL b/Build.PL
index 7980144..c4ef2d3 100644
--- a/Build.PL
+++ b/Build.PL
@@ -1,111 +1,100 @@
# Build.PL
+use strict; use warnings;
use Module::Build;
my $build = Module::Build->new(
# look up Module::Build::API for the info!
'dynamic_config' => 0,
'module_name' => 'POE::Devel::Benchmarker',
'license' => 'perl',
'dist_abstract' => "Benchmarking POE's performance ( acts more like a smoker )",
'dist_author' => 'Apocalypse <APOCAL@cpan.org>',
'create_packlist' => 1,
'create_makefile_pl' => 'traditional',
'create_readme' => 1,
+ 'create_license' => 1,
+ 'sign' => 0,
'test_files' => 't/*.t',
- 'add_to_cleanup' => [ 'META.yml', 'Makefile.PL', 'README' ], # automatically generated
+ 'add_to_cleanup' => [ 'META.yml', 'Makefile.PL', 'README', 'Makefile', 'LICENSE' ], # automatically generated
'requires' => {
# POE Stuff
'POE' => 0,
'POE::Session::AttributeBased' => 0,
- # FIXME POE stuff that Test::Dependencies needs to see
- 'POE::Session' => 0,
- 'POE::Wheel::SocketFactory' => 0,
- 'POE::Wheel::ReadWrite' => 0,
- 'POE::Filter::Line' => 0,
- 'POE::Driver::SysRW' => 0,
-
# misc perl stuff
'Time::HiRes' => 0,
'version' => 0,
'Devel::Hide' => 0,
+ 'File::Spec' => 0,
# Analyzer reqs
'YAML::Tiny' => 0,
# GetPOEdists reqs
'LWP::UserAgent' => 0,
'HTML::LinkExtor' => 0,
'URI::URL' => 0,
'Archive::Tar' => 0,
# Imager reqs
'GD::Graph::lines' => 0,
'GD::Graph::colour' => 0,
'Class::Accessor::Fast' => 0,
'Module::Pluggable' => 0,
# Test stuff
- 'Test::More' => '0.86', # require latest for note() support in t/a_is_prereq_outdated.t
+ 'Test::More' => 0,
+
+ # we need a recent perl
+ 'perl' => '5.008',
},
'recommends' => {
# our POE loops!
'POE::Loop::Event' => 0,
'POE::Loop::Event_Lib' => 0,
'POE::Loop::EV' => 0,
'POE::Loop::Glib' => 0,
'POE::Loop::Prima' => 0,
'POE::Loop::Gtk' => 0,
'POE::Loop::Wx' => 0,
'POE::Loop::Kqueue' => 0,
# included in POE ( listed here for completeness )
#'POE::Loop::Tk' => 0,
#'POE::Loop::Select' => 0,
#'POE::Loop::IO_Poll' => 0,
# the loops' dependencies
'Event' => 0,
'Event::Lib' => 0,
'EV' => 0,
'Glib' => 0,
'Prima' => 0,
'Wx' => 0,
'Tk' => 0,
# the XS stuff
'POE::XS::Queue::Array' => 0,
'POE::XS::Loop::Poll' => 0,
'POE::XS::Loop::EPoll' => 0,
},
- # FIXME wishlist...
-# 'test_requires' => {
-# # Test stuff
-# 'Test::Compile' => 0,
-# 'Test::Perl::Critic' => 0,
-# 'Test::Dependencies' => 0,
-# 'Test::Distribution' => 0,
-# 'Test::Fixme' => 0,
-# 'Test::HasVersion' => 0,
-# 'Test::Kwalitee' => 0,
-# 'Test::CheckManifest' => 0,
-# 'Test::MinimumVersion' => 0,
-# 'Test::Pod::Coverage' => 0,
-# 'Test::Spelling' => 0,
-# 'Test::Pod' => 0,
-# 'Test::Prereq' => 0,
-# 'Test::Strict' => 0,
-# 'Test::UseAllModules' => 0,
-# 'Test::YAML::Meta' => 0,
-# },
+ # include the standard stuff in META.yml
+ 'meta_merge' => {
+ 'resources' => {
+ 'license' => 'http://dev.perl.org/licenses/',
+ 'homepage' => 'http://search.cpan.org/dist/POE-Devel-Benchmarker',
+ 'bugtracker' => 'http://rt.cpan.org/NoAuth/Bugs.html?Dist=POE-Devel-Benchmarker',
+ 'repository' => 'http://github.com/apocalypse/perl-poe-benchmarker',
+ },
+ },
);
# all done!
$build->create_build_script;
diff --git a/Changes b/Changes
index 800c99e..5dae389 100644
--- a/Changes
+++ b/Changes
@@ -1,41 +1,48 @@
Revision history for Perl extension POE::Devel::Benchmarker
+* 0.06
+
+ POD tweaks and typo fixes
+ Cleanup Build.PL and remove a lot of tests in favor of Test::Apocalypse
+ Fixed a bug where the Benchmarker wouldn't recognize old test runs and skip them
+ Add File::Spec so we are more portable, yay!
+
* 0.05
Minor tweaks on the YAML output ( nothing new, hah! )
Added the socket tests, yay! ( still need more work so we test various methods of socket creation )
Some more tweaks to the BasicStatistics plugin for prettier graphs
Lots of refactoring to get things cleaned up :)
Added test versioning, so we make sure we're processing the right version :)
added examples/test.pl to satisfy kwalitee requirements, ha!
* 0.04
Started work on the image generator ( Imager ) and added the BasicStatistics plugin, yay!
Added automatic "pick up where we left off" to the benchmarker
Added the freshstart option to benchmark()
Tweaked the GetPOEdists sub so it will work in the "work directory" and in the poedists dir
Tweaked the YAML output so it's smaller
Removed POE::Loop::Wx from autoprobing ( I'm unable to get it to work )
Removed POE::Loop::Kqueue from autoprobing ( I'm unable to get it to work )
Hardcoded the Benchmarker routines to skip POE < 0.13 ( I'm unable to get it to work )
* 0.03
Added the loop option to benchmark(), thanks dngor!
Added the poe option to benchmark(), thanks dngor!
Added the noxsqueue option to benchmark()
Added the noasserts option to benchmark()
Automatically enable noxsqueue option if we cannot load POE::XS::Queue::Array, saving time
Bump Test::More version requirement because some people reported failures with note()
Fixed bug in SubProcess where it crashed on old POEs that didn't load IO::Handle
More documentation additions/tweaks
* 0.02
Added the Analyzer module ( and dump YAML files, yay! )
A lot of minor changes+tweaks to get a better dump format
* 0.01
initial release
diff --git a/MANIFEST b/MANIFEST
index e1e39c3..fed286c 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -1,38 +1,21 @@
-Makefile.PL
Build.PL
MANIFEST
MANIFEST.SKIP
README
+Makefile.PL
+META.yml
+Changes
+LICENSE
+
lib/POE/Devel/Benchmarker.pm
lib/POE/Devel/Benchmarker/GetInstalledLoops.pm
lib/POE/Devel/Benchmarker/GetPOEdists.pm
lib/POE/Devel/Benchmarker/SubProcess.pm
lib/POE/Devel/Benchmarker/Utils.pm
lib/POE/Devel/Benchmarker/Imager.pm
lib/POE/Devel/Benchmarker/Imager/BasicStatistics.pm
-META.yml
-Changes
examples/test.pl
t/1_load.t
-
-t/a_critic.t
-t/a_kwalitee.t
-t/a_pod.t
-t/a_pod_spelling.t
-t/a_pod_coverage.t
-t/a_strict.t
-t/a_hasversion.t
-t/a_minimumversion.t
-t/a_manifest.t
-t/a_distribution.t
-t/a_compile.t
-t/a_dependencies.t
-t/a_fixme.t
-t/a_prereq.t
-t/a_prereq_build.t
-t/a_dosnewline.t
-t/a_perlmetrics.t
-t/a_is_prereq_outdated.t
-t/a_metayml.t
+t/apocalypse.t
diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP
index 57df5f5..86794f1 100644
--- a/MANIFEST.SKIP
+++ b/MANIFEST.SKIP
@@ -1,31 +1,30 @@
-^.includepath
-^.project
-^.settings/
-
-# Avoid version control files.
-\B\.svn\b
-\B\.git\b
-
-# Avoid Makemaker generated and utility files.
-\bMANIFEST\.SKIP
-\bMakefile$
-\bblib/
-\bMakeMaker-\d
-\bpm_to_blib$
-
-# Avoid Module::Build generated and utility files.
-\bBuild$
-\b_build/
-
-# Avoid temp and backup files.
-~$
-\.old$
-\#$
-\b\.#
-\.bak$
-
-# our tarballs
-\.tar\.gz$
-
-# skip the local scripts directory where I store snippets of benchmarks
-scripts/
+\.includepath$
+\.project$
+\.settings/
+
+# Avoid version control files.
+\B\.svn\b
+\B\.git\b
+
+# Avoid Makemaker generated and utility files.
+\bMakefile$
+\bblib/
+\bMakeMaker-\d
+\bpm_to_blib$
+
+# Avoid Module::Build generated and utility files.
+\bBuild$
+\b_build/
+
+# Avoid temp and backup files.
+~$
+\.old$
+\#$
+\b\.#
+\.bak$
+
+# our tarballs
+\.tar\.gz$
+
+# skip the local scripts directory where I store snippets of benchmarks
+scripts/
diff --git a/POE-Devel-Benchmarker-0.06.tar.gz b/POE-Devel-Benchmarker-0.06.tar.gz
new file mode 100644
index 0000000..5067e8a
Binary files /dev/null and b/POE-Devel-Benchmarker-0.06.tar.gz differ
diff --git a/lib/POE/Devel/Benchmarker.pm b/lib/POE/Devel/Benchmarker.pm
index 438b0ca..00f3b44 100644
--- a/lib/POE/Devel/Benchmarker.pm
+++ b/lib/POE/Devel/Benchmarker.pm
@@ -1,1156 +1,1162 @@
# Declare our package
package POE::Devel::Benchmarker;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
-$VERSION = '0.05';
+$VERSION = '0.06';
# auto-export the only sub we have
use base qw( Exporter );
our @EXPORT = qw( benchmark );
-# we need hires times
+# load needed modules
use Time::HiRes qw( time );
+use version;
+use YAML::Tiny qw( Dump );
+use File::Spec;
# Import what we need from the POE namespace
use POE qw( Session Filter::Line Wheel::Run );
use base 'POE::Session::AttributeBased';
-# load comparison stuff
-use version;
-
-# use the power of YAML
-use YAML::Tiny qw( Dump );
-
# Load our stuff
use POE::Devel::Benchmarker::GetInstalledLoops;
use POE::Devel::Benchmarker::Utils qw( poeloop2load knownloops generateTestfile beautify_times currentTestVersion );
# Actually run the tests!
sub benchmark {
my $options = shift;
# set default options
my $lite_tests = 1;
my $quiet_mode = 0;
my $forceloops = undef; # default to autoprobe all
my $forcepoe = undef; # default to all found POE versions in poedists/
my $forcenoxsqueue = 0; # default to try and load it
my $forcenoasserts = 0; # default is to run it
my $freshstart = 0; # always resume where we left off
# process our options
if ( defined $options and ref $options and ref( $options ) eq 'HASH' ) {
# process YES for freshstart
if ( exists $options->{'freshstart'} ) {
if ( $options->{'freshstart'} ) {
$freshstart = 1;
}
delete $options->{'freshstart'};
}
# process NO for XS::Queue::Array
if ( exists $options->{'noxsqueue'} ) {
if ( $options->{'noxsqueue'} ) {
$forcenoxsqueue = 1;
}
delete $options->{'noxsqueue'};
}
# process NO for ASSERT
if ( exists $options->{'noasserts'} ) {
if ( $options->{'noasserts'} ) {
$forcenoasserts = 1;
}
delete $options->{'noasserts'};
}
# process LITE tests
if ( exists $options->{'litetests'} ) {
if ( $options->{'litetests'} ) {
$lite_tests = 1;
} else {
$lite_tests = 0;
}
delete $options->{'litetests'};
}
# process quiet mode
if ( exists $options->{'quiet'} ) {
if ( $options->{'quiet'} ) {
$quiet_mode = 1;
} else {
$quiet_mode = 0;
}
delete $options->{'quiet'};
}
# process forceloops
if ( exists $options->{'loop'} and defined $options->{'loop'} ) {
if ( ! ref $options->{'loop'} ) {
# split it via CSV
$forceloops = [ split( /,/, $options->{'loop'} ) ];
foreach ( @$forceloops ) {
$_ =~ s/^\s+//; $_ =~ s/\s+$//;
}
} else {
# treat it as array
$forceloops = $options->{'loop'};
}
# check for !loop modules
my @noloops;
foreach my $l ( @$forceloops ) {
if ( $l =~ /^\!/ ) {
push( @noloops, substr( $l, 1 ) );
}
}
if ( scalar @noloops ) {
# replace the forceloops with ALL known, then subtract noloops from it
my %bad;
@bad{@noloops} = () x @noloops;
@$forceloops = grep { !exists $bad{$_} } @{ knownloops() };
}
delete $options->{'loop'};
}
# process the poe versions
if ( exists $options->{'poe'} and defined $options->{'poe'} ) {
if ( ! ref $options->{'poe'} ) {
# split it via CSV
$forcepoe = [ split( /,/, $options->{'poe'} ) ];
foreach ( @$forcepoe ) {
$_ =~ s/^\s+//; $_ =~ s/\s+$//;
}
} else {
# treat it as array
$forcepoe = $options->{'poe'};
}
delete $options->{'poe'};
}
# unknown options!
if ( scalar keys %$options ) {
warn "[BENCHMARKER] Unknown options present in arguments: " . keys %$options;
}
}
# do some sanity checks
if ( ! -d 'poedists' ) {
die "The 'poedists' directory is not found in the working directory!";
}
if ( ! -d 'results' ) {
die "The 'results' directory is not found in the working directory!";
}
if ( ! $quiet_mode ) {
print "[BENCHMARKER] Starting up...\n";
}
# Create our session
POE::Session->create(
__PACKAGE__->inline_states(),
'heap' => {
# misc stuff
'quiet_mode' => $quiet_mode,
# override our testing behavior
'lite_tests' => $lite_tests,
'forceloops' => $forceloops,
'forcepoe' => $forcepoe,
'forcenoxsqueue' => $forcenoxsqueue,
'forcenoasserts' => $forcenoasserts,
'freshstart' => $freshstart,
},
);
# Fire 'er up!
POE::Kernel->run();
return;
}
# Starts up our session
sub _start : State {
# okay, get all the dists we can!
my @versions;
if ( opendir( DISTS, 'poedists' ) ) {
foreach my $d ( readdir( DISTS ) ) {
if ( $d =~ /^POE\-(.+)$/ and $d !~ /\.tar\.gz$/ ) {
# FIXME skip POE < 0.13 because I can't get it to work
my $ver = version->new( $1 );
if ( $ver > version->new( '0.12' ) ) {
push( @versions, $ver );
}
}
}
closedir( DISTS ) or die $!;
} else {
print "[BENCHMARKER] Unable to open 'poedists' for reading: $!\n";
return;
}
# should we munge the versions list?
if ( defined $_[HEAP]->{'forcepoe'} ) {
# check for !poe versions
my @nopoe;
foreach my $p ( @{ $_[HEAP]->{'forcepoe'} } ) {
if ( $p =~ /^\!/ ) {
push( @nopoe, substr( $p, 1 ) );
}
}
if ( scalar @nopoe ) {
# remove the nopoe versions from the found
my %bad;
@bad{@nopoe} = () x @nopoe;
@versions = grep { !exists $bad{$_->stringify} } @versions;
} else {
# make sure the @versions contains only what we specified
my %good;
@good{ @{ $_[HEAP]->{'forcepoe'} } } = () x @{ $_[HEAP]->{'forcepoe'} };
@versions = grep { exists $good{$_->stringify} } @versions;
}
}
# sanity
if ( ! scalar @versions ) {
print "[BENCHMARKER] Unable to find any POE version in the 'poedists' directory!\n";
return;
}
# set our alias
$_[KERNEL]->alias_set( 'Benchmarker' );
# sanely handle some signals
$_[KERNEL]->sig( 'INT', 'handle_kill' );
$_[KERNEL]->sig( 'TERM', 'handle_kill' );
# okay, go through all the dists in version order ( from newest to oldest )
@versions = sort { $b <=> $a } @versions;
# Store the versions in our heap
$_[HEAP]->{'VERSIONS'} = \@versions;
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Detected available POE versions -> " . join( " ", @versions ) . "\n";
}
# First of all, we need to find out what loop libraries are installed
getPOEloops( $_[HEAP]->{'quiet_mode'}, $_[HEAP]->{'forceloops'} );
return;
}
sub _stop : State {
# tell the wheel to kill itself
if ( defined $_[HEAP]->{'WHEEL'} ) {
$_[HEAP]->{'WHEEL'}->kill( 9 );
undef $_[HEAP]->{'WHEEL'};
}
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "\n[BENCHMARKER] Shutting down...\n";
}
return;
}
# misc POE handlers
sub _child : State {
return;
}
sub handle_kill : State {
return;
}
# we received list of loops from GetInstalledLoops
sub found_loops : State {
$_[HEAP]->{'installed_loops'} = [ sort { $a cmp $b } @{ $_[ARG0] } ];
# sanity check
if ( scalar @{ $_[HEAP]->{'installed_loops'} } == 0 ) {
print "[BENCHMARKER] Detected no available POE::Loop, check your configuration?!?\n";
return;
}
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Detected available POE::Loops -> " . join( " ", @{ $_[HEAP]->{'installed_loops'} } ) . "\n";
}
# Okay, do we have XS::Queue installed?
if ( ! $_[HEAP]->{'forcenoxsqueue'} ) {
eval { require POE::XS::Queue::Array };
if ( $@ ) {
$_[HEAP]->{'forcenoxsqueue'} = 1;
}
}
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Starting the benchmarks!" .
( $_[HEAP]->{'forcenoxsqueue'} ? ' Skipping XS::Queue Tests!' : '' ) .
( $_[HEAP]->{'forcenoasserts'} ? ' Skipping ASSERT Tests!' : '' ) .
"\n";
}
# start the benchmark!
$_[KERNEL]->yield( 'run_benchmark' );
return;
}
# Runs one benchmark
sub run_benchmark : State {
# Grab the version from the top of the array
$_[HEAP]->{'current_version'} = shift @{ $_[HEAP]->{'VERSIONS'} };
# did we run out of versions?
if ( ! defined $_[HEAP]->{'current_version'} ) {
# We're done, let POE die...
$_[KERNEL]->alias_remove( 'Benchmarker' );
} else {
$_[HEAP]->{'loops'} = [ @{ $_[HEAP]->{'installed_loops'} } ];
# okay, fire off the first loop
$_[KERNEL]->yield( 'bench_loop' );
}
return;
}
# runs one loop
sub bench_loop : State {
# select our current loop
$_[HEAP]->{'current_loop'} = shift @{ $_[HEAP]->{'loops'} };
# are we done with all loops?
if ( ! defined $_[HEAP]->{'current_loop'} ) {
# yay, go back to the main handler
$_[KERNEL]->yield( 'run_benchmark' );
} else {
# Start the assert test
if ( $_[HEAP]->{'forcenoasserts'} ) {
$_[HEAP]->{'assertions'} = [ qw( 0 ) ];
} else {
$_[HEAP]->{'assertions'} = [ qw( 0 1 ) ];
}
$_[KERNEL]->yield( 'bench_asserts' );
}
return;
}
# runs an assertion
sub bench_asserts : State {
# select our current assert state
$_[HEAP]->{'current_assertions'} = shift @{ $_[HEAP]->{'assertions'} };
# are we done?
if ( ! defined $_[HEAP]->{'current_assertions'} ) {
# yay, go back to the loop handler
$_[KERNEL]->yield( 'bench_loop' );
} else {
# Start the xsqueue test
if ( $_[HEAP]->{'forcenoxsqueue'} ) {
$_[HEAP]->{'noxsqueue'} = [ qw( 1 ) ];
} else {
$_[HEAP]->{'noxsqueue'} = [ qw( 0 1 ) ];
}
$_[KERNEL]->yield( 'bench_xsqueue' );
}
return;
}
# runs test with or without xsqueue
sub bench_xsqueue : State {
# select our current noxsqueue state
$_[HEAP]->{'current_noxsqueue'} = shift @{ $_[HEAP]->{'noxsqueue'} };
# are we done?
if ( ! defined $_[HEAP]->{'current_noxsqueue'} ) {
# yay, go back to the assert handler
$_[KERNEL]->yield( 'bench_asserts' );
} else {
# do some careful analysis
$_[KERNEL]->yield( 'bench_checkprevioustest' );
}
return;
}
# Checks to see if this test was run in the past
sub bench_checkprevioustest : State {
# okay, do we need to check and see if we already did this test?
if ( ! $_[HEAP]->{'freshstart'} ) {
# determine the file used
- my $file = generateTestfile( $_[HEAP] );
+ my $file = File::Spec->catfile( 'results', generateTestfile( $_[HEAP] ) . '.yml' );
# does it exist?
- if ( -e "results/$file.yml" and -f _ and -s _ ) {
+ if ( -e $file and -f _ and -s _ ) {
# okay, sanity check it
- my $yaml = YAML::Tiny->read( "results/$file.yml" );
+ my $yaml = YAML::Tiny->read( $file );
if ( defined $yaml ) {
# inrospect it!
my $isvalid = 0;
eval {
# simple sanity check: the "x_bench" param is at the end of the YML, so if it loads fine we know it's there
if ( exists $yaml->[0]->{'x_bench'} ) {
# version must at least match us
- $isvalid = ( $yaml->[0]->{'x_bench'} eq $POE::Devel::Benchmarker::VERSION ? 1 : 0 );
+ $isvalid = ( $yaml->[0]->{'x_bench'} eq currentTestVersion() ? 1 : 0 );
} else {
$isvalid = undef;
}
};
if ( $isvalid ) {
# yay, this test is A-OK!
+ if ( ! $_[HEAP]->{'quiet_mode'} ) {
+ print " SKIPPING ( found old test run )";
+ }
$_[KERNEL]->yield( 'bench_xsqueue' );
return;
} else {
# was it truncated?
if ( ! defined $isvalid ) {
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "\n[BENCHMARKER] YAML file($file) from previous test was corrupt!\n";
}
}
}
} else {
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "\n[BENCHMARKER] Unable to load YAML file($file) from previous test run: " . YAML::Tiny->errstr . "\n";
}
}
}
}
# could not find previous file or FRESHSTART, proceed normally
$_[KERNEL]->yield( 'create_subprocess' );
return;
}
# actually runs the subprocess
sub create_subprocess : State {
# Okay, start testing this specific combo!
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "\n Testing " . generateTestfile( $_[HEAP] ) . "...";
}
# save the starttime
$_[HEAP]->{'current_starttime'} = time();
$_[HEAP]->{'current_starttimes'} = [ times() ];
# Okay, create the wheel::run to handle this
my $looploader = poeloop2load( $_[HEAP]->{'current_loop'} );
$_[HEAP]->{'WHEEL'} = POE::Wheel::Run->new(
'Program' => $^X,
'ProgramArgs' => [ '-Ipoedists/POE-' . $_[HEAP]->{'current_version'},
'-Ipoedists/POE-' . $_[HEAP]->{'current_version'} . '/lib',
( defined $looploader ? "-M$looploader" : () ),
'-MPOE::Devel::Benchmarker::SubProcess',
'-e',
'POE::Devel::Benchmarker::SubProcess::benchmark',
$_[HEAP]->{'current_loop'},
$_[HEAP]->{'current_assertions'},
$_[HEAP]->{'lite_tests'},
$_[HEAP]->{'current_noxsqueue'},
],
# Kill off existing FD's
'CloseOnCall' => 1,
# setup our data handlers
'StdoutEvent' => 'Got_STDOUT',
'StderrEvent' => 'Got_STDERR',
# the error handler
'ErrorEvent' => 'Got_ERROR',
'CloseEvent' => 'Got_CLOSED',
# set our filters
'StderrFilter' => POE::Filter::Line->new(),
'StdoutFilter' => POE::Filter::Line->new(),
);
if ( ! defined $_[HEAP]->{'WHEEL'} ) {
die 'Unable to create a new wheel!';
} else {
# smart CHLD handling
if ( $_[KERNEL]->can( "sig_child" ) ) {
$_[KERNEL]->sig_child( $_[HEAP]->{'WHEEL'}->PID => 'Got_CHLD' );
} else {
$_[KERNEL]->sig( 'CHLD', 'Got_CHLD' );
}
}
# setup our data we received from the subprocess
$_[HEAP]->{'current_data'} = '';
# Okay, we timeout this test after some time for sanity
$_[HEAP]->{'test_timedout'} = 0;
if ( $_[HEAP]->{'lite_tests'} ) {
# 5min timeout is 5x my average runs on a 1.2ghz core2duo so it should be good enough
$_[HEAP]->{'TIMER'} = $_[KERNEL]->delay_set( 'test_timedout' => 60 * 5 );
} else {
# 30min timeout is 2x my average runs on a 1.2ghz core2duo so it should be good enough
$_[HEAP]->{'TIMER'} = $_[KERNEL]->delay_set( 'test_timedout' => 60 * 30 );
}
return;
}
# Got a CHLD event!
sub Got_CHLD : State {
$_[KERNEL]->sig_handled();
return;
}
# Handles child STDERR output
sub Got_STDERR : State {
my $input = $_[ARG0];
# skip empty lines
if ( $input ne '' ) {
# save it!
$_[HEAP]->{'current_data'} .= '!STDERR: ' . $input . "\n";
}
return;
}
# Handles child STDOUT output
sub Got_STDOUT : State {
my $input = $_[ARG0];
# save it!
$_[HEAP]->{'current_data'} .= $input . "\n";
return;
}
# Handles child error
sub Got_ERROR : State {
# Copied from POE::Wheel::Run manpage
my ( $operation, $errnum, $errstr ) = @_[ ARG0 .. ARG2 ];
# ignore exit 0 errors
if ( $errnum != 0 ) {
print "\n[BENCHMARKER] Wheel::Run got an $operation error $errnum: $errstr\n";
}
return;
}
# Handles child DIE'ing
sub Got_CLOSED : State {
# Get rid of the wheel
undef $_[HEAP]->{'WHEEL'};
# get rid of the delay
$_[KERNEL]->alarm_remove( $_[HEAP]->{'TIMER'} );
undef $_[HEAP]->{'TIMER'};
# wrap up this test
$_[KERNEL]->yield( 'wrapup_test' );
return;
}
# a test timed out, unfortunately!
sub test_timedout : State {
# tell the wheel to kill itself
$_[HEAP]->{'WHEEL'}->kill( 9 );
undef $_[HEAP]->{'WHEEL'};
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print " Test Timed Out!";
}
$_[HEAP]->{'test_timedout'} = 1;
# wrap up this test
$_[KERNEL]->yield( 'wrapup_test' );
return;
}
# finalizes a test
sub wrapup_test : State {
# we're done with this benchmark!
$_[HEAP]->{'current_endtime'} = time();
$_[HEAP]->{'current_endtimes'} = [ times() ];
# store the data
my $file = generateTestfile( $_[HEAP] );
- if ( open( my $fh, '>', "results/$file" ) ) {
+ if ( open( my $fh, '>', File::Spec->catfile( 'results', $file ) ) ) {
print $fh "STARTTIME: " . $_[HEAP]->{'current_starttime'} . " -> TIMES " . join( " ", @{ $_[HEAP]->{'current_starttimes'} } ) . "\n";
print $fh "$file\n";
print $fh $_[HEAP]->{'current_data'} . "\n";
if ( $_[HEAP]->{'test_timedout'} ) {
print $fh "\nTEST TERMINATED DUE TO TIMEOUT\n";
}
print $fh "ENDTIME: " . $_[HEAP]->{'current_endtime'} . " -> TIMES " . join( " ", @{ $_[HEAP]->{'current_endtimes'} } ) . "\n";
close( $fh ) or die $!;
} else {
- print "\n[BENCHMARKER] Unable to open results/$file for writing -> $!\n";
+ print "\n[BENCHMARKER] Unable to open '$file' for writing -> $!\n";
}
# Send the data to the Analyzer to process
$_[KERNEL]->yield( 'analyze_output', {
'poe' => {
'v' => $_[HEAP]->{'current_version'}->stringify, # YAML::Tiny doesn't like version objects :(
'loop' => 'POE::Loop::' . $_[HEAP]->{'current_loop'},
},
't' => {
's_ts' => $_[HEAP]->{'current_starttime'},
'e_ts' => $_[HEAP]->{'current_endtime'},
'd' => $_[HEAP]->{'current_endtime'} - $_[HEAP]->{'current_starttime'},
's_t' => [ @{ $_[HEAP]->{'current_starttimes'} } ],
'e_t' => [ @{ $_[HEAP]->{'current_endtimes'} } ],
},
'raw' => $_[HEAP]->{'current_data'},
'test' => $file,
'x_bench' => currentTestVersion(),
( $_[HEAP]->{'test_timedout'} ? ( 'timedout' => 1 ) : () ),
( $_[HEAP]->{'lite_tests'} ? ( 'litetests' => 1 ) : () ),
( $_[HEAP]->{'current_assertions'} ? ( 'asserts' => 1 ) : () ),
( $_[HEAP]->{'current_noxsqueue'} ? ( 'noxsqueue' => 1 ) : () ),
} );
# process the next test
$_[KERNEL]->yield( 'bench_xsqueue' );
return;
}
sub analyze_output : State {
# get the data
my $test = $_[ARG0];
# clean up the times() stuff
$test->{'t'}->{'t'} = beautify_times(
join( " ", @{ delete $test->{'t'}->{'s_t'} } ) .
" " .
join( " ", @{ delete $test->{'t'}->{'e_t'} } )
);
# Okay, break it down into our data struct
$test->{'metrics'} = {};
my $d = $test->{'metrics'};
my @unknown;
foreach my $l ( split( /(?:\n|\r)/, $test->{'raw'} ) ) {
# skip empty lines
if ( $l eq '' ) { next }
# usual test benchmark output
# 10 startups in 0.885 seconds ( 11.302 per second)
# 10000 posts in 0.497 seconds ( 20101.112 per second)
if ( $l =~ /^\s+\d+\s+(\w+)\s+in\s+([\d\.]+)\s+seconds\s+\(\s+([\d\.]+)\s+per\s+second\)$/ ) {
$d->{ $1 }->{'d'} = $2; # duration in seconds
$d->{ $1 }->{'i'} = $3; # iterations per second
# usual test benchmark times output
# startup times: 0.1 0 0 0 0.1 0 0.76 0.09
} elsif ( $l =~ /^(\w+)\s+times:\s+(.+)$/ ) {
$d->{ $1 }->{'t'} = beautify_times( $2 ); # the times hash
# usual test SKIP output
# SKIPPING br0ken $metric because ...
} elsif ( $l =~ /^SKIPPING\s+br0ken\s+(\w+)\s+because/ ) {
# don't build their data struct
# parse the memory footprint stuff
} elsif ( $l =~ /^pidinfo:\s+(.+)$/ ) {
# what should we analyze?
my $pidinfo = $1;
# VmPeak: 16172 kB
if ( $pidinfo =~ /^VmPeak:\s+(.+)$/ ) {
$test->{'pid'}->{'vmpeak'} = $1;
# voluntary_ctxt_switches: 10
} elsif ( $pidinfo =~ /^voluntary_ctxt_switches:\s+(.+)$/ ) {
$test->{'pid'}->{'vol_ctxt'} = $1;
# nonvoluntary_ctxt_switches: 1221
} elsif ( $pidinfo =~ /^nonvoluntary_ctxt_switches:\s+(.+)$/ ) {
$test->{'pid'}->{'nonvol_ctxt'} = $1;
} else {
# ignore the rest of the fluff
}
# parse the perl binary stuff
} elsif ( $l =~ /^perlconfig:\s+(.+)$/ ) {
# what should we analyze?
my $perlconfig = $1;
# ignore the fluff ( not needed now... )
# parse the CPU info
} elsif ( $l =~ /^cpuinfo:\s+(.+)$/ ) {
# what should we analyze?
my $cpuinfo = $1;
- # FIXME if this is on a multiproc system, we will overwrite the data per processor ( harmless? )
+ # if this is on a multiproc system, we will overwrite the data per processor ( harmless... )
# cpu MHz : 1201.000
if ( $cpuinfo =~ /^cpu\s+MHz\s+:\s+(.+)$/ ) {
$test->{'cpu'}->{'mhz'} = $1;
# model name : Intel(R) Core(TM)2 Duo CPU L7100 @ 1.20GHz
} elsif ( $cpuinfo =~ /^model\s+name\s+:\s+(.+)$/ ) {
$test->{'cpu'}->{'name'} = $1;
# bogomips : 2397.58
} elsif ( $cpuinfo =~ /^bogomips\s+:\s+(.+)$/ ) {
$test->{'cpu'}->{'bogo'} = $1;
} else {
# ignore the rest of the fluff
}
# ignore any Devel::Hide stuff
# $l eq '!STDERR: Devel::Hide hides POE/XS/Queue/Array.pm'
} elsif ( $l =~ /^\!STDERR:\s+Devel\:\:Hide\s+hides/ ) {
# ignore them
# data that we can safely throw away
} elsif ( $l eq 'Using NO Assertions!' or
$l eq 'Using FULL Assertions!' or
$l eq 'Using the LITE tests' or
$l eq 'Using the HEAVY tests' or
$l eq 'DISABLING POE::XS::Queue::Array' or
$l eq 'LETTING POE find POE::XS::Queue::Array' or
$l eq 'UNABLE TO GET /proc/self/status' or
$l eq 'UNABLE TO GET /proc/cpuinfo' or
$l eq '!STDERR: POE::Kernel\'s run() method was never called.' or # to ignore old POEs that threw this warning
$l eq 'TEST TERMINATED DUE TO TIMEOUT' ) {
# ignore them
# parse the perl binary stuff
} elsif ( $l =~ /^Running\s+under\s+perl\s+binary:\s+\'([^\']+)\'\s+v([\d\.]+)$/ ) {
$test->{'perl'}->{'binary'} = $1;
# setup the perl version
$test->{'perl'}->{'v'} = $2;
# the master loop version ( what the POE::Loop::XYZ actually uses )
# Using loop: EV-3.49
} elsif ( $l =~ /^Using\s+master\s+loop:\s+(.+)$/ ) {
$test->{'poe'}->{'loop_m'} = $1;
# the real POE version that was loaded
# Using POE-1.001
} elsif ( $l =~ /^Using\s+POE-(.+)$/ ) {
$test->{'poe'}->{'v_real'} = $1;
# the various queue/loop modules we loaded
# POE is using: POE::XS::Queue::Array v0.005
# POE is using: POE::Queue v1.2328
# POE is using: POE::Loop::EV v0.06
} elsif ( $l =~ /^POE\s+is\s+using:\s+([^\s]+)\s+v(.+)$/ ) {
$test->{'poe'}->{'modules'}->{ $1 } = $2;
# get the uname info
# Running under machine: Linux apoc-x300 2.6.24-21-generic #1 SMP Tue Oct 21 23:43:45 UTC 2008 i686 GNU/Linux
} elsif ( $l =~ /^Running\s+under\s+machine:\s+(.+)$/ ) {
$test->{'uname'} = $1;
# parse any STDERR output
# !STDERR: unable to foo
} elsif ( $l =~ /^\!STDERR:\s+(.+)$/ ) {
push( @{ $test->{'stderr'} }, $1 );
} else {
# unknown line :(
push( @unknown, $l );
}
}
# Get rid of the rawdata
delete $test->{'raw'};
# Dump the unknowns
if ( @unknown ) {
print "\n[ANALYZER] Unknown output from benchmark -> " . Dump( \@unknown );
}
# Dump the data struct we have to the file.yml
- my $yaml_file = 'results/' . delete $test->{'test'};
- $yaml_file .= '.yml';
+ my $yaml_file = File::Spec->catfile( 'results', ( delete $test->{'test'} ) . '.yml' );
my $ret = open( my $fh, '>', $yaml_file );
if ( defined $ret ) {
print $fh Dump( $test );
if ( ! close( $fh ) ) {
print "\n[ANALYZER] Unable to close $yaml_file -> " . $! . "\n";
}
} else {
print "\n[ANALYZER] Unable to open $yaml_file for writing -> " . $! . "\n";
}
# now that we've dumped the stuff, we can do some sanity checks
# the POE we "think" we loaded should match reality!
if ( exists $test->{'poe'}->{'v_real'} ) { # if this exists, then we successfully loaded POE
if ( $test->{'poe'}->{'v'} ne $test->{'poe'}->{'v_real'} ) {
print "\n[ANALYZER] The subprocess loaded a different version of POE than we thought -> $yaml_file\n";
}
# The loop we loaded should match what we wanted!
if ( exists $test->{'poe'}->{'modules'} ) {
if ( ! exists $test->{'poe'}->{'modules'}->{ $test->{'poe'}->{'loop'} } ) {
# gaah special-case for IO_Poll
if ( $test->{'poe'}->{'loop'} eq 'POE::Loop::IO_Poll' and exists $test->{'poe'}->{'modules'}->{'POE::Loop::Poll'} ) {
# ah, ignore this
} else {
print "\n[ANALYZER] The subprocess loaded a different Loop than we thought -> $yaml_file\n";
}
}
}
}
# the perl binary should be the same!
if ( exists $test->{'perl'} ) { # if this exists, we successfully fired up the app ( no compile error )
if ( $test->{'perl'}->{'binary'} ne $^X ) {
print "\n[ANALYZER] The subprocess booted up on a different perl binary -> $yaml_file\n";
}
if ( $test->{'perl'}->{'v'} ne sprintf( "%vd", $^V ) ) {
print "\n[ANALYZER] The subprocess booted up on a different perl version -> $yaml_file\n";
}
}
# all done!
return;
}
1;
__END__
+
+=for stopwords AnnoCPAN CPAN Caputo EV Eventloop Gtk HTTP Kqueue MYFH poe Prima RT SQLite STDIN SocketFactory TODO Tapout Wx XS YAML autoprobing backend benchmarker csv db dngor er freshstart hardcode litetests noasserts noxsqueue poedists pong svn untarred yml
+
=head1 NAME
POE::Devel::Benchmarker - Benchmarking POE's performance ( acts more like a smoker )
=head1 SYNOPSIS
- apoc@apoc-x300:~$ cd poe-benchmarker
- apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker -e 'benchmark()'
+ use POE::Devel::Benchmarker;
+ benchmark();
=head1 ABSTRACT
-This package of tools is designed to benchmark POE's performace across different
+This package of tools is designed to benchmark POE's performance across different
configurations. The current "tests" are:
=over 4
=item Events
posts: This tests how long it takes to post() N times
dispatches: This tests how long it took to dispatch/deliver all the posts enqueued in the "posts" test
single_posts: This tests how long it took to yield() between 2 states for N times
calls: This tests how long it took to call() N times
=item Alarms
alarms: This tests how long it took to add N alarms via alarm(), overwriting each other
alarm_adds: This tests how long it took to add N alarms via alarm_add()
alarm_clears: This tests how long it took to clear all alarms set in the "alarm_adds" test
NOTE: alarm_add is not available on all versions of POE!
=item Sessions
session_creates: This tests how long it took to create N sessions
session_destroys: This tests how long it took to destroy all sessions created in the "session_creates" test
=item Filehandles
select_read_STDIN: This tests how long it took to toggle select_read N times on STDIN
select_write_STDIN: This tests how long it took to toggle select_write N times on STDIN
select_read_MYFH: This tests how long it took to toggle select_read N times on a real filehandle
select_write_MYFH: This tests how long it took to toggle select_write N times on a real filehandle
NOTE: The MYFH tests don't include the time it took to open()/close() the file :)
=item Sockets
socket_connects: This tests how long it took to connect+disconnect to a SocketFactory server via localhost
socket_stream: This tests how long it took to send N chunks of data in a "ping-pong" fashion between the server and client
=item POE startup time
startups: This tests how long it took to start + close N instances of POE+Loop without any sessions/etc via system()
=item POE Loops
This is actually a "super" test where all of the specific tests is ran against various POE::Loop::XYZ/FOO for comparison
NOTE: Not all versions of POE support all Loops!
=item POE Assertions
This is actually a "super" test where all of the specific tests is ran against POE with/without assertions enabled
NOTE: Not all versions of POE support assertions!
=item POE::XS::Queue::Array
This is actually a "super" test where all of the specific tests is ran against POE with XS goodness enabled/disabled
NOTE: Not all versions of POE support XS::Queue::Array!
=back
=head1 DESCRIPTION
This module is poorly documented now. Please give me some time to properly document it over time :)
=head2 INSTALLATION
Here's a simple outline to get you up to speed quickly. ( and smoking! )
=over 4
=item Install CPAN package + dependencies
Download+install the POE::Devel::Benchmarker package from CPAN
apoc@apoc-x300:~$ cpanp -i POE::Devel::Benchmarker
=item Setup initial directories
Go anywhere, and create the "parent" directory where you'll be storing test results + stuff. For this example,
I have chosen to use ~/poe-benchmarker:
apoc@apoc-x300:~$ mkdir poe-benchmarker
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ mkdir poedists results images
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker::GetPOEdists -e 'getPOEdists( 1 )'
( go get a coffee while it downloads if you're on a slow link, ha! )
=item Let 'er rip!
At this point you can start running the benchmark!
NOTE: the Benchmarker expects everything to be in the "local" directory!
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker -e 'benchmark()'
( go sleep or something, this will take a while! )
=back
=head2 BENCHMARKING
On startup the Benchmarker will look in the "poedists" directory and load all the distributions it sees untarred there. Once
that is done it will begin autoprobing for available POE::Loop packages. Once it determines what's available, it will begin
the benchmarks.
As the Benchmarker goes through the combinations of POE + Eventloop + Assertions + XS::Queue it will dump data into
the results directory. The module also dumps YAML output in the same place, with the suffix of ".yml"
This module exposes only one subroutine, the benchmark() one. You can pass a hashref to it to set various options. Here is
a list of the valid options:
=over 4
=item freshstart => boolean
This will tell the Benchmarker to ignore any previous test runs stored in the 'results' directory. This will not delete
data from previous runs, only overwrite them. So be careful if you're mixing test runs from different versions!
benchmark( { freshstart => 1 } );
default: false
=item noxsqueue => boolean
This will tell the Benchmarker to force the unavailability of POE::XS::Queue::Array and skip those tests.
NOTE: The Benchmarker will set this automatically if it cannot load the module!
benchmark( { noxsqueue => 1 } );
default: false
=item noasserts => boolean
This will tell the Benchmarker to not run the ASSERT tests.
benchmark( { noasserts => 1 } );
default: false
=item litetests => boolean
This enables the "lite" tests which will not take up too much time.
benchmark( { litetests => 0 } );
default: true
=item quiet => boolean
This enables quiet mode which will not print anything to the console except for errors.
benchmark( { 'quiet' => 1 } );
default: false
=item loop => csv list or array
This overrides the built-in loop detection algorithm which searches for all known loops.
There is some "magic" here where you can put a negative sign in front of a loop and we will NOT run that.
NOTE: Capitalization is important!
benchmark( { 'loop' => 'IO_Poll,Select' } ); # runs only IO::Poll and Select
benchmark( { 'loop' => [ qw( Tk Gtk ) ] } ); # runs only Tk and Gtk
benchmark( { 'loop' => '-Tk' } ); # runs all available loops EXCEPT for TK
Known loops: Event_Lib EV Glib Prima Gtk Kqueue Tk Select IO_Poll
=item poe => csv list or array
This overrides the built-in POE version detection algorithm which pulls the POE versions from the 'poedists' directory.
There is some "magic" here where you can put a negative sign in front of a version and we will NOT run that.
NOTE: The Benchmarker will ignore versions that wasn't found in the directory!
benchmark( { 'poe' => '0.35,1.003' } ); # runs on 0.35 and 1.003
benchmark( { 'poe' => [ qw( 0.3009 0.12 ) ] } ); # runs on 0.3009 and 0.12
benchmark( { 'poe' => '-0.35' } ); # runs ALL tests except 0.35
=back
=head2 ANALYZING RESULTS
Please look at the pretty charts generated by the L<POE::Devel::Benchmarker::Imager> module.
=head1 EXPORT
Automatically exports the benchmark() subroutine.
=head1 TODO
=over 4
=item Perl version smoking
We should be able to run the benchmark over different Perl versions. This would require some fiddling with our
layout + logic. It's not that urgent because the workaround is to simply execute the benchmarker under a different
perl binary. It's smart enough to use $^X to be consistent across tests/subprocesses :)
=item Select the EV backend
<Khisanth> and if you are benchmarking, try it with POE using EV with EV using Glib? :P
<Apocalypse> I'm not sure how to configure the EV "backend" yet
<Apocalypse> too much docs for me to read hah
<Khisanth> Apocalypse: use EV::Glib; use Glib; use POE; :)
=item Be smarter in smoking timeouts
Currently we depend on the litetests option and hardcode some values including the timeout. If your machine is incredibly
slow, there's a chance that it could timeout unnecessarily. Please look at the outputs and check to see if there are unusual
failures, and inform me.
Also, some loops perform badly and take almost forever! /me glares at Gtk...
=item More benchmarks!
As usual, me and the crowd in #poe have plenty of ideas for tests. We'll be adding them over time, but if you have an idea please
drop me a line and let me know!
dngor said there was some benchmarks in the POE svn under trunk/queue...
<dngor> Apocalypse: Check out the old benchmarks in the queue directory in POE's repot.
They profile queue performance at various sizes, which is a better indication of scalability.
Tapout contributed a script that tests HTTP performance, let's see if it deserves to be in the suite :)
I added the preliminary socket tests, we definitely should expand it seeing how many people use POE for networking...
=item Add SQLite/DBI/etc support to the Analyzer
It would be nice if we could have a local SQLite db to dump our stats into. This would make arbitrary reports much easier than
loading raw YAML files and trying to make sense of them, ha! Also, this means somebody can do the smoking and send the SQLite
db to another person to generate the graphs, cool!
=item Kqueue loop support
As I don't have access to a *BSD box, I cannot really test this. Furthermore, it isn't clear on how I can force/unload this
module from POE...
=item Wx loop support
I have Wx installed, but it doesn't work. Obviously I don't know how to use Wx ;)
If you have experience, please drop me a line on how to do the "right" thing to get Wx loaded under POE. Here's the error:
Can't call method "MainLoop" on an undefined value at /usr/local/share/perl/5.8.8/POE/Loop/Wx.pm line 91.
=item XS::Loop support
The POE::XS::Loop::* modules theoretically could be tested too. However, they will only work in POE >= 1.003! This renders
the concept somewhat moot. Maybe, after POE has progressed some versions we can implement this...
=back
=head1 SEE ALSO
L<POE>
=head1 SUPPORT
You can find documentation for this module with the perldoc command.
perldoc POE::Devel::Benchmarker
=head2 Websites
=over 4
=item * AnnoCPAN: Annotated CPAN documentation
L<http://annocpan.org/dist/POE-Devel-Benchmarker>
=item * CPAN Ratings
L<http://cpanratings.perl.org/d/POE-Devel-Benchmarker>
=item * RT: CPAN's request tracker
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=POE-Devel-Benchmarker>
=item * Search CPAN
L<http://search.cpan.org/dist/POE-Devel-Benchmarker>
+=item * CPAN Testing Service
+
+L<http://cpants.perl.org/dist/overview/POE-Devel-Benchmarker>
+
=back
=head2 Bugs
Please report any bugs or feature requests to C<bug-poe-devel-benchmarker at rt.cpan.org>, or through
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=POE-Devel-Benchmarker>. I will be
notified, and then you'll automatically be notified of progress on your bug as I make changes.
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
BIG THANKS goes to Rocco Caputo E<lt>rcaputo@cpan.orgE<gt> for the first benchmarks!
=head1 COPYRIGHT AND LICENSE
-Copyright 2009 by Apocalypse
+Copyright 2010 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm b/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm
index e8f49e0..60a66fa 100644
--- a/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm
+++ b/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm
@@ -1,207 +1,207 @@
# Declare our package
package POE::Devel::Benchmarker::GetInstalledLoops;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
-$VERSION = '0.05';
+$VERSION = '0.06';
# auto-export the only sub we have
use base qw( Exporter );
our @EXPORT = qw( getPOEloops );
# Import what we need from the POE namespace
use POE qw( Session Filter::Line Wheel::Run );
use base 'POE::Session::AttributeBased';
# Get the utils
use POE::Devel::Benchmarker::Utils qw ( knownloops );
# analyzes the installed perl directory for available loops
sub getPOEloops {
my $quiet_mode = shift;
my $forceloops = shift;
# create our session!
POE::Session->create(
POE::Devel::Benchmarker::GetInstalledLoops->inline_states(),
'heap' => {
'quiet_mode' => $quiet_mode,
'loops' => $forceloops,
},
);
}
# Starts up our session
sub _start : State {
# set our alias
$_[KERNEL]->alias_set( 'Benchmarker::GetInstalledLoops' );
# load our known list of loops
# known impossible loops:
# XS::EPoll ( must be POE > 1.003 and weird way of loading )
# XS::Poll ( must be POE > 1.003 and weird way of loading )
if ( ! defined $_[HEAP]->{'loops'} ) {
$_[HEAP]->{'loops'} = knownloops();
}
# First of all, we need to find out what loop libraries are installed
$_[HEAP]->{'found_loops'} = [];
$_[KERNEL]->yield( 'find_loops' );
return;
}
sub _stop : State {
# tell the wheel to kill itself
if ( defined $_[HEAP]->{'WHEEL'} ) {
$_[HEAP]->{'WHEEL'}->kill( 9 );
undef $_[HEAP]->{'WHEEL'};
}
return;
}
# loops over the "known" loops and sees if they are installed
sub find_loops : State {
# get the loop to test
$_[HEAP]->{'current_loop'} = shift @{ $_[HEAP]->{'loops'} };
# do we have something to test?
if ( ! defined $_[HEAP]->{'current_loop'} ) {
# we're done!
$_[KERNEL]->alias_remove( 'Benchmarker::GetInstalledLoops' );
$_[KERNEL]->post( 'Benchmarker', 'found_loops', $_[HEAP]->{'found_loops'} );
return;
} else {
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[LOOPSEARCH] Trying to find if POE::Loop::" . $_[HEAP]->{'current_loop'} . " is installed...\n";
}
# set the flag
$_[HEAP]->{'test_failure'} = 0;
}
# Okay, create the wheel::run to handle this
$_[HEAP]->{'WHEEL'} = POE::Wheel::Run->new(
'Program' => $^X,
'ProgramArgs' => [ '-MPOE',
'-MPOE::Loop::' . $_[HEAP]->{'current_loop'},
'-e',
'1',
],
# Kill off existing FD's
'CloseOnCall' => 1,
# setup our data handlers
'StdoutEvent' => 'Got_STDOUT',
'StderrEvent' => 'Got_STDERR',
# the error handler
'ErrorEvent' => 'Got_ERROR',
'CloseEvent' => 'Got_CLOSED',
# set our filters
'StderrFilter' => POE::Filter::Line->new(),
'StdoutFilter' => POE::Filter::Line->new(),
);
if ( ! defined $_[HEAP]->{'WHEEL'} ) {
die '[LOOPSEARCH] Unable to create a new wheel!';
} else {
# smart CHLD handling
if ( $_[KERNEL]->can( "sig_child" ) ) {
$_[KERNEL]->sig_child( $_[HEAP]->{'WHEEL'}->PID => 'Got_CHLD' );
} else {
$_[KERNEL]->sig( 'CHLD', 'Got_CHLD' );
}
}
return;
}
# Got a CHLD event!
sub Got_CHLD : State {
$_[KERNEL]->sig_handled();
return;
}
# Handles child STDERR output
sub Got_STDERR : State {
my $input = $_[ARG0];
# since we got an error, must be a failure
$_[HEAP]->{'test_failure'} = 1;
return;
}
# Handles child STDOUT output
sub Got_STDOUT : State {
my $input = $_[ARG0];
return;
}
# Handles child error
sub Got_ERROR : State {
# Copied from POE::Wheel::Run manpage
my ( $operation, $errnum, $errstr ) = @_[ ARG0 .. ARG2 ];
# ignore exit 0 errors
if ( $errnum != 0 ) {
warn "Wheel::Run got an $operation error $errnum: $errstr\n";
}
return;
}
# Handles child DIE'ing
sub Got_CLOSED : State {
# Get rid of the wheel
undef $_[HEAP]->{'WHEEL'};
# Did we pass this test or not?
if ( ! $_[HEAP]->{'test_failure'} ) {
push( @{ $_[HEAP]->{'found_loops'} }, $_[HEAP]->{'current_loop'} );
}
# move on to the next loop
$_[KERNEL]->yield( 'find_loops' );
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::GetInstalledLoops - Automatically detects the installed POE loops
=head1 SYNOPSIS
- Don't use this module directly. Please use POE::Devel::Benchmarker.
+ die "Don't use this module directly. Please use POE::Devel::Benchmarker instead.";
=head1 ABSTRACT
This package implements the guts of searching for POE loops via fork/exec.
=head1 EXPORT
Automatically exports the getPOEloops() sub
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
-Copyright 2009 by Apocalypse
+Copyright 2010 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/GetPOEdists.pm b/lib/POE/Devel/Benchmarker/GetPOEdists.pm
index 118e7e4..b3fdff4 100644
--- a/lib/POE/Devel/Benchmarker/GetPOEdists.pm
+++ b/lib/POE/Devel/Benchmarker/GetPOEdists.pm
@@ -1,144 +1,150 @@
# Declare our package
package POE::Devel::Benchmarker::GetPOEdists;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
-$VERSION = '0.05';
+$VERSION = '0.06';
# auto-export the only sub we have
use base qw( Exporter );
our @EXPORT = qw( getPOEdists );
# import the helper modules
use LWP::UserAgent;
use HTML::LinkExtor;
use URI::URL;
use Archive::Tar;
# autoflush, please!
use IO::Handle;
STDOUT->autoflush( 1 );
# actually retrieves the dists!
sub getPOEdists {
# should we debug?
my $debug = shift;
# okay, should we change directory?
if ( -d 'poedists' ) {
if ( $debug ) {
print "[GETPOEDISTS] chdir( 'poedists' )\n";
}
if ( ! chdir( 'poedists' ) ) {
die "Unable to chdir to 'poedists' dir: $!";
}
} else {
if ( $debug ) {
print "[GETPOEDISTS] downloading to current directory\n";
}
}
# set the default URL
my $url = "http://backpan.cpan.org/authors/id/R/RC/RCAPUTO/";
# create our objects
my $ua = LWP::UserAgent->new;
my $p = HTML::LinkExtor->new;
my $tar = Archive::Tar->new;
# Request document and parse it as it arrives
print "Getting $url via LWP\n" if $debug;
my $res = $ua->request( HTTP::Request->new( GET => $url ),
sub { $p->parse( $_[0] ) },
);
# did we successfully download?
if ( $res->is_error ) {
die "unable to download directory index on BACKPAN: " . $res->status_line;
}
# Download every one!
foreach my $link ( $p->links ) {
# skip IMG stuff
if ( $link->[0] eq 'a' and $link->[1] eq 'href' ) {
# get the actual POE dists!
- if ( $link->[2] =~ /^POE\-\d/ and $link->[2] =~ /\.tar\.gz$/ ) {
+ if ( $link->[2] =~ /^POE\-\d.+\.tar\.gz$/ ) {
# download the tarball!
print "Mirroring $link->[2] via LWP\n" if $debug;
my $mirror_result = $ua->mirror( $url . $link->[2], $link->[2] );
if ( $mirror_result->is_error ) {
warn "unable to mirror $link->[2]: " . $mirror_result->status_line;
next;
}
# did we already untar this one?
my $dir = $link->[2];
$dir =~ s/\.tar\.gz$//;
if ( ! -d $dir ) {
# extract it!
print "Extracting $link->[2] via Tar\n" if $debug;
my $files = $tar->read( $link->[2], undef, { 'extract' => 'true' } );
if ( $files == 0 ) {
warn "unable to extract $link->[2]";
}
}
}
}
}
return;
}
1;
__END__
+
+=for stopwords BACKPAN LWP getPOEdists
+
=head1 NAME
POE::Devel::Benchmarker::GetPOEdists - Automatically download all POE tarballs
=head1 SYNOPSIS
- apoc@apoc-x300:~$ cd poe-benchmarker
- apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker::GetPOEdists -e 'getPOEdists()'
+ use POE::Devel::Benchmarker::GetPOEdists;
+ getPOEdists();
=head1 ABSTRACT
This package automatically downloads all the POE tarballs from BACKPAN.
=head1 DESCRIPTION
This uses LWP + HTML::LinkExtor to retrieve POE tarballs from BACKPAN.
The tarballs are automatically downloaded to the current directory. Then, we use Archive::Tar to extract them all!
NOTE: we use LWP's useful mirror() sub which doesn't re-download files if they already exist!
+ apoc@apoc-x300:~$ cd poe-benchmarker
+ apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker::GetPOEdists -e 'getPOEdists()'
+
=head2 getPOEdists
Normally you should pass nothing to this sub. However, if you want to debug the downloads+extractions you should pass
a true value as the first argument.
perl -MPOE::Devel::Benchmarker::GetPOEdists -e 'getPOEdists( 1 )'
=head1 EXPORT
Automatically exports the getPOEdists() sub
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
-Copyright 2009 by Apocalypse
+Copyright 2010 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/Imager.pm b/lib/POE/Devel/Benchmarker/Imager.pm
index 9b120af..367ecd2 100644
--- a/lib/POE/Devel/Benchmarker/Imager.pm
+++ b/lib/POE/Devel/Benchmarker/Imager.pm
@@ -1,450 +1,458 @@
# Declare our package
package POE::Devel::Benchmarker::Imager;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
-$VERSION = '0.05';
+$VERSION = '0.06';
# auto-export the only sub we have
use base qw( Exporter );
our @EXPORT = qw( imager );
# import the helper modules
use YAML::Tiny;
+use File::Spec;
# load our plugins!
use Module::Pluggable search_path => [ __PACKAGE__ ];
# load comparison stuff
use version;
# Get some stuff from Utils
use POE::Devel::Benchmarker::Utils qw( currentTestVersion );
# generate some accessors
use base qw( Class::Accessor::Fast );
__PACKAGE__->mk_ro_accessors( qw( poe_versions poe_versions_sorted poe_loops data
noxsqueue noasserts litetests quiet
) );
# autoflush, please!
use IO::Handle;
STDOUT->autoflush( 1 );
# starts the work of converting our data to images
sub imager {
my $options = shift;
# instantitate ourself
my $self = __PACKAGE__->new( $options );
# parse all of our YAML modules!
$self->loadtests;
# process some stats
$self->process_data;
# generate the images!
$self->generate_images;
return;
}
# creates a new instance
sub new {
my $class = shift;
my $opts = shift;
# instantitate ourself
my $self = {};
bless $self, $class;
# init the options
$self->init_options( $opts );
if ( ! $self->{'options'}->{'quiet'} ) {
print "[IMAGER] Starting up...\n";
}
return $self;
}
sub init_options {
my $self = shift;
my $options = shift;
# set defaults
$self->{'quiet'} = 0;
$self->{'litetests'} = 1;
$self->{'noasserts'} = undef;
$self->{'noxsqueue'} = undef;
# process our options
if ( defined $options and ref $options and ref( $options ) eq 'HASH' ) {
# process quiet mode
if ( exists $options->{'quiet'} ) {
if ( $options->{'quiet'} ) {
$self->{'quiet'} = 1;
} else {
$self->{'quiet'} = 0;
}
}
# process the LITE/HEAVY
if ( exists $options->{'litetests'} ) {
if ( $options->{'litetests'} ) {
$self->{'litetests'} = 1;
} else {
$self->{'litetests'} = 0;
}
}
# process the noasserts to load
if ( exists $options->{'noasserts'} ) {
if ( $options->{'noasserts'} ) {
$self->{'noasserts'} = 1;
} else {
$self->{'noasserts'} = 0;
}
}
# process the noxsqueue to load
if ( exists $options->{'noxsqueue'} ) {
if ( $options->{'noxsqueue'} ) {
$self->{'noxsqueue'} = 1;
} else {
$self->{'noxsqueue'} = 0;
}
}
# FIXME process the plugins to load -> "types"
# FIXME process the versions to load
# FIXME process the loops to load
}
# some sanity tests
if ( ! -d 'results' ) {
die "The 'results' directory is not found in the working directory!";
}
if ( ! -d 'images' ) {
die "The 'images' directory is not found in the working directory!";
}
return;
}
# starts the process of loading all of our YAML images
sub loadtests {
my $self = shift;
# gather all the YAML dumps
if ( opendir( DUMPS, 'results' ) ) {
foreach my $d ( readdir( DUMPS ) ) {
# parse the file structure
# POE-1.0002-IO_Poll-LITE-assert-noxsqueue.yml
if ( $d =~ /^POE\-([\d\.\_]+)\-(\w+?)\-(LITE|HEAVY)\-(noassert|assert)\-(noxsqueue|xsqueue)\.yml$/ ) {
my( $ver, $loop, $lite, $assert, $xsqueue ) = ( $1, $2, $3, $4, $5 );
# skip this file?
if ( $self->noxsqueue ) {
if ( $xsqueue eq 'xsqueue' ) { next }
} else {
if ( defined $self->noxsqueue ) {
if ( $xsqueue eq 'noxsqueue' ) { next }
}
}
if ( $self->noasserts ) {
if ( $assert eq 'assert' ) { next }
} else {
if ( defined $self->noasserts ) {
if ( $assert eq 'noassert' ) { next }
}
}
if ( $self->litetests ) {
if ( $lite eq 'HEAVY' ) { next }
} else {
if ( $lite eq 'LITE' ) { next }
}
# FIXME allow selective loading of tests, so we can control what to image, etc
# actually load this file!
$self->load_yaml( $d, $ver, $loop, $lite, $assert, $xsqueue );
}
}
closedir( DUMPS ) or die "[IMAGER] Unable to read from 'results' -> " . $!;
} else {
die "[IMAGER] Unable to open 'results' for reading -> " . $!;
}
# sanity
if ( ! exists $self->{'data'} ) {
die "[IMAGER] Unable to find valid POE test result(s) in the 'results' directory!\n";
}
if ( ! $self->quiet ) {
print "[IMAGER] Done with parsing the YAML files...\n";
}
return;
}
# loads the yaml of a specific file
sub load_yaml {
my ( $self, $file, $ver, $loop, $lite, $assert, $xsqueue ) = @_;
- my $yaml = YAML::Tiny->read( 'results/' . $file );
+ my $yaml = YAML::Tiny->read( File::Spec->catfile( 'results', $file ) );
if ( ! defined $yaml ) {
print "[IMAGER] Unable to load YAML file $file -> " . YAML::Tiny->errstr . "\n";
return;
} else {
# inrospect it!
my $isvalid = 0;
eval {
# simple sanity check: the "x_bench" param is at the end of the YML, so if it loads fine we know it's there
if ( defined $yaml->[0] and exists $yaml->[0]->{'x_bench'} ) {
# version must at least match us
$isvalid = ( $yaml->[0]->{'x_bench'} eq currentTestVersion() ? 1 : 0 );
} else {
$isvalid = undef;
}
};
if ( ! $isvalid or $@ ) {
print "[IMAGER] Detected outdated/corrupt benchmark result: $file";
return;
} else {
# reduce indirection
$yaml = $yaml->[0];
}
}
# store the POE version
$self->{'poe_versions'}->{ $ver } = 1;
# sanity check the loop master version ( which should always be our "installed" version, not per-POE )
if ( exists $yaml->{'poe'}->{'loop_m'} ) {
if ( ! defined $self->{'poe_loops'}->{ $loop } ) {
$self->{'poe_loops'}->{ $loop } = $yaml->{'poe'}->{'loop_m'};
} else {
if ( $self->{'poe_loops'}->{ $loop } ne $yaml->{'poe'}->{'loop_m'} ) {
die "[IMAGER] Detected POE::Loop master version inconsistency! $file reported '" . $yaml->{'poe'}->{'loop_m'} .
"' while others had '" . $self->{'poe_loops'}->{ $loop } . "'";
}
}
}
# get the info we're interested in
$self->{'data'}->{ $assert }->{ $xsqueue }->{ $ver }->{ $loop }->{'metrics'} = $yaml->{'metrics'};
$self->{'data'}->{ $assert }->{ $xsqueue }->{ $ver }->{ $loop }->{'time'} = $yaml->{'t'};
if ( exists $yaml->{'pid'} ) {
$self->{'data'}->{ $assert }->{ $xsqueue }->{ $ver }->{ $loop }->{'pid'} = $yaml->{'pid'};
}
if ( exists $yaml->{'poe'}->{'modules'} ) {
$self->{'data'}->{ $assert }->{ $xsqueue }->{ $ver }->{ $loop }->{'poe_modules'} = $yaml->{'poe'}->{'modules'};
}
# sanity check the perl stuff
if ( exists $yaml->{'perl'}->{'binary'} ) {
if ( ! exists $self->{'data'}->{'perlconfig'} ) {
$self->{'data'}->{'perlconfig'}->{'binary'} = $yaml->{'perl'}->{'binary'};
$self->{'data'}->{'perlconfig'}->{'version'} = $yaml->{'perl'}->{'v'};
} else {
if ( $self->{'data'}->{'perlconfig'}->{'binary'} ne $yaml->{'perl'}->{'binary'} ) {
die "[IMAGER] Detected perl binary inconsistency! $file reported '" . $yaml->{'perl'}->{'binary'} .
"' while others had '" . $self->{'data'}->{'perlconfig'}->{'binary'} . "'";
}
if ( $self->{'data'}->{'perlconfig'}->{'version'} ne $yaml->{'perl'}->{'v'} ) {
die "[IMAGER] Detected perl version inconsistency! $file reported '" . $yaml->{'perl'}->{'v'} .
"' while others had '" . $self->{'data'}->{'perlconfig'}->{'version'} . "'";
}
}
}
# sanity check the uname
if ( exists $yaml->{'uname'} ) {
if ( ! exists $self->{'data'}->{'uname'} ) {
$self->{'data'}->{'uname'} = $yaml->{'uname'};
} else {
if ( $self->{'data'}->{'uname'} ne $yaml->{'uname'} ) {
die "[IMAGER] Detected system inconsistency! $file reported '" . $yaml->{'uname'} .
"' while others had '" . $self->{'data'}->{'uname'} . "'";
}
}
}
# sanity check the cpu name
if ( exists $yaml->{'cpu'} ) {
if ( ! exists $self->{'data'}->{'cpu'} ) {
$self->{'data'}->{'cpu'} = $yaml->{'cpu'};
} else {
if ( $self->{'data'}->{'cpu'}->{'name'} ne $yaml->{'cpu'}->{'name'} ) {
die "[IMAGER] Detected system/cpu inconsistency! $file reported '" . $yaml->{'cpu'}->{'name'} .
"' while others had '" . $self->{'data'}->{'cpu'}->{'name'} . "'";
}
}
}
return;
}
sub process_data {
my $self = shift;
# sanitize the versions in an ordered loop
$self->{'poe_versions_sorted'} = [ map { $_->stringify }
sort { $a <=> $b }
map { version->new($_) } keys %{ $self->poe_versions }
];
if ( ! $self->quiet ) {
print "[IMAGER] Done with processing the benchmark statistics...\n";
}
return;
}
sub generate_images {
my $self = shift;
# load our plugins and let them have fun :)
foreach my $plugin ( $self->plugins ) {
# actually load it!
## no critic
eval "require $plugin";
## use critic
if ( $@ ) {
if ( ! $self->quiet ) {
print "[IMAGER] Unable to load plugin $plugin -> $@\n";
next;
}
}
# sanity checks
if ( $plugin->can( 'new' ) and $plugin->can( 'imager' ) ) {
# FIXME did we want this plugin?
# create the plugin's home dir
my $homedir = $plugin;
if ( $homedir =~ /\:\:(\w+)$/ ) {
$homedir = $1;
} else {
die "barf";
}
- if ( ! -d "images/$homedir" ) {
+ $homedir = File::Spec->catdir( 'images', $homedir );
+ if ( ! -d $homedir ) {
# create it!
- if ( ! mkdir( "images/$homedir" ) ) {
+ if ( ! mkdir( $homedir ) ) {
die "[IMAGER] Unable to create plugin directory: $homedir";
}
}
# Okay, get this plugin!
- my $obj = $plugin->new( { 'dir' => "images/$homedir/" } );
+ my $obj = $plugin->new( { 'dir' => $homedir } );
if ( ! $self->quiet ) {
print "[IMAGER] Processing the $plugin plugin...\n";
}
$obj->imager( $self );
}
}
if ( ! $self->quiet ) {
print "[IMAGER] Done with generating images...\n";
}
return;
}
1;
__END__
+
+=for stopwords YAML litetests namespace noassert noxsqueue plugin xsqueue
+
=head1 NAME
POE::Devel::Benchmarker::Imager - Automatically converts the benchmark data into images
=head1 SYNOPSIS
- apoc@apoc-x300:~$ cd poe-benchmarker
- apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker::Imager -e 'imager'
+ use POE::Devel::Benchmarker::Imager;
+ imager();
=head1 ABSTRACT
This package automatically parses the benchmark data and generates pretty charts.
=head1 DESCRIPTION
It will parse the YAML output from the benchmark data and calls it's plugins to generate any charts necessary
and place them in the 'images' directory under the plugin's name. This module only does the high-level stuff, and leaves
the actual chart generation to the plugins.
Furthermore, we use Module::Pluggable to search all modules in the POE::Devel::Benchmarker::Imager::* namespace and
let them handle the generation of images. That way virtually unlimited combinations of images can be generated on the fly
from the data this module parses.
+ apoc@apoc-x300:~$ cd poe-benchmarker
+ apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker::Imager -e 'imager'
+
The way to use this module is by calling the imager() subroutine and let it do it's job. You can pass a hashref to it to
set various options. Here is a list of the valid options:
=over 4
=item quiet => boolean
This enables quiet mode which will not print anything to the console except for errors.
- new( { 'quiet' => 1 } );
+ imager( { 'quiet' => 1 } );
default: false
=item noxsqueue => boolean / undef
This will tell the Imager to not consider those tests for the output.
- benchmark( { noxsqueue => 1 } );
+ imager( { noxsqueue => 1 } );
default: undef ( load both xsqueue and noxsqueue tests )
=item noasserts => boolean / undef
This will tell the Imager to not consider those tests for the output
- benchmark( { noasserts => 1 } );
+ imager( { noasserts => 1 } );
default: undef ( load both assert and noassert tests )
=item litetests => boolean
This will tell the Imager to not consider those tests for the output
- benchmark( { litetests => 0 } );
+ imager( { litetests => 0 } );
default: true
=back
=head1 PLUGIN INTERFACE
For now, this is undocumented. Please look at BasicStatistics for the general concept on how it interacts with this module.
=head1 EXPORT
Automatically exports the imager() sub
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
-Copyright 2009 by Apocalypse
+Copyright 2010 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/Imager/BasicStatistics.pm b/lib/POE/Devel/Benchmarker/Imager/BasicStatistics.pm
index c0f897a..512e10c 100644
--- a/lib/POE/Devel/Benchmarker/Imager/BasicStatistics.pm
+++ b/lib/POE/Devel/Benchmarker/Imager/BasicStatistics.pm
@@ -1,356 +1,360 @@
# Declare our package
package POE::Devel::Benchmarker::Imager::BasicStatistics;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
-$VERSION = '0.05';
+$VERSION = '0.06';
# the GD stuff
use GD::Graph::lines;
use GD::Graph::colour qw( :lists );
# import some stuff
use POE::Devel::Benchmarker::Utils qw( currentMetrics );
# creates a new instance
sub new {
my $class = shift;
my $opts = shift;
# instantitate ourself
my $self = {
'opts' => $opts,
};
return bless $self, $class;
}
# actually generates the graphs!
sub imager {
my $self = shift;
$self->{'imager'} = shift;
# generate the loops vs each other graphs
$self->generate_loopwars;
# generate the single loop performance
$self->generate_loopperf;
# generate the loop assert/xsqueue ( 4 lines ) per metric
$self->generate_loopoptions;
return;
}
# charts a single loop's progress over POE versions
sub generate_loopoptions {
my $self = shift;
if ( ! $self->{'imager'}->quiet ) {
print "[BasicStatistics] Generating the Loop-Options graphs...\n";
}
# go through all the loops we want
foreach my $loop ( keys %{ $self->{'imager'}->poe_loops } ) {
foreach my $metric ( @{ currentMetrics() } ) {
my %data;
# organize data by POE version
foreach my $poe ( @{ $self->{'imager'}->poe_versions_sorted } ) {
# go through the combo of assert/xsqueue
foreach my $assert ( qw( assert noassert ) ) {
if ( ! exists $self->{'imager'}->data->{ $assert } ) {
next;
}
foreach my $xsqueue ( qw( xsqueue noxsqueue ) ) {
if ( ! exists $self->{'imager'}->data->{ $assert }->{ $xsqueue } ) {
next;
}
# sometimes we cannot test a metric
if ( exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }
and exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
and defined $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
) {
push( @{ $data{ $assert . '_' . $xsqueue } }, $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'} );
} else {
push( @{ $data{ $assert . '_' . $xsqueue } }, 0 );
}
}
}
}
# it's possible for us to do runs without assert/xsqueue
if ( scalar keys %data > 0 ) {
# transform %data into something GD likes
my @data_for_gd;
foreach my $m ( sort keys %data ) {
push( @data_for_gd, $data{ $m } );
}
# send it to GD!
$self->make_gdgraph( 'Options_' . $loop . '_' . $metric,
[ sort keys %data ],
\@data_for_gd,
);
}
}
}
return;
}
# charts a single loop's progress over POE versions
sub generate_loopperf {
my $self = shift;
if ( ! $self->{'imager'}->quiet ) {
print "[BasicStatistics] Generating the Loop-Performance graphs...\n";
}
# go through all the loops we want
foreach my $loop ( keys %{ $self->{'imager'}->poe_loops } ) {
# go through the combo of assert/xsqueue
foreach my $assert ( qw( assert noassert ) ) {
if ( ! exists $self->{'imager'}->data->{ $assert } ) {
next;
}
foreach my $xsqueue ( qw( xsqueue noxsqueue ) ) {
if ( ! exists $self->{'imager'}->data->{ $assert }->{ $xsqueue } ) {
next;
}
my %data;
# organize data by POE version
foreach my $poe ( @{ $self->{'imager'}->poe_versions_sorted } ) {
foreach my $metric ( @{ currentMetrics() } ) {
# sometimes we cannot test a metric
if ( exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }
and exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
and defined $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
) {
push( @{ $data{ $metric } }, $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'} );
} else {
push( @{ $data{ $metric } }, 0 );
}
}
}
# transform %data into something GD likes
my @data_for_gd;
foreach my $m ( sort keys %data ) {
push( @data_for_gd, $data{ $m } );
}
# send it to GD!
$self->make_gdgraph( 'Bench_' . $loop,
[ sort keys %data ],
\@data_for_gd,
$assert,
$xsqueue,
);
}
}
}
return;
}
# loop wars!
sub generate_loopwars {
my $self = shift;
if ( ! $self->{'imager'}->quiet ) {
print "[BasicStatistics] Generating the LoopWars graphs...\n";
}
# go through all the metrics we want
foreach my $metric ( @{ currentMetrics() } ) {
# go through the combo of assert/xsqueue
foreach my $assert ( qw( assert noassert ) ) {
if ( ! exists $self->{'imager'}->data->{ $assert } ) {
next;
}
foreach my $xsqueue ( qw( xsqueue noxsqueue ) ) {
if ( ! exists $self->{'imager'}->data->{ $assert }->{ $xsqueue } ) {
next;
}
my %data;
# organize data by POE version
foreach my $poe ( @{ $self->{'imager'}->poe_versions_sorted } ) {
foreach my $loop ( keys %{ $self->{'imager'}->poe_loops } ) {
# sometimes we cannot test a metric
if ( exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }
and exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
and defined $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
) {
push( @{ $data{ $loop } }, $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'} );
} else {
push( @{ $data{ $loop } }, 0 );
}
}
}
# transform %data into something GD likes
my @data_for_gd;
foreach my $m ( sort keys %data ) {
push( @data_for_gd, $data{ $m } );
}
# send it to GD!
$self->make_gdgraph( "LoopWar_$metric",
[ sort keys %{ $self->{'imager'}->poe_loops } ],
\@data_for_gd,
$assert,
$xsqueue,
);
}
}
}
return;
}
sub make_gdgraph {
my $self = shift;
my $metric = shift;
my $legend = shift;
my $data = shift;
my $assert = shift;
my $xsqueue = shift;
# build the title
my $title = $metric;
if ( defined $assert ) {
$title .= ' (';
if ( defined $xsqueue ) {
$title .= $assert . ' ' . $xsqueue;
} else {
$title .= $assert;
}
$title .= ')';
} else {
if ( defined $xsqueue ) {
$title .= ' (' . $xsqueue . ')';
}
}
# Get the graph object
my $graph = new GD::Graph::lines( 800, 600 );
# Set some stuff
$graph->set(
'title' => $title,
'line_width' => 1,
'boxclr' => 'black',
'overwrite' => 0,
'x_labels_vertical' => 1,
'x_all_ticks' => 1,
'legend_placement' => 'BL',
'y_label' => 'iterations/sec',
'transparent' => 0,
'long_ticks' => 1,
) or die $graph->error;
# Set the legend
$graph->set_legend( @$legend );
# Set Font stuff
$graph->set_legend_font( GD::gdMediumBoldFont );
$graph->set_x_axis_font( GD::gdMediumBoldFont );
$graph->set_y_axis_font( GD::gdMediumBoldFont );
$graph->set_y_label_font( GD::gdMediumBoldFont );
$graph->set_title_font( GD::gdGiantFont );
# set the line colors
$graph->set( 'dclrs' => [ grep { $_ ne 'black' and $_ ne 'white' } sorted_colour_list() ] );
# Manufacture the data
my $readydata = [
[ map { 'POE-' . $_ } @{ $self->{'imager'}->poe_versions_sorted } ],
@$data,
];
# Plot it!
$graph->plot( $readydata ) or die $graph->error;
# Print it!
my $filename = $self->{'opts'}->{'dir'} . $metric . '_' .
( $self->{'imager'}->litetests ? 'lite' : 'heavy' ) .
( defined $xsqueue ? '_' . $assert . '_' . $xsqueue : '' ) .
'.png';
open( my $fh, '>', $filename ) or die 'Cannot open graph file!';
binmode( $fh );
print $fh $graph->gd->png();
close( $fh );
return;
}
1;
__END__
+
+=for stopwords backend
+
=head1 NAME
POE::Devel::Benchmarker::Imager::BasicStatistics - Plugin to generates basic statistics graphs
=head1 SYNOPSIS
- apoc@apoc-x300:~$ cd poe-benchmarker
- apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker::Imager -e 'imager( { type => "BasicStatistics" } )'
+ use POE::Devel::Benchmarker::Imager;
+ imager( { type => 'BasicStatistics' } );
=head1 ABSTRACT
This plugin for Imager generates some kinds of graphs from the benchmark tests.
=head1 DESCRIPTION
This package generates some basic graphs from the statistics output. Since the POE::Loop::* modules really are responsible
for the backend logic of POE, it makes sense to graph all related metrics of a single loop across POE versions to see if
it performs differently.
+ apoc@apoc-x300:~$ cd poe-benchmarker
+ apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker::Imager -e 'imager( { type => "BasicStatistics" } )'
+
This will generate some types of graphs:
=over 4
=item Loops against each other
Each metric will have a picture for itself, showing how each loop compare against each other with the POE versions.
file: BasicStatistics/LoopWar_$metric_$lite_$assert_$xsqueue.png
=item Single Loop over POE versions
Each Loop will have a picture for itself, showing how each metric performs over POE versions.
file: BasicStatistics/Bench_$loop_$lite_$assert_$xsqueue.png
=item Single Loop over POE versions with assert/xsqueue
Each Loop will have a picture for itself, showing how each metric is affected by the assert/xsqueue options.
file: BasicStatistics/Options_$loop_$metric_$lite.png
=back
-=head1 EXPORT
-
-Nothing.
-
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
+L<POE::Devel::Benchmarker::Imager>
+
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
-Copyright 2009 by Apocalypse
+Copyright 2010 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/SubProcess.pm b/lib/POE/Devel/Benchmarker/SubProcess.pm
index c45629b..b26c909 100644
--- a/lib/POE/Devel/Benchmarker/SubProcess.pm
+++ b/lib/POE/Devel/Benchmarker/SubProcess.pm
@@ -1,957 +1,943 @@
# Declare our package
package POE::Devel::Benchmarker::SubProcess;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
-$VERSION = '0.05';
+$VERSION = '0.06';
# set our compile-time stuff
BEGIN {
# should we enable assertions?
if ( defined $ARGV[1] and $ARGV[1] ) {
## no critic
eval "sub POE::Kernel::ASSERT_DEFAULT () { 1 }";
eval "sub POE::Session::ASSERT_STATES () { 1 }";
## use critic
}
# Compile a list of modules to hide
my $hide = '';
if ( defined $ARGV[0] ) {
if ( $ARGV[0] ne 'XSPoll' ) {
$hide .= ' POE/XS/Loop/Poll.pm';
}
if ( $ARGV[0] ne 'XSEPoll' ) {
$hide .= ' POE/XS/Loop/EPoll.pm';
}
}
# should we "hide" XS::Queue::Array?
if ( defined $ARGV[3] and $ARGV[3] ) {
$hide .= ' POE/XS/Queue/Array.pm';
}
# actually hide the modules!
{
## no critic
eval "use Devel::Hide qw( $hide )";
## use critic
}
}
-# process the eventloop
-BEGIN {
- # FIXME figure out a better way to load loop with precision based on POE version
-# if ( defined $ARGV[0] ) {
-# eval "use POE::Kernel; use POE::Loop::$ARGV[0]";
-# if ( $@ ) { die $@ }
-# }
-}
-
# Import Time::HiRes's time()
use Time::HiRes qw( time );
# load POE
use POE;
use POE::Session;
use POE::Wheel::SocketFactory;
use POE::Wheel::ReadWrite;
use POE::Filter::Line;
use POE::Driver::SysRW;
# autoflush, please!
use IO::Handle;
STDOUT->autoflush( 1 );
# import some stuff
use Socket qw( INADDR_ANY sockaddr_in );
# we need to compare versions
use version;
# load our utility stuff
use POE::Devel::Benchmarker::Utils qw( loop2realversion poeloop2load currentMetrics );
# init our global variables ( bad, haha )
my( $eventloop, $asserts, $lite_tests, $pocosession );
# setup our metrics and their data
my %metrics = map { $_ => undef } @{ currentMetrics() };
# the main routine which will load everything + start
sub benchmark {
# process the eventloop
process_eventloop();
# process the assertions
process_assertions();
# process the test mode
process_testmode();
# process the XS::Queue hiding
process_xsqueue();
# actually import POE!
process_POE();
# actually run the benchmarks!
run_benchmarks();
# all done!
return;
}
sub process_eventloop {
# Get the desired mode
$eventloop = $ARGV[0];
# print out the loop info
if ( ! defined $eventloop ) {
die "Please supply an event loop!";
} else {
my $loop = poeloop2load( $eventloop );
if ( ! defined $loop ) {
$loop = $eventloop;
}
my $v = loop2realversion( $eventloop );
if ( ! defined $v ) {
$v = 'UNKNOWN';
}
print "Using master loop: $loop-$v\n";
}
return;
}
sub process_assertions {
# Get the desired assert mode
$asserts = $ARGV[1];
if ( defined $asserts and $asserts ) {
print "Using FULL Assertions!\n";
} else {
print "Using NO Assertions!\n";
}
return;
}
sub process_testmode {
# get the desired test mode
$lite_tests = $ARGV[2];
# setup most of the metrics
$metrics{'startups'} = 10;
# event tests
foreach my $s ( qw( posts dispatches calls single_posts ) ) {
$metrics{ $s } = 10_000;
}
# session tests
foreach my $s ( qw( session_creates session_destroys ) ) {
$metrics{ $s } = 500;
}
# alarm tests
foreach my $s ( qw( alarms alarm_adds alarm_clears ) ) {
$metrics{ $s } = 10_000;
}
# select tests
foreach my $s ( qw( select_read_STDIN select_write_STDIN select_read_MYFH select_write_MYFH ) ) {
$metrics{ $s } = 10_000;
}
# socket tests
foreach my $s ( qw( socket_connects socket_stream ) ) {
$metrics{ $s } = 1_000;
}
if ( defined $lite_tests and $lite_tests ) {
print "Using the LITE tests\n";
} else {
print "Using the HEAVY tests\n";
# we simply multiply each metric by 10x
foreach my $s ( @{ currentMetrics() } ) {
$metrics{ $s } = $metrics{ $s } * 10;
}
}
return;
}
sub process_xsqueue {
# should we "hide" XS::Queue::Array?
if ( defined $ARGV[3] and $ARGV[3] ) {
print "DISABLING POE::XS::Queue::Array\n";
} else {
print "LETTING POE find POE::XS::Queue::Array\n";
}
return;
}
sub process_POE {
# Print the POE info
print "Using POE-" . $POE::VERSION . "\n";
# Actually print what loop POE is using
foreach my $m ( keys %INC ) {
if ( $m =~ /^POE\/(?:Loop|XS|Queue)/ ) {
# try to be smart and get version?
my $module = $m;
$module =~ s|/|::|g;
$module =~ s/\.pm$//g;
print "POE is using: $module ";
if ( defined $module->VERSION ) {
print "v" . $module->VERSION . "\n";
} else {
print "vUNKNOWN\n";
}
}
}
return;
}
sub run_benchmarks {
# dump some misc info
dump_perlinfo();
dump_sysinfo();
# run the startup test before we actually run POE
bench_startup();
# load the POE session + do the tests there
bench_poe();
# okay, dump our memory usage
dump_pidinfo();
# all done!
return;
}
sub bench_startup {
# Add the eventloop?
my $looploader = poeloop2load( $eventloop );
my @start_times = times();
my $start = time();
for (my $i = 0; $i < $metrics{'startups'}; $i++) {
- # FIXME should we add assertions?
+ # We do not care about assert/xsqueue for startups, so we don't include them here...
# finally, fire it up!
CORE::system(
$^X,
'-Ipoedists/POE-' . $POE::VERSION,
'-Ipoedists/POE-' . $POE::VERSION . '/lib',
( defined $looploader ? "-M$looploader" : () ),
- '-MPOE',
'-e',
- 1,
+ $asserts ? 'sub POE::Kernel::ASSERT_DEFAULT () { 1 } sub POE::Session::ASSERT_STATES () { 1 } use POE; 1;' : 'use POE; 1;',
);
}
my @end_times = times();
my $elapsed = time() - $start;
printf( "\n\n% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'startups'}, 'startups', $elapsed, $metrics{'startups'}/$elapsed );
print "startups times: @start_times @end_times\n";
return;
}
sub bench_poe {
# figure out POE::Session->create or POE::Session->new or what?
$pocosession = POE::Session->can( 'create' );
if ( defined $pocosession ) {
$pocosession = 'create';
} else {
$pocosession = POE::Session->can( 'spawn' );
if ( defined $pocosession ) {
$pocosession = 'spawn';
} else {
$pocosession = 'new';
}
}
# create the master sesssion + run POE!
POE::Session->$pocosession(
'inline_states' => {
# basic POE states
'_start' => \&poe__start,
'_default' => \&poe__default,
'_stop' => \&poe__stop,
'null' => \&poe_null,
# our test states
'posts' => \&poe_posts,
'posts_start' => \&poe_posts_start,
'posts_end' => \&poe_posts_end,
'alarms' => \&poe_alarms,
'manyalarms' => \&poe_manyalarms,
'sessions' => \&poe_sessions,
'sessions_end' => \&poe_sessions_end,
'stdin_read' => \&poe_stdin_read,
'stdin_write' => \&poe_stdin_write,
'myfh_read' => \&poe_myfh_read,
'myfh_write' => \&poe_myfh_write,
'calls' => \&poe_calls,
'eventsquirt' => \&poe_eventsquirt,
'eventsquirt_done' => \&poe_eventsquirt_done,
'socketfactory' => \&poe_socketfactory,
'socketfactory_start' => \&poe_socketfactory_start,
'socketfactory_connects' => \&poe_socketfactory_connects,
'socketfactory_stream' => \&poe_socketfactory_stream,
'socketfactory_cleanup' => \&poe_socketfactory_cleanup,
# misc states for test stuff
'server_sf_connect' => \&poe_server_sf_connect,
'server_sf_failure' => \&poe_server_sf_failure,
'server_rw_input' => \&poe_server_rw_input,
'server_rw_error' => \&poe_server_rw_error,
'client_sf_connect' => \&poe_client_sf_connect,
'client_sf_failure' => \&poe_client_sf_failure,
'client_rw_input' => \&poe_client_rw_input,
'client_rw_error' => \&poe_client_rw_error,
},
);
# start the kernel!
POE::Kernel->run();
return;
}
# inits our session
sub poe__start {
# fire off the first test!
$_[KERNEL]->yield( 'posts' );
return;
}
sub poe__stop {
}
sub poe__default {
return 0;
}
# a state that does nothing
sub poe_null {
return 1;
}
# How many posts per second? Post a bunch of events, keeping track of the time it takes.
sub poe_posts {
$_[KERNEL]->yield( 'posts_start' );
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $metrics{'posts'}; $i++) {
$_[KERNEL]->yield( 'null' );
}
my @end_times = times();
my $elapsed = time() - $start;
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'posts'}, 'posts', $elapsed, $metrics{'posts'}/$elapsed );
print "posts times: @start_times @end_times\n";
$_[KERNEL]->yield( 'posts_end' );
return;
}
sub poe_posts_start {
$_[HEAP]->{start} = time();
$_[HEAP]->{starttimes} = [ times() ];
return;
}
sub poe_posts_end {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'dispatches'}, 'dispatches', $elapsed, $metrics{'dispatches'}/$elapsed );
print "dispatches times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
$_[KERNEL]->yield( 'alarms' );
return;
}
# How many alarms per second? Set a bunch of alarms and find out.
sub poe_alarms {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $metrics{'alarms'}; $i++) {
$_[KERNEL]->alarm( whee => rand(1_000_000) );
}
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'alarms'}, 'alarms', $elapsed, $metrics{'alarms'}/$elapsed );
print "alarms times: @start_times @end_times\n";
$_[KERNEL]->alarm( 'whee' => undef );
$_[KERNEL]->yield( 'manyalarms' );
return;
}
# How many repetitive alarms per second? Set a bunch of
# additional alarms and find out. Also see how quickly they can
# be cleared.
sub poe_manyalarms {
# can this POE::Kernel support this?
if ( $_[KERNEL]->can( 'alarm_add' ) ) {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $metrics{'alarm_adds'}; $i++) {
$_[KERNEL]->alarm_add( whee => rand(1_000_000) );
}
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'alarm_adds'}, 'alarm_adds', $elapsed, $metrics{'alarm_adds'}/$elapsed );
print "alarm_adds times: @start_times @end_times\n";
$start = time();
@start_times = times();
$_[KERNEL]->alarm( whee => undef );
$elapsed = time() - $start;
@end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'alarm_adds'}, 'alarm_clears', $elapsed, $metrics{'alarm_adds'}/$elapsed );
print "alarm_clears times: @start_times @end_times\n";
} else {
print "SKIPPING br0ken alarm_adds because alarm_add() NOT SUPPORTED on this version of POE\n";
print "SKIPPING br0ken alarm_clears because alarm_add() NOT SUPPORTED on this version of POE\n";
}
$_[KERNEL]->yield( 'sessions' );
return;
}
# How many sessions can we create and destroy per second?
# Create a bunch of sessions, and track that time. Let them
# self-destruct, and track that as well.
sub poe_sessions {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $metrics{'session_creates'}; $i++) {
POE::Session->$pocosession( 'inline_states' => { _start => sub {}, _stop => sub {}, _default => sub { return 0 } } );
}
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'session_creates'}, 'session_creates', $elapsed, $metrics{'session_creates'}/$elapsed );
print "session_creates times: @start_times @end_times\n";
$_[KERNEL]->yield( 'sessions_end' );
$_[HEAP]->{start} = time();
$_[HEAP]->{starttimes} = [ times() ];
return;
}
sub poe_sessions_end {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'session_creates'}, 'session_destroys', $elapsed, $metrics{'session_creates'}/$elapsed );
print "session_destroys times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
$_[KERNEL]->yield( 'stdin_read' );
return;
}
# How many times can we select/unselect READ a from STDIN filehandle per second?
sub poe_stdin_read {
# stupid, but we have to skip those tests
if ( $eventloop eq 'Tk' or $eventloop eq 'Prima' ) {
print "SKIPPING br0ken select_read_STDIN because eventloop doesn't work: $eventloop\n";
print "SKIPPING br0ken select_write_STDIN because eventloop doesn't work: $eventloop\n";
$_[KERNEL]->yield( 'myfh_read' );
return;
}
my $start = time();
my @start_times = times();
eval {
for (my $i = 0; $i < $metrics{'select_read_STDIN'}; $i++) {
$_[KERNEL]->select_read( *STDIN, 'whee' );
$_[KERNEL]->select_read( *STDIN );
}
};
if ( $@ ) {
print "SKIPPING br0ken select_read_STDIN because FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'select_read_STDIN'}, 'select_read_STDIN', $elapsed, $metrics{'select_read_STDIN'}/$elapsed );
print "select_read_STDIN times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'stdin_write' );
return;
}
# How many times can we select/unselect WRITE a from STDIN filehandle per second?
sub poe_stdin_write {
my $start = time();
my @start_times = times();
eval {
for (my $i = 0; $i < $metrics{'select_write_STDIN'}; $i++) {
$_[KERNEL]->select_write( *STDIN, 'whee' );
$_[KERNEL]->select_write( *STDIN );
}
};
if ( $@ ) {
print "SKIPPING br0ken select_write_STDIN because FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'select_write_STDIN'}, 'select_write_STDIN', $elapsed, $metrics{'select_write_STDIN'}/$elapsed );
print "select_write_STDIN times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'myfh_read' );
return;
}
# How many times can we select/unselect READ a real filehandle?
sub poe_myfh_read {
# stupid, but we have to skip those tests
if ( $eventloop eq 'Event_Lib' or $eventloop eq 'Tk' or $eventloop eq 'Prima' ) {
print "SKIPPING br0ken select_read_MYFH because eventloop doesn't work: $eventloop\n";
print "SKIPPING br0ken select_write_MYFH because eventloop doesn't work: $eventloop\n";
$_[KERNEL]->yield( 'calls' );
return;
}
my $start = time();
my @start_times = times();
eval {
open( my $fh, '+>', 'poebench' ) or die $!;
for (my $i = 0; $i < $metrics{'select_read_MYFH'}; $i++) {
$_[KERNEL]->select_read( $fh, 'whee' );
$_[KERNEL]->select_read( $fh );
}
close( $fh ) or die $!;
unlink( 'poebench' ) or die $!;
};
if ( $@ ) {
print "SKIPPING br0ken select_read_MYFH because FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'select_read_MYFH'}, 'select_read_MYFH', $elapsed, $metrics{'select_read_MYFH'}/$elapsed );
print "select_read_MYFH times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'myfh_write' );
return;
}
# How many times can we select/unselect WRITE a real filehandle?
sub poe_myfh_write {
my $start = time();
my @start_times = times();
eval {
open( my $fh, '+>', 'poebench' ) or die $!;
for (my $i = 0; $i < $metrics{'select_write_MYFH'}; $i++) {
$_[KERNEL]->select_write( $fh, 'whee' );
$_[KERNEL]->select_write( $fh );
}
close( $fh ) or die $!;
unlink( 'poebench' ) or die $!;
};
if ( $@ ) {
print "SKIPPING br0ken select_write_MYFH because FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'select_write_MYFH'}, 'select_write_MYFH', $elapsed, $metrics{'select_write_MYFH'}/$elapsed );
print "select_write_MYFH times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'calls' );
return;
}
# How many times can we call a state?
sub poe_calls {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $metrics{'calls'}; $i++) {
$_[KERNEL]->call( $_[SESSION], 'null' );
}
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'calls'}, 'calls', $elapsed, $metrics{'calls'}/$elapsed );
print "calls times: @start_times @end_times\n";
$_[KERNEL]->yield( 'eventsquirt' );
return;
}
# How many events can we squirt through POE, one at a time?
sub poe_eventsquirt {
$_[HEAP]->{start} = time();
$_[HEAP]->{starttimes} = [ times() ];
$_[HEAP]->{yield_count} = $metrics{'single_posts'};
$_[KERNEL]->yield( 'eventsquirt_done' );
return;
}
sub poe_eventsquirt_done {
if (--$_[HEAP]->{yield_count}) {
$_[KERNEL]->yield( 'eventsquirt_done' );
} else {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'single_posts'}, 'single_posts', $elapsed, $metrics{'single_posts'}/$elapsed );
print "single_posts times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
$_[KERNEL]->yield( 'socketfactory' );
}
return;
}
# tests socketfactory interactions
sub poe_socketfactory {
# POE transitioned between Event to State on 0.19 for SocketFactory/ReadWrite
# 0.20+ throws deprecation error :(
$_[HEAP]->{'POE_naming'} = 'Event';
if ( version->new( $POE::VERSION ) < version->new( '0.20' ) ) {
$_[HEAP]->{'POE_naming'} = 'State';
}
# create the socketfactory server
$_[HEAP]->{'SF'} = POE::Wheel::SocketFactory->new(
'Port' => INADDR_ANY,
'Address' => 'localhost',
'Reuse' => 'yes',
'Success' . $_[HEAP]->{'POE_naming'} => 'server_sf_connect',
'Failure' . $_[HEAP]->{'POE_naming'} => 'server_sf_failure',
);
# be evil, and get the port for the client to connect to
( $_[HEAP]->{'SF_port'}, undef ) = sockaddr_in( getsockname( $_[HEAP]->{'SF'}->[ POE::Wheel::SocketFactory::MY_SOCKET_HANDLE() ] ) );
# start the connect tests
$_[HEAP]->{'SF_counter'} = $metrics{'socket_connects'};
$_[HEAP]->{'SF_mode'} = 'socket_connects';
$_[HEAP]->{'start'} = time();
$_[HEAP]->{'starttimes'} = [ times() ];
$_[KERNEL]->yield( 'socketfactory_connects' );
return;
}
# handles SocketFactory connection
sub poe_server_sf_connect {
# what test mode?
if ( $_[HEAP]->{'SF_mode'} eq 'socket_connects' ) {
# simply discard this socket
} elsif ( $_[HEAP]->{'SF_mode'} eq 'socket_stream' ) {
# convert it to ReadWrite
my $wheel = POE::Wheel::ReadWrite->new(
'Handle' => $_[ARG0],
'Filter' => POE::Filter::Line->new,
'Driver' => POE::Driver::SysRW->new,
'Input' . $_[HEAP]->{'POE_naming'} => 'server_rw_input',
'Error' . $_[HEAP]->{'POE_naming'} => 'server_rw_error',
);
# save it in our heap
$_[HEAP]->{'RW'}->{ $wheel->ID } = $wheel;
} else {
die "unknown test mode";
}
return;
}
# handles SocketFactory errors
sub poe_server_sf_failure {
# ARGH, we couldnt create listening socket
print "SKIPPING br0ken socket_connects because we were unable to setup listening socket\n";
print "SKIPPING br0ken socket_stream because we were unable to setup listening socket\n";
$_[KERNEL]->yield( 'socketfactory_cleanup' );
return;
}
# handles ReadWrite input
sub poe_server_rw_input {
# what test mode?
if ( $_[HEAP]->{'SF_mode'} eq 'socket_connects' ) {
# simply discard this data
} elsif ( $_[HEAP]->{'SF_mode'} eq 'socket_stream' ) {
# send it back to the client!
$_[HEAP]->{'RW'}->{ $_[ARG1] }->put( $_[ARG0] );
} else {
die "unknown test mode";
}
return;
}
# handles ReadWrite disconnects
sub poe_server_rw_error {
# simply get rid of the wheel
if ( exists $_[HEAP]->{'RW'}->{ $_[ARG3] } ) {
- # FIXME do we need this?
+ # shutdown everything, so we don't have any lingering sockets
eval {
$_[HEAP]->{'RW'}->{ $_[ARG3] }->shutdown_input;
$_[HEAP]->{'RW'}->{ $_[ARG3] }->shutdown_output;
};
delete $_[HEAP]->{'RW'}->{ $_[ARG3] };
}
return;
}
# starts the client connect tests
sub poe_socketfactory_connects {
if (--$_[HEAP]->{'SF_counter'}) {
# open a new client connection!
$_[HEAP]->{'client_SF'} = POE::Wheel::SocketFactory->new(
'RemoteAddress' => 'localhost',
'RemotePort' => $_[HEAP]->{'SF_port'},
'Success' . $_[HEAP]->{'POE_naming'} => 'client_sf_connect',
'Failure' . $_[HEAP]->{'POE_naming'} => 'client_sf_failure',
);
} else {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'socket_connects'}, 'socket_connects', $elapsed, $metrics{'socket_connects'}/$elapsed );
print "socket_connects times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
$_[KERNEL]->yield( 'socketfactory_stream' );
}
return;
}
# starts the client stream tests
sub poe_socketfactory_stream {
# set the proper test mode
$_[HEAP]->{'SF_mode'} = 'socket_stream';
# open a new client connection!
$_[HEAP]->{'client_SF'} = POE::Wheel::SocketFactory->new(
'RemoteAddress' => 'localhost',
'RemotePort' => $_[HEAP]->{'SF_port'},
'Success' . $_[HEAP]->{'POE_naming'} => 'client_sf_connect',
'Failure' . $_[HEAP]->{'POE_naming'} => 'client_sf_failure',
);
return;
}
# the client connected to the server!
sub poe_client_sf_connect {
# what test mode?
if ( $_[HEAP]->{'SF_mode'} eq 'socket_connects' ) {
# simply discard this connection
delete $_[HEAP]->{'client_SF'};
# make another connection!
$_[KERNEL]->yield( 'socketfactory_connects' );
} elsif ( $_[HEAP]->{'SF_mode'} eq 'socket_stream' ) {
# convert it to ReadWrite
my $wheel = POE::Wheel::ReadWrite->new(
'Handle' => $_[ARG0],
'Filter' => POE::Filter::Line->new,
'Driver' => POE::Driver::SysRW->new,
'Input' . $_[HEAP]->{'POE_naming'} => 'client_rw_input',
'Error' . $_[HEAP]->{'POE_naming'} => 'client_rw_error',
);
# save it in our heap
$_[HEAP]->{'client_RW'}->{ $wheel->ID } = $wheel;
# begin the STREAM test!
$_[HEAP]->{'SF_counter'} = $metrics{'socket_stream'};
$_[HEAP]->{'SF_data'} = 'x' x ( $metrics{'socket_stream'} / 10 ); # set a reasonable-sized chunk of data
$_[HEAP]->{'start'} = time();
$_[HEAP]->{'starttimes'} = [ times() ];
$wheel->put( $_[HEAP]->{'SF_data'} );
} else {
die "unknown test mode";
}
return;
}
# handles SocketFactory errors
sub poe_client_sf_failure {
# ARGH, we couldnt create connecting socket
if ( $_[HEAP]->{'SF_mode'} eq 'socket_connects' ) {
print "SKIPPING br0ken socket_connects because we were unable to setup connecting socket\n";
# go to stream test
$_[KERNEL]->yield( 'socketfactory_stream' );
} elsif ( $_[HEAP]->{'SF_mode'} eq 'socket_stream' ) {
print "SKIPPING br0ken socket_stream because we were unable to setup connecting socket\n";
$_[KERNEL]->yield( 'socketfactory_cleanup' );
}
return;
}
# handles ReadWrite input
sub poe_client_rw_input {
if (--$_[HEAP]->{'SF_counter'}) {
# send it back to the server!
$_[HEAP]->{'client_RW'}->{ $_[ARG1] }->put( $_[ARG0] );
} else {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'socket_stream'}, 'socket_stream', $elapsed, $metrics{'socket_stream'}/$elapsed );
print "socket_stream times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
$_[KERNEL]->yield( 'socketfactory_cleanup' );
}
return;
}
# handles ReadWrite disconnect
sub poe_client_rw_error {
# simply get rid of the wheel
if ( exists $_[HEAP]->{'client_RW'}->{ $_[ARG3] } ) {
- # FIXME do we need this?
+ # shutdown everything, so we don't have any lingering sockets
eval {
$_[HEAP]->{'client_RW'}->{ $_[ARG3] }->shutdown_input;
$_[HEAP]->{'client_RW'}->{ $_[ARG3] }->shutdown_output;
};
delete $_[HEAP]->{'client_RW'}->{ $_[ARG3] };
}
return;
}
# all done with the socketfactory tests
sub poe_socketfactory_cleanup {
# do cleanup
delete $_[HEAP]->{'SF'} if exists $_[HEAP]->{'SF'};
delete $_[HEAP]->{'RW'} if exists $_[HEAP]->{'RW'};
delete $_[HEAP]->{'client_SF'} if exists $_[HEAP]->{'client_SF'};
delete $_[HEAP]->{'client_RW'} if exists $_[HEAP]->{'client_RW'};
- # XXX all done with tests!
+ # all done with tests!
return;
}
# Get the memory footprint
sub dump_pidinfo {
my $ret = open( my $fh, '<', '/proc/self/status' );
if ( defined $ret ) {
while ( <$fh> ) {
chomp;
if ( $_ ne '' ) {
print "pidinfo: $_\n";
}
}
close( $fh ) or die $!;
} else {
print "UNABLE TO GET /proc/self/status\n";
}
return;
}
# print the local Perl info
sub dump_perlinfo {
print "Running under perl binary: '" . $^X . "' v" . sprintf( "%vd", $^V ) . "\n";
require Config;
my $config = Config::myconfig();
foreach my $l ( split( /\n/, $config ) ) {
print "perlconfig: $l\n";
}
return;
}
# print the local system information
sub dump_sysinfo {
print "Running under machine: " . `uname -a` . "\n";
# get cpuinfo
my $ret = open( my $fh, '<', '/proc/cpuinfo' );
if ( defined $ret ) {
while ( <$fh> ) {
chomp;
if ( $_ ne '' ) {
print "cpuinfo: $_\n";
}
}
close( $fh ) or die $!;
} else {
print "UNABLE TO GET /proc/cpuinfo\n";
}
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::SubProcess - Implements the actual POE benchmarks
=head1 SYNOPSIS
- perl -MPOE::Devel::Benchmarker::SubProcess -e 'benchmark()'
+ die "Don't use this module directly. Please use POE::Devel::Benchmarker instead.";
=head1 ABSTRACT
This package is responsible for implementing the guts of the benchmarks, and timing them.
-=head1 EXPORT
-
-Nothing.
-
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
-Copyright 2009 by Apocalypse
+Copyright 2010 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/Utils.pm b/lib/POE/Devel/Benchmarker/Utils.pm
index 58ae260..7e19f22 100644
--- a/lib/POE/Devel/Benchmarker/Utils.pm
+++ b/lib/POE/Devel/Benchmarker/Utils.pm
@@ -1,236 +1,243 @@
# Declare our package
package POE::Devel::Benchmarker::Utils;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
-$VERSION = '0.05';
+$VERSION = '0.06';
# set ourself up for exporting
use base qw( Exporter );
our @EXPORT_OK = qw( poeloop2load load2poeloop loop2realversion beautify_times knownloops generateTestfile
currentMetrics currentTestVersion
);
# returns the current test output version
sub currentTestVersion {
return '1';
}
# returns the list of current metrics
sub currentMetrics {
return [ qw(
startups
alarms alarm_adds alarm_clears
dispatches posts single_posts
session_creates session_destroys
select_read_MYFH select_write_MYFH select_read_STDIN select_write_STDIN
socket_connects socket_stream
) ];
}
# returns the filename for a particular test
sub generateTestfile {
my $heap = shift;
return 'POE-' . $heap->{'current_version'} .
'-' . $heap->{'current_loop'} .
'-' . ( $heap->{'lite_tests'} ? 'LITE' : 'HEAVY' ) .
'-' . ( $heap->{'current_assertions'} ? 'assert' : 'noassert' ) .
'-' . ( $heap->{'current_noxsqueue'} ? 'noxsqueue' : 'xsqueue' );
}
# maintains the mapping of the loop <-> real module
my %poe2load = (
'Event' => 'Event',
'IO_Poll' => 'IO::Poll',
'Event_Lib' => 'Event::Lib',
'EV' => 'EV',
'Glib' => 'Glib',
'Tk' => 'Tk',
'Gtk' => 'Gtk',
'Prima' => 'Prima',
'Wx' => 'Wx',
'Kqueue' => undef,
'Select' => undef,
);
# returns the proper "load" stuff for a specific loop
sub poeloop2load {
my $eventloop = shift;
if ( exists $poe2load{ $eventloop } ) {
return $poe2load{ $eventloop };
} else {
die "Unknown event loop!";
}
}
# returns the version of the "real" installed module that the loop uses
sub loop2realversion {
my $eventloop = shift;
# Decide which event loop to use
if ( ! defined $eventloop ) {
return;
} elsif ( $eventloop eq 'Event' ) {
return $Event::VERSION;
} elsif ( $eventloop eq 'IO_Poll' ) {
return $IO::Poll::VERSION;
} elsif ( $eventloop eq 'Event_Lib' ) {
return $Event::Lib::VERSION;
} elsif ( $eventloop eq 'EV' ) {
return $EV::VERSION;
} elsif ( $eventloop eq 'Glib' ) {
return $Glib::VERSION;
} elsif ( $eventloop eq 'Tk' ) {
return $Tk::VERSION;
} elsif ( $eventloop eq 'Gtk' ) {
return $Gtk::VERSION;
} elsif ( $eventloop eq 'Prima' ) {
return $Prima::VERSION;
} elsif ( $eventloop eq 'Wx' ) {
return $Wx::VERSION;
} elsif ( $eventloop eq 'Kqueue' ) {
# FIXME how do I do this?
return;
} elsif ( $eventloop eq 'Select' ) {
return 'BUILTIN';
# FIXME figure the XS stuff out!
# } elsif ( $eventloop eq 'XSPoll' ) {
# return $POE::XS::Loop::Poll::VERSION;
# } elsif ( $eventloop eq 'XSEpoll' ) {
# return $POE::XS::Loop::EPoll::VERSION;
} else {
die "Unknown event loop!";
}
}
# helper routine to parse times() output
sub beautify_times {
my $string = shift;
my $origdata = shift;
# split it up
$string =~ s/^\s+//; $string =~ s/\s+$//;
my @times = split( /\s+/, $string );
# make the data struct
# ($user,$system,$cuser,$csystem) = times;
my $data = {
'u' => $times[4] - $times[0],
's' => $times[5] - $times[1],
'cu' => $times[6] - $times[2],
'cs' => $times[7] - $times[3],
};
# add original data?
if ( $origdata ) {
$data->{'s_user'} = $times[0];
$data->{'s_sys'} = $times[1];
$data->{'s_cuser'} = $times[2];
$data->{'s_csys'} = $times[3];
$data->{'e_user'} = $times[4];
$data->{'e_sys'} = $times[5];
$data->{'e_cuser'} = $times[6];
$data->{'e_csys'} = $times[7];
}
# send it back!
return $data;
}
# returns a list of "known" POE loops
sub knownloops {
# FIXME we remove Wx because I suck.
# FIXME I have no idea how to load/unload Kqueue...
# FIXME figure out the XS stuff! XSPoll XSEPoll
return [ qw( Event_Lib EV Glib Prima Gtk Tk Select IO_Poll ) ];
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::Utils - Various utility routines for POE::Devel::Benchmarker
=head1 SYNOPSIS
- perl -MPOE::Devel::Benchmarker::Utils -e 'print poeloop2load( "IO_Poll" )'
+ use POE::Devel::Benchmarker::Utils qw( poeloop2load );
+ print poeloop2load( "IO_Poll" );
=head1 ABSTRACT
This package contains the utility routines and constants that POE::Devel::Benchmarker needs.
=head1 EXPORT
This package exports those subs via @EXPORT_OK:
=over 4
=item currentTestVersion()
Returns the current test version, used to identify different versions of the test output
=item currentMetrics()
Returns an arrayref of the current benchmark "metrics" that we process
=item knownloops()
Returns an arrayref of the "known" POE loops as of this version of the Benchmarker
=item poeloop2load()
Returns the "parent" class to load for a specific loop. An example is:
$real = poeloop2load( 'IO_Poll' ); # $real now contains "IO::Poll"
=item loop2realversion()
Returns the version of the "parent" class for a specific loop. An example is:
$ver = loop2realversion( 'IO_Poll' ); # $ver now contains $IO::Poll::VERSION
=item beautify_times()
Returns a hashref of data from parsing 2 consecutive times() structures in a string. You can pass an additional parameter
( boolean ) to include the original data. An example is:
print Data::Dumper::Dumper( beautify_times( '0.1 0 0 0 0.1 0 0.76 0.09', 1 ) );
{
"sys" => 0, # total system time
"user" => 0, # total user time
"csys" => 0.76 # total children system time
"cuser" => 0.08 # total children user time
"e_csys" => "0.09", # end children system time ( optional )
"e_cuser" => "0.76", # end children user time ( optional )
"e_sys" => 0, # end system time ( optional )
"e_user" => "0.1", # end user time ( optional )
"s_csys" => 0, # start children system time ( optional )
"s_cuser" => 0, # start children user time ( optional )
"s_sys" => 0, # start system time ( optional )
"s_user" => "0.1" # start user time ( optional )
}
+=item generateTestfile()
+
+Internal method, accepts the POE HEAP as an argument and returns the filename of the test.
+
+ my $file = generateTestfile( $_[HEAP] );
+
=back
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
-Copyright 2009 by Apocalypse
+Copyright 2010 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/t/1_load.t b/t/1_load.t
index 031289a..b74909a 100644
--- a/t/1_load.t
+++ b/t/1_load.t
@@ -1,15 +1,23 @@
#!/usr/bin/perl
+use strict; use warnings;
-# Import the stuff
-# XXX no idea why this is broken for this particular dist!
-#use Test::UseAllModules;
-#BEGIN { all_uses_ok(); }
+my $numtests;
+BEGIN {
+ $numtests = 7;
+
+ eval "use Test::NoWarnings";
+ if ( ! $@ ) {
+ # increment by one
+ $numtests++;
+ }
+}
+
+use Test::More tests => $numtests;
-use Test::More tests => 7;
-use_ok( 'POE::Devel::Benchmarker' );
use_ok( 'POE::Devel::Benchmarker::SubProcess' );
use_ok( 'POE::Devel::Benchmarker::GetInstalledLoops' );
use_ok( 'POE::Devel::Benchmarker::GetPOEdists' );
use_ok( 'POE::Devel::Benchmarker::Utils' );
-use_ok( 'POE::Devel::Benchmarker::Imager' );
use_ok( 'POE::Devel::Benchmarker::Imager::BasicStatistics' );
+use_ok( 'POE::Devel::Benchmarker::Imager' );
+use_ok( 'POE::Devel::Benchmarker' );
diff --git a/t/a_compile.t b/t/a_compile.t
deleted file mode 100644
index 4b1abfc..0000000
--- a/t/a_compile.t
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/usr/bin/perl
-
-use Test::More;
-
-# AUTHOR test
-if ( not $ENV{TEST_AUTHOR} ) {
- plan skip_all => 'Author test. Sent $ENV{TEST_AUTHOR} to a true value to run.';
-} else {
- eval "use Test::Compile";
- if ( $@ ) {
- plan skip_all => 'Test::Compile required for validating the perl files';
- } else {
- all_pm_files_ok();
- }
-}
diff --git a/t/a_critic.t b/t/a_critic.t
deleted file mode 100644
index 7e30808..0000000
--- a/t/a_critic.t
+++ /dev/null
@@ -1,26 +0,0 @@
-#!/usr/bin/perl
-
-use Test::More;
-
-# AUTHOR test
-if ( not $ENV{TEST_AUTHOR} ) {
- plan skip_all => 'Author test. Sent $ENV{TEST_AUTHOR} to a true value to run.';
-} else {
- if ( not $ENV{PERL_TEST_CRITIC} ) {
- plan skip_all => 'PerlCritic test. Sent $ENV{PERL_TEST_CRITIC} to a true value to run.';
- } else {
- # did we get a severity level?
- if ( length $ENV{PERL_TEST_CRITIC} > 1 ) {
- eval "use Test::Perl::Critic ( -severity => \"$ENV{PERL_TEST_CRITIC}\" );";
- } else {
- eval "use Test::Perl::Critic;";
- #eval "use Test::Perl::Critic ( -severity => 'stern' );";
- }
-
- if ( $@ ) {
- plan skip_all => 'Test::Perl::Critic required to criticise perl files';
- } else {
- all_critic_ok( 'lib/' );
- }
- }
-}
diff --git a/t/a_dependencies.t b/t/a_dependencies.t
deleted file mode 100644
index a27f64a..0000000
--- a/t/a_dependencies.t
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/usr/bin/perl
-
-use Test::More;
-
-# AUTHOR test
-if ( not $ENV{TEST_AUTHOR} ) {
- plan skip_all => 'Author test. Sent $ENV{TEST_AUTHOR} to a true value to run.';
-} else {
- eval "use Test::Dependencies exclude => [ qw/ POE::Devel::Benchmarker Module::Build / ], style => 'light';";
- if ( $@ ) {
- plan skip_all => 'Test::Dependencies required to test perl module deps';
- } else {
- ok_dependencies();
- }
-}
diff --git a/t/a_distribution.t b/t/a_distribution.t
deleted file mode 100644
index 27f7831..0000000
--- a/t/a_distribution.t
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/usr/bin/perl
-
-use Test::More;
-
-# AUTHOR test
-if ( not $ENV{TEST_AUTHOR} ) {
- plan skip_all => 'Author test. Sent $ENV{TEST_AUTHOR} to a true value to run.';
-} else {
- eval "require Test::Distribution";
- if ( $@ ) {
- plan skip_all => 'Test::Distribution required for validating the dist';
- } else {
- Test::Distribution->import( not => 'podcover' );
- }
-}
diff --git a/t/a_dosnewline.t b/t/a_dosnewline.t
deleted file mode 100644
index 89bcd54..0000000
--- a/t/a_dosnewline.t
+++ /dev/null
@@ -1,35 +0,0 @@
-#!/usr/bin/perl
-
-use Test::More;
-
-# AUTHOR test
-if ( not $ENV{TEST_AUTHOR} ) {
- plan skip_all => 'Author test. Sent $ENV{TEST_AUTHOR} to a true value to run.';
-} else {
- eval "use File::Find::Rule";
- if ( $@ ) {
- plan skip_all => 'File::Find::Rule required for checking for presence of DOS newlines';
- } else {
- plan tests => 1;
-
- # generate the file list
- my $rule = File::Find::Rule->new;
- $rule->grep( qr/\r\n/ );
- my @files = $rule->in( qw( lib t ) );
-
- # FIXME read in MANIFEST.SKIP and use it!
- # for now, we skip SVN + git stuff
- @files = grep { $_ !~ /(?:\/\.svn\/|\/\.git\/)/ } @files;
-
- # do we have any?
- if ( scalar @files ) {
- fail( 'newline check' );
- diag( 'DOS newlines found in these files:' );
- foreach my $f ( @files ) {
- diag( ' ' . $f );
- }
- } else {
- pass( 'newline check' );
- }
- }
-}
diff --git a/t/a_fixme.t b/t/a_fixme.t
deleted file mode 100644
index 627cc08..0000000
--- a/t/a_fixme.t
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/usr/bin/perl
-
-use Test::More;
-
-# AUTHOR test
-if ( not $ENV{TEST_AUTHOR} ) {
- plan skip_all => 'Author test. Sent $ENV{TEST_AUTHOR} to a true value to run.';
-} else {
- eval "use Test::Fixme";
- if ( $@ ) {
- plan skip_all => 'Test::Fixme required for checking for presence of FIXMEs';
- } else {
- run_tests(
- 'where' => 'lib',
- 'match' => qr/FIXME|TODO/,
- );
- }
-}
diff --git a/t/a_hasversion.t b/t/a_hasversion.t
deleted file mode 100644
index 9491779..0000000
--- a/t/a_hasversion.t
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/usr/bin/perl
-
-use Test::More;
-
-# AUTHOR test
-if ( not $ENV{TEST_AUTHOR} ) {
- plan skip_all => 'Author test. Sent $ENV{TEST_AUTHOR} to a true value to run.';
-} else {
- eval "use Test::HasVersion";
- if ( $@ ) {
- plan skip_all => 'Test::HasVersion required for testing for version numbers';
- } else {
- all_pm_version_ok();
- }
-}
diff --git a/t/a_is_prereq_outdated.t b/t/a_is_prereq_outdated.t
deleted file mode 100644
index ed1f17f..0000000
--- a/t/a_is_prereq_outdated.t
+++ /dev/null
@@ -1,126 +0,0 @@
-#!/usr/bin/perl
-use strict;
-use warnings;
-use Test::More;
-
-# AUTHOR test
-if ( not $ENV{TEST_AUTHOR} ) {
- plan skip_all => 'Author test. Sent $ENV{TEST_AUTHOR} to a true value to run.';
-} else {
- # can we load YAML?
- eval "use YAML";
- if ( $@ ) {
- plan skip_all => 'YAML is necessary to check META.yml for prerequisites!';
- }
-
- # can we load CPANPLUS?
- eval "use CPANPLUS::Backend";
- if ( $@ ) {
- plan skip_all => 'CPANPLUS is necessary to check module versions!';
- }
-
- # can we load version.pm?
- eval "use version";
- if ( $@ ) {
- plan skip_all => 'version.pm is necessary to compare versions!';
- }
-
- # does META.yml exist?
- if ( -e 'META.yml' and -f _ ) {
- load_yml( 'META.yml' );
- } else {
- # maybe one directory up?
- if ( -e '../META.yml' and -f _ ) {
- load_yml( '../META.yml' );
- } else {
- plan skip_all => 'META.yml is missing, unable to process it!';
- }
- }
-}
-
-# main entry point
-sub load_yml {
- # we'll load a file
- my $file = shift;
-
- # okay, proceed to load it!
- my $data;
- eval {
- $data = YAML::LoadFile( $file );
- };
- if ( $@ ) {
- plan skip_all => "Unable to load $file => $@";
- } else {
- note( "Loaded $file, proceeding with analysis" );
- }
-
- # massage the data
- $data = $data->{'requires'};
- delete $data->{'perl'} if exists $data->{'perl'};
-
- # FIXME shut up warnings ( eval's fault, blame it! )
- require version;
-
- # init the backend ( and set some options )
- my $cpanconfig = CPANPLUS::Configure->new;
- $cpanconfig->set_conf( 'verbose' => 0 );
- $cpanconfig->set_conf( 'no_update' => 1 );
- my $cpanplus = CPANPLUS::Backend->new( $cpanconfig );
-
- # silence CPANPLUS!
- {
- no warnings 'redefine';
- eval "sub Log::Message::Handlers::cp_msg { return }";
- eval "sub Log::Message::Handlers::cp_error { return }";
- }
-
- # Okay, how many prereqs do we have?
- plan tests => scalar keys %$data;
-
- # analyze every one of them!
- foreach my $prereq ( keys %$data ) {
- check_cpan( $cpanplus, $prereq, $data->{ $prereq } );
- }
-}
-
-# checks a prereq against CPAN
-sub check_cpan {
- my $backend = shift;
- my $prereq = shift;
- my $version = shift;
-
- # check CPANPLUS
- my $module = $backend->parse_module( 'module' => $prereq );
- if ( defined $module ) {
- # okay, for starters we check to see if it's version 0 then we skip it
- if ( $version eq '0' ) {
- ok( 1, "Skipping '$prereq' because it is specified as version 0" );
- return;
- }
-
- # Does the prereq have funky characters that we're unable to process now?
- if ( $version =~ /[<>=,!]+/ ) {
- # FIXME simplistic style of parsing
- my @versions = split( ',', $version );
-
- # sort them by version, descending
- s/[\s<>=!]+// for @versions;
- @versions = sort { $b <=> $a }
- map { version->new( $_ ) } @versions;
-
- # pick the highest version to use as comparison
- $version = $versions[0];
- }
-
- # convert both objects to version objects so we can compare
- $version = version->new( $version ) if ! ref $version;
- my $cpanversion = version->new( $module->version );
-
- # check it!
- is( $cpanversion, $version, "Comparing '$prereq' to CPAN version" );
- } else {
- ok( 0, "Warning: '$prereq' is not found on CPAN!" );
- }
-
- return;
-}
diff --git a/t/a_kwalitee.t b/t/a_kwalitee.t
deleted file mode 100644
index ff0f7d7..0000000
--- a/t/a_kwalitee.t
+++ /dev/null
@@ -1,40 +0,0 @@
-#!/usr/bin/perl
-
-use Test::More;
-
-# AUTHOR test
-if ( not $ENV{TEST_AUTHOR} ) {
- plan skip_all => 'Author test. Sent $ENV{TEST_AUTHOR} to a true value to run.';
-} else {
- eval "require Test::Kwalitee";
- if ( $@ ) {
- plan skip_all => 'Test::Kwalitee required for measuring the kwalitee';
- } else {
- Test::Kwalitee->import();
-
- # That piece of crap dumps files all over :(
- cleanup_debian_files();
- }
-}
-
-# Module::CPANTS::Kwalitee::Distros suck!
-#t/a_manifest..............1/1
-## Failed test at t/a_manifest.t line 13.
-## got: 1
-## expected: 0
-## The following files are not named in the MANIFEST file: /home/apoc/workspace/VCS-perl-trunk/VCS-2.12.2/Debian_CPANTS.txt
-## Looks like you failed 1 test of 1.
-#t/a_manifest.............. Dubious, test returned 1 (wstat 256, 0x100)
-sub cleanup_debian_files {
- foreach my $file ( qw( Debian_CPANTS.txt ../Debian_CPANTS.txt ) ) {
- if ( -e $file and -f _ ) {
- my $status = unlink( $file );
- if ( ! $status ) {
- warn "unable to unlink $file";
- }
- }
- }
-
- return;
-}
-
diff --git a/t/a_manifest.t b/t/a_manifest.t
deleted file mode 100644
index 57e9de1..0000000
--- a/t/a_manifest.t
+++ /dev/null
@@ -1,17 +0,0 @@
-#!/usr/bin/perl
-
-use Test::More;
-
-# AUTHOR test
-if ( not $ENV{TEST_AUTHOR} ) {
- plan skip_all => 'Author test. Sent $ENV{TEST_AUTHOR} to a true value to run.';
-} else {
- eval "use Test::CheckManifest";
- if ( $@ ) {
- plan skip_all => 'Test::CheckManifest required for validating the MANIFEST';
- } else {
- ok_manifest( {
- 'filter' => [ qr/\.svn/, qr/\.git/, qr/\.tar\.gz$/ ],
- } );
- }
-}
diff --git a/t/a_metayml.t b/t/a_metayml.t
deleted file mode 100644
index 66562f0..0000000
--- a/t/a_metayml.t
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/usr/bin/perl
-
-use Test::More;
-
-# AUTHOR test
-if ( not $ENV{TEST_AUTHOR} ) {
- plan skip_all => 'Author test. Sent $ENV{TEST_AUTHOR} to a true value to run.';
-} else {
- eval "use Test::YAML::Meta";
- if ( $@ ) {
- plan skip_all => 'Test::YAML::Meta required for validating the meta.yml file';
- } else {
- meta_yaml_ok();
- }
-}
diff --git a/t/a_minimumversion.t b/t/a_minimumversion.t
deleted file mode 100644
index d1c9977..0000000
--- a/t/a_minimumversion.t
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/usr/bin/perl
-
-use Test::More;
-
-# AUTHOR test
-if ( not $ENV{TEST_AUTHOR} ) {
- plan skip_all => 'Author test. Sent $ENV{TEST_AUTHOR} to a true value to run.';
-} else {
- eval "use Test::MinimumVersion";
- if ( $@ ) {
- plan skip_all => 'Test::MinimumVersion required to test minimum perl version';
- } else {
- all_minimum_version_from_metayml_ok();
- }
-}
diff --git a/t/a_perlmetrics.t b/t/a_perlmetrics.t
deleted file mode 100644
index 36db637..0000000
--- a/t/a_perlmetrics.t
+++ /dev/null
@@ -1,63 +0,0 @@
-#!/usr/bin/perl
-
-use Test::More;
-
-# AUTHOR test
-if ( not $ENV{TEST_AUTHOR} ) {
- plan skip_all => 'Author test. Sent $ENV{TEST_AUTHOR} to a true value to run.';
-} else {
- eval "use Perl::Metrics::Simple";
- if ( $@ ) {
- plan skip_all => 'Perl::Metrics::Simple required to analyze code metrics';
- } else {
- # do it!
- plan tests => 1;
- my $analzyer = Perl::Metrics::Simple->new;
- my $analysis = $analzyer->analyze_files( 'lib/' );
-
- if ( ok( $analysis->file_count(), 'analyzed at least one file' ) ) {
- # only print extra stuff if necessary
- if ( $ENV{TEST_VERBOSE} ) {
- diag( '-- Perl Metrics Summary ( countperl ) --' );
- diag( ' File Count: ' . $analysis->file_count );
- diag( ' Package Count: ' . $analysis->package_count );
- diag( ' Subroutine Count: ' . $analysis->sub_count );
- diag( ' Total Code Lines: ' . $analysis->lines );
- diag( ' Non-Sub Lines: ' . $analysis->main_stats->{'lines'} );
-
- diag( '-- Subrotuine Metrics Summary --' );
- my $summary_stats = $analysis->summary_stats;
- diag( ' Min: lines(' . $summary_stats->{sub_length}->{min} . ') McCabe(' . $summary_stats->{sub_complexity}->{min} . ')' );
- diag( ' Max: lines(' . $summary_stats->{sub_length}->{max} . ') McCabe(' . $summary_stats->{sub_complexity}->{max} . ')' );
- diag( ' Mean: lines(' . $summary_stats->{sub_length}->{mean} . ') McCabe(' . $summary_stats->{sub_complexity}->{mean} . ')' );
- diag( ' Standard Deviation: lines(' . $summary_stats->{sub_length}->{standard_deviation} . ') McCabe(' . $summary_stats->{sub_complexity}->{standard_deviation} . ')' );
- diag( ' Median: lines(' . $summary_stats->{sub_length}->{median} . ') McCabe(' . $summary_stats->{sub_complexity}->{median} . ')' );
-
- # set number of subs to display
- my $num = 10;
-
- diag( "-- Top$num subroutines by McCabe Complexity --" );
- my @sorted_subs = sort { $b->{'mccabe_complexity'} <=> $a->{'mccabe_complexity'} } @{ $analysis->subs };
- foreach my $i ( 0 .. ( $num - 1 ) ) {
- diag( ' ' . $sorted_subs[$i]->{'path'} . ':' . $sorted_subs[$i]->{'name'} . ' ->' .
- ' McCabe(' . $sorted_subs[$i]->{'mccabe_complexity'} . ')' .
- ' lines(' . $sorted_subs[$i]->{'lines'} . ')'
- );
- }
-
- diag( "-- Top$num subroutines by lines --" );
- @sorted_subs = sort { $b->{'lines'} <=> $a->{'lines'} } @sorted_subs;
- foreach my $i ( 0 .. ( $num - 1 ) ) {
- diag( ' ' . $sorted_subs[$i]->{'path'} . ':' . $sorted_subs[$i]->{'name'} . ' ->' .
- ' lines(' . $sorted_subs[$i]->{'lines'} . ')' .
- ' McCabe(' . $sorted_subs[$i]->{'mccabe_complexity'} . ')'
- );
- }
-
- #require Data::Dumper;
- #diag( 'Summary Stats: ' . Data::Dumper::Dumper( $analysis->summary_stats ) );
- #diag( 'File Stats: ' . Data::Dumper::Dumper( $analysis->file_stats ) );
- }
- }
- }
-}
diff --git a/t/a_pod.t b/t/a_pod.t
deleted file mode 100644
index 45420d5..0000000
--- a/t/a_pod.t
+++ /dev/null
@@ -1,19 +0,0 @@
-#!/usr/bin/perl
-
-use Test::More;
-
-# AUTHOR test
-if ( not $ENV{TEST_AUTHOR} ) {
- plan skip_all => 'Author test. Sent $ENV{TEST_AUTHOR} to a true value to run.';
-} else {
- if ( not $ENV{PERL_TEST_POD} ) {
- plan skip_all => 'POD test. Sent $ENV{PERL_TEST_POD} to a true value to run.';
- } else {
- eval "use Test::Pod";
- if ( $@ ) {
- plan skip_all => 'Test::Pod required for testing POD';
- } else {
- all_pod_files_ok();
- }
- }
-}
diff --git a/t/a_pod_coverage.t b/t/a_pod_coverage.t
deleted file mode 100644
index 49a5413..0000000
--- a/t/a_pod_coverage.t
+++ /dev/null
@@ -1,21 +0,0 @@
-#!/usr/bin/perl
-
-use Test::More;
-
-# AUTHOR test
-if ( not $ENV{TEST_AUTHOR} ) {
- plan skip_all => 'Author test. Sent $ENV{TEST_AUTHOR} to a true value to run.';
-} else {
- if ( not $ENV{PERL_TEST_POD} ) {
- plan skip_all => 'POD test. Sent $ENV{PERL_TEST_POD} to a true value to run.';
- } else {
- eval "use Test::Pod::Coverage";
- if ( $@ ) {
- plan skip_all => "Test::Pod::Coverage required for testing POD coverage";
- } else {
- # FIXME not used now
- #all_pod_coverage_ok( 'lib/');
- plan skip_all => 'not done yet';
- }
- }
-}
diff --git a/t/a_pod_spelling.t b/t/a_pod_spelling.t
deleted file mode 100644
index d622cf7..0000000
--- a/t/a_pod_spelling.t
+++ /dev/null
@@ -1,20 +0,0 @@
-#!/usr/bin/perl
-
-use Test::More;
-
-# AUTHOR test
-if ( not $ENV{TEST_AUTHOR} ) {
- plan skip_all => 'Author test. Sent $ENV{TEST_AUTHOR} to a true value to run.';
-} else {
- if ( not $ENV{PERL_TEST_POD} ) {
- plan skip_all => 'POD test. Sent $ENV{PERL_TEST_POD} to a true value to run.';
- } else {
- eval "use Test::Spelling";
- if ( $@ ) {
- plan skip_all => 'Test::Spelling required to test POD for spelling errors';
- } else {
- #all_pod_files_spelling_ok();
- plan skip_all => 'need to figure out how to add custom vocabulary to dictionary';
- }
- }
-}
diff --git a/t/a_prereq.t b/t/a_prereq.t
deleted file mode 100644
index 4633fb9..0000000
--- a/t/a_prereq.t
+++ /dev/null
@@ -1,19 +0,0 @@
-#!/usr/bin/perl
-
-use Test::More;
-
-# AUTHOR test
-if ( not $ENV{TEST_AUTHOR} ) {
- plan skip_all => 'Author test. Sent $ENV{TEST_AUTHOR} to a true value to run.';
-} else {
- if ( not $ENV{PERL_TEST_PREREQ} ) {
- plan skip_all => 'PREREQ test ( warning: LONG! ) Sent $ENV{PERL_TEST_PREREQ} to a true value to run.';
- } else {
- eval "use Test::Prereq";
- if ( $@ ) {
- plan skip_all => 'Test::Prereq required to test perl module deps';
- } else {
- prereq_ok();
- }
- }
-}
diff --git a/t/a_prereq_build.t b/t/a_prereq_build.t
deleted file mode 100644
index 5b2df60..0000000
--- a/t/a_prereq_build.t
+++ /dev/null
@@ -1,19 +0,0 @@
-#!/usr/bin/perl
-
-use Test::More;
-
-# AUTHOR test
-if ( not $ENV{TEST_AUTHOR} ) {
- plan skip_all => 'Author test. Sent $ENV{TEST_AUTHOR} to a true value to run.';
-} else {
- if ( not $ENV{PERL_TEST_PREREQ} ) {
- plan skip_all => 'PREREQ test ( warning: LONG! ) Sent $ENV{PERL_TEST_PREREQ} to a true value to run.';
- } else {
- eval "use Test::Prereq::Build";
- if ( $@ ) {
- plan skip_all => 'Test::Prereq required to test perl module deps';
- } else {
- prereq_ok();
- }
- }
-}
diff --git a/t/a_strict.t b/t/a_strict.t
deleted file mode 100644
index 021cb78..0000000
--- a/t/a_strict.t
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/usr/bin/perl
-
-use Test::More;
-
-# AUTHOR test
-if ( not $ENV{TEST_AUTHOR} ) {
- plan skip_all => 'Author test. Sent $ENV{TEST_AUTHOR} to a true value to run.';
-} else {
- eval "use Test::Strict";
- if ( $@ ) {
- plan skip_all => 'Test::Strict required to test strictness';
- } else {
- all_perl_files_ok( 'lib/' );
- }
-}
diff --git a/t/apocalypse.t b/t/apocalypse.t
new file mode 100644
index 0000000..256a1c5
--- /dev/null
+++ b/t/apocalypse.t
@@ -0,0 +1,11 @@
+#!/usr/bin/perl
+use strict; use warnings;
+
+use Test::More;
+eval "use Test::Apocalypse";
+if ( $@ ) {
+ plan skip_all => 'Test::Apocalypse required for validating the distribution';
+} else {
+ require Test::NoWarnings; require Test::Pod; require Test::Pod::Coverage; # lousy hack for kwalitee
+ is_apocalypse_here();
+}
|
apocalypse/perl-poe-benchmarker
|
c010c272a9ed11bec986aa831c3e43e9978471ec
|
added Eclipse prefs
|
diff --git a/.settings/org.eclipse.core.runtime.prefs b/.settings/org.eclipse.core.runtime.prefs
new file mode 100644
index 0000000..9fe81aa
--- /dev/null
+++ b/.settings/org.eclipse.core.runtime.prefs
@@ -0,0 +1,3 @@
+#Sun Nov 15 20:53:57 MST 2009
+eclipse.preferences.version=1
+line.separator=\n
|
apocalypse/perl-poe-benchmarker
|
923750de270fe316176d250a948961933493c708
|
add Eclipse includepath
|
diff --git a/.includepath b/.includepath
new file mode 100644
index 0000000..53c29fe
--- /dev/null
+++ b/.includepath
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<includepath>
+ <includepathentry path="${resource_loc:/perl-poe-benchmarker/lib}" />
+</includepath>
|
apocalypse/perl-poe-benchmarker
|
f55a73eedf43c6b77f3effd5c50169141ae4b691
|
added comment from dngor
|
diff --git a/lib/POE/Devel/Benchmarker.pm b/lib/POE/Devel/Benchmarker.pm
index b232953..438b0ca 100644
--- a/lib/POE/Devel/Benchmarker.pm
+++ b/lib/POE/Devel/Benchmarker.pm
@@ -560,594 +560,597 @@ sub test_timedout : State {
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print " Test Timed Out!";
}
$_[HEAP]->{'test_timedout'} = 1;
# wrap up this test
$_[KERNEL]->yield( 'wrapup_test' );
return;
}
# finalizes a test
sub wrapup_test : State {
# we're done with this benchmark!
$_[HEAP]->{'current_endtime'} = time();
$_[HEAP]->{'current_endtimes'} = [ times() ];
# store the data
my $file = generateTestfile( $_[HEAP] );
if ( open( my $fh, '>', "results/$file" ) ) {
print $fh "STARTTIME: " . $_[HEAP]->{'current_starttime'} . " -> TIMES " . join( " ", @{ $_[HEAP]->{'current_starttimes'} } ) . "\n";
print $fh "$file\n";
print $fh $_[HEAP]->{'current_data'} . "\n";
if ( $_[HEAP]->{'test_timedout'} ) {
print $fh "\nTEST TERMINATED DUE TO TIMEOUT\n";
}
print $fh "ENDTIME: " . $_[HEAP]->{'current_endtime'} . " -> TIMES " . join( " ", @{ $_[HEAP]->{'current_endtimes'} } ) . "\n";
close( $fh ) or die $!;
} else {
print "\n[BENCHMARKER] Unable to open results/$file for writing -> $!\n";
}
# Send the data to the Analyzer to process
$_[KERNEL]->yield( 'analyze_output', {
'poe' => {
'v' => $_[HEAP]->{'current_version'}->stringify, # YAML::Tiny doesn't like version objects :(
'loop' => 'POE::Loop::' . $_[HEAP]->{'current_loop'},
},
't' => {
's_ts' => $_[HEAP]->{'current_starttime'},
'e_ts' => $_[HEAP]->{'current_endtime'},
'd' => $_[HEAP]->{'current_endtime'} - $_[HEAP]->{'current_starttime'},
's_t' => [ @{ $_[HEAP]->{'current_starttimes'} } ],
'e_t' => [ @{ $_[HEAP]->{'current_endtimes'} } ],
},
'raw' => $_[HEAP]->{'current_data'},
'test' => $file,
'x_bench' => currentTestVersion(),
( $_[HEAP]->{'test_timedout'} ? ( 'timedout' => 1 ) : () ),
( $_[HEAP]->{'lite_tests'} ? ( 'litetests' => 1 ) : () ),
( $_[HEAP]->{'current_assertions'} ? ( 'asserts' => 1 ) : () ),
( $_[HEAP]->{'current_noxsqueue'} ? ( 'noxsqueue' => 1 ) : () ),
} );
# process the next test
$_[KERNEL]->yield( 'bench_xsqueue' );
return;
}
sub analyze_output : State {
# get the data
my $test = $_[ARG0];
# clean up the times() stuff
$test->{'t'}->{'t'} = beautify_times(
join( " ", @{ delete $test->{'t'}->{'s_t'} } ) .
" " .
join( " ", @{ delete $test->{'t'}->{'e_t'} } )
);
# Okay, break it down into our data struct
$test->{'metrics'} = {};
my $d = $test->{'metrics'};
my @unknown;
foreach my $l ( split( /(?:\n|\r)/, $test->{'raw'} ) ) {
# skip empty lines
if ( $l eq '' ) { next }
# usual test benchmark output
# 10 startups in 0.885 seconds ( 11.302 per second)
# 10000 posts in 0.497 seconds ( 20101.112 per second)
if ( $l =~ /^\s+\d+\s+(\w+)\s+in\s+([\d\.]+)\s+seconds\s+\(\s+([\d\.]+)\s+per\s+second\)$/ ) {
$d->{ $1 }->{'d'} = $2; # duration in seconds
$d->{ $1 }->{'i'} = $3; # iterations per second
# usual test benchmark times output
# startup times: 0.1 0 0 0 0.1 0 0.76 0.09
} elsif ( $l =~ /^(\w+)\s+times:\s+(.+)$/ ) {
$d->{ $1 }->{'t'} = beautify_times( $2 ); # the times hash
# usual test SKIP output
# SKIPPING br0ken $metric because ...
} elsif ( $l =~ /^SKIPPING\s+br0ken\s+(\w+)\s+because/ ) {
# don't build their data struct
# parse the memory footprint stuff
} elsif ( $l =~ /^pidinfo:\s+(.+)$/ ) {
# what should we analyze?
my $pidinfo = $1;
# VmPeak: 16172 kB
if ( $pidinfo =~ /^VmPeak:\s+(.+)$/ ) {
$test->{'pid'}->{'vmpeak'} = $1;
# voluntary_ctxt_switches: 10
} elsif ( $pidinfo =~ /^voluntary_ctxt_switches:\s+(.+)$/ ) {
$test->{'pid'}->{'vol_ctxt'} = $1;
# nonvoluntary_ctxt_switches: 1221
} elsif ( $pidinfo =~ /^nonvoluntary_ctxt_switches:\s+(.+)$/ ) {
$test->{'pid'}->{'nonvol_ctxt'} = $1;
} else {
# ignore the rest of the fluff
}
# parse the perl binary stuff
} elsif ( $l =~ /^perlconfig:\s+(.+)$/ ) {
# what should we analyze?
my $perlconfig = $1;
# ignore the fluff ( not needed now... )
# parse the CPU info
} elsif ( $l =~ /^cpuinfo:\s+(.+)$/ ) {
# what should we analyze?
my $cpuinfo = $1;
# FIXME if this is on a multiproc system, we will overwrite the data per processor ( harmless? )
# cpu MHz : 1201.000
if ( $cpuinfo =~ /^cpu\s+MHz\s+:\s+(.+)$/ ) {
$test->{'cpu'}->{'mhz'} = $1;
# model name : Intel(R) Core(TM)2 Duo CPU L7100 @ 1.20GHz
} elsif ( $cpuinfo =~ /^model\s+name\s+:\s+(.+)$/ ) {
$test->{'cpu'}->{'name'} = $1;
# bogomips : 2397.58
} elsif ( $cpuinfo =~ /^bogomips\s+:\s+(.+)$/ ) {
$test->{'cpu'}->{'bogo'} = $1;
} else {
# ignore the rest of the fluff
}
# ignore any Devel::Hide stuff
# $l eq '!STDERR: Devel::Hide hides POE/XS/Queue/Array.pm'
} elsif ( $l =~ /^\!STDERR:\s+Devel\:\:Hide\s+hides/ ) {
# ignore them
# data that we can safely throw away
} elsif ( $l eq 'Using NO Assertions!' or
$l eq 'Using FULL Assertions!' or
$l eq 'Using the LITE tests' or
$l eq 'Using the HEAVY tests' or
$l eq 'DISABLING POE::XS::Queue::Array' or
$l eq 'LETTING POE find POE::XS::Queue::Array' or
$l eq 'UNABLE TO GET /proc/self/status' or
$l eq 'UNABLE TO GET /proc/cpuinfo' or
$l eq '!STDERR: POE::Kernel\'s run() method was never called.' or # to ignore old POEs that threw this warning
$l eq 'TEST TERMINATED DUE TO TIMEOUT' ) {
# ignore them
# parse the perl binary stuff
} elsif ( $l =~ /^Running\s+under\s+perl\s+binary:\s+\'([^\']+)\'\s+v([\d\.]+)$/ ) {
$test->{'perl'}->{'binary'} = $1;
# setup the perl version
$test->{'perl'}->{'v'} = $2;
# the master loop version ( what the POE::Loop::XYZ actually uses )
# Using loop: EV-3.49
} elsif ( $l =~ /^Using\s+master\s+loop:\s+(.+)$/ ) {
$test->{'poe'}->{'loop_m'} = $1;
# the real POE version that was loaded
# Using POE-1.001
} elsif ( $l =~ /^Using\s+POE-(.+)$/ ) {
$test->{'poe'}->{'v_real'} = $1;
# the various queue/loop modules we loaded
# POE is using: POE::XS::Queue::Array v0.005
# POE is using: POE::Queue v1.2328
# POE is using: POE::Loop::EV v0.06
} elsif ( $l =~ /^POE\s+is\s+using:\s+([^\s]+)\s+v(.+)$/ ) {
$test->{'poe'}->{'modules'}->{ $1 } = $2;
# get the uname info
# Running under machine: Linux apoc-x300 2.6.24-21-generic #1 SMP Tue Oct 21 23:43:45 UTC 2008 i686 GNU/Linux
} elsif ( $l =~ /^Running\s+under\s+machine:\s+(.+)$/ ) {
$test->{'uname'} = $1;
# parse any STDERR output
# !STDERR: unable to foo
} elsif ( $l =~ /^\!STDERR:\s+(.+)$/ ) {
push( @{ $test->{'stderr'} }, $1 );
} else {
# unknown line :(
push( @unknown, $l );
}
}
# Get rid of the rawdata
delete $test->{'raw'};
# Dump the unknowns
if ( @unknown ) {
print "\n[ANALYZER] Unknown output from benchmark -> " . Dump( \@unknown );
}
# Dump the data struct we have to the file.yml
my $yaml_file = 'results/' . delete $test->{'test'};
$yaml_file .= '.yml';
my $ret = open( my $fh, '>', $yaml_file );
if ( defined $ret ) {
print $fh Dump( $test );
if ( ! close( $fh ) ) {
print "\n[ANALYZER] Unable to close $yaml_file -> " . $! . "\n";
}
} else {
print "\n[ANALYZER] Unable to open $yaml_file for writing -> " . $! . "\n";
}
# now that we've dumped the stuff, we can do some sanity checks
# the POE we "think" we loaded should match reality!
if ( exists $test->{'poe'}->{'v_real'} ) { # if this exists, then we successfully loaded POE
if ( $test->{'poe'}->{'v'} ne $test->{'poe'}->{'v_real'} ) {
print "\n[ANALYZER] The subprocess loaded a different version of POE than we thought -> $yaml_file\n";
}
# The loop we loaded should match what we wanted!
if ( exists $test->{'poe'}->{'modules'} ) {
if ( ! exists $test->{'poe'}->{'modules'}->{ $test->{'poe'}->{'loop'} } ) {
# gaah special-case for IO_Poll
if ( $test->{'poe'}->{'loop'} eq 'POE::Loop::IO_Poll' and exists $test->{'poe'}->{'modules'}->{'POE::Loop::Poll'} ) {
# ah, ignore this
} else {
print "\n[ANALYZER] The subprocess loaded a different Loop than we thought -> $yaml_file\n";
}
}
}
}
# the perl binary should be the same!
if ( exists $test->{'perl'} ) { # if this exists, we successfully fired up the app ( no compile error )
if ( $test->{'perl'}->{'binary'} ne $^X ) {
print "\n[ANALYZER] The subprocess booted up on a different perl binary -> $yaml_file\n";
}
if ( $test->{'perl'}->{'v'} ne sprintf( "%vd", $^V ) ) {
print "\n[ANALYZER] The subprocess booted up on a different perl version -> $yaml_file\n";
}
}
# all done!
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker - Benchmarking POE's performance ( acts more like a smoker )
=head1 SYNOPSIS
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker -e 'benchmark()'
=head1 ABSTRACT
This package of tools is designed to benchmark POE's performace across different
configurations. The current "tests" are:
=over 4
=item Events
posts: This tests how long it takes to post() N times
dispatches: This tests how long it took to dispatch/deliver all the posts enqueued in the "posts" test
single_posts: This tests how long it took to yield() between 2 states for N times
calls: This tests how long it took to call() N times
=item Alarms
alarms: This tests how long it took to add N alarms via alarm(), overwriting each other
alarm_adds: This tests how long it took to add N alarms via alarm_add()
alarm_clears: This tests how long it took to clear all alarms set in the "alarm_adds" test
NOTE: alarm_add is not available on all versions of POE!
=item Sessions
session_creates: This tests how long it took to create N sessions
session_destroys: This tests how long it took to destroy all sessions created in the "session_creates" test
=item Filehandles
select_read_STDIN: This tests how long it took to toggle select_read N times on STDIN
select_write_STDIN: This tests how long it took to toggle select_write N times on STDIN
select_read_MYFH: This tests how long it took to toggle select_read N times on a real filehandle
select_write_MYFH: This tests how long it took to toggle select_write N times on a real filehandle
NOTE: The MYFH tests don't include the time it took to open()/close() the file :)
=item Sockets
socket_connects: This tests how long it took to connect+disconnect to a SocketFactory server via localhost
socket_stream: This tests how long it took to send N chunks of data in a "ping-pong" fashion between the server and client
=item POE startup time
startups: This tests how long it took to start + close N instances of POE+Loop without any sessions/etc via system()
=item POE Loops
This is actually a "super" test where all of the specific tests is ran against various POE::Loop::XYZ/FOO for comparison
NOTE: Not all versions of POE support all Loops!
=item POE Assertions
This is actually a "super" test where all of the specific tests is ran against POE with/without assertions enabled
NOTE: Not all versions of POE support assertions!
=item POE::XS::Queue::Array
This is actually a "super" test where all of the specific tests is ran against POE with XS goodness enabled/disabled
NOTE: Not all versions of POE support XS::Queue::Array!
=back
=head1 DESCRIPTION
This module is poorly documented now. Please give me some time to properly document it over time :)
=head2 INSTALLATION
Here's a simple outline to get you up to speed quickly. ( and smoking! )
=over 4
=item Install CPAN package + dependencies
Download+install the POE::Devel::Benchmarker package from CPAN
apoc@apoc-x300:~$ cpanp -i POE::Devel::Benchmarker
=item Setup initial directories
Go anywhere, and create the "parent" directory where you'll be storing test results + stuff. For this example,
I have chosen to use ~/poe-benchmarker:
apoc@apoc-x300:~$ mkdir poe-benchmarker
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ mkdir poedists results images
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker::GetPOEdists -e 'getPOEdists( 1 )'
( go get a coffee while it downloads if you're on a slow link, ha! )
=item Let 'er rip!
At this point you can start running the benchmark!
NOTE: the Benchmarker expects everything to be in the "local" directory!
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker -e 'benchmark()'
( go sleep or something, this will take a while! )
=back
=head2 BENCHMARKING
On startup the Benchmarker will look in the "poedists" directory and load all the distributions it sees untarred there. Once
that is done it will begin autoprobing for available POE::Loop packages. Once it determines what's available, it will begin
the benchmarks.
As the Benchmarker goes through the combinations of POE + Eventloop + Assertions + XS::Queue it will dump data into
the results directory. The module also dumps YAML output in the same place, with the suffix of ".yml"
This module exposes only one subroutine, the benchmark() one. You can pass a hashref to it to set various options. Here is
a list of the valid options:
=over 4
=item freshstart => boolean
This will tell the Benchmarker to ignore any previous test runs stored in the 'results' directory. This will not delete
data from previous runs, only overwrite them. So be careful if you're mixing test runs from different versions!
benchmark( { freshstart => 1 } );
default: false
=item noxsqueue => boolean
This will tell the Benchmarker to force the unavailability of POE::XS::Queue::Array and skip those tests.
NOTE: The Benchmarker will set this automatically if it cannot load the module!
benchmark( { noxsqueue => 1 } );
default: false
=item noasserts => boolean
This will tell the Benchmarker to not run the ASSERT tests.
benchmark( { noasserts => 1 } );
default: false
=item litetests => boolean
This enables the "lite" tests which will not take up too much time.
benchmark( { litetests => 0 } );
default: true
=item quiet => boolean
This enables quiet mode which will not print anything to the console except for errors.
benchmark( { 'quiet' => 1 } );
default: false
=item loop => csv list or array
This overrides the built-in loop detection algorithm which searches for all known loops.
There is some "magic" here where you can put a negative sign in front of a loop and we will NOT run that.
NOTE: Capitalization is important!
benchmark( { 'loop' => 'IO_Poll,Select' } ); # runs only IO::Poll and Select
benchmark( { 'loop' => [ qw( Tk Gtk ) ] } ); # runs only Tk and Gtk
benchmark( { 'loop' => '-Tk' } ); # runs all available loops EXCEPT for TK
Known loops: Event_Lib EV Glib Prima Gtk Kqueue Tk Select IO_Poll
=item poe => csv list or array
This overrides the built-in POE version detection algorithm which pulls the POE versions from the 'poedists' directory.
There is some "magic" here where you can put a negative sign in front of a version and we will NOT run that.
NOTE: The Benchmarker will ignore versions that wasn't found in the directory!
benchmark( { 'poe' => '0.35,1.003' } ); # runs on 0.35 and 1.003
benchmark( { 'poe' => [ qw( 0.3009 0.12 ) ] } ); # runs on 0.3009 and 0.12
benchmark( { 'poe' => '-0.35' } ); # runs ALL tests except 0.35
=back
=head2 ANALYZING RESULTS
Please look at the pretty charts generated by the L<POE::Devel::Benchmarker::Imager> module.
=head1 EXPORT
Automatically exports the benchmark() subroutine.
=head1 TODO
=over 4
=item Perl version smoking
We should be able to run the benchmark over different Perl versions. This would require some fiddling with our
layout + logic. It's not that urgent because the workaround is to simply execute the benchmarker under a different
perl binary. It's smart enough to use $^X to be consistent across tests/subprocesses :)
=item Select the EV backend
<Khisanth> and if you are benchmarking, try it with POE using EV with EV using Glib? :P
<Apocalypse> I'm not sure how to configure the EV "backend" yet
<Apocalypse> too much docs for me to read hah
<Khisanth> Apocalypse: use EV::Glib; use Glib; use POE; :)
=item Be smarter in smoking timeouts
Currently we depend on the litetests option and hardcode some values including the timeout. If your machine is incredibly
slow, there's a chance that it could timeout unnecessarily. Please look at the outputs and check to see if there are unusual
failures, and inform me.
Also, some loops perform badly and take almost forever! /me glares at Gtk...
=item More benchmarks!
As usual, me and the crowd in #poe have plenty of ideas for tests. We'll be adding them over time, but if you have an idea please
drop me a line and let me know!
dngor said there was some benchmarks in the POE svn under trunk/queue...
+ <dngor> Apocalypse: Check out the old benchmarks in the queue directory in POE's repot.
+ They profile queue performance at various sizes, which is a better indication of scalability.
+
Tapout contributed a script that tests HTTP performance, let's see if it deserves to be in the suite :)
I added the preliminary socket tests, we definitely should expand it seeing how many people use POE for networking...
=item Add SQLite/DBI/etc support to the Analyzer
It would be nice if we could have a local SQLite db to dump our stats into. This would make arbitrary reports much easier than
loading raw YAML files and trying to make sense of them, ha! Also, this means somebody can do the smoking and send the SQLite
db to another person to generate the graphs, cool!
=item Kqueue loop support
As I don't have access to a *BSD box, I cannot really test this. Furthermore, it isn't clear on how I can force/unload this
module from POE...
=item Wx loop support
I have Wx installed, but it doesn't work. Obviously I don't know how to use Wx ;)
If you have experience, please drop me a line on how to do the "right" thing to get Wx loaded under POE. Here's the error:
Can't call method "MainLoop" on an undefined value at /usr/local/share/perl/5.8.8/POE/Loop/Wx.pm line 91.
=item XS::Loop support
The POE::XS::Loop::* modules theoretically could be tested too. However, they will only work in POE >= 1.003! This renders
the concept somewhat moot. Maybe, after POE has progressed some versions we can implement this...
=back
=head1 SEE ALSO
L<POE>
=head1 SUPPORT
You can find documentation for this module with the perldoc command.
perldoc POE::Devel::Benchmarker
=head2 Websites
=over 4
=item * AnnoCPAN: Annotated CPAN documentation
L<http://annocpan.org/dist/POE-Devel-Benchmarker>
=item * CPAN Ratings
L<http://cpanratings.perl.org/d/POE-Devel-Benchmarker>
=item * RT: CPAN's request tracker
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=POE-Devel-Benchmarker>
=item * Search CPAN
L<http://search.cpan.org/dist/POE-Devel-Benchmarker>
=back
=head2 Bugs
Please report any bugs or feature requests to C<bug-poe-devel-benchmarker at rt.cpan.org>, or through
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=POE-Devel-Benchmarker>. I will be
notified, and then you'll automatically be notified of progress on your bug as I make changes.
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
BIG THANKS goes to Rocco Caputo E<lt>rcaputo@cpan.orgE<gt> for the first benchmarks!
=head1 COPYRIGHT AND LICENSE
Copyright 2009 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
|
apocalypse/perl-poe-benchmarker
|
bf1cba87daada010a585fa0af51c0c683eb8d183
|
added new distro
|
diff --git a/POE-Devel-Benchmarker-0.05.tar.gz b/POE-Devel-Benchmarker-0.05.tar.gz
new file mode 100644
index 0000000..8b54049
Binary files /dev/null and b/POE-Devel-Benchmarker-0.05.tar.gz differ
|
apocalypse/perl-poe-benchmarker
|
b8a76bd1f32d2c580f3fddf71f29500c0dff4c9b
|
change chmod to +x
|
diff --git a/examples/test.pl b/examples/test.pl
old mode 100644
new mode 100755
diff --git a/scripts/dngor_socket_test.pl b/scripts/dngor_socket_test.pl
old mode 100644
new mode 100755
diff --git a/scripts/dngor_socket_test_optimized.pl b/scripts/dngor_socket_test_optimized.pl
old mode 100644
new mode 100755
diff --git a/scripts/dngor_socket_test_slow.pl b/scripts/dngor_socket_test_slow.pl
old mode 100644
new mode 100755
diff --git a/scripts/tapout_script b/scripts/tapout_script
old mode 100644
new mode 100755
|
apocalypse/perl-poe-benchmarker
|
f3ccc064526200776b47407636d2e8e1b5c856a4
|
added more files
|
diff --git a/examples/test.pl b/examples/test.pl
new file mode 100644
index 0000000..b8c680c
--- /dev/null
+++ b/examples/test.pl
@@ -0,0 +1,24 @@
+#!/usr/bin/perl
+use strict; use warnings;
+
+# create our test directory
+mkdir( 'poe-benchmarker' ) or die "unable to mkdir: $!";
+
+# enter it!
+chdir( 'poe-benchmarker' ) or die "unable to chdir: $!";
+
+# create the child directories
+foreach my $dir ( qw( poedists results images ) ) {
+ mkdir( $dir ) or die "unable to mkdir: $!";
+}
+
+# now, we actually get the POE dists
+require POE::Devel::Benchmarker::GetPOEdists;
+POE::Devel::Benchmarker::GetPOEdists::getPOEdists( 1 );
+
+
+# run the benchmarks!
+require POE::Devel::Benchmarker;
+POE::Devel::Benchmarker::benchmark();
+
+# all done!
diff --git a/scripts/dngor_socket_test.pl b/scripts/dngor_socket_test.pl
new file mode 100644
index 0000000..18cffb3
--- /dev/null
+++ b/scripts/dngor_socket_test.pl
@@ -0,0 +1,108 @@
+# $Id: tcp-poe.pl,v 1.2 2008/07/09 14:01:24 dk Exp $
+# An echo client-server benchmark.
+# Compare vs. http://cpansearch.perl.org/src/KARASIK/IO-Lambda-1.02/eg/bench/tcp-poe.pl
+
+use warnings;
+use strict;
+
+use Time::HiRes qw(time);
+use POE qw(Wheel::ReadWrite Wheel::ListenAccept);
+use IO::Socket::INET;
+
+my $CYCLES = 500;
+my $port = 11211;
+
+# Server. Created before starting the timer, because other benchmarks
+# also do this.
+
+{
+ POE::Session->create(
+ inline_states => {
+ _start => \&start_server,
+ client_accepted => \&start_reader,
+ client_input => \&handle_input,
+ client_flushed => \&handle_flush,
+ },
+ );
+
+ sub start_server {
+ my $serv_sock = IO::Socket::INET-> new(
+ Listen => 5,
+ LocalPort => $port,
+ Proto => 'tcp',
+ ReuseAddr => 1,
+ ) or die "listen() error: $!\n";
+ $_[HEAP]{listener} = POE::Wheel::ListenAccept->new(
+ Handle => $serv_sock,
+ AcceptEvent => "client_accepted",
+ );
+ }
+
+ sub start_reader {
+ my $readwrite = POE::Wheel::ReadWrite->new(
+ Handle => $_[ARG0],
+ InputEvent => "client_input",
+ FlushedEvent => "client_flushed",
+ );
+ $_[HEAP]{reader}{$readwrite->ID} = $readwrite;
+ }
+
+ sub handle_input {
+ my ($input, $reader_id) = @_[ARG0, ARG1];
+ $_[HEAP]{reader}{$reader_id}->put($input);
+ }
+
+ sub handle_flush {
+ my $reader_id = $_[ARG0];
+ delete $_[HEAP]{reader}{$reader_id};
+ }
+}
+
+my $t = time;
+
+# Client.
+
+{
+ my $connections = 0;
+
+ POE::Session->create(
+ inline_states => {
+ _start => sub { _make_connection($_[HEAP]) },
+ readable => sub {
+ delete $_[HEAP]{reader};
+ if ($connections >= $CYCLES) {
+ $_[KERNEL]->stop();
+ }
+ else {
+ _make_connection($_[HEAP]);
+ }
+ }
+ },
+ );
+
+ # Plain helper function.
+ sub _make_connection {
+ my $heap = shift;
+
+ $connections++;
+
+ my $x = IO::Socket::INET-> new(
+ PeerAddr => 'localhost',
+ PeerPort => $port,
+ Proto => 'tcp',
+ ) or die "connect() error: $!\n";
+
+ my $reader = $heap->{reader} = POE::Wheel::ReadWrite->new(
+ Handle => $x,
+ InputEvent => "readable",
+ );
+
+ $reader->put("can write $connections");
+ }
+}
+
+POE::Kernel->run();
+
+$t = time - $t;
+printf "%.3f sec\n", $t;
+exit;
diff --git a/scripts/dngor_socket_test_optimized.pl b/scripts/dngor_socket_test_optimized.pl
new file mode 100644
index 0000000..3af6e21
--- /dev/null
+++ b/scripts/dngor_socket_test_optimized.pl
@@ -0,0 +1,104 @@
+# $Id: tcp-poe.pl,v 1.2 2008/07/09 14:01:24 dk Exp $
+# An echo client-server benchmark.
+
+use warnings;
+use strict;
+
+use Time::HiRes qw(time);
+use POE;
+use IO::Socket::INET;
+
+my $CYCLES = 500;
+my $port = 11211;
+
+# Server. Created before starting the timer, because other benchmarks
+# also do this.
+
+{
+ POE::Session->create(
+ inline_states => {
+ _start => \&start_server,
+ server_readable => \&accept_connection,
+ client_readable => \&handle_input,
+ },
+ );
+
+ sub start_server {
+ my $serv_sock = IO::Socket::INET-> new(
+ Listen => 5,
+ LocalPort => $port,
+ Proto => 'tcp',
+ ReuseAddr => 1,
+ ) or die "listen() error: $!\n";
+
+ $_[KERNEL]->select_read($serv_sock, "server_readable");
+ }
+
+ sub accept_connection {
+ my $serv_sock = $_[ARG0];
+ my $conn = IO::Handle->new();
+ accept($conn, $serv_sock) or die "accept() error: $!";
+ $_[KERNEL]->select_read($conn, "client_readable");
+ $conn->blocking(1);
+ $conn->autoflush(1);
+ }
+
+ sub handle_input {
+ my $conn = $_[ARG0];
+ my $input = <$conn>;
+ if (defined $input) {
+ print $conn $input;
+ }
+ else {
+ $_[KERNEL]->select_read($conn, undef);
+ }
+ }
+}
+
+my $t = time;
+
+# Client.
+
+{
+ my $connections = 0;
+
+ POE::Session->create(
+ inline_states => {
+ _start => sub { _make_connection($_[KERNEL]) },
+ readable => sub {
+ my $sock = $_[ARG0];
+ $_[KERNEL]->select_read($sock, undef);
+ if ($connections >= $CYCLES) {
+ $_[KERNEL]->stop();
+ }
+ else {
+ _make_connection($_[KERNEL]);
+ }
+ }
+ },
+ );
+
+ # Plain helper function.
+ sub _make_connection {
+ my $kernel = shift;
+
+ $connections++;
+
+ my $x = IO::Socket::INET-> new(
+ PeerAddr => 'localhost',
+ PeerPort => $port,
+ Proto => 'tcp',
+ ) or die "connect() error: $!\n";
+
+ $x->autoflush(1);
+ print $x "can write $connections\n";
+
+ $kernel->select_read($x, "readable");
+ }
+}
+
+POE::Kernel->run();
+
+$t = time - $t;
+printf "%.3f sec\n", $t;
+exit;
diff --git a/scripts/dngor_socket_test_slow.pl b/scripts/dngor_socket_test_slow.pl
new file mode 100644
index 0000000..bc7fe40
--- /dev/null
+++ b/scripts/dngor_socket_test_slow.pl
@@ -0,0 +1,52 @@
+# $Id: tcp-poe.pl,v 1.2 2008/07/09 14:01:24 dk Exp $
+# An POE::Component::{Server,Client}::TCP based echo client/server benchmark.
+
+use warnings;
+use strict;
+
+use Time::HiRes qw(time);
+use POE qw(Component::Server::TCP Component::Client::TCP);
+use IO::Socket::INET;
+
+my $CYCLES = 500;
+my $port = 11211;
+
+# Echo server. Created before starting the timer, because other
+# benchmarks also do this.
+
+POE::Component::Server::TCP->new(
+ Address => '127.0.0.1',
+ Port => $port,
+ ClientInput => sub { $_[HEAP]{client}->put($_[ARG0]); },
+);
+
+my $t = time;
+
+# Client. Client creation is part of the benchmark.
+
+{
+ my $connections = 0;
+
+ POE::Component::Client::TCP->new(
+ RemoteAddress => '127.0.0.1',
+ RemotePort => $port,
+ Connected => sub {
+ $connections++;
+ $_[HEAP]{server}->put("can write $connections");
+ },
+ ServerInput => sub {
+ if ($connections >= $CYCLES) {
+ $_[KERNEL]->stop();
+ }
+ else {
+ $_[KERNEL]->yield("reconnect");
+ }
+ },
+ )
+}
+
+POE::Kernel->run();
+
+$t = time - $t;
+printf "%.3f sec\n", $t;
+exit;
|
apocalypse/perl-poe-benchmarker
|
ec0516db76c0498b208643eb6a623d34b9d9ae10
|
POD tweaks and general fixes for kwalitee
|
diff --git a/Build.PL b/Build.PL
index f0886b4..7980144 100644
--- a/Build.PL
+++ b/Build.PL
@@ -1,108 +1,111 @@
# Build.PL
use Module::Build;
my $build = Module::Build->new(
# look up Module::Build::API for the info!
'dynamic_config' => 0,
'module_name' => 'POE::Devel::Benchmarker',
'license' => 'perl',
'dist_abstract' => "Benchmarking POE's performance ( acts more like a smoker )",
'dist_author' => 'Apocalypse <APOCAL@cpan.org>',
'create_packlist' => 1,
'create_makefile_pl' => 'traditional',
'create_readme' => 1,
'test_files' => 't/*.t',
'add_to_cleanup' => [ 'META.yml', 'Makefile.PL', 'README' ], # automatically generated
'requires' => {
# POE Stuff
'POE' => 0,
'POE::Session::AttributeBased' => 0,
# FIXME POE stuff that Test::Dependencies needs to see
'POE::Session' => 0,
'POE::Wheel::SocketFactory' => 0,
'POE::Wheel::ReadWrite' => 0,
'POE::Filter::Line' => 0,
'POE::Driver::SysRW' => 0,
# misc perl stuff
'Time::HiRes' => 0,
'version' => 0,
'Devel::Hide' => 0,
# Analyzer reqs
'YAML::Tiny' => 0,
# GetPOEdists reqs
'LWP::UserAgent' => 0,
'HTML::LinkExtor' => 0,
'URI::URL' => 0,
'Archive::Tar' => 0,
# Imager reqs
'GD::Graph::lines' => 0,
'GD::Graph::colour' => 0,
'Class::Accessor::Fast' => 0,
'Module::Pluggable' => 0,
# Test stuff
'Test::More' => '0.86', # require latest for note() support in t/a_is_prereq_outdated.t
},
'recommends' => {
# our POE loops!
'POE::Loop::Event' => 0,
'POE::Loop::Event_Lib' => 0,
'POE::Loop::EV' => 0,
'POE::Loop::Glib' => 0,
'POE::Loop::Prima' => 0,
'POE::Loop::Gtk' => 0,
'POE::Loop::Wx' => 0,
'POE::Loop::Kqueue' => 0,
# included in POE ( listed here for completeness )
#'POE::Loop::Tk' => 0,
#'POE::Loop::Select' => 0,
#'POE::Loop::IO_Poll' => 0,
# the loops' dependencies
'Event' => 0,
'Event::Lib' => 0,
'EV' => 0,
'Glib' => 0,
'Prima' => 0,
'Wx' => 0,
'Tk' => 0,
- # the XS queue
+ # the XS stuff
'POE::XS::Queue::Array' => 0,
+ 'POE::XS::Loop::Poll' => 0,
+ 'POE::XS::Loop::EPoll' => 0,
},
# FIXME wishlist...
# 'test_requires' => {
# # Test stuff
# 'Test::Compile' => 0,
# 'Test::Perl::Critic' => 0,
# 'Test::Dependencies' => 0,
# 'Test::Distribution' => 0,
# 'Test::Fixme' => 0,
# 'Test::HasVersion' => 0,
# 'Test::Kwalitee' => 0,
# 'Test::CheckManifest' => 0,
# 'Test::MinimumVersion' => 0,
# 'Test::Pod::Coverage' => 0,
# 'Test::Spelling' => 0,
# 'Test::Pod' => 0,
# 'Test::Prereq' => 0,
# 'Test::Strict' => 0,
# 'Test::UseAllModules' => 0,
+# 'Test::YAML::Meta' => 0,
# },
);
# all done!
$build->create_build_script;
diff --git a/Changes b/Changes
index 56ea3d8..800c99e 100644
--- a/Changes
+++ b/Changes
@@ -1,40 +1,41 @@
Revision history for Perl extension POE::Devel::Benchmarker
* 0.05
Minor tweaks on the YAML output ( nothing new, hah! )
- Added the socket tests, yay! ( adapted from LotR's script, thanks! )
+ Added the socket tests, yay! ( still need more work so we test various methods of socket creation )
Some more tweaks to the BasicStatistics plugin for prettier graphs
Lots of refactoring to get things cleaned up :)
Added test versioning, so we make sure we're processing the right version :)
+ added examples/test.pl to satisfy kwalitee requirements, ha!
* 0.04
Started work on the image generator ( Imager ) and added the BasicStatistics plugin, yay!
Added automatic "pick up where we left off" to the benchmarker
Added the freshstart option to benchmark()
Tweaked the GetPOEdists sub so it will work in the "work directory" and in the poedists dir
Tweaked the YAML output so it's smaller
Removed POE::Loop::Wx from autoprobing ( I'm unable to get it to work )
Removed POE::Loop::Kqueue from autoprobing ( I'm unable to get it to work )
Hardcoded the Benchmarker routines to skip POE < 0.13 ( I'm unable to get it to work )
* 0.03
Added the loop option to benchmark(), thanks dngor!
Added the poe option to benchmark(), thanks dngor!
Added the noxsqueue option to benchmark()
Added the noasserts option to benchmark()
Automatically enable noxsqueue option if we cannot load POE::XS::Queue::Array, saving time
Bump Test::More version requirement because some people reported failures with note()
Fixed bug in SubProcess where it crashed on old POEs that didn't load IO::Handle
More documentation additions/tweaks
* 0.02
Added the Analyzer module ( and dump YAML files, yay! )
A lot of minor changes+tweaks to get a better dump format
* 0.01
initial release
diff --git a/MANIFEST b/MANIFEST
index 5ce3917..e1e39c3 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -1,36 +1,38 @@
Makefile.PL
Build.PL
MANIFEST
MANIFEST.SKIP
README
lib/POE/Devel/Benchmarker.pm
lib/POE/Devel/Benchmarker/GetInstalledLoops.pm
lib/POE/Devel/Benchmarker/GetPOEdists.pm
lib/POE/Devel/Benchmarker/SubProcess.pm
lib/POE/Devel/Benchmarker/Utils.pm
lib/POE/Devel/Benchmarker/Imager.pm
lib/POE/Devel/Benchmarker/Imager/BasicStatistics.pm
META.yml
Changes
+examples/test.pl
+
t/1_load.t
t/a_critic.t
t/a_kwalitee.t
t/a_pod.t
t/a_pod_spelling.t
t/a_pod_coverage.t
t/a_strict.t
t/a_hasversion.t
t/a_minimumversion.t
t/a_manifest.t
t/a_distribution.t
t/a_compile.t
t/a_dependencies.t
t/a_fixme.t
t/a_prereq.t
t/a_prereq_build.t
t/a_dosnewline.t
t/a_perlmetrics.t
t/a_is_prereq_outdated.t
t/a_metayml.t
diff --git a/lib/POE/Devel/Benchmarker.pm b/lib/POE/Devel/Benchmarker.pm
index cb3f62d..b232953 100644
--- a/lib/POE/Devel/Benchmarker.pm
+++ b/lib/POE/Devel/Benchmarker.pm
@@ -594,526 +594,560 @@ sub wrapup_test : State {
'poe' => {
'v' => $_[HEAP]->{'current_version'}->stringify, # YAML::Tiny doesn't like version objects :(
'loop' => 'POE::Loop::' . $_[HEAP]->{'current_loop'},
},
't' => {
's_ts' => $_[HEAP]->{'current_starttime'},
'e_ts' => $_[HEAP]->{'current_endtime'},
'd' => $_[HEAP]->{'current_endtime'} - $_[HEAP]->{'current_starttime'},
's_t' => [ @{ $_[HEAP]->{'current_starttimes'} } ],
'e_t' => [ @{ $_[HEAP]->{'current_endtimes'} } ],
},
'raw' => $_[HEAP]->{'current_data'},
'test' => $file,
'x_bench' => currentTestVersion(),
( $_[HEAP]->{'test_timedout'} ? ( 'timedout' => 1 ) : () ),
( $_[HEAP]->{'lite_tests'} ? ( 'litetests' => 1 ) : () ),
( $_[HEAP]->{'current_assertions'} ? ( 'asserts' => 1 ) : () ),
( $_[HEAP]->{'current_noxsqueue'} ? ( 'noxsqueue' => 1 ) : () ),
} );
# process the next test
$_[KERNEL]->yield( 'bench_xsqueue' );
return;
}
sub analyze_output : State {
# get the data
my $test = $_[ARG0];
# clean up the times() stuff
$test->{'t'}->{'t'} = beautify_times(
join( " ", @{ delete $test->{'t'}->{'s_t'} } ) .
" " .
join( " ", @{ delete $test->{'t'}->{'e_t'} } )
);
# Okay, break it down into our data struct
$test->{'metrics'} = {};
my $d = $test->{'metrics'};
my @unknown;
foreach my $l ( split( /(?:\n|\r)/, $test->{'raw'} ) ) {
# skip empty lines
if ( $l eq '' ) { next }
# usual test benchmark output
# 10 startups in 0.885 seconds ( 11.302 per second)
# 10000 posts in 0.497 seconds ( 20101.112 per second)
if ( $l =~ /^\s+\d+\s+(\w+)\s+in\s+([\d\.]+)\s+seconds\s+\(\s+([\d\.]+)\s+per\s+second\)$/ ) {
$d->{ $1 }->{'d'} = $2; # duration in seconds
$d->{ $1 }->{'i'} = $3; # iterations per second
# usual test benchmark times output
# startup times: 0.1 0 0 0 0.1 0 0.76 0.09
} elsif ( $l =~ /^(\w+)\s+times:\s+(.+)$/ ) {
$d->{ $1 }->{'t'} = beautify_times( $2 ); # the times hash
# usual test SKIP output
# SKIPPING br0ken $metric because ...
} elsif ( $l =~ /^SKIPPING\s+br0ken\s+(\w+)\s+because/ ) {
# don't build their data struct
# parse the memory footprint stuff
} elsif ( $l =~ /^pidinfo:\s+(.+)$/ ) {
# what should we analyze?
my $pidinfo = $1;
# VmPeak: 16172 kB
if ( $pidinfo =~ /^VmPeak:\s+(.+)$/ ) {
$test->{'pid'}->{'vmpeak'} = $1;
# voluntary_ctxt_switches: 10
} elsif ( $pidinfo =~ /^voluntary_ctxt_switches:\s+(.+)$/ ) {
$test->{'pid'}->{'vol_ctxt'} = $1;
# nonvoluntary_ctxt_switches: 1221
} elsif ( $pidinfo =~ /^nonvoluntary_ctxt_switches:\s+(.+)$/ ) {
$test->{'pid'}->{'nonvol_ctxt'} = $1;
} else {
# ignore the rest of the fluff
}
# parse the perl binary stuff
} elsif ( $l =~ /^perlconfig:\s+(.+)$/ ) {
# what should we analyze?
my $perlconfig = $1;
# ignore the fluff ( not needed now... )
# parse the CPU info
} elsif ( $l =~ /^cpuinfo:\s+(.+)$/ ) {
# what should we analyze?
my $cpuinfo = $1;
# FIXME if this is on a multiproc system, we will overwrite the data per processor ( harmless? )
# cpu MHz : 1201.000
if ( $cpuinfo =~ /^cpu\s+MHz\s+:\s+(.+)$/ ) {
$test->{'cpu'}->{'mhz'} = $1;
# model name : Intel(R) Core(TM)2 Duo CPU L7100 @ 1.20GHz
} elsif ( $cpuinfo =~ /^model\s+name\s+:\s+(.+)$/ ) {
$test->{'cpu'}->{'name'} = $1;
# bogomips : 2397.58
} elsif ( $cpuinfo =~ /^bogomips\s+:\s+(.+)$/ ) {
$test->{'cpu'}->{'bogo'} = $1;
} else {
# ignore the rest of the fluff
}
# ignore any Devel::Hide stuff
# $l eq '!STDERR: Devel::Hide hides POE/XS/Queue/Array.pm'
} elsif ( $l =~ /^\!STDERR:\s+Devel\:\:Hide\s+hides/ ) {
# ignore them
# data that we can safely throw away
} elsif ( $l eq 'Using NO Assertions!' or
$l eq 'Using FULL Assertions!' or
$l eq 'Using the LITE tests' or
$l eq 'Using the HEAVY tests' or
$l eq 'DISABLING POE::XS::Queue::Array' or
$l eq 'LETTING POE find POE::XS::Queue::Array' or
$l eq 'UNABLE TO GET /proc/self/status' or
$l eq 'UNABLE TO GET /proc/cpuinfo' or
$l eq '!STDERR: POE::Kernel\'s run() method was never called.' or # to ignore old POEs that threw this warning
$l eq 'TEST TERMINATED DUE TO TIMEOUT' ) {
# ignore them
# parse the perl binary stuff
} elsif ( $l =~ /^Running\s+under\s+perl\s+binary:\s+\'([^\']+)\'\s+v([\d\.]+)$/ ) {
$test->{'perl'}->{'binary'} = $1;
# setup the perl version
$test->{'perl'}->{'v'} = $2;
# the master loop version ( what the POE::Loop::XYZ actually uses )
# Using loop: EV-3.49
} elsif ( $l =~ /^Using\s+master\s+loop:\s+(.+)$/ ) {
$test->{'poe'}->{'loop_m'} = $1;
# the real POE version that was loaded
# Using POE-1.001
} elsif ( $l =~ /^Using\s+POE-(.+)$/ ) {
$test->{'poe'}->{'v_real'} = $1;
# the various queue/loop modules we loaded
# POE is using: POE::XS::Queue::Array v0.005
# POE is using: POE::Queue v1.2328
# POE is using: POE::Loop::EV v0.06
} elsif ( $l =~ /^POE\s+is\s+using:\s+([^\s]+)\s+v(.+)$/ ) {
$test->{'poe'}->{'modules'}->{ $1 } = $2;
# get the uname info
# Running under machine: Linux apoc-x300 2.6.24-21-generic #1 SMP Tue Oct 21 23:43:45 UTC 2008 i686 GNU/Linux
} elsif ( $l =~ /^Running\s+under\s+machine:\s+(.+)$/ ) {
$test->{'uname'} = $1;
# parse any STDERR output
# !STDERR: unable to foo
} elsif ( $l =~ /^\!STDERR:\s+(.+)$/ ) {
push( @{ $test->{'stderr'} }, $1 );
} else {
# unknown line :(
push( @unknown, $l );
}
}
# Get rid of the rawdata
delete $test->{'raw'};
# Dump the unknowns
if ( @unknown ) {
print "\n[ANALYZER] Unknown output from benchmark -> " . Dump( \@unknown );
}
# Dump the data struct we have to the file.yml
my $yaml_file = 'results/' . delete $test->{'test'};
$yaml_file .= '.yml';
my $ret = open( my $fh, '>', $yaml_file );
if ( defined $ret ) {
print $fh Dump( $test );
if ( ! close( $fh ) ) {
print "\n[ANALYZER] Unable to close $yaml_file -> " . $! . "\n";
}
} else {
print "\n[ANALYZER] Unable to open $yaml_file for writing -> " . $! . "\n";
}
# now that we've dumped the stuff, we can do some sanity checks
# the POE we "think" we loaded should match reality!
if ( exists $test->{'poe'}->{'v_real'} ) { # if this exists, then we successfully loaded POE
if ( $test->{'poe'}->{'v'} ne $test->{'poe'}->{'v_real'} ) {
print "\n[ANALYZER] The subprocess loaded a different version of POE than we thought -> $yaml_file\n";
}
# The loop we loaded should match what we wanted!
if ( exists $test->{'poe'}->{'modules'} ) {
if ( ! exists $test->{'poe'}->{'modules'}->{ $test->{'poe'}->{'loop'} } ) {
# gaah special-case for IO_Poll
if ( $test->{'poe'}->{'loop'} eq 'POE::Loop::IO_Poll' and exists $test->{'poe'}->{'modules'}->{'POE::Loop::Poll'} ) {
# ah, ignore this
} else {
print "\n[ANALYZER] The subprocess loaded a different Loop than we thought -> $yaml_file\n";
}
}
}
}
# the perl binary should be the same!
if ( exists $test->{'perl'} ) { # if this exists, we successfully fired up the app ( no compile error )
if ( $test->{'perl'}->{'binary'} ne $^X ) {
print "\n[ANALYZER] The subprocess booted up on a different perl binary -> $yaml_file\n";
}
if ( $test->{'perl'}->{'v'} ne sprintf( "%vd", $^V ) ) {
print "\n[ANALYZER] The subprocess booted up on a different perl version -> $yaml_file\n";
}
}
# all done!
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker - Benchmarking POE's performance ( acts more like a smoker )
=head1 SYNOPSIS
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker -e 'benchmark()'
=head1 ABSTRACT
This package of tools is designed to benchmark POE's performace across different
configurations. The current "tests" are:
=over 4
=item Events
posts: This tests how long it takes to post() N times
dispatches: This tests how long it took to dispatch/deliver all the posts enqueued in the "posts" test
single_posts: This tests how long it took to yield() between 2 states for N times
calls: This tests how long it took to call() N times
=item Alarms
alarms: This tests how long it took to add N alarms via alarm(), overwriting each other
alarm_adds: This tests how long it took to add N alarms via alarm_add()
alarm_clears: This tests how long it took to clear all alarms set in the "alarm_adds" test
NOTE: alarm_add is not available on all versions of POE!
=item Sessions
session_creates: This tests how long it took to create N sessions
session_destroys: This tests how long it took to destroy all sessions created in the "session_creates" test
=item Filehandles
select_read_STDIN: This tests how long it took to toggle select_read N times on STDIN
select_write_STDIN: This tests how long it took to toggle select_write N times on STDIN
select_read_MYFH: This tests how long it took to toggle select_read N times on a real filehandle
select_write_MYFH: This tests how long it took to toggle select_write N times on a real filehandle
NOTE: The MYFH tests don't include the time it took to open()/close() the file :)
=item Sockets
socket_connects: This tests how long it took to connect+disconnect to a SocketFactory server via localhost
socket_stream: This tests how long it took to send N chunks of data in a "ping-pong" fashion between the server and client
=item POE startup time
startups: This tests how long it took to start + close N instances of POE+Loop without any sessions/etc via system()
=item POE Loops
This is actually a "super" test where all of the specific tests is ran against various POE::Loop::XYZ/FOO for comparison
NOTE: Not all versions of POE support all Loops!
=item POE Assertions
This is actually a "super" test where all of the specific tests is ran against POE with/without assertions enabled
NOTE: Not all versions of POE support assertions!
=item POE::XS::Queue::Array
This is actually a "super" test where all of the specific tests is ran against POE with XS goodness enabled/disabled
NOTE: Not all versions of POE support XS::Queue::Array!
=back
=head1 DESCRIPTION
This module is poorly documented now. Please give me some time to properly document it over time :)
=head2 INSTALLATION
Here's a simple outline to get you up to speed quickly. ( and smoking! )
=over 4
=item Install CPAN package + dependencies
Download+install the POE::Devel::Benchmarker package from CPAN
apoc@apoc-x300:~$ cpanp -i POE::Devel::Benchmarker
=item Setup initial directories
Go anywhere, and create the "parent" directory where you'll be storing test results + stuff. For this example,
I have chosen to use ~/poe-benchmarker:
apoc@apoc-x300:~$ mkdir poe-benchmarker
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ mkdir poedists results images
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker::GetPOEdists -e 'getPOEdists( 1 )'
( go get a coffee while it downloads if you're on a slow link, ha! )
=item Let 'er rip!
At this point you can start running the benchmark!
NOTE: the Benchmarker expects everything to be in the "local" directory!
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker -e 'benchmark()'
( go sleep or something, this will take a while! )
=back
=head2 BENCHMARKING
On startup the Benchmarker will look in the "poedists" directory and load all the distributions it sees untarred there. Once
that is done it will begin autoprobing for available POE::Loop packages. Once it determines what's available, it will begin
the benchmarks.
As the Benchmarker goes through the combinations of POE + Eventloop + Assertions + XS::Queue it will dump data into
the results directory. The module also dumps YAML output in the same place, with the suffix of ".yml"
This module exposes only one subroutine, the benchmark() one. You can pass a hashref to it to set various options. Here is
a list of the valid options:
=over 4
=item freshstart => boolean
This will tell the Benchmarker to ignore any previous test runs stored in the 'results' directory. This will not delete
data from previous runs, only overwrite them. So be careful if you're mixing test runs from different versions!
benchmark( { freshstart => 1 } );
default: false
=item noxsqueue => boolean
This will tell the Benchmarker to force the unavailability of POE::XS::Queue::Array and skip those tests.
NOTE: The Benchmarker will set this automatically if it cannot load the module!
benchmark( { noxsqueue => 1 } );
default: false
=item noasserts => boolean
This will tell the Benchmarker to not run the ASSERT tests.
benchmark( { noasserts => 1 } );
default: false
=item litetests => boolean
This enables the "lite" tests which will not take up too much time.
benchmark( { litetests => 0 } );
default: true
=item quiet => boolean
This enables quiet mode which will not print anything to the console except for errors.
benchmark( { 'quiet' => 1 } );
default: false
=item loop => csv list or array
This overrides the built-in loop detection algorithm which searches for all known loops.
There is some "magic" here where you can put a negative sign in front of a loop and we will NOT run that.
NOTE: Capitalization is important!
benchmark( { 'loop' => 'IO_Poll,Select' } ); # runs only IO::Poll and Select
benchmark( { 'loop' => [ qw( Tk Gtk ) ] } ); # runs only Tk and Gtk
benchmark( { 'loop' => '-Tk' } ); # runs all available loops EXCEPT for TK
Known loops: Event_Lib EV Glib Prima Gtk Kqueue Tk Select IO_Poll
=item poe => csv list or array
This overrides the built-in POE version detection algorithm which pulls the POE versions from the 'poedists' directory.
There is some "magic" here where you can put a negative sign in front of a version and we will NOT run that.
NOTE: The Benchmarker will ignore versions that wasn't found in the directory!
benchmark( { 'poe' => '0.35,1.003' } ); # runs on 0.35 and 1.003
benchmark( { 'poe' => [ qw( 0.3009 0.12 ) ] } ); # runs on 0.3009 and 0.12
benchmark( { 'poe' => '-0.35' } ); # runs ALL tests except 0.35
=back
=head2 ANALYZING RESULTS
Please look at the pretty charts generated by the L<POE::Devel::Benchmarker::Imager> module.
=head1 EXPORT
Automatically exports the benchmark() subroutine.
=head1 TODO
=over 4
=item Perl version smoking
We should be able to run the benchmark over different Perl versions. This would require some fiddling with our
layout + logic. It's not that urgent because the workaround is to simply execute the benchmarker under a different
perl binary. It's smart enough to use $^X to be consistent across tests/subprocesses :)
=item Select the EV backend
<Khisanth> and if you are benchmarking, try it with POE using EV with EV using Glib? :P
<Apocalypse> I'm not sure how to configure the EV "backend" yet
<Apocalypse> too much docs for me to read hah
<Khisanth> Apocalypse: use EV::Glib; use Glib; use POE; :)
=item Be smarter in smoking timeouts
Currently we depend on the litetests option and hardcode some values including the timeout. If your machine is incredibly
slow, there's a chance that it could timeout unnecessarily. Please look at the outputs and check to see if there are unusual
failures, and inform me.
Also, some loops perform badly and take almost forever! /me glares at Gtk...
=item More benchmarks!
As usual, me and the crowd in #poe have plenty of ideas for tests. We'll be adding them over time, but if you have an idea please
drop me a line and let me know!
dngor said there was some benchmarks in the POE svn under trunk/queue...
Tapout contributed a script that tests HTTP performance, let's see if it deserves to be in the suite :)
I added the preliminary socket tests, we definitely should expand it seeing how many people use POE for networking...
=item Add SQLite/DBI/etc support to the Analyzer
It would be nice if we could have a local SQLite db to dump our stats into. This would make arbitrary reports much easier than
loading raw YAML files and trying to make sense of them, ha! Also, this means somebody can do the smoking and send the SQLite
db to another person to generate the graphs, cool!
=item Kqueue loop support
As I don't have access to a *BSD box, I cannot really test this. Furthermore, it isn't clear on how I can force/unload this
module from POE...
=item Wx loop support
I have Wx installed, but it doesn't work. Obviously I don't know how to use Wx ;)
If you have experience, please drop me a line on how to do the "right" thing to get Wx loaded under POE. Here's the error:
Can't call method "MainLoop" on an undefined value at /usr/local/share/perl/5.8.8/POE/Loop/Wx.pm line 91.
=item XS::Loop support
The POE::XS::Loop::* modules theoretically could be tested too. However, they will only work in POE >= 1.003! This renders
the concept somewhat moot. Maybe, after POE has progressed some versions we can implement this...
=back
=head1 SEE ALSO
L<POE>
+=head1 SUPPORT
+
+You can find documentation for this module with the perldoc command.
+
+ perldoc POE::Devel::Benchmarker
+
+=head2 Websites
+
+=over 4
+
+=item * AnnoCPAN: Annotated CPAN documentation
+
+L<http://annocpan.org/dist/POE-Devel-Benchmarker>
+
+=item * CPAN Ratings
+
+L<http://cpanratings.perl.org/d/POE-Devel-Benchmarker>
+
+=item * RT: CPAN's request tracker
+
+L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=POE-Devel-Benchmarker>
+
+=item * Search CPAN
+
+L<http://search.cpan.org/dist/POE-Devel-Benchmarker>
+
+=back
+
+=head2 Bugs
+
+Please report any bugs or feature requests to C<bug-poe-devel-benchmarker at rt.cpan.org>, or through
+the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=POE-Devel-Benchmarker>. I will be
+notified, and then you'll automatically be notified of progress on your bug as I make changes.
+
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
BIG THANKS goes to Rocco Caputo E<lt>rcaputo@cpan.orgE<gt> for the first benchmarks!
=head1 COPYRIGHT AND LICENSE
-Copyright 2008 by Apocalypse
+Copyright 2009 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm b/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm
index 1efdd73..e8f49e0 100644
--- a/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm
+++ b/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm
@@ -1,207 +1,207 @@
# Declare our package
package POE::Devel::Benchmarker::GetInstalledLoops;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.05';
# auto-export the only sub we have
use base qw( Exporter );
our @EXPORT = qw( getPOEloops );
# Import what we need from the POE namespace
use POE qw( Session Filter::Line Wheel::Run );
use base 'POE::Session::AttributeBased';
# Get the utils
use POE::Devel::Benchmarker::Utils qw ( knownloops );
# analyzes the installed perl directory for available loops
sub getPOEloops {
my $quiet_mode = shift;
my $forceloops = shift;
# create our session!
POE::Session->create(
POE::Devel::Benchmarker::GetInstalledLoops->inline_states(),
'heap' => {
'quiet_mode' => $quiet_mode,
'loops' => $forceloops,
},
);
}
# Starts up our session
sub _start : State {
# set our alias
$_[KERNEL]->alias_set( 'Benchmarker::GetInstalledLoops' );
# load our known list of loops
# known impossible loops:
# XS::EPoll ( must be POE > 1.003 and weird way of loading )
# XS::Poll ( must be POE > 1.003 and weird way of loading )
if ( ! defined $_[HEAP]->{'loops'} ) {
$_[HEAP]->{'loops'} = knownloops();
}
# First of all, we need to find out what loop libraries are installed
$_[HEAP]->{'found_loops'} = [];
$_[KERNEL]->yield( 'find_loops' );
return;
}
sub _stop : State {
# tell the wheel to kill itself
if ( defined $_[HEAP]->{'WHEEL'} ) {
$_[HEAP]->{'WHEEL'}->kill( 9 );
undef $_[HEAP]->{'WHEEL'};
}
return;
}
# loops over the "known" loops and sees if they are installed
sub find_loops : State {
# get the loop to test
$_[HEAP]->{'current_loop'} = shift @{ $_[HEAP]->{'loops'} };
# do we have something to test?
if ( ! defined $_[HEAP]->{'current_loop'} ) {
# we're done!
$_[KERNEL]->alias_remove( 'Benchmarker::GetInstalledLoops' );
$_[KERNEL]->post( 'Benchmarker', 'found_loops', $_[HEAP]->{'found_loops'} );
return;
} else {
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[LOOPSEARCH] Trying to find if POE::Loop::" . $_[HEAP]->{'current_loop'} . " is installed...\n";
}
# set the flag
$_[HEAP]->{'test_failure'} = 0;
}
# Okay, create the wheel::run to handle this
$_[HEAP]->{'WHEEL'} = POE::Wheel::Run->new(
'Program' => $^X,
'ProgramArgs' => [ '-MPOE',
'-MPOE::Loop::' . $_[HEAP]->{'current_loop'},
'-e',
'1',
],
# Kill off existing FD's
'CloseOnCall' => 1,
# setup our data handlers
'StdoutEvent' => 'Got_STDOUT',
'StderrEvent' => 'Got_STDERR',
# the error handler
'ErrorEvent' => 'Got_ERROR',
'CloseEvent' => 'Got_CLOSED',
# set our filters
'StderrFilter' => POE::Filter::Line->new(),
'StdoutFilter' => POE::Filter::Line->new(),
);
if ( ! defined $_[HEAP]->{'WHEEL'} ) {
die '[LOOPSEARCH] Unable to create a new wheel!';
} else {
# smart CHLD handling
if ( $_[KERNEL]->can( "sig_child" ) ) {
$_[KERNEL]->sig_child( $_[HEAP]->{'WHEEL'}->PID => 'Got_CHLD' );
} else {
$_[KERNEL]->sig( 'CHLD', 'Got_CHLD' );
}
}
return;
}
# Got a CHLD event!
sub Got_CHLD : State {
$_[KERNEL]->sig_handled();
return;
}
# Handles child STDERR output
sub Got_STDERR : State {
my $input = $_[ARG0];
# since we got an error, must be a failure
$_[HEAP]->{'test_failure'} = 1;
return;
}
# Handles child STDOUT output
sub Got_STDOUT : State {
my $input = $_[ARG0];
return;
}
# Handles child error
sub Got_ERROR : State {
# Copied from POE::Wheel::Run manpage
my ( $operation, $errnum, $errstr ) = @_[ ARG0 .. ARG2 ];
# ignore exit 0 errors
if ( $errnum != 0 ) {
warn "Wheel::Run got an $operation error $errnum: $errstr\n";
}
return;
}
# Handles child DIE'ing
sub Got_CLOSED : State {
# Get rid of the wheel
undef $_[HEAP]->{'WHEEL'};
# Did we pass this test or not?
if ( ! $_[HEAP]->{'test_failure'} ) {
push( @{ $_[HEAP]->{'found_loops'} }, $_[HEAP]->{'current_loop'} );
}
# move on to the next loop
$_[KERNEL]->yield( 'find_loops' );
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::GetInstalledLoops - Automatically detects the installed POE loops
=head1 SYNOPSIS
Don't use this module directly. Please use POE::Devel::Benchmarker.
=head1 ABSTRACT
This package implements the guts of searching for POE loops via fork/exec.
=head1 EXPORT
Automatically exports the getPOEloops() sub
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
-Copyright 2008 by Apocalypse
+Copyright 2009 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/GetPOEdists.pm b/lib/POE/Devel/Benchmarker/GetPOEdists.pm
index ed4745a..118e7e4 100644
--- a/lib/POE/Devel/Benchmarker/GetPOEdists.pm
+++ b/lib/POE/Devel/Benchmarker/GetPOEdists.pm
@@ -1,144 +1,144 @@
# Declare our package
package POE::Devel::Benchmarker::GetPOEdists;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.05';
# auto-export the only sub we have
use base qw( Exporter );
our @EXPORT = qw( getPOEdists );
# import the helper modules
use LWP::UserAgent;
use HTML::LinkExtor;
use URI::URL;
use Archive::Tar;
# autoflush, please!
use IO::Handle;
STDOUT->autoflush( 1 );
# actually retrieves the dists!
sub getPOEdists {
# should we debug?
my $debug = shift;
# okay, should we change directory?
if ( -d 'poedists' ) {
if ( $debug ) {
print "[GETPOEDISTS] chdir( 'poedists' )\n";
}
if ( ! chdir( 'poedists' ) ) {
die "Unable to chdir to 'poedists' dir: $!";
}
} else {
if ( $debug ) {
print "[GETPOEDISTS] downloading to current directory\n";
}
}
# set the default URL
my $url = "http://backpan.cpan.org/authors/id/R/RC/RCAPUTO/";
# create our objects
my $ua = LWP::UserAgent->new;
my $p = HTML::LinkExtor->new;
my $tar = Archive::Tar->new;
# Request document and parse it as it arrives
print "Getting $url via LWP\n" if $debug;
my $res = $ua->request( HTTP::Request->new( GET => $url ),
sub { $p->parse( $_[0] ) },
);
# did we successfully download?
if ( $res->is_error ) {
die "unable to download directory index on BACKPAN: " . $res->status_line;
}
# Download every one!
foreach my $link ( $p->links ) {
# skip IMG stuff
if ( $link->[0] eq 'a' and $link->[1] eq 'href' ) {
# get the actual POE dists!
if ( $link->[2] =~ /^POE\-\d/ and $link->[2] =~ /\.tar\.gz$/ ) {
# download the tarball!
print "Mirroring $link->[2] via LWP\n" if $debug;
my $mirror_result = $ua->mirror( $url . $link->[2], $link->[2] );
if ( $mirror_result->is_error ) {
warn "unable to mirror $link->[2]: " . $mirror_result->status_line;
next;
}
# did we already untar this one?
my $dir = $link->[2];
$dir =~ s/\.tar\.gz$//;
if ( ! -d $dir ) {
# extract it!
print "Extracting $link->[2] via Tar\n" if $debug;
my $files = $tar->read( $link->[2], undef, { 'extract' => 'true' } );
if ( $files == 0 ) {
warn "unable to extract $link->[2]";
}
}
}
}
}
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::GetPOEdists - Automatically download all POE tarballs
=head1 SYNOPSIS
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker::GetPOEdists -e 'getPOEdists()'
=head1 ABSTRACT
This package automatically downloads all the POE tarballs from BACKPAN.
=head1 DESCRIPTION
This uses LWP + HTML::LinkExtor to retrieve POE tarballs from BACKPAN.
The tarballs are automatically downloaded to the current directory. Then, we use Archive::Tar to extract them all!
NOTE: we use LWP's useful mirror() sub which doesn't re-download files if they already exist!
=head2 getPOEdists
Normally you should pass nothing to this sub. However, if you want to debug the downloads+extractions you should pass
a true value as the first argument.
perl -MPOE::Devel::Benchmarker::GetPOEdists -e 'getPOEdists( 1 )'
=head1 EXPORT
Automatically exports the getPOEdists() sub
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
-Copyright 2008 by Apocalypse
+Copyright 2009 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/Imager.pm b/lib/POE/Devel/Benchmarker/Imager.pm
index 82fac2a..9b120af 100644
--- a/lib/POE/Devel/Benchmarker/Imager.pm
+++ b/lib/POE/Devel/Benchmarker/Imager.pm
@@ -1,450 +1,450 @@
# Declare our package
package POE::Devel::Benchmarker::Imager;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.05';
# auto-export the only sub we have
use base qw( Exporter );
our @EXPORT = qw( imager );
# import the helper modules
use YAML::Tiny;
# load our plugins!
use Module::Pluggable search_path => [ __PACKAGE__ ];
# load comparison stuff
use version;
# Get some stuff from Utils
use POE::Devel::Benchmarker::Utils qw( currentTestVersion );
# generate some accessors
use base qw( Class::Accessor::Fast );
__PACKAGE__->mk_ro_accessors( qw( poe_versions poe_versions_sorted poe_loops data
noxsqueue noasserts litetests quiet
) );
# autoflush, please!
use IO::Handle;
STDOUT->autoflush( 1 );
# starts the work of converting our data to images
sub imager {
my $options = shift;
# instantitate ourself
my $self = __PACKAGE__->new( $options );
# parse all of our YAML modules!
$self->loadtests;
# process some stats
$self->process_data;
# generate the images!
$self->generate_images;
return;
}
# creates a new instance
sub new {
my $class = shift;
my $opts = shift;
# instantitate ourself
my $self = {};
bless $self, $class;
# init the options
$self->init_options( $opts );
if ( ! $self->{'options'}->{'quiet'} ) {
print "[IMAGER] Starting up...\n";
}
return $self;
}
sub init_options {
my $self = shift;
my $options = shift;
# set defaults
$self->{'quiet'} = 0;
$self->{'litetests'} = 1;
$self->{'noasserts'} = undef;
$self->{'noxsqueue'} = undef;
# process our options
if ( defined $options and ref $options and ref( $options ) eq 'HASH' ) {
# process quiet mode
if ( exists $options->{'quiet'} ) {
if ( $options->{'quiet'} ) {
$self->{'quiet'} = 1;
} else {
$self->{'quiet'} = 0;
}
}
# process the LITE/HEAVY
if ( exists $options->{'litetests'} ) {
if ( $options->{'litetests'} ) {
$self->{'litetests'} = 1;
} else {
$self->{'litetests'} = 0;
}
}
# process the noasserts to load
if ( exists $options->{'noasserts'} ) {
if ( $options->{'noasserts'} ) {
$self->{'noasserts'} = 1;
} else {
$self->{'noasserts'} = 0;
}
}
# process the noxsqueue to load
if ( exists $options->{'noxsqueue'} ) {
if ( $options->{'noxsqueue'} ) {
$self->{'noxsqueue'} = 1;
} else {
$self->{'noxsqueue'} = 0;
}
}
# FIXME process the plugins to load -> "types"
# FIXME process the versions to load
# FIXME process the loops to load
}
# some sanity tests
if ( ! -d 'results' ) {
die "The 'results' directory is not found in the working directory!";
}
if ( ! -d 'images' ) {
die "The 'images' directory is not found in the working directory!";
}
return;
}
# starts the process of loading all of our YAML images
sub loadtests {
my $self = shift;
# gather all the YAML dumps
if ( opendir( DUMPS, 'results' ) ) {
foreach my $d ( readdir( DUMPS ) ) {
# parse the file structure
# POE-1.0002-IO_Poll-LITE-assert-noxsqueue.yml
if ( $d =~ /^POE\-([\d\.\_]+)\-(\w+?)\-(LITE|HEAVY)\-(noassert|assert)\-(noxsqueue|xsqueue)\.yml$/ ) {
my( $ver, $loop, $lite, $assert, $xsqueue ) = ( $1, $2, $3, $4, $5 );
# skip this file?
if ( $self->noxsqueue ) {
if ( $xsqueue eq 'xsqueue' ) { next }
} else {
if ( defined $self->noxsqueue ) {
if ( $xsqueue eq 'noxsqueue' ) { next }
}
}
if ( $self->noasserts ) {
if ( $assert eq 'assert' ) { next }
} else {
if ( defined $self->noasserts ) {
if ( $assert eq 'noassert' ) { next }
}
}
if ( $self->litetests ) {
if ( $lite eq 'HEAVY' ) { next }
} else {
if ( $lite eq 'LITE' ) { next }
}
# FIXME allow selective loading of tests, so we can control what to image, etc
# actually load this file!
$self->load_yaml( $d, $ver, $loop, $lite, $assert, $xsqueue );
}
}
closedir( DUMPS ) or die "[IMAGER] Unable to read from 'results' -> " . $!;
} else {
die "[IMAGER] Unable to open 'results' for reading -> " . $!;
}
# sanity
if ( ! exists $self->{'data'} ) {
die "[IMAGER] Unable to find valid POE test result(s) in the 'results' directory!\n";
}
if ( ! $self->quiet ) {
print "[IMAGER] Done with parsing the YAML files...\n";
}
return;
}
# loads the yaml of a specific file
sub load_yaml {
my ( $self, $file, $ver, $loop, $lite, $assert, $xsqueue ) = @_;
my $yaml = YAML::Tiny->read( 'results/' . $file );
if ( ! defined $yaml ) {
print "[IMAGER] Unable to load YAML file $file -> " . YAML::Tiny->errstr . "\n";
return;
} else {
# inrospect it!
my $isvalid = 0;
eval {
# simple sanity check: the "x_bench" param is at the end of the YML, so if it loads fine we know it's there
if ( defined $yaml->[0] and exists $yaml->[0]->{'x_bench'} ) {
# version must at least match us
$isvalid = ( $yaml->[0]->{'x_bench'} eq currentTestVersion() ? 1 : 0 );
} else {
$isvalid = undef;
}
};
if ( ! $isvalid or $@ ) {
print "[IMAGER] Detected outdated/corrupt benchmark result: $file";
return;
} else {
# reduce indirection
$yaml = $yaml->[0];
}
}
# store the POE version
$self->{'poe_versions'}->{ $ver } = 1;
# sanity check the loop master version ( which should always be our "installed" version, not per-POE )
if ( exists $yaml->{'poe'}->{'loop_m'} ) {
if ( ! defined $self->{'poe_loops'}->{ $loop } ) {
$self->{'poe_loops'}->{ $loop } = $yaml->{'poe'}->{'loop_m'};
} else {
if ( $self->{'poe_loops'}->{ $loop } ne $yaml->{'poe'}->{'loop_m'} ) {
die "[IMAGER] Detected POE::Loop master version inconsistency! $file reported '" . $yaml->{'poe'}->{'loop_m'} .
"' while others had '" . $self->{'poe_loops'}->{ $loop } . "'";
}
}
}
# get the info we're interested in
$self->{'data'}->{ $assert }->{ $xsqueue }->{ $ver }->{ $loop }->{'metrics'} = $yaml->{'metrics'};
$self->{'data'}->{ $assert }->{ $xsqueue }->{ $ver }->{ $loop }->{'time'} = $yaml->{'t'};
if ( exists $yaml->{'pid'} ) {
$self->{'data'}->{ $assert }->{ $xsqueue }->{ $ver }->{ $loop }->{'pid'} = $yaml->{'pid'};
}
if ( exists $yaml->{'poe'}->{'modules'} ) {
$self->{'data'}->{ $assert }->{ $xsqueue }->{ $ver }->{ $loop }->{'poe_modules'} = $yaml->{'poe'}->{'modules'};
}
# sanity check the perl stuff
if ( exists $yaml->{'perl'}->{'binary'} ) {
if ( ! exists $self->{'data'}->{'perlconfig'} ) {
$self->{'data'}->{'perlconfig'}->{'binary'} = $yaml->{'perl'}->{'binary'};
$self->{'data'}->{'perlconfig'}->{'version'} = $yaml->{'perl'}->{'v'};
} else {
if ( $self->{'data'}->{'perlconfig'}->{'binary'} ne $yaml->{'perl'}->{'binary'} ) {
die "[IMAGER] Detected perl binary inconsistency! $file reported '" . $yaml->{'perl'}->{'binary'} .
"' while others had '" . $self->{'data'}->{'perlconfig'}->{'binary'} . "'";
}
if ( $self->{'data'}->{'perlconfig'}->{'version'} ne $yaml->{'perl'}->{'v'} ) {
die "[IMAGER] Detected perl version inconsistency! $file reported '" . $yaml->{'perl'}->{'v'} .
"' while others had '" . $self->{'data'}->{'perlconfig'}->{'version'} . "'";
}
}
}
# sanity check the uname
if ( exists $yaml->{'uname'} ) {
if ( ! exists $self->{'data'}->{'uname'} ) {
$self->{'data'}->{'uname'} = $yaml->{'uname'};
} else {
if ( $self->{'data'}->{'uname'} ne $yaml->{'uname'} ) {
die "[IMAGER] Detected system inconsistency! $file reported '" . $yaml->{'uname'} .
"' while others had '" . $self->{'data'}->{'uname'} . "'";
}
}
}
# sanity check the cpu name
if ( exists $yaml->{'cpu'} ) {
if ( ! exists $self->{'data'}->{'cpu'} ) {
$self->{'data'}->{'cpu'} = $yaml->{'cpu'};
} else {
if ( $self->{'data'}->{'cpu'}->{'name'} ne $yaml->{'cpu'}->{'name'} ) {
die "[IMAGER] Detected system/cpu inconsistency! $file reported '" . $yaml->{'cpu'}->{'name'} .
"' while others had '" . $self->{'data'}->{'cpu'}->{'name'} . "'";
}
}
}
return;
}
sub process_data {
my $self = shift;
# sanitize the versions in an ordered loop
$self->{'poe_versions_sorted'} = [ map { $_->stringify }
sort { $a <=> $b }
map { version->new($_) } keys %{ $self->poe_versions }
];
if ( ! $self->quiet ) {
print "[IMAGER] Done with processing the benchmark statistics...\n";
}
return;
}
sub generate_images {
my $self = shift;
# load our plugins and let them have fun :)
foreach my $plugin ( $self->plugins ) {
# actually load it!
## no critic
eval "require $plugin";
## use critic
if ( $@ ) {
if ( ! $self->quiet ) {
print "[IMAGER] Unable to load plugin $plugin -> $@\n";
next;
}
}
# sanity checks
if ( $plugin->can( 'new' ) and $plugin->can( 'imager' ) ) {
# FIXME did we want this plugin?
# create the plugin's home dir
my $homedir = $plugin;
if ( $homedir =~ /\:\:(\w+)$/ ) {
$homedir = $1;
} else {
die "barf";
}
if ( ! -d "images/$homedir" ) {
# create it!
if ( ! mkdir( "images/$homedir" ) ) {
die "[IMAGER] Unable to create plugin directory: $homedir";
}
}
# Okay, get this plugin!
my $obj = $plugin->new( { 'dir' => "images/$homedir/" } );
if ( ! $self->quiet ) {
print "[IMAGER] Processing the $plugin plugin...\n";
}
$obj->imager( $self );
}
}
if ( ! $self->quiet ) {
print "[IMAGER] Done with generating images...\n";
}
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::Imager - Automatically converts the benchmark data into images
=head1 SYNOPSIS
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker::Imager -e 'imager'
=head1 ABSTRACT
This package automatically parses the benchmark data and generates pretty charts.
=head1 DESCRIPTION
It will parse the YAML output from the benchmark data and calls it's plugins to generate any charts necessary
and place them in the 'images' directory under the plugin's name. This module only does the high-level stuff, and leaves
the actual chart generation to the plugins.
Furthermore, we use Module::Pluggable to search all modules in the POE::Devel::Benchmarker::Imager::* namespace and
let them handle the generation of images. That way virtually unlimited combinations of images can be generated on the fly
from the data this module parses.
The way to use this module is by calling the imager() subroutine and let it do it's job. You can pass a hashref to it to
set various options. Here is a list of the valid options:
=over 4
=item quiet => boolean
This enables quiet mode which will not print anything to the console except for errors.
new( { 'quiet' => 1 } );
default: false
=item noxsqueue => boolean / undef
This will tell the Imager to not consider those tests for the output.
benchmark( { noxsqueue => 1 } );
default: undef ( load both xsqueue and noxsqueue tests )
=item noasserts => boolean / undef
This will tell the Imager to not consider those tests for the output
benchmark( { noasserts => 1 } );
default: undef ( load both assert and noassert tests )
=item litetests => boolean
This will tell the Imager to not consider those tests for the output
benchmark( { litetests => 0 } );
default: true
=back
=head1 PLUGIN INTERFACE
For now, this is undocumented. Please look at BasicStatistics for the general concept on how it interacts with this module.
=head1 EXPORT
Automatically exports the imager() sub
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
-Copyright 2008 by Apocalypse
+Copyright 2009 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/Imager/BasicStatistics.pm b/lib/POE/Devel/Benchmarker/Imager/BasicStatistics.pm
index 1cd67bc..c0f897a 100644
--- a/lib/POE/Devel/Benchmarker/Imager/BasicStatistics.pm
+++ b/lib/POE/Devel/Benchmarker/Imager/BasicStatistics.pm
@@ -1,356 +1,356 @@
# Declare our package
package POE::Devel::Benchmarker::Imager::BasicStatistics;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.05';
# the GD stuff
use GD::Graph::lines;
use GD::Graph::colour qw( :lists );
# import some stuff
use POE::Devel::Benchmarker::Utils qw( currentMetrics );
# creates a new instance
sub new {
my $class = shift;
my $opts = shift;
# instantitate ourself
my $self = {
'opts' => $opts,
};
return bless $self, $class;
}
# actually generates the graphs!
sub imager {
my $self = shift;
$self->{'imager'} = shift;
# generate the loops vs each other graphs
$self->generate_loopwars;
# generate the single loop performance
$self->generate_loopperf;
# generate the loop assert/xsqueue ( 4 lines ) per metric
$self->generate_loopoptions;
return;
}
# charts a single loop's progress over POE versions
sub generate_loopoptions {
my $self = shift;
if ( ! $self->{'imager'}->quiet ) {
print "[BasicStatistics] Generating the Loop-Options graphs...\n";
}
# go through all the loops we want
foreach my $loop ( keys %{ $self->{'imager'}->poe_loops } ) {
foreach my $metric ( @{ currentMetrics() } ) {
my %data;
# organize data by POE version
foreach my $poe ( @{ $self->{'imager'}->poe_versions_sorted } ) {
# go through the combo of assert/xsqueue
foreach my $assert ( qw( assert noassert ) ) {
if ( ! exists $self->{'imager'}->data->{ $assert } ) {
next;
}
foreach my $xsqueue ( qw( xsqueue noxsqueue ) ) {
if ( ! exists $self->{'imager'}->data->{ $assert }->{ $xsqueue } ) {
next;
}
# sometimes we cannot test a metric
if ( exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }
and exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
and defined $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
) {
push( @{ $data{ $assert . '_' . $xsqueue } }, $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'} );
} else {
push( @{ $data{ $assert . '_' . $xsqueue } }, 0 );
}
}
}
}
# it's possible for us to do runs without assert/xsqueue
if ( scalar keys %data > 0 ) {
# transform %data into something GD likes
my @data_for_gd;
foreach my $m ( sort keys %data ) {
push( @data_for_gd, $data{ $m } );
}
# send it to GD!
$self->make_gdgraph( 'Options_' . $loop . '_' . $metric,
[ sort keys %data ],
\@data_for_gd,
);
}
}
}
return;
}
# charts a single loop's progress over POE versions
sub generate_loopperf {
my $self = shift;
if ( ! $self->{'imager'}->quiet ) {
print "[BasicStatistics] Generating the Loop-Performance graphs...\n";
}
# go through all the loops we want
foreach my $loop ( keys %{ $self->{'imager'}->poe_loops } ) {
# go through the combo of assert/xsqueue
foreach my $assert ( qw( assert noassert ) ) {
if ( ! exists $self->{'imager'}->data->{ $assert } ) {
next;
}
foreach my $xsqueue ( qw( xsqueue noxsqueue ) ) {
if ( ! exists $self->{'imager'}->data->{ $assert }->{ $xsqueue } ) {
next;
}
my %data;
# organize data by POE version
foreach my $poe ( @{ $self->{'imager'}->poe_versions_sorted } ) {
foreach my $metric ( @{ currentMetrics() } ) {
# sometimes we cannot test a metric
if ( exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }
and exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
and defined $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
) {
push( @{ $data{ $metric } }, $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'} );
} else {
push( @{ $data{ $metric } }, 0 );
}
}
}
# transform %data into something GD likes
my @data_for_gd;
foreach my $m ( sort keys %data ) {
push( @data_for_gd, $data{ $m } );
}
# send it to GD!
$self->make_gdgraph( 'Bench_' . $loop,
[ sort keys %data ],
\@data_for_gd,
$assert,
$xsqueue,
);
}
}
}
return;
}
# loop wars!
sub generate_loopwars {
my $self = shift;
if ( ! $self->{'imager'}->quiet ) {
print "[BasicStatistics] Generating the LoopWars graphs...\n";
}
# go through all the metrics we want
foreach my $metric ( @{ currentMetrics() } ) {
# go through the combo of assert/xsqueue
foreach my $assert ( qw( assert noassert ) ) {
if ( ! exists $self->{'imager'}->data->{ $assert } ) {
next;
}
foreach my $xsqueue ( qw( xsqueue noxsqueue ) ) {
if ( ! exists $self->{'imager'}->data->{ $assert }->{ $xsqueue } ) {
next;
}
my %data;
# organize data by POE version
foreach my $poe ( @{ $self->{'imager'}->poe_versions_sorted } ) {
foreach my $loop ( keys %{ $self->{'imager'}->poe_loops } ) {
# sometimes we cannot test a metric
if ( exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }
and exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
and defined $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
) {
push( @{ $data{ $loop } }, $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'} );
} else {
push( @{ $data{ $loop } }, 0 );
}
}
}
# transform %data into something GD likes
my @data_for_gd;
foreach my $m ( sort keys %data ) {
push( @data_for_gd, $data{ $m } );
}
# send it to GD!
$self->make_gdgraph( "LoopWar_$metric",
[ sort keys %{ $self->{'imager'}->poe_loops } ],
\@data_for_gd,
$assert,
$xsqueue,
);
}
}
}
return;
}
sub make_gdgraph {
my $self = shift;
my $metric = shift;
my $legend = shift;
my $data = shift;
my $assert = shift;
my $xsqueue = shift;
# build the title
my $title = $metric;
if ( defined $assert ) {
$title .= ' (';
if ( defined $xsqueue ) {
$title .= $assert . ' ' . $xsqueue;
} else {
$title .= $assert;
}
$title .= ')';
} else {
if ( defined $xsqueue ) {
$title .= ' (' . $xsqueue . ')';
}
}
# Get the graph object
my $graph = new GD::Graph::lines( 800, 600 );
# Set some stuff
$graph->set(
'title' => $title,
'line_width' => 1,
'boxclr' => 'black',
'overwrite' => 0,
'x_labels_vertical' => 1,
'x_all_ticks' => 1,
'legend_placement' => 'BL',
'y_label' => 'iterations/sec',
'transparent' => 0,
'long_ticks' => 1,
) or die $graph->error;
# Set the legend
$graph->set_legend( @$legend );
# Set Font stuff
$graph->set_legend_font( GD::gdMediumBoldFont );
$graph->set_x_axis_font( GD::gdMediumBoldFont );
$graph->set_y_axis_font( GD::gdMediumBoldFont );
$graph->set_y_label_font( GD::gdMediumBoldFont );
$graph->set_title_font( GD::gdGiantFont );
# set the line colors
$graph->set( 'dclrs' => [ grep { $_ ne 'black' and $_ ne 'white' } sorted_colour_list() ] );
# Manufacture the data
my $readydata = [
[ map { 'POE-' . $_ } @{ $self->{'imager'}->poe_versions_sorted } ],
@$data,
];
# Plot it!
$graph->plot( $readydata ) or die $graph->error;
# Print it!
my $filename = $self->{'opts'}->{'dir'} . $metric . '_' .
( $self->{'imager'}->litetests ? 'lite' : 'heavy' ) .
( defined $xsqueue ? '_' . $assert . '_' . $xsqueue : '' ) .
'.png';
open( my $fh, '>', $filename ) or die 'Cannot open graph file!';
binmode( $fh );
print $fh $graph->gd->png();
close( $fh );
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::Imager::BasicStatistics - Plugin to generates basic statistics graphs
=head1 SYNOPSIS
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker::Imager -e 'imager( { type => "BasicStatistics" } )'
=head1 ABSTRACT
This plugin for Imager generates some kinds of graphs from the benchmark tests.
=head1 DESCRIPTION
This package generates some basic graphs from the statistics output. Since the POE::Loop::* modules really are responsible
for the backend logic of POE, it makes sense to graph all related metrics of a single loop across POE versions to see if
it performs differently.
This will generate some types of graphs:
=over 4
=item Loops against each other
Each metric will have a picture for itself, showing how each loop compare against each other with the POE versions.
file: BasicStatistics/LoopWar_$metric_$lite_$assert_$xsqueue.png
=item Single Loop over POE versions
Each Loop will have a picture for itself, showing how each metric performs over POE versions.
file: BasicStatistics/Bench_$loop_$lite_$assert_$xsqueue.png
=item Single Loop over POE versions with assert/xsqueue
Each Loop will have a picture for itself, showing how each metric is affected by the assert/xsqueue options.
file: BasicStatistics/Options_$loop_$metric_$lite.png
=back
=head1 EXPORT
Nothing.
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
-Copyright 2008 by Apocalypse
+Copyright 2009 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/SubProcess.pm b/lib/POE/Devel/Benchmarker/SubProcess.pm
index 93a78b4..c45629b 100644
--- a/lib/POE/Devel/Benchmarker/SubProcess.pm
+++ b/lib/POE/Devel/Benchmarker/SubProcess.pm
@@ -439,519 +439,519 @@ sub poe_manyalarms {
# How many sessions can we create and destroy per second?
# Create a bunch of sessions, and track that time. Let them
# self-destruct, and track that as well.
sub poe_sessions {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $metrics{'session_creates'}; $i++) {
POE::Session->$pocosession( 'inline_states' => { _start => sub {}, _stop => sub {}, _default => sub { return 0 } } );
}
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'session_creates'}, 'session_creates', $elapsed, $metrics{'session_creates'}/$elapsed );
print "session_creates times: @start_times @end_times\n";
$_[KERNEL]->yield( 'sessions_end' );
$_[HEAP]->{start} = time();
$_[HEAP]->{starttimes} = [ times() ];
return;
}
sub poe_sessions_end {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'session_creates'}, 'session_destroys', $elapsed, $metrics{'session_creates'}/$elapsed );
print "session_destroys times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
$_[KERNEL]->yield( 'stdin_read' );
return;
}
# How many times can we select/unselect READ a from STDIN filehandle per second?
sub poe_stdin_read {
# stupid, but we have to skip those tests
if ( $eventloop eq 'Tk' or $eventloop eq 'Prima' ) {
print "SKIPPING br0ken select_read_STDIN because eventloop doesn't work: $eventloop\n";
print "SKIPPING br0ken select_write_STDIN because eventloop doesn't work: $eventloop\n";
$_[KERNEL]->yield( 'myfh_read' );
return;
}
my $start = time();
my @start_times = times();
eval {
for (my $i = 0; $i < $metrics{'select_read_STDIN'}; $i++) {
$_[KERNEL]->select_read( *STDIN, 'whee' );
$_[KERNEL]->select_read( *STDIN );
}
};
if ( $@ ) {
print "SKIPPING br0ken select_read_STDIN because FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'select_read_STDIN'}, 'select_read_STDIN', $elapsed, $metrics{'select_read_STDIN'}/$elapsed );
print "select_read_STDIN times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'stdin_write' );
return;
}
# How many times can we select/unselect WRITE a from STDIN filehandle per second?
sub poe_stdin_write {
my $start = time();
my @start_times = times();
eval {
for (my $i = 0; $i < $metrics{'select_write_STDIN'}; $i++) {
$_[KERNEL]->select_write( *STDIN, 'whee' );
$_[KERNEL]->select_write( *STDIN );
}
};
if ( $@ ) {
print "SKIPPING br0ken select_write_STDIN because FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'select_write_STDIN'}, 'select_write_STDIN', $elapsed, $metrics{'select_write_STDIN'}/$elapsed );
print "select_write_STDIN times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'myfh_read' );
return;
}
# How many times can we select/unselect READ a real filehandle?
sub poe_myfh_read {
# stupid, but we have to skip those tests
if ( $eventloop eq 'Event_Lib' or $eventloop eq 'Tk' or $eventloop eq 'Prima' ) {
print "SKIPPING br0ken select_read_MYFH because eventloop doesn't work: $eventloop\n";
print "SKIPPING br0ken select_write_MYFH because eventloop doesn't work: $eventloop\n";
$_[KERNEL]->yield( 'calls' );
return;
}
my $start = time();
my @start_times = times();
eval {
open( my $fh, '+>', 'poebench' ) or die $!;
for (my $i = 0; $i < $metrics{'select_read_MYFH'}; $i++) {
$_[KERNEL]->select_read( $fh, 'whee' );
$_[KERNEL]->select_read( $fh );
}
close( $fh ) or die $!;
unlink( 'poebench' ) or die $!;
};
if ( $@ ) {
print "SKIPPING br0ken select_read_MYFH because FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'select_read_MYFH'}, 'select_read_MYFH', $elapsed, $metrics{'select_read_MYFH'}/$elapsed );
print "select_read_MYFH times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'myfh_write' );
return;
}
# How many times can we select/unselect WRITE a real filehandle?
sub poe_myfh_write {
my $start = time();
my @start_times = times();
eval {
open( my $fh, '+>', 'poebench' ) or die $!;
for (my $i = 0; $i < $metrics{'select_write_MYFH'}; $i++) {
$_[KERNEL]->select_write( $fh, 'whee' );
$_[KERNEL]->select_write( $fh );
}
close( $fh ) or die $!;
unlink( 'poebench' ) or die $!;
};
if ( $@ ) {
print "SKIPPING br0ken select_write_MYFH because FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'select_write_MYFH'}, 'select_write_MYFH', $elapsed, $metrics{'select_write_MYFH'}/$elapsed );
print "select_write_MYFH times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'calls' );
return;
}
# How many times can we call a state?
sub poe_calls {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $metrics{'calls'}; $i++) {
$_[KERNEL]->call( $_[SESSION], 'null' );
}
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'calls'}, 'calls', $elapsed, $metrics{'calls'}/$elapsed );
print "calls times: @start_times @end_times\n";
$_[KERNEL]->yield( 'eventsquirt' );
return;
}
# How many events can we squirt through POE, one at a time?
sub poe_eventsquirt {
$_[HEAP]->{start} = time();
$_[HEAP]->{starttimes} = [ times() ];
$_[HEAP]->{yield_count} = $metrics{'single_posts'};
$_[KERNEL]->yield( 'eventsquirt_done' );
return;
}
sub poe_eventsquirt_done {
if (--$_[HEAP]->{yield_count}) {
$_[KERNEL]->yield( 'eventsquirt_done' );
} else {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'single_posts'}, 'single_posts', $elapsed, $metrics{'single_posts'}/$elapsed );
print "single_posts times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
$_[KERNEL]->yield( 'socketfactory' );
}
return;
}
# tests socketfactory interactions
sub poe_socketfactory {
# POE transitioned between Event to State on 0.19 for SocketFactory/ReadWrite
# 0.20+ throws deprecation error :(
$_[HEAP]->{'POE_naming'} = 'Event';
if ( version->new( $POE::VERSION ) < version->new( '0.20' ) ) {
$_[HEAP]->{'POE_naming'} = 'State';
}
# create the socketfactory server
$_[HEAP]->{'SF'} = POE::Wheel::SocketFactory->new(
'Port' => INADDR_ANY,
'Address' => 'localhost',
'Reuse' => 'yes',
'Success' . $_[HEAP]->{'POE_naming'} => 'server_sf_connect',
'Failure' . $_[HEAP]->{'POE_naming'} => 'server_sf_failure',
);
# be evil, and get the port for the client to connect to
( $_[HEAP]->{'SF_port'}, undef ) = sockaddr_in( getsockname( $_[HEAP]->{'SF'}->[ POE::Wheel::SocketFactory::MY_SOCKET_HANDLE() ] ) );
# start the connect tests
$_[HEAP]->{'SF_counter'} = $metrics{'socket_connects'};
$_[HEAP]->{'SF_mode'} = 'socket_connects';
$_[HEAP]->{'start'} = time();
$_[HEAP]->{'starttimes'} = [ times() ];
$_[KERNEL]->yield( 'socketfactory_connects' );
return;
}
# handles SocketFactory connection
sub poe_server_sf_connect {
# what test mode?
if ( $_[HEAP]->{'SF_mode'} eq 'socket_connects' ) {
# simply discard this socket
} elsif ( $_[HEAP]->{'SF_mode'} eq 'socket_stream' ) {
# convert it to ReadWrite
my $wheel = POE::Wheel::ReadWrite->new(
'Handle' => $_[ARG0],
'Filter' => POE::Filter::Line->new,
'Driver' => POE::Driver::SysRW->new,
'Input' . $_[HEAP]->{'POE_naming'} => 'server_rw_input',
'Error' . $_[HEAP]->{'POE_naming'} => 'server_rw_error',
);
# save it in our heap
$_[HEAP]->{'RW'}->{ $wheel->ID } = $wheel;
} else {
die "unknown test mode";
}
return;
}
# handles SocketFactory errors
sub poe_server_sf_failure {
# ARGH, we couldnt create listening socket
print "SKIPPING br0ken socket_connects because we were unable to setup listening socket\n";
print "SKIPPING br0ken socket_stream because we were unable to setup listening socket\n";
$_[KERNEL]->yield( 'socketfactory_cleanup' );
return;
}
# handles ReadWrite input
sub poe_server_rw_input {
# what test mode?
if ( $_[HEAP]->{'SF_mode'} eq 'socket_connects' ) {
# simply discard this data
} elsif ( $_[HEAP]->{'SF_mode'} eq 'socket_stream' ) {
# send it back to the client!
$_[HEAP]->{'RW'}->{ $_[ARG1] }->put( $_[ARG0] );
} else {
die "unknown test mode";
}
return;
}
# handles ReadWrite disconnects
sub poe_server_rw_error {
# simply get rid of the wheel
if ( exists $_[HEAP]->{'RW'}->{ $_[ARG3] } ) {
# FIXME do we need this?
eval {
$_[HEAP]->{'RW'}->{ $_[ARG3] }->shutdown_input;
$_[HEAP]->{'RW'}->{ $_[ARG3] }->shutdown_output;
};
delete $_[HEAP]->{'RW'}->{ $_[ARG3] };
}
return;
}
# starts the client connect tests
sub poe_socketfactory_connects {
if (--$_[HEAP]->{'SF_counter'}) {
# open a new client connection!
$_[HEAP]->{'client_SF'} = POE::Wheel::SocketFactory->new(
'RemoteAddress' => 'localhost',
'RemotePort' => $_[HEAP]->{'SF_port'},
'Success' . $_[HEAP]->{'POE_naming'} => 'client_sf_connect',
'Failure' . $_[HEAP]->{'POE_naming'} => 'client_sf_failure',
);
} else {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'socket_connects'}, 'socket_connects', $elapsed, $metrics{'socket_connects'}/$elapsed );
print "socket_connects times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
$_[KERNEL]->yield( 'socketfactory_stream' );
}
return;
}
# starts the client stream tests
sub poe_socketfactory_stream {
# set the proper test mode
$_[HEAP]->{'SF_mode'} = 'socket_stream';
# open a new client connection!
$_[HEAP]->{'client_SF'} = POE::Wheel::SocketFactory->new(
'RemoteAddress' => 'localhost',
'RemotePort' => $_[HEAP]->{'SF_port'},
'Success' . $_[HEAP]->{'POE_naming'} => 'client_sf_connect',
'Failure' . $_[HEAP]->{'POE_naming'} => 'client_sf_failure',
);
return;
}
# the client connected to the server!
sub poe_client_sf_connect {
# what test mode?
if ( $_[HEAP]->{'SF_mode'} eq 'socket_connects' ) {
# simply discard this connection
delete $_[HEAP]->{'client_SF'};
# make another connection!
$_[KERNEL]->yield( 'socketfactory_connects' );
} elsif ( $_[HEAP]->{'SF_mode'} eq 'socket_stream' ) {
# convert it to ReadWrite
my $wheel = POE::Wheel::ReadWrite->new(
'Handle' => $_[ARG0],
'Filter' => POE::Filter::Line->new,
'Driver' => POE::Driver::SysRW->new,
'Input' . $_[HEAP]->{'POE_naming'} => 'client_rw_input',
'Error' . $_[HEAP]->{'POE_naming'} => 'client_rw_error',
);
# save it in our heap
$_[HEAP]->{'client_RW'}->{ $wheel->ID } = $wheel;
# begin the STREAM test!
$_[HEAP]->{'SF_counter'} = $metrics{'socket_stream'};
$_[HEAP]->{'SF_data'} = 'x' x ( $metrics{'socket_stream'} / 10 ); # set a reasonable-sized chunk of data
$_[HEAP]->{'start'} = time();
$_[HEAP]->{'starttimes'} = [ times() ];
$wheel->put( $_[HEAP]->{'SF_data'} );
} else {
die "unknown test mode";
}
return;
}
# handles SocketFactory errors
sub poe_client_sf_failure {
# ARGH, we couldnt create connecting socket
if ( $_[HEAP]->{'SF_mode'} eq 'socket_connects' ) {
print "SKIPPING br0ken socket_connects because we were unable to setup connecting socket\n";
# go to stream test
$_[KERNEL]->yield( 'socketfactory_stream' );
} elsif ( $_[HEAP]->{'SF_mode'} eq 'socket_stream' ) {
print "SKIPPING br0ken socket_stream because we were unable to setup connecting socket\n";
$_[KERNEL]->yield( 'socketfactory_cleanup' );
}
return;
}
# handles ReadWrite input
sub poe_client_rw_input {
if (--$_[HEAP]->{'SF_counter'}) {
# send it back to the server!
$_[HEAP]->{'client_RW'}->{ $_[ARG1] }->put( $_[ARG0] );
} else {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'socket_stream'}, 'socket_stream', $elapsed, $metrics{'socket_stream'}/$elapsed );
print "socket_stream times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
$_[KERNEL]->yield( 'socketfactory_cleanup' );
}
return;
}
# handles ReadWrite disconnect
sub poe_client_rw_error {
# simply get rid of the wheel
if ( exists $_[HEAP]->{'client_RW'}->{ $_[ARG3] } ) {
# FIXME do we need this?
eval {
$_[HEAP]->{'client_RW'}->{ $_[ARG3] }->shutdown_input;
$_[HEAP]->{'client_RW'}->{ $_[ARG3] }->shutdown_output;
};
delete $_[HEAP]->{'client_RW'}->{ $_[ARG3] };
}
return;
}
# all done with the socketfactory tests
sub poe_socketfactory_cleanup {
# do cleanup
delete $_[HEAP]->{'SF'} if exists $_[HEAP]->{'SF'};
delete $_[HEAP]->{'RW'} if exists $_[HEAP]->{'RW'};
delete $_[HEAP]->{'client_SF'} if exists $_[HEAP]->{'client_SF'};
delete $_[HEAP]->{'client_RW'} if exists $_[HEAP]->{'client_RW'};
# XXX all done with tests!
return;
}
# Get the memory footprint
sub dump_pidinfo {
my $ret = open( my $fh, '<', '/proc/self/status' );
if ( defined $ret ) {
while ( <$fh> ) {
chomp;
if ( $_ ne '' ) {
print "pidinfo: $_\n";
}
}
close( $fh ) or die $!;
} else {
print "UNABLE TO GET /proc/self/status\n";
}
return;
}
# print the local Perl info
sub dump_perlinfo {
print "Running under perl binary: '" . $^X . "' v" . sprintf( "%vd", $^V ) . "\n";
require Config;
my $config = Config::myconfig();
foreach my $l ( split( /\n/, $config ) ) {
print "perlconfig: $l\n";
}
return;
}
# print the local system information
sub dump_sysinfo {
print "Running under machine: " . `uname -a` . "\n";
# get cpuinfo
my $ret = open( my $fh, '<', '/proc/cpuinfo' );
if ( defined $ret ) {
while ( <$fh> ) {
chomp;
if ( $_ ne '' ) {
print "cpuinfo: $_\n";
}
}
close( $fh ) or die $!;
} else {
print "UNABLE TO GET /proc/cpuinfo\n";
}
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::SubProcess - Implements the actual POE benchmarks
=head1 SYNOPSIS
perl -MPOE::Devel::Benchmarker::SubProcess -e 'benchmark()'
=head1 ABSTRACT
This package is responsible for implementing the guts of the benchmarks, and timing them.
=head1 EXPORT
Nothing.
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
-Copyright 2008 by Apocalypse
+Copyright 2009 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/Utils.pm b/lib/POE/Devel/Benchmarker/Utils.pm
index 8086095..58ae260 100644
--- a/lib/POE/Devel/Benchmarker/Utils.pm
+++ b/lib/POE/Devel/Benchmarker/Utils.pm
@@ -1,236 +1,236 @@
# Declare our package
package POE::Devel::Benchmarker::Utils;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.05';
# set ourself up for exporting
use base qw( Exporter );
our @EXPORT_OK = qw( poeloop2load load2poeloop loop2realversion beautify_times knownloops generateTestfile
currentMetrics currentTestVersion
);
# returns the current test output version
sub currentTestVersion {
return '1';
}
# returns the list of current metrics
sub currentMetrics {
return [ qw(
startups
alarms alarm_adds alarm_clears
dispatches posts single_posts
session_creates session_destroys
select_read_MYFH select_write_MYFH select_read_STDIN select_write_STDIN
socket_connects socket_stream
) ];
}
# returns the filename for a particular test
sub generateTestfile {
my $heap = shift;
return 'POE-' . $heap->{'current_version'} .
'-' . $heap->{'current_loop'} .
'-' . ( $heap->{'lite_tests'} ? 'LITE' : 'HEAVY' ) .
'-' . ( $heap->{'current_assertions'} ? 'assert' : 'noassert' ) .
'-' . ( $heap->{'current_noxsqueue'} ? 'noxsqueue' : 'xsqueue' );
}
# maintains the mapping of the loop <-> real module
my %poe2load = (
'Event' => 'Event',
'IO_Poll' => 'IO::Poll',
'Event_Lib' => 'Event::Lib',
'EV' => 'EV',
'Glib' => 'Glib',
'Tk' => 'Tk',
'Gtk' => 'Gtk',
'Prima' => 'Prima',
'Wx' => 'Wx',
'Kqueue' => undef,
'Select' => undef,
);
# returns the proper "load" stuff for a specific loop
sub poeloop2load {
my $eventloop = shift;
if ( exists $poe2load{ $eventloop } ) {
return $poe2load{ $eventloop };
} else {
die "Unknown event loop!";
}
}
# returns the version of the "real" installed module that the loop uses
sub loop2realversion {
my $eventloop = shift;
# Decide which event loop to use
if ( ! defined $eventloop ) {
return;
} elsif ( $eventloop eq 'Event' ) {
return $Event::VERSION;
} elsif ( $eventloop eq 'IO_Poll' ) {
return $IO::Poll::VERSION;
} elsif ( $eventloop eq 'Event_Lib' ) {
return $Event::Lib::VERSION;
} elsif ( $eventloop eq 'EV' ) {
return $EV::VERSION;
} elsif ( $eventloop eq 'Glib' ) {
return $Glib::VERSION;
} elsif ( $eventloop eq 'Tk' ) {
return $Tk::VERSION;
} elsif ( $eventloop eq 'Gtk' ) {
return $Gtk::VERSION;
} elsif ( $eventloop eq 'Prima' ) {
return $Prima::VERSION;
} elsif ( $eventloop eq 'Wx' ) {
return $Wx::VERSION;
} elsif ( $eventloop eq 'Kqueue' ) {
# FIXME how do I do this?
return;
} elsif ( $eventloop eq 'Select' ) {
return 'BUILTIN';
# FIXME figure the XS stuff out!
# } elsif ( $eventloop eq 'XSPoll' ) {
# return $POE::XS::Loop::Poll::VERSION;
# } elsif ( $eventloop eq 'XSEpoll' ) {
# return $POE::XS::Loop::EPoll::VERSION;
} else {
die "Unknown event loop!";
}
}
# helper routine to parse times() output
sub beautify_times {
my $string = shift;
my $origdata = shift;
# split it up
$string =~ s/^\s+//; $string =~ s/\s+$//;
my @times = split( /\s+/, $string );
# make the data struct
# ($user,$system,$cuser,$csystem) = times;
my $data = {
'u' => $times[4] - $times[0],
's' => $times[5] - $times[1],
'cu' => $times[6] - $times[2],
'cs' => $times[7] - $times[3],
};
# add original data?
if ( $origdata ) {
$data->{'s_user'} = $times[0];
$data->{'s_sys'} = $times[1];
$data->{'s_cuser'} = $times[2];
$data->{'s_csys'} = $times[3];
$data->{'e_user'} = $times[4];
$data->{'e_sys'} = $times[5];
$data->{'e_cuser'} = $times[6];
$data->{'e_csys'} = $times[7];
}
# send it back!
return $data;
}
# returns a list of "known" POE loops
sub knownloops {
# FIXME we remove Wx because I suck.
# FIXME I have no idea how to load/unload Kqueue...
# FIXME figure out the XS stuff! XSPoll XSEPoll
return [ qw( Event_Lib EV Glib Prima Gtk Tk Select IO_Poll ) ];
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::Utils - Various utility routines for POE::Devel::Benchmarker
=head1 SYNOPSIS
perl -MPOE::Devel::Benchmarker::Utils -e 'print poeloop2load( "IO_Poll" )'
=head1 ABSTRACT
This package contains the utility routines and constants that POE::Devel::Benchmarker needs.
=head1 EXPORT
This package exports those subs via @EXPORT_OK:
=over 4
=item currentTestVersion()
Returns the current test version, used to identify different versions of the test output
=item currentMetrics()
Returns an arrayref of the current benchmark "metrics" that we process
=item knownloops()
Returns an arrayref of the "known" POE loops as of this version of the Benchmarker
=item poeloop2load()
Returns the "parent" class to load for a specific loop. An example is:
$real = poeloop2load( 'IO_Poll' ); # $real now contains "IO::Poll"
=item loop2realversion()
Returns the version of the "parent" class for a specific loop. An example is:
$ver = loop2realversion( 'IO_Poll' ); # $ver now contains $IO::Poll::VERSION
=item beautify_times()
Returns a hashref of data from parsing 2 consecutive times() structures in a string. You can pass an additional parameter
( boolean ) to include the original data. An example is:
print Data::Dumper::Dumper( beautify_times( '0.1 0 0 0 0.1 0 0.76 0.09', 1 ) );
{
"sys" => 0, # total system time
"user" => 0, # total user time
"csys" => 0.76 # total children system time
"cuser" => 0.08 # total children user time
"e_csys" => "0.09", # end children system time ( optional )
"e_cuser" => "0.76", # end children user time ( optional )
"e_sys" => 0, # end system time ( optional )
"e_user" => "0.1", # end user time ( optional )
"s_csys" => 0, # start children system time ( optional )
"s_cuser" => 0, # start children user time ( optional )
"s_sys" => 0, # start system time ( optional )
"s_user" => "0.1" # start user time ( optional )
}
=back
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
-Copyright 2008 by Apocalypse
+Copyright 2009 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
|
apocalypse/perl-poe-benchmarker
|
da8579c9d51e2175358b4745c737560c9fd632b0
|
remove Gtk dep, as we only need Glib
|
diff --git a/Build.PL b/Build.PL
index a606594..f0886b4 100644
--- a/Build.PL
+++ b/Build.PL
@@ -1,109 +1,108 @@
# Build.PL
use Module::Build;
my $build = Module::Build->new(
# look up Module::Build::API for the info!
'dynamic_config' => 0,
'module_name' => 'POE::Devel::Benchmarker',
'license' => 'perl',
'dist_abstract' => "Benchmarking POE's performance ( acts more like a smoker )",
'dist_author' => 'Apocalypse <APOCAL@cpan.org>',
'create_packlist' => 1,
'create_makefile_pl' => 'traditional',
'create_readme' => 1,
'test_files' => 't/*.t',
'add_to_cleanup' => [ 'META.yml', 'Makefile.PL', 'README' ], # automatically generated
'requires' => {
# POE Stuff
'POE' => 0,
'POE::Session::AttributeBased' => 0,
# FIXME POE stuff that Test::Dependencies needs to see
'POE::Session' => 0,
'POE::Wheel::SocketFactory' => 0,
'POE::Wheel::ReadWrite' => 0,
'POE::Filter::Line' => 0,
'POE::Driver::SysRW' => 0,
# misc perl stuff
'Time::HiRes' => 0,
'version' => 0,
'Devel::Hide' => 0,
# Analyzer reqs
'YAML::Tiny' => 0,
# GetPOEdists reqs
'LWP::UserAgent' => 0,
'HTML::LinkExtor' => 0,
'URI::URL' => 0,
'Archive::Tar' => 0,
# Imager reqs
'GD::Graph::lines' => 0,
'GD::Graph::colour' => 0,
'Class::Accessor::Fast' => 0,
'Module::Pluggable' => 0,
# Test stuff
'Test::More' => '0.86', # require latest for note() support in t/a_is_prereq_outdated.t
},
'recommends' => {
# our POE loops!
'POE::Loop::Event' => 0,
'POE::Loop::Event_Lib' => 0,
'POE::Loop::EV' => 0,
'POE::Loop::Glib' => 0,
'POE::Loop::Prima' => 0,
'POE::Loop::Gtk' => 0,
'POE::Loop::Wx' => 0,
'POE::Loop::Kqueue' => 0,
# included in POE ( listed here for completeness )
#'POE::Loop::Tk' => 0,
#'POE::Loop::Select' => 0,
#'POE::Loop::IO_Poll' => 0,
# the loops' dependencies
'Event' => 0,
'Event::Lib' => 0,
'EV' => 0,
'Glib' => 0,
'Prima' => 0,
- 'Gtk' => 0,
'Wx' => 0,
'Tk' => 0,
# the XS queue
'POE::XS::Queue::Array' => 0,
},
# FIXME wishlist...
# 'test_requires' => {
# # Test stuff
# 'Test::Compile' => 0,
# 'Test::Perl::Critic' => 0,
# 'Test::Dependencies' => 0,
# 'Test::Distribution' => 0,
# 'Test::Fixme' => 0,
# 'Test::HasVersion' => 0,
# 'Test::Kwalitee' => 0,
# 'Test::CheckManifest' => 0,
# 'Test::MinimumVersion' => 0,
# 'Test::Pod::Coverage' => 0,
# 'Test::Spelling' => 0,
# 'Test::Pod' => 0,
# 'Test::Prereq' => 0,
# 'Test::Strict' => 0,
# 'Test::UseAllModules' => 0,
# },
);
# all done!
$build->create_build_script;
|
apocalypse/perl-poe-benchmarker
|
02fcc50f534eb6206bf7f7b27aaffb639b731241
|
add some more stuff
|
diff --git a/Changes b/Changes
index 30ab3c1..56ea3d8 100644
--- a/Changes
+++ b/Changes
@@ -1,39 +1,40 @@
Revision history for Perl extension POE::Devel::Benchmarker
* 0.05
Minor tweaks on the YAML output ( nothing new, hah! )
Added the socket tests, yay! ( adapted from LotR's script, thanks! )
Some more tweaks to the BasicStatistics plugin for prettier graphs
Lots of refactoring to get things cleaned up :)
+ Added test versioning, so we make sure we're processing the right version :)
* 0.04
Started work on the image generator ( Imager ) and added the BasicStatistics plugin, yay!
Added automatic "pick up where we left off" to the benchmarker
Added the freshstart option to benchmark()
Tweaked the GetPOEdists sub so it will work in the "work directory" and in the poedists dir
Tweaked the YAML output so it's smaller
Removed POE::Loop::Wx from autoprobing ( I'm unable to get it to work )
Removed POE::Loop::Kqueue from autoprobing ( I'm unable to get it to work )
Hardcoded the Benchmarker routines to skip POE < 0.13 ( I'm unable to get it to work )
* 0.03
Added the loop option to benchmark(), thanks dngor!
Added the poe option to benchmark(), thanks dngor!
Added the noxsqueue option to benchmark()
Added the noasserts option to benchmark()
Automatically enable noxsqueue option if we cannot load POE::XS::Queue::Array, saving time
Bump Test::More version requirement because some people reported failures with note()
Fixed bug in SubProcess where it crashed on old POEs that didn't load IO::Handle
More documentation additions/tweaks
* 0.02
Added the Analyzer module ( and dump YAML files, yay! )
A lot of minor changes+tweaks to get a better dump format
* 0.01
initial release
|
apocalypse/perl-poe-benchmarker
|
cb4b3f530f5f41aec6db4d172dfa14c8327846bc
|
general cleanups
|
diff --git a/Build.PL b/Build.PL
old mode 100755
new mode 100644
diff --git a/Changes b/Changes
old mode 100755
new mode 100644
diff --git a/MANIFEST b/MANIFEST
old mode 100755
new mode 100644
index 50f5869..5ce3917
--- a/MANIFEST
+++ b/MANIFEST
@@ -1,35 +1,36 @@
Makefile.PL
Build.PL
MANIFEST
MANIFEST.SKIP
README
lib/POE/Devel/Benchmarker.pm
lib/POE/Devel/Benchmarker/GetInstalledLoops.pm
lib/POE/Devel/Benchmarker/GetPOEdists.pm
lib/POE/Devel/Benchmarker/SubProcess.pm
lib/POE/Devel/Benchmarker/Utils.pm
lib/POE/Devel/Benchmarker/Imager.pm
lib/POE/Devel/Benchmarker/Imager/BasicStatistics.pm
META.yml
Changes
t/1_load.t
t/a_critic.t
t/a_kwalitee.t
t/a_pod.t
t/a_pod_spelling.t
t/a_pod_coverage.t
t/a_strict.t
t/a_hasversion.t
t/a_minimumversion.t
t/a_manifest.t
t/a_distribution.t
t/a_compile.t
t/a_dependencies.t
t/a_fixme.t
t/a_prereq.t
t/a_prereq_build.t
t/a_dosnewline.t
t/a_perlmetrics.t
t/a_is_prereq_outdated.t
+t/a_metayml.t
diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP
old mode 100755
new mode 100644
diff --git a/lib/POE/Devel/Benchmarker/Imager.pm b/lib/POE/Devel/Benchmarker/Imager.pm
index e5f977d..82fac2a 100644
--- a/lib/POE/Devel/Benchmarker/Imager.pm
+++ b/lib/POE/Devel/Benchmarker/Imager.pm
@@ -1,447 +1,450 @@
# Declare our package
package POE::Devel::Benchmarker::Imager;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.05';
# auto-export the only sub we have
use base qw( Exporter );
our @EXPORT = qw( imager );
# import the helper modules
use YAML::Tiny;
# load our plugins!
use Module::Pluggable search_path => [ __PACKAGE__ ];
# load comparison stuff
use version;
# Get some stuff from Utils
use POE::Devel::Benchmarker::Utils qw( currentTestVersion );
# generate some accessors
use base qw( Class::Accessor::Fast );
__PACKAGE__->mk_ro_accessors( qw( poe_versions poe_versions_sorted poe_loops data
noxsqueue noasserts litetests quiet
) );
# autoflush, please!
use IO::Handle;
STDOUT->autoflush( 1 );
# starts the work of converting our data to images
sub imager {
my $options = shift;
# instantitate ourself
my $self = __PACKAGE__->new( $options );
# parse all of our YAML modules!
$self->loadtests;
# process some stats
$self->process_data;
# generate the images!
$self->generate_images;
return;
}
# creates a new instance
sub new {
my $class = shift;
my $opts = shift;
# instantitate ourself
my $self = {};
bless $self, $class;
# init the options
$self->init_options( $opts );
if ( ! $self->{'options'}->{'quiet'} ) {
print "[IMAGER] Starting up...\n";
}
return $self;
}
sub init_options {
my $self = shift;
my $options = shift;
# set defaults
$self->{'quiet'} = 0;
$self->{'litetests'} = 1;
$self->{'noasserts'} = undef;
$self->{'noxsqueue'} = undef;
# process our options
if ( defined $options and ref $options and ref( $options ) eq 'HASH' ) {
# process quiet mode
if ( exists $options->{'quiet'} ) {
if ( $options->{'quiet'} ) {
$self->{'quiet'} = 1;
} else {
$self->{'quiet'} = 0;
}
}
# process the LITE/HEAVY
if ( exists $options->{'litetests'} ) {
if ( $options->{'litetests'} ) {
$self->{'litetests'} = 1;
} else {
$self->{'litetests'} = 0;
}
}
# process the noasserts to load
if ( exists $options->{'noasserts'} ) {
if ( $options->{'noasserts'} ) {
$self->{'noasserts'} = 1;
} else {
$self->{'noasserts'} = 0;
}
}
# process the noxsqueue to load
if ( exists $options->{'noxsqueue'} ) {
if ( $options->{'noxsqueue'} ) {
$self->{'noxsqueue'} = 1;
} else {
$self->{'noxsqueue'} = 0;
}
}
# FIXME process the plugins to load -> "types"
# FIXME process the versions to load
# FIXME process the loops to load
}
# some sanity tests
if ( ! -d 'results' ) {
die "The 'results' directory is not found in the working directory!";
}
if ( ! -d 'images' ) {
die "The 'images' directory is not found in the working directory!";
}
return;
}
# starts the process of loading all of our YAML images
sub loadtests {
my $self = shift;
# gather all the YAML dumps
if ( opendir( DUMPS, 'results' ) ) {
foreach my $d ( readdir( DUMPS ) ) {
# parse the file structure
# POE-1.0002-IO_Poll-LITE-assert-noxsqueue.yml
if ( $d =~ /^POE\-([\d\.\_]+)\-(\w+?)\-(LITE|HEAVY)\-(noassert|assert)\-(noxsqueue|xsqueue)\.yml$/ ) {
my( $ver, $loop, $lite, $assert, $xsqueue ) = ( $1, $2, $3, $4, $5 );
# skip this file?
if ( $self->noxsqueue ) {
if ( $xsqueue eq 'xsqueue' ) { next }
} else {
if ( defined $self->noxsqueue ) {
if ( $xsqueue eq 'noxsqueue' ) { next }
}
}
if ( $self->noasserts ) {
if ( $assert eq 'assert' ) { next }
} else {
if ( defined $self->noasserts ) {
if ( $assert eq 'noassert' ) { next }
}
}
if ( $self->litetests ) {
if ( $lite eq 'HEAVY' ) { next }
} else {
if ( $lite eq 'LITE' ) { next }
}
# FIXME allow selective loading of tests, so we can control what to image, etc
# actually load this file!
$self->load_yaml( $d, $ver, $loop, $lite, $assert, $xsqueue );
}
}
closedir( DUMPS ) or die "[IMAGER] Unable to read from 'results' -> " . $!;
} else {
die "[IMAGER] Unable to open 'results' for reading -> " . $!;
}
# sanity
if ( ! exists $self->{'data'} ) {
die "[IMAGER] Unable to find valid POE test result(s) in the 'results' directory!\n";
}
if ( ! $self->quiet ) {
print "[IMAGER] Done with parsing the YAML files...\n";
}
return;
}
# loads the yaml of a specific file
sub load_yaml {
my ( $self, $file, $ver, $loop, $lite, $assert, $xsqueue ) = @_;
my $yaml = YAML::Tiny->read( 'results/' . $file );
if ( ! defined $yaml ) {
print "[IMAGER] Unable to load YAML file $file -> " . YAML::Tiny->errstr . "\n";
return;
} else {
# inrospect it!
my $isvalid = 0;
eval {
# simple sanity check: the "x_bench" param is at the end of the YML, so if it loads fine we know it's there
if ( defined $yaml->[0] and exists $yaml->[0]->{'x_bench'} ) {
# version must at least match us
$isvalid = ( $yaml->[0]->{'x_bench'} eq currentTestVersion() ? 1 : 0 );
} else {
$isvalid = undef;
}
};
if ( ! $isvalid or $@ ) {
print "[IMAGER] Detected outdated/corrupt benchmark result: $file";
return;
} else {
# reduce indirection
$yaml = $yaml->[0];
}
}
# store the POE version
$self->{'poe_versions'}->{ $ver } = 1;
# sanity check the loop master version ( which should always be our "installed" version, not per-POE )
if ( exists $yaml->{'poe'}->{'loop_m'} ) {
if ( ! defined $self->{'poe_loops'}->{ $loop } ) {
$self->{'poe_loops'}->{ $loop } = $yaml->{'poe'}->{'loop_m'};
} else {
if ( $self->{'poe_loops'}->{ $loop } ne $yaml->{'poe'}->{'loop_m'} ) {
die "[IMAGER] Detected POE::Loop master version inconsistency! $file reported '" . $yaml->{'poe'}->{'loop_m'} .
"' while others had '" . $self->{'poe_loops'}->{ $loop } . "'";
}
}
}
# get the info we're interested in
$self->{'data'}->{ $assert }->{ $xsqueue }->{ $ver }->{ $loop }->{'metrics'} = $yaml->{'metrics'};
$self->{'data'}->{ $assert }->{ $xsqueue }->{ $ver }->{ $loop }->{'time'} = $yaml->{'t'};
if ( exists $yaml->{'pid'} ) {
$self->{'data'}->{ $assert }->{ $xsqueue }->{ $ver }->{ $loop }->{'pid'} = $yaml->{'pid'};
}
if ( exists $yaml->{'poe'}->{'modules'} ) {
$self->{'data'}->{ $assert }->{ $xsqueue }->{ $ver }->{ $loop }->{'poe_modules'} = $yaml->{'poe'}->{'modules'};
}
# sanity check the perl stuff
if ( exists $yaml->{'perl'}->{'binary'} ) {
if ( ! exists $self->{'data'}->{'perlconfig'} ) {
$self->{'data'}->{'perlconfig'}->{'binary'} = $yaml->{'perl'}->{'binary'};
$self->{'data'}->{'perlconfig'}->{'version'} = $yaml->{'perl'}->{'v'};
} else {
if ( $self->{'data'}->{'perlconfig'}->{'binary'} ne $yaml->{'perl'}->{'binary'} ) {
die "[IMAGER] Detected perl binary inconsistency! $file reported '" . $yaml->{'perl'}->{'binary'} .
"' while others had '" . $self->{'data'}->{'perlconfig'}->{'binary'} . "'";
}
if ( $self->{'data'}->{'perlconfig'}->{'version'} ne $yaml->{'perl'}->{'v'} ) {
die "[IMAGER] Detected perl version inconsistency! $file reported '" . $yaml->{'perl'}->{'v'} .
"' while others had '" . $self->{'data'}->{'perlconfig'}->{'version'} . "'";
}
}
}
# sanity check the uname
if ( exists $yaml->{'uname'} ) {
if ( ! exists $self->{'data'}->{'uname'} ) {
$self->{'data'}->{'uname'} = $yaml->{'uname'};
} else {
if ( $self->{'data'}->{'uname'} ne $yaml->{'uname'} ) {
die "[IMAGER] Detected system inconsistency! $file reported '" . $yaml->{'uname'} .
"' while others had '" . $self->{'data'}->{'uname'} . "'";
}
}
}
# sanity check the cpu name
if ( exists $yaml->{'cpu'} ) {
if ( ! exists $self->{'data'}->{'cpu'} ) {
$self->{'data'}->{'cpu'} = $yaml->{'cpu'};
} else {
if ( $self->{'data'}->{'cpu'}->{'name'} ne $yaml->{'cpu'}->{'name'} ) {
die "[IMAGER] Detected system/cpu inconsistency! $file reported '" . $yaml->{'cpu'}->{'name'} .
"' while others had '" . $self->{'data'}->{'cpu'}->{'name'} . "'";
}
}
}
return;
}
sub process_data {
my $self = shift;
# sanitize the versions in an ordered loop
- $self->{'poe_versions_sorted'} = [ map { $_->stringify } sort { $a <=> $b } map { version->new($_) } keys %{ $self->poe_versions } ];
+ $self->{'poe_versions_sorted'} = [ map { $_->stringify }
+ sort { $a <=> $b }
+ map { version->new($_) } keys %{ $self->poe_versions }
+ ];
if ( ! $self->quiet ) {
print "[IMAGER] Done with processing the benchmark statistics...\n";
}
return;
}
sub generate_images {
my $self = shift;
# load our plugins and let them have fun :)
foreach my $plugin ( $self->plugins ) {
# actually load it!
## no critic
eval "require $plugin";
## use critic
if ( $@ ) {
if ( ! $self->quiet ) {
print "[IMAGER] Unable to load plugin $plugin -> $@\n";
next;
}
}
# sanity checks
if ( $plugin->can( 'new' ) and $plugin->can( 'imager' ) ) {
# FIXME did we want this plugin?
# create the plugin's home dir
my $homedir = $plugin;
if ( $homedir =~ /\:\:(\w+)$/ ) {
$homedir = $1;
} else {
die "barf";
}
if ( ! -d "images/$homedir" ) {
# create it!
if ( ! mkdir( "images/$homedir" ) ) {
die "[IMAGER] Unable to create plugin directory: $homedir";
}
}
# Okay, get this plugin!
my $obj = $plugin->new( { 'dir' => "images/$homedir/" } );
if ( ! $self->quiet ) {
print "[IMAGER] Processing the $plugin plugin...\n";
}
$obj->imager( $self );
}
}
if ( ! $self->quiet ) {
print "[IMAGER] Done with generating images...\n";
}
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::Imager - Automatically converts the benchmark data into images
=head1 SYNOPSIS
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker::Imager -e 'imager'
=head1 ABSTRACT
This package automatically parses the benchmark data and generates pretty charts.
=head1 DESCRIPTION
It will parse the YAML output from the benchmark data and calls it's plugins to generate any charts necessary
and place them in the 'images' directory under the plugin's name. This module only does the high-level stuff, and leaves
the actual chart generation to the plugins.
Furthermore, we use Module::Pluggable to search all modules in the POE::Devel::Benchmarker::Imager::* namespace and
let them handle the generation of images. That way virtually unlimited combinations of images can be generated on the fly
from the data this module parses.
The way to use this module is by calling the imager() subroutine and let it do it's job. You can pass a hashref to it to
set various options. Here is a list of the valid options:
=over 4
=item quiet => boolean
This enables quiet mode which will not print anything to the console except for errors.
new( { 'quiet' => 1 } );
default: false
=item noxsqueue => boolean / undef
This will tell the Imager to not consider those tests for the output.
benchmark( { noxsqueue => 1 } );
default: undef ( load both xsqueue and noxsqueue tests )
=item noasserts => boolean / undef
This will tell the Imager to not consider those tests for the output
benchmark( { noasserts => 1 } );
default: undef ( load both assert and noassert tests )
=item litetests => boolean
This will tell the Imager to not consider those tests for the output
benchmark( { litetests => 0 } );
default: true
=back
=head1 PLUGIN INTERFACE
For now, this is undocumented. Please look at BasicStatistics for the general concept on how it interacts with this module.
=head1 EXPORT
Automatically exports the imager() sub
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/t/1_load.t b/t/1_load.t
old mode 100755
new mode 100644
diff --git a/t/a_distribution.t b/t/a_distribution.t
old mode 100755
new mode 100644
diff --git a/t/a_hasversion.t b/t/a_hasversion.t
old mode 100755
new mode 100644
diff --git a/t/a_is_prereq_outdated.t b/t/a_is_prereq_outdated.t
index 1d7661b..ed1f17f 100644
--- a/t/a_is_prereq_outdated.t
+++ b/t/a_is_prereq_outdated.t
@@ -1,128 +1,126 @@
#!/usr/bin/perl
use strict;
use warnings;
use Test::More;
# AUTHOR test
if ( not $ENV{TEST_AUTHOR} ) {
plan skip_all => 'Author test. Sent $ENV{TEST_AUTHOR} to a true value to run.';
} else {
# can we load YAML?
eval "use YAML";
if ( $@ ) {
plan skip_all => 'YAML is necessary to check META.yml for prerequisites!';
}
# can we load CPANPLUS?
eval "use CPANPLUS::Backend";
if ( $@ ) {
plan skip_all => 'CPANPLUS is necessary to check module versions!';
}
# can we load version.pm?
eval "use version";
if ( $@ ) {
plan skip_all => 'version.pm is necessary to compare versions!';
}
# does META.yml exist?
if ( -e 'META.yml' and -f _ ) {
load_yml( 'META.yml' );
} else {
# maybe one directory up?
if ( -e '../META.yml' and -f _ ) {
load_yml( '../META.yml' );
} else {
plan skip_all => 'META.yml is missing, unable to process it!';
}
}
}
# main entry point
sub load_yml {
# we'll load a file
my $file = shift;
# okay, proceed to load it!
my $data;
eval {
$data = YAML::LoadFile( $file );
};
if ( $@ ) {
plan skip_all => "Unable to load $file => $@";
} else {
- note "Loaded $file, proceeding with analysis";
+ note( "Loaded $file, proceeding with analysis" );
}
# massage the data
$data = $data->{'requires'};
delete $data->{'perl'} if exists $data->{'perl'};
# FIXME shut up warnings ( eval's fault, blame it! )
require version;
# init the backend ( and set some options )
my $cpanconfig = CPANPLUS::Configure->new;
$cpanconfig->set_conf( 'verbose' => 0 );
$cpanconfig->set_conf( 'no_update' => 1 );
my $cpanplus = CPANPLUS::Backend->new( $cpanconfig );
# silence CPANPLUS!
{
no warnings 'redefine';
eval "sub Log::Message::Handlers::cp_msg { return }";
eval "sub Log::Message::Handlers::cp_error { return }";
}
# Okay, how many prereqs do we have?
plan tests => scalar keys %$data;
# analyze every one of them!
foreach my $prereq ( keys %$data ) {
check_cpan( $cpanplus, $prereq, $data->{ $prereq } );
}
}
# checks a prereq against CPAN
sub check_cpan {
my $backend = shift;
my $prereq = shift;
my $version = shift;
# check CPANPLUS
my $module = $backend->parse_module( 'module' => $prereq );
if ( defined $module ) {
# okay, for starters we check to see if it's version 0 then we skip it
if ( $version eq '0' ) {
ok( 1, "Skipping '$prereq' because it is specified as version 0" );
return;
}
# Does the prereq have funky characters that we're unable to process now?
if ( $version =~ /[<>=,!]+/ ) {
# FIXME simplistic style of parsing
my @versions = split( ',', $version );
# sort them by version, descending
- @versions =
- sort { $b <=> $a }
- map { version->new( $_ ) }
- map { $_ =~ s/[\s<>=!]+//; $_ }
- @versions;
+ s/[\s<>=!]+// for @versions;
+ @versions = sort { $b <=> $a }
+ map { version->new( $_ ) } @versions;
# pick the highest version to use as comparison
$version = $versions[0];
}
# convert both objects to version objects so we can compare
$version = version->new( $version ) if ! ref $version;
my $cpanversion = version->new( $module->version );
# check it!
is( $cpanversion, $version, "Comparing '$prereq' to CPAN version" );
} else {
ok( 0, "Warning: '$prereq' is not found on CPAN!" );
}
return;
}
diff --git a/t/a_kwalitee.t b/t/a_kwalitee.t
old mode 100755
new mode 100644
diff --git a/t/a_manifest.t b/t/a_manifest.t
old mode 100755
new mode 100644
diff --git a/t/a_metayml.t b/t/a_metayml.t
new file mode 100644
index 0000000..66562f0
--- /dev/null
+++ b/t/a_metayml.t
@@ -0,0 +1,15 @@
+#!/usr/bin/perl
+
+use Test::More;
+
+# AUTHOR test
+if ( not $ENV{TEST_AUTHOR} ) {
+ plan skip_all => 'Author test. Sent $ENV{TEST_AUTHOR} to a true value to run.';
+} else {
+ eval "use Test::YAML::Meta";
+ if ( $@ ) {
+ plan skip_all => 'Test::YAML::Meta required for validating the meta.yml file';
+ } else {
+ meta_yaml_ok();
+ }
+}
diff --git a/t/a_minimumversion.t b/t/a_minimumversion.t
old mode 100755
new mode 100644
diff --git a/t/a_pod.t b/t/a_pod.t
old mode 100755
new mode 100644
diff --git a/t/a_strict.t b/t/a_strict.t
old mode 100755
new mode 100644
|
apocalypse/perl-poe-benchmarker
|
f43780f7a173c6e70b9c44fd2afabfa597eb4a64
|
lots of cleanups
|
diff --git a/Build.PL b/Build.PL
index fc5089c..a606594 100755
--- a/Build.PL
+++ b/Build.PL
@@ -1,108 +1,109 @@
# Build.PL
use Module::Build;
my $build = Module::Build->new(
# look up Module::Build::API for the info!
'dynamic_config' => 0,
'module_name' => 'POE::Devel::Benchmarker',
'license' => 'perl',
'dist_abstract' => "Benchmarking POE's performance ( acts more like a smoker )",
'dist_author' => 'Apocalypse <APOCAL@cpan.org>',
'create_packlist' => 1,
'create_makefile_pl' => 'traditional',
'create_readme' => 1,
'test_files' => 't/*.t',
'add_to_cleanup' => [ 'META.yml', 'Makefile.PL', 'README' ], # automatically generated
'requires' => {
# POE Stuff
'POE' => 0,
'POE::Session::AttributeBased' => 0,
# FIXME POE stuff that Test::Dependencies needs to see
'POE::Session' => 0,
'POE::Wheel::SocketFactory' => 0,
'POE::Wheel::ReadWrite' => 0,
'POE::Filter::Line' => 0,
'POE::Driver::SysRW' => 0,
# misc perl stuff
'Time::HiRes' => 0,
'version' => 0,
'Devel::Hide' => 0,
# Analyzer reqs
'YAML::Tiny' => 0,
# GetPOEdists reqs
'LWP::UserAgent' => 0,
'HTML::LinkExtor' => 0,
'URI::URL' => 0,
'Archive::Tar' => 0,
# Imager reqs
'GD::Graph::lines' => 0,
+ 'GD::Graph::colour' => 0,
'Class::Accessor::Fast' => 0,
'Module::Pluggable' => 0,
# Test stuff
'Test::More' => '0.86', # require latest for note() support in t/a_is_prereq_outdated.t
},
'recommends' => {
# our POE loops!
'POE::Loop::Event' => 0,
'POE::Loop::Event_Lib' => 0,
'POE::Loop::EV' => 0,
'POE::Loop::Glib' => 0,
'POE::Loop::Prima' => 0,
'POE::Loop::Gtk' => 0,
'POE::Loop::Wx' => 0,
'POE::Loop::Kqueue' => 0,
# included in POE ( listed here for completeness )
#'POE::Loop::Tk' => 0,
#'POE::Loop::Select' => 0,
#'POE::Loop::IO_Poll' => 0,
# the loops' dependencies
'Event' => 0,
'Event::Lib' => 0,
'EV' => 0,
'Glib' => 0,
'Prima' => 0,
'Gtk' => 0,
'Wx' => 0,
'Tk' => 0,
# the XS queue
'POE::XS::Queue::Array' => 0,
},
# FIXME wishlist...
# 'test_requires' => {
# # Test stuff
# 'Test::Compile' => 0,
# 'Test::Perl::Critic' => 0,
# 'Test::Dependencies' => 0,
# 'Test::Distribution' => 0,
# 'Test::Fixme' => 0,
# 'Test::HasVersion' => 0,
# 'Test::Kwalitee' => 0,
# 'Test::CheckManifest' => 0,
# 'Test::MinimumVersion' => 0,
# 'Test::Pod::Coverage' => 0,
# 'Test::Spelling' => 0,
# 'Test::Pod' => 0,
# 'Test::Prereq' => 0,
# 'Test::Strict' => 0,
# 'Test::UseAllModules' => 0,
# },
);
# all done!
$build->create_build_script;
diff --git a/Changes b/Changes
index 9d915b8..30ab3c1 100755
--- a/Changes
+++ b/Changes
@@ -1,38 +1,39 @@
Revision history for Perl extension POE::Devel::Benchmarker
* 0.05
Minor tweaks on the YAML output ( nothing new, hah! )
Added the socket tests, yay! ( adapted from LotR's script, thanks! )
- Some more tweaks to the BasicStatistics plugin
+ Some more tweaks to the BasicStatistics plugin for prettier graphs
+ Lots of refactoring to get things cleaned up :)
* 0.04
Started work on the image generator ( Imager ) and added the BasicStatistics plugin, yay!
Added automatic "pick up where we left off" to the benchmarker
Added the freshstart option to benchmark()
Tweaked the GetPOEdists sub so it will work in the "work directory" and in the poedists dir
Tweaked the YAML output so it's smaller
Removed POE::Loop::Wx from autoprobing ( I'm unable to get it to work )
Removed POE::Loop::Kqueue from autoprobing ( I'm unable to get it to work )
Hardcoded the Benchmarker routines to skip POE < 0.13 ( I'm unable to get it to work )
* 0.03
Added the loop option to benchmark(), thanks dngor!
Added the poe option to benchmark(), thanks dngor!
Added the noxsqueue option to benchmark()
Added the noasserts option to benchmark()
Automatically enable noxsqueue option if we cannot load POE::XS::Queue::Array, saving time
Bump Test::More version requirement because some people reported failures with note()
Fixed bug in SubProcess where it crashed on old POEs that didn't load IO::Handle
More documentation additions/tweaks
* 0.02
Added the Analyzer module ( and dump YAML files, yay! )
A lot of minor changes+tweaks to get a better dump format
* 0.01
initial release
diff --git a/MANIFEST b/MANIFEST
index 0ed8dd0..50f5869 100755
--- a/MANIFEST
+++ b/MANIFEST
@@ -1,36 +1,35 @@
Makefile.PL
Build.PL
MANIFEST
MANIFEST.SKIP
README
lib/POE/Devel/Benchmarker.pm
lib/POE/Devel/Benchmarker/GetInstalledLoops.pm
lib/POE/Devel/Benchmarker/GetPOEdists.pm
lib/POE/Devel/Benchmarker/SubProcess.pm
lib/POE/Devel/Benchmarker/Utils.pm
-lib/POE/Devel/Benchmarker/Analyzer.pm
lib/POE/Devel/Benchmarker/Imager.pm
lib/POE/Devel/Benchmarker/Imager/BasicStatistics.pm
META.yml
Changes
t/1_load.t
t/a_critic.t
t/a_kwalitee.t
t/a_pod.t
t/a_pod_spelling.t
t/a_pod_coverage.t
t/a_strict.t
t/a_hasversion.t
t/a_minimumversion.t
t/a_manifest.t
t/a_distribution.t
t/a_compile.t
t/a_dependencies.t
t/a_fixme.t
t/a_prereq.t
t/a_prereq_build.t
t/a_dosnewline.t
t/a_perlmetrics.t
t/a_is_prereq_outdated.t
diff --git a/lib/POE/Devel/Benchmarker.pm b/lib/POE/Devel/Benchmarker.pm
index 44187d5..cb3f62d 100644
--- a/lib/POE/Devel/Benchmarker.pm
+++ b/lib/POE/Devel/Benchmarker.pm
@@ -1,920 +1,1119 @@
# Declare our package
package POE::Devel::Benchmarker;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.05';
# auto-export the only sub we have
use base qw( Exporter );
our @EXPORT = qw( benchmark );
# we need hires times
use Time::HiRes qw( time );
# Import what we need from the POE namespace
use POE qw( Session Filter::Line Wheel::Run );
use base 'POE::Session::AttributeBased';
# load comparison stuff
use version;
# use the power of YAML
-use YAML::Tiny;
+use YAML::Tiny qw( Dump );
# Load our stuff
use POE::Devel::Benchmarker::GetInstalledLoops;
-use POE::Devel::Benchmarker::Utils qw( poeloop2load knownloops generateTestfile );
-use POE::Devel::Benchmarker::Analyzer;
+use POE::Devel::Benchmarker::Utils qw( poeloop2load knownloops generateTestfile beautify_times currentTestVersion );
# Actually run the tests!
sub benchmark {
my $options = shift;
# set default options
my $lite_tests = 1;
my $quiet_mode = 0;
my $forceloops = undef; # default to autoprobe all
my $forcepoe = undef; # default to all found POE versions in poedists/
my $forcenoxsqueue = 0; # default to try and load it
my $forcenoasserts = 0; # default is to run it
my $freshstart = 0; # always resume where we left off
# process our options
if ( defined $options and ref $options and ref( $options ) eq 'HASH' ) {
# process YES for freshstart
if ( exists $options->{'freshstart'} ) {
if ( $options->{'freshstart'} ) {
$freshstart = 1;
}
delete $options->{'freshstart'};
}
# process NO for XS::Queue::Array
if ( exists $options->{'noxsqueue'} ) {
if ( $options->{'noxsqueue'} ) {
$forcenoxsqueue = 1;
}
delete $options->{'noxsqueue'};
}
# process NO for ASSERT
if ( exists $options->{'noasserts'} ) {
if ( $options->{'noasserts'} ) {
$forcenoasserts = 1;
}
delete $options->{'noasserts'};
}
# process LITE tests
if ( exists $options->{'litetests'} ) {
if ( $options->{'litetests'} ) {
$lite_tests = 1;
} else {
$lite_tests = 0;
}
delete $options->{'litetests'};
}
# process quiet mode
if ( exists $options->{'quiet'} ) {
if ( $options->{'quiet'} ) {
$quiet_mode = 1;
} else {
$quiet_mode = 0;
}
delete $options->{'quiet'};
}
# process forceloops
if ( exists $options->{'loop'} and defined $options->{'loop'} ) {
if ( ! ref $options->{'loop'} ) {
# split it via CSV
$forceloops = [ split( /,/, $options->{'loop'} ) ];
foreach ( @$forceloops ) {
$_ =~ s/^\s+//; $_ =~ s/\s+$//;
}
} else {
# treat it as array
$forceloops = $options->{'loop'};
}
# check for !loop modules
my @noloops;
foreach my $l ( @$forceloops ) {
if ( $l =~ /^\!/ ) {
push( @noloops, substr( $l, 1 ) );
}
}
if ( scalar @noloops ) {
# replace the forceloops with ALL known, then subtract noloops from it
my %bad;
@bad{@noloops} = () x @noloops;
@$forceloops = grep { !exists $bad{$_} } @{ knownloops() };
}
delete $options->{'loop'};
}
# process the poe versions
if ( exists $options->{'poe'} and defined $options->{'poe'} ) {
if ( ! ref $options->{'poe'} ) {
# split it via CSV
$forcepoe = [ split( /,/, $options->{'poe'} ) ];
foreach ( @$forcepoe ) {
$_ =~ s/^\s+//; $_ =~ s/\s+$//;
}
} else {
# treat it as array
$forcepoe = $options->{'poe'};
}
delete $options->{'poe'};
}
# unknown options!
if ( scalar keys %$options ) {
warn "[BENCHMARKER] Unknown options present in arguments: " . keys %$options;
}
}
# do some sanity checks
if ( ! -d 'poedists' ) {
die "The 'poedists' directory is not found in the working directory!";
}
if ( ! -d 'results' ) {
die "The 'results' directory is not found in the working directory!";
}
if ( ! $quiet_mode ) {
print "[BENCHMARKER] Starting up...\n";
}
# Create our session
POE::Session->create(
__PACKAGE__->inline_states(),
'heap' => {
# misc stuff
'quiet_mode' => $quiet_mode,
# override our testing behavior
'lite_tests' => $lite_tests,
'forceloops' => $forceloops,
'forcepoe' => $forcepoe,
'forcenoxsqueue' => $forcenoxsqueue,
'forcenoasserts' => $forcenoasserts,
'freshstart' => $freshstart,
},
);
# Fire 'er up!
POE::Kernel->run();
return;
}
# Starts up our session
sub _start : State {
# okay, get all the dists we can!
my @versions;
if ( opendir( DISTS, 'poedists' ) ) {
foreach my $d ( readdir( DISTS ) ) {
if ( $d =~ /^POE\-(.+)$/ and $d !~ /\.tar\.gz$/ ) {
# FIXME skip POE < 0.13 because I can't get it to work
my $ver = version->new( $1 );
if ( $ver > version->new( '0.12' ) ) {
push( @versions, $ver );
}
}
}
closedir( DISTS ) or die $!;
} else {
print "[BENCHMARKER] Unable to open 'poedists' for reading: $!\n";
return;
}
# should we munge the versions list?
if ( defined $_[HEAP]->{'forcepoe'} ) {
# check for !poe versions
my @nopoe;
foreach my $p ( @{ $_[HEAP]->{'forcepoe'} } ) {
if ( $p =~ /^\!/ ) {
push( @nopoe, substr( $p, 1 ) );
}
}
if ( scalar @nopoe ) {
# remove the nopoe versions from the found
my %bad;
@bad{@nopoe} = () x @nopoe;
@versions = grep { !exists $bad{$_->stringify} } @versions;
} else {
# make sure the @versions contains only what we specified
my %good;
@good{ @{ $_[HEAP]->{'forcepoe'} } } = () x @{ $_[HEAP]->{'forcepoe'} };
@versions = grep { exists $good{$_->stringify} } @versions;
}
}
# sanity
if ( ! scalar @versions ) {
print "[BENCHMARKER] Unable to find any POE version in the 'poedists' directory!\n";
return;
}
# set our alias
$_[KERNEL]->alias_set( 'Benchmarker' );
# sanely handle some signals
$_[KERNEL]->sig( 'INT', 'handle_kill' );
$_[KERNEL]->sig( 'TERM', 'handle_kill' );
# okay, go through all the dists in version order ( from newest to oldest )
@versions = sort { $b <=> $a } @versions;
# Store the versions in our heap
$_[HEAP]->{'VERSIONS'} = \@versions;
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Detected available POE versions -> " . join( " ", @versions ) . "\n";
}
# First of all, we need to find out what loop libraries are installed
getPOEloops( $_[HEAP]->{'quiet_mode'}, $_[HEAP]->{'forceloops'} );
return;
}
sub _stop : State {
# tell the wheel to kill itself
if ( defined $_[HEAP]->{'WHEEL'} ) {
$_[HEAP]->{'WHEEL'}->kill( 9 );
undef $_[HEAP]->{'WHEEL'};
}
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "\n[BENCHMARKER] Shutting down...\n";
}
return;
}
# misc POE handlers
sub _child : State {
return;
}
sub handle_kill : State {
return;
}
# we received list of loops from GetInstalledLoops
sub found_loops : State {
$_[HEAP]->{'installed_loops'} = [ sort { $a cmp $b } @{ $_[ARG0] } ];
# sanity check
if ( scalar @{ $_[HEAP]->{'installed_loops'} } == 0 ) {
print "[BENCHMARKER] Detected no available POE::Loop, check your configuration?!?\n";
return;
}
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Detected available POE::Loops -> " . join( " ", @{ $_[HEAP]->{'installed_loops'} } ) . "\n";
}
# Okay, do we have XS::Queue installed?
if ( ! $_[HEAP]->{'forcenoxsqueue'} ) {
eval { require POE::XS::Queue::Array };
if ( $@ ) {
$_[HEAP]->{'forcenoxsqueue'} = 1;
}
}
- # Fire up the analyzer
- initAnalyzer( $_[HEAP]->{'quiet_mode'} );
-
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Starting the benchmarks!" .
( $_[HEAP]->{'forcenoxsqueue'} ? ' Skipping XS::Queue Tests!' : '' ) .
( $_[HEAP]->{'forcenoasserts'} ? ' Skipping ASSERT Tests!' : '' ) .
"\n";
}
# start the benchmark!
$_[KERNEL]->yield( 'run_benchmark' );
return;
}
# Runs one benchmark
sub run_benchmark : State {
# Grab the version from the top of the array
$_[HEAP]->{'current_version'} = shift @{ $_[HEAP]->{'VERSIONS'} };
# did we run out of versions?
if ( ! defined $_[HEAP]->{'current_version'} ) {
# We're done, let POE die...
$_[KERNEL]->alias_remove( 'Benchmarker' );
} else {
$_[HEAP]->{'loops'} = [ @{ $_[HEAP]->{'installed_loops'} } ];
# okay, fire off the first loop
$_[KERNEL]->yield( 'bench_loop' );
}
return;
}
# runs one loop
sub bench_loop : State {
# select our current loop
$_[HEAP]->{'current_loop'} = shift @{ $_[HEAP]->{'loops'} };
# are we done with all loops?
if ( ! defined $_[HEAP]->{'current_loop'} ) {
# yay, go back to the main handler
$_[KERNEL]->yield( 'run_benchmark' );
} else {
# Start the assert test
if ( $_[HEAP]->{'forcenoasserts'} ) {
$_[HEAP]->{'assertions'} = [ qw( 0 ) ];
} else {
$_[HEAP]->{'assertions'} = [ qw( 0 1 ) ];
}
$_[KERNEL]->yield( 'bench_asserts' );
}
return;
}
# runs an assertion
sub bench_asserts : State {
# select our current assert state
$_[HEAP]->{'current_assertions'} = shift @{ $_[HEAP]->{'assertions'} };
# are we done?
if ( ! defined $_[HEAP]->{'current_assertions'} ) {
# yay, go back to the loop handler
$_[KERNEL]->yield( 'bench_loop' );
} else {
# Start the xsqueue test
if ( $_[HEAP]->{'forcenoxsqueue'} ) {
$_[HEAP]->{'noxsqueue'} = [ qw( 1 ) ];
} else {
$_[HEAP]->{'noxsqueue'} = [ qw( 0 1 ) ];
}
$_[KERNEL]->yield( 'bench_xsqueue' );
}
return;
}
# runs test with or without xsqueue
sub bench_xsqueue : State {
# select our current noxsqueue state
$_[HEAP]->{'current_noxsqueue'} = shift @{ $_[HEAP]->{'noxsqueue'} };
# are we done?
if ( ! defined $_[HEAP]->{'current_noxsqueue'} ) {
# yay, go back to the assert handler
$_[KERNEL]->yield( 'bench_asserts' );
} else {
# do some careful analysis
$_[KERNEL]->yield( 'bench_checkprevioustest' );
}
return;
}
# Checks to see if this test was run in the past
sub bench_checkprevioustest : State {
# okay, do we need to check and see if we already did this test?
if ( ! $_[HEAP]->{'freshstart'} ) {
# determine the file used
my $file = generateTestfile( $_[HEAP] );
# does it exist?
if ( -e "results/$file.yml" and -f _ and -s _ ) {
# okay, sanity check it
my $yaml = YAML::Tiny->read( "results/$file.yml" );
if ( defined $yaml ) {
# inrospect it!
my $isvalid = 0;
eval {
# simple sanity check: the "x_bench" param is at the end of the YML, so if it loads fine we know it's there
if ( exists $yaml->[0]->{'x_bench'} ) {
# version must at least match us
$isvalid = ( $yaml->[0]->{'x_bench'} eq $POE::Devel::Benchmarker::VERSION ? 1 : 0 );
} else {
$isvalid = undef;
}
};
if ( $isvalid ) {
# yay, this test is A-OK!
$_[KERNEL]->yield( 'bench_xsqueue' );
return;
} else {
# was it truncated?
if ( ! defined $isvalid ) {
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "\n[BENCHMARKER] YAML file($file) from previous test was corrupt!\n";
}
}
}
} else {
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "\n[BENCHMARKER] Unable to load YAML file($file) from previous test run: " . YAML::Tiny->errstr . "\n";
}
}
}
}
# could not find previous file or FRESHSTART, proceed normally
$_[KERNEL]->yield( 'create_subprocess' );
return;
}
# actually runs the subprocess
sub create_subprocess : State {
# Okay, start testing this specific combo!
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "\n Testing " . generateTestfile( $_[HEAP] ) . "...";
}
# save the starttime
$_[HEAP]->{'current_starttime'} = time();
$_[HEAP]->{'current_starttimes'} = [ times() ];
# Okay, create the wheel::run to handle this
my $looploader = poeloop2load( $_[HEAP]->{'current_loop'} );
$_[HEAP]->{'WHEEL'} = POE::Wheel::Run->new(
'Program' => $^X,
'ProgramArgs' => [ '-Ipoedists/POE-' . $_[HEAP]->{'current_version'},
'-Ipoedists/POE-' . $_[HEAP]->{'current_version'} . '/lib',
( defined $looploader ? "-M$looploader" : () ),
'-MPOE::Devel::Benchmarker::SubProcess',
'-e',
'POE::Devel::Benchmarker::SubProcess::benchmark',
$_[HEAP]->{'current_loop'},
$_[HEAP]->{'current_assertions'},
$_[HEAP]->{'lite_tests'},
$_[HEAP]->{'current_noxsqueue'},
],
# Kill off existing FD's
'CloseOnCall' => 1,
# setup our data handlers
'StdoutEvent' => 'Got_STDOUT',
'StderrEvent' => 'Got_STDERR',
# the error handler
'ErrorEvent' => 'Got_ERROR',
'CloseEvent' => 'Got_CLOSED',
# set our filters
'StderrFilter' => POE::Filter::Line->new(),
'StdoutFilter' => POE::Filter::Line->new(),
);
if ( ! defined $_[HEAP]->{'WHEEL'} ) {
die 'Unable to create a new wheel!';
} else {
# smart CHLD handling
if ( $_[KERNEL]->can( "sig_child" ) ) {
$_[KERNEL]->sig_child( $_[HEAP]->{'WHEEL'}->PID => 'Got_CHLD' );
} else {
$_[KERNEL]->sig( 'CHLD', 'Got_CHLD' );
}
}
# setup our data we received from the subprocess
$_[HEAP]->{'current_data'} = '';
# Okay, we timeout this test after some time for sanity
$_[HEAP]->{'test_timedout'} = 0;
if ( $_[HEAP]->{'lite_tests'} ) {
# 5min timeout is 5x my average runs on a 1.2ghz core2duo so it should be good enough
$_[HEAP]->{'TIMER'} = $_[KERNEL]->delay_set( 'test_timedout' => 60 * 5 );
} else {
# 30min timeout is 2x my average runs on a 1.2ghz core2duo so it should be good enough
$_[HEAP]->{'TIMER'} = $_[KERNEL]->delay_set( 'test_timedout' => 60 * 30 );
}
return;
}
# Got a CHLD event!
sub Got_CHLD : State {
$_[KERNEL]->sig_handled();
return;
}
# Handles child STDERR output
sub Got_STDERR : State {
my $input = $_[ARG0];
# skip empty lines
if ( $input ne '' ) {
# save it!
$_[HEAP]->{'current_data'} .= '!STDERR: ' . $input . "\n";
}
return;
}
# Handles child STDOUT output
sub Got_STDOUT : State {
my $input = $_[ARG0];
# save it!
$_[HEAP]->{'current_data'} .= $input . "\n";
return;
}
# Handles child error
sub Got_ERROR : State {
# Copied from POE::Wheel::Run manpage
my ( $operation, $errnum, $errstr ) = @_[ ARG0 .. ARG2 ];
# ignore exit 0 errors
if ( $errnum != 0 ) {
print "\n[BENCHMARKER] Wheel::Run got an $operation error $errnum: $errstr\n";
}
return;
}
# Handles child DIE'ing
sub Got_CLOSED : State {
# Get rid of the wheel
undef $_[HEAP]->{'WHEEL'};
# get rid of the delay
$_[KERNEL]->alarm_remove( $_[HEAP]->{'TIMER'} );
undef $_[HEAP]->{'TIMER'};
# wrap up this test
$_[KERNEL]->yield( 'wrapup_test' );
return;
}
# a test timed out, unfortunately!
sub test_timedout : State {
# tell the wheel to kill itself
$_[HEAP]->{'WHEEL'}->kill( 9 );
undef $_[HEAP]->{'WHEEL'};
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print " Test Timed Out!";
}
$_[HEAP]->{'test_timedout'} = 1;
# wrap up this test
$_[KERNEL]->yield( 'wrapup_test' );
return;
}
# finalizes a test
sub wrapup_test : State {
# we're done with this benchmark!
$_[HEAP]->{'current_endtime'} = time();
$_[HEAP]->{'current_endtimes'} = [ times() ];
# store the data
my $file = generateTestfile( $_[HEAP] );
if ( open( my $fh, '>', "results/$file" ) ) {
print $fh "STARTTIME: " . $_[HEAP]->{'current_starttime'} . " -> TIMES " . join( " ", @{ $_[HEAP]->{'current_starttimes'} } ) . "\n";
print $fh "$file\n";
print $fh $_[HEAP]->{'current_data'} . "\n";
if ( $_[HEAP]->{'test_timedout'} ) {
print $fh "\nTEST TERMINATED DUE TO TIMEOUT\n";
}
print $fh "ENDTIME: " . $_[HEAP]->{'current_endtime'} . " -> TIMES " . join( " ", @{ $_[HEAP]->{'current_endtimes'} } ) . "\n";
close( $fh ) or die $!;
} else {
print "\n[BENCHMARKER] Unable to open results/$file for writing -> $!\n";
}
# Send the data to the Analyzer to process
- $_[KERNEL]->post( 'Benchmarker::Analyzer', 'analyze', {
+ $_[KERNEL]->yield( 'analyze_output', {
'poe' => {
'v' => $_[HEAP]->{'current_version'}->stringify, # YAML::Tiny doesn't like version objects :(
'loop' => 'POE::Loop::' . $_[HEAP]->{'current_loop'},
},
't' => {
's_ts' => $_[HEAP]->{'current_starttime'},
'e_ts' => $_[HEAP]->{'current_endtime'},
'd' => $_[HEAP]->{'current_endtime'} - $_[HEAP]->{'current_starttime'},
's_t' => [ @{ $_[HEAP]->{'current_starttimes'} } ],
'e_t' => [ @{ $_[HEAP]->{'current_endtimes'} } ],
},
'raw' => $_[HEAP]->{'current_data'},
'test' => $file,
- 'x_bench' => $POE::Devel::Benchmarker::VERSION,
+ 'x_bench' => currentTestVersion(),
( $_[HEAP]->{'test_timedout'} ? ( 'timedout' => 1 ) : () ),
( $_[HEAP]->{'lite_tests'} ? ( 'litetests' => 1 ) : () ),
( $_[HEAP]->{'current_assertions'} ? ( 'asserts' => 1 ) : () ),
( $_[HEAP]->{'current_noxsqueue'} ? ( 'noxsqueue' => 1 ) : () ),
} );
# process the next test
$_[KERNEL]->yield( 'bench_xsqueue' );
return;
}
+sub analyze_output : State {
+ # get the data
+ my $test = $_[ARG0];
+
+ # clean up the times() stuff
+ $test->{'t'}->{'t'} = beautify_times(
+ join( " ", @{ delete $test->{'t'}->{'s_t'} } ) .
+ " " .
+ join( " ", @{ delete $test->{'t'}->{'e_t'} } )
+ );
+
+ # Okay, break it down into our data struct
+ $test->{'metrics'} = {};
+ my $d = $test->{'metrics'};
+ my @unknown;
+ foreach my $l ( split( /(?:\n|\r)/, $test->{'raw'} ) ) {
+ # skip empty lines
+ if ( $l eq '' ) { next }
+
+ # usual test benchmark output
+ # 10 startups in 0.885 seconds ( 11.302 per second)
+ # 10000 posts in 0.497 seconds ( 20101.112 per second)
+ if ( $l =~ /^\s+\d+\s+(\w+)\s+in\s+([\d\.]+)\s+seconds\s+\(\s+([\d\.]+)\s+per\s+second\)$/ ) {
+ $d->{ $1 }->{'d'} = $2; # duration in seconds
+ $d->{ $1 }->{'i'} = $3; # iterations per second
+
+ # usual test benchmark times output
+ # startup times: 0.1 0 0 0 0.1 0 0.76 0.09
+ } elsif ( $l =~ /^(\w+)\s+times:\s+(.+)$/ ) {
+ $d->{ $1 }->{'t'} = beautify_times( $2 ); # the times hash
+
+ # usual test SKIP output
+ # SKIPPING br0ken $metric because ...
+ } elsif ( $l =~ /^SKIPPING\s+br0ken\s+(\w+)\s+because/ ) {
+ # don't build their data struct
+
+ # parse the memory footprint stuff
+ } elsif ( $l =~ /^pidinfo:\s+(.+)$/ ) {
+ # what should we analyze?
+ my $pidinfo = $1;
+
+ # VmPeak: 16172 kB
+ if ( $pidinfo =~ /^VmPeak:\s+(.+)$/ ) {
+ $test->{'pid'}->{'vmpeak'} = $1;
+
+ # voluntary_ctxt_switches: 10
+ } elsif ( $pidinfo =~ /^voluntary_ctxt_switches:\s+(.+)$/ ) {
+ $test->{'pid'}->{'vol_ctxt'} = $1;
+
+ # nonvoluntary_ctxt_switches: 1221
+ } elsif ( $pidinfo =~ /^nonvoluntary_ctxt_switches:\s+(.+)$/ ) {
+ $test->{'pid'}->{'nonvol_ctxt'} = $1;
+
+ } else {
+ # ignore the rest of the fluff
+ }
+ # parse the perl binary stuff
+ } elsif ( $l =~ /^perlconfig:\s+(.+)$/ ) {
+ # what should we analyze?
+ my $perlconfig = $1;
+
+ # ignore the fluff ( not needed now... )
+
+ # parse the CPU info
+ } elsif ( $l =~ /^cpuinfo:\s+(.+)$/ ) {
+ # what should we analyze?
+ my $cpuinfo = $1;
+
+ # FIXME if this is on a multiproc system, we will overwrite the data per processor ( harmless? )
+
+ # cpu MHz : 1201.000
+ if ( $cpuinfo =~ /^cpu\s+MHz\s+:\s+(.+)$/ ) {
+ $test->{'cpu'}->{'mhz'} = $1;
+
+ # model name : Intel(R) Core(TM)2 Duo CPU L7100 @ 1.20GHz
+ } elsif ( $cpuinfo =~ /^model\s+name\s+:\s+(.+)$/ ) {
+ $test->{'cpu'}->{'name'} = $1;
+
+ # bogomips : 2397.58
+ } elsif ( $cpuinfo =~ /^bogomips\s+:\s+(.+)$/ ) {
+ $test->{'cpu'}->{'bogo'} = $1;
+
+ } else {
+ # ignore the rest of the fluff
+ }
+
+ # ignore any Devel::Hide stuff
+ # $l eq '!STDERR: Devel::Hide hides POE/XS/Queue/Array.pm'
+ } elsif ( $l =~ /^\!STDERR:\s+Devel\:\:Hide\s+hides/ ) {
+ # ignore them
+
+ # data that we can safely throw away
+ } elsif ( $l eq 'Using NO Assertions!' or
+ $l eq 'Using FULL Assertions!' or
+ $l eq 'Using the LITE tests' or
+ $l eq 'Using the HEAVY tests' or
+ $l eq 'DISABLING POE::XS::Queue::Array' or
+ $l eq 'LETTING POE find POE::XS::Queue::Array' or
+ $l eq 'UNABLE TO GET /proc/self/status' or
+ $l eq 'UNABLE TO GET /proc/cpuinfo' or
+ $l eq '!STDERR: POE::Kernel\'s run() method was never called.' or # to ignore old POEs that threw this warning
+ $l eq 'TEST TERMINATED DUE TO TIMEOUT' ) {
+ # ignore them
+
+ # parse the perl binary stuff
+ } elsif ( $l =~ /^Running\s+under\s+perl\s+binary:\s+\'([^\']+)\'\s+v([\d\.]+)$/ ) {
+ $test->{'perl'}->{'binary'} = $1;
+
+ # setup the perl version
+ $test->{'perl'}->{'v'} = $2;
+
+ # the master loop version ( what the POE::Loop::XYZ actually uses )
+ # Using loop: EV-3.49
+ } elsif ( $l =~ /^Using\s+master\s+loop:\s+(.+)$/ ) {
+ $test->{'poe'}->{'loop_m'} = $1;
+
+ # the real POE version that was loaded
+ # Using POE-1.001
+ } elsif ( $l =~ /^Using\s+POE-(.+)$/ ) {
+ $test->{'poe'}->{'v_real'} = $1;
+
+ # the various queue/loop modules we loaded
+ # POE is using: POE::XS::Queue::Array v0.005
+ # POE is using: POE::Queue v1.2328
+ # POE is using: POE::Loop::EV v0.06
+ } elsif ( $l =~ /^POE\s+is\s+using:\s+([^\s]+)\s+v(.+)$/ ) {
+ $test->{'poe'}->{'modules'}->{ $1 } = $2;
+
+ # get the uname info
+ # Running under machine: Linux apoc-x300 2.6.24-21-generic #1 SMP Tue Oct 21 23:43:45 UTC 2008 i686 GNU/Linux
+ } elsif ( $l =~ /^Running\s+under\s+machine:\s+(.+)$/ ) {
+ $test->{'uname'} = $1;
+
+ # parse any STDERR output
+ # !STDERR: unable to foo
+ } elsif ( $l =~ /^\!STDERR:\s+(.+)$/ ) {
+ push( @{ $test->{'stderr'} }, $1 );
+
+ } else {
+ # unknown line :(
+ push( @unknown, $l );
+ }
+ }
+
+ # Get rid of the rawdata
+ delete $test->{'raw'};
+
+ # Dump the unknowns
+ if ( @unknown ) {
+ print "\n[ANALYZER] Unknown output from benchmark -> " . Dump( \@unknown );
+ }
+
+ # Dump the data struct we have to the file.yml
+ my $yaml_file = 'results/' . delete $test->{'test'};
+ $yaml_file .= '.yml';
+ my $ret = open( my $fh, '>', $yaml_file );
+ if ( defined $ret ) {
+ print $fh Dump( $test );
+ if ( ! close( $fh ) ) {
+ print "\n[ANALYZER] Unable to close $yaml_file -> " . $! . "\n";
+ }
+ } else {
+ print "\n[ANALYZER] Unable to open $yaml_file for writing -> " . $! . "\n";
+ }
+
+ # now that we've dumped the stuff, we can do some sanity checks
+
+ # the POE we "think" we loaded should match reality!
+ if ( exists $test->{'poe'}->{'v_real'} ) { # if this exists, then we successfully loaded POE
+ if ( $test->{'poe'}->{'v'} ne $test->{'poe'}->{'v_real'} ) {
+ print "\n[ANALYZER] The subprocess loaded a different version of POE than we thought -> $yaml_file\n";
+ }
+
+ # The loop we loaded should match what we wanted!
+ if ( exists $test->{'poe'}->{'modules'} ) {
+ if ( ! exists $test->{'poe'}->{'modules'}->{ $test->{'poe'}->{'loop'} } ) {
+ # gaah special-case for IO_Poll
+ if ( $test->{'poe'}->{'loop'} eq 'POE::Loop::IO_Poll' and exists $test->{'poe'}->{'modules'}->{'POE::Loop::Poll'} ) {
+ # ah, ignore this
+ } else {
+ print "\n[ANALYZER] The subprocess loaded a different Loop than we thought -> $yaml_file\n";
+ }
+ }
+ }
+ }
+
+ # the perl binary should be the same!
+ if ( exists $test->{'perl'} ) { # if this exists, we successfully fired up the app ( no compile error )
+ if ( $test->{'perl'}->{'binary'} ne $^X ) {
+ print "\n[ANALYZER] The subprocess booted up on a different perl binary -> $yaml_file\n";
+ }
+ if ( $test->{'perl'}->{'v'} ne sprintf( "%vd", $^V ) ) {
+ print "\n[ANALYZER] The subprocess booted up on a different perl version -> $yaml_file\n";
+ }
+ }
+
+ # all done!
+ return;
+}
+
1;
__END__
=head1 NAME
POE::Devel::Benchmarker - Benchmarking POE's performance ( acts more like a smoker )
=head1 SYNOPSIS
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker -e 'benchmark()'
=head1 ABSTRACT
This package of tools is designed to benchmark POE's performace across different
configurations. The current "tests" are:
=over 4
=item Events
posts: This tests how long it takes to post() N times
dispatches: This tests how long it took to dispatch/deliver all the posts enqueued in the "posts" test
single_posts: This tests how long it took to yield() between 2 states for N times
calls: This tests how long it took to call() N times
=item Alarms
alarms: This tests how long it took to add N alarms via alarm(), overwriting each other
alarm_adds: This tests how long it took to add N alarms via alarm_add()
alarm_clears: This tests how long it took to clear all alarms set in the "alarm_adds" test
NOTE: alarm_add is not available on all versions of POE!
=item Sessions
session_creates: This tests how long it took to create N sessions
session_destroys: This tests how long it took to destroy all sessions created in the "session_creates" test
=item Filehandles
select_read_STDIN: This tests how long it took to toggle select_read N times on STDIN
select_write_STDIN: This tests how long it took to toggle select_write N times on STDIN
select_read_MYFH: This tests how long it took to toggle select_read N times on a real filehandle
select_write_MYFH: This tests how long it took to toggle select_write N times on a real filehandle
NOTE: The MYFH tests don't include the time it took to open()/close() the file :)
=item Sockets
socket_connects: This tests how long it took to connect+disconnect to a SocketFactory server via localhost
socket_stream: This tests how long it took to send N chunks of data in a "ping-pong" fashion between the server and client
=item POE startup time
startups: This tests how long it took to start + close N instances of POE+Loop without any sessions/etc via system()
=item POE Loops
This is actually a "super" test where all of the specific tests is ran against various POE::Loop::XYZ/FOO for comparison
+NOTE: Not all versions of POE support all Loops!
+
=item POE Assertions
This is actually a "super" test where all of the specific tests is ran against POE with/without assertions enabled
NOTE: Not all versions of POE support assertions!
=item POE::XS::Queue::Array
This is actually a "super" test where all of the specific tests is ran against POE with XS goodness enabled/disabled
NOTE: Not all versions of POE support XS::Queue::Array!
=back
=head1 DESCRIPTION
This module is poorly documented now. Please give me some time to properly document it over time :)
=head2 INSTALLATION
Here's a simple outline to get you up to speed quickly. ( and smoking! )
=over 4
=item Install CPAN package + dependencies
Download+install the POE::Devel::Benchmarker package from CPAN
apoc@apoc-x300:~$ cpanp -i POE::Devel::Benchmarker
=item Setup initial directories
Go anywhere, and create the "parent" directory where you'll be storing test results + stuff. For this example,
I have chosen to use ~/poe-benchmarker:
apoc@apoc-x300:~$ mkdir poe-benchmarker
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ mkdir poedists results images
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker::GetPOEdists -e 'getPOEdists( 1 )'
( go get a coffee while it downloads if you're on a slow link, ha! )
=item Let 'er rip!
At this point you can start running the benchmark!
NOTE: the Benchmarker expects everything to be in the "local" directory!
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker -e 'benchmark()'
( go sleep or something, this will take a while! )
=back
=head2 BENCHMARKING
On startup the Benchmarker will look in the "poedists" directory and load all the distributions it sees untarred there. Once
that is done it will begin autoprobing for available POE::Loop packages. Once it determines what's available, it will begin
the benchmarks.
As the Benchmarker goes through the combinations of POE + Eventloop + Assertions + XS::Queue it will dump data into
-the results directory. The Analyzer module also dumps YAML output in the same place, with the suffix of ".yml"
+the results directory. The module also dumps YAML output in the same place, with the suffix of ".yml"
This module exposes only one subroutine, the benchmark() one. You can pass a hashref to it to set various options. Here is
a list of the valid options:
=over 4
=item freshstart => boolean
-This will tell the Benchmarker to ignore any previous test runs stored in the 'results' directory.
+This will tell the Benchmarker to ignore any previous test runs stored in the 'results' directory. This will not delete
+data from previous runs, only overwrite them. So be careful if you're mixing test runs from different versions!
benchmark( { freshstart => 1 } );
default: false
=item noxsqueue => boolean
This will tell the Benchmarker to force the unavailability of POE::XS::Queue::Array and skip those tests.
NOTE: The Benchmarker will set this automatically if it cannot load the module!
benchmark( { noxsqueue => 1 } );
default: false
=item noasserts => boolean
This will tell the Benchmarker to not run the ASSERT tests.
benchmark( { noasserts => 1 } );
default: false
=item litetests => boolean
This enables the "lite" tests which will not take up too much time.
benchmark( { litetests => 0 } );
default: true
=item quiet => boolean
This enables quiet mode which will not print anything to the console except for errors.
benchmark( { 'quiet' => 1 } );
default: false
=item loop => csv list or array
This overrides the built-in loop detection algorithm which searches for all known loops.
There is some "magic" here where you can put a negative sign in front of a loop and we will NOT run that.
NOTE: Capitalization is important!
benchmark( { 'loop' => 'IO_Poll,Select' } ); # runs only IO::Poll and Select
benchmark( { 'loop' => [ qw( Tk Gtk ) ] } ); # runs only Tk and Gtk
benchmark( { 'loop' => '-Tk' } ); # runs all available loops EXCEPT for TK
Known loops: Event_Lib EV Glib Prima Gtk Kqueue Tk Select IO_Poll
=item poe => csv list or array
This overrides the built-in POE version detection algorithm which pulls the POE versions from the 'poedists' directory.
There is some "magic" here where you can put a negative sign in front of a version and we will NOT run that.
NOTE: The Benchmarker will ignore versions that wasn't found in the directory!
benchmark( { 'poe' => '0.35,1.003' } ); # runs on 0.35 and 1.003
benchmark( { 'poe' => [ qw( 0.3009 0.12 ) ] } ); # runs on 0.3009 and 0.12
benchmark( { 'poe' => '-0.35' } ); # runs ALL tests except 0.35
=back
=head2 ANALYZING RESULTS
Please look at the pretty charts generated by the L<POE::Devel::Benchmarker::Imager> module.
=head1 EXPORT
Automatically exports the benchmark() subroutine.
=head1 TODO
=over 4
=item Perl version smoking
We should be able to run the benchmark over different Perl versions. This would require some fiddling with our
layout + logic. It's not that urgent because the workaround is to simply execute the benchmarker under a different
perl binary. It's smart enough to use $^X to be consistent across tests/subprocesses :)
=item Select the EV backend
<Khisanth> and if you are benchmarking, try it with POE using EV with EV using Glib? :P
<Apocalypse> I'm not sure how to configure the EV "backend" yet
<Apocalypse> too much docs for me to read hah
<Khisanth> Apocalypse: use EV::Glib; use Glib; use POE; :)
=item Be smarter in smoking timeouts
Currently we depend on the litetests option and hardcode some values including the timeout. If your machine is incredibly
slow, there's a chance that it could timeout unnecessarily. Please look at the outputs and check to see if there are unusual
failures, and inform me.
Also, some loops perform badly and take almost forever! /me glares at Gtk...
=item More benchmarks!
As usual, me and the crowd in #poe have plenty of ideas for tests. We'll be adding them over time, but if you have an idea please
drop me a line and let me know!
dngor said there was some benchmarks in the POE svn under trunk/queue...
Tapout contributed a script that tests HTTP performance, let's see if it deserves to be in the suite :)
I added the preliminary socket tests, we definitely should expand it seeing how many people use POE for networking...
=item Add SQLite/DBI/etc support to the Analyzer
It would be nice if we could have a local SQLite db to dump our stats into. This would make arbitrary reports much easier than
loading raw YAML files and trying to make sense of them, ha! Also, this means somebody can do the smoking and send the SQLite
db to another person to generate the graphs, cool!
=item Kqueue loop support
As I don't have access to a *BSD box, I cannot really test this. Furthermore, it isn't clear on how I can force/unload this
module from POE...
=item Wx loop support
I have Wx installed, but it doesn't work. Obviously I don't know how to use Wx ;)
If you have experience, please drop me a line on how to do the "right" thing to get Wx loaded under POE. Here's the error:
Can't call method "MainLoop" on an undefined value at /usr/local/share/perl/5.8.8/POE/Loop/Wx.pm line 91.
=item XS::Loop support
The POE::XS::Loop::* modules theoretically could be tested too. However, they will only work in POE >= 1.003! This renders
the concept somewhat moot. Maybe, after POE has progressed some versions we can implement this...
=back
=head1 SEE ALSO
L<POE>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
BIG THANKS goes to Rocco Caputo E<lt>rcaputo@cpan.orgE<gt> for the first benchmarks!
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/Analyzer.pm b/lib/POE/Devel/Benchmarker/Analyzer.pm
deleted file mode 100644
index 5cfc704..0000000
--- a/lib/POE/Devel/Benchmarker/Analyzer.pm
+++ /dev/null
@@ -1,449 +0,0 @@
-# Declare our package
-package POE::Devel::Benchmarker::Analyzer;
-use strict; use warnings;
-
-# Initialize our version
-use vars qw( $VERSION );
-$VERSION = '0.05';
-
-# auto-export the only sub we have
-use base qw( Exporter );
-our @EXPORT = qw( initAnalyzer );
-
-# Import what we need from the POE namespace
-use POE qw( Session );
-use base 'POE::Session::AttributeBased';
-
-# use the power of YAML
-use YAML::Tiny qw( Dump );
-
-# Load the utils
-use POE::Devel::Benchmarker::Utils qw( beautify_times );
-
-# fires up the engine
-sub initAnalyzer {
- my $quiet_mode = shift;
-
- # create our session!
- POE::Session->create(
- __PACKAGE__->inline_states(),
- 'heap' => {
- 'quiet_mode' => $quiet_mode,
- },
- );
-}
-
-# Starts up our session
-sub _start : State {
- # set our alias
- $_[KERNEL]->alias_set( 'Benchmarker::Analyzer' );
-
- return;
-}
-
-sub _stop : State {
- return;
-}
-sub _child : State {
- return;
-}
-
-sub analyze : State {
- # get the data
- my $test = $_[ARG0];
-
- # clean up the times() stuff
- $test->{'t'}->{'t'} = beautify_times(
- join( " ", @{ delete $test->{'t'}->{'s_t'} } ) .
- " " .
- join( " ", @{ delete $test->{'t'}->{'e_t'} } )
- );
-
- # Okay, break it down into our data struct
- $test->{'metrics'} = {};
- my $d = $test->{'metrics'};
- my @unknown;
- foreach my $l ( split( /(?:\n|\r)/, $test->{'raw'} ) ) {
- # skip empty lines
- if ( $l eq '' ) { next }
-
- # usual test benchmark output
- # 10 startups in 0.885 seconds ( 11.302 per second)
- # 10000 posts in 0.497 seconds ( 20101.112 per second)
- if ( $l =~ /^\s+\d+\s+(\w+)\s+in\s+([\d\.]+)\s+seconds\s+\(\s+([\d\.]+)\s+per\s+second\)$/ ) {
- $d->{ $1 }->{'d'} = $2; # duration in seconds
- $d->{ $1 }->{'i'} = $3; # iterations per second
-
- # usual test benchmark times output
- # startup times: 0.1 0 0 0 0.1 0 0.76 0.09
- } elsif ( $l =~ /^(\w+)\s+times:\s+(.+)$/ ) {
- $d->{ $1 }->{'t'} = beautify_times( $2 ); # the times hash
-
- # usual test SKIP output
- # SKIPPING br0ken $metric because ...
- } elsif ( $l =~ /^SKIPPING\s+br0ken\s+(\w+)\s+because/ ) {
- # nullify the data struct for that
- $d->{ $1 }->{'d'} = undef;
- $d->{ $1 }->{'t'} = undef;
- $d->{ $1 }->{'i'} = undef;
-
- # parse the memory footprint stuff
- } elsif ( $l =~ /^pidinfo:\s+(.+)$/ ) {
- # what should we analyze?
- my $pidinfo = $1;
-
- # VmPeak: 16172 kB
- if ( $pidinfo =~ /^VmPeak:\s+(.+)$/ ) {
- $test->{'pid'}->{'vmpeak'} = $1;
-
- # voluntary_ctxt_switches: 10
- } elsif ( $pidinfo =~ /^voluntary_ctxt_switches:\s+(.+)$/ ) {
- $test->{'pid'}->{'vol_ctxt'} = $1;
-
- # nonvoluntary_ctxt_switches: 1221
- } elsif ( $pidinfo =~ /^nonvoluntary_ctxt_switches:\s+(.+)$/ ) {
- $test->{'pid'}->{'nonvol_ctxt'} = $1;
-
- } else {
- # ignore the rest of the fluff
- }
- # parse the perl binary stuff
- } elsif ( $l =~ /^perlconfig:\s+(.+)$/ ) {
- # what should we analyze?
- my $perlconfig = $1;
-
- # ignore the fluff ( not needed now... )
-
- # parse the CPU info
- } elsif ( $l =~ /^cpuinfo:\s+(.+)$/ ) {
- # what should we analyze?
- my $cpuinfo = $1;
-
- # FIXME if this is on a multiproc system, we will overwrite the data per processor ( harmless? )
-
- # cpu MHz : 1201.000
- if ( $cpuinfo =~ /^cpu\s+MHz\s+:\s+(.+)$/ ) {
- $test->{'cpu'}->{'mhz'} = $1;
-
- # model name : Intel(R) Core(TM)2 Duo CPU L7100 @ 1.20GHz
- } elsif ( $cpuinfo =~ /^model\s+name\s+:\s+(.+)$/ ) {
- $test->{'cpu'}->{'name'} = $1;
-
- # bogomips : 2397.58
- } elsif ( $cpuinfo =~ /^bogomips\s+:\s+(.+)$/ ) {
- $test->{'cpu'}->{'bogo'} = $1;
-
- } else {
- # ignore the rest of the fluff
- }
-
- # ignore any Devel::Hide stuff
- # $l eq '!STDERR: Devel::Hide hides POE/XS/Queue/Array.pm'
- } elsif ( $l =~ /^\!STDERR:\s+Devel\:\:Hide\s+hides/ ) {
- # ignore them
-
- # data that we can safely throw away
- } elsif ( $l eq 'Using NO Assertions!' or
- $l eq 'Using FULL Assertions!' or
- $l eq 'Using the LITE tests' or
- $l eq 'Using the HEAVY tests' or
- $l eq 'DISABLING POE::XS::Queue::Array' or
- $l eq 'LETTING POE find POE::XS::Queue::Array' or
- $l eq 'UNABLE TO GET /proc/self/status' or
- $l eq 'UNABLE TO GET /proc/cpuinfo' or
- $l eq '!STDERR: POE::Kernel\'s run() method was never called.' or # to ignore old POEs that threw this warning
- $l eq 'TEST TERMINATED DUE TO TIMEOUT' ) {
- # ignore them
-
- # parse the perl binary stuff
- } elsif ( $l =~ /^Running\s+under\s+perl\s+binary:\s+\'([^\']+)\'\s+v([\d\.]+)$/ ) {
- $test->{'perl'}->{'binary'} = $1;
-
- # setup the perl version
- $test->{'perl'}->{'v'} = $2;
-
- # the master loop version ( what the POE::Loop::XYZ actually uses )
- # Using loop: EV-3.49
- } elsif ( $l =~ /^Using\s+master\s+loop:\s+(.+)$/ ) {
- $test->{'poe'}->{'loop_m'} = $1;
-
- # the real POE version that was loaded
- # Using POE-1.001
- } elsif ( $l =~ /^Using\s+POE-(.+)$/ ) {
- $test->{'poe'}->{'v_real'} = $1;
-
- # the various queue/loop modules we loaded
- # POE is using: POE::XS::Queue::Array v0.005
- # POE is using: POE::Queue v1.2328
- # POE is using: POE::Loop::EV v0.06
- } elsif ( $l =~ /^POE\s+is\s+using:\s+([^\s]+)\s+v(.+)$/ ) {
- $test->{'poe'}->{'modules'}->{ $1 } = $2;
-
- # get the uname info
- # Running under machine: Linux apoc-x300 2.6.24-21-generic #1 SMP Tue Oct 21 23:43:45 UTC 2008 i686 GNU/Linux
- } elsif ( $l =~ /^Running\s+under\s+machine:\s+(.+)$/ ) {
- $test->{'uname'} = $1;
-
- # parse any STDERR output
- # !STDERR: unable to foo
- } elsif ( $l =~ /^\!STDERR:\s+(.+)$/ ) {
- push( @{ $test->{'stderr'} }, $1 );
-
- } else {
- # unknown line :(
- push( @unknown, $l );
- }
- }
-
- # Get rid of the rawdata
- delete $test->{'raw'};
-
- # Dump the unknowns
- if ( @unknown ) {
- print "[ANALYZER] Unknown output from benchmark -> " . Dump( \@unknown );
- }
-
- # Dump the data struct we have to the file.yml
- my $yaml_file = 'results/' . delete $test->{'test'};
- $yaml_file .= '.yml';
- my $ret = open( my $fh, '>', $yaml_file );
- if ( defined $ret ) {
- print $fh Dump( $test );
- if ( ! close( $fh ) ) {
- print "[ANALYZER] Unable to close $yaml_file -> " . $! . "\n";
- }
- } else {
- print "[ANALYZER] Unable to open $yaml_file for writing -> " . $! . "\n";
- }
-
- # now that we've dumped the stuff, we can do some sanity checks
-
- # the POE we "think" we loaded should match reality!
- if ( exists $test->{'poe'}->{'v_real'} ) { # if this exists, then we successfully loaded POE
- if ( $test->{'poe'}->{'v'} ne $test->{'poe'}->{'v_real'} ) {
- print "\n[ANALYZER] The subprocess loaded a different version of POE than we thought -> $yaml_file\n";
- }
-
- # The loop we loaded should match what we wanted!
- if ( exists $test->{'poe'}->{'modules'} ) {
- if ( ! exists $test->{'poe'}->{'modules'}->{ $test->{'poe'}->{'loop'} } ) {
- # gaah special-case for IO_Poll
- if ( $test->{'poe'}->{'loop'} eq 'POE::Loop::IO_Poll' and exists $test->{'poe'}->{'modules'}->{'POE::Loop::Poll'} ) {
- # ah, ignore this
- } else {
- print "\n[ANALYZER] The subprocess loaded a different Loop than we thought -> $yaml_file\n";
- }
- }
- }
- }
-
- # the perl binary should be the same!
- if ( exists $test->{'perl'} ) { # if this exists, we successfully fired up the app ( no compile error )
- if ( $test->{'perl'}->{'binary'} ne $^X ) {
- print "\n[ANALYZER] The subprocess booted up on a different perl binary -> $yaml_file\n";
- }
- if ( $test->{'perl'}->{'v'} ne sprintf( "%vd", $^V ) ) {
- print "\n[ANALYZER] The subprocess booted up on a different perl version -> $yaml_file\n";
- }
- }
-
- # all done!
- return;
-}
-
-1;
-__END__
-=head1 NAME
-
-POE::Devel::Benchmarker::Analyzer - Analyzes the output from the benchmarks
-
-=head1 SYNOPSIS
-
- Don't use this module directly. Please see L<POE::Devel::Benchmarker>
-
-=head1 ABSTRACT
-
-This package implements the guts of converting the raw data into a machine-readable format. Furthermore, it dumps the data
-in YAML format.
-
-=head1 DESCRIPTION
-
-I promise you that once I've stabilized the YAML format I'll have it documented here :)
-
-=head1 EXPORT
-
-Automatically exports the initAnalyzer() sub
-
-=head1 SEE ALSO
-
-L<POE::Devel::Benchmarker>
-
-=head1 AUTHOR
-
-Apocalypse E<lt>apocal@cpan.orgE<gt>
-
-=head1 COPYRIGHT AND LICENSE
-
-Copyright 2008 by Apocalypse
-
-This library is free software; you can redistribute it and/or modify
-it under the same terms as Perl itself.
-
-=cut
-
-# sample test output ( from SubProcess v0.02 )
-STARTTIME: 1229232743.49131 -> TIMES 0.24 0.01 11.2 0.32
-POE-1.003-Select-LITE-assert-xsqueue
-Using master loop: Select-BUILTIN
-Using FULL Assertions!
-Using the LITE tests
-LETTING POE find POE::XS::Queue::Array
-Using POE-1.003
-POE is using: POE::Loop::Select v1.2355
-POE is using: POE::XS::Queue::Array v0.005
-POE is using: POE::Queue v1.2328
-POE is using: POE::Loop::PerlSignals v1.2329
-
-
- 10 startups in 0.853 seconds ( 11.723 per second)
-startups times: 0.09 0 0 0 0.09 0 0.73 0.11
- 10000 posts in 0.495 seconds ( 20211.935 per second)
-posts times: 0.1 0 0.73 0.11 0.53 0.06 0.73 0.11
- 10000 dispatches in 1.113 seconds ( 8984.775 per second)
-dispatches times: 0.53 0.06 0.73 0.11 1.64 0.06 0.73 0.11
- 10000 alarms in 1.017 seconds ( 9829.874 per second)
-alarms times: 1.64 0.06 0.73 0.11 2.66 0.06 0.73 0.11
- 10000 alarm_adds in 0.523 seconds ( 19102.416 per second)
-alarm_adds times: 2.66 0.06 0.73 0.11 3.18 0.06 0.73 0.11
- 10000 alarm_clears in 0.377 seconds ( 26540.332 per second)
-alarm_clears times: 3.18 0.06 0.73 0.11 3.55 0.07 0.73 0.11
- 500 session_creates in 0.130 seconds ( 3858.918 per second)
-session_creates times: 3.55 0.07 0.73 0.11 3.68 0.08 0.73 0.11
- 500 session_destroys in 0.172 seconds ( 2901.191 per second)
-session_destroys times: 3.68 0.08 0.73 0.11 3.85 0.08 0.73 0.11
- 10000 select_read_STDIN in 1.823 seconds ( 5485.878 per second)
-select_read_STDIN times: 3.85 0.08 0.73 0.11 5.66 0.08 0.73 0.11
- 10000 select_write_STDIN in 1.827 seconds ( 5472.283 per second)
-select_write_STDIN times: 5.66 0.08 0.73 0.11 7.47 0.08 0.73 0.11
- 10000 select_read_MYFH in 1.662 seconds ( 6016.387 per second)
-select_read_MYFH times: 7.47 0.08 0.73 0.11 9.12 0.1 0.73 0.11
- 10000 select_write_MYFH in 1.704 seconds ( 5868.537 per second)
-select_write_MYFH times: 9.12 0.1 0.73 0.11 10.78 0.11 0.73 0.11
- 10000 calls in 0.222 seconds ( 45038.974 per second)
-calls times: 10.78 0.11 0.73 0.11 11 0.11 0.73 0.11
- 10000 single_posts in 1.999 seconds ( 5003.473 per second)
-single_posts times: 11 0.11 0.73 0.11 12.86 0.22 0.73 0.11
-pidinfo: Name: perl
-pidinfo: State: R (running)
-pidinfo: Tgid: 16643
-pidinfo: Pid: 16643
-pidinfo: PPid: 16600
-pidinfo: TracerPid: 0
-pidinfo: Uid: 1000 1000 1000 1000
-pidinfo: Gid: 1000 1000 1000 1000
-pidinfo: FDSize: 32
-pidinfo: Groups: 4 20 24 25 29 30 44 46 107 109 115 127 1000 1001
-pidinfo: VmPeak: 14376 kB
-pidinfo: VmSize: 14216 kB
-pidinfo: VmLck: 0 kB
-pidinfo: VmHWM: 11440 kB
-pidinfo: VmRSS: 11292 kB
-pidinfo: VmData: 9908 kB
-pidinfo: VmStk: 84 kB
-pidinfo: VmExe: 1044 kB
-pidinfo: VmLib: 1872 kB
-pidinfo: VmPTE: 24 kB
-pidinfo: Threads: 1
-pidinfo: SigQ: 0/16182
-pidinfo: SigPnd: 0000000000000000
-pidinfo: ShdPnd: 0000000000000000
-pidinfo: SigBlk: 0000000000000000
-pidinfo: SigIgn: 0000000000001000
-pidinfo: SigCgt: 0000000180000000
-pidinfo: CapInh: 0000000000000000
-pidinfo: CapPrm: 0000000000000000
-pidinfo: CapEff: 0000000000000000
-pidinfo: Cpus_allowed: 03
-pidinfo: Mems_allowed: 1
-pidinfo: voluntary_ctxt_switches: 10
-pidinfo: nonvoluntary_ctxt_switches: 512
-Running under perl binary: /usr/bin/perl
-perlconfig: Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
-perlconfig: Platform:
-perlconfig: osname=linux, osvers=2.6.15.7, archname=i486-linux-gnu-thread-multi
-perlconfig: uname='linux palmer 2.6.15.7 #1 smp thu sep 7 19:42:20 utc 2006 i686 gnulinux '
-perlconfig: config_args='-Dusethreads -Duselargefiles -Dccflags=-DDEBIAN -Dcccdlflags=-fPIC -Darchname=i486-linux-gnu -Dprefix=/usr -Dprivlib=/usr/share/perl/5.8 -Darchlib=/usr/lib/perl/5.8 -Dvendorprefix=/usr -Dvendorlib=/usr/share/perl5 -Dvendorarch=/usr/lib/perl5 -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl/5.8.8 -Dsitearch=/usr/local/lib/perl/5.8.8 -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 -Dsiteman1dir=/usr/local/man/man1 -Dsiteman3dir=/usr/local/man/man3 -Dman1ext=1 -Dman3ext=3perl -Dpager=/usr/bin/sensible-pager -Uafs -Ud_csh -Ud_ualarm -Uusesfio -Uusenm -Duseshrplib -Dlibperl=libperl.so.5.8.8 -Dd_dosuid -des'
-perlconfig: hint=recommended, useposix=true, d_sigaction=define
-perlconfig: usethreads=define use5005threads=undef useithreads=define usemultiplicity=define
-perlconfig: useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
-perlconfig: use64bitint=undef use64bitall=undef uselongdouble=undef
-perlconfig: usemymalloc=n, bincompat5005=undef
-perlconfig: Compiler:
-perlconfig: cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBIAN -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
-perlconfig: optimize='-O2',
-perlconfig: cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBIAN -fno-strict-aliasing -pipe -I/usr/local/include'
-perlconfig: ccversion='', gccversion='4.2.3 20071123 (prerelease) (Ubuntu 4.2.2-3ubuntu4)', gccosandvers=''
-perlconfig: intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
-perlconfig: d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
-perlconfig: ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
-perlconfig: alignbytes=4, prototype=define
-perlconfig: Linker and Libraries:
-perlconfig: ld='cc', ldflags =' -L/usr/local/lib'
-perlconfig: libpth=/usr/local/lib /lib /usr/lib
-perlconfig: libs=-lgdbm -lgdbm_compat -ldb -ldl -lm -lpthread -lc -lcrypt
-perlconfig: perllibs=-ldl -lm -lpthread -lc -lcrypt
-perlconfig: libc=/lib/libc-2.6.1.so, so=so, useshrplib=true, libperl=libperl.so.5.8.8
-perlconfig: gnulibc_version='2.6.1'
-perlconfig: Dynamic Linking:
-perlconfig: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
-perlconfig: cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib'
-Running under machine: Linux apoc-x300 2.6.24-21-generic #1 SMP Tue Oct 21 23:43:45 UTC 2008 i686 GNU/Linux
-
-cpuinfo: processor : 0
-cpuinfo: vendor_id : GenuineIntel
-cpuinfo: cpu family : 6
-cpuinfo: model : 15
-cpuinfo: model name : Intel(R) Core(TM)2 Duo CPU L7100 @ 1.20GHz
-cpuinfo: stepping : 11
-cpuinfo: cpu MHz : 1201.000
-cpuinfo: cache size : 4096 KB
-cpuinfo: physical id : 0
-cpuinfo: siblings : 2
-cpuinfo: core id : 0
-cpuinfo: cpu cores : 2
-cpuinfo: fdiv_bug : no
-cpuinfo: hlt_bug : no
-cpuinfo: f00f_bug : no
-cpuinfo: coma_bug : no
-cpuinfo: fpu : yes
-cpuinfo: fpu_exception : yes
-cpuinfo: cpuid level : 10
-cpuinfo: wp : yes
-cpuinfo: flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc arch_perfmon pebs bts pni monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr lahf_lm ida
-cpuinfo: bogomips : 2397.58
-cpuinfo: clflush size : 64
-cpuinfo: processor : 1
-cpuinfo: vendor_id : GenuineIntel
-cpuinfo: cpu family : 6
-cpuinfo: model : 15
-cpuinfo: model name : Intel(R) Core(TM)2 Duo CPU L7100 @ 1.20GHz
-cpuinfo: stepping : 11
-cpuinfo: cpu MHz : 1201.000
-cpuinfo: cache size : 4096 KB
-cpuinfo: physical id : 0
-cpuinfo: siblings : 2
-cpuinfo: core id : 1
-cpuinfo: cpu cores : 2
-cpuinfo: fdiv_bug : no
-cpuinfo: hlt_bug : no
-cpuinfo: f00f_bug : no
-cpuinfo: coma_bug : no
-cpuinfo: fpu : yes
-cpuinfo: fpu_exception : yes
-cpuinfo: cpuid level : 10
-cpuinfo: wp : yes
-cpuinfo: flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc arch_perfmon pebs bts pni monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr lahf_lm ida
-cpuinfo: bogomips : 2394.02
-cpuinfo: clflush size : 64
-
-ENDTIME: 1229232757.53804 -> TIMES 0.27 0.01 23.1 0.62
diff --git a/lib/POE/Devel/Benchmarker/Imager.pm b/lib/POE/Devel/Benchmarker/Imager.pm
index d6a81c7..e5f977d 100644
--- a/lib/POE/Devel/Benchmarker/Imager.pm
+++ b/lib/POE/Devel/Benchmarker/Imager.pm
@@ -1,442 +1,447 @@
# Declare our package
package POE::Devel::Benchmarker::Imager;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.05';
# auto-export the only sub we have
use base qw( Exporter );
our @EXPORT = qw( imager );
# import the helper modules
use YAML::Tiny;
# load our plugins!
use Module::Pluggable search_path => [ __PACKAGE__ ];
# load comparison stuff
use version;
+# Get some stuff from Utils
+use POE::Devel::Benchmarker::Utils qw( currentTestVersion );
+
# generate some accessors
use base qw( Class::Accessor::Fast );
__PACKAGE__->mk_ro_accessors( qw( poe_versions poe_versions_sorted poe_loops data
noxsqueue noasserts litetests quiet
) );
# autoflush, please!
use IO::Handle;
STDOUT->autoflush( 1 );
# starts the work of converting our data to images
sub imager {
my $options = shift;
# instantitate ourself
my $self = __PACKAGE__->new( $options );
# parse all of our YAML modules!
$self->loadtests;
# process some stats
$self->process_data;
# generate the images!
$self->generate_images;
return;
}
# creates a new instance
sub new {
my $class = shift;
my $opts = shift;
# instantitate ourself
my $self = {};
bless $self, $class;
# init the options
$self->init_options( $opts );
if ( ! $self->{'options'}->{'quiet'} ) {
print "[IMAGER] Starting up...\n";
}
return $self;
}
sub init_options {
my $self = shift;
my $options = shift;
# set defaults
$self->{'quiet'} = 0;
$self->{'litetests'} = 1;
$self->{'noasserts'} = undef;
$self->{'noxsqueue'} = undef;
# process our options
if ( defined $options and ref $options and ref( $options ) eq 'HASH' ) {
# process quiet mode
if ( exists $options->{'quiet'} ) {
if ( $options->{'quiet'} ) {
$self->{'quiet'} = 1;
} else {
$self->{'quiet'} = 0;
}
}
# process the LITE/HEAVY
if ( exists $options->{'litetests'} ) {
if ( $options->{'litetests'} ) {
$self->{'litetests'} = 1;
} else {
$self->{'litetests'} = 0;
}
}
# process the noasserts to load
if ( exists $options->{'noasserts'} ) {
if ( $options->{'noasserts'} ) {
$self->{'noasserts'} = 1;
} else {
$self->{'noasserts'} = 0;
}
}
# process the noxsqueue to load
if ( exists $options->{'noxsqueue'} ) {
if ( $options->{'noxsqueue'} ) {
$self->{'noxsqueue'} = 1;
} else {
$self->{'noxsqueue'} = 0;
}
}
# FIXME process the plugins to load -> "types"
# FIXME process the versions to load
# FIXME process the loops to load
}
# some sanity tests
if ( ! -d 'results' ) {
die "The 'results' directory is not found in the working directory!";
}
if ( ! -d 'images' ) {
die "The 'images' directory is not found in the working directory!";
}
return;
}
# starts the process of loading all of our YAML images
sub loadtests {
my $self = shift;
# gather all the YAML dumps
if ( opendir( DUMPS, 'results' ) ) {
foreach my $d ( readdir( DUMPS ) ) {
# parse the file structure
- # POE-1.0002-IO_Poll-LITE-assert-noxsqueue
+ # POE-1.0002-IO_Poll-LITE-assert-noxsqueue.yml
if ( $d =~ /^POE\-([\d\.\_]+)\-(\w+?)\-(LITE|HEAVY)\-(noassert|assert)\-(noxsqueue|xsqueue)\.yml$/ ) {
my( $ver, $loop, $lite, $assert, $xsqueue ) = ( $1, $2, $3, $4, $5 );
# skip this file?
if ( $self->noxsqueue ) {
if ( $xsqueue eq 'xsqueue' ) { next }
} else {
if ( defined $self->noxsqueue ) {
if ( $xsqueue eq 'noxsqueue' ) { next }
}
}
if ( $self->noasserts ) {
if ( $assert eq 'assert' ) { next }
} else {
if ( defined $self->noasserts ) {
if ( $assert eq 'noassert' ) { next }
}
}
if ( $self->litetests ) {
if ( $lite eq 'HEAVY' ) { next }
} else {
if ( $lite eq 'LITE' ) { next }
}
# FIXME allow selective loading of tests, so we can control what to image, etc
# actually load this file!
$self->load_yaml( $d, $ver, $loop, $lite, $assert, $xsqueue );
}
}
closedir( DUMPS ) or die "[IMAGER] Unable to read from 'results' -> " . $!;
} else {
die "[IMAGER] Unable to open 'results' for reading -> " . $!;
}
# sanity
if ( ! exists $self->{'data'} ) {
- die "[IMAGER] Unable to find any POE test result(s) in the 'results' directory!\n";
+ die "[IMAGER] Unable to find valid POE test result(s) in the 'results' directory!\n";
}
if ( ! $self->quiet ) {
print "[IMAGER] Done with parsing the YAML files...\n";
}
return;
}
# loads the yaml of a specific file
sub load_yaml {
my ( $self, $file, $ver, $loop, $lite, $assert, $xsqueue ) = @_;
my $yaml = YAML::Tiny->read( 'results/' . $file );
if ( ! defined $yaml ) {
- die "[IMAGER] Unable to load YAML file $file -> " . YAML::Tiny->errstr . "\n";
+ print "[IMAGER] Unable to load YAML file $file -> " . YAML::Tiny->errstr . "\n";
+ return;
} else {
# inrospect it!
my $isvalid = 0;
eval {
# simple sanity check: the "x_bench" param is at the end of the YML, so if it loads fine we know it's there
- if ( exists $yaml->[0]->{'x_bench'} ) {
+ if ( defined $yaml->[0] and exists $yaml->[0]->{'x_bench'} ) {
# version must at least match us
- $isvalid = ( $yaml->[0]->{'x_bench'} eq $POE::Devel::Benchmarker::Imager::VERSION ? 1 : 0 );
+ $isvalid = ( $yaml->[0]->{'x_bench'} eq currentTestVersion() ? 1 : 0 );
} else {
$isvalid = undef;
}
};
if ( ! $isvalid or $@ ) {
- die "[IMAGER] Detected outdated/corrupt benchmark result: $file";
+ print "[IMAGER] Detected outdated/corrupt benchmark result: $file";
+ return;
} else {
# reduce indirection
$yaml = $yaml->[0];
}
}
# store the POE version
$self->{'poe_versions'}->{ $ver } = 1;
# sanity check the loop master version ( which should always be our "installed" version, not per-POE )
if ( exists $yaml->{'poe'}->{'loop_m'} ) {
if ( ! defined $self->{'poe_loops'}->{ $loop } ) {
$self->{'poe_loops'}->{ $loop } = $yaml->{'poe'}->{'loop_m'};
} else {
if ( $self->{'poe_loops'}->{ $loop } ne $yaml->{'poe'}->{'loop_m'} ) {
die "[IMAGER] Detected POE::Loop master version inconsistency! $file reported '" . $yaml->{'poe'}->{'loop_m'} .
"' while others had '" . $self->{'poe_loops'}->{ $loop } . "'";
}
}
}
# get the info we're interested in
$self->{'data'}->{ $assert }->{ $xsqueue }->{ $ver }->{ $loop }->{'metrics'} = $yaml->{'metrics'};
$self->{'data'}->{ $assert }->{ $xsqueue }->{ $ver }->{ $loop }->{'time'} = $yaml->{'t'};
if ( exists $yaml->{'pid'} ) {
$self->{'data'}->{ $assert }->{ $xsqueue }->{ $ver }->{ $loop }->{'pid'} = $yaml->{'pid'};
}
if ( exists $yaml->{'poe'}->{'modules'} ) {
$self->{'data'}->{ $assert }->{ $xsqueue }->{ $ver }->{ $loop }->{'poe_modules'} = $yaml->{'poe'}->{'modules'};
}
# sanity check the perl stuff
if ( exists $yaml->{'perl'}->{'binary'} ) {
if ( ! exists $self->{'data'}->{'perlconfig'} ) {
$self->{'data'}->{'perlconfig'}->{'binary'} = $yaml->{'perl'}->{'binary'};
$self->{'data'}->{'perlconfig'}->{'version'} = $yaml->{'perl'}->{'v'};
} else {
if ( $self->{'data'}->{'perlconfig'}->{'binary'} ne $yaml->{'perl'}->{'binary'} ) {
die "[IMAGER] Detected perl binary inconsistency! $file reported '" . $yaml->{'perl'}->{'binary'} .
"' while others had '" . $self->{'data'}->{'perlconfig'}->{'binary'} . "'";
}
if ( $self->{'data'}->{'perlconfig'}->{'version'} ne $yaml->{'perl'}->{'v'} ) {
die "[IMAGER] Detected perl version inconsistency! $file reported '" . $yaml->{'perl'}->{'v'} .
"' while others had '" . $self->{'data'}->{'perlconfig'}->{'version'} . "'";
}
}
}
# sanity check the uname
if ( exists $yaml->{'uname'} ) {
if ( ! exists $self->{'data'}->{'uname'} ) {
$self->{'data'}->{'uname'} = $yaml->{'uname'};
} else {
if ( $self->{'data'}->{'uname'} ne $yaml->{'uname'} ) {
die "[IMAGER] Detected system inconsistency! $file reported '" . $yaml->{'uname'} .
"' while others had '" . $self->{'data'}->{'uname'} . "'";
}
}
}
# sanity check the cpu name
if ( exists $yaml->{'cpu'} ) {
if ( ! exists $self->{'data'}->{'cpu'} ) {
$self->{'data'}->{'cpu'} = $yaml->{'cpu'};
} else {
if ( $self->{'data'}->{'cpu'}->{'name'} ne $yaml->{'cpu'}->{'name'} ) {
die "[IMAGER] Detected system/cpu inconsistency! $file reported '" . $yaml->{'cpu'}->{'name'} .
"' while others had '" . $self->{'data'}->{'cpu'}->{'name'} . "'";
}
}
}
return;
}
sub process_data {
my $self = shift;
# sanitize the versions in an ordered loop
$self->{'poe_versions_sorted'} = [ map { $_->stringify } sort { $a <=> $b } map { version->new($_) } keys %{ $self->poe_versions } ];
if ( ! $self->quiet ) {
print "[IMAGER] Done with processing the benchmark statistics...\n";
}
return;
}
sub generate_images {
my $self = shift;
# load our plugins and let them have fun :)
foreach my $plugin ( $self->plugins ) {
# actually load it!
## no critic
eval "require $plugin";
## use critic
if ( $@ ) {
if ( ! $self->quiet ) {
print "[IMAGER] Unable to load plugin $plugin -> $@\n";
next;
}
}
# sanity checks
if ( $plugin->can( 'new' ) and $plugin->can( 'imager' ) ) {
# FIXME did we want this plugin?
# create the plugin's home dir
my $homedir = $plugin;
if ( $homedir =~ /\:\:(\w+)$/ ) {
$homedir = $1;
} else {
die "barf";
}
if ( ! -d "images/$homedir" ) {
# create it!
if ( ! mkdir( "images/$homedir" ) ) {
die "[IMAGER] Unable to create plugin directory: $homedir";
}
}
# Okay, get this plugin!
my $obj = $plugin->new( { 'dir' => "images/$homedir/" } );
if ( ! $self->quiet ) {
print "[IMAGER] Processing the $plugin plugin...\n";
}
$obj->imager( $self );
}
}
if ( ! $self->quiet ) {
print "[IMAGER] Done with generating images...\n";
}
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::Imager - Automatically converts the benchmark data into images
=head1 SYNOPSIS
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker::Imager -e 'imager'
=head1 ABSTRACT
This package automatically parses the benchmark data and generates pretty charts.
=head1 DESCRIPTION
It will parse the YAML output from the benchmark data and calls it's plugins to generate any charts necessary
and place them in the 'images' directory under the plugin's name. This module only does the high-level stuff, and leaves
the actual chart generation to the plugins.
Furthermore, we use Module::Pluggable to search all modules in the POE::Devel::Benchmarker::Imager::* namespace and
let them handle the generation of images. That way virtually unlimited combinations of images can be generated on the fly
from the data this module parses.
The way to use this module is by calling the imager() subroutine and let it do it's job. You can pass a hashref to it to
set various options. Here is a list of the valid options:
=over 4
=item quiet => boolean
This enables quiet mode which will not print anything to the console except for errors.
new( { 'quiet' => 1 } );
default: false
=item noxsqueue => boolean / undef
This will tell the Imager to not consider those tests for the output.
benchmark( { noxsqueue => 1 } );
default: undef ( load both xsqueue and noxsqueue tests )
=item noasserts => boolean / undef
This will tell the Imager to not consider those tests for the output
benchmark( { noasserts => 1 } );
default: undef ( load both assert and noassert tests )
=item litetests => boolean
This will tell the Imager to not consider those tests for the output
benchmark( { litetests => 0 } );
default: true
=back
=head1 PLUGIN INTERFACE
For now, this is undocumented. Please look at BasicStatistics for the general concept on how it interacts with this module.
=head1 EXPORT
Automatically exports the imager() sub
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/Imager/BasicStatistics.pm b/lib/POE/Devel/Benchmarker/Imager/BasicStatistics.pm
index 52f75b3..1cd67bc 100644
--- a/lib/POE/Devel/Benchmarker/Imager/BasicStatistics.pm
+++ b/lib/POE/Devel/Benchmarker/Imager/BasicStatistics.pm
@@ -1,323 +1,356 @@
# Declare our package
package POE::Devel::Benchmarker::Imager::BasicStatistics;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.05';
# the GD stuff
use GD::Graph::lines;
+use GD::Graph::colour qw( :lists );
# import some stuff
use POE::Devel::Benchmarker::Utils qw( currentMetrics );
# creates a new instance
sub new {
my $class = shift;
my $opts = shift;
# instantitate ourself
my $self = {
'opts' => $opts,
};
return bless $self, $class;
}
# actually generates the graphs!
sub imager {
my $self = shift;
$self->{'imager'} = shift;
# generate the loops vs each other graphs
$self->generate_loopwars;
# generate the single loop performance
$self->generate_loopperf;
# generate the loop assert/xsqueue ( 4 lines ) per metric
$self->generate_loopoptions;
return;
}
# charts a single loop's progress over POE versions
sub generate_loopoptions {
my $self = shift;
if ( ! $self->{'imager'}->quiet ) {
print "[BasicStatistics] Generating the Loop-Options graphs...\n";
}
# go through all the loops we want
foreach my $loop ( keys %{ $self->{'imager'}->poe_loops } ) {
foreach my $metric ( @{ currentMetrics() } ) {
my %data;
# organize data by POE version
foreach my $poe ( @{ $self->{'imager'}->poe_versions_sorted } ) {
# go through the combo of assert/xsqueue
foreach my $assert ( qw( assert noassert ) ) {
if ( ! exists $self->{'imager'}->data->{ $assert } ) {
next;
}
foreach my $xsqueue ( qw( xsqueue noxsqueue ) ) {
if ( ! exists $self->{'imager'}->data->{ $assert }->{ $xsqueue } ) {
next;
}
- if ( exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
+ # sometimes we cannot test a metric
+ if ( exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }
+ and exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
and defined $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
) {
push( @{ $data{ $assert . '_' . $xsqueue } }, $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'} );
} else {
push( @{ $data{ $assert . '_' . $xsqueue } }, 0 );
}
}
}
}
- # transform %data into something GD likes
- my @data_for_gd;
- foreach my $m ( sort keys %data ) {
- push( @data_for_gd, $data{ $m } );
- }
+ # it's possible for us to do runs without assert/xsqueue
+ if ( scalar keys %data > 0 ) {
+ # transform %data into something GD likes
+ my @data_for_gd;
+ foreach my $m ( sort keys %data ) {
+ push( @data_for_gd, $data{ $m } );
+ }
- # send it to GD!
- $self->make_gdgraph( 'Options_' . $loop . '_' . $metric,
- [ sort keys %data ],
- \@data_for_gd,
- );
+ # send it to GD!
+ $self->make_gdgraph( 'Options_' . $loop . '_' . $metric,
+ [ sort keys %data ],
+ \@data_for_gd,
+ );
+ }
}
}
return;
}
# charts a single loop's progress over POE versions
sub generate_loopperf {
my $self = shift;
if ( ! $self->{'imager'}->quiet ) {
print "[BasicStatistics] Generating the Loop-Performance graphs...\n";
}
# go through all the loops we want
foreach my $loop ( keys %{ $self->{'imager'}->poe_loops } ) {
# go through the combo of assert/xsqueue
foreach my $assert ( qw( assert noassert ) ) {
if ( ! exists $self->{'imager'}->data->{ $assert } ) {
next;
}
foreach my $xsqueue ( qw( xsqueue noxsqueue ) ) {
if ( ! exists $self->{'imager'}->data->{ $assert }->{ $xsqueue } ) {
next;
}
my %data;
# organize data by POE version
foreach my $poe ( @{ $self->{'imager'}->poe_versions_sorted } ) {
foreach my $metric ( @{ currentMetrics() } ) {
- if ( exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
+ # sometimes we cannot test a metric
+ if ( exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }
+ and exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
and defined $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
) {
push( @{ $data{ $metric } }, $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'} );
} else {
push( @{ $data{ $metric } }, 0 );
}
}
}
# transform %data into something GD likes
my @data_for_gd;
foreach my $m ( sort keys %data ) {
push( @data_for_gd, $data{ $m } );
}
# send it to GD!
$self->make_gdgraph( 'Bench_' . $loop,
[ sort keys %data ],
\@data_for_gd,
$assert,
$xsqueue,
);
}
}
}
return;
}
# loop wars!
sub generate_loopwars {
my $self = shift;
if ( ! $self->{'imager'}->quiet ) {
print "[BasicStatistics] Generating the LoopWars graphs...\n";
}
# go through all the metrics we want
foreach my $metric ( @{ currentMetrics() } ) {
# go through the combo of assert/xsqueue
foreach my $assert ( qw( assert noassert ) ) {
+ if ( ! exists $self->{'imager'}->data->{ $assert } ) {
+ next;
+ }
foreach my $xsqueue ( qw( xsqueue noxsqueue ) ) {
+ if ( ! exists $self->{'imager'}->data->{ $assert }->{ $xsqueue } ) {
+ next;
+ }
my %data;
# organize data by POE version
foreach my $poe ( @{ $self->{'imager'}->poe_versions_sorted } ) {
foreach my $loop ( keys %{ $self->{'imager'}->poe_loops } ) {
- if ( exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
+ # sometimes we cannot test a metric
+ if ( exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }
+ and exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
and defined $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
) {
push( @{ $data{ $loop } }, $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'} );
} else {
push( @{ $data{ $loop } }, 0 );
}
}
}
# transform %data into something GD likes
my @data_for_gd;
foreach my $m ( sort keys %data ) {
push( @data_for_gd, $data{ $m } );
}
# send it to GD!
$self->make_gdgraph( "LoopWar_$metric",
[ sort keys %{ $self->{'imager'}->poe_loops } ],
\@data_for_gd,
$assert,
$xsqueue,
);
}
}
}
return;
}
sub make_gdgraph {
my $self = shift;
my $metric = shift;
my $legend = shift;
my $data = shift;
my $assert = shift;
my $xsqueue = shift;
+ # build the title
+ my $title = $metric;
+ if ( defined $assert ) {
+ $title .= ' (';
+ if ( defined $xsqueue ) {
+ $title .= $assert . ' ' . $xsqueue;
+ } else {
+ $title .= $assert;
+ }
+ $title .= ')';
+ } else {
+ if ( defined $xsqueue ) {
+ $title .= ' (' . $xsqueue . ')';
+ }
+ }
+
# Get the graph object
my $graph = new GD::Graph::lines( 800, 600 );
# Set some stuff
$graph->set(
-# 'x_label' => 'POE Versions',
- 'title' => $metric . ( defined $xsqueue ? " ($assert - $xsqueue)" : '' ),
- 'line_width' => 1,
- 'boxclr' => 'black',
- 'overwrite' => 0,
- 'x_labels_vertical' => 1,
- 'x_all_ticks' => 1,
- 'legend_placement' => 'BL',
- 'y_label' => 'iterations/sec',
-
- # 3d options only
- #'line_depth' => 2.5,
+ 'title' => $title,
+ 'line_width' => 1,
+ 'boxclr' => 'black',
+ 'overwrite' => 0,
+ 'x_labels_vertical' => 1,
+ 'x_all_ticks' => 1,
+ 'legend_placement' => 'BL',
+ 'y_label' => 'iterations/sec',
+ 'transparent' => 0,
+ 'long_ticks' => 1,
) or die $graph->error;
# Set the legend
$graph->set_legend( @$legend );
# Set Font stuff
$graph->set_legend_font( GD::gdMediumBoldFont );
$graph->set_x_axis_font( GD::gdMediumBoldFont );
$graph->set_y_axis_font( GD::gdMediumBoldFont );
$graph->set_y_label_font( GD::gdMediumBoldFont );
$graph->set_title_font( GD::gdGiantFont );
+ # set the line colors
+ $graph->set( 'dclrs' => [ grep { $_ ne 'black' and $_ ne 'white' } sorted_colour_list() ] );
+
# Manufacture the data
my $readydata = [
[ map { 'POE-' . $_ } @{ $self->{'imager'}->poe_versions_sorted } ],
@$data,
];
# Plot it!
$graph->plot( $readydata ) or die $graph->error;
# Print it!
my $filename = $self->{'opts'}->{'dir'} . $metric . '_' .
( $self->{'imager'}->litetests ? 'lite' : 'heavy' ) .
( defined $xsqueue ? '_' . $assert . '_' . $xsqueue : '' ) .
'.png';
open( my $fh, '>', $filename ) or die 'Cannot open graph file!';
binmode( $fh );
print $fh $graph->gd->png();
close( $fh );
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::Imager::BasicStatistics - Plugin to generates basic statistics graphs
=head1 SYNOPSIS
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker::Imager -e 'imager( { type => "BasicStatistics" } )'
=head1 ABSTRACT
This plugin for Imager generates some kinds of graphs from the benchmark tests.
=head1 DESCRIPTION
This package generates some basic graphs from the statistics output. Since the POE::Loop::* modules really are responsible
for the backend logic of POE, it makes sense to graph all related metrics of a single loop across POE versions to see if
it performs differently.
This will generate some types of graphs:
=over 4
=item Loops against each other
Each metric will have a picture for itself, showing how each loop compare against each other with the POE versions.
file: BasicStatistics/LoopWar_$metric_$lite_$assert_$xsqueue.png
=item Single Loop over POE versions
Each Loop will have a picture for itself, showing how each metric performs over POE versions.
file: BasicStatistics/Bench_$loop_$lite_$assert_$xsqueue.png
=item Single Loop over POE versions with assert/xsqueue
Each Loop will have a picture for itself, showing how each metric is affected by the assert/xsqueue options.
file: BasicStatistics/Options_$loop_$metric_$lite.png
=back
=head1 EXPORT
Nothing.
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/SubProcess.pm b/lib/POE/Devel/Benchmarker/SubProcess.pm
index 91dbdd9..93a78b4 100644
--- a/lib/POE/Devel/Benchmarker/SubProcess.pm
+++ b/lib/POE/Devel/Benchmarker/SubProcess.pm
@@ -1,936 +1,957 @@
# Declare our package
package POE::Devel::Benchmarker::SubProcess;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.05';
# set our compile-time stuff
BEGIN {
# should we enable assertions?
if ( defined $ARGV[1] and $ARGV[1] ) {
## no critic
eval "sub POE::Kernel::ASSERT_DEFAULT () { 1 }";
eval "sub POE::Session::ASSERT_STATES () { 1 }";
## use critic
}
# Compile a list of modules to hide
my $hide = '';
if ( defined $ARGV[0] ) {
if ( $ARGV[0] ne 'XSPoll' ) {
$hide .= ' POE/XS/Loop/Poll.pm';
}
if ( $ARGV[0] ne 'XSEPoll' ) {
$hide .= ' POE/XS/Loop/EPoll.pm';
}
}
# should we "hide" XS::Queue::Array?
if ( defined $ARGV[3] and $ARGV[3] ) {
$hide .= ' POE/XS/Queue/Array.pm';
}
# actually hide the modules!
{
## no critic
eval "use Devel::Hide qw( $hide )";
## use critic
}
}
+# process the eventloop
+BEGIN {
+ # FIXME figure out a better way to load loop with precision based on POE version
+# if ( defined $ARGV[0] ) {
+# eval "use POE::Kernel; use POE::Loop::$ARGV[0]";
+# if ( $@ ) { die $@ }
+# }
+}
+
# Import Time::HiRes's time()
use Time::HiRes qw( time );
# load POE
use POE;
use POE::Session;
use POE::Wheel::SocketFactory;
use POE::Wheel::ReadWrite;
use POE::Filter::Line;
use POE::Driver::SysRW;
# autoflush, please!
use IO::Handle;
STDOUT->autoflush( 1 );
# import some stuff
use Socket qw( INADDR_ANY sockaddr_in );
# we need to compare versions
use version;
# load our utility stuff
-use POE::Devel::Benchmarker::Utils qw( loop2realversion poeloop2load );
+use POE::Devel::Benchmarker::Utils qw( loop2realversion poeloop2load currentMetrics );
# init our global variables ( bad, haha )
-# FIXME change this to a hash because it's becoming unwieldy with too many variables
my( $eventloop, $asserts, $lite_tests, $pocosession );
-my( $post_limit, $alarm_limit, $alarm_add_limit, $session_limit, $select_limit, $through_limit, $call_limit, $start_limit, $sf_connects, $sf_stream );
+
+# setup our metrics and their data
+my %metrics = map { $_ => undef } @{ currentMetrics() };
# the main routine which will load everything + start
sub benchmark {
# process the eventloop
process_eventloop();
# process the assertions
process_assertions();
# process the test mode
process_testmode();
# process the XS::Queue hiding
process_xsqueue();
# actually import POE!
process_POE();
# actually run the benchmarks!
run_benchmarks();
# all done!
return;
}
sub process_eventloop {
# Get the desired mode
$eventloop = $ARGV[0];
# print out the loop info
if ( ! defined $eventloop ) {
die "Please supply an event loop!";
} else {
my $loop = poeloop2load( $eventloop );
if ( ! defined $loop ) {
$loop = $eventloop;
}
my $v = loop2realversion( $eventloop );
if ( ! defined $v ) {
$v = 'UNKNOWN';
}
print "Using master loop: $loop-$v\n";
}
return;
}
sub process_assertions {
# Get the desired assert mode
$asserts = $ARGV[1];
if ( defined $asserts and $asserts ) {
print "Using FULL Assertions!\n";
} else {
print "Using NO Assertions!\n";
}
return;
}
sub process_testmode {
# get the desired test mode
$lite_tests = $ARGV[2];
+ # setup most of the metrics
+ $metrics{'startups'} = 10;
+
+ # event tests
+ foreach my $s ( qw( posts dispatches calls single_posts ) ) {
+ $metrics{ $s } = 10_000;
+ }
+
+ # session tests
+ foreach my $s ( qw( session_creates session_destroys ) ) {
+ $metrics{ $s } = 500;
+ }
+
+ # alarm tests
+ foreach my $s ( qw( alarms alarm_adds alarm_clears ) ) {
+ $metrics{ $s } = 10_000;
+ }
+
+ # select tests
+ foreach my $s ( qw( select_read_STDIN select_write_STDIN select_read_MYFH select_write_MYFH ) ) {
+ $metrics{ $s } = 10_000;
+ }
+
+ # socket tests
+ foreach my $s ( qw( socket_connects socket_stream ) ) {
+ $metrics{ $s } = 1_000;
+ }
+
if ( defined $lite_tests and $lite_tests ) {
print "Using the LITE tests\n";
-
- $post_limit = 10_000;
- $alarm_limit = 10_000;
- $alarm_add_limit = 10_000;
- $session_limit = 500;
- $select_limit = 10_000;
- $through_limit = 10_000;
- $call_limit = 10_000;
- $start_limit = 10;
- $sf_connects = 1_000;
- $sf_stream = 1_000;
} else {
print "Using the HEAVY tests\n";
- $post_limit = 100_000;
- $alarm_limit = 100_000;
- $alarm_add_limit = 100_000;
- $session_limit = 5_000;
- $select_limit = 100_000;
- $through_limit = 100_000;
- $call_limit = 100_000;
- $start_limit = 100;
- $sf_connects = 10_000;
- $sf_stream = 10_000;
+ # we simply multiply each metric by 10x
+ foreach my $s ( @{ currentMetrics() } ) {
+ $metrics{ $s } = $metrics{ $s } * 10;
+ }
}
return;
}
sub process_xsqueue {
# should we "hide" XS::Queue::Array?
if ( defined $ARGV[3] and $ARGV[3] ) {
print "DISABLING POE::XS::Queue::Array\n";
} else {
print "LETTING POE find POE::XS::Queue::Array\n";
}
return;
}
sub process_POE {
# Print the POE info
print "Using POE-" . $POE::VERSION . "\n";
# Actually print what loop POE is using
foreach my $m ( keys %INC ) {
if ( $m =~ /^POE\/(?:Loop|XS|Queue)/ ) {
# try to be smart and get version?
my $module = $m;
$module =~ s|/|::|g;
$module =~ s/\.pm$//g;
print "POE is using: $module ";
if ( defined $module->VERSION ) {
print "v" . $module->VERSION . "\n";
} else {
print "vUNKNOWN\n";
}
}
}
return;
}
sub run_benchmarks {
# dump some misc info
dump_perlinfo();
dump_sysinfo();
# run the startup test before we actually run POE
bench_startup();
# load the POE session + do the tests there
bench_poe();
# okay, dump our memory usage
dump_pidinfo();
# all done!
return;
}
sub bench_startup {
# Add the eventloop?
my $looploader = poeloop2load( $eventloop );
my @start_times = times();
my $start = time();
- for (my $i = 0; $i < $start_limit; $i++) {
+ for (my $i = 0; $i < $metrics{'startups'}; $i++) {
# FIXME should we add assertions?
# finally, fire it up!
CORE::system(
$^X,
'-Ipoedists/POE-' . $POE::VERSION,
'-Ipoedists/POE-' . $POE::VERSION . '/lib',
( defined $looploader ? "-M$looploader" : () ),
'-MPOE',
'-e',
1,
);
}
my @end_times = times();
my $elapsed = time() - $start;
- printf( "\n\n% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $start_limit, 'startups', $elapsed, $start_limit/$elapsed );
+ printf( "\n\n% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'startups'}, 'startups', $elapsed, $metrics{'startups'}/$elapsed );
print "startups times: @start_times @end_times\n";
return;
}
sub bench_poe {
# figure out POE::Session->create or POE::Session->new or what?
$pocosession = POE::Session->can( 'create' );
if ( defined $pocosession ) {
$pocosession = 'create';
} else {
$pocosession = POE::Session->can( 'spawn' );
if ( defined $pocosession ) {
$pocosession = 'spawn';
} else {
$pocosession = 'new';
}
}
# create the master sesssion + run POE!
POE::Session->$pocosession(
'inline_states' => {
# basic POE states
'_start' => \&poe__start,
'_default' => \&poe__default,
'_stop' => \&poe__stop,
'null' => \&poe_null,
# our test states
'posts' => \&poe_posts,
'posts_start' => \&poe_posts_start,
'posts_end' => \&poe_posts_end,
'alarms' => \&poe_alarms,
'manyalarms' => \&poe_manyalarms,
'sessions' => \&poe_sessions,
'sessions_end' => \&poe_sessions_end,
'stdin_read' => \&poe_stdin_read,
'stdin_write' => \&poe_stdin_write,
'myfh_read' => \&poe_myfh_read,
'myfh_write' => \&poe_myfh_write,
'calls' => \&poe_calls,
'eventsquirt' => \&poe_eventsquirt,
'eventsquirt_done' => \&poe_eventsquirt_done,
'socketfactory' => \&poe_socketfactory,
'socketfactory_start' => \&poe_socketfactory_start,
'socketfactory_connects' => \&poe_socketfactory_connects,
'socketfactory_stream' => \&poe_socketfactory_stream,
'socketfactory_cleanup' => \&poe_socketfactory_cleanup,
# misc states for test stuff
'server_sf_connect' => \&poe_server_sf_connect,
'server_sf_failure' => \&poe_server_sf_failure,
'server_rw_input' => \&poe_server_rw_input,
'server_rw_error' => \&poe_server_rw_error,
'client_sf_connect' => \&poe_client_sf_connect,
'client_sf_failure' => \&poe_client_sf_failure,
'client_rw_input' => \&poe_client_rw_input,
'client_rw_error' => \&poe_client_rw_error,
},
);
# start the kernel!
POE::Kernel->run();
return;
}
# inits our session
sub poe__start {
# fire off the first test!
$_[KERNEL]->yield( 'posts' );
return;
}
sub poe__stop {
}
sub poe__default {
return 0;
}
# a state that does nothing
sub poe_null {
return 1;
}
# How many posts per second? Post a bunch of events, keeping track of the time it takes.
sub poe_posts {
$_[KERNEL]->yield( 'posts_start' );
my $start = time();
my @start_times = times();
- for (my $i = 0; $i < $post_limit; $i++) {
+ for (my $i = 0; $i < $metrics{'posts'}; $i++) {
$_[KERNEL]->yield( 'null' );
}
my @end_times = times();
my $elapsed = time() - $start;
- printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $post_limit, 'posts', $elapsed, $post_limit/$elapsed );
+ printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'posts'}, 'posts', $elapsed, $metrics{'posts'}/$elapsed );
print "posts times: @start_times @end_times\n";
$_[KERNEL]->yield( 'posts_end' );
return;
}
sub poe_posts_start {
$_[HEAP]->{start} = time();
$_[HEAP]->{starttimes} = [ times() ];
return;
}
sub poe_posts_end {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
- printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $post_limit, 'dispatches', $elapsed, $post_limit/$elapsed );
+ printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'dispatches'}, 'dispatches', $elapsed, $metrics{'dispatches'}/$elapsed );
print "dispatches times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
$_[KERNEL]->yield( 'alarms' );
return;
}
# How many alarms per second? Set a bunch of alarms and find out.
sub poe_alarms {
my $start = time();
my @start_times = times();
- for (my $i = 0; $i < $alarm_limit; $i++) {
+ for (my $i = 0; $i < $metrics{'alarms'}; $i++) {
$_[KERNEL]->alarm( whee => rand(1_000_000) );
}
my $elapsed = time() - $start;
my @end_times = times();
- printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $alarm_limit, 'alarms', $elapsed, $alarm_limit/$elapsed );
+ printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'alarms'}, 'alarms', $elapsed, $metrics{'alarms'}/$elapsed );
print "alarms times: @start_times @end_times\n";
$_[KERNEL]->alarm( 'whee' => undef );
$_[KERNEL]->yield( 'manyalarms' );
return;
}
# How many repetitive alarms per second? Set a bunch of
# additional alarms and find out. Also see how quickly they can
# be cleared.
sub poe_manyalarms {
# can this POE::Kernel support this?
if ( $_[KERNEL]->can( 'alarm_add' ) ) {
my $start = time();
my @start_times = times();
- for (my $i = 0; $i < $alarm_add_limit; $i++) {
+ for (my $i = 0; $i < $metrics{'alarm_adds'}; $i++) {
$_[KERNEL]->alarm_add( whee => rand(1_000_000) );
}
my $elapsed = time() - $start;
my @end_times = times();
- printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $alarm_add_limit, 'alarm_adds', $elapsed, $alarm_add_limit/$elapsed );
+ printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'alarm_adds'}, 'alarm_adds', $elapsed, $metrics{'alarm_adds'}/$elapsed );
print "alarm_adds times: @start_times @end_times\n";
$start = time();
@start_times = times();
$_[KERNEL]->alarm( whee => undef );
$elapsed = time() - $start;
@end_times = times();
- printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $alarm_add_limit, 'alarm_clears', $elapsed, $alarm_add_limit/$elapsed );
+ printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'alarm_adds'}, 'alarm_clears', $elapsed, $metrics{'alarm_adds'}/$elapsed );
print "alarm_clears times: @start_times @end_times\n";
} else {
print "SKIPPING br0ken alarm_adds because alarm_add() NOT SUPPORTED on this version of POE\n";
print "SKIPPING br0ken alarm_clears because alarm_add() NOT SUPPORTED on this version of POE\n";
}
$_[KERNEL]->yield( 'sessions' );
return;
}
# How many sessions can we create and destroy per second?
# Create a bunch of sessions, and track that time. Let them
# self-destruct, and track that as well.
sub poe_sessions {
my $start = time();
my @start_times = times();
- for (my $i = 0; $i < $session_limit; $i++) {
+ for (my $i = 0; $i < $metrics{'session_creates'}; $i++) {
POE::Session->$pocosession( 'inline_states' => { _start => sub {}, _stop => sub {}, _default => sub { return 0 } } );
}
my $elapsed = time() - $start;
my @end_times = times();
- printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $session_limit, 'session_creates', $elapsed, $session_limit/$elapsed );
+ printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'session_creates'}, 'session_creates', $elapsed, $metrics{'session_creates'}/$elapsed );
print "session_creates times: @start_times @end_times\n";
$_[KERNEL]->yield( 'sessions_end' );
$_[HEAP]->{start} = time();
$_[HEAP]->{starttimes} = [ times() ];
return;
}
sub poe_sessions_end {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
- printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $session_limit, 'session_destroys', $elapsed, $session_limit/$elapsed );
+ printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'session_creates'}, 'session_destroys', $elapsed, $metrics{'session_creates'}/$elapsed );
print "session_destroys times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
$_[KERNEL]->yield( 'stdin_read' );
return;
}
# How many times can we select/unselect READ a from STDIN filehandle per second?
sub poe_stdin_read {
# stupid, but we have to skip those tests
if ( $eventloop eq 'Tk' or $eventloop eq 'Prima' ) {
print "SKIPPING br0ken select_read_STDIN because eventloop doesn't work: $eventloop\n";
print "SKIPPING br0ken select_write_STDIN because eventloop doesn't work: $eventloop\n";
$_[KERNEL]->yield( 'myfh_read' );
return;
}
my $start = time();
my @start_times = times();
eval {
- for (my $i = 0; $i < $select_limit; $i++) {
+ for (my $i = 0; $i < $metrics{'select_read_STDIN'}; $i++) {
$_[KERNEL]->select_read( *STDIN, 'whee' );
$_[KERNEL]->select_read( *STDIN );
}
};
if ( $@ ) {
print "SKIPPING br0ken select_read_STDIN because FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
- printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $select_limit, 'select_read_STDIN', $elapsed, $select_limit/$elapsed );
+ printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'select_read_STDIN'}, 'select_read_STDIN', $elapsed, $metrics{'select_read_STDIN'}/$elapsed );
print "select_read_STDIN times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'stdin_write' );
return;
}
# How many times can we select/unselect WRITE a from STDIN filehandle per second?
sub poe_stdin_write {
my $start = time();
my @start_times = times();
eval {
- for (my $i = 0; $i < $select_limit; $i++) {
+ for (my $i = 0; $i < $metrics{'select_write_STDIN'}; $i++) {
$_[KERNEL]->select_write( *STDIN, 'whee' );
$_[KERNEL]->select_write( *STDIN );
}
};
if ( $@ ) {
print "SKIPPING br0ken select_write_STDIN because FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
- printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $select_limit, 'select_write_STDIN', $elapsed, $select_limit/$elapsed );
+ printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'select_write_STDIN'}, 'select_write_STDIN', $elapsed, $metrics{'select_write_STDIN'}/$elapsed );
print "select_write_STDIN times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'myfh_read' );
return;
}
# How many times can we select/unselect READ a real filehandle?
sub poe_myfh_read {
# stupid, but we have to skip those tests
if ( $eventloop eq 'Event_Lib' or $eventloop eq 'Tk' or $eventloop eq 'Prima' ) {
print "SKIPPING br0ken select_read_MYFH because eventloop doesn't work: $eventloop\n";
print "SKIPPING br0ken select_write_MYFH because eventloop doesn't work: $eventloop\n";
$_[KERNEL]->yield( 'calls' );
return;
}
my $start = time();
my @start_times = times();
eval {
open( my $fh, '+>', 'poebench' ) or die $!;
- for (my $i = 0; $i < $select_limit; $i++) {
+ for (my $i = 0; $i < $metrics{'select_read_MYFH'}; $i++) {
$_[KERNEL]->select_read( $fh, 'whee' );
$_[KERNEL]->select_read( $fh );
}
close( $fh ) or die $!;
unlink( 'poebench' ) or die $!;
};
if ( $@ ) {
print "SKIPPING br0ken select_read_MYFH because FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
- printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $select_limit, 'select_read_MYFH', $elapsed, $select_limit/$elapsed );
+ printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'select_read_MYFH'}, 'select_read_MYFH', $elapsed, $metrics{'select_read_MYFH'}/$elapsed );
print "select_read_MYFH times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'myfh_write' );
return;
}
# How many times can we select/unselect WRITE a real filehandle?
sub poe_myfh_write {
my $start = time();
my @start_times = times();
eval {
open( my $fh, '+>', 'poebench' ) or die $!;
- for (my $i = 0; $i < $select_limit; $i++) {
+ for (my $i = 0; $i < $metrics{'select_write_MYFH'}; $i++) {
$_[KERNEL]->select_write( $fh, 'whee' );
$_[KERNEL]->select_write( $fh );
}
close( $fh ) or die $!;
unlink( 'poebench' ) or die $!;
};
if ( $@ ) {
print "SKIPPING br0ken select_write_MYFH because FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
- printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $select_limit, 'select_write_MYFH', $elapsed, $select_limit/$elapsed );
+ printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'select_write_MYFH'}, 'select_write_MYFH', $elapsed, $metrics{'select_write_MYFH'}/$elapsed );
print "select_write_MYFH times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'calls' );
return;
}
# How many times can we call a state?
sub poe_calls {
my $start = time();
my @start_times = times();
- for (my $i = 0; $i < $call_limit; $i++) {
+ for (my $i = 0; $i < $metrics{'calls'}; $i++) {
$_[KERNEL]->call( $_[SESSION], 'null' );
}
my $elapsed = time() - $start;
my @end_times = times();
- printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $call_limit, 'calls', $elapsed, $call_limit/$elapsed );
+ printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'calls'}, 'calls', $elapsed, $metrics{'calls'}/$elapsed );
print "calls times: @start_times @end_times\n";
$_[KERNEL]->yield( 'eventsquirt' );
return;
}
# How many events can we squirt through POE, one at a time?
sub poe_eventsquirt {
$_[HEAP]->{start} = time();
$_[HEAP]->{starttimes} = [ times() ];
- $_[HEAP]->{yield_count} = $through_limit;
+ $_[HEAP]->{yield_count} = $metrics{'single_posts'};
$_[KERNEL]->yield( 'eventsquirt_done' );
return;
}
sub poe_eventsquirt_done {
if (--$_[HEAP]->{yield_count}) {
$_[KERNEL]->yield( 'eventsquirt_done' );
} else {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
- printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $through_limit, 'single_posts', $elapsed, $through_limit/$elapsed );
+ printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'single_posts'}, 'single_posts', $elapsed, $metrics{'single_posts'}/$elapsed );
print "single_posts times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
$_[KERNEL]->yield( 'socketfactory' );
}
return;
}
# tests socketfactory interactions
sub poe_socketfactory {
# POE transitioned between Event to State on 0.19 for SocketFactory/ReadWrite
# 0.20+ throws deprecation error :(
$_[HEAP]->{'POE_naming'} = 'Event';
if ( version->new( $POE::VERSION ) < version->new( '0.20' ) ) {
$_[HEAP]->{'POE_naming'} = 'State';
}
# create the socketfactory server
$_[HEAP]->{'SF'} = POE::Wheel::SocketFactory->new(
'Port' => INADDR_ANY,
'Address' => 'localhost',
'Reuse' => 'yes',
'Success' . $_[HEAP]->{'POE_naming'} => 'server_sf_connect',
'Failure' . $_[HEAP]->{'POE_naming'} => 'server_sf_failure',
);
# be evil, and get the port for the client to connect to
( $_[HEAP]->{'SF_port'}, undef ) = sockaddr_in( getsockname( $_[HEAP]->{'SF'}->[ POE::Wheel::SocketFactory::MY_SOCKET_HANDLE() ] ) );
# start the connect tests
- $_[HEAP]->{'SF_counter'} = $sf_connects;
- $_[HEAP]->{'SF_mode'} = 'CONNECTS';
+ $_[HEAP]->{'SF_counter'} = $metrics{'socket_connects'};
+ $_[HEAP]->{'SF_mode'} = 'socket_connects';
$_[HEAP]->{'start'} = time();
$_[HEAP]->{'starttimes'} = [ times() ];
$_[KERNEL]->yield( 'socketfactory_connects' );
return;
}
# handles SocketFactory connection
sub poe_server_sf_connect {
# what test mode?
- if ( $_[HEAP]->{'SF_mode'} eq 'CONNECTS' ) {
+ if ( $_[HEAP]->{'SF_mode'} eq 'socket_connects' ) {
# simply discard this socket
- } elsif ( $_[HEAP]->{'SF_mode'} eq 'STREAM' ) {
+ } elsif ( $_[HEAP]->{'SF_mode'} eq 'socket_stream' ) {
# convert it to ReadWrite
my $wheel = POE::Wheel::ReadWrite->new(
'Handle' => $_[ARG0],
'Filter' => POE::Filter::Line->new,
'Driver' => POE::Driver::SysRW->new,
'Input' . $_[HEAP]->{'POE_naming'} => 'server_rw_input',
'Error' . $_[HEAP]->{'POE_naming'} => 'server_rw_error',
);
# save it in our heap
$_[HEAP]->{'RW'}->{ $wheel->ID } = $wheel;
} else {
die "unknown test mode";
}
return;
}
# handles SocketFactory errors
sub poe_server_sf_failure {
# ARGH, we couldnt create listening socket
print "SKIPPING br0ken socket_connects because we were unable to setup listening socket\n";
print "SKIPPING br0ken socket_stream because we were unable to setup listening socket\n";
$_[KERNEL]->yield( 'socketfactory_cleanup' );
return;
}
# handles ReadWrite input
sub poe_server_rw_input {
# what test mode?
- if ( $_[HEAP]->{'SF_mode'} eq 'CONNECTS' ) {
+ if ( $_[HEAP]->{'SF_mode'} eq 'socket_connects' ) {
# simply discard this data
- } elsif ( $_[HEAP]->{'SF_mode'} eq 'STREAM' ) {
+ } elsif ( $_[HEAP]->{'SF_mode'} eq 'socket_stream' ) {
# send it back to the client!
$_[HEAP]->{'RW'}->{ $_[ARG1] }->put( $_[ARG0] );
} else {
die "unknown test mode";
}
return;
}
# handles ReadWrite disconnects
sub poe_server_rw_error {
# simply get rid of the wheel
if ( exists $_[HEAP]->{'RW'}->{ $_[ARG3] } ) {
# FIXME do we need this?
eval {
$_[HEAP]->{'RW'}->{ $_[ARG3] }->shutdown_input;
$_[HEAP]->{'RW'}->{ $_[ARG3] }->shutdown_output;
};
delete $_[HEAP]->{'RW'}->{ $_[ARG3] };
}
return;
}
# starts the client connect tests
sub poe_socketfactory_connects {
if (--$_[HEAP]->{'SF_counter'}) {
# open a new client connection!
$_[HEAP]->{'client_SF'} = POE::Wheel::SocketFactory->new(
'RemoteAddress' => 'localhost',
'RemotePort' => $_[HEAP]->{'SF_port'},
'Success' . $_[HEAP]->{'POE_naming'} => 'client_sf_connect',
'Failure' . $_[HEAP]->{'POE_naming'} => 'client_sf_failure',
);
} else {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
- printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $sf_connects, 'socket_connects', $elapsed, $sf_connects/$elapsed );
+ printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'socket_connects'}, 'socket_connects', $elapsed, $metrics{'socket_connects'}/$elapsed );
print "socket_connects times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
$_[KERNEL]->yield( 'socketfactory_stream' );
}
return;
}
# starts the client stream tests
sub poe_socketfactory_stream {
# set the proper test mode
- $_[HEAP]->{'SF_mode'} = 'STREAM';
+ $_[HEAP]->{'SF_mode'} = 'socket_stream';
# open a new client connection!
$_[HEAP]->{'client_SF'} = POE::Wheel::SocketFactory->new(
'RemoteAddress' => 'localhost',
'RemotePort' => $_[HEAP]->{'SF_port'},
'Success' . $_[HEAP]->{'POE_naming'} => 'client_sf_connect',
'Failure' . $_[HEAP]->{'POE_naming'} => 'client_sf_failure',
);
return;
}
# the client connected to the server!
sub poe_client_sf_connect {
# what test mode?
- if ( $_[HEAP]->{'SF_mode'} eq 'CONNECTS' ) {
+ if ( $_[HEAP]->{'SF_mode'} eq 'socket_connects' ) {
# simply discard this connection
delete $_[HEAP]->{'client_SF'};
# make another connection!
$_[KERNEL]->yield( 'socketfactory_connects' );
- } elsif ( $_[HEAP]->{'SF_mode'} eq 'STREAM' ) {
+ } elsif ( $_[HEAP]->{'SF_mode'} eq 'socket_stream' ) {
# convert it to ReadWrite
my $wheel = POE::Wheel::ReadWrite->new(
'Handle' => $_[ARG0],
'Filter' => POE::Filter::Line->new,
'Driver' => POE::Driver::SysRW->new,
'Input' . $_[HEAP]->{'POE_naming'} => 'client_rw_input',
'Error' . $_[HEAP]->{'POE_naming'} => 'client_rw_error',
);
# save it in our heap
$_[HEAP]->{'client_RW'}->{ $wheel->ID } = $wheel;
# begin the STREAM test!
- $_[HEAP]->{'SF_counter'} = $sf_stream;
- $_[HEAP]->{'SF_data'} = 'x' x ( $sf_stream / 10 ); # set a reasonable-sized chunk of data
+ $_[HEAP]->{'SF_counter'} = $metrics{'socket_stream'};
+ $_[HEAP]->{'SF_data'} = 'x' x ( $metrics{'socket_stream'} / 10 ); # set a reasonable-sized chunk of data
$_[HEAP]->{'start'} = time();
$_[HEAP]->{'starttimes'} = [ times() ];
$wheel->put( $_[HEAP]->{'SF_data'} );
} else {
die "unknown test mode";
}
return;
}
# handles SocketFactory errors
sub poe_client_sf_failure {
# ARGH, we couldnt create connecting socket
- if ( $_[HEAP]->{'SF_mode'} eq 'CONNECTS' ) {
+ if ( $_[HEAP]->{'SF_mode'} eq 'socket_connects' ) {
print "SKIPPING br0ken socket_connects because we were unable to setup connecting socket\n";
# go to stream test
$_[KERNEL]->yield( 'socketfactory_stream' );
- } elsif ( $_[HEAP]->{'SF_mode'} eq 'STREAM' ) {
+ } elsif ( $_[HEAP]->{'SF_mode'} eq 'socket_stream' ) {
print "SKIPPING br0ken socket_stream because we were unable to setup connecting socket\n";
$_[KERNEL]->yield( 'socketfactory_cleanup' );
}
return;
}
# handles ReadWrite input
sub poe_client_rw_input {
if (--$_[HEAP]->{'SF_counter'}) {
# send it back to the server!
$_[HEAP]->{'client_RW'}->{ $_[ARG1] }->put( $_[ARG0] );
} else {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
- printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $sf_stream, 'socket_stream', $elapsed, $sf_stream/$elapsed );
+ printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $metrics{'socket_stream'}, 'socket_stream', $elapsed, $metrics{'socket_stream'}/$elapsed );
print "socket_stream times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
$_[KERNEL]->yield( 'socketfactory_cleanup' );
}
return;
}
# handles ReadWrite disconnect
sub poe_client_rw_error {
# simply get rid of the wheel
if ( exists $_[HEAP]->{'client_RW'}->{ $_[ARG3] } ) {
# FIXME do we need this?
eval {
$_[HEAP]->{'client_RW'}->{ $_[ARG3] }->shutdown_input;
$_[HEAP]->{'client_RW'}->{ $_[ARG3] }->shutdown_output;
};
delete $_[HEAP]->{'client_RW'}->{ $_[ARG3] };
}
return;
}
# all done with the socketfactory tests
sub poe_socketfactory_cleanup {
# do cleanup
delete $_[HEAP]->{'SF'} if exists $_[HEAP]->{'SF'};
delete $_[HEAP]->{'RW'} if exists $_[HEAP]->{'RW'};
delete $_[HEAP]->{'client_SF'} if exists $_[HEAP]->{'client_SF'};
delete $_[HEAP]->{'client_RW'} if exists $_[HEAP]->{'client_RW'};
# XXX all done with tests!
return;
}
# Get the memory footprint
sub dump_pidinfo {
my $ret = open( my $fh, '<', '/proc/self/status' );
if ( defined $ret ) {
while ( <$fh> ) {
chomp;
if ( $_ ne '' ) {
print "pidinfo: $_\n";
}
}
close( $fh ) or die $!;
} else {
print "UNABLE TO GET /proc/self/status\n";
}
return;
}
# print the local Perl info
sub dump_perlinfo {
print "Running under perl binary: '" . $^X . "' v" . sprintf( "%vd", $^V ) . "\n";
require Config;
my $config = Config::myconfig();
foreach my $l ( split( /\n/, $config ) ) {
print "perlconfig: $l\n";
}
return;
}
# print the local system information
sub dump_sysinfo {
print "Running under machine: " . `uname -a` . "\n";
# get cpuinfo
my $ret = open( my $fh, '<', '/proc/cpuinfo' );
if ( defined $ret ) {
while ( <$fh> ) {
chomp;
if ( $_ ne '' ) {
print "cpuinfo: $_\n";
}
}
close( $fh ) or die $!;
} else {
print "UNABLE TO GET /proc/cpuinfo\n";
}
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::SubProcess - Implements the actual POE benchmarks
=head1 SYNOPSIS
perl -MPOE::Devel::Benchmarker::SubProcess -e 'benchmark()'
=head1 ABSTRACT
This package is responsible for implementing the guts of the benchmarks, and timing them.
=head1 EXPORT
Nothing.
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/Utils.pm b/lib/POE/Devel/Benchmarker/Utils.pm
index 21e8840..8086095 100644
--- a/lib/POE/Devel/Benchmarker/Utils.pm
+++ b/lib/POE/Devel/Benchmarker/Utils.pm
@@ -1,223 +1,236 @@
# Declare our package
package POE::Devel::Benchmarker::Utils;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.05';
# set ourself up for exporting
use base qw( Exporter );
our @EXPORT_OK = qw( poeloop2load load2poeloop loop2realversion beautify_times knownloops generateTestfile
- currentMetrics
+ currentMetrics currentTestVersion
);
+# returns the current test output version
+sub currentTestVersion {
+ return '1';
+}
+
# returns the list of current metrics
sub currentMetrics {
- return [ qw( alarms dispatches posts single_posts startups
+ return [ qw(
+ startups
+ alarms alarm_adds alarm_clears
+ dispatches posts single_posts
+ session_creates session_destroys
select_read_MYFH select_write_MYFH select_read_STDIN select_write_STDIN
socket_connects socket_stream
) ];
}
# returns the filename for a particular test
sub generateTestfile {
my $heap = shift;
return 'POE-' . $heap->{'current_version'} .
'-' . $heap->{'current_loop'} .
'-' . ( $heap->{'lite_tests'} ? 'LITE' : 'HEAVY' ) .
'-' . ( $heap->{'current_assertions'} ? 'assert' : 'noassert' ) .
'-' . ( $heap->{'current_noxsqueue'} ? 'noxsqueue' : 'xsqueue' );
}
# maintains the mapping of the loop <-> real module
my %poe2load = (
'Event' => 'Event',
'IO_Poll' => 'IO::Poll',
'Event_Lib' => 'Event::Lib',
'EV' => 'EV',
'Glib' => 'Glib',
'Tk' => 'Tk',
'Gtk' => 'Gtk',
'Prima' => 'Prima',
'Wx' => 'Wx',
'Kqueue' => undef,
'Select' => undef,
);
# returns the proper "load" stuff for a specific loop
sub poeloop2load {
my $eventloop = shift;
if ( exists $poe2load{ $eventloop } ) {
return $poe2load{ $eventloop };
} else {
die "Unknown event loop!";
}
}
# returns the version of the "real" installed module that the loop uses
sub loop2realversion {
my $eventloop = shift;
# Decide which event loop to use
if ( ! defined $eventloop ) {
return;
} elsif ( $eventloop eq 'Event' ) {
return $Event::VERSION;
} elsif ( $eventloop eq 'IO_Poll' ) {
return $IO::Poll::VERSION;
} elsif ( $eventloop eq 'Event_Lib' ) {
return $Event::Lib::VERSION;
} elsif ( $eventloop eq 'EV' ) {
return $EV::VERSION;
} elsif ( $eventloop eq 'Glib' ) {
return $Glib::VERSION;
} elsif ( $eventloop eq 'Tk' ) {
return $Tk::VERSION;
} elsif ( $eventloop eq 'Gtk' ) {
return $Gtk::VERSION;
} elsif ( $eventloop eq 'Prima' ) {
return $Prima::VERSION;
} elsif ( $eventloop eq 'Wx' ) {
return $Wx::VERSION;
} elsif ( $eventloop eq 'Kqueue' ) {
# FIXME how do I do this?
return;
} elsif ( $eventloop eq 'Select' ) {
return 'BUILTIN';
# FIXME figure the XS stuff out!
# } elsif ( $eventloop eq 'XSPoll' ) {
# return $POE::XS::Loop::Poll::VERSION;
# } elsif ( $eventloop eq 'XSEpoll' ) {
# return $POE::XS::Loop::EPoll::VERSION;
} else {
die "Unknown event loop!";
}
}
# helper routine to parse times() output
sub beautify_times {
my $string = shift;
my $origdata = shift;
# split it up
$string =~ s/^\s+//; $string =~ s/\s+$//;
my @times = split( /\s+/, $string );
# make the data struct
# ($user,$system,$cuser,$csystem) = times;
my $data = {
'u' => $times[4] - $times[0],
's' => $times[5] - $times[1],
'cu' => $times[6] - $times[2],
'cs' => $times[7] - $times[3],
};
# add original data?
if ( $origdata ) {
$data->{'s_user'} = $times[0];
$data->{'s_sys'} = $times[1];
$data->{'s_cuser'} = $times[2];
$data->{'s_csys'} = $times[3];
$data->{'e_user'} = $times[4];
$data->{'e_sys'} = $times[5];
$data->{'e_cuser'} = $times[6];
$data->{'e_csys'} = $times[7];
}
# send it back!
return $data;
}
# returns a list of "known" POE loops
sub knownloops {
# FIXME we remove Wx because I suck.
# FIXME I have no idea how to load/unload Kqueue...
# FIXME figure out the XS stuff! XSPoll XSEPoll
return [ qw( Event_Lib EV Glib Prima Gtk Tk Select IO_Poll ) ];
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::Utils - Various utility routines for POE::Devel::Benchmarker
=head1 SYNOPSIS
perl -MPOE::Devel::Benchmarker::Utils -e 'print poeloop2load( "IO_Poll" )'
=head1 ABSTRACT
This package contains the utility routines and constants that POE::Devel::Benchmarker needs.
=head1 EXPORT
This package exports those subs via @EXPORT_OK:
=over 4
+=item currentTestVersion()
+
+Returns the current test version, used to identify different versions of the test output
+
=item currentMetrics()
Returns an arrayref of the current benchmark "metrics" that we process
=item knownloops()
Returns an arrayref of the "known" POE loops as of this version of the Benchmarker
=item poeloop2load()
Returns the "parent" class to load for a specific loop. An example is:
$real = poeloop2load( 'IO_Poll' ); # $real now contains "IO::Poll"
=item loop2realversion()
Returns the version of the "parent" class for a specific loop. An example is:
$ver = loop2realversion( 'IO_Poll' ); # $ver now contains $IO::Poll::VERSION
=item beautify_times()
Returns a hashref of data from parsing 2 consecutive times() structures in a string. You can pass an additional parameter
( boolean ) to include the original data. An example is:
print Data::Dumper::Dumper( beautify_times( '0.1 0 0 0 0.1 0 0.76 0.09', 1 ) );
{
"sys" => 0, # total system time
"user" => 0, # total user time
"csys" => 0.76 # total children system time
"cuser" => 0.08 # total children user time
"e_csys" => "0.09", # end children system time ( optional )
"e_cuser" => "0.76", # end children user time ( optional )
"e_sys" => 0, # end system time ( optional )
"e_user" => "0.1", # end user time ( optional )
"s_csys" => 0, # start children system time ( optional )
"s_cuser" => 0, # start children user time ( optional )
"s_sys" => 0, # start system time ( optional )
"s_user" => "0.1" # start user time ( optional )
}
=back
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/t/1_load.t b/t/1_load.t
index 38d0393..031289a 100755
--- a/t/1_load.t
+++ b/t/1_load.t
@@ -1,13 +1,15 @@
#!/usr/bin/perl
# Import the stuff
# XXX no idea why this is broken for this particular dist!
#use Test::UseAllModules;
#BEGIN { all_uses_ok(); }
-use Test::More tests => 5;
+use Test::More tests => 7;
use_ok( 'POE::Devel::Benchmarker' );
use_ok( 'POE::Devel::Benchmarker::SubProcess' );
use_ok( 'POE::Devel::Benchmarker::GetInstalledLoops' );
use_ok( 'POE::Devel::Benchmarker::GetPOEdists' );
use_ok( 'POE::Devel::Benchmarker::Utils' );
+use_ok( 'POE::Devel::Benchmarker::Imager' );
+use_ok( 'POE::Devel::Benchmarker::Imager::BasicStatistics' );
|
apocalypse/perl-poe-benchmarker
|
e5d556ee6e86f8c8a6bfd29213ab1ec8c3ec7bdd
|
more tweaks
|
diff --git a/Build.PL b/Build.PL
index 03bda6e..fc5089c 100755
--- a/Build.PL
+++ b/Build.PL
@@ -1,107 +1,108 @@
# Build.PL
use Module::Build;
my $build = Module::Build->new(
# look up Module::Build::API for the info!
'dynamic_config' => 0,
'module_name' => 'POE::Devel::Benchmarker',
'license' => 'perl',
'dist_abstract' => "Benchmarking POE's performance ( acts more like a smoker )",
'dist_author' => 'Apocalypse <APOCAL@cpan.org>',
'create_packlist' => 1,
'create_makefile_pl' => 'traditional',
'create_readme' => 1,
'test_files' => 't/*.t',
'add_to_cleanup' => [ 'META.yml', 'Makefile.PL', 'README' ], # automatically generated
'requires' => {
# POE Stuff
'POE' => 0,
'POE::Session::AttributeBased' => 0,
# FIXME POE stuff that Test::Dependencies needs to see
- #'POE::Session' => 0,
- #'POE::Wheel::SocketFactory' => 0,
- #'POE::Wheel::ReadWrite' => 0,
- #'POE::Filter::Line' => 0,
+ 'POE::Session' => 0,
+ 'POE::Wheel::SocketFactory' => 0,
+ 'POE::Wheel::ReadWrite' => 0,
+ 'POE::Filter::Line' => 0,
+ 'POE::Driver::SysRW' => 0,
# misc perl stuff
'Time::HiRes' => 0,
'version' => 0,
'Devel::Hide' => 0,
# Analyzer reqs
'YAML::Tiny' => 0,
# GetPOEdists reqs
'LWP::UserAgent' => 0,
'HTML::LinkExtor' => 0,
'URI::URL' => 0,
'Archive::Tar' => 0,
# Imager reqs
'GD::Graph::lines' => 0,
'Class::Accessor::Fast' => 0,
'Module::Pluggable' => 0,
# Test stuff
'Test::More' => '0.86', # require latest for note() support in t/a_is_prereq_outdated.t
},
'recommends' => {
# our POE loops!
'POE::Loop::Event' => 0,
'POE::Loop::Event_Lib' => 0,
'POE::Loop::EV' => 0,
'POE::Loop::Glib' => 0,
'POE::Loop::Prima' => 0,
'POE::Loop::Gtk' => 0,
'POE::Loop::Wx' => 0,
'POE::Loop::Kqueue' => 0,
# included in POE ( listed here for completeness )
#'POE::Loop::Tk' => 0,
#'POE::Loop::Select' => 0,
#'POE::Loop::IO_Poll' => 0,
# the loops' dependencies
'Event' => 0,
'Event::Lib' => 0,
'EV' => 0,
'Glib' => 0,
'Prima' => 0,
'Gtk' => 0,
'Wx' => 0,
'Tk' => 0,
# the XS queue
'POE::XS::Queue::Array' => 0,
},
# FIXME wishlist...
# 'test_requires' => {
# # Test stuff
# 'Test::Compile' => 0,
# 'Test::Perl::Critic' => 0,
# 'Test::Dependencies' => 0,
# 'Test::Distribution' => 0,
# 'Test::Fixme' => 0,
# 'Test::HasVersion' => 0,
# 'Test::Kwalitee' => 0,
# 'Test::CheckManifest' => 0,
# 'Test::MinimumVersion' => 0,
# 'Test::Pod::Coverage' => 0,
# 'Test::Spelling' => 0,
# 'Test::Pod' => 0,
# 'Test::Prereq' => 0,
# 'Test::Strict' => 0,
# 'Test::UseAllModules' => 0,
# },
);
# all done!
$build->create_build_script;
diff --git a/Changes b/Changes
index 8a97459..9d915b8 100755
--- a/Changes
+++ b/Changes
@@ -1,32 +1,38 @@
Revision history for Perl extension POE::Devel::Benchmarker
+* 0.05
+
+ Minor tweaks on the YAML output ( nothing new, hah! )
+ Added the socket tests, yay! ( adapted from LotR's script, thanks! )
+ Some more tweaks to the BasicStatistics plugin
+
* 0.04
Started work on the image generator ( Imager ) and added the BasicStatistics plugin, yay!
Added automatic "pick up where we left off" to the benchmarker
Added the freshstart option to benchmark()
Tweaked the GetPOEdists sub so it will work in the "work directory" and in the poedists dir
Tweaked the YAML output so it's smaller
Removed POE::Loop::Wx from autoprobing ( I'm unable to get it to work )
Removed POE::Loop::Kqueue from autoprobing ( I'm unable to get it to work )
Hardcoded the Benchmarker routines to skip POE < 0.13 ( I'm unable to get it to work )
* 0.03
Added the loop option to benchmark(), thanks dngor!
Added the poe option to benchmark(), thanks dngor!
Added the noxsqueue option to benchmark()
Added the noasserts option to benchmark()
Automatically enable noxsqueue option if we cannot load POE::XS::Queue::Array, saving time
Bump Test::More version requirement because some people reported failures with note()
Fixed bug in SubProcess where it crashed on old POEs that didn't load IO::Handle
More documentation additions/tweaks
* 0.02
Added the Analyzer module ( and dump YAML files, yay! )
A lot of minor changes+tweaks to get a better dump format
* 0.01
initial release
diff --git a/lib/POE/Devel/Benchmarker.pm b/lib/POE/Devel/Benchmarker.pm
index 9ae396d..4ff2c8b 100644
--- a/lib/POE/Devel/Benchmarker.pm
+++ b/lib/POE/Devel/Benchmarker.pm
@@ -1,888 +1,920 @@
# Declare our package
package POE::Devel::Benchmarker;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.05';
# auto-export the only sub we have
use base qw( Exporter );
our @EXPORT = qw( benchmark );
+# we need hires times
+use Time::HiRes qw( time );
+
# Import what we need from the POE namespace
use POE qw( Session Filter::Line Wheel::Run );
use base 'POE::Session::AttributeBased';
-# we need hires times
-use Time::HiRes qw( time );
-
# load comparison stuff
use version;
# use the power of YAML
use YAML::Tiny;
# Load our stuff
use POE::Devel::Benchmarker::GetInstalledLoops;
use POE::Devel::Benchmarker::Utils qw( poeloop2load knownloops generateTestfile );
use POE::Devel::Benchmarker::Analyzer;
# Actually run the tests!
sub benchmark {
my $options = shift;
# set default options
my $lite_tests = 1;
my $quiet_mode = 0;
my $forceloops = undef; # default to autoprobe all
my $forcepoe = undef; # default to all found POE versions in poedists/
my $forcenoxsqueue = 0; # default to try and load it
my $forcenoasserts = 0; # default is to run it
my $freshstart = 0; # always resume where we left off
# process our options
if ( defined $options and ref $options and ref( $options ) eq 'HASH' ) {
# process YES for freshstart
if ( exists $options->{'freshstart'} ) {
if ( $options->{'freshstart'} ) {
$freshstart = 1;
}
+ delete $options->{'freshstart'};
}
# process NO for XS::Queue::Array
if ( exists $options->{'noxsqueue'} ) {
if ( $options->{'noxsqueue'} ) {
$forcenoxsqueue = 1;
}
+ delete $options->{'noxsqueue'};
}
# process NO for ASSERT
if ( exists $options->{'noasserts'} ) {
if ( $options->{'noasserts'} ) {
$forcenoasserts = 1;
}
+ delete $options->{'noasserts'};
}
# process LITE tests
if ( exists $options->{'litetests'} ) {
if ( $options->{'litetests'} ) {
$lite_tests = 1;
} else {
$lite_tests = 0;
}
+ delete $options->{'litetests'};
}
# process quiet mode
if ( exists $options->{'quiet'} ) {
if ( $options->{'quiet'} ) {
$quiet_mode = 1;
} else {
$quiet_mode = 0;
}
+ delete $options->{'quiet'};
}
# process forceloops
if ( exists $options->{'loop'} and defined $options->{'loop'} ) {
if ( ! ref $options->{'loop'} ) {
# split it via CSV
$forceloops = [ split( /,/, $options->{'loop'} ) ];
foreach ( @$forceloops ) {
$_ =~ s/^\s+//; $_ =~ s/\s+$//;
}
} else {
# treat it as array
$forceloops = $options->{'loop'};
}
# check for !loop modules
my @noloops;
foreach my $l ( @$forceloops ) {
if ( $l =~ /^\!/ ) {
push( @noloops, substr( $l, 1 ) );
}
}
if ( scalar @noloops ) {
# replace the forceloops with ALL known, then subtract noloops from it
my %bad;
@bad{@noloops} = () x @noloops;
@$forceloops = grep { !exists $bad{$_} } @{ knownloops() };
}
+
+ delete $options->{'loop'};
}
# process the poe versions
if ( exists $options->{'poe'} and defined $options->{'poe'} ) {
if ( ! ref $options->{'poe'} ) {
# split it via CSV
$forcepoe = [ split( /,/, $options->{'poe'} ) ];
foreach ( @$forcepoe ) {
$_ =~ s/^\s+//; $_ =~ s/\s+$//;
}
} else {
# treat it as array
$forcepoe = $options->{'poe'};
}
+
+ delete $options->{'poe'};
+ }
+
+ # unknown options!
+ if ( scalar keys %$options ) {
+ warn "[BENCHMARKER] Unknown options present in arguments: " . keys %$options;
}
}
# do some sanity checks
if ( ! -d 'poedists' ) {
die "The 'poedists' directory is not found in the working directory!";
}
if ( ! -d 'results' ) {
die "The 'results' directory is not found in the working directory!";
}
if ( ! $quiet_mode ) {
print "[BENCHMARKER] Starting up...\n";
}
# Create our session
POE::Session->create(
__PACKAGE__->inline_states(),
'heap' => {
# misc stuff
'quiet_mode' => $quiet_mode,
# override our testing behavior
'lite_tests' => $lite_tests,
'forceloops' => $forceloops,
'forcepoe' => $forcepoe,
'forcenoxsqueue' => $forcenoxsqueue,
'forcenoasserts' => $forcenoasserts,
'freshstart' => $freshstart,
},
);
# Fire 'er up!
POE::Kernel->run();
return;
}
# Starts up our session
sub _start : State {
# okay, get all the dists we can!
my @versions;
if ( opendir( DISTS, 'poedists' ) ) {
foreach my $d ( readdir( DISTS ) ) {
if ( $d =~ /^POE\-(.+)$/ and $d !~ /\.tar\.gz$/ ) {
# FIXME skip POE < 0.13 because I can't get it to work
my $ver = version->new( $1 );
- if ( $ver > v0.12 ) {
+ if ( $ver > version->new( '0.12' ) ) {
push( @versions, $ver );
}
}
}
closedir( DISTS ) or die $!;
} else {
print "[BENCHMARKER] Unable to open 'poedists' for reading: $!\n";
return;
}
# should we munge the versions list?
if ( defined $_[HEAP]->{'forcepoe'} ) {
# check for !poe versions
my @nopoe;
foreach my $p ( @{ $_[HEAP]->{'forcepoe'} } ) {
if ( $p =~ /^\!/ ) {
push( @nopoe, substr( $p, 1 ) );
}
}
if ( scalar @nopoe ) {
# remove the nopoe versions from the found
my %bad;
@bad{@nopoe} = () x @nopoe;
@versions = grep { !exists $bad{$_->stringify} } @versions;
} else {
# make sure the @versions contains only what we specified
my %good;
@good{ @{ $_[HEAP]->{'forcepoe'} } } = () x @{ $_[HEAP]->{'forcepoe'} };
@versions = grep { exists $good{$_->stringify} } @versions;
}
}
# sanity
if ( ! scalar @versions ) {
print "[BENCHMARKER] Unable to find any POE version in the 'poedists' directory!\n";
return;
}
# set our alias
$_[KERNEL]->alias_set( 'Benchmarker' );
# sanely handle some signals
$_[KERNEL]->sig( 'INT', 'handle_kill' );
$_[KERNEL]->sig( 'TERM', 'handle_kill' );
# okay, go through all the dists in version order
@versions = sort { $a <=> $b } @versions;
# Store the versions in our heap
$_[HEAP]->{'VERSIONS'} = \@versions;
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Detected available POE versions -> " . join( " ", @versions ) . "\n";
}
# First of all, we need to find out what loop libraries are installed
getPOEloops( $_[HEAP]->{'quiet_mode'}, $_[HEAP]->{'forceloops'} );
return;
}
sub _stop : State {
# tell the wheel to kill itself
if ( defined $_[HEAP]->{'WHEEL'} ) {
$_[HEAP]->{'WHEEL'}->kill( 9 );
undef $_[HEAP]->{'WHEEL'};
}
if ( ! $_[HEAP]->{'quiet_mode'} ) {
- print "[BENCHMARKER] Shutting down...\n";
+ print "\n[BENCHMARKER] Shutting down...\n";
}
return;
}
# misc POE handlers
sub _child : State {
return;
}
sub handle_kill : State {
return;
}
# we received list of loops from GetInstalledLoops
sub found_loops : State {
$_[HEAP]->{'installed_loops'} = [ sort { $a cmp $b } @{ $_[ARG0] } ];
# sanity check
if ( scalar @{ $_[HEAP]->{'installed_loops'} } == 0 ) {
print "[BENCHMARKER] Detected no available POE::Loop, check your configuration?!?\n";
return;
}
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Detected available POE::Loops -> " . join( " ", @{ $_[HEAP]->{'installed_loops'} } ) . "\n";
}
# Okay, do we have XS::Queue installed?
if ( ! $_[HEAP]->{'forcenoxsqueue'} ) {
eval { require POE::XS::Queue::Array };
if ( $@ ) {
$_[HEAP]->{'forcenoxsqueue'} = 1;
}
}
# Fire up the analyzer
initAnalyzer( $_[HEAP]->{'quiet_mode'} );
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Starting the benchmarks!" .
( $_[HEAP]->{'forcenoxsqueue'} ? ' Skipping XS::Queue Tests!' : '' ) .
( $_[HEAP]->{'forcenoasserts'} ? ' Skipping ASSERT Tests!' : '' ) .
"\n";
}
# start the benchmark!
$_[KERNEL]->yield( 'run_benchmark' );
return;
}
# Runs one benchmark
sub run_benchmark : State {
# Grab the version from the top of the array
$_[HEAP]->{'current_version'} = shift @{ $_[HEAP]->{'VERSIONS'} };
# did we run out of versions?
if ( ! defined $_[HEAP]->{'current_version'} ) {
# We're done, let POE die...
$_[KERNEL]->alias_remove( 'Benchmarker' );
} else {
$_[HEAP]->{'loops'} = [ @{ $_[HEAP]->{'installed_loops'} } ];
# okay, fire off the first loop
$_[KERNEL]->yield( 'bench_loop' );
}
return;
}
# runs one loop
sub bench_loop : State {
# select our current loop
$_[HEAP]->{'current_loop'} = shift @{ $_[HEAP]->{'loops'} };
# are we done with all loops?
if ( ! defined $_[HEAP]->{'current_loop'} ) {
# yay, go back to the main handler
$_[KERNEL]->yield( 'run_benchmark' );
} else {
# Start the assert test
if ( $_[HEAP]->{'forcenoasserts'} ) {
$_[HEAP]->{'assertions'} = [ qw( 0 ) ];
} else {
$_[HEAP]->{'assertions'} = [ qw( 0 1 ) ];
}
$_[KERNEL]->yield( 'bench_asserts' );
}
return;
}
# runs an assertion
sub bench_asserts : State {
# select our current assert state
$_[HEAP]->{'current_assertions'} = shift @{ $_[HEAP]->{'assertions'} };
# are we done?
if ( ! defined $_[HEAP]->{'current_assertions'} ) {
# yay, go back to the loop handler
$_[KERNEL]->yield( 'bench_loop' );
} else {
# Start the xsqueue test
if ( $_[HEAP]->{'forcenoxsqueue'} ) {
$_[HEAP]->{'noxsqueue'} = [ qw( 1 ) ];
} else {
$_[HEAP]->{'noxsqueue'} = [ qw( 0 1 ) ];
}
$_[KERNEL]->yield( 'bench_xsqueue' );
}
return;
}
# runs test with or without xsqueue
sub bench_xsqueue : State {
# select our current noxsqueue state
$_[HEAP]->{'current_noxsqueue'} = shift @{ $_[HEAP]->{'noxsqueue'} };
# are we done?
if ( ! defined $_[HEAP]->{'current_noxsqueue'} ) {
# yay, go back to the assert handler
$_[KERNEL]->yield( 'bench_asserts' );
} else {
# do some careful analysis
$_[KERNEL]->yield( 'bench_checkprevioustest' );
}
return;
}
# Checks to see if this test was run in the past
sub bench_checkprevioustest : State {
# okay, do we need to check and see if we already did this test?
if ( ! $_[HEAP]->{'freshstart'} ) {
# determine the file used
my $file = generateTestfile( $_[HEAP] );
# does it exist?
if ( -e "results/$file.yml" and -f _ and -s _ ) {
# okay, sanity check it
my $yaml = YAML::Tiny->read( "results/$file.yml" );
if ( defined $yaml ) {
# inrospect it!
my $isvalid = 0;
eval {
# simple sanity check: the "x_bench" param is at the end of the YML, so if it loads fine we know it's there
if ( exists $yaml->[0]->{'x_bench'} ) {
# version must at least match us
$isvalid = ( $yaml->[0]->{'x_bench'} eq $POE::Devel::Benchmarker::VERSION ? 1 : 0 );
} else {
$isvalid = undef;
}
};
if ( $isvalid ) {
# yay, this test is A-OK!
$_[KERNEL]->yield( 'bench_xsqueue' );
return;
} else {
# was it truncated?
if ( ! defined $isvalid ) {
if ( ! $_[HEAP]->{'quiet_mode'} ) {
- print "[BENCHMARKER] YAML file($file) from previous test was corrupt!\n";
+ print "\n[BENCHMARKER] YAML file($file) from previous test was corrupt!\n";
}
}
}
} else {
if ( ! $_[HEAP]->{'quiet_mode'} ) {
- print "[BENCHMARKER] Unable to load YAML file($file) from previous test run: " . YAML::Tiny->errstr . "\n";
+ print "\n[BENCHMARKER] Unable to load YAML file($file) from previous test run: " . YAML::Tiny->errstr . "\n";
}
}
}
}
# could not find previous file or FRESHSTART, proceed normally
$_[KERNEL]->yield( 'create_subprocess' );
return;
}
# actually runs the subprocess
sub create_subprocess : State {
# Okay, start testing this specific combo!
if ( ! $_[HEAP]->{'quiet_mode'} ) {
- print "Testing " . generateTestfile( $_[HEAP] ) . "\n";
+ print "\n Testing " . generateTestfile( $_[HEAP] ) . "...";
}
# save the starttime
$_[HEAP]->{'current_starttime'} = time();
$_[HEAP]->{'current_starttimes'} = [ times() ];
# Okay, create the wheel::run to handle this
my $looploader = poeloop2load( $_[HEAP]->{'current_loop'} );
$_[HEAP]->{'WHEEL'} = POE::Wheel::Run->new(
'Program' => $^X,
'ProgramArgs' => [ '-Ipoedists/POE-' . $_[HEAP]->{'current_version'},
'-Ipoedists/POE-' . $_[HEAP]->{'current_version'} . '/lib',
( defined $looploader ? "-M$looploader" : () ),
'-MPOE::Devel::Benchmarker::SubProcess',
'-e',
'POE::Devel::Benchmarker::SubProcess::benchmark',
$_[HEAP]->{'current_loop'},
$_[HEAP]->{'current_assertions'},
$_[HEAP]->{'lite_tests'},
$_[HEAP]->{'current_noxsqueue'},
],
# Kill off existing FD's
'CloseOnCall' => 1,
# setup our data handlers
'StdoutEvent' => 'Got_STDOUT',
'StderrEvent' => 'Got_STDERR',
# the error handler
'ErrorEvent' => 'Got_ERROR',
'CloseEvent' => 'Got_CLOSED',
# set our filters
'StderrFilter' => POE::Filter::Line->new(),
'StdoutFilter' => POE::Filter::Line->new(),
);
if ( ! defined $_[HEAP]->{'WHEEL'} ) {
die 'Unable to create a new wheel!';
} else {
# smart CHLD handling
if ( $_[KERNEL]->can( "sig_child" ) ) {
$_[KERNEL]->sig_child( $_[HEAP]->{'WHEEL'}->PID => 'Got_CHLD' );
} else {
$_[KERNEL]->sig( 'CHLD', 'Got_CHLD' );
}
}
# setup our data we received from the subprocess
$_[HEAP]->{'current_data'} = '';
# Okay, we timeout this test after some time for sanity
$_[HEAP]->{'test_timedout'} = 0;
if ( $_[HEAP]->{'lite_tests'} ) {
- # on my core2duo 1.2ghz laptop, running Gtk+LITE+assert+noxsqueue takes approx 45s
- $_[HEAP]->{'TIMER'} = $_[KERNEL]->delay_set( 'test_timedout' => 60 * 2 );
+ # 5min timeout is 5x my average runs on a 1.2ghz core2duo so it should be good enough
+ $_[HEAP]->{'TIMER'} = $_[KERNEL]->delay_set( 'test_timedout' => 60 * 5 );
} else {
- # on my core2duo 1.2ghz laptop, running Gtk+HEAVY+assert+noxsqueue takes all day long :(
- $_[HEAP]->{'TIMER'} = $_[KERNEL]->delay_set( 'test_timedout' => 60 * 15 );
+ # 30min timeout is 2x my average runs on a 1.2ghz core2duo so it should be good enough
+ $_[HEAP]->{'TIMER'} = $_[KERNEL]->delay_set( 'test_timedout' => 60 * 30 );
}
return;
}
# Got a CHLD event!
sub Got_CHLD : State {
$_[KERNEL]->sig_handled();
return;
}
# Handles child STDERR output
sub Got_STDERR : State {
my $input = $_[ARG0];
# skip empty lines
if ( $input ne '' ) {
# save it!
$_[HEAP]->{'current_data'} .= '!STDERR: ' . $input . "\n";
}
return;
}
# Handles child STDOUT output
sub Got_STDOUT : State {
my $input = $_[ARG0];
# save it!
$_[HEAP]->{'current_data'} .= $input . "\n";
return;
}
# Handles child error
sub Got_ERROR : State {
# Copied from POE::Wheel::Run manpage
my ( $operation, $errnum, $errstr ) = @_[ ARG0 .. ARG2 ];
# ignore exit 0 errors
if ( $errnum != 0 ) {
- print "[BENCHMARKER] Wheel::Run got an $operation error $errnum: $errstr\n";
+ print "\n[BENCHMARKER] Wheel::Run got an $operation error $errnum: $errstr\n";
}
return;
}
# Handles child DIE'ing
sub Got_CLOSED : State {
# Get rid of the wheel
undef $_[HEAP]->{'WHEEL'};
# get rid of the delay
$_[KERNEL]->alarm_remove( $_[HEAP]->{'TIMER'} );
undef $_[HEAP]->{'TIMER'};
# wrap up this test
$_[KERNEL]->yield( 'wrapup_test' );
return;
}
# a test timed out, unfortunately!
sub test_timedout : State {
# tell the wheel to kill itself
$_[HEAP]->{'WHEEL'}->kill( 9 );
undef $_[HEAP]->{'WHEEL'};
if ( ! $_[HEAP]->{'quiet_mode'} ) {
- print "[BENCHMARKER] Test Timed Out!\n";
+ print " Test Timed Out!";
}
$_[HEAP]->{'test_timedout'} = 1;
# wrap up this test
$_[KERNEL]->yield( 'wrapup_test' );
return;
}
# finalizes a test
sub wrapup_test : State {
# we're done with this benchmark!
$_[HEAP]->{'current_endtime'} = time();
$_[HEAP]->{'current_endtimes'} = [ times() ];
# store the data
my $file = generateTestfile( $_[HEAP] );
if ( open( my $fh, '>', "results/$file" ) ) {
print $fh "STARTTIME: " . $_[HEAP]->{'current_starttime'} . " -> TIMES " . join( " ", @{ $_[HEAP]->{'current_starttimes'} } ) . "\n";
print $fh "$file\n";
print $fh $_[HEAP]->{'current_data'} . "\n";
if ( $_[HEAP]->{'test_timedout'} ) {
print $fh "\nTEST TERMINATED DUE TO TIMEOUT\n";
}
print $fh "ENDTIME: " . $_[HEAP]->{'current_endtime'} . " -> TIMES " . join( " ", @{ $_[HEAP]->{'current_endtimes'} } ) . "\n";
close( $fh ) or die $!;
} else {
- print "[BENCHMARKER] Unable to open results/$file for writing -> $!\n";
+ print "\n[BENCHMARKER] Unable to open results/$file for writing -> $!\n";
}
# Send the data to the Analyzer to process
$_[KERNEL]->post( 'Benchmarker::Analyzer', 'analyze', {
'poe' => {
'v' => $_[HEAP]->{'current_version'}->stringify, # YAML::Tiny doesn't like version objects :(
'loop' => 'POE::Loop::' . $_[HEAP]->{'current_loop'},
},
't' => {
's_ts' => $_[HEAP]->{'current_starttime'},
'e_ts' => $_[HEAP]->{'current_endtime'},
'd' => $_[HEAP]->{'current_endtime'} - $_[HEAP]->{'current_starttime'},
's_t' => [ @{ $_[HEAP]->{'current_starttimes'} } ],
'e_t' => [ @{ $_[HEAP]->{'current_endtimes'} } ],
},
'raw' => $_[HEAP]->{'current_data'},
'test' => $file,
'x_bench' => $POE::Devel::Benchmarker::VERSION,
( $_[HEAP]->{'test_timedout'} ? ( 'timedout' => 1 ) : () ),
( $_[HEAP]->{'lite_tests'} ? ( 'litetests' => 1 ) : () ),
( $_[HEAP]->{'current_assertions'} ? ( 'asserts' => 1 ) : () ),
( $_[HEAP]->{'current_noxsqueue'} ? ( 'noxsqueue' => 1 ) : () ),
} );
# process the next test
$_[KERNEL]->yield( 'bench_xsqueue' );
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker - Benchmarking POE's performance ( acts more like a smoker )
=head1 SYNOPSIS
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker -e 'benchmark()'
=head1 ABSTRACT
This package of tools is designed to benchmark POE's performace across different
configurations. The current "tests" are:
=over 4
-=item posts
+=item Events
-This tests how long it takes to post() N times
+posts: This tests how long it takes to post() N times
-This tests how long it took to dispatch/deliver all the posts enqueued in the post() test
+dispatches: This tests how long it took to dispatch/deliver all the posts enqueued in the "posts" test
-This tests how long it took to yield() between 2 states for N times
+single_posts: This tests how long it took to yield() between 2 states for N times
-=item calls
+calls: This tests how long it took to call() N times
-This tests how long it took to call() N times
+=item Alarms
-=item alarms
+alarms: This tests how long it took to add N alarms via alarm(), overwriting each other
-This tests how long it took to add N alarms via alarm(), overwriting each other
+alarm_adds: This tests how long it took to add N alarms via alarm_add()
-This tests how long it took to add N alarms via alarm_add() and how long it took to delete them all
+alarm_clears: This tests how long it took to clear all alarms set in the "alarm_adds" test
NOTE: alarm_add is not available on all versions of POE!
-=item sessions
+=item Sessions
-This tests how long it took to create N sessions, and how long it took to destroy them all
+session_creates: This tests how long it took to create N sessions
-=item filehandles
+session_destroys: This tests how long it took to destroy all sessions created in the "session_creates" test
-This tests how long it took to toggle select_read N times on STDIN and a real filehandle via open()
+=item Filehandles
-This tests how long it took to toggle select_write N times on STDIN and a real filehandle via open()
+select_read_STDIN: This tests how long it took to toggle select_read N times on STDIN
+
+select_write_STDIN: This tests how long it took to toggle select_write N times on STDIN
+
+select_read_MYFH: This tests how long it took to toggle select_read N times on a real filehandle
+
+select_write_MYFH: This tests how long it took to toggle select_write N times on a real filehandle
+
+NOTE: The MYFH tests don't include the time it took to open()/close() the file :)
+
+=item Sockets
+
+socket_connects: This tests how long it took to connect+disconnect to a SocketFactory server via localhost
+
+socket_stream: This tests how long it took to send N chunks of data in a "ping-pong" fashion between the server and client
=item POE startup time
-This tests how long it took to start + close N instances of a "virgin" POE without any sessions/etc
+startups: This tests how long it took to start + close N instances of POE+Loop without any sessions/etc via system()
=item POE Loops
This is actually a "super" test where all of the specific tests is ran against various POE::Loop::XYZ/FOO for comparison
=item POE Assertions
This is actually a "super" test where all of the specific tests is ran against POE with/without assertions enabled
+NOTE: Not all versions of POE support assertions!
+
=item POE::XS::Queue::Array
This is actually a "super" test where all of the specific tests is ran against POE with XS goodness enabled/disabled
+NOTE: Not all versions of POE support XS::Queue::Array!
+
=back
=head1 DESCRIPTION
This module is poorly documented now. Please give me some time to properly document it over time :)
=head2 INSTALLATION
Here's a simple outline to get you up to speed quickly. ( and smoking! )
=over 4
=item Install CPAN package + dependencies
Download+install the POE::Devel::Benchmarker package from CPAN
apoc@apoc-x300:~$ cpanp -i POE::Devel::Benchmarker
=item Setup initial directories
Go anywhere, and create the "parent" directory where you'll be storing test results + stuff. For this example,
I have chosen to use ~/poe-benchmarker:
apoc@apoc-x300:~$ mkdir poe-benchmarker
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ mkdir poedists results images
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker::GetPOEdists -e 'getPOEdists( 1 )'
( go get a coffee while it downloads if you're on a slow link, ha! )
=item Let 'er rip!
At this point you can start running the benchmark!
NOTE: the Benchmarker expects everything to be in the "local" directory!
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker -e 'benchmark()'
( go sleep or something, this will take a while! )
=back
=head2 BENCHMARKING
On startup the Benchmarker will look in the "poedists" directory and load all the distributions it sees untarred there. Once
that is done it will begin autoprobing for available POE::Loop packages. Once it determines what's available, it will begin
the benchmarks.
As the Benchmarker goes through the combinations of POE + Eventloop + Assertions + XS::Queue it will dump data into
the results directory. The Analyzer module also dumps YAML output in the same place, with the suffix of ".yml"
This module exposes only one subroutine, the benchmark() one. You can pass a hashref to it to set various options. Here is
a list of the valid options:
=over 4
=item freshstart => boolean
This will tell the Benchmarker to ignore any previous test runs stored in the 'results' directory.
benchmark( { freshstart => 1 } );
default: false
=item noxsqueue => boolean
This will tell the Benchmarker to force the unavailability of POE::XS::Queue::Array and skip those tests.
NOTE: The Benchmarker will set this automatically if it cannot load the module!
benchmark( { noxsqueue => 1 } );
default: false
=item noasserts => boolean
This will tell the Benchmarker to not run the ASSERT tests.
benchmark( { noasserts => 1 } );
default: false
=item litetests => boolean
This enables the "lite" tests which will not take up too much time.
benchmark( { litetests => 0 } );
default: true
=item quiet => boolean
This enables quiet mode which will not print anything to the console except for errors.
benchmark( { 'quiet' => 1 } );
default: false
=item loop => csv list or array
This overrides the built-in loop detection algorithm which searches for all known loops.
There is some "magic" here where you can put a negative sign in front of a loop and we will NOT run that.
NOTE: Capitalization is important!
benchmark( { 'loop' => 'IO_Poll,Select' } ); # runs only IO::Poll and Select
benchmark( { 'loop' => [ qw( Tk Gtk ) ] } ); # runs only Tk and Gtk
benchmark( { 'loop' => '-Tk' } ); # runs all available loops EXCEPT for TK
Known loops: Event_Lib EV Glib Prima Gtk Kqueue Tk Select IO_Poll
=item poe => csv list or array
This overrides the built-in POE version detection algorithm which pulls the POE versions from the 'poedists' directory.
There is some "magic" here where you can put a negative sign in front of a version and we will NOT run that.
NOTE: The Benchmarker will ignore versions that wasn't found in the directory!
benchmark( { 'poe' => '0.35,1.003' } ); # runs on 0.35 and 1.003
benchmark( { 'poe' => [ qw( 0.3009 0.12 ) ] } ); # runs on 0.3009 and 0.12
benchmark( { 'poe' => '-0.35' } ); # runs ALL tests except 0.35
=back
=head2 ANALYZING RESULTS
Please look at the pretty charts generated by the L<POE::Devel::Benchmarker::Imager> module.
=head1 EXPORT
Automatically exports the benchmark() subroutine.
=head1 TODO
=over 4
=item Perl version smoking
We should be able to run the benchmark over different Perl versions. This would require some fiddling with our
layout + logic. It's not that urgent because the workaround is to simply execute the benchmarker under a different
perl binary. It's smart enough to use $^X to be consistent across tests/subprocesses :)
=item Select the EV backend
<Khisanth> and if you are benchmarking, try it with POE using EV with EV using Glib? :P
<Apocalypse> I'm not sure how to configure the EV "backend" yet
<Apocalypse> too much docs for me to read hah
<Khisanth> Apocalypse: use EV::Glib; use Glib; use POE; :)
=item Be smarter in smoking timeouts
Currently we depend on the litetests option and hardcode some values including the timeout. If your machine is incredibly
slow, there's a chance that it could timeout unnecessarily. Please look at the outputs and check to see if there are unusual
failures, and inform me.
Also, some loops perform badly and take almost forever! /me glares at Gtk...
=item More benchmarks!
As usual, me and the crowd in #poe have plenty of ideas for tests. We'll be adding them over time, but if you have an idea please
drop me a line and let me know!
dngor said there was some benchmarks in the POE svn under trunk/queue...
-I want a bench that actually tests socket traffic - stream 10MB of traffic over localhost, and time it?
+Tapout contributed a script that tests HTTP performance, let's see if it deserves to be in the suite :)
-LotR and Tapout contributed some samples, let's see if I can integrate them...
+I added the preliminary socket tests, we definitely should expand it seeing how many people use POE for networking...
=item Add SQLite/DBI/etc support to the Analyzer
It would be nice if we could have a local SQLite db to dump our stats into. This would make arbitrary reports much easier than
loading raw YAML files and trying to make sense of them, ha! Also, this means somebody can do the smoking and send the SQLite
db to another person to generate the graphs, cool!
=item Kqueue loop support
As I don't have access to a *BSD box, I cannot really test this. Furthermore, it isn't clear on how I can force/unload this
module from POE...
=item Wx loop support
I have Wx installed, but it doesn't work. Obviously I don't know how to use Wx ;)
If you have experience, please drop me a line on how to do the "right" thing to get Wx loaded under POE. Here's the error:
Can't call method "MainLoop" on an undefined value at /usr/local/share/perl/5.8.8/POE/Loop/Wx.pm line 91.
=item XS::Loop support
The POE::XS::Loop::* modules theoretically could be tested too. However, they will only work in POE >= 1.003! This renders
the concept somewhat moot. Maybe, after POE has progressed some versions we can implement this...
=back
=head1 SEE ALSO
L<POE>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
BIG THANKS goes to Rocco Caputo E<lt>rcaputo@cpan.orgE<gt> for the first benchmarks!
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/Analyzer.pm b/lib/POE/Devel/Benchmarker/Analyzer.pm
index 76352f0..6091880 100644
--- a/lib/POE/Devel/Benchmarker/Analyzer.pm
+++ b/lib/POE/Devel/Benchmarker/Analyzer.pm
@@ -1,448 +1,440 @@
# Declare our package
package POE::Devel::Benchmarker::Analyzer;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.05';
# auto-export the only sub we have
use base qw( Exporter );
our @EXPORT = qw( initAnalyzer );
# Import what we need from the POE namespace
use POE qw( Session );
use base 'POE::Session::AttributeBased';
# use the power of YAML
use YAML::Tiny qw( Dump );
# Load the utils
use POE::Devel::Benchmarker::Utils qw( beautify_times );
# fires up the engine
sub initAnalyzer {
my $quiet_mode = shift;
# create our session!
POE::Session->create(
__PACKAGE__->inline_states(),
'heap' => {
'quiet_mode' => $quiet_mode,
},
);
}
# Starts up our session
sub _start : State {
# set our alias
$_[KERNEL]->alias_set( 'Benchmarker::Analyzer' );
- if ( ! $_[HEAP]->{'quiet_mode'} ) {
- print "[ANALYZER] Starting up...\n";
- }
-
return;
}
sub _stop : State {
- if ( ! $_[HEAP]->{'quiet_mode'} ) {
- print "[ANALYZER] Shutting down...\n";
- }
-
return;
}
sub _child : State {
return;
}
sub analyze : State {
# get the data
my $test = $_[ARG0];
# clean up the times() stuff
$test->{'t'}->{'t'} = beautify_times(
join( " ", @{ delete $test->{'t'}->{'s_t'} } ) .
" " .
join( " ", @{ delete $test->{'t'}->{'e_t'} } )
);
- # setup the perl version
- $test->{'perl'}->{'v'} = sprintf( "%vd", $^V );
-
# Okay, break it down into our data struct
$test->{'metrics'} = {};
my $d = $test->{'metrics'};
my @unknown;
foreach my $l ( split( /(?:\n|\r)/, $test->{'raw'} ) ) {
# skip empty lines
if ( $l eq '' ) { next }
# usual test benchmark output
# 10 startups in 0.885 seconds ( 11.302 per second)
# 10000 posts in 0.497 seconds ( 20101.112 per second)
if ( $l =~ /^\s+\d+\s+(\w+)\s+in\s+([\d\.]+)\s+seconds\s+\(\s+([\d\.]+)\s+per\s+second\)$/ ) {
$d->{ $1 }->{'d'} = $2; # duration in seconds
$d->{ $1 }->{'i'} = $3; # iterations per second
# usual test benchmark times output
# startup times: 0.1 0 0 0 0.1 0 0.76 0.09
} elsif ( $l =~ /^(\w+)\s+times:\s+(.+)$/ ) {
$d->{ $1 }->{'t'} = beautify_times( $2 ); # the times hash
+ # usual test SKIP output
+ # SKIPPING br0ken $metric because ...
+ } elsif ( $l =~ /^SKIPPING\s+br0ken\s+(\w+)\s+because/ ) {
+ # nullify the data struct for that
+ $d->{ $1 }->{'d'} = undef;
+ $d->{ $1 }->{'t'} = undef;
+ $d->{ $1 }->{'i'} = undef;
+
# parse the memory footprint stuff
} elsif ( $l =~ /^pidinfo:\s+(.+)$/ ) {
# what should we analyze?
my $pidinfo = $1;
# VmPeak: 16172 kB
if ( $pidinfo =~ /^VmPeak:\s+(.+)$/ ) {
$test->{'pid'}->{'vmpeak'} = $1;
# voluntary_ctxt_switches: 10
} elsif ( $pidinfo =~ /^voluntary_ctxt_switches:\s+(.+)$/ ) {
$test->{'pid'}->{'vol_ctxt'} = $1;
# nonvoluntary_ctxt_switches: 1221
} elsif ( $pidinfo =~ /^nonvoluntary_ctxt_switches:\s+(.+)$/ ) {
$test->{'pid'}->{'nonvol_ctxt'} = $1;
} else {
# ignore the rest of the fluff
}
# parse the perl binary stuff
} elsif ( $l =~ /^perlconfig:\s+(.+)$/ ) {
# what should we analyze?
my $perlconfig = $1;
# ignore the fluff ( not needed now... )
# parse the CPU info
} elsif ( $l =~ /^cpuinfo:\s+(.+)$/ ) {
# what should we analyze?
my $cpuinfo = $1;
# FIXME if this is on a multiproc system, we will overwrite the data per processor ( harmless? )
# cpu MHz : 1201.000
if ( $cpuinfo =~ /^cpu\s+MHz\s+:\s+(.+)$/ ) {
$test->{'cpu'}->{'mhz'} = $1;
# model name : Intel(R) Core(TM)2 Duo CPU L7100 @ 1.20GHz
} elsif ( $cpuinfo =~ /^model\s+name\s+:\s+(.+)$/ ) {
$test->{'cpu'}->{'name'} = $1;
# bogomips : 2397.58
} elsif ( $cpuinfo =~ /^bogomips\s+:\s+(.+)$/ ) {
$test->{'cpu'}->{'bogo'} = $1;
} else {
# ignore the rest of the fluff
}
# data that we can safely throw away
} elsif ( $l eq 'Using NO Assertions!' or
$l eq 'Using FULL Assertions!' or
$l eq 'Using the LITE tests' or
$l eq 'Using the HEAVY tests' or
$l eq 'DISABLING POE::XS::Queue::Array' or
$l eq '!STDERR: Devel::Hide hides POE/XS/Queue/Array.pm' or
$l eq 'LETTING POE find POE::XS::Queue::Array' or
$l eq 'UNABLE TO GET /proc/self/status' or
$l eq 'UNABLE TO GET /proc/cpuinfo' or
$l eq '!STDERR: POE::Kernel\'s run() method was never called.' or # to ignore old POEs that threw this warning
$l eq 'TEST TERMINATED DUE TO TIMEOUT' ) {
# ignore them
# parse the perl binary stuff
- } elsif ( $l =~ /^Running\s+under\s+perl\s+binary:\s+(.+)$/ ) {
+ } elsif ( $l =~ /^Running\s+under\s+perl\s+binary:\s+\'([^\']+)\'\s+v([\d\.]+)$/ ) {
$test->{'perl'}->{'binary'} = $1;
+ # setup the perl version
+ $test->{'perl'}->{'v'} = $2;
+
# the master loop version ( what the POE::Loop::XYZ actually uses )
# Using loop: EV-3.49
} elsif ( $l =~ /^Using\s+master\s+loop:\s+(.+)$/ ) {
$test->{'poe'}->{'loop_m'} = $1;
# the real POE version that was loaded
# Using POE-1.001
} elsif ( $l =~ /^Using\s+POE-(.+)$/ ) {
$test->{'poe'}->{'v_real'} = $1;
# the various queue/loop modules we loaded
# POE is using: POE::XS::Queue::Array v0.005
# POE is using: POE::Queue v1.2328
# POE is using: POE::Loop::EV v0.06
} elsif ( $l =~ /^POE\s+is\s+using:\s+([^\s]+)\s+v(.+)$/ ) {
$test->{'poe'}->{'modules'}->{ $1 } = $2;
# get the uname info
# Running under machine: Linux apoc-x300 2.6.24-21-generic #1 SMP Tue Oct 21 23:43:45 UTC 2008 i686 GNU/Linux
} elsif ( $l =~ /^Running\s+under\s+machine:\s+(.+)$/ ) {
$test->{'uname'} = $1;
- # parse the SKIP tests
- # SKIPPING MYFH tests on broken loop: Event_Lib
- # SKIPPING STDIN tests on broken loop: Tk
- } elsif ( $l =~ /^SKIPPING\s+(\w+)\s+tests\s+on\s+broken/ ) {
- my $fh = $1;
-
- # nullify the data struct for that
- foreach my $type ( qw( select_read select_write ) ) {
- $d->{ $type . $fh }->{'d'} = undef;
- $d->{ $type . $fh }->{'t'} = undef;
- $d->{ $type . $fh }->{'i'} = undef;
- }
-
- # parse the FH/STDIN failures
- # filehandle select_read on STDIN FAILED: error
- # filehandle select_write on MYFH FAILED: foo
- } elsif ( $l =~ /^filehandle\s+(\w+)\s+on\s+(\w+)\s+FAILED:/ ) {
- my( $mode, $type ) = ( $1, $2 );
-
- # nullify the data struct for that
- $d->{ $mode . $type }->{'d'} = undef;
- $d->{ $mode . $type }->{'t'} = undef;
- $d->{ $mode . $type }->{'i'} = undef;
-
- # parse the alarm_add skip
- # alarm_add NOT SUPPORTED on this version of POE, skipping alarm_adds/alarm_clears tests!
- } elsif ( $l =~ /^alarm_add\s+NOT\s+SUPPORTED\s+on/ ) {
- # nullify the data struct for that
- foreach my $type ( qw( alarm_adds alarm_clears ) ) {
- $d->{ $type }->{'d'} = undef;
- $d->{ $type }->{'t'} = undef;
- $d->{ $type }->{'i'} = undef;
- }
-
# parse any STDERR output
# !STDERR: unable to foo
} elsif ( $l =~ /^\!STDERR:\s+(.+)$/ ) {
push( @{ $test->{'stderr'} }, $1 );
} else {
# unknown line :(
push( @unknown, $l );
}
}
# Get rid of the rawdata
delete $test->{'raw'};
# Dump the unknowns
if ( @unknown ) {
print "[ANALYZER] Unknown output from benchmark -> " . Dump( \@unknown );
}
# Dump the data struct we have to the file.yml
my $yaml_file = 'results/' . delete $test->{'test'};
$yaml_file .= '.yml';
my $ret = open( my $fh, '>', $yaml_file );
if ( defined $ret ) {
print $fh Dump( $test );
if ( ! close( $fh ) ) {
print "[ANALYZER] Unable to close $yaml_file -> " . $! . "\n";
}
} else {
print "[ANALYZER] Unable to open $yaml_file for writing -> " . $! . "\n";
}
+ # now that we've dumped the stuff, we can do some sanity checks
+
+ # the POE we "think" we loaded should match reality!
+ if ( exists $test->{'poe'}->{'v_real'} ) { # if this exists, then we successfully loaded POE
+ if ( $test->{'poe'}->{'v'} ne $test->{'poe'}->{'v_real'} ) {
+ print "\n[ANALYZER] The subprocess loaded a different version of POE than we thought -> $yaml_file\n";
+ }
+
+ # The loop we loaded should match what we wanted!
+ if ( exists $test->{'poe'}->{'modules'} ) {
+ if ( ! exists $test->{'poe'}->{'modules'}->{ $test->{'poe'}->{'loop'} } ) {
+ print "\n[ANALYZER] The subprocess loaded a different Loop than we thought -> $yaml_file\n";
+ }
+ }
+ }
+
+ # the perl binary should be the same!
+ if ( exists $test->{'perl'} ) { # if this exists, we successfully fired up the app ( no compile error )
+ if ( $test->{'perl'}->{'binary'} ne $^X ) {
+ print "\n[ANALYZER] The subprocess booted up on a different perl binary -> $yaml_file\n";
+ }
+ if ( $test->{'perl'}->{'v'} ne sprintf( "%vd", $^V ) ) {
+ print "\n[ANALYZER] The subprocess booted up on a different perl version -> $yaml_file\n";
+ }
+ }
+
# all done!
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::Analyzer - Analyzes the output from the benchmarks
=head1 SYNOPSIS
Don't use this module directly. Please see L<POE::Devel::Benchmarker>
=head1 ABSTRACT
This package implements the guts of converting the raw data into a machine-readable format. Furthermore, it dumps the data
in YAML format.
=head1 DESCRIPTION
I promise you that once I've stabilized the YAML format I'll have it documented here :)
=head1 EXPORT
Automatically exports the initAnalyzer() sub
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
# sample test output ( from SubProcess v0.02 )
STARTTIME: 1229232743.49131 -> TIMES 0.24 0.01 11.2 0.32
POE-1.003-Select-LITE-assert-xsqueue
Using master loop: Select-BUILTIN
Using FULL Assertions!
Using the LITE tests
LETTING POE find POE::XS::Queue::Array
Using POE-1.003
POE is using: POE::Loop::Select v1.2355
POE is using: POE::XS::Queue::Array v0.005
POE is using: POE::Queue v1.2328
POE is using: POE::Loop::PerlSignals v1.2329
10 startups in 0.853 seconds ( 11.723 per second)
startups times: 0.09 0 0 0 0.09 0 0.73 0.11
10000 posts in 0.495 seconds ( 20211.935 per second)
posts times: 0.1 0 0.73 0.11 0.53 0.06 0.73 0.11
10000 dispatches in 1.113 seconds ( 8984.775 per second)
dispatches times: 0.53 0.06 0.73 0.11 1.64 0.06 0.73 0.11
10000 alarms in 1.017 seconds ( 9829.874 per second)
alarms times: 1.64 0.06 0.73 0.11 2.66 0.06 0.73 0.11
10000 alarm_adds in 0.523 seconds ( 19102.416 per second)
alarm_adds times: 2.66 0.06 0.73 0.11 3.18 0.06 0.73 0.11
10000 alarm_clears in 0.377 seconds ( 26540.332 per second)
alarm_clears times: 3.18 0.06 0.73 0.11 3.55 0.07 0.73 0.11
500 session_creates in 0.130 seconds ( 3858.918 per second)
session_creates times: 3.55 0.07 0.73 0.11 3.68 0.08 0.73 0.11
500 session_destroys in 0.172 seconds ( 2901.191 per second)
session_destroys times: 3.68 0.08 0.73 0.11 3.85 0.08 0.73 0.11
10000 select_read_STDIN in 1.823 seconds ( 5485.878 per second)
select_read_STDIN times: 3.85 0.08 0.73 0.11 5.66 0.08 0.73 0.11
10000 select_write_STDIN in 1.827 seconds ( 5472.283 per second)
select_write_STDIN times: 5.66 0.08 0.73 0.11 7.47 0.08 0.73 0.11
10000 select_read_MYFH in 1.662 seconds ( 6016.387 per second)
select_read_MYFH times: 7.47 0.08 0.73 0.11 9.12 0.1 0.73 0.11
10000 select_write_MYFH in 1.704 seconds ( 5868.537 per second)
select_write_MYFH times: 9.12 0.1 0.73 0.11 10.78 0.11 0.73 0.11
10000 calls in 0.222 seconds ( 45038.974 per second)
calls times: 10.78 0.11 0.73 0.11 11 0.11 0.73 0.11
10000 single_posts in 1.999 seconds ( 5003.473 per second)
single_posts times: 11 0.11 0.73 0.11 12.86 0.22 0.73 0.11
pidinfo: Name: perl
pidinfo: State: R (running)
pidinfo: Tgid: 16643
pidinfo: Pid: 16643
pidinfo: PPid: 16600
pidinfo: TracerPid: 0
pidinfo: Uid: 1000 1000 1000 1000
pidinfo: Gid: 1000 1000 1000 1000
pidinfo: FDSize: 32
pidinfo: Groups: 4 20 24 25 29 30 44 46 107 109 115 127 1000 1001
pidinfo: VmPeak: 14376 kB
pidinfo: VmSize: 14216 kB
pidinfo: VmLck: 0 kB
pidinfo: VmHWM: 11440 kB
pidinfo: VmRSS: 11292 kB
pidinfo: VmData: 9908 kB
pidinfo: VmStk: 84 kB
pidinfo: VmExe: 1044 kB
pidinfo: VmLib: 1872 kB
pidinfo: VmPTE: 24 kB
pidinfo: Threads: 1
pidinfo: SigQ: 0/16182
pidinfo: SigPnd: 0000000000000000
pidinfo: ShdPnd: 0000000000000000
pidinfo: SigBlk: 0000000000000000
pidinfo: SigIgn: 0000000000001000
pidinfo: SigCgt: 0000000180000000
pidinfo: CapInh: 0000000000000000
pidinfo: CapPrm: 0000000000000000
pidinfo: CapEff: 0000000000000000
pidinfo: Cpus_allowed: 03
pidinfo: Mems_allowed: 1
pidinfo: voluntary_ctxt_switches: 10
pidinfo: nonvoluntary_ctxt_switches: 512
Running under perl binary: /usr/bin/perl
perlconfig: Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
perlconfig: Platform:
perlconfig: osname=linux, osvers=2.6.15.7, archname=i486-linux-gnu-thread-multi
perlconfig: uname='linux palmer 2.6.15.7 #1 smp thu sep 7 19:42:20 utc 2006 i686 gnulinux '
perlconfig: config_args='-Dusethreads -Duselargefiles -Dccflags=-DDEBIAN -Dcccdlflags=-fPIC -Darchname=i486-linux-gnu -Dprefix=/usr -Dprivlib=/usr/share/perl/5.8 -Darchlib=/usr/lib/perl/5.8 -Dvendorprefix=/usr -Dvendorlib=/usr/share/perl5 -Dvendorarch=/usr/lib/perl5 -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl/5.8.8 -Dsitearch=/usr/local/lib/perl/5.8.8 -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 -Dsiteman1dir=/usr/local/man/man1 -Dsiteman3dir=/usr/local/man/man3 -Dman1ext=1 -Dman3ext=3perl -Dpager=/usr/bin/sensible-pager -Uafs -Ud_csh -Ud_ualarm -Uusesfio -Uusenm -Duseshrplib -Dlibperl=libperl.so.5.8.8 -Dd_dosuid -des'
perlconfig: hint=recommended, useposix=true, d_sigaction=define
perlconfig: usethreads=define use5005threads=undef useithreads=define usemultiplicity=define
perlconfig: useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
perlconfig: use64bitint=undef use64bitall=undef uselongdouble=undef
perlconfig: usemymalloc=n, bincompat5005=undef
perlconfig: Compiler:
perlconfig: cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBIAN -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
perlconfig: optimize='-O2',
perlconfig: cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBIAN -fno-strict-aliasing -pipe -I/usr/local/include'
perlconfig: ccversion='', gccversion='4.2.3 20071123 (prerelease) (Ubuntu 4.2.2-3ubuntu4)', gccosandvers=''
perlconfig: intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
perlconfig: d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
perlconfig: ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
perlconfig: alignbytes=4, prototype=define
perlconfig: Linker and Libraries:
perlconfig: ld='cc', ldflags =' -L/usr/local/lib'
perlconfig: libpth=/usr/local/lib /lib /usr/lib
perlconfig: libs=-lgdbm -lgdbm_compat -ldb -ldl -lm -lpthread -lc -lcrypt
perlconfig: perllibs=-ldl -lm -lpthread -lc -lcrypt
perlconfig: libc=/lib/libc-2.6.1.so, so=so, useshrplib=true, libperl=libperl.so.5.8.8
perlconfig: gnulibc_version='2.6.1'
perlconfig: Dynamic Linking:
perlconfig: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
perlconfig: cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib'
Running under machine: Linux apoc-x300 2.6.24-21-generic #1 SMP Tue Oct 21 23:43:45 UTC 2008 i686 GNU/Linux
cpuinfo: processor : 0
cpuinfo: vendor_id : GenuineIntel
cpuinfo: cpu family : 6
cpuinfo: model : 15
cpuinfo: model name : Intel(R) Core(TM)2 Duo CPU L7100 @ 1.20GHz
cpuinfo: stepping : 11
cpuinfo: cpu MHz : 1201.000
cpuinfo: cache size : 4096 KB
cpuinfo: physical id : 0
cpuinfo: siblings : 2
cpuinfo: core id : 0
cpuinfo: cpu cores : 2
cpuinfo: fdiv_bug : no
cpuinfo: hlt_bug : no
cpuinfo: f00f_bug : no
cpuinfo: coma_bug : no
cpuinfo: fpu : yes
cpuinfo: fpu_exception : yes
cpuinfo: cpuid level : 10
cpuinfo: wp : yes
cpuinfo: flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc arch_perfmon pebs bts pni monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr lahf_lm ida
cpuinfo: bogomips : 2397.58
cpuinfo: clflush size : 64
cpuinfo: processor : 1
cpuinfo: vendor_id : GenuineIntel
cpuinfo: cpu family : 6
cpuinfo: model : 15
cpuinfo: model name : Intel(R) Core(TM)2 Duo CPU L7100 @ 1.20GHz
cpuinfo: stepping : 11
cpuinfo: cpu MHz : 1201.000
cpuinfo: cache size : 4096 KB
cpuinfo: physical id : 0
cpuinfo: siblings : 2
cpuinfo: core id : 1
cpuinfo: cpu cores : 2
cpuinfo: fdiv_bug : no
cpuinfo: hlt_bug : no
cpuinfo: f00f_bug : no
cpuinfo: coma_bug : no
cpuinfo: fpu : yes
cpuinfo: fpu_exception : yes
cpuinfo: cpuid level : 10
cpuinfo: wp : yes
cpuinfo: flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc arch_perfmon pebs bts pni monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr lahf_lm ida
cpuinfo: bogomips : 2394.02
cpuinfo: clflush size : 64
ENDTIME: 1229232757.53804 -> TIMES 0.27 0.01 23.1 0.62
diff --git a/lib/POE/Devel/Benchmarker/Imager.pm b/lib/POE/Devel/Benchmarker/Imager.pm
index 8062d98..d6a81c7 100644
--- a/lib/POE/Devel/Benchmarker/Imager.pm
+++ b/lib/POE/Devel/Benchmarker/Imager.pm
@@ -1,443 +1,442 @@
# Declare our package
package POE::Devel::Benchmarker::Imager;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.05';
# auto-export the only sub we have
use base qw( Exporter );
our @EXPORT = qw( imager );
# import the helper modules
use YAML::Tiny;
# load our plugins!
use Module::Pluggable search_path => [ __PACKAGE__ ];
# load comparison stuff
use version;
# generate some accessors
use base qw( Class::Accessor::Fast );
__PACKAGE__->mk_ro_accessors( qw( poe_versions poe_versions_sorted poe_loops data
noxsqueue noasserts litetests quiet
) );
# autoflush, please!
use IO::Handle;
STDOUT->autoflush( 1 );
# starts the work of converting our data to images
sub imager {
my $options = shift;
# instantitate ourself
my $self = __PACKAGE__->new( $options );
# parse all of our YAML modules!
$self->loadtests;
# process some stats
$self->process_data;
# generate the images!
$self->generate_images;
return;
}
# creates a new instance
sub new {
my $class = shift;
my $opts = shift;
# instantitate ourself
my $self = {};
bless $self, $class;
# init the options
$self->init_options( $opts );
if ( ! $self->{'options'}->{'quiet'} ) {
print "[IMAGER] Starting up...\n";
}
return $self;
}
sub init_options {
my $self = shift;
my $options = shift;
# set defaults
$self->{'quiet'} = 0;
$self->{'litetests'} = 1;
$self->{'noasserts'} = undef;
$self->{'noxsqueue'} = undef;
# process our options
if ( defined $options and ref $options and ref( $options ) eq 'HASH' ) {
# process quiet mode
if ( exists $options->{'quiet'} ) {
if ( $options->{'quiet'} ) {
$self->{'quiet'} = 1;
} else {
$self->{'quiet'} = 0;
}
}
# process the LITE/HEAVY
if ( exists $options->{'litetests'} ) {
if ( $options->{'litetests'} ) {
$self->{'litetests'} = 1;
} else {
$self->{'litetests'} = 0;
}
}
# process the noasserts to load
if ( exists $options->{'noasserts'} ) {
if ( $options->{'noasserts'} ) {
$self->{'noasserts'} = 1;
} else {
$self->{'noasserts'} = 0;
}
}
# process the noxsqueue to load
if ( exists $options->{'noxsqueue'} ) {
if ( $options->{'noxsqueue'} ) {
$self->{'noxsqueue'} = 1;
} else {
$self->{'noxsqueue'} = 0;
}
}
# FIXME process the plugins to load -> "types"
# FIXME process the versions to load
# FIXME process the loops to load
}
# some sanity tests
- # FIXME find a way to set the results directory via attribute
if ( ! -d 'results' ) {
die "The 'results' directory is not found in the working directory!";
}
if ( ! -d 'images' ) {
die "The 'images' directory is not found in the working directory!";
}
return;
}
# starts the process of loading all of our YAML images
sub loadtests {
my $self = shift;
# gather all the YAML dumps
if ( opendir( DUMPS, 'results' ) ) {
foreach my $d ( readdir( DUMPS ) ) {
# parse the file structure
# POE-1.0002-IO_Poll-LITE-assert-noxsqueue
if ( $d =~ /^POE\-([\d\.\_]+)\-(\w+?)\-(LITE|HEAVY)\-(noassert|assert)\-(noxsqueue|xsqueue)\.yml$/ ) {
my( $ver, $loop, $lite, $assert, $xsqueue ) = ( $1, $2, $3, $4, $5 );
# skip this file?
if ( $self->noxsqueue ) {
if ( $xsqueue eq 'xsqueue' ) { next }
} else {
if ( defined $self->noxsqueue ) {
if ( $xsqueue eq 'noxsqueue' ) { next }
}
}
if ( $self->noasserts ) {
if ( $assert eq 'assert' ) { next }
} else {
if ( defined $self->noasserts ) {
if ( $assert eq 'noassert' ) { next }
}
}
if ( $self->litetests ) {
if ( $lite eq 'HEAVY' ) { next }
} else {
if ( $lite eq 'LITE' ) { next }
}
# FIXME allow selective loading of tests, so we can control what to image, etc
# actually load this file!
$self->load_yaml( $d, $ver, $loop, $lite, $assert, $xsqueue );
}
}
closedir( DUMPS ) or die "[IMAGER] Unable to read from 'results' -> " . $!;
} else {
die "[IMAGER] Unable to open 'results' for reading -> " . $!;
}
# sanity
if ( ! exists $self->{'data'} ) {
die "[IMAGER] Unable to find any POE test result(s) in the 'results' directory!\n";
}
if ( ! $self->quiet ) {
print "[IMAGER] Done with parsing the YAML files...\n";
}
return;
}
# loads the yaml of a specific file
sub load_yaml {
my ( $self, $file, $ver, $loop, $lite, $assert, $xsqueue ) = @_;
my $yaml = YAML::Tiny->read( 'results/' . $file );
if ( ! defined $yaml ) {
die "[IMAGER] Unable to load YAML file $file -> " . YAML::Tiny->errstr . "\n";
} else {
# inrospect it!
my $isvalid = 0;
eval {
# simple sanity check: the "x_bench" param is at the end of the YML, so if it loads fine we know it's there
if ( exists $yaml->[0]->{'x_bench'} ) {
# version must at least match us
$isvalid = ( $yaml->[0]->{'x_bench'} eq $POE::Devel::Benchmarker::Imager::VERSION ? 1 : 0 );
} else {
$isvalid = undef;
}
};
if ( ! $isvalid or $@ ) {
die "[IMAGER] Detected outdated/corrupt benchmark result: $file";
} else {
# reduce indirection
$yaml = $yaml->[0];
}
}
# store the POE version
$self->{'poe_versions'}->{ $ver } = 1;
# sanity check the loop master version ( which should always be our "installed" version, not per-POE )
if ( exists $yaml->{'poe'}->{'loop_m'} ) {
if ( ! defined $self->{'poe_loops'}->{ $loop } ) {
$self->{'poe_loops'}->{ $loop } = $yaml->{'poe'}->{'loop_m'};
} else {
if ( $self->{'poe_loops'}->{ $loop } ne $yaml->{'poe'}->{'loop_m'} ) {
die "[IMAGER] Detected POE::Loop master version inconsistency! $file reported '" . $yaml->{'poe'}->{'loop_m'} .
"' while others had '" . $self->{'poe_loops'}->{ $loop } . "'";
}
}
}
# get the info we're interested in
$self->{'data'}->{ $assert }->{ $xsqueue }->{ $ver }->{ $loop }->{'metrics'} = $yaml->{'metrics'};
$self->{'data'}->{ $assert }->{ $xsqueue }->{ $ver }->{ $loop }->{'time'} = $yaml->{'t'};
if ( exists $yaml->{'pid'} ) {
$self->{'data'}->{ $assert }->{ $xsqueue }->{ $ver }->{ $loop }->{'pid'} = $yaml->{'pid'};
}
if ( exists $yaml->{'poe'}->{'modules'} ) {
$self->{'data'}->{ $assert }->{ $xsqueue }->{ $ver }->{ $loop }->{'poe_modules'} = $yaml->{'poe'}->{'modules'};
}
# sanity check the perl stuff
if ( exists $yaml->{'perl'}->{'binary'} ) {
if ( ! exists $self->{'data'}->{'perlconfig'} ) {
$self->{'data'}->{'perlconfig'}->{'binary'} = $yaml->{'perl'}->{'binary'};
$self->{'data'}->{'perlconfig'}->{'version'} = $yaml->{'perl'}->{'v'};
} else {
if ( $self->{'data'}->{'perlconfig'}->{'binary'} ne $yaml->{'perl'}->{'binary'} ) {
die "[IMAGER] Detected perl binary inconsistency! $file reported '" . $yaml->{'perl'}->{'binary'} .
"' while others had '" . $self->{'data'}->{'perlconfig'}->{'binary'} . "'";
}
if ( $self->{'data'}->{'perlconfig'}->{'version'} ne $yaml->{'perl'}->{'v'} ) {
die "[IMAGER] Detected perl version inconsistency! $file reported '" . $yaml->{'perl'}->{'v'} .
"' while others had '" . $self->{'data'}->{'perlconfig'}->{'version'} . "'";
}
}
}
# sanity check the uname
if ( exists $yaml->{'uname'} ) {
if ( ! exists $self->{'data'}->{'uname'} ) {
$self->{'data'}->{'uname'} = $yaml->{'uname'};
} else {
if ( $self->{'data'}->{'uname'} ne $yaml->{'uname'} ) {
die "[IMAGER] Detected system inconsistency! $file reported '" . $yaml->{'uname'} .
"' while others had '" . $self->{'data'}->{'uname'} . "'";
}
}
}
# sanity check the cpu name
if ( exists $yaml->{'cpu'} ) {
if ( ! exists $self->{'data'}->{'cpu'} ) {
$self->{'data'}->{'cpu'} = $yaml->{'cpu'};
} else {
if ( $self->{'data'}->{'cpu'}->{'name'} ne $yaml->{'cpu'}->{'name'} ) {
die "[IMAGER] Detected system/cpu inconsistency! $file reported '" . $yaml->{'cpu'}->{'name'} .
"' while others had '" . $self->{'data'}->{'cpu'}->{'name'} . "'";
}
}
}
return;
}
sub process_data {
my $self = shift;
# sanitize the versions in an ordered loop
$self->{'poe_versions_sorted'} = [ map { $_->stringify } sort { $a <=> $b } map { version->new($_) } keys %{ $self->poe_versions } ];
if ( ! $self->quiet ) {
print "[IMAGER] Done with processing the benchmark statistics...\n";
}
return;
}
sub generate_images {
my $self = shift;
# load our plugins and let them have fun :)
foreach my $plugin ( $self->plugins ) {
# actually load it!
## no critic
eval "require $plugin";
## use critic
if ( $@ ) {
if ( ! $self->quiet ) {
print "[IMAGER] Unable to load plugin $plugin -> $@\n";
next;
}
}
# sanity checks
if ( $plugin->can( 'new' ) and $plugin->can( 'imager' ) ) {
# FIXME did we want this plugin?
# create the plugin's home dir
my $homedir = $plugin;
if ( $homedir =~ /\:\:(\w+)$/ ) {
$homedir = $1;
} else {
die "barf";
}
if ( ! -d "images/$homedir" ) {
# create it!
if ( ! mkdir( "images/$homedir" ) ) {
die "[IMAGER] Unable to create plugin directory: $homedir";
}
}
# Okay, get this plugin!
my $obj = $plugin->new( { 'dir' => "images/$homedir/" } );
if ( ! $self->quiet ) {
print "[IMAGER] Processing the $plugin plugin...\n";
}
$obj->imager( $self );
}
}
if ( ! $self->quiet ) {
print "[IMAGER] Done with generating images...\n";
}
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::Imager - Automatically converts the benchmark data into images
=head1 SYNOPSIS
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker::Imager -e 'imager'
=head1 ABSTRACT
This package automatically parses the benchmark data and generates pretty charts.
=head1 DESCRIPTION
It will parse the YAML output from the benchmark data and calls it's plugins to generate any charts necessary
and place them in the 'images' directory under the plugin's name. This module only does the high-level stuff, and leaves
the actual chart generation to the plugins.
Furthermore, we use Module::Pluggable to search all modules in the POE::Devel::Benchmarker::Imager::* namespace and
let them handle the generation of images. That way virtually unlimited combinations of images can be generated on the fly
from the data this module parses.
The way to use this module is by calling the imager() subroutine and let it do it's job. You can pass a hashref to it to
set various options. Here is a list of the valid options:
=over 4
=item quiet => boolean
This enables quiet mode which will not print anything to the console except for errors.
new( { 'quiet' => 1 } );
default: false
=item noxsqueue => boolean / undef
This will tell the Imager to not consider those tests for the output.
benchmark( { noxsqueue => 1 } );
default: undef ( load both xsqueue and noxsqueue tests )
=item noasserts => boolean / undef
This will tell the Imager to not consider those tests for the output
benchmark( { noasserts => 1 } );
default: undef ( load both assert and noassert tests )
=item litetests => boolean
This will tell the Imager to not consider those tests for the output
benchmark( { litetests => 0 } );
default: true
=back
=head1 PLUGIN INTERFACE
For now, this is undocumented. Please look at BasicStatistics for the general concept on how it interacts with this module.
=head1 EXPORT
Automatically exports the imager() sub
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/Imager/BasicStatistics.pm b/lib/POE/Devel/Benchmarker/Imager/BasicStatistics.pm
index fe522d2..52f75b3 100644
--- a/lib/POE/Devel/Benchmarker/Imager/BasicStatistics.pm
+++ b/lib/POE/Devel/Benchmarker/Imager/BasicStatistics.pm
@@ -1,320 +1,323 @@
# Declare our package
package POE::Devel::Benchmarker::Imager::BasicStatistics;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.05';
# the GD stuff
use GD::Graph::lines;
+# import some stuff
+use POE::Devel::Benchmarker::Utils qw( currentMetrics );
+
# creates a new instance
sub new {
my $class = shift;
my $opts = shift;
# instantitate ourself
my $self = {
'opts' => $opts,
};
return bless $self, $class;
}
# actually generates the graphs!
sub imager {
my $self = shift;
$self->{'imager'} = shift;
# generate the loops vs each other graphs
$self->generate_loopwars;
# generate the single loop performance
$self->generate_loopperf;
# generate the loop assert/xsqueue ( 4 lines ) per metric
$self->generate_loopoptions;
return;
}
# charts a single loop's progress over POE versions
sub generate_loopoptions {
my $self = shift;
if ( ! $self->{'imager'}->quiet ) {
print "[BasicStatistics] Generating the Loop-Options graphs...\n";
}
# go through all the loops we want
foreach my $loop ( keys %{ $self->{'imager'}->poe_loops } ) {
- foreach my $metric ( qw( alarms dispatches posts single_posts startups select_read_MYFH select_write_MYFH select_read_STDIN select_write_STDIN ) ) {
+ foreach my $metric ( @{ currentMetrics() } ) {
my %data;
# organize data by POE version
foreach my $poe ( @{ $self->{'imager'}->poe_versions_sorted } ) {
# go through the combo of assert/xsqueue
foreach my $assert ( qw( assert noassert ) ) {
if ( ! exists $self->{'imager'}->data->{ $assert } ) {
next;
}
foreach my $xsqueue ( qw( xsqueue noxsqueue ) ) {
if ( ! exists $self->{'imager'}->data->{ $assert }->{ $xsqueue } ) {
next;
}
if ( exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
and defined $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
) {
push( @{ $data{ $assert . '_' . $xsqueue } }, $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'} );
} else {
push( @{ $data{ $assert . '_' . $xsqueue } }, 0 );
}
}
}
}
# transform %data into something GD likes
my @data_for_gd;
foreach my $m ( sort keys %data ) {
push( @data_for_gd, $data{ $m } );
}
# send it to GD!
$self->make_gdgraph( 'Options_' . $loop . '_' . $metric,
[ sort keys %data ],
\@data_for_gd,
);
}
}
return;
}
# charts a single loop's progress over POE versions
sub generate_loopperf {
my $self = shift;
if ( ! $self->{'imager'}->quiet ) {
print "[BasicStatistics] Generating the Loop-Performance graphs...\n";
}
# go through all the loops we want
foreach my $loop ( keys %{ $self->{'imager'}->poe_loops } ) {
# go through the combo of assert/xsqueue
foreach my $assert ( qw( assert noassert ) ) {
if ( ! exists $self->{'imager'}->data->{ $assert } ) {
next;
}
foreach my $xsqueue ( qw( xsqueue noxsqueue ) ) {
if ( ! exists $self->{'imager'}->data->{ $assert }->{ $xsqueue } ) {
next;
}
my %data;
# organize data by POE version
foreach my $poe ( @{ $self->{'imager'}->poe_versions_sorted } ) {
- foreach my $metric ( qw( alarms dispatches posts single_posts startups select_read_MYFH select_write_MYFH select_read_STDIN select_write_STDIN ) ) {
+ foreach my $metric ( @{ currentMetrics() } ) {
if ( exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
and defined $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
) {
push( @{ $data{ $metric } }, $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'} );
} else {
push( @{ $data{ $metric } }, 0 );
}
}
}
# transform %data into something GD likes
my @data_for_gd;
foreach my $m ( sort keys %data ) {
push( @data_for_gd, $data{ $m } );
}
# send it to GD!
$self->make_gdgraph( 'Bench_' . $loop,
[ sort keys %data ],
\@data_for_gd,
$assert,
$xsqueue,
);
}
}
}
return;
}
# loop wars!
sub generate_loopwars {
my $self = shift;
if ( ! $self->{'imager'}->quiet ) {
print "[BasicStatistics] Generating the LoopWars graphs...\n";
}
# go through all the metrics we want
- foreach my $metric ( qw( alarms dispatches posts single_posts startups select_read_MYFH select_write_MYFH select_read_STDIN select_write_STDIN ) ) {
+ foreach my $metric ( @{ currentMetrics() } ) {
# go through the combo of assert/xsqueue
foreach my $assert ( qw( assert noassert ) ) {
foreach my $xsqueue ( qw( xsqueue noxsqueue ) ) {
my %data;
# organize data by POE version
foreach my $poe ( @{ $self->{'imager'}->poe_versions_sorted } ) {
foreach my $loop ( keys %{ $self->{'imager'}->poe_loops } ) {
if ( exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
and defined $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
) {
push( @{ $data{ $loop } }, $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'} );
} else {
push( @{ $data{ $loop } }, 0 );
}
}
}
# transform %data into something GD likes
my @data_for_gd;
foreach my $m ( sort keys %data ) {
push( @data_for_gd, $data{ $m } );
}
# send it to GD!
$self->make_gdgraph( "LoopWar_$metric",
[ sort keys %{ $self->{'imager'}->poe_loops } ],
\@data_for_gd,
$assert,
$xsqueue,
);
}
}
}
return;
}
sub make_gdgraph {
my $self = shift;
my $metric = shift;
my $legend = shift;
my $data = shift;
my $assert = shift;
my $xsqueue = shift;
# Get the graph object
my $graph = new GD::Graph::lines( 800, 600 );
# Set some stuff
$graph->set(
# 'x_label' => 'POE Versions',
'title' => $metric . ( defined $xsqueue ? " ($assert - $xsqueue)" : '' ),
'line_width' => 1,
'boxclr' => 'black',
'overwrite' => 0,
'x_labels_vertical' => 1,
'x_all_ticks' => 1,
'legend_placement' => 'BL',
'y_label' => 'iterations/sec',
# 3d options only
#'line_depth' => 2.5,
) or die $graph->error;
# Set the legend
$graph->set_legend( @$legend );
# Set Font stuff
$graph->set_legend_font( GD::gdMediumBoldFont );
$graph->set_x_axis_font( GD::gdMediumBoldFont );
$graph->set_y_axis_font( GD::gdMediumBoldFont );
$graph->set_y_label_font( GD::gdMediumBoldFont );
$graph->set_title_font( GD::gdGiantFont );
# Manufacture the data
my $readydata = [
[ map { 'POE-' . $_ } @{ $self->{'imager'}->poe_versions_sorted } ],
@$data,
];
# Plot it!
$graph->plot( $readydata ) or die $graph->error;
# Print it!
my $filename = $self->{'opts'}->{'dir'} . $metric . '_' .
( $self->{'imager'}->litetests ? 'lite' : 'heavy' ) .
( defined $xsqueue ? '_' . $assert . '_' . $xsqueue : '' ) .
'.png';
open( my $fh, '>', $filename ) or die 'Cannot open graph file!';
binmode( $fh );
print $fh $graph->gd->png();
close( $fh );
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::Imager::BasicStatistics - Plugin to generates basic statistics graphs
=head1 SYNOPSIS
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker::Imager -e 'imager( { type => "BasicStatistics" } )'
=head1 ABSTRACT
This plugin for Imager generates some kinds of graphs from the benchmark tests.
=head1 DESCRIPTION
This package generates some basic graphs from the statistics output. Since the POE::Loop::* modules really are responsible
for the backend logic of POE, it makes sense to graph all related metrics of a single loop across POE versions to see if
-it performs differently. The related benchmark metrics are: events, alarms, filehandles, and startup.
+it performs differently.
This will generate some types of graphs:
=over 4
=item Loops against each other
Each metric will have a picture for itself, showing how each loop compare against each other with the POE versions.
file: BasicStatistics/LoopWar_$metric_$lite_$assert_$xsqueue.png
=item Single Loop over POE versions
Each Loop will have a picture for itself, showing how each metric performs over POE versions.
file: BasicStatistics/Bench_$loop_$lite_$assert_$xsqueue.png
=item Single Loop over POE versions with assert/xsqueue
Each Loop will have a picture for itself, showing how each metric is affected by the assert/xsqueue options.
file: BasicStatistics/Options_$loop_$metric_$lite.png
=back
=head1 EXPORT
Nothing.
=head1 SEE ALSO
-L<POE::Devel::Benchmarker::Imager>
+L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/SubProcess.pm b/lib/POE/Devel/Benchmarker/SubProcess.pm
index 6e6d54e..0e0ad97 100644
--- a/lib/POE/Devel/Benchmarker/SubProcess.pm
+++ b/lib/POE/Devel/Benchmarker/SubProcess.pm
@@ -1,920 +1,920 @@
# Declare our package
package POE::Devel::Benchmarker::SubProcess;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.05';
-# Import Time::HiRes's time()
-use Time::HiRes qw( time );
-
-# FIXME UGLY HACK here
+# set our compile-time stuff
BEGIN {
# should we enable assertions?
if ( defined $ARGV[1] and $ARGV[1] ) {
## no critic
eval "sub POE::Kernel::ASSERT_DEFAULT () { 1 }";
eval "sub POE::Session::ASSERT_STATES () { 1 }";
## use critic
}
# should we "hide" XS::Queue::Array?
if ( defined $ARGV[3] and $ARGV[3] ) {
## no critic
eval "use Devel::Hide qw( POE/XS/Queue/Array.pm )";
## use critic
}
}
+# Import Time::HiRes's time()
+use Time::HiRes qw( time );
+
# load POE
use POE;
use POE::Session;
use POE::Wheel::SocketFactory;
use POE::Wheel::ReadWrite;
use POE::Filter::Line;
use POE::Driver::SysRW;
# autoflush, please!
use IO::Handle;
STDOUT->autoflush( 1 );
# import some stuff
use Socket qw( INADDR_ANY sockaddr_in );
# we need to compare versions
use version;
# load our utility stuff
use POE::Devel::Benchmarker::Utils qw( loop2realversion poeloop2load );
# init our global variables ( bad, haha )
# FIXME change this to a hash because it's becoming unwieldy with too many variables
my( $eventloop, $asserts, $lite_tests, $pocosession );
my( $post_limit, $alarm_limit, $alarm_add_limit, $session_limit, $select_limit, $through_limit, $call_limit, $start_limit, $sf_connects, $sf_stream );
# the main routine which will load everything + start
sub benchmark {
# process the eventloop
process_eventloop();
# process the assertions
process_assertions();
# process the test mode
process_testmode();
# process the XS::Queue hiding
process_xsqueue();
# actually import POE!
process_POE();
# actually run the benchmarks!
run_benchmarks();
# all done!
return;
}
sub process_eventloop {
# Get the desired mode
$eventloop = $ARGV[0];
# print out the loop info
if ( ! defined $eventloop ) {
die "Please supply an event loop!";
} else {
my $loop = poeloop2load( $eventloop );
if ( ! defined $loop ) {
$loop = $eventloop;
}
my $v = loop2realversion( $eventloop );
if ( ! defined $v ) {
$v = 'UNKNOWN';
}
print "Using master loop: $loop-$v\n";
}
return;
}
sub process_assertions {
# Get the desired assert mode
$asserts = $ARGV[1];
if ( defined $asserts and $asserts ) {
print "Using FULL Assertions!\n";
} else {
print "Using NO Assertions!\n";
}
return;
}
sub process_testmode {
# get the desired test mode
$lite_tests = $ARGV[2];
if ( defined $lite_tests and $lite_tests ) {
print "Using the LITE tests\n";
$post_limit = 10_000;
$alarm_limit = 10_000;
$alarm_add_limit = 10_000;
$session_limit = 500;
$select_limit = 10_000;
$through_limit = 10_000;
$call_limit = 10_000;
$start_limit = 10;
$sf_connects = 1_000;
$sf_stream = 1_000;
} else {
print "Using the HEAVY tests\n";
$post_limit = 100_000;
$alarm_limit = 100_000;
$alarm_add_limit = 100_000;
$session_limit = 5_000;
$select_limit = 100_000;
$through_limit = 100_000;
$call_limit = 100_000;
$start_limit = 100;
$sf_connects = 10_000;
$sf_stream = 10_000;
}
return;
}
sub process_xsqueue {
# should we "hide" XS::Queue::Array?
if ( defined $ARGV[3] and $ARGV[3] ) {
print "DISABLING POE::XS::Queue::Array\n";
} else {
print "LETTING POE find POE::XS::Queue::Array\n";
}
return;
}
sub process_POE {
# Print the POE info
print "Using POE-" . $POE::VERSION . "\n";
# Actually print what loop POE is using
foreach my $m ( keys %INC ) {
if ( $m =~ /^POE\/(?:Loop|XS|Queue)/ ) {
# try to be smart and get version?
my $module = $m;
$module =~ s|/|::|g;
$module =~ s/\.pm$//g;
print "POE is using: $module ";
if ( defined $module->VERSION ) {
print "v" . $module->VERSION . "\n";
} else {
print "vUNKNOWN\n";
}
}
}
return;
}
sub run_benchmarks {
# dump some misc info
dump_perlinfo();
dump_sysinfo();
# run the startup test before we actually run POE
bench_startup();
# load the POE session + do the tests there
bench_poe();
# okay, dump our memory usage
dump_pidinfo();
# all done!
return;
}
sub bench_startup {
# Add the eventloop?
my $looploader = poeloop2load( $eventloop );
my @start_times = times();
my $start = time();
for (my $i = 0; $i < $start_limit; $i++) {
# FIXME should we add assertions?
# finally, fire it up!
CORE::system(
$^X,
'-Ipoedists/POE-' . $POE::VERSION,
'-Ipoedists/POE-' . $POE::VERSION . '/lib',
( defined $looploader ? "-M$looploader" : () ),
'-MPOE',
'-e',
1,
);
}
my @end_times = times();
my $elapsed = time() - $start;
printf( "\n\n% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $start_limit, 'startups', $elapsed, $start_limit/$elapsed );
print "startups times: @start_times @end_times\n";
return;
}
sub bench_poe {
# figure out POE::Session->create or POE::Session->new or what?
$pocosession = POE::Session->can( 'create' );
if ( defined $pocosession ) {
$pocosession = 'create';
} else {
$pocosession = POE::Session->can( 'spawn' );
if ( defined $pocosession ) {
$pocosession = 'spawn';
} else {
$pocosession = 'new';
}
}
# create the master sesssion + run POE!
POE::Session->$pocosession(
'inline_states' => {
# basic POE states
'_start' => \&poe__start,
'_default' => \&poe__default,
'_stop' => \&poe__stop,
'null' => \&poe_null,
# our test states
'posts' => \&poe_posts,
'posts_start' => \&poe_posts_start,
'posts_end' => \&poe_posts_end,
'alarms' => \&poe_alarms,
'manyalarms' => \&poe_manyalarms,
'sessions' => \&poe_sessions,
'sessions_end' => \&poe_sessions_end,
'stdin_read' => \&poe_stdin_read,
'stdin_write' => \&poe_stdin_write,
'myfh_read' => \&poe_myfh_read,
'myfh_write' => \&poe_myfh_write,
'calls' => \&poe_calls,
'eventsquirt' => \&poe_eventsquirt,
'eventsquirt_done' => \&poe_eventsquirt_done,
'socketfactory' => \&poe_socketfactory,
'socketfactory_start' => \&poe_socketfactory_start,
'socketfactory_connects' => \&poe_socketfactory_connects,
'socketfactory_stream' => \&poe_socketfactory_stream,
'socketfactory_cleanup' => \&poe_socketfactory_cleanup,
# misc states for test stuff
'server_sf_connect' => \&poe_server_sf_connect,
'server_sf_failure' => \&poe_server_sf_failure,
'server_rw_input' => \&poe_server_rw_input,
'server_rw_error' => \&poe_server_rw_error,
'client_sf_connect' => \&poe_client_sf_connect,
'client_sf_failure' => \&poe_client_sf_failure,
'client_rw_input' => \&poe_client_rw_input,
'client_rw_error' => \&poe_client_rw_error,
},
);
# start the kernel!
POE::Kernel->run();
return;
}
# inits our session
sub poe__start {
# fire off the first test!
$_[KERNEL]->yield( 'posts' );
return;
}
sub poe__stop {
}
sub poe__default {
return 0;
}
# a state that does nothing
sub poe_null {
return 1;
}
# How many posts per second? Post a bunch of events, keeping track of the time it takes.
sub poe_posts {
$_[KERNEL]->yield( 'posts_start' );
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $post_limit; $i++) {
$_[KERNEL]->yield( 'null' );
}
my @end_times = times();
my $elapsed = time() - $start;
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $post_limit, 'posts', $elapsed, $post_limit/$elapsed );
print "posts times: @start_times @end_times\n";
$_[KERNEL]->yield( 'posts_end' );
return;
}
sub poe_posts_start {
$_[HEAP]->{start} = time();
$_[HEAP]->{starttimes} = [ times() ];
return;
}
sub poe_posts_end {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $post_limit, 'dispatches', $elapsed, $post_limit/$elapsed );
print "dispatches times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
$_[KERNEL]->yield( 'alarms' );
return;
}
# How many alarms per second? Set a bunch of alarms and find out.
sub poe_alarms {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $alarm_limit; $i++) {
$_[KERNEL]->alarm( whee => rand(1_000_000) );
}
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $alarm_limit, 'alarms', $elapsed, $alarm_limit/$elapsed );
print "alarms times: @start_times @end_times\n";
$_[KERNEL]->alarm( 'whee' => undef );
$_[KERNEL]->yield( 'manyalarms' );
return;
}
# How many repetitive alarms per second? Set a bunch of
# additional alarms and find out. Also see how quickly they can
# be cleared.
sub poe_manyalarms {
# can this POE::Kernel support this?
if ( $_[KERNEL]->can( 'alarm_add' ) ) {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $alarm_add_limit; $i++) {
$_[KERNEL]->alarm_add( whee => rand(1_000_000) );
}
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $alarm_add_limit, 'alarm_adds', $elapsed, $alarm_add_limit/$elapsed );
print "alarm_adds times: @start_times @end_times\n";
$start = time();
@start_times = times();
$_[KERNEL]->alarm( whee => undef );
$elapsed = time() - $start;
@end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $alarm_add_limit, 'alarm_clears', $elapsed, $alarm_add_limit/$elapsed );
print "alarm_clears times: @start_times @end_times\n";
} else {
- print "alarm_add NOT SUPPORTED on this version of POE, skipping alarm_adds/alarm_clears tests!\n";
+ print "SKIPPING br0ken alarm_adds because alarm_add() NOT SUPPORTED on this version of POE\n";
+ print "SKIPPING br0ken alarm_clears because alarm_add() NOT SUPPORTED on this version of POE\n";
}
$_[KERNEL]->yield( 'sessions' );
return;
}
# How many sessions can we create and destroy per second?
# Create a bunch of sessions, and track that time. Let them
# self-destruct, and track that as well.
sub poe_sessions {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $session_limit; $i++) {
POE::Session->$pocosession( 'inline_states' => { _start => sub {}, _stop => sub {}, _default => sub { return 0 } } );
}
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $session_limit, 'session_creates', $elapsed, $session_limit/$elapsed );
print "session_creates times: @start_times @end_times\n";
$_[KERNEL]->yield( 'sessions_end' );
$_[HEAP]->{start} = time();
$_[HEAP]->{starttimes} = [ times() ];
return;
}
sub poe_sessions_end {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $session_limit, 'session_destroys', $elapsed, $session_limit/$elapsed );
print "session_destroys times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
$_[KERNEL]->yield( 'stdin_read' );
return;
}
# How many times can we select/unselect READ a from STDIN filehandle per second?
sub poe_stdin_read {
# stupid, but we have to skip those tests
if ( $eventloop eq 'Tk' or $eventloop eq 'Prima' ) {
- print "SKIPPING STDIN tests on broken loop: $eventloop\n";
+ print "SKIPPING br0ken select_read_STDIN because eventloop doesn't work: $eventloop\n";
+ print "SKIPPING br0ken select_write_STDIN because eventloop doesn't work: $eventloop\n";
$_[KERNEL]->yield( 'myfh_read' );
return;
}
my $start = time();
my @start_times = times();
eval {
for (my $i = 0; $i < $select_limit; $i++) {
$_[KERNEL]->select_read( *STDIN, 'whee' );
$_[KERNEL]->select_read( *STDIN );
}
};
if ( $@ ) {
- print "filehandle select_read on STDIN FAILED: $@\n";
+ print "SKIPPING br0ken select_read_STDIN because FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $select_limit, 'select_read_STDIN', $elapsed, $select_limit/$elapsed );
print "select_read_STDIN times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'stdin_write' );
return;
}
# How many times can we select/unselect WRITE a from STDIN filehandle per second?
sub poe_stdin_write {
my $start = time();
my @start_times = times();
eval {
for (my $i = 0; $i < $select_limit; $i++) {
$_[KERNEL]->select_write( *STDIN, 'whee' );
$_[KERNEL]->select_write( *STDIN );
}
};
if ( $@ ) {
- print "filehandle select_write on STDIN FAILED: $@\n";
+ print "SKIPPING br0ken select_write_STDIN because FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $select_limit, 'select_write_STDIN', $elapsed, $select_limit/$elapsed );
print "select_write_STDIN times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'myfh_read' );
return;
}
# How many times can we select/unselect READ a real filehandle?
sub poe_myfh_read {
# stupid, but we have to skip those tests
if ( $eventloop eq 'Event_Lib' or $eventloop eq 'Tk' or $eventloop eq 'Prima' ) {
- print "SKIPPING MYFH tests on broken loop: $eventloop\n";
+ print "SKIPPING br0ken select_read_MYFH because eventloop doesn't work: $eventloop\n";
+ print "SKIPPING br0ken select_write_MYFH because eventloop doesn't work: $eventloop\n";
$_[KERNEL]->yield( 'calls' );
return;
}
my $start = time();
my @start_times = times();
eval {
open( my $fh, '+>', 'poebench' ) or die $!;
for (my $i = 0; $i < $select_limit; $i++) {
$_[KERNEL]->select_read( $fh, 'whee' );
$_[KERNEL]->select_read( $fh );
}
close( $fh ) or die $!;
unlink( 'poebench' ) or die $!;
};
if ( $@ ) {
- print "filehandle select_read on MYFH FAILED: $@\n";
+ print "SKIPPING br0ken select_read_MYFH because FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $select_limit, 'select_read_MYFH', $elapsed, $select_limit/$elapsed );
print "select_read_MYFH times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'myfh_write' );
return;
}
# How many times can we select/unselect WRITE a real filehandle?
sub poe_myfh_write {
my $start = time();
my @start_times = times();
eval {
open( my $fh, '+>', 'poebench' ) or die $!;
for (my $i = 0; $i < $select_limit; $i++) {
$_[KERNEL]->select_write( $fh, 'whee' );
$_[KERNEL]->select_write( $fh );
}
close( $fh ) or die $!;
unlink( 'poebench' ) or die $!;
};
if ( $@ ) {
- print "filehandle select_write on MYFH FAILED: $@\n";
+ print "SKIPPING br0ken select_write_MYFH because FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $select_limit, 'select_write_MYFH', $elapsed, $select_limit/$elapsed );
print "select_write_MYFH times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'calls' );
return;
}
# How many times can we call a state?
sub poe_calls {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $call_limit; $i++) {
$_[KERNEL]->call( $_[SESSION], 'null' );
}
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $call_limit, 'calls', $elapsed, $call_limit/$elapsed );
print "calls times: @start_times @end_times\n";
$_[KERNEL]->yield( 'eventsquirt' );
return;
}
# How many events can we squirt through POE, one at a time?
sub poe_eventsquirt {
$_[HEAP]->{start} = time();
$_[HEAP]->{starttimes} = [ times() ];
$_[HEAP]->{yield_count} = $through_limit;
$_[KERNEL]->yield( 'eventsquirt_done' );
return;
}
sub poe_eventsquirt_done {
if (--$_[HEAP]->{yield_count}) {
$_[KERNEL]->yield( 'eventsquirt_done' );
} else {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $through_limit, 'single_posts', $elapsed, $through_limit/$elapsed );
print "single_posts times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
$_[KERNEL]->yield( 'socketfactory' );
}
return;
}
# tests socketfactory interactions
sub poe_socketfactory {
# POE transitioned between Event to State on 0.19 for SocketFactory/ReadWrite
# 0.20+ throws deprecation error :(
$_[HEAP]->{'POE_naming'} = 'Event';
if ( version->new( $POE::VERSION ) < version->new( '0.20' ) ) {
$_[HEAP]->{'POE_naming'} = 'State';
}
# create the socketfactory server
$_[HEAP]->{'SF'} = POE::Wheel::SocketFactory->new(
'Port' => INADDR_ANY,
'Address' => 'localhost',
'Reuse' => 'yes',
'Success' . $_[HEAP]->{'POE_naming'} => 'server_sf_connect',
'Failure' . $_[HEAP]->{'POE_naming'} => 'server_sf_failure',
);
# be evil, and get the port for the client to connect to
( $_[HEAP]->{'SF_port'}, undef ) = sockaddr_in( getsockname( $_[HEAP]->{'SF'}->[ POE::Wheel::SocketFactory::MY_SOCKET_HANDLE() ] ) );
# start the connect tests
$_[HEAP]->{'SF_counter'} = $sf_connects;
$_[HEAP]->{'SF_mode'} = 'CONNECTS';
$_[HEAP]->{'start'} = time();
$_[HEAP]->{'starttimes'} = [ times() ];
$_[KERNEL]->yield( 'socketfactory_connects' );
return;
}
# handles SocketFactory connection
sub poe_server_sf_connect {
# what test mode?
if ( $_[HEAP]->{'SF_mode'} eq 'CONNECTS' ) {
# simply discard this socket
} elsif ( $_[HEAP]->{'SF_mode'} eq 'STREAM' ) {
# convert it to ReadWrite
my $wheel = POE::Wheel::ReadWrite->new(
'Handle' => $_[ARG0],
'Filter' => POE::Filter::Line->new,
'Driver' => POE::Driver::SysRW->new,
'Input' . $_[HEAP]->{'POE_naming'} => 'server_rw_input',
'Error' . $_[HEAP]->{'POE_naming'} => 'server_rw_error',
);
# save it in our heap
$_[HEAP]->{'RW'}->{ $wheel->ID } = $wheel;
} else {
die "unknown test mode";
}
return;
}
# handles SocketFactory errors
sub poe_server_sf_failure {
# ARGH, we couldnt create listening socket
- print "SKIPPING socket_connect tests because we were unable to setup listening socket\n";
- print "SKIPPING socket_stream tests because we were unable to setup listening socket\n";
+ print "SKIPPING br0ken socket_connects because we were unable to setup listening socket\n";
+ print "SKIPPING br0ken socket_stream because we were unable to setup listening socket\n";
$_[KERNEL]->yield( 'socketfactory_cleanup' );
return;
}
# handles ReadWrite input
sub poe_server_rw_input {
# what test mode?
if ( $_[HEAP]->{'SF_mode'} eq 'CONNECTS' ) {
# simply discard this data
} elsif ( $_[HEAP]->{'SF_mode'} eq 'STREAM' ) {
# send it back to the client!
$_[HEAP]->{'RW'}->{ $_[ARG1] }->put( $_[ARG0] );
} else {
die "unknown test mode";
}
return;
}
# handles ReadWrite disconnects
sub poe_server_rw_error {
# simply get rid of the wheel
if ( exists $_[HEAP]->{'RW'}->{ $_[ARG3] } ) {
# FIXME do we need this?
eval {
$_[HEAP]->{'RW'}->{ $_[ARG3] }->shutdown_input;
$_[HEAP]->{'RW'}->{ $_[ARG3] }->shutdown_output;
};
delete $_[HEAP]->{'RW'}->{ $_[ARG3] };
}
return;
}
# starts the client connect tests
sub poe_socketfactory_connects {
if (--$_[HEAP]->{'SF_counter'}) {
# open a new client connection!
$_[HEAP]->{'client_SF'} = POE::Wheel::SocketFactory->new(
'RemoteAddress' => 'localhost',
'RemotePort' => $_[HEAP]->{'SF_port'},
'Success' . $_[HEAP]->{'POE_naming'} => 'client_sf_connect',
'Failure' . $_[HEAP]->{'POE_naming'} => 'client_sf_failure',
);
} else {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
- printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $sf_connects, 'socket_connect', $elapsed, $sf_connects/$elapsed );
- print "socket_connect times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
+ printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $sf_connects, 'socket_connects', $elapsed, $sf_connects/$elapsed );
+ print "socket_connects times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
$_[KERNEL]->yield( 'socketfactory_stream' );
}
return;
}
# starts the client stream tests
sub poe_socketfactory_stream {
# set the proper test mode
$_[HEAP]->{'SF_mode'} = 'STREAM';
# open a new client connection!
$_[HEAP]->{'client_SF'} = POE::Wheel::SocketFactory->new(
'RemoteAddress' => 'localhost',
'RemotePort' => $_[HEAP]->{'SF_port'},
'Success' . $_[HEAP]->{'POE_naming'} => 'client_sf_connect',
'Failure' . $_[HEAP]->{'POE_naming'} => 'client_sf_failure',
);
return;
}
# the client connected to the server!
sub poe_client_sf_connect {
# what test mode?
if ( $_[HEAP]->{'SF_mode'} eq 'CONNECTS' ) {
# simply discard this connection
delete $_[HEAP]->{'client_SF'};
# make another connection!
$_[KERNEL]->yield( 'socketfactory_connects' );
} elsif ( $_[HEAP]->{'SF_mode'} eq 'STREAM' ) {
# convert it to ReadWrite
my $wheel = POE::Wheel::ReadWrite->new(
'Handle' => $_[ARG0],
'Filter' => POE::Filter::Line->new,
'Driver' => POE::Driver::SysRW->new,
'Input' . $_[HEAP]->{'POE_naming'} => 'client_rw_input',
'Error' . $_[HEAP]->{'POE_naming'} => 'client_rw_error',
);
# save it in our heap
$_[HEAP]->{'client_RW'}->{ $wheel->ID } = $wheel;
# begin the STREAM test!
$_[HEAP]->{'SF_counter'} = $sf_stream;
$_[HEAP]->{'SF_data'} = 'x' x ( $sf_stream / 10 ); # set a reasonable-sized chunk of data
$_[HEAP]->{'start'} = time();
$_[HEAP]->{'starttimes'} = [ times() ];
$wheel->put( $_[HEAP]->{'SF_data'} );
} else {
die "unknown test mode";
}
return;
}
# handles SocketFactory errors
sub poe_client_sf_failure {
-my ($operation, $errnum, $errstr, $wheel_id) = @_[ARG0..ARG3];
-warn "Wheel $wheel_id generated $operation error $errnum: $errstr\n";
-
# ARGH, we couldnt create connecting socket
if ( $_[HEAP]->{'SF_mode'} eq 'CONNECTS' ) {
- print "SKIPPING socket_connects tests because we were unable to setup connecting socket\n";
+ print "SKIPPING br0ken socket_connects because we were unable to setup connecting socket\n";
# go to stream test
$_[KERNEL]->yield( 'socketfactory_stream' );
} elsif ( $_[HEAP]->{'SF_mode'} eq 'STREAM' ) {
- print "SKIPPING socket_stream tests because we were unable to setup connecting socket\n";
+ print "SKIPPING br0ken socket_stream because we were unable to setup connecting socket\n";
$_[KERNEL]->yield( 'socketfactory_cleanup' );
}
return;
}
# handles ReadWrite input
sub poe_client_rw_input {
if (--$_[HEAP]->{'SF_counter'}) {
# send it back to the server!
$_[HEAP]->{'client_RW'}->{ $_[ARG1] }->put( $_[ARG0] );
} else {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $sf_stream, 'socket_stream', $elapsed, $sf_stream/$elapsed );
print "socket_stream times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
$_[KERNEL]->yield( 'socketfactory_cleanup' );
}
return;
}
# handles ReadWrite disconnect
sub poe_client_rw_error {
# simply get rid of the wheel
if ( exists $_[HEAP]->{'client_RW'}->{ $_[ARG3] } ) {
# FIXME do we need this?
eval {
$_[HEAP]->{'client_RW'}->{ $_[ARG3] }->shutdown_input;
$_[HEAP]->{'client_RW'}->{ $_[ARG3] }->shutdown_output;
};
delete $_[HEAP]->{'client_RW'}->{ $_[ARG3] };
}
return;
}
# all done with the socketfactory tests
sub poe_socketfactory_cleanup {
# do cleanup
delete $_[HEAP]->{'SF'} if exists $_[HEAP]->{'SF'};
delete $_[HEAP]->{'RW'} if exists $_[HEAP]->{'RW'};
delete $_[HEAP]->{'client_SF'} if exists $_[HEAP]->{'client_SF'};
delete $_[HEAP]->{'client_RW'} if exists $_[HEAP]->{'client_RW'};
# XXX all done with tests!
return;
}
# Get the memory footprint
sub dump_pidinfo {
my $ret = open( my $fh, '<', '/proc/self/status' );
if ( defined $ret ) {
while ( <$fh> ) {
chomp;
if ( $_ ne '' ) {
print "pidinfo: $_\n";
}
}
close( $fh ) or die $!;
} else {
print "UNABLE TO GET /proc/self/status\n";
}
return;
}
# print the local Perl info
sub dump_perlinfo {
- print "Running under perl binary: " . $^X . "\n";
+ print "Running under perl binary: '" . $^X . "' v" . sprintf( "%vd", $^V ) . "\n";
require Config;
my $config = Config::myconfig();
foreach my $l ( split( /\n/, $config ) ) {
print "perlconfig: $l\n";
}
return;
}
# print the local system information
sub dump_sysinfo {
print "Running under machine: " . `uname -a` . "\n";
# get cpuinfo
my $ret = open( my $fh, '<', '/proc/cpuinfo' );
if ( defined $ret ) {
while ( <$fh> ) {
chomp;
if ( $_ ne '' ) {
print "cpuinfo: $_\n";
}
}
close( $fh ) or die $!;
} else {
print "UNABLE TO GET /proc/cpuinfo\n";
}
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::SubProcess - Implements the actual POE benchmarks
=head1 SYNOPSIS
perl -MPOE::Devel::Benchmarker::SubProcess -e 'benchmark()'
=head1 ABSTRACT
This package is responsible for implementing the guts of the benchmarks, and timing them.
=head1 EXPORT
Nothing.
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/Utils.pm b/lib/POE/Devel/Benchmarker/Utils.pm
index 62cf95c..81fd57b 100644
--- a/lib/POE/Devel/Benchmarker/Utils.pm
+++ b/lib/POE/Devel/Benchmarker/Utils.pm
@@ -1,202 +1,216 @@
# Declare our package
package POE::Devel::Benchmarker::Utils;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.05';
# set ourself up for exporting
use base qw( Exporter );
-our @EXPORT_OK = qw( poeloop2load load2poeloop loop2realversion beautify_times knownloops generateTestfile );
+our @EXPORT_OK = qw( poeloop2load load2poeloop loop2realversion beautify_times knownloops generateTestfile
+ currentMetrics
+);
+
+# returns the list of current metrics
+sub currentMetrics {
+ return [ qw( alarms dispatches posts single_posts startups
+ select_read_MYFH select_write_MYFH select_read_STDIN select_write_STDIN
+ socket_connects socket_stream
+ ) ];
+}
# returns the filename for a particular test
sub generateTestfile {
my $heap = shift;
return 'POE-' . $heap->{'current_version'} .
'-' . $heap->{'current_loop'} .
'-' . ( $heap->{'lite_tests'} ? 'LITE' : 'HEAVY' ) .
'-' . ( $heap->{'current_assertions'} ? 'assert' : 'noassert' ) .
'-' . ( $heap->{'current_noxsqueue'} ? 'noxsqueue' : 'xsqueue' );
}
# maintains the mapping of the loop <-> real module
my %poe2load = (
'Event' => 'Event',
'IO_Poll' => 'IO::Poll',
'Event_Lib' => 'Event::Lib',
'EV' => 'EV',
'Glib' => 'Glib',
'Tk' => 'Tk',
'Gtk' => 'Gtk',
'Prima' => 'Prima',
'Wx' => 'Wx',
'Kqueue' => undef,
'Select' => undef,
);
# returns the proper "load" stuff for a specific loop
sub poeloop2load {
my $eventloop = shift;
if ( exists $poe2load{ $eventloop } ) {
return $poe2load{ $eventloop };
} else {
die "Unknown event loop!";
}
}
# returns the version of the "real" installed module that the loop uses
sub loop2realversion {
my $eventloop = shift;
# Decide which event loop to use
if ( ! defined $eventloop ) {
return;
} elsif ( $eventloop eq 'Event' ) {
return $Event::VERSION;
} elsif ( $eventloop eq 'IO_Poll' ) {
return $IO::Poll::VERSION;
} elsif ( $eventloop eq 'Event_Lib' ) {
return $Event::Lib::VERSION;
} elsif ( $eventloop eq 'EV' ) {
return $EV::VERSION;
} elsif ( $eventloop eq 'Glib' ) {
return $Glib::VERSION;
} elsif ( $eventloop eq 'Tk' ) {
return $Tk::VERSION;
} elsif ( $eventloop eq 'Gtk' ) {
return $Gtk::VERSION;
} elsif ( $eventloop eq 'Prima' ) {
return $Prima::VERSION;
} elsif ( $eventloop eq 'Wx' ) {
return $Wx::VERSION;
} elsif ( $eventloop eq 'Kqueue' ) {
# FIXME how do I do this?
return;
} elsif ( $eventloop eq 'Select' ) {
return 'BUILTIN';
} else {
die "Unknown event loop!";
}
}
# helper routine to parse times() output
sub beautify_times {
my $string = shift;
my $origdata = shift;
# split it up
$string =~ s/^\s+//; $string =~ s/\s+$//;
my @times = split( /\s+/, $string );
# make the data struct
# ($user,$system,$cuser,$csystem) = times;
my $data = {
'u' => $times[4] - $times[0],
's' => $times[5] - $times[1],
'cu' => $times[6] - $times[2],
'cs' => $times[7] - $times[3],
};
# add original data?
if ( $origdata ) {
$data->{'s_user'} = $times[0];
$data->{'s_sys'} = $times[1];
$data->{'s_cuser'} = $times[2];
$data->{'s_csys'} = $times[3];
$data->{'e_user'} = $times[4];
$data->{'e_sys'} = $times[5];
$data->{'e_cuser'} = $times[6];
$data->{'e_csys'} = $times[7];
}
# send it back!
return $data;
}
# returns a list of "known" POE loops
sub knownloops {
# FIXME we remove Wx because I suck.
# FIXME I have no idea how to load/unload Kqueue...
return [ qw( Event_Lib EV Glib Prima Gtk Tk Select IO_Poll ) ];
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::Utils - Various utility routines for POE::Devel::Benchmarker
=head1 SYNOPSIS
perl -MPOE::Devel::Benchmarker::Utils -e 'print poeloop2load( "IO_Poll" )'
=head1 ABSTRACT
This package contains the utility routines and constants that POE::Devel::Benchmarker needs.
=head1 EXPORT
This package exports those subs via @EXPORT_OK:
=over 4
+=item currentMetrics()
+
+Returns an arrayref of the current benchmark "metrics" that we process
+
=item knownloops()
Returns an arrayref of the "known" POE loops as of this version of the Benchmarker
=item poeloop2load()
Returns the "parent" class to load for a specific loop. An example is:
$real = poeloop2load( 'IO_Poll' ); # $real now contains "IO::Poll"
=item loop2realversion()
Returns the version of the "parent" class for a specific loop. An example is:
$ver = loop2realversion( 'IO_Poll' ); # $ver now contains $IO::Poll::VERSION
=item beautify_times()
Returns a hashref of data from parsing 2 consecutive times() structures in a string. You can pass an additional parameter
( boolean ) to include the original data. An example is:
print Data::Dumper::Dumper( beautify_times( '0.1 0 0 0 0.1 0 0.76 0.09', 1 ) );
{
"sys" => 0, # total system time
"user" => 0, # total user time
"csys" => 0.76 # total children system time
"cuser" => 0.08 # total children user time
"e_csys" => "0.09", # end children system time ( optional )
"e_cuser" => "0.76", # end children user time ( optional )
"e_sys" => 0, # end system time ( optional )
"e_user" => "0.1", # end user time ( optional )
"s_csys" => 0, # start children system time ( optional )
"s_cuser" => 0, # start children user time ( optional )
"s_sys" => 0, # start system time ( optional )
"s_user" => "0.1" # start user time ( optional )
}
=back
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
|
apocalypse/perl-poe-benchmarker
|
e50b55a1a6e7d02373c064a0194e229e15154fd7
|
almost done with socket stuff
|
diff --git a/Build.PL b/Build.PL
index 1f20faf..03bda6e 100755
--- a/Build.PL
+++ b/Build.PL
@@ -1,104 +1,107 @@
# Build.PL
use Module::Build;
my $build = Module::Build->new(
# look up Module::Build::API for the info!
'dynamic_config' => 0,
'module_name' => 'POE::Devel::Benchmarker',
'license' => 'perl',
'dist_abstract' => "Benchmarking POE's performance ( acts more like a smoker )",
'dist_author' => 'Apocalypse <APOCAL@cpan.org>',
'create_packlist' => 1,
'create_makefile_pl' => 'traditional',
'create_readme' => 1,
'test_files' => 't/*.t',
'add_to_cleanup' => [ 'META.yml', 'Makefile.PL', 'README' ], # automatically generated
'requires' => {
# POE Stuff
'POE' => 0,
'POE::Session::AttributeBased' => 0,
# FIXME POE stuff that Test::Dependencies needs to see
- 'POE::Session' => 0,
+ #'POE::Session' => 0,
+ #'POE::Wheel::SocketFactory' => 0,
+ #'POE::Wheel::ReadWrite' => 0,
+ #'POE::Filter::Line' => 0,
# misc perl stuff
'Time::HiRes' => 0,
'version' => 0,
'Devel::Hide' => 0,
# Analyzer reqs
'YAML::Tiny' => 0,
# GetPOEdists reqs
'LWP::UserAgent' => 0,
'HTML::LinkExtor' => 0,
'URI::URL' => 0,
'Archive::Tar' => 0,
# Imager reqs
'GD::Graph::lines' => 0,
'Class::Accessor::Fast' => 0,
'Module::Pluggable' => 0,
# Test stuff
'Test::More' => '0.86', # require latest for note() support in t/a_is_prereq_outdated.t
},
'recommends' => {
# our POE loops!
'POE::Loop::Event' => 0,
'POE::Loop::Event_Lib' => 0,
'POE::Loop::EV' => 0,
'POE::Loop::Glib' => 0,
'POE::Loop::Prima' => 0,
'POE::Loop::Gtk' => 0,
'POE::Loop::Wx' => 0,
'POE::Loop::Kqueue' => 0,
# included in POE ( listed here for completeness )
#'POE::Loop::Tk' => 0,
#'POE::Loop::Select' => 0,
#'POE::Loop::IO_Poll' => 0,
# the loops' dependencies
'Event' => 0,
'Event::Lib' => 0,
'EV' => 0,
'Glib' => 0,
'Prima' => 0,
'Gtk' => 0,
'Wx' => 0,
'Tk' => 0,
# the XS queue
'POE::XS::Queue::Array' => 0,
},
# FIXME wishlist...
# 'test_requires' => {
# # Test stuff
# 'Test::Compile' => 0,
# 'Test::Perl::Critic' => 0,
# 'Test::Dependencies' => 0,
# 'Test::Distribution' => 0,
# 'Test::Fixme' => 0,
# 'Test::HasVersion' => 0,
# 'Test::Kwalitee' => 0,
# 'Test::CheckManifest' => 0,
# 'Test::MinimumVersion' => 0,
# 'Test::Pod::Coverage' => 0,
# 'Test::Spelling' => 0,
# 'Test::Pod' => 0,
# 'Test::Prereq' => 0,
# 'Test::Strict' => 0,
# 'Test::UseAllModules' => 0,
# },
);
# all done!
$build->create_build_script;
diff --git a/lib/POE/Devel/Benchmarker.pm b/lib/POE/Devel/Benchmarker.pm
index 24d2c6c..9ae396d 100644
--- a/lib/POE/Devel/Benchmarker.pm
+++ b/lib/POE/Devel/Benchmarker.pm
@@ -1,889 +1,888 @@
# Declare our package
package POE::Devel::Benchmarker;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
-$VERSION = '0.04';
+$VERSION = '0.05';
# auto-export the only sub we have
use base qw( Exporter );
our @EXPORT = qw( benchmark );
# Import what we need from the POE namespace
use POE qw( Session Filter::Line Wheel::Run );
use base 'POE::Session::AttributeBased';
# we need hires times
use Time::HiRes qw( time );
# load comparison stuff
use version;
# use the power of YAML
use YAML::Tiny;
# Load our stuff
use POE::Devel::Benchmarker::GetInstalledLoops;
use POE::Devel::Benchmarker::Utils qw( poeloop2load knownloops generateTestfile );
use POE::Devel::Benchmarker::Analyzer;
# Actually run the tests!
sub benchmark {
my $options = shift;
# set default options
my $lite_tests = 1;
my $quiet_mode = 0;
my $forceloops = undef; # default to autoprobe all
my $forcepoe = undef; # default to all found POE versions in poedists/
my $forcenoxsqueue = 0; # default to try and load it
my $forcenoasserts = 0; # default is to run it
my $freshstart = 0; # always resume where we left off
# process our options
if ( defined $options and ref $options and ref( $options ) eq 'HASH' ) {
# process YES for freshstart
if ( exists $options->{'freshstart'} ) {
if ( $options->{'freshstart'} ) {
$freshstart = 1;
}
}
# process NO for XS::Queue::Array
if ( exists $options->{'noxsqueue'} ) {
if ( $options->{'noxsqueue'} ) {
$forcenoxsqueue = 1;
}
}
# process NO for ASSERT
if ( exists $options->{'noasserts'} ) {
if ( $options->{'noasserts'} ) {
$forcenoasserts = 1;
}
}
# process LITE tests
if ( exists $options->{'litetests'} ) {
if ( $options->{'litetests'} ) {
$lite_tests = 1;
} else {
$lite_tests = 0;
}
}
# process quiet mode
if ( exists $options->{'quiet'} ) {
if ( $options->{'quiet'} ) {
$quiet_mode = 1;
} else {
$quiet_mode = 0;
}
}
# process forceloops
if ( exists $options->{'loop'} and defined $options->{'loop'} ) {
if ( ! ref $options->{'loop'} ) {
# split it via CSV
$forceloops = [ split( /,/, $options->{'loop'} ) ];
foreach ( @$forceloops ) {
$_ =~ s/^\s+//; $_ =~ s/\s+$//;
}
} else {
# treat it as array
$forceloops = $options->{'loop'};
}
# check for !loop modules
my @noloops;
foreach my $l ( @$forceloops ) {
if ( $l =~ /^\!/ ) {
push( @noloops, substr( $l, 1 ) );
}
}
if ( scalar @noloops ) {
# replace the forceloops with ALL known, then subtract noloops from it
my %bad;
@bad{@noloops} = () x @noloops;
@$forceloops = grep { !exists $bad{$_} } @{ knownloops() };
}
}
# process the poe versions
if ( exists $options->{'poe'} and defined $options->{'poe'} ) {
if ( ! ref $options->{'poe'} ) {
# split it via CSV
$forcepoe = [ split( /,/, $options->{'poe'} ) ];
foreach ( @$forcepoe ) {
$_ =~ s/^\s+//; $_ =~ s/\s+$//;
}
} else {
# treat it as array
$forcepoe = $options->{'poe'};
}
}
}
# do some sanity checks
if ( ! -d 'poedists' ) {
die "The 'poedists' directory is not found in the working directory!";
}
if ( ! -d 'results' ) {
die "The 'results' directory is not found in the working directory!";
}
if ( ! $quiet_mode ) {
print "[BENCHMARKER] Starting up...\n";
}
# Create our session
POE::Session->create(
__PACKAGE__->inline_states(),
'heap' => {
# misc stuff
'quiet_mode' => $quiet_mode,
# override our testing behavior
'lite_tests' => $lite_tests,
'forceloops' => $forceloops,
'forcepoe' => $forcepoe,
'forcenoxsqueue' => $forcenoxsqueue,
'forcenoasserts' => $forcenoasserts,
'freshstart' => $freshstart,
},
);
# Fire 'er up!
POE::Kernel->run();
return;
}
# Starts up our session
sub _start : State {
# okay, get all the dists we can!
my @versions;
if ( opendir( DISTS, 'poedists' ) ) {
foreach my $d ( readdir( DISTS ) ) {
if ( $d =~ /^POE\-(.+)$/ and $d !~ /\.tar\.gz$/ ) {
# FIXME skip POE < 0.13 because I can't get it to work
my $ver = version->new( $1 );
if ( $ver > v0.12 ) {
push( @versions, $ver );
}
}
}
closedir( DISTS ) or die $!;
} else {
print "[BENCHMARKER] Unable to open 'poedists' for reading: $!\n";
return;
}
# should we munge the versions list?
if ( defined $_[HEAP]->{'forcepoe'} ) {
# check for !poe versions
my @nopoe;
foreach my $p ( @{ $_[HEAP]->{'forcepoe'} } ) {
if ( $p =~ /^\!/ ) {
push( @nopoe, substr( $p, 1 ) );
}
}
if ( scalar @nopoe ) {
# remove the nopoe versions from the found
my %bad;
@bad{@nopoe} = () x @nopoe;
@versions = grep { !exists $bad{$_->stringify} } @versions;
} else {
# make sure the @versions contains only what we specified
my %good;
@good{ @{ $_[HEAP]->{'forcepoe'} } } = () x @{ $_[HEAP]->{'forcepoe'} };
@versions = grep { exists $good{$_->stringify} } @versions;
}
}
# sanity
if ( ! scalar @versions ) {
print "[BENCHMARKER] Unable to find any POE version in the 'poedists' directory!\n";
return;
}
# set our alias
$_[KERNEL]->alias_set( 'Benchmarker' );
# sanely handle some signals
$_[KERNEL]->sig( 'INT', 'handle_kill' );
$_[KERNEL]->sig( 'TERM', 'handle_kill' );
# okay, go through all the dists in version order
@versions = sort { $a <=> $b } @versions;
# Store the versions in our heap
$_[HEAP]->{'VERSIONS'} = \@versions;
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Detected available POE versions -> " . join( " ", @versions ) . "\n";
}
# First of all, we need to find out what loop libraries are installed
getPOEloops( $_[HEAP]->{'quiet_mode'}, $_[HEAP]->{'forceloops'} );
return;
}
sub _stop : State {
# tell the wheel to kill itself
if ( defined $_[HEAP]->{'WHEEL'} ) {
$_[HEAP]->{'WHEEL'}->kill( 9 );
undef $_[HEAP]->{'WHEEL'};
}
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Shutting down...\n";
}
return;
}
# misc POE handlers
sub _child : State {
return;
}
sub handle_kill : State {
return;
}
# we received list of loops from GetInstalledLoops
sub found_loops : State {
$_[HEAP]->{'installed_loops'} = [ sort { $a cmp $b } @{ $_[ARG0] } ];
# sanity check
if ( scalar @{ $_[HEAP]->{'installed_loops'} } == 0 ) {
print "[BENCHMARKER] Detected no available POE::Loop, check your configuration?!?\n";
return;
}
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Detected available POE::Loops -> " . join( " ", @{ $_[HEAP]->{'installed_loops'} } ) . "\n";
}
# Okay, do we have XS::Queue installed?
if ( ! $_[HEAP]->{'forcenoxsqueue'} ) {
eval { require POE::XS::Queue::Array };
if ( $@ ) {
$_[HEAP]->{'forcenoxsqueue'} = 1;
}
}
# Fire up the analyzer
initAnalyzer( $_[HEAP]->{'quiet_mode'} );
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Starting the benchmarks!" .
( $_[HEAP]->{'forcenoxsqueue'} ? ' Skipping XS::Queue Tests!' : '' ) .
( $_[HEAP]->{'forcenoasserts'} ? ' Skipping ASSERT Tests!' : '' ) .
"\n";
}
# start the benchmark!
$_[KERNEL]->yield( 'run_benchmark' );
return;
}
# Runs one benchmark
sub run_benchmark : State {
# Grab the version from the top of the array
$_[HEAP]->{'current_version'} = shift @{ $_[HEAP]->{'VERSIONS'} };
# did we run out of versions?
if ( ! defined $_[HEAP]->{'current_version'} ) {
# We're done, let POE die...
$_[KERNEL]->alias_remove( 'Benchmarker' );
} else {
$_[HEAP]->{'loops'} = [ @{ $_[HEAP]->{'installed_loops'} } ];
# okay, fire off the first loop
$_[KERNEL]->yield( 'bench_loop' );
}
return;
}
# runs one loop
sub bench_loop : State {
# select our current loop
$_[HEAP]->{'current_loop'} = shift @{ $_[HEAP]->{'loops'} };
# are we done with all loops?
if ( ! defined $_[HEAP]->{'current_loop'} ) {
# yay, go back to the main handler
$_[KERNEL]->yield( 'run_benchmark' );
} else {
# Start the assert test
if ( $_[HEAP]->{'forcenoasserts'} ) {
$_[HEAP]->{'assertions'} = [ qw( 0 ) ];
} else {
$_[HEAP]->{'assertions'} = [ qw( 0 1 ) ];
}
$_[KERNEL]->yield( 'bench_asserts' );
}
return;
}
# runs an assertion
sub bench_asserts : State {
# select our current assert state
$_[HEAP]->{'current_assertions'} = shift @{ $_[HEAP]->{'assertions'} };
# are we done?
if ( ! defined $_[HEAP]->{'current_assertions'} ) {
# yay, go back to the loop handler
$_[KERNEL]->yield( 'bench_loop' );
} else {
# Start the xsqueue test
if ( $_[HEAP]->{'forcenoxsqueue'} ) {
$_[HEAP]->{'noxsqueue'} = [ qw( 1 ) ];
} else {
$_[HEAP]->{'noxsqueue'} = [ qw( 0 1 ) ];
}
$_[KERNEL]->yield( 'bench_xsqueue' );
}
return;
}
# runs test with or without xsqueue
sub bench_xsqueue : State {
# select our current noxsqueue state
$_[HEAP]->{'current_noxsqueue'} = shift @{ $_[HEAP]->{'noxsqueue'} };
# are we done?
if ( ! defined $_[HEAP]->{'current_noxsqueue'} ) {
# yay, go back to the assert handler
$_[KERNEL]->yield( 'bench_asserts' );
} else {
# do some careful analysis
$_[KERNEL]->yield( 'bench_checkprevioustest' );
}
return;
}
# Checks to see if this test was run in the past
sub bench_checkprevioustest : State {
# okay, do we need to check and see if we already did this test?
if ( ! $_[HEAP]->{'freshstart'} ) {
# determine the file used
my $file = generateTestfile( $_[HEAP] );
# does it exist?
if ( -e "results/$file.yml" and -f _ and -s _ ) {
# okay, sanity check it
my $yaml = YAML::Tiny->read( "results/$file.yml" );
if ( defined $yaml ) {
# inrospect it!
my $isvalid = 0;
eval {
# simple sanity check: the "x_bench" param is at the end of the YML, so if it loads fine we know it's there
if ( exists $yaml->[0]->{'x_bench'} ) {
# version must at least match us
$isvalid = ( $yaml->[0]->{'x_bench'} eq $POE::Devel::Benchmarker::VERSION ? 1 : 0 );
} else {
$isvalid = undef;
}
};
if ( $isvalid ) {
# yay, this test is A-OK!
$_[KERNEL]->yield( 'bench_xsqueue' );
return;
} else {
# was it truncated?
if ( ! defined $isvalid ) {
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] YAML file($file) from previous test was corrupt!\n";
}
}
}
} else {
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Unable to load YAML file($file) from previous test run: " . YAML::Tiny->errstr . "\n";
}
}
}
}
# could not find previous file or FRESHSTART, proceed normally
$_[KERNEL]->yield( 'create_subprocess' );
return;
}
# actually runs the subprocess
sub create_subprocess : State {
# Okay, start testing this specific combo!
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "Testing " . generateTestfile( $_[HEAP] ) . "\n";
}
# save the starttime
$_[HEAP]->{'current_starttime'} = time();
$_[HEAP]->{'current_starttimes'} = [ times() ];
# Okay, create the wheel::run to handle this
my $looploader = poeloop2load( $_[HEAP]->{'current_loop'} );
$_[HEAP]->{'WHEEL'} = POE::Wheel::Run->new(
'Program' => $^X,
'ProgramArgs' => [ '-Ipoedists/POE-' . $_[HEAP]->{'current_version'},
'-Ipoedists/POE-' . $_[HEAP]->{'current_version'} . '/lib',
( defined $looploader ? "-M$looploader" : () ),
'-MPOE::Devel::Benchmarker::SubProcess',
'-e',
'POE::Devel::Benchmarker::SubProcess::benchmark',
- $_[HEAP]->{'current_version'},
$_[HEAP]->{'current_loop'},
$_[HEAP]->{'current_assertions'},
$_[HEAP]->{'lite_tests'},
$_[HEAP]->{'current_noxsqueue'},
],
# Kill off existing FD's
'CloseOnCall' => 1,
# setup our data handlers
'StdoutEvent' => 'Got_STDOUT',
'StderrEvent' => 'Got_STDERR',
# the error handler
'ErrorEvent' => 'Got_ERROR',
'CloseEvent' => 'Got_CLOSED',
# set our filters
'StderrFilter' => POE::Filter::Line->new(),
'StdoutFilter' => POE::Filter::Line->new(),
);
if ( ! defined $_[HEAP]->{'WHEEL'} ) {
die 'Unable to create a new wheel!';
} else {
# smart CHLD handling
if ( $_[KERNEL]->can( "sig_child" ) ) {
$_[KERNEL]->sig_child( $_[HEAP]->{'WHEEL'}->PID => 'Got_CHLD' );
} else {
$_[KERNEL]->sig( 'CHLD', 'Got_CHLD' );
}
}
# setup our data we received from the subprocess
$_[HEAP]->{'current_data'} = '';
# Okay, we timeout this test after some time for sanity
$_[HEAP]->{'test_timedout'} = 0;
if ( $_[HEAP]->{'lite_tests'} ) {
# on my core2duo 1.2ghz laptop, running Gtk+LITE+assert+noxsqueue takes approx 45s
$_[HEAP]->{'TIMER'} = $_[KERNEL]->delay_set( 'test_timedout' => 60 * 2 );
} else {
# on my core2duo 1.2ghz laptop, running Gtk+HEAVY+assert+noxsqueue takes all day long :(
$_[HEAP]->{'TIMER'} = $_[KERNEL]->delay_set( 'test_timedout' => 60 * 15 );
}
return;
}
# Got a CHLD event!
sub Got_CHLD : State {
$_[KERNEL]->sig_handled();
return;
}
# Handles child STDERR output
sub Got_STDERR : State {
my $input = $_[ARG0];
# skip empty lines
if ( $input ne '' ) {
# save it!
$_[HEAP]->{'current_data'} .= '!STDERR: ' . $input . "\n";
}
return;
}
# Handles child STDOUT output
sub Got_STDOUT : State {
my $input = $_[ARG0];
# save it!
$_[HEAP]->{'current_data'} .= $input . "\n";
return;
}
# Handles child error
sub Got_ERROR : State {
# Copied from POE::Wheel::Run manpage
my ( $operation, $errnum, $errstr ) = @_[ ARG0 .. ARG2 ];
# ignore exit 0 errors
if ( $errnum != 0 ) {
print "[BENCHMARKER] Wheel::Run got an $operation error $errnum: $errstr\n";
}
return;
}
# Handles child DIE'ing
sub Got_CLOSED : State {
# Get rid of the wheel
undef $_[HEAP]->{'WHEEL'};
# get rid of the delay
$_[KERNEL]->alarm_remove( $_[HEAP]->{'TIMER'} );
undef $_[HEAP]->{'TIMER'};
# wrap up this test
$_[KERNEL]->yield( 'wrapup_test' );
return;
}
# a test timed out, unfortunately!
sub test_timedout : State {
# tell the wheel to kill itself
$_[HEAP]->{'WHEEL'}->kill( 9 );
undef $_[HEAP]->{'WHEEL'};
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Test Timed Out!\n";
}
$_[HEAP]->{'test_timedout'} = 1;
# wrap up this test
$_[KERNEL]->yield( 'wrapup_test' );
return;
}
# finalizes a test
sub wrapup_test : State {
# we're done with this benchmark!
$_[HEAP]->{'current_endtime'} = time();
$_[HEAP]->{'current_endtimes'} = [ times() ];
# store the data
my $file = generateTestfile( $_[HEAP] );
if ( open( my $fh, '>', "results/$file" ) ) {
print $fh "STARTTIME: " . $_[HEAP]->{'current_starttime'} . " -> TIMES " . join( " ", @{ $_[HEAP]->{'current_starttimes'} } ) . "\n";
print $fh "$file\n";
print $fh $_[HEAP]->{'current_data'} . "\n";
if ( $_[HEAP]->{'test_timedout'} ) {
print $fh "\nTEST TERMINATED DUE TO TIMEOUT\n";
}
print $fh "ENDTIME: " . $_[HEAP]->{'current_endtime'} . " -> TIMES " . join( " ", @{ $_[HEAP]->{'current_endtimes'} } ) . "\n";
close( $fh ) or die $!;
} else {
print "[BENCHMARKER] Unable to open results/$file for writing -> $!\n";
}
# Send the data to the Analyzer to process
$_[KERNEL]->post( 'Benchmarker::Analyzer', 'analyze', {
'poe' => {
'v' => $_[HEAP]->{'current_version'}->stringify, # YAML::Tiny doesn't like version objects :(
'loop' => 'POE::Loop::' . $_[HEAP]->{'current_loop'},
},
't' => {
's_ts' => $_[HEAP]->{'current_starttime'},
'e_ts' => $_[HEAP]->{'current_endtime'},
'd' => $_[HEAP]->{'current_endtime'} - $_[HEAP]->{'current_starttime'},
's_t' => [ @{ $_[HEAP]->{'current_starttimes'} } ],
'e_t' => [ @{ $_[HEAP]->{'current_endtimes'} } ],
},
'raw' => $_[HEAP]->{'current_data'},
'test' => $file,
'x_bench' => $POE::Devel::Benchmarker::VERSION,
( $_[HEAP]->{'test_timedout'} ? ( 'timedout' => 1 ) : () ),
( $_[HEAP]->{'lite_tests'} ? ( 'litetests' => 1 ) : () ),
( $_[HEAP]->{'current_assertions'} ? ( 'asserts' => 1 ) : () ),
( $_[HEAP]->{'current_noxsqueue'} ? ( 'noxsqueue' => 1 ) : () ),
} );
# process the next test
$_[KERNEL]->yield( 'bench_xsqueue' );
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker - Benchmarking POE's performance ( acts more like a smoker )
=head1 SYNOPSIS
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker -e 'benchmark()'
=head1 ABSTRACT
This package of tools is designed to benchmark POE's performace across different
configurations. The current "tests" are:
=over 4
=item posts
This tests how long it takes to post() N times
This tests how long it took to dispatch/deliver all the posts enqueued in the post() test
This tests how long it took to yield() between 2 states for N times
=item calls
This tests how long it took to call() N times
=item alarms
This tests how long it took to add N alarms via alarm(), overwriting each other
This tests how long it took to add N alarms via alarm_add() and how long it took to delete them all
NOTE: alarm_add is not available on all versions of POE!
=item sessions
This tests how long it took to create N sessions, and how long it took to destroy them all
=item filehandles
This tests how long it took to toggle select_read N times on STDIN and a real filehandle via open()
This tests how long it took to toggle select_write N times on STDIN and a real filehandle via open()
=item POE startup time
This tests how long it took to start + close N instances of a "virgin" POE without any sessions/etc
=item POE Loops
This is actually a "super" test where all of the specific tests is ran against various POE::Loop::XYZ/FOO for comparison
=item POE Assertions
This is actually a "super" test where all of the specific tests is ran against POE with/without assertions enabled
=item POE::XS::Queue::Array
This is actually a "super" test where all of the specific tests is ran against POE with XS goodness enabled/disabled
=back
=head1 DESCRIPTION
This module is poorly documented now. Please give me some time to properly document it over time :)
=head2 INSTALLATION
Here's a simple outline to get you up to speed quickly. ( and smoking! )
=over 4
=item Install CPAN package + dependencies
Download+install the POE::Devel::Benchmarker package from CPAN
apoc@apoc-x300:~$ cpanp -i POE::Devel::Benchmarker
=item Setup initial directories
Go anywhere, and create the "parent" directory where you'll be storing test results + stuff. For this example,
I have chosen to use ~/poe-benchmarker:
apoc@apoc-x300:~$ mkdir poe-benchmarker
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ mkdir poedists results images
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker::GetPOEdists -e 'getPOEdists( 1 )'
( go get a coffee while it downloads if you're on a slow link, ha! )
=item Let 'er rip!
At this point you can start running the benchmark!
NOTE: the Benchmarker expects everything to be in the "local" directory!
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker -e 'benchmark()'
( go sleep or something, this will take a while! )
=back
=head2 BENCHMARKING
On startup the Benchmarker will look in the "poedists" directory and load all the distributions it sees untarred there. Once
that is done it will begin autoprobing for available POE::Loop packages. Once it determines what's available, it will begin
the benchmarks.
As the Benchmarker goes through the combinations of POE + Eventloop + Assertions + XS::Queue it will dump data into
the results directory. The Analyzer module also dumps YAML output in the same place, with the suffix of ".yml"
This module exposes only one subroutine, the benchmark() one. You can pass a hashref to it to set various options. Here is
a list of the valid options:
=over 4
=item freshstart => boolean
This will tell the Benchmarker to ignore any previous test runs stored in the 'results' directory.
benchmark( { freshstart => 1 } );
default: false
=item noxsqueue => boolean
This will tell the Benchmarker to force the unavailability of POE::XS::Queue::Array and skip those tests.
NOTE: The Benchmarker will set this automatically if it cannot load the module!
benchmark( { noxsqueue => 1 } );
default: false
=item noasserts => boolean
This will tell the Benchmarker to not run the ASSERT tests.
benchmark( { noasserts => 1 } );
default: false
=item litetests => boolean
This enables the "lite" tests which will not take up too much time.
benchmark( { litetests => 0 } );
default: true
=item quiet => boolean
This enables quiet mode which will not print anything to the console except for errors.
benchmark( { 'quiet' => 1 } );
default: false
=item loop => csv list or array
This overrides the built-in loop detection algorithm which searches for all known loops.
There is some "magic" here where you can put a negative sign in front of a loop and we will NOT run that.
NOTE: Capitalization is important!
benchmark( { 'loop' => 'IO_Poll,Select' } ); # runs only IO::Poll and Select
benchmark( { 'loop' => [ qw( Tk Gtk ) ] } ); # runs only Tk and Gtk
benchmark( { 'loop' => '-Tk' } ); # runs all available loops EXCEPT for TK
Known loops: Event_Lib EV Glib Prima Gtk Kqueue Tk Select IO_Poll
=item poe => csv list or array
This overrides the built-in POE version detection algorithm which pulls the POE versions from the 'poedists' directory.
There is some "magic" here where you can put a negative sign in front of a version and we will NOT run that.
NOTE: The Benchmarker will ignore versions that wasn't found in the directory!
benchmark( { 'poe' => '0.35,1.003' } ); # runs on 0.35 and 1.003
benchmark( { 'poe' => [ qw( 0.3009 0.12 ) ] } ); # runs on 0.3009 and 0.12
benchmark( { 'poe' => '-0.35' } ); # runs ALL tests except 0.35
=back
=head2 ANALYZING RESULTS
Please look at the pretty charts generated by the L<POE::Devel::Benchmarker::Imager> module.
=head1 EXPORT
Automatically exports the benchmark() subroutine.
=head1 TODO
=over 4
=item Perl version smoking
We should be able to run the benchmark over different Perl versions. This would require some fiddling with our
layout + logic. It's not that urgent because the workaround is to simply execute the benchmarker under a different
perl binary. It's smart enough to use $^X to be consistent across tests/subprocesses :)
=item Select the EV backend
<Khisanth> and if you are benchmarking, try it with POE using EV with EV using Glib? :P
<Apocalypse> I'm not sure how to configure the EV "backend" yet
<Apocalypse> too much docs for me to read hah
<Khisanth> Apocalypse: use EV::Glib; use Glib; use POE; :)
=item Be smarter in smoking timeouts
Currently we depend on the litetests option and hardcode some values including the timeout. If your machine is incredibly
slow, there's a chance that it could timeout unnecessarily. Please look at the outputs and check to see if there are unusual
failures, and inform me.
Also, some loops perform badly and take almost forever! /me glares at Gtk...
=item More benchmarks!
As usual, me and the crowd in #poe have plenty of ideas for tests. We'll be adding them over time, but if you have an idea please
drop me a line and let me know!
dngor said there was some benchmarks in the POE svn under trunk/queue...
I want a bench that actually tests socket traffic - stream 10MB of traffic over localhost, and time it?
LotR and Tapout contributed some samples, let's see if I can integrate them...
=item Add SQLite/DBI/etc support to the Analyzer
It would be nice if we could have a local SQLite db to dump our stats into. This would make arbitrary reports much easier than
loading raw YAML files and trying to make sense of them, ha! Also, this means somebody can do the smoking and send the SQLite
db to another person to generate the graphs, cool!
=item Kqueue loop support
As I don't have access to a *BSD box, I cannot really test this. Furthermore, it isn't clear on how I can force/unload this
module from POE...
=item Wx loop support
I have Wx installed, but it doesn't work. Obviously I don't know how to use Wx ;)
If you have experience, please drop me a line on how to do the "right" thing to get Wx loaded under POE. Here's the error:
Can't call method "MainLoop" on an undefined value at /usr/local/share/perl/5.8.8/POE/Loop/Wx.pm line 91.
=item XS::Loop support
The POE::XS::Loop::* modules theoretically could be tested too. However, they will only work in POE >= 1.003! This renders
the concept somewhat moot. Maybe, after POE has progressed some versions we can implement this...
=back
=head1 SEE ALSO
L<POE>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
BIG THANKS goes to Rocco Caputo E<lt>rcaputo@cpan.orgE<gt> for the first benchmarks!
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/Analyzer.pm b/lib/POE/Devel/Benchmarker/Analyzer.pm
index 87f4961..76352f0 100644
--- a/lib/POE/Devel/Benchmarker/Analyzer.pm
+++ b/lib/POE/Devel/Benchmarker/Analyzer.pm
@@ -1,448 +1,448 @@
# Declare our package
package POE::Devel::Benchmarker::Analyzer;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
-$VERSION = '0.04';
+$VERSION = '0.05';
# auto-export the only sub we have
use base qw( Exporter );
our @EXPORT = qw( initAnalyzer );
# Import what we need from the POE namespace
use POE qw( Session );
use base 'POE::Session::AttributeBased';
# use the power of YAML
use YAML::Tiny qw( Dump );
# Load the utils
use POE::Devel::Benchmarker::Utils qw( beautify_times );
# fires up the engine
sub initAnalyzer {
my $quiet_mode = shift;
# create our session!
POE::Session->create(
__PACKAGE__->inline_states(),
'heap' => {
'quiet_mode' => $quiet_mode,
},
);
}
# Starts up our session
sub _start : State {
# set our alias
$_[KERNEL]->alias_set( 'Benchmarker::Analyzer' );
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[ANALYZER] Starting up...\n";
}
return;
}
sub _stop : State {
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[ANALYZER] Shutting down...\n";
}
return;
}
sub _child : State {
return;
}
sub analyze : State {
# get the data
my $test = $_[ARG0];
# clean up the times() stuff
$test->{'t'}->{'t'} = beautify_times(
join( " ", @{ delete $test->{'t'}->{'s_t'} } ) .
" " .
join( " ", @{ delete $test->{'t'}->{'e_t'} } )
);
# setup the perl version
$test->{'perl'}->{'v'} = sprintf( "%vd", $^V );
# Okay, break it down into our data struct
$test->{'metrics'} = {};
my $d = $test->{'metrics'};
my @unknown;
foreach my $l ( split( /(?:\n|\r)/, $test->{'raw'} ) ) {
# skip empty lines
if ( $l eq '' ) { next }
# usual test benchmark output
# 10 startups in 0.885 seconds ( 11.302 per second)
# 10000 posts in 0.497 seconds ( 20101.112 per second)
if ( $l =~ /^\s+\d+\s+(\w+)\s+in\s+([\d\.]+)\s+seconds\s+\(\s+([\d\.]+)\s+per\s+second\)$/ ) {
$d->{ $1 }->{'d'} = $2; # duration in seconds
$d->{ $1 }->{'i'} = $3; # iterations per second
# usual test benchmark times output
# startup times: 0.1 0 0 0 0.1 0 0.76 0.09
} elsif ( $l =~ /^(\w+)\s+times:\s+(.+)$/ ) {
$d->{ $1 }->{'t'} = beautify_times( $2 ); # the times hash
# parse the memory footprint stuff
} elsif ( $l =~ /^pidinfo:\s+(.+)$/ ) {
# what should we analyze?
my $pidinfo = $1;
# VmPeak: 16172 kB
if ( $pidinfo =~ /^VmPeak:\s+(.+)$/ ) {
$test->{'pid'}->{'vmpeak'} = $1;
# voluntary_ctxt_switches: 10
} elsif ( $pidinfo =~ /^voluntary_ctxt_switches:\s+(.+)$/ ) {
$test->{'pid'}->{'vol_ctxt'} = $1;
# nonvoluntary_ctxt_switches: 1221
} elsif ( $pidinfo =~ /^nonvoluntary_ctxt_switches:\s+(.+)$/ ) {
$test->{'pid'}->{'nonvol_ctxt'} = $1;
} else {
# ignore the rest of the fluff
}
# parse the perl binary stuff
} elsif ( $l =~ /^perlconfig:\s+(.+)$/ ) {
# what should we analyze?
my $perlconfig = $1;
# ignore the fluff ( not needed now... )
# parse the CPU info
} elsif ( $l =~ /^cpuinfo:\s+(.+)$/ ) {
# what should we analyze?
my $cpuinfo = $1;
# FIXME if this is on a multiproc system, we will overwrite the data per processor ( harmless? )
# cpu MHz : 1201.000
if ( $cpuinfo =~ /^cpu\s+MHz\s+:\s+(.+)$/ ) {
$test->{'cpu'}->{'mhz'} = $1;
# model name : Intel(R) Core(TM)2 Duo CPU L7100 @ 1.20GHz
} elsif ( $cpuinfo =~ /^model\s+name\s+:\s+(.+)$/ ) {
$test->{'cpu'}->{'name'} = $1;
# bogomips : 2397.58
} elsif ( $cpuinfo =~ /^bogomips\s+:\s+(.+)$/ ) {
$test->{'cpu'}->{'bogo'} = $1;
} else {
# ignore the rest of the fluff
}
# data that we can safely throw away
} elsif ( $l eq 'Using NO Assertions!' or
$l eq 'Using FULL Assertions!' or
$l eq 'Using the LITE tests' or
$l eq 'Using the HEAVY tests' or
$l eq 'DISABLING POE::XS::Queue::Array' or
$l eq '!STDERR: Devel::Hide hides POE/XS/Queue/Array.pm' or
$l eq 'LETTING POE find POE::XS::Queue::Array' or
$l eq 'UNABLE TO GET /proc/self/status' or
$l eq 'UNABLE TO GET /proc/cpuinfo' or
$l eq '!STDERR: POE::Kernel\'s run() method was never called.' or # to ignore old POEs that threw this warning
$l eq 'TEST TERMINATED DUE TO TIMEOUT' ) {
# ignore them
# parse the perl binary stuff
} elsif ( $l =~ /^Running\s+under\s+perl\s+binary:\s+(.+)$/ ) {
$test->{'perl'}->{'binary'} = $1;
# the master loop version ( what the POE::Loop::XYZ actually uses )
# Using loop: EV-3.49
} elsif ( $l =~ /^Using\s+master\s+loop:\s+(.+)$/ ) {
$test->{'poe'}->{'loop_m'} = $1;
# the real POE version that was loaded
# Using POE-1.001
} elsif ( $l =~ /^Using\s+POE-(.+)$/ ) {
$test->{'poe'}->{'v_real'} = $1;
# the various queue/loop modules we loaded
# POE is using: POE::XS::Queue::Array v0.005
# POE is using: POE::Queue v1.2328
# POE is using: POE::Loop::EV v0.06
} elsif ( $l =~ /^POE\s+is\s+using:\s+([^\s]+)\s+v(.+)$/ ) {
$test->{'poe'}->{'modules'}->{ $1 } = $2;
# get the uname info
# Running under machine: Linux apoc-x300 2.6.24-21-generic #1 SMP Tue Oct 21 23:43:45 UTC 2008 i686 GNU/Linux
} elsif ( $l =~ /^Running\s+under\s+machine:\s+(.+)$/ ) {
$test->{'uname'} = $1;
# parse the SKIP tests
# SKIPPING MYFH tests on broken loop: Event_Lib
# SKIPPING STDIN tests on broken loop: Tk
} elsif ( $l =~ /^SKIPPING\s+(\w+)\s+tests\s+on\s+broken/ ) {
my $fh = $1;
# nullify the data struct for that
foreach my $type ( qw( select_read select_write ) ) {
$d->{ $type . $fh }->{'d'} = undef;
$d->{ $type . $fh }->{'t'} = undef;
$d->{ $type . $fh }->{'i'} = undef;
}
# parse the FH/STDIN failures
# filehandle select_read on STDIN FAILED: error
# filehandle select_write on MYFH FAILED: foo
} elsif ( $l =~ /^filehandle\s+(\w+)\s+on\s+(\w+)\s+FAILED:/ ) {
my( $mode, $type ) = ( $1, $2 );
# nullify the data struct for that
$d->{ $mode . $type }->{'d'} = undef;
$d->{ $mode . $type }->{'t'} = undef;
$d->{ $mode . $type }->{'i'} = undef;
# parse the alarm_add skip
# alarm_add NOT SUPPORTED on this version of POE, skipping alarm_adds/alarm_clears tests!
} elsif ( $l =~ /^alarm_add\s+NOT\s+SUPPORTED\s+on/ ) {
# nullify the data struct for that
foreach my $type ( qw( alarm_adds alarm_clears ) ) {
$d->{ $type }->{'d'} = undef;
$d->{ $type }->{'t'} = undef;
$d->{ $type }->{'i'} = undef;
}
# parse any STDERR output
# !STDERR: unable to foo
} elsif ( $l =~ /^\!STDERR:\s+(.+)$/ ) {
push( @{ $test->{'stderr'} }, $1 );
} else {
# unknown line :(
push( @unknown, $l );
}
}
# Get rid of the rawdata
delete $test->{'raw'};
# Dump the unknowns
if ( @unknown ) {
print "[ANALYZER] Unknown output from benchmark -> " . Dump( \@unknown );
}
# Dump the data struct we have to the file.yml
my $yaml_file = 'results/' . delete $test->{'test'};
$yaml_file .= '.yml';
my $ret = open( my $fh, '>', $yaml_file );
if ( defined $ret ) {
print $fh Dump( $test );
if ( ! close( $fh ) ) {
print "[ANALYZER] Unable to close $yaml_file -> " . $! . "\n";
}
} else {
print "[ANALYZER] Unable to open $yaml_file for writing -> " . $! . "\n";
}
# all done!
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::Analyzer - Analyzes the output from the benchmarks
=head1 SYNOPSIS
Don't use this module directly. Please see L<POE::Devel::Benchmarker>
=head1 ABSTRACT
This package implements the guts of converting the raw data into a machine-readable format. Furthermore, it dumps the data
in YAML format.
=head1 DESCRIPTION
I promise you that once I've stabilized the YAML format I'll have it documented here :)
=head1 EXPORT
Automatically exports the initAnalyzer() sub
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
# sample test output ( from SubProcess v0.02 )
STARTTIME: 1229232743.49131 -> TIMES 0.24 0.01 11.2 0.32
POE-1.003-Select-LITE-assert-xsqueue
Using master loop: Select-BUILTIN
Using FULL Assertions!
Using the LITE tests
LETTING POE find POE::XS::Queue::Array
Using POE-1.003
POE is using: POE::Loop::Select v1.2355
POE is using: POE::XS::Queue::Array v0.005
POE is using: POE::Queue v1.2328
POE is using: POE::Loop::PerlSignals v1.2329
10 startups in 0.853 seconds ( 11.723 per second)
startups times: 0.09 0 0 0 0.09 0 0.73 0.11
10000 posts in 0.495 seconds ( 20211.935 per second)
posts times: 0.1 0 0.73 0.11 0.53 0.06 0.73 0.11
10000 dispatches in 1.113 seconds ( 8984.775 per second)
dispatches times: 0.53 0.06 0.73 0.11 1.64 0.06 0.73 0.11
10000 alarms in 1.017 seconds ( 9829.874 per second)
alarms times: 1.64 0.06 0.73 0.11 2.66 0.06 0.73 0.11
10000 alarm_adds in 0.523 seconds ( 19102.416 per second)
alarm_adds times: 2.66 0.06 0.73 0.11 3.18 0.06 0.73 0.11
10000 alarm_clears in 0.377 seconds ( 26540.332 per second)
alarm_clears times: 3.18 0.06 0.73 0.11 3.55 0.07 0.73 0.11
500 session_creates in 0.130 seconds ( 3858.918 per second)
session_creates times: 3.55 0.07 0.73 0.11 3.68 0.08 0.73 0.11
500 session_destroys in 0.172 seconds ( 2901.191 per second)
session_destroys times: 3.68 0.08 0.73 0.11 3.85 0.08 0.73 0.11
10000 select_read_STDIN in 1.823 seconds ( 5485.878 per second)
select_read_STDIN times: 3.85 0.08 0.73 0.11 5.66 0.08 0.73 0.11
10000 select_write_STDIN in 1.827 seconds ( 5472.283 per second)
select_write_STDIN times: 5.66 0.08 0.73 0.11 7.47 0.08 0.73 0.11
10000 select_read_MYFH in 1.662 seconds ( 6016.387 per second)
select_read_MYFH times: 7.47 0.08 0.73 0.11 9.12 0.1 0.73 0.11
10000 select_write_MYFH in 1.704 seconds ( 5868.537 per second)
select_write_MYFH times: 9.12 0.1 0.73 0.11 10.78 0.11 0.73 0.11
10000 calls in 0.222 seconds ( 45038.974 per second)
calls times: 10.78 0.11 0.73 0.11 11 0.11 0.73 0.11
10000 single_posts in 1.999 seconds ( 5003.473 per second)
single_posts times: 11 0.11 0.73 0.11 12.86 0.22 0.73 0.11
pidinfo: Name: perl
pidinfo: State: R (running)
pidinfo: Tgid: 16643
pidinfo: Pid: 16643
pidinfo: PPid: 16600
pidinfo: TracerPid: 0
pidinfo: Uid: 1000 1000 1000 1000
pidinfo: Gid: 1000 1000 1000 1000
pidinfo: FDSize: 32
pidinfo: Groups: 4 20 24 25 29 30 44 46 107 109 115 127 1000 1001
pidinfo: VmPeak: 14376 kB
pidinfo: VmSize: 14216 kB
pidinfo: VmLck: 0 kB
pidinfo: VmHWM: 11440 kB
pidinfo: VmRSS: 11292 kB
pidinfo: VmData: 9908 kB
pidinfo: VmStk: 84 kB
pidinfo: VmExe: 1044 kB
pidinfo: VmLib: 1872 kB
pidinfo: VmPTE: 24 kB
pidinfo: Threads: 1
pidinfo: SigQ: 0/16182
pidinfo: SigPnd: 0000000000000000
pidinfo: ShdPnd: 0000000000000000
pidinfo: SigBlk: 0000000000000000
pidinfo: SigIgn: 0000000000001000
pidinfo: SigCgt: 0000000180000000
pidinfo: CapInh: 0000000000000000
pidinfo: CapPrm: 0000000000000000
pidinfo: CapEff: 0000000000000000
pidinfo: Cpus_allowed: 03
pidinfo: Mems_allowed: 1
pidinfo: voluntary_ctxt_switches: 10
pidinfo: nonvoluntary_ctxt_switches: 512
Running under perl binary: /usr/bin/perl
perlconfig: Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
perlconfig: Platform:
perlconfig: osname=linux, osvers=2.6.15.7, archname=i486-linux-gnu-thread-multi
perlconfig: uname='linux palmer 2.6.15.7 #1 smp thu sep 7 19:42:20 utc 2006 i686 gnulinux '
perlconfig: config_args='-Dusethreads -Duselargefiles -Dccflags=-DDEBIAN -Dcccdlflags=-fPIC -Darchname=i486-linux-gnu -Dprefix=/usr -Dprivlib=/usr/share/perl/5.8 -Darchlib=/usr/lib/perl/5.8 -Dvendorprefix=/usr -Dvendorlib=/usr/share/perl5 -Dvendorarch=/usr/lib/perl5 -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl/5.8.8 -Dsitearch=/usr/local/lib/perl/5.8.8 -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 -Dsiteman1dir=/usr/local/man/man1 -Dsiteman3dir=/usr/local/man/man3 -Dman1ext=1 -Dman3ext=3perl -Dpager=/usr/bin/sensible-pager -Uafs -Ud_csh -Ud_ualarm -Uusesfio -Uusenm -Duseshrplib -Dlibperl=libperl.so.5.8.8 -Dd_dosuid -des'
perlconfig: hint=recommended, useposix=true, d_sigaction=define
perlconfig: usethreads=define use5005threads=undef useithreads=define usemultiplicity=define
perlconfig: useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
perlconfig: use64bitint=undef use64bitall=undef uselongdouble=undef
perlconfig: usemymalloc=n, bincompat5005=undef
perlconfig: Compiler:
perlconfig: cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBIAN -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
perlconfig: optimize='-O2',
perlconfig: cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBIAN -fno-strict-aliasing -pipe -I/usr/local/include'
perlconfig: ccversion='', gccversion='4.2.3 20071123 (prerelease) (Ubuntu 4.2.2-3ubuntu4)', gccosandvers=''
perlconfig: intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
perlconfig: d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
perlconfig: ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
perlconfig: alignbytes=4, prototype=define
perlconfig: Linker and Libraries:
perlconfig: ld='cc', ldflags =' -L/usr/local/lib'
perlconfig: libpth=/usr/local/lib /lib /usr/lib
perlconfig: libs=-lgdbm -lgdbm_compat -ldb -ldl -lm -lpthread -lc -lcrypt
perlconfig: perllibs=-ldl -lm -lpthread -lc -lcrypt
perlconfig: libc=/lib/libc-2.6.1.so, so=so, useshrplib=true, libperl=libperl.so.5.8.8
perlconfig: gnulibc_version='2.6.1'
perlconfig: Dynamic Linking:
perlconfig: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
perlconfig: cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib'
Running under machine: Linux apoc-x300 2.6.24-21-generic #1 SMP Tue Oct 21 23:43:45 UTC 2008 i686 GNU/Linux
cpuinfo: processor : 0
cpuinfo: vendor_id : GenuineIntel
cpuinfo: cpu family : 6
cpuinfo: model : 15
cpuinfo: model name : Intel(R) Core(TM)2 Duo CPU L7100 @ 1.20GHz
cpuinfo: stepping : 11
cpuinfo: cpu MHz : 1201.000
cpuinfo: cache size : 4096 KB
cpuinfo: physical id : 0
cpuinfo: siblings : 2
cpuinfo: core id : 0
cpuinfo: cpu cores : 2
cpuinfo: fdiv_bug : no
cpuinfo: hlt_bug : no
cpuinfo: f00f_bug : no
cpuinfo: coma_bug : no
cpuinfo: fpu : yes
cpuinfo: fpu_exception : yes
cpuinfo: cpuid level : 10
cpuinfo: wp : yes
cpuinfo: flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc arch_perfmon pebs bts pni monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr lahf_lm ida
cpuinfo: bogomips : 2397.58
cpuinfo: clflush size : 64
cpuinfo: processor : 1
cpuinfo: vendor_id : GenuineIntel
cpuinfo: cpu family : 6
cpuinfo: model : 15
cpuinfo: model name : Intel(R) Core(TM)2 Duo CPU L7100 @ 1.20GHz
cpuinfo: stepping : 11
cpuinfo: cpu MHz : 1201.000
cpuinfo: cache size : 4096 KB
cpuinfo: physical id : 0
cpuinfo: siblings : 2
cpuinfo: core id : 1
cpuinfo: cpu cores : 2
cpuinfo: fdiv_bug : no
cpuinfo: hlt_bug : no
cpuinfo: f00f_bug : no
cpuinfo: coma_bug : no
cpuinfo: fpu : yes
cpuinfo: fpu_exception : yes
cpuinfo: cpuid level : 10
cpuinfo: wp : yes
cpuinfo: flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc arch_perfmon pebs bts pni monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr lahf_lm ida
cpuinfo: bogomips : 2394.02
cpuinfo: clflush size : 64
ENDTIME: 1229232757.53804 -> TIMES 0.27 0.01 23.1 0.62
diff --git a/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm b/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm
index 87b8d6b..1efdd73 100644
--- a/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm
+++ b/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm
@@ -1,207 +1,207 @@
# Declare our package
package POE::Devel::Benchmarker::GetInstalledLoops;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
-$VERSION = '0.04';
+$VERSION = '0.05';
# auto-export the only sub we have
use base qw( Exporter );
our @EXPORT = qw( getPOEloops );
# Import what we need from the POE namespace
use POE qw( Session Filter::Line Wheel::Run );
use base 'POE::Session::AttributeBased';
# Get the utils
use POE::Devel::Benchmarker::Utils qw ( knownloops );
# analyzes the installed perl directory for available loops
sub getPOEloops {
my $quiet_mode = shift;
my $forceloops = shift;
# create our session!
POE::Session->create(
POE::Devel::Benchmarker::GetInstalledLoops->inline_states(),
'heap' => {
'quiet_mode' => $quiet_mode,
'loops' => $forceloops,
},
);
}
# Starts up our session
sub _start : State {
# set our alias
$_[KERNEL]->alias_set( 'Benchmarker::GetInstalledLoops' );
# load our known list of loops
# known impossible loops:
# XS::EPoll ( must be POE > 1.003 and weird way of loading )
# XS::Poll ( must be POE > 1.003 and weird way of loading )
if ( ! defined $_[HEAP]->{'loops'} ) {
$_[HEAP]->{'loops'} = knownloops();
}
# First of all, we need to find out what loop libraries are installed
$_[HEAP]->{'found_loops'} = [];
$_[KERNEL]->yield( 'find_loops' );
return;
}
sub _stop : State {
# tell the wheel to kill itself
if ( defined $_[HEAP]->{'WHEEL'} ) {
$_[HEAP]->{'WHEEL'}->kill( 9 );
undef $_[HEAP]->{'WHEEL'};
}
return;
}
# loops over the "known" loops and sees if they are installed
sub find_loops : State {
# get the loop to test
$_[HEAP]->{'current_loop'} = shift @{ $_[HEAP]->{'loops'} };
# do we have something to test?
if ( ! defined $_[HEAP]->{'current_loop'} ) {
# we're done!
$_[KERNEL]->alias_remove( 'Benchmarker::GetInstalledLoops' );
$_[KERNEL]->post( 'Benchmarker', 'found_loops', $_[HEAP]->{'found_loops'} );
return;
} else {
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[LOOPSEARCH] Trying to find if POE::Loop::" . $_[HEAP]->{'current_loop'} . " is installed...\n";
}
# set the flag
$_[HEAP]->{'test_failure'} = 0;
}
# Okay, create the wheel::run to handle this
$_[HEAP]->{'WHEEL'} = POE::Wheel::Run->new(
'Program' => $^X,
'ProgramArgs' => [ '-MPOE',
'-MPOE::Loop::' . $_[HEAP]->{'current_loop'},
'-e',
'1',
],
# Kill off existing FD's
'CloseOnCall' => 1,
# setup our data handlers
'StdoutEvent' => 'Got_STDOUT',
'StderrEvent' => 'Got_STDERR',
# the error handler
'ErrorEvent' => 'Got_ERROR',
'CloseEvent' => 'Got_CLOSED',
# set our filters
'StderrFilter' => POE::Filter::Line->new(),
'StdoutFilter' => POE::Filter::Line->new(),
);
if ( ! defined $_[HEAP]->{'WHEEL'} ) {
die '[LOOPSEARCH] Unable to create a new wheel!';
} else {
# smart CHLD handling
if ( $_[KERNEL]->can( "sig_child" ) ) {
$_[KERNEL]->sig_child( $_[HEAP]->{'WHEEL'}->PID => 'Got_CHLD' );
} else {
$_[KERNEL]->sig( 'CHLD', 'Got_CHLD' );
}
}
return;
}
# Got a CHLD event!
sub Got_CHLD : State {
$_[KERNEL]->sig_handled();
return;
}
# Handles child STDERR output
sub Got_STDERR : State {
my $input = $_[ARG0];
# since we got an error, must be a failure
$_[HEAP]->{'test_failure'} = 1;
return;
}
# Handles child STDOUT output
sub Got_STDOUT : State {
my $input = $_[ARG0];
return;
}
# Handles child error
sub Got_ERROR : State {
# Copied from POE::Wheel::Run manpage
my ( $operation, $errnum, $errstr ) = @_[ ARG0 .. ARG2 ];
# ignore exit 0 errors
if ( $errnum != 0 ) {
warn "Wheel::Run got an $operation error $errnum: $errstr\n";
}
return;
}
# Handles child DIE'ing
sub Got_CLOSED : State {
# Get rid of the wheel
undef $_[HEAP]->{'WHEEL'};
# Did we pass this test or not?
if ( ! $_[HEAP]->{'test_failure'} ) {
push( @{ $_[HEAP]->{'found_loops'} }, $_[HEAP]->{'current_loop'} );
}
# move on to the next loop
$_[KERNEL]->yield( 'find_loops' );
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::GetInstalledLoops - Automatically detects the installed POE loops
=head1 SYNOPSIS
Don't use this module directly. Please use POE::Devel::Benchmarker.
=head1 ABSTRACT
This package implements the guts of searching for POE loops via fork/exec.
=head1 EXPORT
Automatically exports the getPOEloops() sub
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/GetPOEdists.pm b/lib/POE/Devel/Benchmarker/GetPOEdists.pm
index ce1a991..ed4745a 100644
--- a/lib/POE/Devel/Benchmarker/GetPOEdists.pm
+++ b/lib/POE/Devel/Benchmarker/GetPOEdists.pm
@@ -1,144 +1,144 @@
# Declare our package
package POE::Devel::Benchmarker::GetPOEdists;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
-$VERSION = '0.04';
+$VERSION = '0.05';
# auto-export the only sub we have
use base qw( Exporter );
our @EXPORT = qw( getPOEdists );
# import the helper modules
use LWP::UserAgent;
use HTML::LinkExtor;
use URI::URL;
use Archive::Tar;
# autoflush, please!
use IO::Handle;
STDOUT->autoflush( 1 );
# actually retrieves the dists!
sub getPOEdists {
# should we debug?
my $debug = shift;
# okay, should we change directory?
if ( -d 'poedists' ) {
if ( $debug ) {
print "[GETPOEDISTS] chdir( 'poedists' )\n";
}
if ( ! chdir( 'poedists' ) ) {
die "Unable to chdir to 'poedists' dir: $!";
}
} else {
if ( $debug ) {
print "[GETPOEDISTS] downloading to current directory\n";
}
}
# set the default URL
my $url = "http://backpan.cpan.org/authors/id/R/RC/RCAPUTO/";
# create our objects
my $ua = LWP::UserAgent->new;
my $p = HTML::LinkExtor->new;
my $tar = Archive::Tar->new;
# Request document and parse it as it arrives
print "Getting $url via LWP\n" if $debug;
my $res = $ua->request( HTTP::Request->new( GET => $url ),
sub { $p->parse( $_[0] ) },
);
# did we successfully download?
if ( $res->is_error ) {
die "unable to download directory index on BACKPAN: " . $res->status_line;
}
# Download every one!
foreach my $link ( $p->links ) {
# skip IMG stuff
if ( $link->[0] eq 'a' and $link->[1] eq 'href' ) {
# get the actual POE dists!
if ( $link->[2] =~ /^POE\-\d/ and $link->[2] =~ /\.tar\.gz$/ ) {
# download the tarball!
print "Mirroring $link->[2] via LWP\n" if $debug;
my $mirror_result = $ua->mirror( $url . $link->[2], $link->[2] );
if ( $mirror_result->is_error ) {
warn "unable to mirror $link->[2]: " . $mirror_result->status_line;
next;
}
# did we already untar this one?
my $dir = $link->[2];
$dir =~ s/\.tar\.gz$//;
if ( ! -d $dir ) {
# extract it!
print "Extracting $link->[2] via Tar\n" if $debug;
my $files = $tar->read( $link->[2], undef, { 'extract' => 'true' } );
if ( $files == 0 ) {
warn "unable to extract $link->[2]";
}
}
}
}
}
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::GetPOEdists - Automatically download all POE tarballs
=head1 SYNOPSIS
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker::GetPOEdists -e 'getPOEdists()'
=head1 ABSTRACT
This package automatically downloads all the POE tarballs from BACKPAN.
=head1 DESCRIPTION
This uses LWP + HTML::LinkExtor to retrieve POE tarballs from BACKPAN.
The tarballs are automatically downloaded to the current directory. Then, we use Archive::Tar to extract them all!
NOTE: we use LWP's useful mirror() sub which doesn't re-download files if they already exist!
=head2 getPOEdists
Normally you should pass nothing to this sub. However, if you want to debug the downloads+extractions you should pass
a true value as the first argument.
perl -MPOE::Devel::Benchmarker::GetPOEdists -e 'getPOEdists( 1 )'
=head1 EXPORT
Automatically exports the getPOEdists() sub
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/Imager.pm b/lib/POE/Devel/Benchmarker/Imager.pm
index ce7cb28..8062d98 100644
--- a/lib/POE/Devel/Benchmarker/Imager.pm
+++ b/lib/POE/Devel/Benchmarker/Imager.pm
@@ -1,443 +1,443 @@
# Declare our package
package POE::Devel::Benchmarker::Imager;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
-$VERSION = '0.04';
+$VERSION = '0.05';
# auto-export the only sub we have
use base qw( Exporter );
our @EXPORT = qw( imager );
# import the helper modules
use YAML::Tiny;
# load our plugins!
use Module::Pluggable search_path => [ __PACKAGE__ ];
# load comparison stuff
use version;
# generate some accessors
use base qw( Class::Accessor::Fast );
__PACKAGE__->mk_ro_accessors( qw( poe_versions poe_versions_sorted poe_loops data
noxsqueue noasserts litetests quiet
) );
# autoflush, please!
use IO::Handle;
STDOUT->autoflush( 1 );
# starts the work of converting our data to images
sub imager {
my $options = shift;
# instantitate ourself
my $self = __PACKAGE__->new( $options );
# parse all of our YAML modules!
$self->loadtests;
# process some stats
$self->process_data;
# generate the images!
$self->generate_images;
return;
}
# creates a new instance
sub new {
my $class = shift;
my $opts = shift;
# instantitate ourself
my $self = {};
bless $self, $class;
# init the options
$self->init_options( $opts );
if ( ! $self->{'options'}->{'quiet'} ) {
print "[IMAGER] Starting up...\n";
}
return $self;
}
sub init_options {
my $self = shift;
my $options = shift;
# set defaults
$self->{'quiet'} = 0;
$self->{'litetests'} = 1;
$self->{'noasserts'} = undef;
$self->{'noxsqueue'} = undef;
# process our options
if ( defined $options and ref $options and ref( $options ) eq 'HASH' ) {
# process quiet mode
if ( exists $options->{'quiet'} ) {
if ( $options->{'quiet'} ) {
$self->{'quiet'} = 1;
} else {
$self->{'quiet'} = 0;
}
}
# process the LITE/HEAVY
if ( exists $options->{'litetests'} ) {
if ( $options->{'litetests'} ) {
$self->{'litetests'} = 1;
} else {
$self->{'litetests'} = 0;
}
}
# process the noasserts to load
if ( exists $options->{'noasserts'} ) {
if ( $options->{'noasserts'} ) {
$self->{'noasserts'} = 1;
} else {
$self->{'noasserts'} = 0;
}
}
# process the noxsqueue to load
if ( exists $options->{'noxsqueue'} ) {
if ( $options->{'noxsqueue'} ) {
$self->{'noxsqueue'} = 1;
} else {
$self->{'noxsqueue'} = 0;
}
}
# FIXME process the plugins to load -> "types"
# FIXME process the versions to load
# FIXME process the loops to load
}
# some sanity tests
# FIXME find a way to set the results directory via attribute
if ( ! -d 'results' ) {
die "The 'results' directory is not found in the working directory!";
}
if ( ! -d 'images' ) {
die "The 'images' directory is not found in the working directory!";
}
return;
}
# starts the process of loading all of our YAML images
sub loadtests {
my $self = shift;
# gather all the YAML dumps
if ( opendir( DUMPS, 'results' ) ) {
foreach my $d ( readdir( DUMPS ) ) {
# parse the file structure
# POE-1.0002-IO_Poll-LITE-assert-noxsqueue
if ( $d =~ /^POE\-([\d\.\_]+)\-(\w+?)\-(LITE|HEAVY)\-(noassert|assert)\-(noxsqueue|xsqueue)\.yml$/ ) {
my( $ver, $loop, $lite, $assert, $xsqueue ) = ( $1, $2, $3, $4, $5 );
# skip this file?
if ( $self->noxsqueue ) {
if ( $xsqueue eq 'xsqueue' ) { next }
} else {
if ( defined $self->noxsqueue ) {
if ( $xsqueue eq 'noxsqueue' ) { next }
}
}
if ( $self->noasserts ) {
if ( $assert eq 'assert' ) { next }
} else {
if ( defined $self->noasserts ) {
if ( $assert eq 'noassert' ) { next }
}
}
if ( $self->litetests ) {
if ( $lite eq 'HEAVY' ) { next }
} else {
if ( $lite eq 'LITE' ) { next }
}
# FIXME allow selective loading of tests, so we can control what to image, etc
# actually load this file!
$self->load_yaml( $d, $ver, $loop, $lite, $assert, $xsqueue );
}
}
closedir( DUMPS ) or die "[IMAGER] Unable to read from 'results' -> " . $!;
} else {
die "[IMAGER] Unable to open 'results' for reading -> " . $!;
}
# sanity
if ( ! exists $self->{'data'} ) {
die "[IMAGER] Unable to find any POE test result(s) in the 'results' directory!\n";
}
if ( ! $self->quiet ) {
print "[IMAGER] Done with parsing the YAML files...\n";
}
return;
}
# loads the yaml of a specific file
sub load_yaml {
my ( $self, $file, $ver, $loop, $lite, $assert, $xsqueue ) = @_;
my $yaml = YAML::Tiny->read( 'results/' . $file );
if ( ! defined $yaml ) {
die "[IMAGER] Unable to load YAML file $file -> " . YAML::Tiny->errstr . "\n";
} else {
# inrospect it!
my $isvalid = 0;
eval {
# simple sanity check: the "x_bench" param is at the end of the YML, so if it loads fine we know it's there
if ( exists $yaml->[0]->{'x_bench'} ) {
# version must at least match us
$isvalid = ( $yaml->[0]->{'x_bench'} eq $POE::Devel::Benchmarker::Imager::VERSION ? 1 : 0 );
} else {
$isvalid = undef;
}
};
if ( ! $isvalid or $@ ) {
die "[IMAGER] Detected outdated/corrupt benchmark result: $file";
} else {
# reduce indirection
$yaml = $yaml->[0];
}
}
# store the POE version
$self->{'poe_versions'}->{ $ver } = 1;
# sanity check the loop master version ( which should always be our "installed" version, not per-POE )
if ( exists $yaml->{'poe'}->{'loop_m'} ) {
if ( ! defined $self->{'poe_loops'}->{ $loop } ) {
$self->{'poe_loops'}->{ $loop } = $yaml->{'poe'}->{'loop_m'};
} else {
if ( $self->{'poe_loops'}->{ $loop } ne $yaml->{'poe'}->{'loop_m'} ) {
die "[IMAGER] Detected POE::Loop master version inconsistency! $file reported '" . $yaml->{'poe'}->{'loop_m'} .
"' while others had '" . $self->{'poe_loops'}->{ $loop } . "'";
}
}
}
# get the info we're interested in
$self->{'data'}->{ $assert }->{ $xsqueue }->{ $ver }->{ $loop }->{'metrics'} = $yaml->{'metrics'};
$self->{'data'}->{ $assert }->{ $xsqueue }->{ $ver }->{ $loop }->{'time'} = $yaml->{'t'};
if ( exists $yaml->{'pid'} ) {
$self->{'data'}->{ $assert }->{ $xsqueue }->{ $ver }->{ $loop }->{'pid'} = $yaml->{'pid'};
}
if ( exists $yaml->{'poe'}->{'modules'} ) {
$self->{'data'}->{ $assert }->{ $xsqueue }->{ $ver }->{ $loop }->{'poe_modules'} = $yaml->{'poe'}->{'modules'};
}
# sanity check the perl stuff
if ( exists $yaml->{'perl'}->{'binary'} ) {
if ( ! exists $self->{'data'}->{'perlconfig'} ) {
$self->{'data'}->{'perlconfig'}->{'binary'} = $yaml->{'perl'}->{'binary'};
$self->{'data'}->{'perlconfig'}->{'version'} = $yaml->{'perl'}->{'v'};
} else {
if ( $self->{'data'}->{'perlconfig'}->{'binary'} ne $yaml->{'perl'}->{'binary'} ) {
die "[IMAGER] Detected perl binary inconsistency! $file reported '" . $yaml->{'perl'}->{'binary'} .
"' while others had '" . $self->{'data'}->{'perlconfig'}->{'binary'} . "'";
}
if ( $self->{'data'}->{'perlconfig'}->{'version'} ne $yaml->{'perl'}->{'v'} ) {
die "[IMAGER] Detected perl version inconsistency! $file reported '" . $yaml->{'perl'}->{'v'} .
"' while others had '" . $self->{'data'}->{'perlconfig'}->{'version'} . "'";
}
}
}
# sanity check the uname
if ( exists $yaml->{'uname'} ) {
if ( ! exists $self->{'data'}->{'uname'} ) {
$self->{'data'}->{'uname'} = $yaml->{'uname'};
} else {
if ( $self->{'data'}->{'uname'} ne $yaml->{'uname'} ) {
die "[IMAGER] Detected system inconsistency! $file reported '" . $yaml->{'uname'} .
"' while others had '" . $self->{'data'}->{'uname'} . "'";
}
}
}
# sanity check the cpu name
if ( exists $yaml->{'cpu'} ) {
if ( ! exists $self->{'data'}->{'cpu'} ) {
$self->{'data'}->{'cpu'} = $yaml->{'cpu'};
} else {
if ( $self->{'data'}->{'cpu'}->{'name'} ne $yaml->{'cpu'}->{'name'} ) {
die "[IMAGER] Detected system/cpu inconsistency! $file reported '" . $yaml->{'cpu'}->{'name'} .
"' while others had '" . $self->{'data'}->{'cpu'}->{'name'} . "'";
}
}
}
return;
}
sub process_data {
my $self = shift;
# sanitize the versions in an ordered loop
$self->{'poe_versions_sorted'} = [ map { $_->stringify } sort { $a <=> $b } map { version->new($_) } keys %{ $self->poe_versions } ];
if ( ! $self->quiet ) {
print "[IMAGER] Done with processing the benchmark statistics...\n";
}
return;
}
sub generate_images {
my $self = shift;
# load our plugins and let them have fun :)
foreach my $plugin ( $self->plugins ) {
# actually load it!
## no critic
eval "require $plugin";
## use critic
if ( $@ ) {
if ( ! $self->quiet ) {
print "[IMAGER] Unable to load plugin $plugin -> $@\n";
next;
}
}
# sanity checks
if ( $plugin->can( 'new' ) and $plugin->can( 'imager' ) ) {
# FIXME did we want this plugin?
# create the plugin's home dir
my $homedir = $plugin;
if ( $homedir =~ /\:\:(\w+)$/ ) {
$homedir = $1;
} else {
die "barf";
}
if ( ! -d "images/$homedir" ) {
# create it!
if ( ! mkdir( "images/$homedir" ) ) {
die "[IMAGER] Unable to create plugin directory: $homedir";
}
}
# Okay, get this plugin!
my $obj = $plugin->new( { 'dir' => "images/$homedir/" } );
if ( ! $self->quiet ) {
print "[IMAGER] Processing the $plugin plugin...\n";
}
$obj->imager( $self );
}
}
if ( ! $self->quiet ) {
print "[IMAGER] Done with generating images...\n";
}
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::Imager - Automatically converts the benchmark data into images
=head1 SYNOPSIS
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker::Imager -e 'imager'
=head1 ABSTRACT
This package automatically parses the benchmark data and generates pretty charts.
=head1 DESCRIPTION
It will parse the YAML output from the benchmark data and calls it's plugins to generate any charts necessary
and place them in the 'images' directory under the plugin's name. This module only does the high-level stuff, and leaves
the actual chart generation to the plugins.
Furthermore, we use Module::Pluggable to search all modules in the POE::Devel::Benchmarker::Imager::* namespace and
let them handle the generation of images. That way virtually unlimited combinations of images can be generated on the fly
from the data this module parses.
The way to use this module is by calling the imager() subroutine and let it do it's job. You can pass a hashref to it to
set various options. Here is a list of the valid options:
=over 4
=item quiet => boolean
This enables quiet mode which will not print anything to the console except for errors.
new( { 'quiet' => 1 } );
default: false
=item noxsqueue => boolean / undef
This will tell the Imager to not consider those tests for the output.
benchmark( { noxsqueue => 1 } );
default: undef ( load both xsqueue and noxsqueue tests )
=item noasserts => boolean / undef
This will tell the Imager to not consider those tests for the output
benchmark( { noasserts => 1 } );
default: undef ( load both assert and noassert tests )
=item litetests => boolean
This will tell the Imager to not consider those tests for the output
benchmark( { litetests => 0 } );
default: true
=back
=head1 PLUGIN INTERFACE
For now, this is undocumented. Please look at BasicStatistics for the general concept on how it interacts with this module.
=head1 EXPORT
Automatically exports the imager() sub
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/Imager/BasicStatistics.pm b/lib/POE/Devel/Benchmarker/Imager/BasicStatistics.pm
index e72c6de..fe522d2 100644
--- a/lib/POE/Devel/Benchmarker/Imager/BasicStatistics.pm
+++ b/lib/POE/Devel/Benchmarker/Imager/BasicStatistics.pm
@@ -1,320 +1,320 @@
# Declare our package
package POE::Devel::Benchmarker::Imager::BasicStatistics;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
-$VERSION = '0.04';
+$VERSION = '0.05';
# the GD stuff
use GD::Graph::lines;
# creates a new instance
sub new {
my $class = shift;
my $opts = shift;
# instantitate ourself
my $self = {
'opts' => $opts,
};
return bless $self, $class;
}
# actually generates the graphs!
sub imager {
my $self = shift;
$self->{'imager'} = shift;
# generate the loops vs each other graphs
$self->generate_loopwars;
# generate the single loop performance
$self->generate_loopperf;
# generate the loop assert/xsqueue ( 4 lines ) per metric
$self->generate_loopoptions;
return;
}
# charts a single loop's progress over POE versions
sub generate_loopoptions {
my $self = shift;
if ( ! $self->{'imager'}->quiet ) {
print "[BasicStatistics] Generating the Loop-Options graphs...\n";
}
# go through all the loops we want
foreach my $loop ( keys %{ $self->{'imager'}->poe_loops } ) {
foreach my $metric ( qw( alarms dispatches posts single_posts startups select_read_MYFH select_write_MYFH select_read_STDIN select_write_STDIN ) ) {
my %data;
# organize data by POE version
foreach my $poe ( @{ $self->{'imager'}->poe_versions_sorted } ) {
# go through the combo of assert/xsqueue
foreach my $assert ( qw( assert noassert ) ) {
if ( ! exists $self->{'imager'}->data->{ $assert } ) {
next;
}
foreach my $xsqueue ( qw( xsqueue noxsqueue ) ) {
if ( ! exists $self->{'imager'}->data->{ $assert }->{ $xsqueue } ) {
next;
}
if ( exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
and defined $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
) {
push( @{ $data{ $assert . '_' . $xsqueue } }, $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'} );
} else {
push( @{ $data{ $assert . '_' . $xsqueue } }, 0 );
}
}
}
}
# transform %data into something GD likes
my @data_for_gd;
foreach my $m ( sort keys %data ) {
push( @data_for_gd, $data{ $m } );
}
# send it to GD!
$self->make_gdgraph( 'Options_' . $loop . '_' . $metric,
[ sort keys %data ],
\@data_for_gd,
);
}
}
return;
}
# charts a single loop's progress over POE versions
sub generate_loopperf {
my $self = shift;
if ( ! $self->{'imager'}->quiet ) {
print "[BasicStatistics] Generating the Loop-Performance graphs...\n";
}
# go through all the loops we want
foreach my $loop ( keys %{ $self->{'imager'}->poe_loops } ) {
# go through the combo of assert/xsqueue
foreach my $assert ( qw( assert noassert ) ) {
if ( ! exists $self->{'imager'}->data->{ $assert } ) {
next;
}
foreach my $xsqueue ( qw( xsqueue noxsqueue ) ) {
if ( ! exists $self->{'imager'}->data->{ $assert }->{ $xsqueue } ) {
next;
}
my %data;
# organize data by POE version
foreach my $poe ( @{ $self->{'imager'}->poe_versions_sorted } ) {
foreach my $metric ( qw( alarms dispatches posts single_posts startups select_read_MYFH select_write_MYFH select_read_STDIN select_write_STDIN ) ) {
if ( exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
and defined $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
) {
push( @{ $data{ $metric } }, $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'} );
} else {
push( @{ $data{ $metric } }, 0 );
}
}
}
# transform %data into something GD likes
my @data_for_gd;
foreach my $m ( sort keys %data ) {
push( @data_for_gd, $data{ $m } );
}
# send it to GD!
$self->make_gdgraph( 'Bench_' . $loop,
[ sort keys %data ],
\@data_for_gd,
$assert,
$xsqueue,
);
}
}
}
return;
}
# loop wars!
sub generate_loopwars {
my $self = shift;
if ( ! $self->{'imager'}->quiet ) {
print "[BasicStatistics] Generating the LoopWars graphs...\n";
}
# go through all the metrics we want
foreach my $metric ( qw( alarms dispatches posts single_posts startups select_read_MYFH select_write_MYFH select_read_STDIN select_write_STDIN ) ) {
# go through the combo of assert/xsqueue
foreach my $assert ( qw( assert noassert ) ) {
foreach my $xsqueue ( qw( xsqueue noxsqueue ) ) {
my %data;
# organize data by POE version
foreach my $poe ( @{ $self->{'imager'}->poe_versions_sorted } ) {
foreach my $loop ( keys %{ $self->{'imager'}->poe_loops } ) {
if ( exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
and defined $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
) {
push( @{ $data{ $loop } }, $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'} );
} else {
push( @{ $data{ $loop } }, 0 );
}
}
}
# transform %data into something GD likes
my @data_for_gd;
foreach my $m ( sort keys %data ) {
push( @data_for_gd, $data{ $m } );
}
# send it to GD!
$self->make_gdgraph( "LoopWar_$metric",
[ sort keys %{ $self->{'imager'}->poe_loops } ],
\@data_for_gd,
$assert,
$xsqueue,
);
}
}
}
return;
}
sub make_gdgraph {
my $self = shift;
my $metric = shift;
my $legend = shift;
my $data = shift;
my $assert = shift;
my $xsqueue = shift;
# Get the graph object
my $graph = new GD::Graph::lines( 800, 600 );
# Set some stuff
$graph->set(
# 'x_label' => 'POE Versions',
'title' => $metric . ( defined $xsqueue ? " ($assert - $xsqueue)" : '' ),
'line_width' => 1,
'boxclr' => 'black',
'overwrite' => 0,
'x_labels_vertical' => 1,
'x_all_ticks' => 1,
'legend_placement' => 'BL',
'y_label' => 'iterations/sec',
# 3d options only
#'line_depth' => 2.5,
) or die $graph->error;
# Set the legend
$graph->set_legend( @$legend );
# Set Font stuff
$graph->set_legend_font( GD::gdMediumBoldFont );
$graph->set_x_axis_font( GD::gdMediumBoldFont );
$graph->set_y_axis_font( GD::gdMediumBoldFont );
$graph->set_y_label_font( GD::gdMediumBoldFont );
$graph->set_title_font( GD::gdGiantFont );
# Manufacture the data
my $readydata = [
[ map { 'POE-' . $_ } @{ $self->{'imager'}->poe_versions_sorted } ],
@$data,
];
# Plot it!
$graph->plot( $readydata ) or die $graph->error;
# Print it!
my $filename = $self->{'opts'}->{'dir'} . $metric . '_' .
( $self->{'imager'}->litetests ? 'lite' : 'heavy' ) .
( defined $xsqueue ? '_' . $assert . '_' . $xsqueue : '' ) .
'.png';
open( my $fh, '>', $filename ) or die 'Cannot open graph file!';
binmode( $fh );
print $fh $graph->gd->png();
close( $fh );
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::Imager::BasicStatistics - Plugin to generates basic statistics graphs
=head1 SYNOPSIS
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker::Imager -e 'imager( { type => "BasicStatistics" } )'
=head1 ABSTRACT
This plugin for Imager generates some kinds of graphs from the benchmark tests.
=head1 DESCRIPTION
This package generates some basic graphs from the statistics output. Since the POE::Loop::* modules really are responsible
for the backend logic of POE, it makes sense to graph all related metrics of a single loop across POE versions to see if
it performs differently. The related benchmark metrics are: events, alarms, filehandles, and startup.
This will generate some types of graphs:
=over 4
=item Loops against each other
Each metric will have a picture for itself, showing how each loop compare against each other with the POE versions.
file: BasicStatistics/LoopWar_$metric_$lite_$assert_$xsqueue.png
=item Single Loop over POE versions
Each Loop will have a picture for itself, showing how each metric performs over POE versions.
file: BasicStatistics/Bench_$loop_$lite_$assert_$xsqueue.png
=item Single Loop over POE versions with assert/xsqueue
Each Loop will have a picture for itself, showing how each metric is affected by the assert/xsqueue options.
file: BasicStatistics/Options_$loop_$metric_$lite.png
=back
=head1 EXPORT
Nothing.
=head1 SEE ALSO
L<POE::Devel::Benchmarker::Imager>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/SubProcess.pm b/lib/POE/Devel/Benchmarker/SubProcess.pm
index 3fd418b..6e6d54e 100644
--- a/lib/POE/Devel/Benchmarker/SubProcess.pm
+++ b/lib/POE/Devel/Benchmarker/SubProcess.pm
@@ -1,658 +1,920 @@
# Declare our package
package POE::Devel::Benchmarker::SubProcess;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
-$VERSION = '0.04';
+$VERSION = '0.05';
# Import Time::HiRes's time()
use Time::HiRes qw( time );
# FIXME UGLY HACK here
BEGIN {
# should we enable assertions?
- if ( defined $ARGV[2] and $ARGV[2] ) {
+ if ( defined $ARGV[1] and $ARGV[1] ) {
## no critic
eval "sub POE::Kernel::ASSERT_DEFAULT () { 1 }";
eval "sub POE::Session::ASSERT_STATES () { 1 }";
## use critic
}
# should we "hide" XS::Queue::Array?
- if ( defined $ARGV[4] and $ARGV[4] ) {
+ if ( defined $ARGV[3] and $ARGV[3] ) {
## no critic
eval "use Devel::Hide qw( POE/XS/Queue/Array.pm )";
## use critic
}
}
# load POE
use POE;
use POE::Session;
+use POE::Wheel::SocketFactory;
+use POE::Wheel::ReadWrite;
+use POE::Filter::Line;
+use POE::Driver::SysRW;
# autoflush, please!
use IO::Handle;
STDOUT->autoflush( 1 );
+# import some stuff
+use Socket qw( INADDR_ANY sockaddr_in );
+
+# we need to compare versions
+use version;
+
# load our utility stuff
use POE::Devel::Benchmarker::Utils qw( loop2realversion poeloop2load );
# init our global variables ( bad, haha )
-my( $version, $eventloop, $asserts, $lite_tests, $pocosession );
-my( $post_limit, $alarm_limit, $alarm_add_limit, $session_limit, $select_limit, $through_limit, $call_limit, $start_limit );
+# FIXME change this to a hash because it's becoming unwieldy with too many variables
+my( $eventloop, $asserts, $lite_tests, $pocosession );
+my( $post_limit, $alarm_limit, $alarm_add_limit, $session_limit, $select_limit, $through_limit, $call_limit, $start_limit, $sf_connects, $sf_stream );
# the main routine which will load everything + start
sub benchmark {
- # process the version
- process_version();
-
# process the eventloop
process_eventloop();
# process the assertions
process_assertions();
# process the test mode
process_testmode();
# process the XS::Queue hiding
process_xsqueue();
# actually import POE!
process_POE();
# actually run the benchmarks!
run_benchmarks();
# all done!
return;
}
-sub process_version {
- # Get the desired POE version
- $version = $ARGV[0];
-
- # Decide what to do
- if ( ! defined $version ) {
- die "Please supply a version to test!";
- } elsif ( ! -d 'poedists/POE-' . $version ) {
- die "That specified version does not exist!";
- } else {
- # we're happy...
- }
-
- return;
-}
-
sub process_eventloop {
# Get the desired mode
- $eventloop = $ARGV[1];
+ $eventloop = $ARGV[0];
# print out the loop info
if ( ! defined $eventloop ) {
die "Please supply an event loop!";
} else {
my $loop = poeloop2load( $eventloop );
if ( ! defined $loop ) {
$loop = $eventloop;
}
my $v = loop2realversion( $eventloop );
if ( ! defined $v ) {
$v = 'UNKNOWN';
}
print "Using master loop: $loop-$v\n";
}
return;
}
sub process_assertions {
# Get the desired assert mode
- $asserts = $ARGV[2];
+ $asserts = $ARGV[1];
if ( defined $asserts and $asserts ) {
print "Using FULL Assertions!\n";
} else {
print "Using NO Assertions!\n";
}
return;
}
sub process_testmode {
# get the desired test mode
- $lite_tests = $ARGV[3];
+ $lite_tests = $ARGV[2];
+
if ( defined $lite_tests and $lite_tests ) {
print "Using the LITE tests\n";
$post_limit = 10_000;
$alarm_limit = 10_000;
$alarm_add_limit = 10_000;
$session_limit = 500;
$select_limit = 10_000;
$through_limit = 10_000;
$call_limit = 10_000;
$start_limit = 10;
+ $sf_connects = 1_000;
+ $sf_stream = 1_000;
} else {
print "Using the HEAVY tests\n";
$post_limit = 100_000;
$alarm_limit = 100_000;
$alarm_add_limit = 100_000;
$session_limit = 5_000;
$select_limit = 100_000;
$through_limit = 100_000;
$call_limit = 100_000;
$start_limit = 100;
+ $sf_connects = 10_000;
+ $sf_stream = 10_000;
}
return;
}
sub process_xsqueue {
# should we "hide" XS::Queue::Array?
- if ( defined $ARGV[4] and $ARGV[4] ) {
+ if ( defined $ARGV[3] and $ARGV[3] ) {
print "DISABLING POE::XS::Queue::Array\n";
} else {
print "LETTING POE find POE::XS::Queue::Array\n";
}
return;
}
sub process_POE {
# Print the POE info
print "Using POE-" . $POE::VERSION . "\n";
# Actually print what loop POE is using
foreach my $m ( keys %INC ) {
if ( $m =~ /^POE\/(?:Loop|XS|Queue)/ ) {
# try to be smart and get version?
my $module = $m;
$module =~ s|/|::|g;
$module =~ s/\.pm$//g;
print "POE is using: $module ";
if ( defined $module->VERSION ) {
print "v" . $module->VERSION . "\n";
} else {
print "vUNKNOWN\n";
}
}
}
return;
}
sub run_benchmarks {
# dump some misc info
dump_perlinfo();
dump_sysinfo();
# run the startup test before we actually run POE
bench_startup();
# load the POE session + do the tests there
bench_poe();
# okay, dump our memory usage
dump_pidinfo();
# all done!
return;
}
sub bench_startup {
# Add the eventloop?
my $looploader = poeloop2load( $eventloop );
my @start_times = times();
my $start = time();
for (my $i = 0; $i < $start_limit; $i++) {
# FIXME should we add assertions?
# finally, fire it up!
CORE::system(
$^X,
- '-Ipoedists/POE-' . $version,
- '-Ipoedists/POE-' . $version . '/lib',
+ '-Ipoedists/POE-' . $POE::VERSION,
+ '-Ipoedists/POE-' . $POE::VERSION . '/lib',
( defined $looploader ? "-M$looploader" : () ),
'-MPOE',
'-e',
1,
);
}
my @end_times = times();
my $elapsed = time() - $start;
printf( "\n\n% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $start_limit, 'startups', $elapsed, $start_limit/$elapsed );
print "startups times: @start_times @end_times\n";
return;
}
sub bench_poe {
# figure out POE::Session->create or POE::Session->new or what?
$pocosession = POE::Session->can( 'create' );
if ( defined $pocosession ) {
$pocosession = 'create';
} else {
$pocosession = POE::Session->can( 'spawn' );
if ( defined $pocosession ) {
$pocosession = 'spawn';
} else {
$pocosession = 'new';
}
}
# create the master sesssion + run POE!
POE::Session->$pocosession(
'inline_states' => {
# basic POE states
'_start' => \&poe__start,
'_default' => \&poe__default,
'_stop' => \&poe__stop,
'null' => \&poe_null,
# our test states
'posts' => \&poe_posts,
'posts_start' => \&poe_posts_start,
'posts_end' => \&poe_posts_end,
+
'alarms' => \&poe_alarms,
'manyalarms' => \&poe_manyalarms,
+
'sessions' => \&poe_sessions,
'sessions_end' => \&poe_sessions_end,
+
'stdin_read' => \&poe_stdin_read,
'stdin_write' => \&poe_stdin_write,
'myfh_read' => \&poe_myfh_read,
'myfh_write' => \&poe_myfh_write,
+
'calls' => \&poe_calls,
+
'eventsquirt' => \&poe_eventsquirt,
'eventsquirt_done' => \&poe_eventsquirt_done,
+
+ 'socketfactory' => \&poe_socketfactory,
+ 'socketfactory_start' => \&poe_socketfactory_start,
+ 'socketfactory_connects' => \&poe_socketfactory_connects,
+ 'socketfactory_stream' => \&poe_socketfactory_stream,
+ 'socketfactory_cleanup' => \&poe_socketfactory_cleanup,
+
+ # misc states for test stuff
+ 'server_sf_connect' => \&poe_server_sf_connect,
+ 'server_sf_failure' => \&poe_server_sf_failure,
+ 'server_rw_input' => \&poe_server_rw_input,
+ 'server_rw_error' => \&poe_server_rw_error,
+
+ 'client_sf_connect' => \&poe_client_sf_connect,
+ 'client_sf_failure' => \&poe_client_sf_failure,
+ 'client_rw_input' => \&poe_client_rw_input,
+ 'client_rw_error' => \&poe_client_rw_error,
},
);
# start the kernel!
POE::Kernel->run();
return;
}
# inits our session
sub poe__start {
# fire off the first test!
$_[KERNEL]->yield( 'posts' );
return;
}
sub poe__stop {
}
sub poe__default {
return 0;
}
# a state that does nothing
sub poe_null {
return 1;
}
# How many posts per second? Post a bunch of events, keeping track of the time it takes.
sub poe_posts {
$_[KERNEL]->yield( 'posts_start' );
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $post_limit; $i++) {
$_[KERNEL]->yield( 'null' );
}
my @end_times = times();
my $elapsed = time() - $start;
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $post_limit, 'posts', $elapsed, $post_limit/$elapsed );
print "posts times: @start_times @end_times\n";
$_[KERNEL]->yield( 'posts_end' );
return;
}
sub poe_posts_start {
$_[HEAP]->{start} = time();
$_[HEAP]->{starttimes} = [ times() ];
return;
}
sub poe_posts_end {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $post_limit, 'dispatches', $elapsed, $post_limit/$elapsed );
print "dispatches times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
$_[KERNEL]->yield( 'alarms' );
return;
}
# How many alarms per second? Set a bunch of alarms and find out.
sub poe_alarms {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $alarm_limit; $i++) {
$_[KERNEL]->alarm( whee => rand(1_000_000) );
}
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $alarm_limit, 'alarms', $elapsed, $alarm_limit/$elapsed );
print "alarms times: @start_times @end_times\n";
$_[KERNEL]->alarm( 'whee' => undef );
$_[KERNEL]->yield( 'manyalarms' );
return;
}
# How many repetitive alarms per second? Set a bunch of
# additional alarms and find out. Also see how quickly they can
# be cleared.
sub poe_manyalarms {
# can this POE::Kernel support this?
if ( $_[KERNEL]->can( 'alarm_add' ) ) {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $alarm_add_limit; $i++) {
$_[KERNEL]->alarm_add( whee => rand(1_000_000) );
}
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $alarm_add_limit, 'alarm_adds', $elapsed, $alarm_add_limit/$elapsed );
print "alarm_adds times: @start_times @end_times\n";
$start = time();
@start_times = times();
$_[KERNEL]->alarm( whee => undef );
$elapsed = time() - $start;
@end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $alarm_add_limit, 'alarm_clears', $elapsed, $alarm_add_limit/$elapsed );
print "alarm_clears times: @start_times @end_times\n";
} else {
print "alarm_add NOT SUPPORTED on this version of POE, skipping alarm_adds/alarm_clears tests!\n";
}
$_[KERNEL]->yield( 'sessions' );
return;
}
# How many sessions can we create and destroy per second?
# Create a bunch of sessions, and track that time. Let them
# self-destruct, and track that as well.
sub poe_sessions {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $session_limit; $i++) {
POE::Session->$pocosession( 'inline_states' => { _start => sub {}, _stop => sub {}, _default => sub { return 0 } } );
}
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $session_limit, 'session_creates', $elapsed, $session_limit/$elapsed );
print "session_creates times: @start_times @end_times\n";
$_[KERNEL]->yield( 'sessions_end' );
$_[HEAP]->{start} = time();
$_[HEAP]->{starttimes} = [ times() ];
return;
}
sub poe_sessions_end {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $session_limit, 'session_destroys', $elapsed, $session_limit/$elapsed );
print "session_destroys times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
$_[KERNEL]->yield( 'stdin_read' );
return;
}
# How many times can we select/unselect READ a from STDIN filehandle per second?
sub poe_stdin_read {
# stupid, but we have to skip those tests
if ( $eventloop eq 'Tk' or $eventloop eq 'Prima' ) {
print "SKIPPING STDIN tests on broken loop: $eventloop\n";
$_[KERNEL]->yield( 'myfh_read' );
return;
}
my $start = time();
my @start_times = times();
eval {
for (my $i = 0; $i < $select_limit; $i++) {
$_[KERNEL]->select_read( *STDIN, 'whee' );
$_[KERNEL]->select_read( *STDIN );
}
};
if ( $@ ) {
print "filehandle select_read on STDIN FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $select_limit, 'select_read_STDIN', $elapsed, $select_limit/$elapsed );
print "select_read_STDIN times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'stdin_write' );
return;
}
# How many times can we select/unselect WRITE a from STDIN filehandle per second?
sub poe_stdin_write {
my $start = time();
my @start_times = times();
eval {
for (my $i = 0; $i < $select_limit; $i++) {
$_[KERNEL]->select_write( *STDIN, 'whee' );
$_[KERNEL]->select_write( *STDIN );
}
};
if ( $@ ) {
print "filehandle select_write on STDIN FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $select_limit, 'select_write_STDIN', $elapsed, $select_limit/$elapsed );
print "select_write_STDIN times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'myfh_read' );
return;
}
# How many times can we select/unselect READ a real filehandle?
sub poe_myfh_read {
# stupid, but we have to skip those tests
if ( $eventloop eq 'Event_Lib' or $eventloop eq 'Tk' or $eventloop eq 'Prima' ) {
print "SKIPPING MYFH tests on broken loop: $eventloop\n";
$_[KERNEL]->yield( 'calls' );
return;
}
my $start = time();
my @start_times = times();
eval {
open( my $fh, '+>', 'poebench' ) or die $!;
for (my $i = 0; $i < $select_limit; $i++) {
$_[KERNEL]->select_read( $fh, 'whee' );
$_[KERNEL]->select_read( $fh );
}
close( $fh ) or die $!;
unlink( 'poebench' ) or die $!;
};
if ( $@ ) {
print "filehandle select_read on MYFH FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $select_limit, 'select_read_MYFH', $elapsed, $select_limit/$elapsed );
print "select_read_MYFH times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'myfh_write' );
return;
}
# How many times can we select/unselect WRITE a real filehandle?
sub poe_myfh_write {
my $start = time();
my @start_times = times();
eval {
open( my $fh, '+>', 'poebench' ) or die $!;
for (my $i = 0; $i < $select_limit; $i++) {
$_[KERNEL]->select_write( $fh, 'whee' );
$_[KERNEL]->select_write( $fh );
}
close( $fh ) or die $!;
unlink( 'poebench' ) or die $!;
};
if ( $@ ) {
print "filehandle select_write on MYFH FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $select_limit, 'select_write_MYFH', $elapsed, $select_limit/$elapsed );
print "select_write_MYFH times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'calls' );
return;
}
# How many times can we call a state?
sub poe_calls {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $call_limit; $i++) {
$_[KERNEL]->call( $_[SESSION], 'null' );
}
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $call_limit, 'calls', $elapsed, $call_limit/$elapsed );
print "calls times: @start_times @end_times\n";
$_[KERNEL]->yield( 'eventsquirt' );
return;
}
# How many events can we squirt through POE, one at a time?
sub poe_eventsquirt {
$_[HEAP]->{start} = time();
$_[HEAP]->{starttimes} = [ times() ];
$_[HEAP]->{yield_count} = $through_limit;
$_[KERNEL]->yield( 'eventsquirt_done' );
return;
}
sub poe_eventsquirt_done {
if (--$_[HEAP]->{yield_count}) {
$_[KERNEL]->yield( 'eventsquirt_done' );
} else {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $through_limit, 'single_posts', $elapsed, $through_limit/$elapsed );
print "single_posts times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
+
+ $_[KERNEL]->yield( 'socketfactory' );
+ }
+
+ return;
+}
+
+# tests socketfactory interactions
+sub poe_socketfactory {
+ # POE transitioned between Event to State on 0.19 for SocketFactory/ReadWrite
+ # 0.20+ throws deprecation error :(
+ $_[HEAP]->{'POE_naming'} = 'Event';
+ if ( version->new( $POE::VERSION ) < version->new( '0.20' ) ) {
+ $_[HEAP]->{'POE_naming'} = 'State';
}
- # reached end of tests!
+ # create the socketfactory server
+ $_[HEAP]->{'SF'} = POE::Wheel::SocketFactory->new(
+ 'Port' => INADDR_ANY,
+ 'Address' => 'localhost',
+ 'Reuse' => 'yes',
+
+ 'Success' . $_[HEAP]->{'POE_naming'} => 'server_sf_connect',
+ 'Failure' . $_[HEAP]->{'POE_naming'} => 'server_sf_failure',
+ );
+
+ # be evil, and get the port for the client to connect to
+ ( $_[HEAP]->{'SF_port'}, undef ) = sockaddr_in( getsockname( $_[HEAP]->{'SF'}->[ POE::Wheel::SocketFactory::MY_SOCKET_HANDLE() ] ) );
+
+ # start the connect tests
+ $_[HEAP]->{'SF_counter'} = $sf_connects;
+ $_[HEAP]->{'SF_mode'} = 'CONNECTS';
+ $_[HEAP]->{'start'} = time();
+ $_[HEAP]->{'starttimes'} = [ times() ];
+ $_[KERNEL]->yield( 'socketfactory_connects' );
+
+ return;
+}
+
+# handles SocketFactory connection
+sub poe_server_sf_connect {
+ # what test mode?
+ if ( $_[HEAP]->{'SF_mode'} eq 'CONNECTS' ) {
+ # simply discard this socket
+ } elsif ( $_[HEAP]->{'SF_mode'} eq 'STREAM' ) {
+ # convert it to ReadWrite
+ my $wheel = POE::Wheel::ReadWrite->new(
+ 'Handle' => $_[ARG0],
+ 'Filter' => POE::Filter::Line->new,
+ 'Driver' => POE::Driver::SysRW->new,
+
+ 'Input' . $_[HEAP]->{'POE_naming'} => 'server_rw_input',
+ 'Error' . $_[HEAP]->{'POE_naming'} => 'server_rw_error',
+ );
+
+ # save it in our heap
+ $_[HEAP]->{'RW'}->{ $wheel->ID } = $wheel;
+ } else {
+ die "unknown test mode";
+ }
+
+ return;
+}
+
+# handles SocketFactory errors
+sub poe_server_sf_failure {
+ # ARGH, we couldnt create listening socket
+ print "SKIPPING socket_connect tests because we were unable to setup listening socket\n";
+ print "SKIPPING socket_stream tests because we were unable to setup listening socket\n";
+
+ $_[KERNEL]->yield( 'socketfactory_cleanup' );
+
+ return;
+}
+
+# handles ReadWrite input
+sub poe_server_rw_input {
+ # what test mode?
+ if ( $_[HEAP]->{'SF_mode'} eq 'CONNECTS' ) {
+ # simply discard this data
+ } elsif ( $_[HEAP]->{'SF_mode'} eq 'STREAM' ) {
+ # send it back to the client!
+ $_[HEAP]->{'RW'}->{ $_[ARG1] }->put( $_[ARG0] );
+ } else {
+ die "unknown test mode";
+ }
+
+ return;
+}
+
+# handles ReadWrite disconnects
+sub poe_server_rw_error {
+ # simply get rid of the wheel
+ if ( exists $_[HEAP]->{'RW'}->{ $_[ARG3] } ) {
+ # FIXME do we need this?
+ eval {
+ $_[HEAP]->{'RW'}->{ $_[ARG3] }->shutdown_input;
+ $_[HEAP]->{'RW'}->{ $_[ARG3] }->shutdown_output;
+ };
+
+ delete $_[HEAP]->{'RW'}->{ $_[ARG3] };
+ }
+
+ return;
+}
+
+# starts the client connect tests
+sub poe_socketfactory_connects {
+ if (--$_[HEAP]->{'SF_counter'}) {
+ # open a new client connection!
+ $_[HEAP]->{'client_SF'} = POE::Wheel::SocketFactory->new(
+ 'RemoteAddress' => 'localhost',
+ 'RemotePort' => $_[HEAP]->{'SF_port'},
+
+ 'Success' . $_[HEAP]->{'POE_naming'} => 'client_sf_connect',
+ 'Failure' . $_[HEAP]->{'POE_naming'} => 'client_sf_failure',
+ );
+ } else {
+ my $elapsed = time() - $_[HEAP]->{start};
+ my @end_times = times();
+ printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $sf_connects, 'socket_connect', $elapsed, $sf_connects/$elapsed );
+ print "socket_connect times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
+
+ $_[KERNEL]->yield( 'socketfactory_stream' );
+ }
+
+ return;
+}
+
+# starts the client stream tests
+sub poe_socketfactory_stream {
+ # set the proper test mode
+ $_[HEAP]->{'SF_mode'} = 'STREAM';
+
+ # open a new client connection!
+ $_[HEAP]->{'client_SF'} = POE::Wheel::SocketFactory->new(
+ 'RemoteAddress' => 'localhost',
+ 'RemotePort' => $_[HEAP]->{'SF_port'},
+
+ 'Success' . $_[HEAP]->{'POE_naming'} => 'client_sf_connect',
+ 'Failure' . $_[HEAP]->{'POE_naming'} => 'client_sf_failure',
+ );
+
+ return;
+}
+
+# the client connected to the server!
+sub poe_client_sf_connect {
+ # what test mode?
+ if ( $_[HEAP]->{'SF_mode'} eq 'CONNECTS' ) {
+ # simply discard this connection
+ delete $_[HEAP]->{'client_SF'};
+
+ # make another connection!
+ $_[KERNEL]->yield( 'socketfactory_connects' );
+ } elsif ( $_[HEAP]->{'SF_mode'} eq 'STREAM' ) {
+ # convert it to ReadWrite
+ my $wheel = POE::Wheel::ReadWrite->new(
+ 'Handle' => $_[ARG0],
+ 'Filter' => POE::Filter::Line->new,
+ 'Driver' => POE::Driver::SysRW->new,
+
+ 'Input' . $_[HEAP]->{'POE_naming'} => 'client_rw_input',
+ 'Error' . $_[HEAP]->{'POE_naming'} => 'client_rw_error',
+ );
+
+ # save it in our heap
+ $_[HEAP]->{'client_RW'}->{ $wheel->ID } = $wheel;
+
+ # begin the STREAM test!
+ $_[HEAP]->{'SF_counter'} = $sf_stream;
+ $_[HEAP]->{'SF_data'} = 'x' x ( $sf_stream / 10 ); # set a reasonable-sized chunk of data
+ $_[HEAP]->{'start'} = time();
+ $_[HEAP]->{'starttimes'} = [ times() ];
+
+ $wheel->put( $_[HEAP]->{'SF_data'} );
+ } else {
+ die "unknown test mode";
+ }
+
+ return;
+}
+
+# handles SocketFactory errors
+sub poe_client_sf_failure {
+my ($operation, $errnum, $errstr, $wheel_id) = @_[ARG0..ARG3];
+warn "Wheel $wheel_id generated $operation error $errnum: $errstr\n";
+
+ # ARGH, we couldnt create connecting socket
+ if ( $_[HEAP]->{'SF_mode'} eq 'CONNECTS' ) {
+ print "SKIPPING socket_connects tests because we were unable to setup connecting socket\n";
+
+ # go to stream test
+ $_[KERNEL]->yield( 'socketfactory_stream' );
+ } elsif ( $_[HEAP]->{'SF_mode'} eq 'STREAM' ) {
+ print "SKIPPING socket_stream tests because we were unable to setup connecting socket\n";
+
+ $_[KERNEL]->yield( 'socketfactory_cleanup' );
+ }
+
+ return;
+}
+
+# handles ReadWrite input
+sub poe_client_rw_input {
+ if (--$_[HEAP]->{'SF_counter'}) {
+ # send it back to the server!
+ $_[HEAP]->{'client_RW'}->{ $_[ARG1] }->put( $_[ARG0] );
+ } else {
+ my $elapsed = time() - $_[HEAP]->{start};
+ my @end_times = times();
+ printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $sf_stream, 'socket_stream', $elapsed, $sf_stream/$elapsed );
+ print "socket_stream times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
+
+ $_[KERNEL]->yield( 'socketfactory_cleanup' );
+
+ }
+
+ return;
+}
+
+# handles ReadWrite disconnect
+sub poe_client_rw_error {
+ # simply get rid of the wheel
+ if ( exists $_[HEAP]->{'client_RW'}->{ $_[ARG3] } ) {
+ # FIXME do we need this?
+ eval {
+ $_[HEAP]->{'client_RW'}->{ $_[ARG3] }->shutdown_input;
+ $_[HEAP]->{'client_RW'}->{ $_[ARG3] }->shutdown_output;
+ };
+
+ delete $_[HEAP]->{'client_RW'}->{ $_[ARG3] };
+ }
+
+ return;
+}
+
+# all done with the socketfactory tests
+sub poe_socketfactory_cleanup {
+ # do cleanup
+ delete $_[HEAP]->{'SF'} if exists $_[HEAP]->{'SF'};
+ delete $_[HEAP]->{'RW'} if exists $_[HEAP]->{'RW'};
+ delete $_[HEAP]->{'client_SF'} if exists $_[HEAP]->{'client_SF'};
+ delete $_[HEAP]->{'client_RW'} if exists $_[HEAP]->{'client_RW'};
+
+ # XXX all done with tests!
return;
}
# Get the memory footprint
sub dump_pidinfo {
my $ret = open( my $fh, '<', '/proc/self/status' );
if ( defined $ret ) {
while ( <$fh> ) {
chomp;
if ( $_ ne '' ) {
print "pidinfo: $_\n";
}
}
close( $fh ) or die $!;
} else {
print "UNABLE TO GET /proc/self/status\n";
}
return;
}
# print the local Perl info
sub dump_perlinfo {
print "Running under perl binary: " . $^X . "\n";
require Config;
my $config = Config::myconfig();
foreach my $l ( split( /\n/, $config ) ) {
print "perlconfig: $l\n";
}
return;
}
# print the local system information
sub dump_sysinfo {
print "Running under machine: " . `uname -a` . "\n";
# get cpuinfo
my $ret = open( my $fh, '<', '/proc/cpuinfo' );
if ( defined $ret ) {
while ( <$fh> ) {
chomp;
if ( $_ ne '' ) {
print "cpuinfo: $_\n";
}
}
close( $fh ) or die $!;
} else {
print "UNABLE TO GET /proc/cpuinfo\n";
}
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::SubProcess - Implements the actual POE benchmarks
=head1 SYNOPSIS
perl -MPOE::Devel::Benchmarker::SubProcess -e 'benchmark()'
=head1 ABSTRACT
This package is responsible for implementing the guts of the benchmarks, and timing them.
=head1 EXPORT
Nothing.
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/Utils.pm b/lib/POE/Devel/Benchmarker/Utils.pm
index f3ea8cd..62cf95c 100644
--- a/lib/POE/Devel/Benchmarker/Utils.pm
+++ b/lib/POE/Devel/Benchmarker/Utils.pm
@@ -1,202 +1,202 @@
# Declare our package
package POE::Devel::Benchmarker::Utils;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
-$VERSION = '0.04';
+$VERSION = '0.05';
# set ourself up for exporting
use base qw( Exporter );
our @EXPORT_OK = qw( poeloop2load load2poeloop loop2realversion beautify_times knownloops generateTestfile );
# returns the filename for a particular test
sub generateTestfile {
my $heap = shift;
return 'POE-' . $heap->{'current_version'} .
'-' . $heap->{'current_loop'} .
'-' . ( $heap->{'lite_tests'} ? 'LITE' : 'HEAVY' ) .
'-' . ( $heap->{'current_assertions'} ? 'assert' : 'noassert' ) .
'-' . ( $heap->{'current_noxsqueue'} ? 'noxsqueue' : 'xsqueue' );
}
# maintains the mapping of the loop <-> real module
my %poe2load = (
'Event' => 'Event',
'IO_Poll' => 'IO::Poll',
'Event_Lib' => 'Event::Lib',
'EV' => 'EV',
'Glib' => 'Glib',
'Tk' => 'Tk',
'Gtk' => 'Gtk',
'Prima' => 'Prima',
'Wx' => 'Wx',
'Kqueue' => undef,
'Select' => undef,
);
# returns the proper "load" stuff for a specific loop
sub poeloop2load {
my $eventloop = shift;
if ( exists $poe2load{ $eventloop } ) {
return $poe2load{ $eventloop };
} else {
die "Unknown event loop!";
}
}
# returns the version of the "real" installed module that the loop uses
sub loop2realversion {
my $eventloop = shift;
# Decide which event loop to use
if ( ! defined $eventloop ) {
return;
} elsif ( $eventloop eq 'Event' ) {
return $Event::VERSION;
} elsif ( $eventloop eq 'IO_Poll' ) {
return $IO::Poll::VERSION;
} elsif ( $eventloop eq 'Event_Lib' ) {
return $Event::Lib::VERSION;
} elsif ( $eventloop eq 'EV' ) {
return $EV::VERSION;
} elsif ( $eventloop eq 'Glib' ) {
return $Glib::VERSION;
} elsif ( $eventloop eq 'Tk' ) {
return $Tk::VERSION;
} elsif ( $eventloop eq 'Gtk' ) {
return $Gtk::VERSION;
} elsif ( $eventloop eq 'Prima' ) {
return $Prima::VERSION;
} elsif ( $eventloop eq 'Wx' ) {
return $Wx::VERSION;
} elsif ( $eventloop eq 'Kqueue' ) {
# FIXME how do I do this?
return;
} elsif ( $eventloop eq 'Select' ) {
return 'BUILTIN';
} else {
die "Unknown event loop!";
}
}
# helper routine to parse times() output
sub beautify_times {
my $string = shift;
my $origdata = shift;
# split it up
$string =~ s/^\s+//; $string =~ s/\s+$//;
my @times = split( /\s+/, $string );
# make the data struct
# ($user,$system,$cuser,$csystem) = times;
my $data = {
'u' => $times[4] - $times[0],
's' => $times[5] - $times[1],
'cu' => $times[6] - $times[2],
'cs' => $times[7] - $times[3],
};
# add original data?
if ( $origdata ) {
$data->{'s_user'} = $times[0];
$data->{'s_sys'} = $times[1];
$data->{'s_cuser'} = $times[2];
$data->{'s_csys'} = $times[3];
$data->{'e_user'} = $times[4];
$data->{'e_sys'} = $times[5];
$data->{'e_cuser'} = $times[6];
$data->{'e_csys'} = $times[7];
}
# send it back!
return $data;
}
# returns a list of "known" POE loops
sub knownloops {
# FIXME we remove Wx because I suck.
# FIXME I have no idea how to load/unload Kqueue...
return [ qw( Event_Lib EV Glib Prima Gtk Tk Select IO_Poll ) ];
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::Utils - Various utility routines for POE::Devel::Benchmarker
=head1 SYNOPSIS
perl -MPOE::Devel::Benchmarker::Utils -e 'print poeloop2load( "IO_Poll" )'
=head1 ABSTRACT
This package contains the utility routines and constants that POE::Devel::Benchmarker needs.
=head1 EXPORT
This package exports those subs via @EXPORT_OK:
=over 4
=item knownloops()
Returns an arrayref of the "known" POE loops as of this version of the Benchmarker
=item poeloop2load()
Returns the "parent" class to load for a specific loop. An example is:
$real = poeloop2load( 'IO_Poll' ); # $real now contains "IO::Poll"
=item loop2realversion()
Returns the version of the "parent" class for a specific loop. An example is:
$ver = loop2realversion( 'IO_Poll' ); # $ver now contains $IO::Poll::VERSION
=item beautify_times()
Returns a hashref of data from parsing 2 consecutive times() structures in a string. You can pass an additional parameter
( boolean ) to include the original data. An example is:
print Data::Dumper::Dumper( beautify_times( '0.1 0 0 0 0.1 0 0.76 0.09', 1 ) );
{
"sys" => 0, # total system time
"user" => 0, # total user time
"csys" => 0.76 # total children system time
"cuser" => 0.08 # total children user time
"e_csys" => "0.09", # end children system time ( optional )
"e_cuser" => "0.76", # end children user time ( optional )
"e_sys" => 0, # end system time ( optional )
"e_user" => "0.1", # end user time ( optional )
"s_csys" => 0, # start children system time ( optional )
"s_cuser" => 0, # start children user time ( optional )
"s_sys" => 0, # start system time ( optional )
"s_user" => "0.1" # start user time ( optional )
}
=back
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
|
apocalypse/perl-poe-benchmarker
|
79851233e86f24cd095cc811cf0420f1fc4d7e1d
|
new distro
|
diff --git a/Build.PL b/Build.PL
index df7dbaa..1f20faf 100755
--- a/Build.PL
+++ b/Build.PL
@@ -1,101 +1,104 @@
# Build.PL
use Module::Build;
my $build = Module::Build->new(
# look up Module::Build::API for the info!
'dynamic_config' => 0,
'module_name' => 'POE::Devel::Benchmarker',
'license' => 'perl',
'dist_abstract' => "Benchmarking POE's performance ( acts more like a smoker )",
'dist_author' => 'Apocalypse <APOCAL@cpan.org>',
'create_packlist' => 1,
'create_makefile_pl' => 'traditional',
'create_readme' => 1,
'test_files' => 't/*.t',
'add_to_cleanup' => [ 'META.yml', 'Makefile.PL', 'README' ], # automatically generated
'requires' => {
# POE Stuff
'POE' => 0,
'POE::Session::AttributeBased' => 0,
+ # FIXME POE stuff that Test::Dependencies needs to see
+ 'POE::Session' => 0,
+
# misc perl stuff
'Time::HiRes' => 0,
'version' => 0,
'Devel::Hide' => 0,
# Analyzer reqs
'YAML::Tiny' => 0,
# GetPOEdists reqs
'LWP::UserAgent' => 0,
'HTML::LinkExtor' => 0,
'URI::URL' => 0,
'Archive::Tar' => 0,
# Imager reqs
'GD::Graph::lines' => 0,
'Class::Accessor::Fast' => 0,
'Module::Pluggable' => 0,
- },
- 'recommends' => {
# Test stuff
'Test::More' => '0.86', # require latest for note() support in t/a_is_prereq_outdated.t
+ },
+ 'recommends' => {
# our POE loops!
'POE::Loop::Event' => 0,
'POE::Loop::Event_Lib' => 0,
'POE::Loop::EV' => 0,
'POE::Loop::Glib' => 0,
'POE::Loop::Prima' => 0,
'POE::Loop::Gtk' => 0,
'POE::Loop::Wx' => 0,
'POE::Loop::Kqueue' => 0,
# included in POE ( listed here for completeness )
#'POE::Loop::Tk' => 0,
#'POE::Loop::Select' => 0,
#'POE::Loop::IO_Poll' => 0,
# the loops' dependencies
'Event' => 0,
'Event::Lib' => 0,
'EV' => 0,
'Glib' => 0,
'Prima' => 0,
'Gtk' => 0,
'Wx' => 0,
'Tk' => 0,
# the XS queue
'POE::XS::Queue::Array' => 0,
},
# FIXME wishlist...
# 'test_requires' => {
# # Test stuff
# 'Test::Compile' => 0,
# 'Test::Perl::Critic' => 0,
# 'Test::Dependencies' => 0,
# 'Test::Distribution' => 0,
# 'Test::Fixme' => 0,
# 'Test::HasVersion' => 0,
# 'Test::Kwalitee' => 0,
# 'Test::CheckManifest' => 0,
# 'Test::MinimumVersion' => 0,
# 'Test::Pod::Coverage' => 0,
# 'Test::Spelling' => 0,
# 'Test::Pod' => 0,
# 'Test::Prereq' => 0,
# 'Test::Strict' => 0,
# 'Test::UseAllModules' => 0,
# },
);
# all done!
$build->create_build_script;
diff --git a/POE-Devel-Benchmarker-0.04.tar.gz b/POE-Devel-Benchmarker-0.04.tar.gz
new file mode 100644
index 0000000..c85f0b9
Binary files /dev/null and b/POE-Devel-Benchmarker-0.04.tar.gz differ
|
apocalypse/perl-poe-benchmarker
|
01de65ed2f7a3b8d872a8d44b1113fc71ac75cec
|
more tweaks to the basicstats output
|
diff --git a/Build.PL b/Build.PL
index 905d6f4..df7dbaa 100755
--- a/Build.PL
+++ b/Build.PL
@@ -1,101 +1,101 @@
# Build.PL
use Module::Build;
my $build = Module::Build->new(
# look up Module::Build::API for the info!
'dynamic_config' => 0,
'module_name' => 'POE::Devel::Benchmarker',
'license' => 'perl',
'dist_abstract' => "Benchmarking POE's performance ( acts more like a smoker )",
'dist_author' => 'Apocalypse <APOCAL@cpan.org>',
'create_packlist' => 1,
'create_makefile_pl' => 'traditional',
'create_readme' => 1,
'test_files' => 't/*.t',
'add_to_cleanup' => [ 'META.yml', 'Makefile.PL', 'README' ], # automatically generated
'requires' => {
# POE Stuff
'POE' => 0,
'POE::Session::AttributeBased' => 0,
# misc perl stuff
'Time::HiRes' => 0,
'version' => 0,
'Devel::Hide' => 0,
# Analyzer reqs
'YAML::Tiny' => 0,
# GetPOEdists reqs
'LWP::UserAgent' => 0,
'HTML::LinkExtor' => 0,
'URI::URL' => 0,
'Archive::Tar' => 0,
# Imager reqs
'GD::Graph::lines' => 0,
'Class::Accessor::Fast' => 0,
'Module::Pluggable' => 0,
},
'recommends' => {
# Test stuff
'Test::More' => '0.86', # require latest for note() support in t/a_is_prereq_outdated.t
# our POE loops!
'POE::Loop::Event' => 0,
'POE::Loop::Event_Lib' => 0,
'POE::Loop::EV' => 0,
'POE::Loop::Glib' => 0,
'POE::Loop::Prima' => 0,
'POE::Loop::Gtk' => 0,
'POE::Loop::Wx' => 0,
'POE::Loop::Kqueue' => 0,
# included in POE ( listed here for completeness )
- #'POE::Loop::Tk' => 0,
- #'POE::Loop::Select' => 0,
- #'POE::Loop::IO_Poll' => 0,
+ #'POE::Loop::Tk' => 0,
+ #'POE::Loop::Select' => 0,
+ #'POE::Loop::IO_Poll' => 0,
# the loops' dependencies
'Event' => 0,
'Event::Lib' => 0,
'EV' => 0,
'Glib' => 0,
'Prima' => 0,
'Gtk' => 0,
'Wx' => 0,
'Tk' => 0,
# the XS queue
'POE::XS::Queue::Array' => 0,
},
# FIXME wishlist...
# 'test_requires' => {
# # Test stuff
# 'Test::Compile' => 0,
# 'Test::Perl::Critic' => 0,
# 'Test::Dependencies' => 0,
# 'Test::Distribution' => 0,
# 'Test::Fixme' => 0,
# 'Test::HasVersion' => 0,
# 'Test::Kwalitee' => 0,
# 'Test::CheckManifest' => 0,
# 'Test::MinimumVersion' => 0,
# 'Test::Pod::Coverage' => 0,
# 'Test::Spelling' => 0,
# 'Test::Pod' => 0,
# 'Test::Prereq' => 0,
# 'Test::Strict' => 0,
# 'Test::UseAllModules' => 0,
# },
);
# all done!
$build->create_build_script;
diff --git a/Changes b/Changes
index cea775c..8a97459 100755
--- a/Changes
+++ b/Changes
@@ -1,32 +1,32 @@
Revision history for Perl extension POE::Devel::Benchmarker
-* 0.04 Mon Dec 15 15:12:42 2008
+* 0.04
Started work on the image generator ( Imager ) and added the BasicStatistics plugin, yay!
Added automatic "pick up where we left off" to the benchmarker
Added the freshstart option to benchmark()
Tweaked the GetPOEdists sub so it will work in the "work directory" and in the poedists dir
Tweaked the YAML output so it's smaller
Removed POE::Loop::Wx from autoprobing ( I'm unable to get it to work )
Removed POE::Loop::Kqueue from autoprobing ( I'm unable to get it to work )
Hardcoded the Benchmarker routines to skip POE < 0.13 ( I'm unable to get it to work )
* 0.03
Added the loop option to benchmark(), thanks dngor!
Added the poe option to benchmark(), thanks dngor!
Added the noxsqueue option to benchmark()
Added the noasserts option to benchmark()
Automatically enable noxsqueue option if we cannot load POE::XS::Queue::Array, saving time
Bump Test::More version requirement because some people reported failures with note()
Fixed bug in SubProcess where it crashed on old POEs that didn't load IO::Handle
More documentation additions/tweaks
* 0.02
Added the Analyzer module ( and dump YAML files, yay! )
A lot of minor changes+tweaks to get a better dump format
* 0.01
initial release
diff --git a/lib/POE/Devel/Benchmarker/Imager.pm b/lib/POE/Devel/Benchmarker/Imager.pm
index 48fa23a..ce7cb28 100644
--- a/lib/POE/Devel/Benchmarker/Imager.pm
+++ b/lib/POE/Devel/Benchmarker/Imager.pm
@@ -1,439 +1,443 @@
# Declare our package
package POE::Devel::Benchmarker::Imager;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.04';
# auto-export the only sub we have
use base qw( Exporter );
our @EXPORT = qw( imager );
# import the helper modules
use YAML::Tiny;
# load our plugins!
use Module::Pluggable search_path => [ __PACKAGE__ ];
# load comparison stuff
use version;
# generate some accessors
use base qw( Class::Accessor::Fast );
__PACKAGE__->mk_ro_accessors( qw( poe_versions poe_versions_sorted poe_loops data
- noxsqueue noasserts litetests
+ noxsqueue noasserts litetests quiet
) );
# autoflush, please!
use IO::Handle;
STDOUT->autoflush( 1 );
# starts the work of converting our data to images
sub imager {
my $options = shift;
# instantitate ourself
my $self = __PACKAGE__->new( $options );
# parse all of our YAML modules!
$self->loadtests;
# process some stats
$self->process_data;
# generate the images!
$self->generate_images;
return;
}
# creates a new instance
sub new {
my $class = shift;
my $opts = shift;
# instantitate ourself
my $self = {};
bless $self, $class;
# init the options
$self->init_options( $opts );
if ( ! $self->{'options'}->{'quiet'} ) {
print "[IMAGER] Starting up...\n";
}
return $self;
}
sub init_options {
my $self = shift;
my $options = shift;
# set defaults
$self->{'quiet'} = 0;
$self->{'litetests'} = 1;
- $self->{'noasserts'} = 0;
- $self->{'noxsqueue'} = 0;
+ $self->{'noasserts'} = undef;
+ $self->{'noxsqueue'} = undef;
# process our options
if ( defined $options and ref $options and ref( $options ) eq 'HASH' ) {
# process quiet mode
if ( exists $options->{'quiet'} ) {
if ( $options->{'quiet'} ) {
$self->{'quiet'} = 1;
} else {
$self->{'quiet'} = 0;
}
}
# process the LITE/HEAVY
if ( exists $options->{'litetests'} ) {
if ( $options->{'litetests'} ) {
$self->{'litetests'} = 1;
} else {
$self->{'litetests'} = 0;
}
}
# process the noasserts to load
if ( exists $options->{'noasserts'} ) {
if ( $options->{'noasserts'} ) {
$self->{'noasserts'} = 1;
} else {
$self->{'noasserts'} = 0;
}
}
# process the noxsqueue to load
if ( exists $options->{'noxsqueue'} ) {
if ( $options->{'noxsqueue'} ) {
$self->{'noxsqueue'} = 1;
} else {
$self->{'noxsqueue'} = 0;
}
}
# FIXME process the plugins to load -> "types"
# FIXME process the versions to load
# FIXME process the loops to load
}
# some sanity tests
# FIXME find a way to set the results directory via attribute
if ( ! -d 'results' ) {
die "The 'results' directory is not found in the working directory!";
}
if ( ! -d 'images' ) {
die "The 'images' directory is not found in the working directory!";
}
return;
}
# starts the process of loading all of our YAML images
sub loadtests {
my $self = shift;
# gather all the YAML dumps
if ( opendir( DUMPS, 'results' ) ) {
foreach my $d ( readdir( DUMPS ) ) {
# parse the file structure
# POE-1.0002-IO_Poll-LITE-assert-noxsqueue
if ( $d =~ /^POE\-([\d\.\_]+)\-(\w+?)\-(LITE|HEAVY)\-(noassert|assert)\-(noxsqueue|xsqueue)\.yml$/ ) {
my( $ver, $loop, $lite, $assert, $xsqueue ) = ( $1, $2, $3, $4, $5 );
# skip this file?
if ( $self->noxsqueue ) {
if ( $xsqueue eq 'xsqueue' ) { next }
} else {
- if ( $xsqueue eq 'noxsqueue' ) { next }
+ if ( defined $self->noxsqueue ) {
+ if ( $xsqueue eq 'noxsqueue' ) { next }
+ }
}
if ( $self->noasserts ) {
if ( $assert eq 'assert' ) { next }
} else {
- if ( $assert eq 'noassert' ) { next }
+ if ( defined $self->noasserts ) {
+ if ( $assert eq 'noassert' ) { next }
+ }
}
if ( $self->litetests ) {
if ( $lite eq 'HEAVY' ) { next }
} else {
if ( $lite eq 'LITE' ) { next }
}
# FIXME allow selective loading of tests, so we can control what to image, etc
# actually load this file!
$self->load_yaml( $d, $ver, $loop, $lite, $assert, $xsqueue );
}
}
closedir( DUMPS ) or die "[IMAGER] Unable to read from 'results' -> " . $!;
} else {
die "[IMAGER] Unable to open 'results' for reading -> " . $!;
}
# sanity
if ( ! exists $self->{'data'} ) {
die "[IMAGER] Unable to find any POE test result(s) in the 'results' directory!\n";
}
if ( ! $self->quiet ) {
print "[IMAGER] Done with parsing the YAML files...\n";
}
return;
}
# loads the yaml of a specific file
sub load_yaml {
my ( $self, $file, $ver, $loop, $lite, $assert, $xsqueue ) = @_;
my $yaml = YAML::Tiny->read( 'results/' . $file );
if ( ! defined $yaml ) {
die "[IMAGER] Unable to load YAML file $file -> " . YAML::Tiny->errstr . "\n";
} else {
# inrospect it!
my $isvalid = 0;
eval {
# simple sanity check: the "x_bench" param is at the end of the YML, so if it loads fine we know it's there
if ( exists $yaml->[0]->{'x_bench'} ) {
# version must at least match us
$isvalid = ( $yaml->[0]->{'x_bench'} eq $POE::Devel::Benchmarker::Imager::VERSION ? 1 : 0 );
} else {
$isvalid = undef;
}
};
if ( ! $isvalid or $@ ) {
die "[IMAGER] Detected outdated/corrupt benchmark result: $file";
} else {
# reduce indirection
$yaml = $yaml->[0];
}
}
# store the POE version
$self->{'poe_versions'}->{ $ver } = 1;
# sanity check the loop master version ( which should always be our "installed" version, not per-POE )
if ( exists $yaml->{'poe'}->{'loop_m'} ) {
if ( ! defined $self->{'poe_loops'}->{ $loop } ) {
$self->{'poe_loops'}->{ $loop } = $yaml->{'poe'}->{'loop_m'};
} else {
if ( $self->{'poe_loops'}->{ $loop } ne $yaml->{'poe'}->{'loop_m'} ) {
die "[IMAGER] Detected POE::Loop master version inconsistency! $file reported '" . $yaml->{'poe'}->{'loop_m'} .
"' while others had '" . $self->{'poe_loops'}->{ $loop } . "'";
}
}
}
# get the info we're interested in
- $self->{'data'}->{ $ver }->{ $loop }->{'metrics'} = $yaml->{'metrics'};
- $self->{'data'}->{ $ver }->{ $loop }->{'time'} = $yaml->{'t'};
+ $self->{'data'}->{ $assert }->{ $xsqueue }->{ $ver }->{ $loop }->{'metrics'} = $yaml->{'metrics'};
+ $self->{'data'}->{ $assert }->{ $xsqueue }->{ $ver }->{ $loop }->{'time'} = $yaml->{'t'};
if ( exists $yaml->{'pid'} ) {
- $self->{'data'}->{ $ver }->{ $loop }->{'pid'} = $yaml->{'pid'};
+ $self->{'data'}->{ $assert }->{ $xsqueue }->{ $ver }->{ $loop }->{'pid'} = $yaml->{'pid'};
}
if ( exists $yaml->{'poe'}->{'modules'} ) {
- $self->{'data'}->{ $ver }->{ $loop }->{'poe_modules'} = $yaml->{'poe'}->{'modules'};
+ $self->{'data'}->{ $assert }->{ $xsqueue }->{ $ver }->{ $loop }->{'poe_modules'} = $yaml->{'poe'}->{'modules'};
}
# sanity check the perl stuff
if ( exists $yaml->{'perl'}->{'binary'} ) {
if ( ! exists $self->{'data'}->{'perlconfig'} ) {
$self->{'data'}->{'perlconfig'}->{'binary'} = $yaml->{'perl'}->{'binary'};
$self->{'data'}->{'perlconfig'}->{'version'} = $yaml->{'perl'}->{'v'};
} else {
if ( $self->{'data'}->{'perlconfig'}->{'binary'} ne $yaml->{'perl'}->{'binary'} ) {
die "[IMAGER] Detected perl binary inconsistency! $file reported '" . $yaml->{'perl'}->{'binary'} .
"' while others had '" . $self->{'data'}->{'perlconfig'}->{'binary'} . "'";
}
if ( $self->{'data'}->{'perlconfig'}->{'version'} ne $yaml->{'perl'}->{'v'} ) {
die "[IMAGER] Detected perl version inconsistency! $file reported '" . $yaml->{'perl'}->{'v'} .
"' while others had '" . $self->{'data'}->{'perlconfig'}->{'version'} . "'";
}
}
}
# sanity check the uname
if ( exists $yaml->{'uname'} ) {
if ( ! exists $self->{'data'}->{'uname'} ) {
$self->{'data'}->{'uname'} = $yaml->{'uname'};
} else {
if ( $self->{'data'}->{'uname'} ne $yaml->{'uname'} ) {
die "[IMAGER] Detected system inconsistency! $file reported '" . $yaml->{'uname'} .
"' while others had '" . $self->{'data'}->{'uname'} . "'";
}
}
}
# sanity check the cpu name
if ( exists $yaml->{'cpu'} ) {
if ( ! exists $self->{'data'}->{'cpu'} ) {
$self->{'data'}->{'cpu'} = $yaml->{'cpu'};
} else {
if ( $self->{'data'}->{'cpu'}->{'name'} ne $yaml->{'cpu'}->{'name'} ) {
die "[IMAGER] Detected system/cpu inconsistency! $file reported '" . $yaml->{'cpu'}->{'name'} .
"' while others had '" . $self->{'data'}->{'cpu'}->{'name'} . "'";
}
}
}
return;
}
sub process_data {
my $self = shift;
# sanitize the versions in an ordered loop
$self->{'poe_versions_sorted'} = [ map { $_->stringify } sort { $a <=> $b } map { version->new($_) } keys %{ $self->poe_versions } ];
if ( ! $self->quiet ) {
print "[IMAGER] Done with processing the benchmark statistics...\n";
}
return;
}
sub generate_images {
my $self = shift;
# load our plugins and let them have fun :)
foreach my $plugin ( $self->plugins ) {
# actually load it!
## no critic
eval "require $plugin";
## use critic
if ( $@ ) {
if ( ! $self->quiet ) {
print "[IMAGER] Unable to load plugin $plugin -> $@\n";
next;
}
}
# sanity checks
if ( $plugin->can( 'new' ) and $plugin->can( 'imager' ) ) {
# FIXME did we want this plugin?
# create the plugin's home dir
my $homedir = $plugin;
if ( $homedir =~ /\:\:(\w+)$/ ) {
$homedir = $1;
} else {
die "barf";
}
if ( ! -d "images/$homedir" ) {
# create it!
if ( ! mkdir( "images/$homedir" ) ) {
die "[IMAGER] Unable to create plugin directory: $homedir";
}
}
# Okay, get this plugin!
my $obj = $plugin->new( { 'dir' => "images/$homedir/" } );
if ( ! $self->quiet ) {
print "[IMAGER] Processing the $plugin plugin...\n";
}
$obj->imager( $self );
}
}
if ( ! $self->quiet ) {
print "[IMAGER] Done with generating images...\n";
}
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::Imager - Automatically converts the benchmark data into images
=head1 SYNOPSIS
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker::Imager -e 'imager'
=head1 ABSTRACT
This package automatically parses the benchmark data and generates pretty charts.
=head1 DESCRIPTION
-This package uses the excellent L<Chart::Clicker> module to generate the images. It will parse the YAML output from
-the benchmark data and calls it's plugins to generate any charts necessary and place them in the 'images' directory.
+It will parse the YAML output from the benchmark data and calls it's plugins to generate any charts necessary
+and place them in the 'images' directory under the plugin's name. This module only does the high-level stuff, and leaves
+the actual chart generation to the plugins.
Furthermore, we use Module::Pluggable to search all modules in the POE::Devel::Benchmarker::Imager::* namespace and
let them handle the generation of images. That way virtually unlimited combinations of images can be generated on the fly
from the data this module parses.
The way to use this module is by calling the imager() subroutine and let it do it's job. You can pass a hashref to it to
set various options. Here is a list of the valid options:
=over 4
=item quiet => boolean
This enables quiet mode which will not print anything to the console except for errors.
new( { 'quiet' => 1 } );
default: false
-=item noxsqueue => boolean
+=item noxsqueue => boolean / undef
-This will tell the Imager to not consider those tests for the output
+This will tell the Imager to not consider those tests for the output.
benchmark( { noxsqueue => 1 } );
-default: false
+default: undef ( load both xsqueue and noxsqueue tests )
-=item noasserts => boolean
+=item noasserts => boolean / undef
This will tell the Imager to not consider those tests for the output
benchmark( { noasserts => 1 } );
-default: false
+default: undef ( load both assert and noassert tests )
=item litetests => boolean
This will tell the Imager to not consider those tests for the output
benchmark( { litetests => 0 } );
default: true
=back
=head1 PLUGIN INTERFACE
-For now, this is undocumented. Please look at BasicStatistics for the general concept on how it interacts with this module
-and as always, feel free to look at the source :)
+For now, this is undocumented. Please look at BasicStatistics for the general concept on how it interacts with this module.
=head1 EXPORT
Automatically exports the imager() sub
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/Imager/BasicStatistics.pm b/lib/POE/Devel/Benchmarker/Imager/BasicStatistics.pm
index e8ee51e..e72c6de 100644
--- a/lib/POE/Devel/Benchmarker/Imager/BasicStatistics.pm
+++ b/lib/POE/Devel/Benchmarker/Imager/BasicStatistics.pm
@@ -1,232 +1,320 @@
# Declare our package
package POE::Devel::Benchmarker::Imager::BasicStatistics;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.04';
# the GD stuff
use GD::Graph::lines;
# creates a new instance
sub new {
my $class = shift;
my $opts = shift;
# instantitate ourself
my $self = {
'opts' => $opts,
};
return bless $self, $class;
}
# actually generates the graphs!
sub imager {
my $self = shift;
$self->{'imager'} = shift;
# generate the loops vs each other graphs
$self->generate_loopwars;
# generate the single loop performance
$self->generate_loopperf;
+ # generate the loop assert/xsqueue ( 4 lines ) per metric
+ $self->generate_loopoptions;
+
return;
}
# charts a single loop's progress over POE versions
-sub generate_loopperf {
+sub generate_loopoptions {
my $self = shift;
+ if ( ! $self->{'imager'}->quiet ) {
+ print "[BasicStatistics] Generating the Loop-Options graphs...\n";
+ }
+
# go through all the loops we want
foreach my $loop ( keys %{ $self->{'imager'}->poe_loops } ) {
- my %data;
-
- # organize data by POE version
- foreach my $poe ( @{ $self->{'imager'}->poe_versions_sorted } ) {
- foreach my $metric ( qw( alarms dispatches posts single_posts startups select_read_MYFH select_write_MYFH select_read_STDIN select_write_STDIN ) ) {
- if ( exists $self->{'imager'}->data->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
- and defined $self->{'imager'}->data->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
- ) {
- push( @{ $data{ $metric } }, $self->{'imager'}->data->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'} );
- } else {
- push( @{ $data{ $metric } }, 0 );
+ foreach my $metric ( qw( alarms dispatches posts single_posts startups select_read_MYFH select_write_MYFH select_read_STDIN select_write_STDIN ) ) {
+ my %data;
+
+ # organize data by POE version
+ foreach my $poe ( @{ $self->{'imager'}->poe_versions_sorted } ) {
+ # go through the combo of assert/xsqueue
+ foreach my $assert ( qw( assert noassert ) ) {
+ if ( ! exists $self->{'imager'}->data->{ $assert } ) {
+ next;
+ }
+ foreach my $xsqueue ( qw( xsqueue noxsqueue ) ) {
+ if ( ! exists $self->{'imager'}->data->{ $assert }->{ $xsqueue } ) {
+ next;
+ }
+
+ if ( exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
+ and defined $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
+ ) {
+ push( @{ $data{ $assert . '_' . $xsqueue } }, $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'} );
+ } else {
+ push( @{ $data{ $assert . '_' . $xsqueue } }, 0 );
+ }
+ }
}
}
- }
- # transform %data into something GD likes
- my @data_for_gd;
- foreach my $metric ( sort keys %data ) {
- push( @data_for_gd, $data{ $metric } );
+ # transform %data into something GD likes
+ my @data_for_gd;
+ foreach my $m ( sort keys %data ) {
+ push( @data_for_gd, $data{ $m } );
+ }
+
+ # send it to GD!
+ $self->make_gdgraph( 'Options_' . $loop . '_' . $metric,
+ [ sort keys %data ],
+ \@data_for_gd,
+ );
}
+ }
+
+ return;
+}
+
+# charts a single loop's progress over POE versions
+sub generate_loopperf {
+ my $self = shift;
+
+ if ( ! $self->{'imager'}->quiet ) {
+ print "[BasicStatistics] Generating the Loop-Performance graphs...\n";
+ }
+
+ # go through all the loops we want
+ foreach my $loop ( keys %{ $self->{'imager'}->poe_loops } ) {
+ # go through the combo of assert/xsqueue
+ foreach my $assert ( qw( assert noassert ) ) {
+ if ( ! exists $self->{'imager'}->data->{ $assert } ) {
+ next;
+ }
+ foreach my $xsqueue ( qw( xsqueue noxsqueue ) ) {
+ if ( ! exists $self->{'imager'}->data->{ $assert }->{ $xsqueue } ) {
+ next;
+ }
+ my %data;
+
+ # organize data by POE version
+ foreach my $poe ( @{ $self->{'imager'}->poe_versions_sorted } ) {
+ foreach my $metric ( qw( alarms dispatches posts single_posts startups select_read_MYFH select_write_MYFH select_read_STDIN select_write_STDIN ) ) {
+ if ( exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
+ and defined $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
+ ) {
+ push( @{ $data{ $metric } }, $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'} );
+ } else {
+ push( @{ $data{ $metric } }, 0 );
+ }
+ }
+ }
+
+ # transform %data into something GD likes
+ my @data_for_gd;
+ foreach my $m ( sort keys %data ) {
+ push( @data_for_gd, $data{ $m } );
+ }
- # send it to GD!
- $self->make_gdgraph( "Bench_$loop",
- [ sort keys %data ],
- 'iterations/sec',
- \@data_for_gd,
- );
+ # send it to GD!
+ $self->make_gdgraph( 'Bench_' . $loop,
+ [ sort keys %data ],
+ \@data_for_gd,
+ $assert,
+ $xsqueue,
+ );
+ }
+ }
}
return;
}
# loop wars!
sub generate_loopwars {
my $self = shift;
+ if ( ! $self->{'imager'}->quiet ) {
+ print "[BasicStatistics] Generating the LoopWars graphs...\n";
+ }
+
# go through all the metrics we want
foreach my $metric ( qw( alarms dispatches posts single_posts startups select_read_MYFH select_write_MYFH select_read_STDIN select_write_STDIN ) ) {
- my %data;
-
- # organize data by POE version
- foreach my $poe ( @{ $self->{'imager'}->poe_versions_sorted } ) {
- foreach my $loop ( keys %{ $self->{'imager'}->poe_loops } ) {
- if ( exists $self->{'imager'}->data->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
- and defined $self->{'imager'}->data->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
- ) {
- push( @{ $data{ $loop } }, $self->{'imager'}->data->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'} );
- } else {
- push( @{ $data{ $loop } }, 0 );
+ # go through the combo of assert/xsqueue
+ foreach my $assert ( qw( assert noassert ) ) {
+ foreach my $xsqueue ( qw( xsqueue noxsqueue ) ) {
+ my %data;
+
+ # organize data by POE version
+ foreach my $poe ( @{ $self->{'imager'}->poe_versions_sorted } ) {
+ foreach my $loop ( keys %{ $self->{'imager'}->poe_loops } ) {
+ if ( exists $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
+ and defined $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
+ ) {
+ push( @{ $data{ $loop } }, $self->{'imager'}->data->{ $assert }->{ $xsqueue }->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'} );
+ } else {
+ push( @{ $data{ $loop } }, 0 );
+ }
+ }
}
- }
- }
- # transform %data into something GD likes
- my @data_for_gd;
- foreach my $loop ( sort keys %data ) {
- push( @data_for_gd, $data{ $loop } );
- }
+ # transform %data into something GD likes
+ my @data_for_gd;
+ foreach my $m ( sort keys %data ) {
+ push( @data_for_gd, $data{ $m } );
+ }
- # send it to GD!
- $self->make_gdgraph( "LoopWar_$metric",
- [ sort keys %{ $self->{'imager'}->poe_loops } ],
- 'iterations/sec',
- \@data_for_gd,
- );
+ # send it to GD!
+ $self->make_gdgraph( "LoopWar_$metric",
+ [ sort keys %{ $self->{'imager'}->poe_loops } ],
+ \@data_for_gd,
+ $assert,
+ $xsqueue,
+ );
+ }
+ }
}
return;
}
sub make_gdgraph {
my $self = shift;
my $metric = shift;
my $legend = shift;
- my $ylabel = shift;
my $data = shift;
+ my $assert = shift;
+ my $xsqueue = shift;
# Get the graph object
my $graph = new GD::Graph::lines( 800, 600 );
# Set some stuff
$graph->set(
# 'x_label' => 'POE Versions',
- 'title' => $metric,
+ 'title' => $metric . ( defined $xsqueue ? " ($assert - $xsqueue)" : '' ),
'line_width' => 1,
'boxclr' => 'black',
'overwrite' => 0,
'x_labels_vertical' => 1,
'x_all_ticks' => 1,
'legend_placement' => 'BL',
- 'y_label' => $ylabel,
+ 'y_label' => 'iterations/sec',
# 3d options only
#'line_depth' => 2.5,
) or die $graph->error;
# Set the legend
$graph->set_legend( @$legend );
# Set Font stuff
$graph->set_legend_font( GD::gdMediumBoldFont );
$graph->set_x_axis_font( GD::gdMediumBoldFont );
$graph->set_y_axis_font( GD::gdMediumBoldFont );
$graph->set_y_label_font( GD::gdMediumBoldFont );
$graph->set_title_font( GD::gdGiantFont );
# Manufacture the data
my $readydata = [
[ map { 'POE-' . $_ } @{ $self->{'imager'}->poe_versions_sorted } ],
@$data,
];
# Plot it!
$graph->plot( $readydata ) or die $graph->error;
# Print it!
my $filename = $self->{'opts'}->{'dir'} . $metric . '_' .
- ( $self->{'imager'}->litetests ? 'lite' : 'heavy' ) . '_' .
- ( $self->{'imager'}->noasserts ? 'noasserts' : 'asserts' ) . '_' .
- ( $self->{'imager'}->noxsqueue ? 'noxsqueue' : 'xsqueue' ) .
+ ( $self->{'imager'}->litetests ? 'lite' : 'heavy' ) .
+ ( defined $xsqueue ? '_' . $assert . '_' . $xsqueue : '' ) .
'.png';
open( my $fh, '>', $filename ) or die 'Cannot open graph file!';
binmode( $fh );
print $fh $graph->gd->png();
close( $fh );
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::Imager::BasicStatistics - Plugin to generates basic statistics graphs
=head1 SYNOPSIS
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker::Imager -e 'imager( { type => "BasicStatistics" } )'
=head1 ABSTRACT
This plugin for Imager generates some kinds of graphs from the benchmark tests.
=head1 DESCRIPTION
This package generates some basic graphs from the statistics output. Since the POE::Loop::* modules really are responsible
for the backend logic of POE, it makes sense to graph all related metrics of a single loop across POE versions to see if
it performs differently. The related benchmark metrics are: events, alarms, filehandles, and startup.
-This will generate 2 types of graphs:
+This will generate some types of graphs:
=over 4
=item Loops against each other
Each metric will have a picture for itself, showing how each loop compare against each other with the POE versions.
-file: BasicStatistics/$metric.png
+file: BasicStatistics/LoopWar_$metric_$lite_$assert_$xsqueue.png
=item Single Loop over POE versions
Each Loop will have a picture for itself, showing how each metric performs over POE versions.
-file: BasicStatistics/$loop.png
+file: BasicStatistics/Bench_$loop_$lite_$assert_$xsqueue.png
+
+=item Single Loop over POE versions with assert/xsqueue
+
+Each Loop will have a picture for itself, showing how each metric is affected by the assert/xsqueue options.
+
+file: BasicStatistics/Options_$loop_$metric_$lite.png
=back
=head1 EXPORT
Nothing.
=head1 SEE ALSO
L<POE::Devel::Benchmarker::Imager>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/Utils.pm b/lib/POE/Devel/Benchmarker/Utils.pm
index 0ca6dce..f3ea8cd 100644
--- a/lib/POE/Devel/Benchmarker/Utils.pm
+++ b/lib/POE/Devel/Benchmarker/Utils.pm
@@ -1,210 +1,202 @@
# Declare our package
package POE::Devel::Benchmarker::Utils;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.04';
# set ourself up for exporting
use base qw( Exporter );
-our @EXPORT_OK = qw( poeloop2load loop2realversion beautify_times knownloops generateTestfile );
+our @EXPORT_OK = qw( poeloop2load load2poeloop loop2realversion beautify_times knownloops generateTestfile );
# returns the filename for a particular test
sub generateTestfile {
my $heap = shift;
return 'POE-' . $heap->{'current_version'} .
'-' . $heap->{'current_loop'} .
'-' . ( $heap->{'lite_tests'} ? 'LITE' : 'HEAVY' ) .
'-' . ( $heap->{'current_assertions'} ? 'assert' : 'noassert' ) .
'-' . ( $heap->{'current_noxsqueue'} ? 'noxsqueue' : 'xsqueue' );
}
+# maintains the mapping of the loop <-> real module
+my %poe2load = (
+ 'Event' => 'Event',
+ 'IO_Poll' => 'IO::Poll',
+ 'Event_Lib' => 'Event::Lib',
+ 'EV' => 'EV',
+ 'Glib' => 'Glib',
+ 'Tk' => 'Tk',
+ 'Gtk' => 'Gtk',
+ 'Prima' => 'Prima',
+ 'Wx' => 'Wx',
+ 'Kqueue' => undef,
+ 'Select' => undef,
+);
+
# returns the proper "load" stuff for a specific loop
sub poeloop2load {
my $eventloop = shift;
- # Decide which event loop to use
- # Event_Lib EV Glib Prima Gtk Wx Kqueue Tk Select IO_Poll
- if ( $eventloop eq 'Event' ) {
- return 'Event';
- } elsif ( $eventloop eq 'IO_Poll' ) {
- return 'IO::Poll';
- } elsif ( $eventloop eq 'Event_Lib' ) {
- return 'Event::Lib';
- } elsif ( $eventloop eq 'EV' ) {
- return 'EV';
- } elsif ( $eventloop eq 'Glib' ) {
- return 'Glib';
- } elsif ( $eventloop eq 'Tk' ) {
- return 'Tk',
- } elsif ( $eventloop eq 'Gtk' ) {
- return 'Gtk';
- } elsif ( $eventloop eq 'Prima' ) {
- return 'Prima';
- } elsif ( $eventloop eq 'Wx' ) {
- return 'Wx';
- } elsif ( $eventloop eq 'Kqueue' ) {
- # FIXME dunno what to do here!
- return;
- } elsif ( $eventloop eq 'Select' ) {
- return;
+ if ( exists $poe2load{ $eventloop } ) {
+ return $poe2load{ $eventloop };
} else {
die "Unknown event loop!";
}
}
# returns the version of the "real" installed module that the loop uses
sub loop2realversion {
my $eventloop = shift;
# Decide which event loop to use
if ( ! defined $eventloop ) {
return;
} elsif ( $eventloop eq 'Event' ) {
return $Event::VERSION;
} elsif ( $eventloop eq 'IO_Poll' ) {
return $IO::Poll::VERSION;
} elsif ( $eventloop eq 'Event_Lib' ) {
return $Event::Lib::VERSION;
} elsif ( $eventloop eq 'EV' ) {
return $EV::VERSION;
} elsif ( $eventloop eq 'Glib' ) {
return $Glib::VERSION;
} elsif ( $eventloop eq 'Tk' ) {
return $Tk::VERSION;
} elsif ( $eventloop eq 'Gtk' ) {
return $Gtk::VERSION;
} elsif ( $eventloop eq 'Prima' ) {
return $Prima::VERSION;
} elsif ( $eventloop eq 'Wx' ) {
return $Wx::VERSION;
} elsif ( $eventloop eq 'Kqueue' ) {
# FIXME how do I do this?
return;
} elsif ( $eventloop eq 'Select' ) {
return 'BUILTIN';
} else {
die "Unknown event loop!";
}
}
# helper routine to parse times() output
sub beautify_times {
my $string = shift;
my $origdata = shift;
# split it up
$string =~ s/^\s+//; $string =~ s/\s+$//;
my @times = split( /\s+/, $string );
# make the data struct
# ($user,$system,$cuser,$csystem) = times;
my $data = {
'u' => $times[4] - $times[0],
's' => $times[5] - $times[1],
'cu' => $times[6] - $times[2],
'cs' => $times[7] - $times[3],
};
# add original data?
if ( $origdata ) {
$data->{'s_user'} = $times[0];
$data->{'s_sys'} = $times[1];
$data->{'s_cuser'} = $times[2];
$data->{'s_csys'} = $times[3];
$data->{'e_user'} = $times[4];
$data->{'e_sys'} = $times[5];
$data->{'e_cuser'} = $times[6];
$data->{'e_csys'} = $times[7];
}
# send it back!
return $data;
}
# returns a list of "known" POE loops
sub knownloops {
# FIXME we remove Wx because I suck.
# FIXME I have no idea how to load/unload Kqueue...
return [ qw( Event_Lib EV Glib Prima Gtk Tk Select IO_Poll ) ];
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::Utils - Various utility routines for POE::Devel::Benchmarker
=head1 SYNOPSIS
perl -MPOE::Devel::Benchmarker::Utils -e 'print poeloop2load( "IO_Poll" )'
=head1 ABSTRACT
This package contains the utility routines and constants that POE::Devel::Benchmarker needs.
=head1 EXPORT
This package exports those subs via @EXPORT_OK:
=over 4
=item knownloops()
Returns an arrayref of the "known" POE loops as of this version of the Benchmarker
=item poeloop2load()
Returns the "parent" class to load for a specific loop. An example is:
$real = poeloop2load( 'IO_Poll' ); # $real now contains "IO::Poll"
=item loop2realversion()
Returns the version of the "parent" class for a specific loop. An example is:
$ver = loop2realversion( 'IO_Poll' ); # $ver now contains $IO::Poll::VERSION
=item beautify_times()
Returns a hashref of data from parsing 2 consecutive times() structures in a string. You can pass an additional parameter
( boolean ) to include the original data. An example is:
print Data::Dumper::Dumper( beautify_times( '0.1 0 0 0 0.1 0 0.76 0.09', 1 ) );
{
"sys" => 0, # total system time
"user" => 0, # total user time
"csys" => 0.76 # total children system time
"cuser" => 0.08 # total children user time
"e_csys" => "0.09", # end children system time ( optional )
"e_cuser" => "0.76", # end children user time ( optional )
"e_sys" => 0, # end system time ( optional )
"e_user" => "0.1", # end user time ( optional )
"s_csys" => 0, # start children system time ( optional )
"s_cuser" => 0, # start children user time ( optional )
"s_sys" => 0, # start system time ( optional )
"s_user" => "0.1" # start user time ( optional )
}
=back
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
|
apocalypse/perl-poe-benchmarker
|
87601897bc77b8ca3489bb9565809035681938db
|
nearing release of 0.04
|
diff --git a/Build.PL b/Build.PL
index 88358bf..905d6f4 100755
--- a/Build.PL
+++ b/Build.PL
@@ -1,102 +1,101 @@
# Build.PL
use Module::Build;
my $build = Module::Build->new(
# look up Module::Build::API for the info!
'dynamic_config' => 0,
'module_name' => 'POE::Devel::Benchmarker',
'license' => 'perl',
'dist_abstract' => "Benchmarking POE's performance ( acts more like a smoker )",
'dist_author' => 'Apocalypse <APOCAL@cpan.org>',
'create_packlist' => 1,
'create_makefile_pl' => 'traditional',
'create_readme' => 1,
'test_files' => 't/*.t',
'add_to_cleanup' => [ 'META.yml', 'Makefile.PL', 'README' ], # automatically generated
'requires' => {
# POE Stuff
'POE' => 0,
'POE::Session::AttributeBased' => 0,
# misc perl stuff
'Time::HiRes' => 0,
'version' => 0,
'Devel::Hide' => 0,
# Analyzer reqs
'YAML::Tiny' => 0,
- #'POE::Component::SimpleDBI' => 0,
# GetPOEdists reqs
'LWP::UserAgent' => 0,
'HTML::LinkExtor' => 0,
'URI::URL' => 0,
'Archive::Tar' => 0,
# Imager reqs
- 'Chart::Clicker' => 0,
- 'Chart::Clicker::Data::DataSet' => 0,
- 'Chart::Clicker::Data::Series' => 0,
+ 'GD::Graph::lines' => 0,
+ 'Class::Accessor::Fast' => 0,
+ 'Module::Pluggable' => 0,
},
'recommends' => {
# Test stuff
'Test::More' => '0.86', # require latest for note() support in t/a_is_prereq_outdated.t
# our POE loops!
'POE::Loop::Event' => 0,
'POE::Loop::Event_Lib' => 0,
'POE::Loop::EV' => 0,
'POE::Loop::Glib' => 0,
'POE::Loop::Prima' => 0,
'POE::Loop::Gtk' => 0,
'POE::Loop::Wx' => 0,
'POE::Loop::Kqueue' => 0,
# included in POE ( listed here for completeness )
#'POE::Loop::Tk' => 0,
#'POE::Loop::Select' => 0,
#'POE::Loop::IO_Poll' => 0,
# the loops' dependencies
'Event' => 0,
'Event::Lib' => 0,
'EV' => 0,
'Glib' => 0,
'Prima' => 0,
'Gtk' => 0,
'Wx' => 0,
'Tk' => 0,
# the XS queue
'POE::XS::Queue::Array' => 0,
},
# FIXME wishlist...
# 'test_requires' => {
# # Test stuff
# 'Test::Compile' => 0,
# 'Test::Perl::Critic' => 0,
# 'Test::Dependencies' => 0,
# 'Test::Distribution' => 0,
# 'Test::Fixme' => 0,
# 'Test::HasVersion' => 0,
# 'Test::Kwalitee' => 0,
# 'Test::CheckManifest' => 0,
# 'Test::MinimumVersion' => 0,
# 'Test::Pod::Coverage' => 0,
# 'Test::Spelling' => 0,
# 'Test::Pod' => 0,
# 'Test::Prereq' => 0,
# 'Test::Strict' => 0,
# 'Test::UseAllModules' => 0,
# },
);
# all done!
$build->create_build_script;
diff --git a/Changes b/Changes
index 6c77d40..cea775c 100755
--- a/Changes
+++ b/Changes
@@ -1,31 +1,32 @@
Revision history for Perl extension POE::Devel::Benchmarker
-* 0.04
+* 0.04 Mon Dec 15 15:12:42 2008
- Started work on the image generator ( Imager )
+ Started work on the image generator ( Imager ) and added the BasicStatistics plugin, yay!
Added automatic "pick up where we left off" to the benchmarker
Added the freshstart option to benchmark()
Tweaked the GetPOEdists sub so it will work in the "work directory" and in the poedists dir
Tweaked the YAML output so it's smaller
Removed POE::Loop::Wx from autoprobing ( I'm unable to get it to work )
+ Removed POE::Loop::Kqueue from autoprobing ( I'm unable to get it to work )
Hardcoded the Benchmarker routines to skip POE < 0.13 ( I'm unable to get it to work )
* 0.03
Added the loop option to benchmark(), thanks dngor!
Added the poe option to benchmark(), thanks dngor!
Added the noxsqueue option to benchmark()
Added the noasserts option to benchmark()
Automatically enable noxsqueue option if we cannot load POE::XS::Queue::Array, saving time
Bump Test::More version requirement because some people reported failures with note()
Fixed bug in SubProcess where it crashed on old POEs that didn't load IO::Handle
More documentation additions/tweaks
* 0.02
Added the Analyzer module ( and dump YAML files, yay! )
A lot of minor changes+tweaks to get a better dump format
* 0.01
initial release
diff --git a/MANIFEST b/MANIFEST
index bb66c92..0ed8dd0 100755
--- a/MANIFEST
+++ b/MANIFEST
@@ -1,35 +1,36 @@
Makefile.PL
Build.PL
MANIFEST
MANIFEST.SKIP
README
lib/POE/Devel/Benchmarker.pm
lib/POE/Devel/Benchmarker/GetInstalledLoops.pm
lib/POE/Devel/Benchmarker/GetPOEdists.pm
lib/POE/Devel/Benchmarker/SubProcess.pm
lib/POE/Devel/Benchmarker/Utils.pm
lib/POE/Devel/Benchmarker/Analyzer.pm
lib/POE/Devel/Benchmarker/Imager.pm
+lib/POE/Devel/Benchmarker/Imager/BasicStatistics.pm
META.yml
Changes
t/1_load.t
t/a_critic.t
t/a_kwalitee.t
t/a_pod.t
t/a_pod_spelling.t
t/a_pod_coverage.t
t/a_strict.t
t/a_hasversion.t
t/a_minimumversion.t
t/a_manifest.t
t/a_distribution.t
t/a_compile.t
t/a_dependencies.t
t/a_fixme.t
t/a_prereq.t
t/a_prereq_build.t
t/a_dosnewline.t
t/a_perlmetrics.t
t/a_is_prereq_outdated.t
diff --git a/lib/POE/Devel/Benchmarker.pm b/lib/POE/Devel/Benchmarker.pm
index bff18c7..24d2c6c 100644
--- a/lib/POE/Devel/Benchmarker.pm
+++ b/lib/POE/Devel/Benchmarker.pm
@@ -1,897 +1,889 @@
# Declare our package
package POE::Devel::Benchmarker;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.04';
# auto-export the only sub we have
-BEGIN {
- require Exporter;
- use vars qw( @ISA @EXPORT );
- @ISA = qw(Exporter);
- @EXPORT = qw( benchmark );
-}
+use base qw( Exporter );
+our @EXPORT = qw( benchmark );
# Import what we need from the POE namespace
-sub POE::Kernel::ASSERT_DEFAULT { 1 }
-sub POE::Session::ASSERT_DEFAULT { 1 }
use POE qw( Session Filter::Line Wheel::Run );
use base 'POE::Session::AttributeBased';
# we need hires times
use Time::HiRes qw( time );
# load comparison stuff
use version;
# use the power of YAML
use YAML::Tiny;
# Load our stuff
use POE::Devel::Benchmarker::GetInstalledLoops;
use POE::Devel::Benchmarker::Utils qw( poeloop2load knownloops generateTestfile );
use POE::Devel::Benchmarker::Analyzer;
# Actually run the tests!
sub benchmark {
my $options = shift;
# set default options
my $lite_tests = 1;
my $quiet_mode = 0;
my $forceloops = undef; # default to autoprobe all
my $forcepoe = undef; # default to all found POE versions in poedists/
my $forcenoxsqueue = 0; # default to try and load it
my $forcenoasserts = 0; # default is to run it
my $freshstart = 0; # always resume where we left off
# process our options
if ( defined $options and ref $options and ref( $options ) eq 'HASH' ) {
# process YES for freshstart
if ( exists $options->{'freshstart'} ) {
if ( $options->{'freshstart'} ) {
$freshstart = 1;
}
}
# process NO for XS::Queue::Array
if ( exists $options->{'noxsqueue'} ) {
if ( $options->{'noxsqueue'} ) {
$forcenoxsqueue = 1;
}
}
# process NO for ASSERT
if ( exists $options->{'noasserts'} ) {
if ( $options->{'noasserts'} ) {
$forcenoasserts = 1;
}
}
# process LITE tests
if ( exists $options->{'litetests'} ) {
if ( $options->{'litetests'} ) {
$lite_tests = 1;
} else {
$lite_tests = 0;
}
}
# process quiet mode
if ( exists $options->{'quiet'} ) {
if ( $options->{'quiet'} ) {
$quiet_mode = 1;
} else {
$quiet_mode = 0;
}
}
# process forceloops
if ( exists $options->{'loop'} and defined $options->{'loop'} ) {
if ( ! ref $options->{'loop'} ) {
# split it via CSV
$forceloops = [ split( /,/, $options->{'loop'} ) ];
foreach ( @$forceloops ) {
$_ =~ s/^\s+//; $_ =~ s/\s+$//;
}
} else {
# treat it as array
$forceloops = $options->{'loop'};
}
# check for !loop modules
my @noloops;
foreach my $l ( @$forceloops ) {
if ( $l =~ /^\!/ ) {
push( @noloops, substr( $l, 1 ) );
}
}
if ( scalar @noloops ) {
# replace the forceloops with ALL known, then subtract noloops from it
my %bad;
@bad{@noloops} = () x @noloops;
@$forceloops = grep { !exists $bad{$_} } @{ knownloops() };
}
}
# process the poe versions
if ( exists $options->{'poe'} and defined $options->{'poe'} ) {
if ( ! ref $options->{'poe'} ) {
# split it via CSV
$forcepoe = [ split( /,/, $options->{'poe'} ) ];
foreach ( @$forcepoe ) {
$_ =~ s/^\s+//; $_ =~ s/\s+$//;
}
} else {
# treat it as array
$forcepoe = $options->{'poe'};
}
}
}
# do some sanity checks
if ( ! -d 'poedists' ) {
die "The 'poedists' directory is not found in the working directory!";
}
if ( ! -d 'results' ) {
die "The 'results' directory is not found in the working directory!";
}
if ( ! $quiet_mode ) {
print "[BENCHMARKER] Starting up...\n";
}
# Create our session
POE::Session->create(
__PACKAGE__->inline_states(),
'heap' => {
# misc stuff
'quiet_mode' => $quiet_mode,
# override our testing behavior
'lite_tests' => $lite_tests,
'forceloops' => $forceloops,
'forcepoe' => $forcepoe,
'forcenoxsqueue' => $forcenoxsqueue,
'forcenoasserts' => $forcenoasserts,
'freshstart' => $freshstart,
},
);
# Fire 'er up!
POE::Kernel->run();
return;
}
# Starts up our session
sub _start : State {
# okay, get all the dists we can!
my @versions;
if ( opendir( DISTS, 'poedists' ) ) {
foreach my $d ( readdir( DISTS ) ) {
if ( $d =~ /^POE\-(.+)$/ and $d !~ /\.tar\.gz$/ ) {
# FIXME skip POE < 0.13 because I can't get it to work
my $ver = version->new( $1 );
- if ( $ver > v0.13 ) {
- push( @versions, $ver->stringify );
+ if ( $ver > v0.12 ) {
+ push( @versions, $ver );
}
}
}
closedir( DISTS ) or die $!;
} else {
print "[BENCHMARKER] Unable to open 'poedists' for reading: $!\n";
return;
}
# should we munge the versions list?
if ( defined $_[HEAP]->{'forcepoe'} ) {
# check for !poe versions
my @nopoe;
foreach my $p ( @{ $_[HEAP]->{'forcepoe'} } ) {
if ( $p =~ /^\!/ ) {
push( @nopoe, substr( $p, 1 ) );
}
}
if ( scalar @nopoe ) {
# remove the nopoe versions from the found
my %bad;
@bad{@nopoe} = () x @nopoe;
- @versions = grep { !exists $bad{$_} } @versions;
+ @versions = grep { !exists $bad{$_->stringify} } @versions;
} else {
# make sure the @versions contains only what we specified
my %good;
@good{ @{ $_[HEAP]->{'forcepoe'} } } = () x @{ $_[HEAP]->{'forcepoe'} };
- @versions = grep { exists $good{$_} } @versions;
+ @versions = grep { exists $good{$_->stringify} } @versions;
}
}
# sanity
if ( ! scalar @versions ) {
print "[BENCHMARKER] Unable to find any POE version in the 'poedists' directory!\n";
return;
}
# set our alias
$_[KERNEL]->alias_set( 'Benchmarker' );
# sanely handle some signals
$_[KERNEL]->sig( 'INT', 'handle_kill' );
$_[KERNEL]->sig( 'TERM', 'handle_kill' );
# okay, go through all the dists in version order
- @versions = sort { $b <=> $a }
- map { version->new( $_ ) } @versions;
+ @versions = sort { $a <=> $b } @versions;
# Store the versions in our heap
$_[HEAP]->{'VERSIONS'} = \@versions;
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Detected available POE versions -> " . join( " ", @versions ) . "\n";
}
# First of all, we need to find out what loop libraries are installed
getPOEloops( $_[HEAP]->{'quiet_mode'}, $_[HEAP]->{'forceloops'} );
return;
}
sub _stop : State {
# tell the wheel to kill itself
if ( defined $_[HEAP]->{'WHEEL'} ) {
$_[HEAP]->{'WHEEL'}->kill( 9 );
undef $_[HEAP]->{'WHEEL'};
}
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Shutting down...\n";
}
return;
}
# misc POE handlers
sub _child : State {
return;
}
sub handle_kill : State {
return;
}
# we received list of loops from GetInstalledLoops
sub found_loops : State {
$_[HEAP]->{'installed_loops'} = [ sort { $a cmp $b } @{ $_[ARG0] } ];
# sanity check
if ( scalar @{ $_[HEAP]->{'installed_loops'} } == 0 ) {
print "[BENCHMARKER] Detected no available POE::Loop, check your configuration?!?\n";
return;
}
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Detected available POE::Loops -> " . join( " ", @{ $_[HEAP]->{'installed_loops'} } ) . "\n";
}
# Okay, do we have XS::Queue installed?
if ( ! $_[HEAP]->{'forcenoxsqueue'} ) {
eval { require POE::XS::Queue::Array };
if ( $@ ) {
$_[HEAP]->{'forcenoxsqueue'} = 1;
}
}
# Fire up the analyzer
initAnalyzer( $_[HEAP]->{'quiet_mode'} );
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Starting the benchmarks!" .
( $_[HEAP]->{'forcenoxsqueue'} ? ' Skipping XS::Queue Tests!' : '' ) .
( $_[HEAP]->{'forcenoasserts'} ? ' Skipping ASSERT Tests!' : '' ) .
"\n";
}
# start the benchmark!
$_[KERNEL]->yield( 'run_benchmark' );
return;
}
# Runs one benchmark
sub run_benchmark : State {
# Grab the version from the top of the array
$_[HEAP]->{'current_version'} = shift @{ $_[HEAP]->{'VERSIONS'} };
# did we run out of versions?
if ( ! defined $_[HEAP]->{'current_version'} ) {
# We're done, let POE die...
$_[KERNEL]->alias_remove( 'Benchmarker' );
} else {
$_[HEAP]->{'loops'} = [ @{ $_[HEAP]->{'installed_loops'} } ];
# okay, fire off the first loop
$_[KERNEL]->yield( 'bench_loop' );
}
return;
}
# runs one loop
sub bench_loop : State {
# select our current loop
$_[HEAP]->{'current_loop'} = shift @{ $_[HEAP]->{'loops'} };
# are we done with all loops?
if ( ! defined $_[HEAP]->{'current_loop'} ) {
# yay, go back to the main handler
$_[KERNEL]->yield( 'run_benchmark' );
} else {
# Start the assert test
if ( $_[HEAP]->{'forcenoasserts'} ) {
$_[HEAP]->{'assertions'} = [ qw( 0 ) ];
} else {
$_[HEAP]->{'assertions'} = [ qw( 0 1 ) ];
}
$_[KERNEL]->yield( 'bench_asserts' );
}
return;
}
# runs an assertion
sub bench_asserts : State {
# select our current assert state
$_[HEAP]->{'current_assertions'} = shift @{ $_[HEAP]->{'assertions'} };
# are we done?
if ( ! defined $_[HEAP]->{'current_assertions'} ) {
# yay, go back to the loop handler
$_[KERNEL]->yield( 'bench_loop' );
} else {
# Start the xsqueue test
if ( $_[HEAP]->{'forcenoxsqueue'} ) {
$_[HEAP]->{'noxsqueue'} = [ qw( 1 ) ];
} else {
$_[HEAP]->{'noxsqueue'} = [ qw( 0 1 ) ];
}
$_[KERNEL]->yield( 'bench_xsqueue' );
}
return;
}
# runs test with or without xsqueue
sub bench_xsqueue : State {
# select our current noxsqueue state
$_[HEAP]->{'current_noxsqueue'} = shift @{ $_[HEAP]->{'noxsqueue'} };
# are we done?
if ( ! defined $_[HEAP]->{'current_noxsqueue'} ) {
# yay, go back to the assert handler
$_[KERNEL]->yield( 'bench_asserts' );
} else {
# do some careful analysis
$_[KERNEL]->yield( 'bench_checkprevioustest' );
}
return;
}
# Checks to see if this test was run in the past
sub bench_checkprevioustest : State {
# okay, do we need to check and see if we already did this test?
if ( ! $_[HEAP]->{'freshstart'} ) {
# determine the file used
my $file = generateTestfile( $_[HEAP] );
# does it exist?
if ( -e "results/$file.yml" and -f _ and -s _ ) {
# okay, sanity check it
my $yaml = YAML::Tiny->read( "results/$file.yml" );
if ( defined $yaml ) {
# inrospect it!
my $isvalid = 0;
eval {
- # the version must at least match us
- $isvalid = ( $yaml->[0]->{'benchmarker'} eq $POE::Devel::Benchmarker::VERSION ? 1 : 0 );
- if ( $isvalid ) {
- # simple sanity check: the "uname" param is at the end of the YML, so if it loads fine we know it's there
- if ( ! exists $yaml->[0]->{'uname'} ) {
- $isvalid = undef;
- }
+ # simple sanity check: the "x_bench" param is at the end of the YML, so if it loads fine we know it's there
+ if ( exists $yaml->[0]->{'x_bench'} ) {
+ # version must at least match us
+ $isvalid = ( $yaml->[0]->{'x_bench'} eq $POE::Devel::Benchmarker::VERSION ? 1 : 0 );
+ } else {
+ $isvalid = undef;
}
};
if ( $isvalid ) {
# yay, this test is A-OK!
$_[KERNEL]->yield( 'bench_xsqueue' );
return;
} else {
# was it truncated?
if ( ! defined $isvalid ) {
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] YAML file($file) from previous test was corrupt!\n";
}
}
}
} else {
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Unable to load YAML file($file) from previous test run: " . YAML::Tiny->errstr . "\n";
}
}
}
}
# could not find previous file or FRESHSTART, proceed normally
$_[KERNEL]->yield( 'create_subprocess' );
return;
}
# actually runs the subprocess
sub create_subprocess : State {
# Okay, start testing this specific combo!
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "Testing " . generateTestfile( $_[HEAP] ) . "\n";
}
# save the starttime
$_[HEAP]->{'current_starttime'} = time();
$_[HEAP]->{'current_starttimes'} = [ times() ];
# Okay, create the wheel::run to handle this
my $looploader = poeloop2load( $_[HEAP]->{'current_loop'} );
$_[HEAP]->{'WHEEL'} = POE::Wheel::Run->new(
'Program' => $^X,
'ProgramArgs' => [ '-Ipoedists/POE-' . $_[HEAP]->{'current_version'},
'-Ipoedists/POE-' . $_[HEAP]->{'current_version'} . '/lib',
( defined $looploader ? "-M$looploader" : () ),
'-MPOE::Devel::Benchmarker::SubProcess',
'-e',
'POE::Devel::Benchmarker::SubProcess::benchmark',
$_[HEAP]->{'current_version'},
$_[HEAP]->{'current_loop'},
$_[HEAP]->{'current_assertions'},
$_[HEAP]->{'lite_tests'},
$_[HEAP]->{'current_noxsqueue'},
],
# Kill off existing FD's
'CloseOnCall' => 1,
# setup our data handlers
'StdoutEvent' => 'Got_STDOUT',
'StderrEvent' => 'Got_STDERR',
# the error handler
'ErrorEvent' => 'Got_ERROR',
'CloseEvent' => 'Got_CLOSED',
# set our filters
'StderrFilter' => POE::Filter::Line->new(),
'StdoutFilter' => POE::Filter::Line->new(),
);
if ( ! defined $_[HEAP]->{'WHEEL'} ) {
die 'Unable to create a new wheel!';
} else {
# smart CHLD handling
if ( $_[KERNEL]->can( "sig_child" ) ) {
$_[KERNEL]->sig_child( $_[HEAP]->{'WHEEL'}->PID => 'Got_CHLD' );
} else {
$_[KERNEL]->sig( 'CHLD', 'Got_CHLD' );
}
}
# setup our data we received from the subprocess
$_[HEAP]->{'current_data'} = '';
# Okay, we timeout this test after some time for sanity
$_[HEAP]->{'test_timedout'} = 0;
if ( $_[HEAP]->{'lite_tests'} ) {
# on my core2duo 1.2ghz laptop, running Gtk+LITE+assert+noxsqueue takes approx 45s
$_[HEAP]->{'TIMER'} = $_[KERNEL]->delay_set( 'test_timedout' => 60 * 2 );
} else {
# on my core2duo 1.2ghz laptop, running Gtk+HEAVY+assert+noxsqueue takes all day long :(
$_[HEAP]->{'TIMER'} = $_[KERNEL]->delay_set( 'test_timedout' => 60 * 15 );
}
return;
}
# Got a CHLD event!
sub Got_CHLD : State {
$_[KERNEL]->sig_handled();
return;
}
# Handles child STDERR output
sub Got_STDERR : State {
my $input = $_[ARG0];
# skip empty lines
if ( $input ne '' ) {
# save it!
$_[HEAP]->{'current_data'} .= '!STDERR: ' . $input . "\n";
}
return;
}
# Handles child STDOUT output
sub Got_STDOUT : State {
my $input = $_[ARG0];
# save it!
$_[HEAP]->{'current_data'} .= $input . "\n";
return;
}
# Handles child error
sub Got_ERROR : State {
# Copied from POE::Wheel::Run manpage
my ( $operation, $errnum, $errstr ) = @_[ ARG0 .. ARG2 ];
# ignore exit 0 errors
if ( $errnum != 0 ) {
print "[BENCHMARKER] Wheel::Run got an $operation error $errnum: $errstr\n";
}
return;
}
# Handles child DIE'ing
sub Got_CLOSED : State {
# Get rid of the wheel
undef $_[HEAP]->{'WHEEL'};
# get rid of the delay
$_[KERNEL]->alarm_remove( $_[HEAP]->{'TIMER'} );
undef $_[HEAP]->{'TIMER'};
# wrap up this test
$_[KERNEL]->yield( 'wrapup_test' );
return;
}
# a test timed out, unfortunately!
sub test_timedout : State {
# tell the wheel to kill itself
$_[HEAP]->{'WHEEL'}->kill( 9 );
undef $_[HEAP]->{'WHEEL'};
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Test Timed Out!\n";
}
$_[HEAP]->{'test_timedout'} = 1;
# wrap up this test
$_[KERNEL]->yield( 'wrapup_test' );
return;
}
# finalizes a test
sub wrapup_test : State {
# we're done with this benchmark!
$_[HEAP]->{'current_endtime'} = time();
$_[HEAP]->{'current_endtimes'} = [ times() ];
# store the data
my $file = generateTestfile( $_[HEAP] );
if ( open( my $fh, '>', "results/$file" ) ) {
print $fh "STARTTIME: " . $_[HEAP]->{'current_starttime'} . " -> TIMES " . join( " ", @{ $_[HEAP]->{'current_starttimes'} } ) . "\n";
print $fh "$file\n";
print $fh $_[HEAP]->{'current_data'} . "\n";
if ( $_[HEAP]->{'test_timedout'} ) {
print $fh "\nTEST TERMINATED DUE TO TIMEOUT\n";
}
print $fh "ENDTIME: " . $_[HEAP]->{'current_endtime'} . " -> TIMES " . join( " ", @{ $_[HEAP]->{'current_endtimes'} } ) . "\n";
close( $fh ) or die $!;
} else {
print "[BENCHMARKER] Unable to open results/$file for writing -> $!\n";
}
# Send the data to the Analyzer to process
$_[KERNEL]->post( 'Benchmarker::Analyzer', 'analyze', {
'poe' => {
'v' => $_[HEAP]->{'current_version'}->stringify, # YAML::Tiny doesn't like version objects :(
'loop' => 'POE::Loop::' . $_[HEAP]->{'current_loop'},
},
't' => {
's_ts' => $_[HEAP]->{'current_starttime'},
'e_ts' => $_[HEAP]->{'current_endtime'},
'd' => $_[HEAP]->{'current_endtime'} - $_[HEAP]->{'current_starttime'},
's_t' => [ @{ $_[HEAP]->{'current_starttimes'} } ],
'e_t' => [ @{ $_[HEAP]->{'current_endtimes'} } ],
},
'raw' => $_[HEAP]->{'current_data'},
'test' => $file,
- 'benchmarker' => $POE::Devel::Benchmarker::VERSION,
+ 'x_bench' => $POE::Devel::Benchmarker::VERSION,
( $_[HEAP]->{'test_timedout'} ? ( 'timedout' => 1 ) : () ),
( $_[HEAP]->{'lite_tests'} ? ( 'litetests' => 1 ) : () ),
( $_[HEAP]->{'current_assertions'} ? ( 'asserts' => 1 ) : () ),
( $_[HEAP]->{'current_noxsqueue'} ? ( 'noxsqueue' => 1 ) : () ),
} );
# process the next test
$_[KERNEL]->yield( 'bench_xsqueue' );
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker - Benchmarking POE's performance ( acts more like a smoker )
=head1 SYNOPSIS
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker -e 'benchmark()'
=head1 ABSTRACT
This package of tools is designed to benchmark POE's performace across different
configurations. The current "tests" are:
=over 4
=item posts
This tests how long it takes to post() N times
This tests how long it took to dispatch/deliver all the posts enqueued in the post() test
This tests how long it took to yield() between 2 states for N times
=item calls
This tests how long it took to call() N times
=item alarms
This tests how long it took to add N alarms via alarm(), overwriting each other
This tests how long it took to add N alarms via alarm_add() and how long it took to delete them all
NOTE: alarm_add is not available on all versions of POE!
=item sessions
This tests how long it took to create N sessions, and how long it took to destroy them all
=item filehandles
This tests how long it took to toggle select_read N times on STDIN and a real filehandle via open()
This tests how long it took to toggle select_write N times on STDIN and a real filehandle via open()
=item POE startup time
This tests how long it took to start + close N instances of a "virgin" POE without any sessions/etc
=item POE Loops
This is actually a "super" test where all of the specific tests is ran against various POE::Loop::XYZ/FOO for comparison
=item POE Assertions
This is actually a "super" test where all of the specific tests is ran against POE with/without assertions enabled
=item POE::XS::Queue::Array
This is actually a "super" test where all of the specific tests is ran against POE with XS goodness enabled/disabled
=back
=head1 DESCRIPTION
This module is poorly documented now. Please give me some time to properly document it over time :)
=head2 INSTALLATION
Here's a simple outline to get you up to speed quickly. ( and smoking! )
=over 4
=item Install CPAN package + dependencies
Download+install the POE::Devel::Benchmarker package from CPAN
apoc@apoc-x300:~$ cpanp -i POE::Devel::Benchmarker
=item Setup initial directories
Go anywhere, and create the "parent" directory where you'll be storing test results + stuff. For this example,
I have chosen to use ~/poe-benchmarker:
apoc@apoc-x300:~$ mkdir poe-benchmarker
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ mkdir poedists results images
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker::GetPOEdists -e 'getPOEdists( 1 )'
( go get a coffee while it downloads if you're on a slow link, ha! )
=item Let 'er rip!
At this point you can start running the benchmark!
NOTE: the Benchmarker expects everything to be in the "local" directory!
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker -e 'benchmark()'
( go sleep or something, this will take a while! )
=back
=head2 BENCHMARKING
On startup the Benchmarker will look in the "poedists" directory and load all the distributions it sees untarred there. Once
that is done it will begin autoprobing for available POE::Loop packages. Once it determines what's available, it will begin
the benchmarks.
As the Benchmarker goes through the combinations of POE + Eventloop + Assertions + XS::Queue it will dump data into
the results directory. The Analyzer module also dumps YAML output in the same place, with the suffix of ".yml"
This module exposes only one subroutine, the benchmark() one. You can pass a hashref to it to set various options. Here is
a list of the valid options:
=over 4
=item freshstart => boolean
This will tell the Benchmarker to ignore any previous test runs stored in the 'results' directory.
benchmark( { freshstart => 1 } );
default: false
=item noxsqueue => boolean
This will tell the Benchmarker to force the unavailability of POE::XS::Queue::Array and skip those tests.
NOTE: The Benchmarker will set this automatically if it cannot load the module!
benchmark( { noxsqueue => 1 } );
default: false
=item noasserts => boolean
This will tell the Benchmarker to not run the ASSERT tests.
benchmark( { noasserts => 1 } );
default: false
=item litetests => boolean
This enables the "lite" tests which will not take up too much time.
benchmark( { litetests => 0 } );
default: true
=item quiet => boolean
This enables quiet mode which will not print anything to the console except for errors.
benchmark( { 'quiet' => 1 } );
default: false
=item loop => csv list or array
This overrides the built-in loop detection algorithm which searches for all known loops.
There is some "magic" here where you can put a negative sign in front of a loop and we will NOT run that.
NOTE: Capitalization is important!
benchmark( { 'loop' => 'IO_Poll,Select' } ); # runs only IO::Poll and Select
benchmark( { 'loop' => [ qw( Tk Gtk ) ] } ); # runs only Tk and Gtk
benchmark( { 'loop' => '-Tk' } ); # runs all available loops EXCEPT for TK
Known loops: Event_Lib EV Glib Prima Gtk Kqueue Tk Select IO_Poll
=item poe => csv list or array
This overrides the built-in POE version detection algorithm which pulls the POE versions from the 'poedists' directory.
There is some "magic" here where you can put a negative sign in front of a version and we will NOT run that.
NOTE: The Benchmarker will ignore versions that wasn't found in the directory!
benchmark( { 'poe' => '0.35,1.003' } ); # runs on 0.35 and 1.003
benchmark( { 'poe' => [ qw( 0.3009 0.12 ) ] } ); # runs on 0.3009 and 0.12
benchmark( { 'poe' => '-0.35' } ); # runs ALL tests except 0.35
=back
=head2 ANALYZING RESULTS
Please look at the pretty charts generated by the L<POE::Devel::Benchmarker::Imager> module.
=head1 EXPORT
Automatically exports the benchmark() subroutine.
=head1 TODO
=over 4
=item Perl version smoking
We should be able to run the benchmark over different Perl versions. This would require some fiddling with our
layout + logic. It's not that urgent because the workaround is to simply execute the benchmarker under a different
perl binary. It's smart enough to use $^X to be consistent across tests/subprocesses :)
=item Select the EV backend
<Khisanth> and if you are benchmarking, try it with POE using EV with EV using Glib? :P
<Apocalypse> I'm not sure how to configure the EV "backend" yet
<Apocalypse> too much docs for me to read hah
<Khisanth> Apocalypse: use EV::Glib; use Glib; use POE; :)
=item Be smarter in smoking timeouts
Currently we depend on the litetests option and hardcode some values including the timeout. If your machine is incredibly
slow, there's a chance that it could timeout unnecessarily. Please look at the outputs and check to see if there are unusual
failures, and inform me.
Also, some loops perform badly and take almost forever! /me glares at Gtk...
=item More benchmarks!
As usual, me and the crowd in #poe have plenty of ideas for tests. We'll be adding them over time, but if you have an idea please
drop me a line and let me know!
dngor said there was some benchmarks in the POE svn under trunk/queue...
I want a bench that actually tests socket traffic - stream 10MB of traffic over localhost, and time it?
LotR and Tapout contributed some samples, let's see if I can integrate them...
=item Add SQLite/DBI/etc support to the Analyzer
It would be nice if we could have a local SQLite db to dump our stats into. This would make arbitrary reports much easier than
loading raw YAML files and trying to make sense of them, ha! Also, this means somebody can do the smoking and send the SQLite
db to another person to generate the graphs, cool!
=item Kqueue loop support
As I don't have access to a *BSD box, I cannot really test this. Furthermore, it isn't clear on how I can force/unload this
module from POE...
=item Wx loop support
I have Wx installed, but it doesn't work. Obviously I don't know how to use Wx ;)
If you have experience, please drop me a line on how to do the "right" thing to get Wx loaded under POE. Here's the error:
Can't call method "MainLoop" on an undefined value at /usr/local/share/perl/5.8.8/POE/Loop/Wx.pm line 91.
=item XS::Loop support
The POE::XS::Loop::* modules theoretically could be tested too. However, they will only work in POE >= 1.003! This renders
the concept somewhat moot. Maybe, after POE has progressed some versions we can implement this...
=back
=head1 SEE ALSO
L<POE>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
BIG THANKS goes to Rocco Caputo E<lt>rcaputo@cpan.orgE<gt> for the first benchmarks!
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/Analyzer.pm b/lib/POE/Devel/Benchmarker/Analyzer.pm
index 08bf7aa..87f4961 100644
--- a/lib/POE/Devel/Benchmarker/Analyzer.pm
+++ b/lib/POE/Devel/Benchmarker/Analyzer.pm
@@ -1,458 +1,448 @@
# Declare our package
package POE::Devel::Benchmarker::Analyzer;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.04';
# auto-export the only sub we have
-BEGIN {
- require Exporter;
- use vars qw( @ISA @EXPORT );
- @ISA = qw(Exporter);
- @EXPORT = qw( initAnalyzer );
-}
+use base qw( Exporter );
+our @EXPORT = qw( initAnalyzer );
# Import what we need from the POE namespace
use POE qw( Session );
use base 'POE::Session::AttributeBased';
# use the power of YAML
use YAML::Tiny qw( Dump );
# Load the utils
use POE::Devel::Benchmarker::Utils qw( beautify_times );
# fires up the engine
sub initAnalyzer {
my $quiet_mode = shift;
# create our session!
POE::Session->create(
__PACKAGE__->inline_states(),
'heap' => {
'quiet_mode' => $quiet_mode,
},
);
}
# Starts up our session
sub _start : State {
# set our alias
$_[KERNEL]->alias_set( 'Benchmarker::Analyzer' );
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[ANALYZER] Starting up...\n";
}
return;
}
sub _stop : State {
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[ANALYZER] Shutting down...\n";
}
return;
}
sub _child : State {
return;
}
sub analyze : State {
# get the data
my $test = $_[ARG0];
# clean up the times() stuff
$test->{'t'}->{'t'} = beautify_times(
join( " ", @{ delete $test->{'t'}->{'s_t'} } ) .
" " .
join( " ", @{ delete $test->{'t'}->{'e_t'} } )
);
# setup the perl version
$test->{'perl'}->{'v'} = sprintf( "%vd", $^V );
# Okay, break it down into our data struct
$test->{'metrics'} = {};
my $d = $test->{'metrics'};
my @unknown;
foreach my $l ( split( /(?:\n|\r)/, $test->{'raw'} ) ) {
# skip empty lines
if ( $l eq '' ) { next }
# usual test benchmark output
# 10 startups in 0.885 seconds ( 11.302 per second)
# 10000 posts in 0.497 seconds ( 20101.112 per second)
if ( $l =~ /^\s+\d+\s+(\w+)\s+in\s+([\d\.]+)\s+seconds\s+\(\s+([\d\.]+)\s+per\s+second\)$/ ) {
$d->{ $1 }->{'d'} = $2; # duration in seconds
$d->{ $1 }->{'i'} = $3; # iterations per second
# usual test benchmark times output
# startup times: 0.1 0 0 0 0.1 0 0.76 0.09
} elsif ( $l =~ /^(\w+)\s+times:\s+(.+)$/ ) {
$d->{ $1 }->{'t'} = beautify_times( $2 ); # the times hash
# parse the memory footprint stuff
} elsif ( $l =~ /^pidinfo:\s+(.+)$/ ) {
# what should we analyze?
my $pidinfo = $1;
# VmPeak: 16172 kB
if ( $pidinfo =~ /^VmPeak:\s+(.+)$/ ) {
$test->{'pid'}->{'vmpeak'} = $1;
# voluntary_ctxt_switches: 10
} elsif ( $pidinfo =~ /^voluntary_ctxt_switches:\s+(.+)$/ ) {
$test->{'pid'}->{'vol_ctxt'} = $1;
# nonvoluntary_ctxt_switches: 1221
} elsif ( $pidinfo =~ /^nonvoluntary_ctxt_switches:\s+(.+)$/ ) {
$test->{'pid'}->{'nonvol_ctxt'} = $1;
} else {
# ignore the rest of the fluff
}
# parse the perl binary stuff
} elsif ( $l =~ /^perlconfig:\s+(.+)$/ ) {
# what should we analyze?
my $perlconfig = $1;
- # Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
- if ( $perlconfig =~ /^Summary\s+of\s+my\s+perl\d\s+\(([^\)]+)\)/ ) {
- $test->{'perl'}->{'version'} = $1;
-
- } else {
- # ignore the rest of the fluff
- }
+ # ignore the fluff ( not needed now... )
# parse the CPU info
} elsif ( $l =~ /^cpuinfo:\s+(.+)$/ ) {
# what should we analyze?
my $cpuinfo = $1;
# FIXME if this is on a multiproc system, we will overwrite the data per processor ( harmless? )
# cpu MHz : 1201.000
if ( $cpuinfo =~ /^cpu\s+MHz\s+:\s+(.+)$/ ) {
$test->{'cpu'}->{'mhz'} = $1;
# model name : Intel(R) Core(TM)2 Duo CPU L7100 @ 1.20GHz
} elsif ( $cpuinfo =~ /^model\s+name\s+:\s+(.+)$/ ) {
$test->{'cpu'}->{'name'} = $1;
# bogomips : 2397.58
} elsif ( $cpuinfo =~ /^bogomips\s+:\s+(.+)$/ ) {
$test->{'cpu'}->{'bogo'} = $1;
} else {
# ignore the rest of the fluff
}
# data that we can safely throw away
} elsif ( $l eq 'Using NO Assertions!' or
$l eq 'Using FULL Assertions!' or
$l eq 'Using the LITE tests' or
$l eq 'Using the HEAVY tests' or
$l eq 'DISABLING POE::XS::Queue::Array' or
$l eq '!STDERR: Devel::Hide hides POE/XS/Queue/Array.pm' or
$l eq 'LETTING POE find POE::XS::Queue::Array' or
$l eq 'UNABLE TO GET /proc/self/status' or
$l eq 'UNABLE TO GET /proc/cpuinfo' or
$l eq '!STDERR: POE::Kernel\'s run() method was never called.' or # to ignore old POEs that threw this warning
$l eq 'TEST TERMINATED DUE TO TIMEOUT' ) {
# ignore them
# parse the perl binary stuff
} elsif ( $l =~ /^Running\s+under\s+perl\s+binary:\s+(.+)$/ ) {
$test->{'perl'}->{'binary'} = $1;
# the master loop version ( what the POE::Loop::XYZ actually uses )
# Using loop: EV-3.49
} elsif ( $l =~ /^Using\s+master\s+loop:\s+(.+)$/ ) {
$test->{'poe'}->{'loop_m'} = $1;
# the real POE version that was loaded
# Using POE-1.001
} elsif ( $l =~ /^Using\s+POE-(.+)$/ ) {
$test->{'poe'}->{'v_real'} = $1;
# the various queue/loop modules we loaded
# POE is using: POE::XS::Queue::Array v0.005
# POE is using: POE::Queue v1.2328
# POE is using: POE::Loop::EV v0.06
} elsif ( $l =~ /^POE\s+is\s+using:\s+([^\s]+)\s+v(.+)$/ ) {
$test->{'poe'}->{'modules'}->{ $1 } = $2;
# get the uname info
# Running under machine: Linux apoc-x300 2.6.24-21-generic #1 SMP Tue Oct 21 23:43:45 UTC 2008 i686 GNU/Linux
} elsif ( $l =~ /^Running\s+under\s+machine:\s+(.+)$/ ) {
$test->{'uname'} = $1;
# parse the SKIP tests
# SKIPPING MYFH tests on broken loop: Event_Lib
# SKIPPING STDIN tests on broken loop: Tk
} elsif ( $l =~ /^SKIPPING\s+(\w+)\s+tests\s+on\s+broken/ ) {
my $fh = $1;
# nullify the data struct for that
foreach my $type ( qw( select_read select_write ) ) {
$d->{ $type . $fh }->{'d'} = undef;
$d->{ $type . $fh }->{'t'} = undef;
$d->{ $type . $fh }->{'i'} = undef;
}
# parse the FH/STDIN failures
# filehandle select_read on STDIN FAILED: error
# filehandle select_write on MYFH FAILED: foo
} elsif ( $l =~ /^filehandle\s+(\w+)\s+on\s+(\w+)\s+FAILED:/ ) {
my( $mode, $type ) = ( $1, $2 );
# nullify the data struct for that
$d->{ $mode . $type }->{'d'} = undef;
$d->{ $mode . $type }->{'t'} = undef;
$d->{ $mode . $type }->{'i'} = undef;
# parse the alarm_add skip
# alarm_add NOT SUPPORTED on this version of POE, skipping alarm_adds/alarm_clears tests!
} elsif ( $l =~ /^alarm_add\s+NOT\s+SUPPORTED\s+on/ ) {
# nullify the data struct for that
foreach my $type ( qw( alarm_adds alarm_clears ) ) {
$d->{ $type }->{'d'} = undef;
$d->{ $type }->{'t'} = undef;
$d->{ $type }->{'i'} = undef;
}
# parse any STDERR output
# !STDERR: unable to foo
} elsif ( $l =~ /^\!STDERR:\s+(.+)$/ ) {
push( @{ $test->{'stderr'} }, $1 );
} else {
# unknown line :(
push( @unknown, $l );
}
}
# Get rid of the rawdata
delete $test->{'raw'};
# Dump the unknowns
if ( @unknown ) {
print "[ANALYZER] Unknown output from benchmark -> " . Dump( \@unknown );
}
# Dump the data struct we have to the file.yml
my $yaml_file = 'results/' . delete $test->{'test'};
$yaml_file .= '.yml';
my $ret = open( my $fh, '>', $yaml_file );
if ( defined $ret ) {
print $fh Dump( $test );
if ( ! close( $fh ) ) {
print "[ANALYZER] Unable to close $yaml_file -> " . $! . "\n";
}
} else {
print "[ANALYZER] Unable to open $yaml_file for writing -> " . $! . "\n";
}
# all done!
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::Analyzer - Analyzes the output from the benchmarks
=head1 SYNOPSIS
Don't use this module directly. Please see L<POE::Devel::Benchmarker>
=head1 ABSTRACT
This package implements the guts of converting the raw data into a machine-readable format. Furthermore, it dumps the data
in YAML format.
=head1 DESCRIPTION
I promise you that once I've stabilized the YAML format I'll have it documented here :)
=head1 EXPORT
Automatically exports the initAnalyzer() sub
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
# sample test output ( from SubProcess v0.02 )
STARTTIME: 1229232743.49131 -> TIMES 0.24 0.01 11.2 0.32
POE-1.003-Select-LITE-assert-xsqueue
Using master loop: Select-BUILTIN
Using FULL Assertions!
Using the LITE tests
LETTING POE find POE::XS::Queue::Array
Using POE-1.003
POE is using: POE::Loop::Select v1.2355
POE is using: POE::XS::Queue::Array v0.005
POE is using: POE::Queue v1.2328
POE is using: POE::Loop::PerlSignals v1.2329
10 startups in 0.853 seconds ( 11.723 per second)
startups times: 0.09 0 0 0 0.09 0 0.73 0.11
10000 posts in 0.495 seconds ( 20211.935 per second)
posts times: 0.1 0 0.73 0.11 0.53 0.06 0.73 0.11
10000 dispatches in 1.113 seconds ( 8984.775 per second)
dispatches times: 0.53 0.06 0.73 0.11 1.64 0.06 0.73 0.11
10000 alarms in 1.017 seconds ( 9829.874 per second)
alarms times: 1.64 0.06 0.73 0.11 2.66 0.06 0.73 0.11
10000 alarm_adds in 0.523 seconds ( 19102.416 per second)
alarm_adds times: 2.66 0.06 0.73 0.11 3.18 0.06 0.73 0.11
10000 alarm_clears in 0.377 seconds ( 26540.332 per second)
alarm_clears times: 3.18 0.06 0.73 0.11 3.55 0.07 0.73 0.11
500 session_creates in 0.130 seconds ( 3858.918 per second)
session_creates times: 3.55 0.07 0.73 0.11 3.68 0.08 0.73 0.11
500 session_destroys in 0.172 seconds ( 2901.191 per second)
session_destroys times: 3.68 0.08 0.73 0.11 3.85 0.08 0.73 0.11
10000 select_read_STDIN in 1.823 seconds ( 5485.878 per second)
select_read_STDIN times: 3.85 0.08 0.73 0.11 5.66 0.08 0.73 0.11
10000 select_write_STDIN in 1.827 seconds ( 5472.283 per second)
select_write_STDIN times: 5.66 0.08 0.73 0.11 7.47 0.08 0.73 0.11
10000 select_read_MYFH in 1.662 seconds ( 6016.387 per second)
select_read_MYFH times: 7.47 0.08 0.73 0.11 9.12 0.1 0.73 0.11
10000 select_write_MYFH in 1.704 seconds ( 5868.537 per second)
select_write_MYFH times: 9.12 0.1 0.73 0.11 10.78 0.11 0.73 0.11
10000 calls in 0.222 seconds ( 45038.974 per second)
calls times: 10.78 0.11 0.73 0.11 11 0.11 0.73 0.11
10000 single_posts in 1.999 seconds ( 5003.473 per second)
single_posts times: 11 0.11 0.73 0.11 12.86 0.22 0.73 0.11
pidinfo: Name: perl
pidinfo: State: R (running)
pidinfo: Tgid: 16643
pidinfo: Pid: 16643
pidinfo: PPid: 16600
pidinfo: TracerPid: 0
pidinfo: Uid: 1000 1000 1000 1000
pidinfo: Gid: 1000 1000 1000 1000
pidinfo: FDSize: 32
pidinfo: Groups: 4 20 24 25 29 30 44 46 107 109 115 127 1000 1001
pidinfo: VmPeak: 14376 kB
pidinfo: VmSize: 14216 kB
pidinfo: VmLck: 0 kB
pidinfo: VmHWM: 11440 kB
pidinfo: VmRSS: 11292 kB
pidinfo: VmData: 9908 kB
pidinfo: VmStk: 84 kB
pidinfo: VmExe: 1044 kB
pidinfo: VmLib: 1872 kB
pidinfo: VmPTE: 24 kB
pidinfo: Threads: 1
pidinfo: SigQ: 0/16182
pidinfo: SigPnd: 0000000000000000
pidinfo: ShdPnd: 0000000000000000
pidinfo: SigBlk: 0000000000000000
pidinfo: SigIgn: 0000000000001000
pidinfo: SigCgt: 0000000180000000
pidinfo: CapInh: 0000000000000000
pidinfo: CapPrm: 0000000000000000
pidinfo: CapEff: 0000000000000000
pidinfo: Cpus_allowed: 03
pidinfo: Mems_allowed: 1
pidinfo: voluntary_ctxt_switches: 10
pidinfo: nonvoluntary_ctxt_switches: 512
Running under perl binary: /usr/bin/perl
perlconfig: Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
perlconfig: Platform:
perlconfig: osname=linux, osvers=2.6.15.7, archname=i486-linux-gnu-thread-multi
perlconfig: uname='linux palmer 2.6.15.7 #1 smp thu sep 7 19:42:20 utc 2006 i686 gnulinux '
perlconfig: config_args='-Dusethreads -Duselargefiles -Dccflags=-DDEBIAN -Dcccdlflags=-fPIC -Darchname=i486-linux-gnu -Dprefix=/usr -Dprivlib=/usr/share/perl/5.8 -Darchlib=/usr/lib/perl/5.8 -Dvendorprefix=/usr -Dvendorlib=/usr/share/perl5 -Dvendorarch=/usr/lib/perl5 -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl/5.8.8 -Dsitearch=/usr/local/lib/perl/5.8.8 -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 -Dsiteman1dir=/usr/local/man/man1 -Dsiteman3dir=/usr/local/man/man3 -Dman1ext=1 -Dman3ext=3perl -Dpager=/usr/bin/sensible-pager -Uafs -Ud_csh -Ud_ualarm -Uusesfio -Uusenm -Duseshrplib -Dlibperl=libperl.so.5.8.8 -Dd_dosuid -des'
perlconfig: hint=recommended, useposix=true, d_sigaction=define
perlconfig: usethreads=define use5005threads=undef useithreads=define usemultiplicity=define
perlconfig: useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
perlconfig: use64bitint=undef use64bitall=undef uselongdouble=undef
perlconfig: usemymalloc=n, bincompat5005=undef
perlconfig: Compiler:
perlconfig: cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBIAN -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
perlconfig: optimize='-O2',
perlconfig: cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBIAN -fno-strict-aliasing -pipe -I/usr/local/include'
perlconfig: ccversion='', gccversion='4.2.3 20071123 (prerelease) (Ubuntu 4.2.2-3ubuntu4)', gccosandvers=''
perlconfig: intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
perlconfig: d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
perlconfig: ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
perlconfig: alignbytes=4, prototype=define
perlconfig: Linker and Libraries:
perlconfig: ld='cc', ldflags =' -L/usr/local/lib'
perlconfig: libpth=/usr/local/lib /lib /usr/lib
perlconfig: libs=-lgdbm -lgdbm_compat -ldb -ldl -lm -lpthread -lc -lcrypt
perlconfig: perllibs=-ldl -lm -lpthread -lc -lcrypt
perlconfig: libc=/lib/libc-2.6.1.so, so=so, useshrplib=true, libperl=libperl.so.5.8.8
perlconfig: gnulibc_version='2.6.1'
perlconfig: Dynamic Linking:
perlconfig: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
perlconfig: cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib'
Running under machine: Linux apoc-x300 2.6.24-21-generic #1 SMP Tue Oct 21 23:43:45 UTC 2008 i686 GNU/Linux
cpuinfo: processor : 0
cpuinfo: vendor_id : GenuineIntel
cpuinfo: cpu family : 6
cpuinfo: model : 15
cpuinfo: model name : Intel(R) Core(TM)2 Duo CPU L7100 @ 1.20GHz
cpuinfo: stepping : 11
cpuinfo: cpu MHz : 1201.000
cpuinfo: cache size : 4096 KB
cpuinfo: physical id : 0
cpuinfo: siblings : 2
cpuinfo: core id : 0
cpuinfo: cpu cores : 2
cpuinfo: fdiv_bug : no
cpuinfo: hlt_bug : no
cpuinfo: f00f_bug : no
cpuinfo: coma_bug : no
cpuinfo: fpu : yes
cpuinfo: fpu_exception : yes
cpuinfo: cpuid level : 10
cpuinfo: wp : yes
cpuinfo: flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc arch_perfmon pebs bts pni monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr lahf_lm ida
cpuinfo: bogomips : 2397.58
cpuinfo: clflush size : 64
cpuinfo: processor : 1
cpuinfo: vendor_id : GenuineIntel
cpuinfo: cpu family : 6
cpuinfo: model : 15
cpuinfo: model name : Intel(R) Core(TM)2 Duo CPU L7100 @ 1.20GHz
cpuinfo: stepping : 11
cpuinfo: cpu MHz : 1201.000
cpuinfo: cache size : 4096 KB
cpuinfo: physical id : 0
cpuinfo: siblings : 2
cpuinfo: core id : 1
cpuinfo: cpu cores : 2
cpuinfo: fdiv_bug : no
cpuinfo: hlt_bug : no
cpuinfo: f00f_bug : no
cpuinfo: coma_bug : no
cpuinfo: fpu : yes
cpuinfo: fpu_exception : yes
cpuinfo: cpuid level : 10
cpuinfo: wp : yes
cpuinfo: flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc arch_perfmon pebs bts pni monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr lahf_lm ida
cpuinfo: bogomips : 2394.02
cpuinfo: clflush size : 64
ENDTIME: 1229232757.53804 -> TIMES 0.27 0.01 23.1 0.62
diff --git a/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm b/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm
index f70065b..87b8d6b 100644
--- a/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm
+++ b/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm
@@ -1,211 +1,207 @@
# Declare our package
package POE::Devel::Benchmarker::GetInstalledLoops;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.04';
# auto-export the only sub we have
-BEGIN {
- require Exporter;
- use vars qw( @ISA @EXPORT );
- @ISA = qw(Exporter);
- @EXPORT = qw( getPOEloops );
-}
+use base qw( Exporter );
+our @EXPORT = qw( getPOEloops );
# Import what we need from the POE namespace
use POE qw( Session Filter::Line Wheel::Run );
use base 'POE::Session::AttributeBased';
# Get the utils
use POE::Devel::Benchmarker::Utils qw ( knownloops );
# analyzes the installed perl directory for available loops
sub getPOEloops {
my $quiet_mode = shift;
my $forceloops = shift;
# create our session!
POE::Session->create(
POE::Devel::Benchmarker::GetInstalledLoops->inline_states(),
'heap' => {
'quiet_mode' => $quiet_mode,
'loops' => $forceloops,
},
);
}
# Starts up our session
sub _start : State {
# set our alias
$_[KERNEL]->alias_set( 'Benchmarker::GetInstalledLoops' );
# load our known list of loops
# known impossible loops:
# XS::EPoll ( must be POE > 1.003 and weird way of loading )
# XS::Poll ( must be POE > 1.003 and weird way of loading )
if ( ! defined $_[HEAP]->{'loops'} ) {
$_[HEAP]->{'loops'} = knownloops();
}
# First of all, we need to find out what loop libraries are installed
$_[HEAP]->{'found_loops'} = [];
$_[KERNEL]->yield( 'find_loops' );
return;
}
sub _stop : State {
# tell the wheel to kill itself
if ( defined $_[HEAP]->{'WHEEL'} ) {
$_[HEAP]->{'WHEEL'}->kill( 9 );
undef $_[HEAP]->{'WHEEL'};
}
return;
}
# loops over the "known" loops and sees if they are installed
sub find_loops : State {
# get the loop to test
$_[HEAP]->{'current_loop'} = shift @{ $_[HEAP]->{'loops'} };
# do we have something to test?
if ( ! defined $_[HEAP]->{'current_loop'} ) {
# we're done!
$_[KERNEL]->alias_remove( 'Benchmarker::GetInstalledLoops' );
$_[KERNEL]->post( 'Benchmarker', 'found_loops', $_[HEAP]->{'found_loops'} );
return;
} else {
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[LOOPSEARCH] Trying to find if POE::Loop::" . $_[HEAP]->{'current_loop'} . " is installed...\n";
}
# set the flag
$_[HEAP]->{'test_failure'} = 0;
}
# Okay, create the wheel::run to handle this
$_[HEAP]->{'WHEEL'} = POE::Wheel::Run->new(
'Program' => $^X,
'ProgramArgs' => [ '-MPOE',
'-MPOE::Loop::' . $_[HEAP]->{'current_loop'},
'-e',
'1',
],
# Kill off existing FD's
'CloseOnCall' => 1,
# setup our data handlers
'StdoutEvent' => 'Got_STDOUT',
'StderrEvent' => 'Got_STDERR',
# the error handler
'ErrorEvent' => 'Got_ERROR',
'CloseEvent' => 'Got_CLOSED',
# set our filters
'StderrFilter' => POE::Filter::Line->new(),
'StdoutFilter' => POE::Filter::Line->new(),
);
if ( ! defined $_[HEAP]->{'WHEEL'} ) {
die '[LOOPSEARCH] Unable to create a new wheel!';
} else {
# smart CHLD handling
if ( $_[KERNEL]->can( "sig_child" ) ) {
$_[KERNEL]->sig_child( $_[HEAP]->{'WHEEL'}->PID => 'Got_CHLD' );
} else {
$_[KERNEL]->sig( 'CHLD', 'Got_CHLD' );
}
}
return;
}
# Got a CHLD event!
sub Got_CHLD : State {
$_[KERNEL]->sig_handled();
return;
}
# Handles child STDERR output
sub Got_STDERR : State {
my $input = $_[ARG0];
# since we got an error, must be a failure
$_[HEAP]->{'test_failure'} = 1;
return;
}
# Handles child STDOUT output
sub Got_STDOUT : State {
my $input = $_[ARG0];
return;
}
# Handles child error
sub Got_ERROR : State {
# Copied from POE::Wheel::Run manpage
my ( $operation, $errnum, $errstr ) = @_[ ARG0 .. ARG2 ];
# ignore exit 0 errors
if ( $errnum != 0 ) {
warn "Wheel::Run got an $operation error $errnum: $errstr\n";
}
return;
}
# Handles child DIE'ing
sub Got_CLOSED : State {
# Get rid of the wheel
undef $_[HEAP]->{'WHEEL'};
# Did we pass this test or not?
if ( ! $_[HEAP]->{'test_failure'} ) {
push( @{ $_[HEAP]->{'found_loops'} }, $_[HEAP]->{'current_loop'} );
}
# move on to the next loop
$_[KERNEL]->yield( 'find_loops' );
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::GetInstalledLoops - Automatically detects the installed POE loops
=head1 SYNOPSIS
Don't use this module directly. Please use POE::Devel::Benchmarker.
=head1 ABSTRACT
This package implements the guts of searching for POE loops via fork/exec.
=head1 EXPORT
Automatically exports the getPOEloops() sub
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/GetPOEdists.pm b/lib/POE/Devel/Benchmarker/GetPOEdists.pm
index 7f10f39..ce1a991 100644
--- a/lib/POE/Devel/Benchmarker/GetPOEdists.pm
+++ b/lib/POE/Devel/Benchmarker/GetPOEdists.pm
@@ -1,142 +1,144 @@
# Declare our package
package POE::Devel::Benchmarker::GetPOEdists;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.04';
# auto-export the only sub we have
-require Exporter;
-use vars qw( @ISA @EXPORT );
-@ISA = qw(Exporter);
-@EXPORT = qw( getPOEdists );
+use base qw( Exporter );
+our @EXPORT = qw( getPOEdists );
# import the helper modules
use LWP::UserAgent;
use HTML::LinkExtor;
use URI::URL;
use Archive::Tar;
+# autoflush, please!
+use IO::Handle;
+STDOUT->autoflush( 1 );
+
# actually retrieves the dists!
sub getPOEdists {
# should we debug?
my $debug = shift;
# okay, should we change directory?
if ( -d 'poedists' ) {
if ( $debug ) {
print "[GETPOEDISTS] chdir( 'poedists' )\n";
}
if ( ! chdir( 'poedists' ) ) {
die "Unable to chdir to 'poedists' dir: $!";
}
} else {
if ( $debug ) {
print "[GETPOEDISTS] downloading to current directory\n";
}
}
# set the default URL
my $url = "http://backpan.cpan.org/authors/id/R/RC/RCAPUTO/";
# create our objects
my $ua = LWP::UserAgent->new;
my $p = HTML::LinkExtor->new;
my $tar = Archive::Tar->new;
# Request document and parse it as it arrives
print "Getting $url via LWP\n" if $debug;
my $res = $ua->request( HTTP::Request->new( GET => $url ),
sub { $p->parse( $_[0] ) },
);
# did we successfully download?
if ( $res->is_error ) {
die "unable to download directory index on BACKPAN: " . $res->status_line;
}
# Download every one!
foreach my $link ( $p->links ) {
# skip IMG stuff
if ( $link->[0] eq 'a' and $link->[1] eq 'href' ) {
# get the actual POE dists!
if ( $link->[2] =~ /^POE\-\d/ and $link->[2] =~ /\.tar\.gz$/ ) {
# download the tarball!
print "Mirroring $link->[2] via LWP\n" if $debug;
my $mirror_result = $ua->mirror( $url . $link->[2], $link->[2] );
if ( $mirror_result->is_error ) {
warn "unable to mirror $link->[2]: " . $mirror_result->status_line;
next;
}
# did we already untar this one?
my $dir = $link->[2];
$dir =~ s/\.tar\.gz$//;
if ( ! -d $dir ) {
# extract it!
print "Extracting $link->[2] via Tar\n" if $debug;
my $files = $tar->read( $link->[2], undef, { 'extract' => 'true' } );
if ( $files == 0 ) {
warn "unable to extract $link->[2]";
}
}
}
}
}
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::GetPOEdists - Automatically download all POE tarballs
=head1 SYNOPSIS
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker::GetPOEdists -e 'getPOEdists()'
=head1 ABSTRACT
This package automatically downloads all the POE tarballs from BACKPAN.
=head1 DESCRIPTION
This uses LWP + HTML::LinkExtor to retrieve POE tarballs from BACKPAN.
The tarballs are automatically downloaded to the current directory. Then, we use Archive::Tar to extract them all!
NOTE: we use LWP's useful mirror() sub which doesn't re-download files if they already exist!
=head2 getPOEdists
Normally you should pass nothing to this sub. However, if you want to debug the downloads+extractions you should pass
a true value as the first argument.
perl -MPOE::Devel::Benchmarker::GetPOEdists -e 'getPOEdists( 1 )'
=head1 EXPORT
Automatically exports the getPOEdists() sub
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/Imager.pm b/lib/POE/Devel/Benchmarker/Imager.pm
index e5a2a29..48fa23a 100644
--- a/lib/POE/Devel/Benchmarker/Imager.pm
+++ b/lib/POE/Devel/Benchmarker/Imager.pm
@@ -1,182 +1,439 @@
# Declare our package
package POE::Devel::Benchmarker::Imager;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.04';
# auto-export the only sub we have
-require Exporter;
-use vars qw( @ISA @EXPORT );
-@ISA = qw(Exporter);
-@EXPORT = qw( imager );
+use base qw( Exporter );
+our @EXPORT = qw( imager );
# import the helper modules
use YAML::Tiny;
-use Chart::Clicker;
-use Chart::Clicker::Data::Series;
-use Chart::Clicker::Data::DataSet;
-# olds our data structure
-my %data;
+# load our plugins!
+use Module::Pluggable search_path => [ __PACKAGE__ ];
-# debug or not?
-my $debug = 0;
+# load comparison stuff
+use version;
+
+# generate some accessors
+use base qw( Class::Accessor::Fast );
+__PACKAGE__->mk_ro_accessors( qw( poe_versions poe_versions_sorted poe_loops data
+ noxsqueue noasserts litetests
+) );
+
+# autoflush, please!
+use IO::Handle;
+STDOUT->autoflush( 1 );
# starts the work of converting our data to images
sub imager {
- # should we debug?
- $debug = shift;
- if ( $debug ) {
- $debug = 1;
- } else {
- $debug = 0;
+ my $options = shift;
+
+ # instantitate ourself
+ my $self = __PACKAGE__->new( $options );
+
+ # parse all of our YAML modules!
+ $self->loadtests;
+
+ # process some stats
+ $self->process_data;
+
+ # generate the images!
+ $self->generate_images;
+
+ return;
+}
+
+# creates a new instance
+sub new {
+ my $class = shift;
+ my $opts = shift;
+
+ # instantitate ourself
+ my $self = {};
+ bless $self, $class;
+
+ # init the options
+ $self->init_options( $opts );
+
+ if ( ! $self->{'options'}->{'quiet'} ) {
+ print "[IMAGER] Starting up...\n";
+ }
+
+ return $self;
+}
+
+sub init_options {
+ my $self = shift;
+ my $options = shift;
+
+ # set defaults
+ $self->{'quiet'} = 0;
+ $self->{'litetests'} = 1;
+ $self->{'noasserts'} = 0;
+ $self->{'noxsqueue'} = 0;
+
+ # process our options
+ if ( defined $options and ref $options and ref( $options ) eq 'HASH' ) {
+ # process quiet mode
+ if ( exists $options->{'quiet'} ) {
+ if ( $options->{'quiet'} ) {
+ $self->{'quiet'} = 1;
+ } else {
+ $self->{'quiet'} = 0;
+ }
+ }
+
+ # process the LITE/HEAVY
+ if ( exists $options->{'litetests'} ) {
+ if ( $options->{'litetests'} ) {
+ $self->{'litetests'} = 1;
+ } else {
+ $self->{'litetests'} = 0;
+ }
+ }
+
+ # process the noasserts to load
+ if ( exists $options->{'noasserts'} ) {
+ if ( $options->{'noasserts'} ) {
+ $self->{'noasserts'} = 1;
+ } else {
+ $self->{'noasserts'} = 0;
+ }
+ }
+
+ # process the noxsqueue to load
+ if ( exists $options->{'noxsqueue'} ) {
+ if ( $options->{'noxsqueue'} ) {
+ $self->{'noxsqueue'} = 1;
+ } else {
+ $self->{'noxsqueue'} = 0;
+ }
+ }
+
+ # FIXME process the plugins to load -> "types"
+
+ # FIXME process the versions to load
+
+ # FIXME process the loops to load
}
# some sanity tests
+ # FIXME find a way to set the results directory via attribute
if ( ! -d 'results' ) {
die "The 'results' directory is not found in the working directory!";
}
if ( ! -d 'images' ) {
die "The 'images' directory is not found in the working directory!";
}
- if ( $debug ) {
- print "[IMAGER] Starting up...\n";
- }
-
- # parse all of our YAML modules!
- parse_yaml();
-
- # Do some processing of the data
- process_data();
-
- # generate the images!
- generate_images();
-
- # for now, we simply freeze up
- sleep 30;
-
return;
}
# starts the process of loading all of our YAML images
-sub parse_yaml {
+sub loadtests {
+ my $self = shift;
+
# gather all the YAML dumps
- my @versions;
if ( opendir( DUMPS, 'results' ) ) {
foreach my $d ( readdir( DUMPS ) ) {
- if ( $d =~ /\.yml$/ ) {
- push( @versions, $d );
+ # parse the file structure
+ # POE-1.0002-IO_Poll-LITE-assert-noxsqueue
+ if ( $d =~ /^POE\-([\d\.\_]+)\-(\w+?)\-(LITE|HEAVY)\-(noassert|assert)\-(noxsqueue|xsqueue)\.yml$/ ) {
+ my( $ver, $loop, $lite, $assert, $xsqueue ) = ( $1, $2, $3, $4, $5 );
+
+ # skip this file?
+ if ( $self->noxsqueue ) {
+ if ( $xsqueue eq 'xsqueue' ) { next }
+ } else {
+ if ( $xsqueue eq 'noxsqueue' ) { next }
+ }
+ if ( $self->noasserts ) {
+ if ( $assert eq 'assert' ) { next }
+ } else {
+ if ( $assert eq 'noassert' ) { next }
+ }
+ if ( $self->litetests ) {
+ if ( $lite eq 'HEAVY' ) { next }
+ } else {
+ if ( $lite eq 'LITE' ) { next }
+ }
+
+ # FIXME allow selective loading of tests, so we can control what to image, etc
+
+ # actually load this file!
+ $self->load_yaml( $d, $ver, $loop, $lite, $assert, $xsqueue );
}
}
closedir( DUMPS ) or die "[IMAGER] Unable to read from 'results' -> " . $!;
} else {
die "[IMAGER] Unable to open 'results' for reading -> " . $!;
}
# sanity
- if ( ! scalar @versions ) {
+ if ( ! exists $self->{'data'} ) {
die "[IMAGER] Unable to find any POE test result(s) in the 'results' directory!\n";
}
- # FIXME allow selective loading of tests, so we can control what to image, etc
-
- # Parse every one of them!
- foreach my $v ( @versions ) {
- load_yaml( "results/$v" );
- }
-
- if ( $debug ) {
+ if ( ! $self->quiet ) {
print "[IMAGER] Done with parsing the YAML files...\n";
}
return;
}
# loads the yaml of a specific file
sub load_yaml {
- my $file = shift;
+ my ( $self, $file, $ver, $loop, $lite, $assert, $xsqueue ) = @_;
- my $yaml = YAML::Tiny->read( $file );
+ my $yaml = YAML::Tiny->read( 'results/' . $file );
if ( ! defined $yaml ) {
die "[IMAGER] Unable to load YAML file $file -> " . YAML::Tiny->errstr . "\n";
} else {
- # store it in the global hash
- $data{ $file } = $yaml->[0];
+ # inrospect it!
+ my $isvalid = 0;
+ eval {
+ # simple sanity check: the "x_bench" param is at the end of the YML, so if it loads fine we know it's there
+ if ( exists $yaml->[0]->{'x_bench'} ) {
+ # version must at least match us
+ $isvalid = ( $yaml->[0]->{'x_bench'} eq $POE::Devel::Benchmarker::Imager::VERSION ? 1 : 0 );
+ } else {
+ $isvalid = undef;
+ }
+ };
+ if ( ! $isvalid or $@ ) {
+ die "[IMAGER] Detected outdated/corrupt benchmark result: $file";
+ } else {
+ # reduce indirection
+ $yaml = $yaml->[0];
+ }
+ }
+
+ # store the POE version
+ $self->{'poe_versions'}->{ $ver } = 1;
+
+ # sanity check the loop master version ( which should always be our "installed" version, not per-POE )
+ if ( exists $yaml->{'poe'}->{'loop_m'} ) {
+ if ( ! defined $self->{'poe_loops'}->{ $loop } ) {
+ $self->{'poe_loops'}->{ $loop } = $yaml->{'poe'}->{'loop_m'};
+ } else {
+ if ( $self->{'poe_loops'}->{ $loop } ne $yaml->{'poe'}->{'loop_m'} ) {
+ die "[IMAGER] Detected POE::Loop master version inconsistency! $file reported '" . $yaml->{'poe'}->{'loop_m'} .
+ "' while others had '" . $self->{'poe_loops'}->{ $loop } . "'";
+ }
+ }
+ }
+
+ # get the info we're interested in
+ $self->{'data'}->{ $ver }->{ $loop }->{'metrics'} = $yaml->{'metrics'};
+ $self->{'data'}->{ $ver }->{ $loop }->{'time'} = $yaml->{'t'};
+
+ if ( exists $yaml->{'pid'} ) {
+ $self->{'data'}->{ $ver }->{ $loop }->{'pid'} = $yaml->{'pid'};
+ }
+ if ( exists $yaml->{'poe'}->{'modules'} ) {
+ $self->{'data'}->{ $ver }->{ $loop }->{'poe_modules'} = $yaml->{'poe'}->{'modules'};
+ }
+
+ # sanity check the perl stuff
+ if ( exists $yaml->{'perl'}->{'binary'} ) {
+ if ( ! exists $self->{'data'}->{'perlconfig'} ) {
+ $self->{'data'}->{'perlconfig'}->{'binary'} = $yaml->{'perl'}->{'binary'};
+ $self->{'data'}->{'perlconfig'}->{'version'} = $yaml->{'perl'}->{'v'};
+ } else {
+ if ( $self->{'data'}->{'perlconfig'}->{'binary'} ne $yaml->{'perl'}->{'binary'} ) {
+ die "[IMAGER] Detected perl binary inconsistency! $file reported '" . $yaml->{'perl'}->{'binary'} .
+ "' while others had '" . $self->{'data'}->{'perlconfig'}->{'binary'} . "'";
+ }
+ if ( $self->{'data'}->{'perlconfig'}->{'version'} ne $yaml->{'perl'}->{'v'} ) {
+ die "[IMAGER] Detected perl version inconsistency! $file reported '" . $yaml->{'perl'}->{'v'} .
+ "' while others had '" . $self->{'data'}->{'perlconfig'}->{'version'} . "'";
+ }
+ }
+ }
+
+ # sanity check the uname
+ if ( exists $yaml->{'uname'} ) {
+ if ( ! exists $self->{'data'}->{'uname'} ) {
+ $self->{'data'}->{'uname'} = $yaml->{'uname'};
+ } else {
+ if ( $self->{'data'}->{'uname'} ne $yaml->{'uname'} ) {
+ die "[IMAGER] Detected system inconsistency! $file reported '" . $yaml->{'uname'} .
+ "' while others had '" . $self->{'data'}->{'uname'} . "'";
+ }
+ }
+ }
+
+ # sanity check the cpu name
+ if ( exists $yaml->{'cpu'} ) {
+ if ( ! exists $self->{'data'}->{'cpu'} ) {
+ $self->{'data'}->{'cpu'} = $yaml->{'cpu'};
+ } else {
+ if ( $self->{'data'}->{'cpu'}->{'name'} ne $yaml->{'cpu'}->{'name'} ) {
+ die "[IMAGER] Detected system/cpu inconsistency! $file reported '" . $yaml->{'cpu'}->{'name'} .
+ "' while others had '" . $self->{'data'}->{'cpu'}->{'name'} . "'";
+ }
+ }
}
return;
}
-# mangles the data we've collected so far
sub process_data {
- # FIXME okay what should we do?
+ my $self = shift;
+
+ # sanitize the versions in an ordered loop
+ $self->{'poe_versions_sorted'} = [ map { $_->stringify } sort { $a <=> $b } map { version->new($_) } keys %{ $self->poe_versions } ];
- if ( $debug ) {
- print "[IMAGER] Done with processing the test statistics...\n";
+ if ( ! $self->quiet ) {
+ print "[IMAGER] Done with processing the benchmark statistics...\n";
}
return;
}
sub generate_images {
- # FIXME okay what should we do?
+ my $self = shift;
+
+ # load our plugins and let them have fun :)
+ foreach my $plugin ( $self->plugins ) {
+ # actually load it!
+ ## no critic
+ eval "require $plugin";
+ ## use critic
+ if ( $@ ) {
+ if ( ! $self->quiet ) {
+ print "[IMAGER] Unable to load plugin $plugin -> $@\n";
+ next;
+ }
+ }
+
+ # sanity checks
+ if ( $plugin->can( 'new' ) and $plugin->can( 'imager' ) ) {
+ # FIXME did we want this plugin?
+
+ # create the plugin's home dir
+ my $homedir = $plugin;
+ if ( $homedir =~ /\:\:(\w+)$/ ) {
+ $homedir = $1;
+ } else {
+ die "barf";
+ }
+ if ( ! -d "images/$homedir" ) {
+ # create it!
+ if ( ! mkdir( "images/$homedir" ) ) {
+ die "[IMAGER] Unable to create plugin directory: $homedir";
+ }
+ }
- if ( $debug ) {
+ # Okay, get this plugin!
+ my $obj = $plugin->new( { 'dir' => "images/$homedir/" } );
+
+ if ( ! $self->quiet ) {
+ print "[IMAGER] Processing the $plugin plugin...\n";
+ }
+
+ $obj->imager( $self );
+ }
+ }
+
+ if ( ! $self->quiet ) {
print "[IMAGER] Done with generating images...\n";
}
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::Imager - Automatically converts the benchmark data into images
=head1 SYNOPSIS
apoc@apoc-x300:~$ cd poe-benchmarker
- apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker::Imager -e 'imager()'
+ apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker::Imager -e 'imager'
=head1 ABSTRACT
This package automatically parses the benchmark data and generates pretty charts.
=head1 DESCRIPTION
-This package uses the excellent L<Chart::Clicker> module to generate the images
+This package uses the excellent L<Chart::Clicker> module to generate the images. It will parse the YAML output from
+the benchmark data and calls it's plugins to generate any charts necessary and place them in the 'images' directory.
+
+Furthermore, we use Module::Pluggable to search all modules in the POE::Devel::Benchmarker::Imager::* namespace and
+let them handle the generation of images. That way virtually unlimited combinations of images can be generated on the fly
+from the data this module parses.
+
+The way to use this module is by calling the imager() subroutine and let it do it's job. You can pass a hashref to it to
+set various options. Here is a list of the valid options:
+
+=over 4
+
+=item quiet => boolean
+
+This enables quiet mode which will not print anything to the console except for errors.
+
+ new( { 'quiet' => 1 } );
+
+default: false
-=head2 imager
+=item noxsqueue => boolean
-Normally you should pass nothing to this sub. However, if you want to debug the processing you should pass a true
-value as the first argument.
+This will tell the Imager to not consider those tests for the output
- perl -MPOE::Devel::Benchmarker::Imager -e 'imager( 1 )'
+ benchmark( { noxsqueue => 1 } );
+
+default: false
+
+=item noasserts => boolean
+
+This will tell the Imager to not consider those tests for the output
+
+ benchmark( { noasserts => 1 } );
+
+default: false
+
+=item litetests => boolean
+
+This will tell the Imager to not consider those tests for the output
+
+ benchmark( { litetests => 0 } );
+
+default: true
+
+=back
+
+=head1 PLUGIN INTERFACE
+
+For now, this is undocumented. Please look at BasicStatistics for the general concept on how it interacts with this module
+and as always, feel free to look at the source :)
=head1 EXPORT
Automatically exports the imager() sub
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
-L<Chart::Clicker>
-
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/Imager/BasicStatistics.pm b/lib/POE/Devel/Benchmarker/Imager/BasicStatistics.pm
new file mode 100644
index 0000000..e8ee51e
--- /dev/null
+++ b/lib/POE/Devel/Benchmarker/Imager/BasicStatistics.pm
@@ -0,0 +1,232 @@
+# Declare our package
+package POE::Devel::Benchmarker::Imager::BasicStatistics;
+use strict; use warnings;
+
+# Initialize our version
+use vars qw( $VERSION );
+$VERSION = '0.04';
+
+# the GD stuff
+use GD::Graph::lines;
+
+# creates a new instance
+sub new {
+ my $class = shift;
+ my $opts = shift;
+
+ # instantitate ourself
+ my $self = {
+ 'opts' => $opts,
+ };
+ return bless $self, $class;
+}
+
+# actually generates the graphs!
+sub imager {
+ my $self = shift;
+ $self->{'imager'} = shift;
+
+ # generate the loops vs each other graphs
+ $self->generate_loopwars;
+
+ # generate the single loop performance
+ $self->generate_loopperf;
+
+ return;
+}
+
+# charts a single loop's progress over POE versions
+sub generate_loopperf {
+ my $self = shift;
+
+ # go through all the loops we want
+ foreach my $loop ( keys %{ $self->{'imager'}->poe_loops } ) {
+ my %data;
+
+ # organize data by POE version
+ foreach my $poe ( @{ $self->{'imager'}->poe_versions_sorted } ) {
+ foreach my $metric ( qw( alarms dispatches posts single_posts startups select_read_MYFH select_write_MYFH select_read_STDIN select_write_STDIN ) ) {
+ if ( exists $self->{'imager'}->data->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
+ and defined $self->{'imager'}->data->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
+ ) {
+ push( @{ $data{ $metric } }, $self->{'imager'}->data->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'} );
+ } else {
+ push( @{ $data{ $metric } }, 0 );
+ }
+ }
+ }
+
+ # transform %data into something GD likes
+ my @data_for_gd;
+ foreach my $metric ( sort keys %data ) {
+ push( @data_for_gd, $data{ $metric } );
+ }
+
+ # send it to GD!
+ $self->make_gdgraph( "Bench_$loop",
+ [ sort keys %data ],
+ 'iterations/sec',
+ \@data_for_gd,
+ );
+ }
+
+ return;
+}
+
+# loop wars!
+sub generate_loopwars {
+ my $self = shift;
+
+ # go through all the metrics we want
+ foreach my $metric ( qw( alarms dispatches posts single_posts startups select_read_MYFH select_write_MYFH select_read_STDIN select_write_STDIN ) ) {
+ my %data;
+
+ # organize data by POE version
+ foreach my $poe ( @{ $self->{'imager'}->poe_versions_sorted } ) {
+ foreach my $loop ( keys %{ $self->{'imager'}->poe_loops } ) {
+ if ( exists $self->{'imager'}->data->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
+ and defined $self->{'imager'}->data->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'}
+ ) {
+ push( @{ $data{ $loop } }, $self->{'imager'}->data->{ $poe }->{ $loop }->{'metrics'}->{ $metric }->{'i'} );
+ } else {
+ push( @{ $data{ $loop } }, 0 );
+ }
+ }
+ }
+
+ # transform %data into something GD likes
+ my @data_for_gd;
+ foreach my $loop ( sort keys %data ) {
+ push( @data_for_gd, $data{ $loop } );
+ }
+
+ # send it to GD!
+ $self->make_gdgraph( "LoopWar_$metric",
+ [ sort keys %{ $self->{'imager'}->poe_loops } ],
+ 'iterations/sec',
+ \@data_for_gd,
+ );
+ }
+
+ return;
+}
+
+sub make_gdgraph {
+ my $self = shift;
+ my $metric = shift;
+ my $legend = shift;
+ my $ylabel = shift;
+ my $data = shift;
+
+ # Get the graph object
+ my $graph = new GD::Graph::lines( 800, 600 );
+
+ # Set some stuff
+ $graph->set(
+# 'x_label' => 'POE Versions',
+ 'title' => $metric,
+ 'line_width' => 1,
+ 'boxclr' => 'black',
+ 'overwrite' => 0,
+ 'x_labels_vertical' => 1,
+ 'x_all_ticks' => 1,
+ 'legend_placement' => 'BL',
+ 'y_label' => $ylabel,
+
+ # 3d options only
+ #'line_depth' => 2.5,
+ ) or die $graph->error;
+
+ # Set the legend
+ $graph->set_legend( @$legend );
+
+ # Set Font stuff
+ $graph->set_legend_font( GD::gdMediumBoldFont );
+ $graph->set_x_axis_font( GD::gdMediumBoldFont );
+ $graph->set_y_axis_font( GD::gdMediumBoldFont );
+ $graph->set_y_label_font( GD::gdMediumBoldFont );
+ $graph->set_title_font( GD::gdGiantFont );
+
+ # Manufacture the data
+ my $readydata = [
+ [ map { 'POE-' . $_ } @{ $self->{'imager'}->poe_versions_sorted } ],
+ @$data,
+ ];
+
+ # Plot it!
+ $graph->plot( $readydata ) or die $graph->error;
+
+ # Print it!
+ my $filename = $self->{'opts'}->{'dir'} . $metric . '_' .
+ ( $self->{'imager'}->litetests ? 'lite' : 'heavy' ) . '_' .
+ ( $self->{'imager'}->noasserts ? 'noasserts' : 'asserts' ) . '_' .
+ ( $self->{'imager'}->noxsqueue ? 'noxsqueue' : 'xsqueue' ) .
+ '.png';
+ open( my $fh, '>', $filename ) or die 'Cannot open graph file!';
+ binmode( $fh );
+ print $fh $graph->gd->png();
+ close( $fh );
+
+ return;
+}
+
+1;
+__END__
+=head1 NAME
+
+POE::Devel::Benchmarker::Imager::BasicStatistics - Plugin to generates basic statistics graphs
+
+=head1 SYNOPSIS
+
+ apoc@apoc-x300:~$ cd poe-benchmarker
+ apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker::Imager -e 'imager( { type => "BasicStatistics" } )'
+
+=head1 ABSTRACT
+
+This plugin for Imager generates some kinds of graphs from the benchmark tests.
+
+=head1 DESCRIPTION
+
+This package generates some basic graphs from the statistics output. Since the POE::Loop::* modules really are responsible
+for the backend logic of POE, it makes sense to graph all related metrics of a single loop across POE versions to see if
+it performs differently. The related benchmark metrics are: events, alarms, filehandles, and startup.
+
+This will generate 2 types of graphs:
+
+=over 4
+
+=item Loops against each other
+
+Each metric will have a picture for itself, showing how each loop compare against each other with the POE versions.
+
+file: BasicStatistics/$metric.png
+
+=item Single Loop over POE versions
+
+Each Loop will have a picture for itself, showing how each metric performs over POE versions.
+
+file: BasicStatistics/$loop.png
+
+=back
+
+=head1 EXPORT
+
+Nothing.
+
+=head1 SEE ALSO
+
+L<POE::Devel::Benchmarker::Imager>
+
+=head1 AUTHOR
+
+Apocalypse E<lt>apocal@cpan.orgE<gt>
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright 2008 by Apocalypse
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
+
diff --git a/lib/POE/Devel/Benchmarker/SubProcess.pm b/lib/POE/Devel/Benchmarker/SubProcess.pm
index b49c950..3fd418b 100644
--- a/lib/POE/Devel/Benchmarker/SubProcess.pm
+++ b/lib/POE/Devel/Benchmarker/SubProcess.pm
@@ -1,656 +1,658 @@
# Declare our package
package POE::Devel::Benchmarker::SubProcess;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.04';
# Import Time::HiRes's time()
use Time::HiRes qw( time );
# FIXME UGLY HACK here
BEGIN {
# should we enable assertions?
if ( defined $ARGV[2] and $ARGV[2] ) {
## no critic
eval "sub POE::Kernel::ASSERT_DEFAULT () { 1 }";
eval "sub POE::Session::ASSERT_STATES () { 1 }";
## use critic
}
# should we "hide" XS::Queue::Array?
if ( defined $ARGV[4] and $ARGV[4] ) {
## no critic
eval "use Devel::Hide qw( POE/XS/Queue/Array.pm )";
## use critic
}
}
# load POE
use POE;
use POE::Session;
+
+# autoflush, please!
use IO::Handle;
+STDOUT->autoflush( 1 );
# load our utility stuff
use POE::Devel::Benchmarker::Utils qw( loop2realversion poeloop2load );
# init our global variables ( bad, haha )
my( $version, $eventloop, $asserts, $lite_tests, $pocosession );
my( $post_limit, $alarm_limit, $alarm_add_limit, $session_limit, $select_limit, $through_limit, $call_limit, $start_limit );
# the main routine which will load everything + start
sub benchmark {
- # autoflush our STDOUT for sanity
- STDOUT->autoflush( 1 );
-
# process the version
process_version();
# process the eventloop
process_eventloop();
# process the assertions
process_assertions();
# process the test mode
process_testmode();
# process the XS::Queue hiding
process_xsqueue();
# actually import POE!
process_POE();
# actually run the benchmarks!
run_benchmarks();
# all done!
return;
}
sub process_version {
# Get the desired POE version
$version = $ARGV[0];
# Decide what to do
if ( ! defined $version ) {
die "Please supply a version to test!";
} elsif ( ! -d 'poedists/POE-' . $version ) {
die "That specified version does not exist!";
} else {
# we're happy...
}
return;
}
sub process_eventloop {
# Get the desired mode
$eventloop = $ARGV[1];
# print out the loop info
if ( ! defined $eventloop ) {
die "Please supply an event loop!";
} else {
my $loop = poeloop2load( $eventloop );
if ( ! defined $loop ) {
$loop = $eventloop;
}
my $v = loop2realversion( $eventloop );
if ( ! defined $v ) {
$v = 'UNKNOWN';
}
print "Using master loop: $loop-$v\n";
}
return;
}
sub process_assertions {
# Get the desired assert mode
$asserts = $ARGV[2];
if ( defined $asserts and $asserts ) {
print "Using FULL Assertions!\n";
} else {
print "Using NO Assertions!\n";
}
return;
}
sub process_testmode {
# get the desired test mode
$lite_tests = $ARGV[3];
if ( defined $lite_tests and $lite_tests ) {
print "Using the LITE tests\n";
$post_limit = 10_000;
$alarm_limit = 10_000;
$alarm_add_limit = 10_000;
$session_limit = 500;
$select_limit = 10_000;
$through_limit = 10_000;
$call_limit = 10_000;
$start_limit = 10;
} else {
print "Using the HEAVY tests\n";
$post_limit = 100_000;
$alarm_limit = 100_000;
$alarm_add_limit = 100_000;
$session_limit = 5_000;
$select_limit = 100_000;
$through_limit = 100_000;
$call_limit = 100_000;
$start_limit = 100;
}
return;
}
sub process_xsqueue {
# should we "hide" XS::Queue::Array?
if ( defined $ARGV[4] and $ARGV[4] ) {
print "DISABLING POE::XS::Queue::Array\n";
} else {
print "LETTING POE find POE::XS::Queue::Array\n";
}
return;
}
sub process_POE {
# Print the POE info
print "Using POE-" . $POE::VERSION . "\n";
# Actually print what loop POE is using
foreach my $m ( keys %INC ) {
if ( $m =~ /^POE\/(?:Loop|XS|Queue)/ ) {
# try to be smart and get version?
my $module = $m;
$module =~ s|/|::|g;
$module =~ s/\.pm$//g;
print "POE is using: $module ";
if ( defined $module->VERSION ) {
print "v" . $module->VERSION . "\n";
} else {
print "vUNKNOWN\n";
}
}
}
return;
}
sub run_benchmarks {
+ # dump some misc info
+ dump_perlinfo();
+ dump_sysinfo();
+
# run the startup test before we actually run POE
bench_startup();
# load the POE session + do the tests there
bench_poe();
- # dump some misc info
+ # okay, dump our memory usage
dump_pidinfo();
- dump_perlinfo();
- dump_sysinfo();
# all done!
return;
}
sub bench_startup {
# Add the eventloop?
my $looploader = poeloop2load( $eventloop );
my @start_times = times();
my $start = time();
for (my $i = 0; $i < $start_limit; $i++) {
# FIXME should we add assertions?
# finally, fire it up!
CORE::system(
$^X,
'-Ipoedists/POE-' . $version,
'-Ipoedists/POE-' . $version . '/lib',
( defined $looploader ? "-M$looploader" : () ),
'-MPOE',
'-e',
1,
);
}
my @end_times = times();
my $elapsed = time() - $start;
printf( "\n\n% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $start_limit, 'startups', $elapsed, $start_limit/$elapsed );
print "startups times: @start_times @end_times\n";
return;
}
sub bench_poe {
# figure out POE::Session->create or POE::Session->new or what?
$pocosession = POE::Session->can( 'create' );
if ( defined $pocosession ) {
$pocosession = 'create';
} else {
$pocosession = POE::Session->can( 'spawn' );
if ( defined $pocosession ) {
$pocosession = 'spawn';
} else {
$pocosession = 'new';
}
}
# create the master sesssion + run POE!
POE::Session->$pocosession(
'inline_states' => {
# basic POE states
'_start' => \&poe__start,
'_default' => \&poe__default,
'_stop' => \&poe__stop,
'null' => \&poe_null,
# our test states
'posts' => \&poe_posts,
'posts_start' => \&poe_posts_start,
'posts_end' => \&poe_posts_end,
'alarms' => \&poe_alarms,
'manyalarms' => \&poe_manyalarms,
'sessions' => \&poe_sessions,
'sessions_end' => \&poe_sessions_end,
'stdin_read' => \&poe_stdin_read,
'stdin_write' => \&poe_stdin_write,
'myfh_read' => \&poe_myfh_read,
'myfh_write' => \&poe_myfh_write,
'calls' => \&poe_calls,
'eventsquirt' => \&poe_eventsquirt,
'eventsquirt_done' => \&poe_eventsquirt_done,
},
);
# start the kernel!
POE::Kernel->run();
return;
}
# inits our session
sub poe__start {
# fire off the first test!
$_[KERNEL]->yield( 'posts' );
return;
}
sub poe__stop {
}
sub poe__default {
return 0;
}
# a state that does nothing
sub poe_null {
return 1;
}
# How many posts per second? Post a bunch of events, keeping track of the time it takes.
sub poe_posts {
$_[KERNEL]->yield( 'posts_start' );
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $post_limit; $i++) {
$_[KERNEL]->yield( 'null' );
}
my @end_times = times();
my $elapsed = time() - $start;
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $post_limit, 'posts', $elapsed, $post_limit/$elapsed );
print "posts times: @start_times @end_times\n";
$_[KERNEL]->yield( 'posts_end' );
return;
}
sub poe_posts_start {
$_[HEAP]->{start} = time();
$_[HEAP]->{starttimes} = [ times() ];
return;
}
sub poe_posts_end {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $post_limit, 'dispatches', $elapsed, $post_limit/$elapsed );
print "dispatches times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
$_[KERNEL]->yield( 'alarms' );
return;
}
# How many alarms per second? Set a bunch of alarms and find out.
sub poe_alarms {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $alarm_limit; $i++) {
$_[KERNEL]->alarm( whee => rand(1_000_000) );
}
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $alarm_limit, 'alarms', $elapsed, $alarm_limit/$elapsed );
print "alarms times: @start_times @end_times\n";
$_[KERNEL]->alarm( 'whee' => undef );
$_[KERNEL]->yield( 'manyalarms' );
return;
}
# How many repetitive alarms per second? Set a bunch of
# additional alarms and find out. Also see how quickly they can
# be cleared.
sub poe_manyalarms {
# can this POE::Kernel support this?
if ( $_[KERNEL]->can( 'alarm_add' ) ) {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $alarm_add_limit; $i++) {
$_[KERNEL]->alarm_add( whee => rand(1_000_000) );
}
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $alarm_add_limit, 'alarm_adds', $elapsed, $alarm_add_limit/$elapsed );
print "alarm_adds times: @start_times @end_times\n";
$start = time();
@start_times = times();
$_[KERNEL]->alarm( whee => undef );
$elapsed = time() - $start;
@end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $alarm_add_limit, 'alarm_clears', $elapsed, $alarm_add_limit/$elapsed );
print "alarm_clears times: @start_times @end_times\n";
} else {
print "alarm_add NOT SUPPORTED on this version of POE, skipping alarm_adds/alarm_clears tests!\n";
}
$_[KERNEL]->yield( 'sessions' );
return;
}
# How many sessions can we create and destroy per second?
# Create a bunch of sessions, and track that time. Let them
# self-destruct, and track that as well.
sub poe_sessions {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $session_limit; $i++) {
POE::Session->$pocosession( 'inline_states' => { _start => sub {}, _stop => sub {}, _default => sub { return 0 } } );
}
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $session_limit, 'session_creates', $elapsed, $session_limit/$elapsed );
print "session_creates times: @start_times @end_times\n";
$_[KERNEL]->yield( 'sessions_end' );
$_[HEAP]->{start} = time();
$_[HEAP]->{starttimes} = [ times() ];
return;
}
sub poe_sessions_end {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $session_limit, 'session_destroys', $elapsed, $session_limit/$elapsed );
print "session_destroys times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
$_[KERNEL]->yield( 'stdin_read' );
return;
}
# How many times can we select/unselect READ a from STDIN filehandle per second?
sub poe_stdin_read {
# stupid, but we have to skip those tests
if ( $eventloop eq 'Tk' or $eventloop eq 'Prima' ) {
print "SKIPPING STDIN tests on broken loop: $eventloop\n";
$_[KERNEL]->yield( 'myfh_read' );
return;
}
my $start = time();
my @start_times = times();
eval {
for (my $i = 0; $i < $select_limit; $i++) {
$_[KERNEL]->select_read( *STDIN, 'whee' );
$_[KERNEL]->select_read( *STDIN );
}
};
if ( $@ ) {
print "filehandle select_read on STDIN FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $select_limit, 'select_read_STDIN', $elapsed, $select_limit/$elapsed );
print "select_read_STDIN times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'stdin_write' );
return;
}
# How many times can we select/unselect WRITE a from STDIN filehandle per second?
sub poe_stdin_write {
my $start = time();
my @start_times = times();
eval {
for (my $i = 0; $i < $select_limit; $i++) {
$_[KERNEL]->select_write( *STDIN, 'whee' );
$_[KERNEL]->select_write( *STDIN );
}
};
if ( $@ ) {
print "filehandle select_write on STDIN FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $select_limit, 'select_write_STDIN', $elapsed, $select_limit/$elapsed );
print "select_write_STDIN times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'myfh_read' );
return;
}
# How many times can we select/unselect READ a real filehandle?
sub poe_myfh_read {
# stupid, but we have to skip those tests
if ( $eventloop eq 'Event_Lib' or $eventloop eq 'Tk' or $eventloop eq 'Prima' ) {
print "SKIPPING MYFH tests on broken loop: $eventloop\n";
$_[KERNEL]->yield( 'calls' );
return;
}
my $start = time();
my @start_times = times();
eval {
open( my $fh, '+>', 'poebench' ) or die $!;
for (my $i = 0; $i < $select_limit; $i++) {
$_[KERNEL]->select_read( $fh, 'whee' );
$_[KERNEL]->select_read( $fh );
}
close( $fh ) or die $!;
unlink( 'poebench' ) or die $!;
};
if ( $@ ) {
print "filehandle select_read on MYFH FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $select_limit, 'select_read_MYFH', $elapsed, $select_limit/$elapsed );
print "select_read_MYFH times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'myfh_write' );
return;
}
# How many times can we select/unselect WRITE a real filehandle?
sub poe_myfh_write {
my $start = time();
my @start_times = times();
eval {
open( my $fh, '+>', 'poebench' ) or die $!;
for (my $i = 0; $i < $select_limit; $i++) {
$_[KERNEL]->select_write( $fh, 'whee' );
$_[KERNEL]->select_write( $fh );
}
close( $fh ) or die $!;
unlink( 'poebench' ) or die $!;
};
if ( $@ ) {
print "filehandle select_write on MYFH FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $select_limit, 'select_write_MYFH', $elapsed, $select_limit/$elapsed );
print "select_write_MYFH times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'calls' );
return;
}
# How many times can we call a state?
sub poe_calls {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $call_limit; $i++) {
$_[KERNEL]->call( $_[SESSION], 'null' );
}
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $call_limit, 'calls', $elapsed, $call_limit/$elapsed );
print "calls times: @start_times @end_times\n";
$_[KERNEL]->yield( 'eventsquirt' );
return;
}
# How many events can we squirt through POE, one at a time?
sub poe_eventsquirt {
$_[HEAP]->{start} = time();
$_[HEAP]->{starttimes} = [ times() ];
$_[HEAP]->{yield_count} = $through_limit;
$_[KERNEL]->yield( 'eventsquirt_done' );
return;
}
sub poe_eventsquirt_done {
if (--$_[HEAP]->{yield_count}) {
$_[KERNEL]->yield( 'eventsquirt_done' );
} else {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $through_limit, 'single_posts', $elapsed, $through_limit/$elapsed );
print "single_posts times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
}
# reached end of tests!
return;
}
# Get the memory footprint
sub dump_pidinfo {
my $ret = open( my $fh, '<', '/proc/self/status' );
if ( defined $ret ) {
while ( <$fh> ) {
chomp;
if ( $_ ne '' ) {
print "pidinfo: $_\n";
}
}
close( $fh ) or die $!;
} else {
print "UNABLE TO GET /proc/self/status\n";
}
return;
}
# print the local Perl info
sub dump_perlinfo {
print "Running under perl binary: " . $^X . "\n";
require Config;
my $config = Config::myconfig();
foreach my $l ( split( /\n/, $config ) ) {
print "perlconfig: $l\n";
}
return;
}
# print the local system information
sub dump_sysinfo {
print "Running under machine: " . `uname -a` . "\n";
# get cpuinfo
my $ret = open( my $fh, '<', '/proc/cpuinfo' );
if ( defined $ret ) {
while ( <$fh> ) {
chomp;
if ( $_ ne '' ) {
print "cpuinfo: $_\n";
}
}
close( $fh ) or die $!;
} else {
print "UNABLE TO GET /proc/cpuinfo\n";
}
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::SubProcess - Implements the actual POE benchmarks
=head1 SYNOPSIS
perl -MPOE::Devel::Benchmarker::SubProcess -e 'benchmark()'
=head1 ABSTRACT
This package is responsible for implementing the guts of the benchmarks, and timing them.
=head1 EXPORT
Nothing.
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/Utils.pm b/lib/POE/Devel/Benchmarker/Utils.pm
index 191d70c..0ca6dce 100644
--- a/lib/POE/Devel/Benchmarker/Utils.pm
+++ b/lib/POE/Devel/Benchmarker/Utils.pm
@@ -1,211 +1,210 @@
# Declare our package
package POE::Devel::Benchmarker::Utils;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.04';
-# auto-export the only sub we have
-require Exporter;
-use vars qw( @ISA @EXPORT_OK );
-@ISA = qw(Exporter);
-@EXPORT_OK = qw( poeloop2load loop2realversion beautify_times knownloops generateTestfile );
+# set ourself up for exporting
+use base qw( Exporter );
+our @EXPORT_OK = qw( poeloop2load loop2realversion beautify_times knownloops generateTestfile );
# returns the filename for a particular test
sub generateTestfile {
my $heap = shift;
return 'POE-' . $heap->{'current_version'} .
'-' . $heap->{'current_loop'} .
'-' . ( $heap->{'lite_tests'} ? 'LITE' : 'HEAVY' ) .
'-' . ( $heap->{'current_assertions'} ? 'assert' : 'noassert' ) .
'-' . ( $heap->{'current_noxsqueue'} ? 'noxsqueue' : 'xsqueue' );
}
# returns the proper "load" stuff for a specific loop
sub poeloop2load {
my $eventloop = shift;
# Decide which event loop to use
# Event_Lib EV Glib Prima Gtk Wx Kqueue Tk Select IO_Poll
if ( $eventloop eq 'Event' ) {
return 'Event';
} elsif ( $eventloop eq 'IO_Poll' ) {
return 'IO::Poll';
} elsif ( $eventloop eq 'Event_Lib' ) {
return 'Event::Lib';
} elsif ( $eventloop eq 'EV' ) {
return 'EV';
} elsif ( $eventloop eq 'Glib' ) {
return 'Glib';
} elsif ( $eventloop eq 'Tk' ) {
return 'Tk',
} elsif ( $eventloop eq 'Gtk' ) {
return 'Gtk';
} elsif ( $eventloop eq 'Prima' ) {
return 'Prima';
} elsif ( $eventloop eq 'Wx' ) {
return 'Wx';
} elsif ( $eventloop eq 'Kqueue' ) {
# FIXME dunno what to do here!
return;
} elsif ( $eventloop eq 'Select' ) {
return;
} else {
die "Unknown event loop!";
}
}
# returns the version of the "real" installed module that the loop uses
sub loop2realversion {
my $eventloop = shift;
# Decide which event loop to use
if ( ! defined $eventloop ) {
return;
} elsif ( $eventloop eq 'Event' ) {
return $Event::VERSION;
} elsif ( $eventloop eq 'IO_Poll' ) {
return $IO::Poll::VERSION;
} elsif ( $eventloop eq 'Event_Lib' ) {
return $Event::Lib::VERSION;
} elsif ( $eventloop eq 'EV' ) {
return $EV::VERSION;
} elsif ( $eventloop eq 'Glib' ) {
return $Glib::VERSION;
} elsif ( $eventloop eq 'Tk' ) {
return $Tk::VERSION;
} elsif ( $eventloop eq 'Gtk' ) {
return $Gtk::VERSION;
} elsif ( $eventloop eq 'Prima' ) {
return $Prima::VERSION;
} elsif ( $eventloop eq 'Wx' ) {
return $Wx::VERSION;
} elsif ( $eventloop eq 'Kqueue' ) {
# FIXME how do I do this?
return;
} elsif ( $eventloop eq 'Select' ) {
return 'BUILTIN';
} else {
die "Unknown event loop!";
}
}
# helper routine to parse times() output
sub beautify_times {
my $string = shift;
my $origdata = shift;
# split it up
$string =~ s/^\s+//; $string =~ s/\s+$//;
my @times = split( /\s+/, $string );
# make the data struct
# ($user,$system,$cuser,$csystem) = times;
my $data = {
'u' => $times[4] - $times[0],
's' => $times[5] - $times[1],
'cu' => $times[6] - $times[2],
'cs' => $times[7] - $times[3],
};
# add original data?
if ( $origdata ) {
$data->{'s_user'} = $times[0];
$data->{'s_sys'} = $times[1];
$data->{'s_cuser'} = $times[2];
$data->{'s_csys'} = $times[3];
$data->{'e_user'} = $times[4];
$data->{'e_sys'} = $times[5];
$data->{'e_cuser'} = $times[6];
$data->{'e_csys'} = $times[7];
}
# send it back!
return $data;
}
# returns a list of "known" POE loops
sub knownloops {
# FIXME we remove Wx because I suck.
- return [ qw( Event_Lib EV Glib Prima Gtk Kqueue Tk Select IO_Poll ) ];
+ # FIXME I have no idea how to load/unload Kqueue...
+ return [ qw( Event_Lib EV Glib Prima Gtk Tk Select IO_Poll ) ];
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::Utils - Various utility routines for POE::Devel::Benchmarker
=head1 SYNOPSIS
perl -MPOE::Devel::Benchmarker::Utils -e 'print poeloop2load( "IO_Poll" )'
=head1 ABSTRACT
This package contains the utility routines and constants that POE::Devel::Benchmarker needs.
=head1 EXPORT
This package exports those subs via @EXPORT_OK:
=over 4
=item knownloops()
Returns an arrayref of the "known" POE loops as of this version of the Benchmarker
=item poeloop2load()
Returns the "parent" class to load for a specific loop. An example is:
$real = poeloop2load( 'IO_Poll' ); # $real now contains "IO::Poll"
=item loop2realversion()
Returns the version of the "parent" class for a specific loop. An example is:
$ver = loop2realversion( 'IO_Poll' ); # $ver now contains $IO::Poll::VERSION
=item beautify_times()
Returns a hashref of data from parsing 2 consecutive times() structures in a string. You can pass an additional parameter
( boolean ) to include the original data. An example is:
print Data::Dumper::Dumper( beautify_times( '0.1 0 0 0 0.1 0 0.76 0.09', 1 ) );
{
"sys" => 0, # total system time
"user" => 0, # total user time
"csys" => 0.76 # total children system time
"cuser" => 0.08 # total children user time
"e_csys" => "0.09", # end children system time ( optional )
"e_cuser" => "0.76", # end children user time ( optional )
"e_sys" => 0, # end system time ( optional )
"e_user" => "0.1", # end user time ( optional )
"s_csys" => 0, # start children system time ( optional )
"s_cuser" => 0, # start children user time ( optional )
"s_sys" => 0, # start system time ( optional )
"s_user" => "0.1" # start user time ( optional )
}
=back
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
|
apocalypse/perl-poe-benchmarker
|
279baf9a8141ed65b530e62884e2753c8a97b572
|
more tweaks to get YAML filesize down
|
diff --git a/Build.PL b/Build.PL
index 9758a94..88358bf 100755
--- a/Build.PL
+++ b/Build.PL
@@ -1,100 +1,102 @@
# Build.PL
use Module::Build;
my $build = Module::Build->new(
# look up Module::Build::API for the info!
'dynamic_config' => 0,
'module_name' => 'POE::Devel::Benchmarker',
'license' => 'perl',
'dist_abstract' => "Benchmarking POE's performance ( acts more like a smoker )",
'dist_author' => 'Apocalypse <APOCAL@cpan.org>',
'create_packlist' => 1,
'create_makefile_pl' => 'traditional',
'create_readme' => 1,
'test_files' => 't/*.t',
'add_to_cleanup' => [ 'META.yml', 'Makefile.PL', 'README' ], # automatically generated
'requires' => {
# POE Stuff
'POE' => 0,
'POE::Session::AttributeBased' => 0,
# misc perl stuff
'Time::HiRes' => 0,
'version' => 0,
'Devel::Hide' => 0,
# Analyzer reqs
'YAML::Tiny' => 0,
#'POE::Component::SimpleDBI' => 0,
# GetPOEdists reqs
'LWP::UserAgent' => 0,
'HTML::LinkExtor' => 0,
'URI::URL' => 0,
'Archive::Tar' => 0,
# Imager reqs
'Chart::Clicker' => 0,
+ 'Chart::Clicker::Data::DataSet' => 0,
+ 'Chart::Clicker::Data::Series' => 0,
},
'recommends' => {
# Test stuff
'Test::More' => '0.86', # require latest for note() support in t/a_is_prereq_outdated.t
# our POE loops!
'POE::Loop::Event' => 0,
'POE::Loop::Event_Lib' => 0,
'POE::Loop::EV' => 0,
'POE::Loop::Glib' => 0,
'POE::Loop::Prima' => 0,
'POE::Loop::Gtk' => 0,
'POE::Loop::Wx' => 0,
'POE::Loop::Kqueue' => 0,
# included in POE ( listed here for completeness )
#'POE::Loop::Tk' => 0,
#'POE::Loop::Select' => 0,
#'POE::Loop::IO_Poll' => 0,
# the loops' dependencies
'Event' => 0,
'Event::Lib' => 0,
'EV' => 0,
'Glib' => 0,
'Prima' => 0,
'Gtk' => 0,
'Wx' => 0,
'Tk' => 0,
# the XS queue
'POE::XS::Queue::Array' => 0,
},
# FIXME wishlist...
# 'test_requires' => {
# # Test stuff
# 'Test::Compile' => 0,
# 'Test::Perl::Critic' => 0,
# 'Test::Dependencies' => 0,
# 'Test::Distribution' => 0,
# 'Test::Fixme' => 0,
# 'Test::HasVersion' => 0,
# 'Test::Kwalitee' => 0,
# 'Test::CheckManifest' => 0,
# 'Test::MinimumVersion' => 0,
# 'Test::Pod::Coverage' => 0,
# 'Test::Spelling' => 0,
# 'Test::Pod' => 0,
# 'Test::Prereq' => 0,
# 'Test::Strict' => 0,
# 'Test::UseAllModules' => 0,
# },
);
# all done!
$build->create_build_script;
diff --git a/Changes b/Changes
index 9e9e474..6c77d40 100755
--- a/Changes
+++ b/Changes
@@ -1,28 +1,31 @@
Revision history for Perl extension POE::Devel::Benchmarker
* 0.04
Started work on the image generator ( Imager )
Added automatic "pick up where we left off" to the benchmarker
Added the freshstart option to benchmark()
Tweaked the GetPOEdists sub so it will work in the "work directory" and in the poedists dir
+ Tweaked the YAML output so it's smaller
+ Removed POE::Loop::Wx from autoprobing ( I'm unable to get it to work )
+ Hardcoded the Benchmarker routines to skip POE < 0.13 ( I'm unable to get it to work )
* 0.03
Added the loop option to benchmark(), thanks dngor!
Added the poe option to benchmark(), thanks dngor!
Added the noxsqueue option to benchmark()
Added the noasserts option to benchmark()
Automatically enable noxsqueue option if we cannot load POE::XS::Queue::Array, saving time
Bump Test::More version requirement because some people reported failures with note()
Fixed bug in SubProcess where it crashed on old POEs that didn't load IO::Handle
More documentation additions/tweaks
* 0.02
Added the Analyzer module ( and dump YAML files, yay! )
A lot of minor changes+tweaks to get a better dump format
* 0.01
initial release
diff --git a/lib/POE/Devel/Benchmarker.pm b/lib/POE/Devel/Benchmarker.pm
index 6fbbdc0..bff18c7 100644
--- a/lib/POE/Devel/Benchmarker.pm
+++ b/lib/POE/Devel/Benchmarker.pm
@@ -1,884 +1,897 @@
# Declare our package
package POE::Devel::Benchmarker;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.04';
# auto-export the only sub we have
BEGIN {
require Exporter;
use vars qw( @ISA @EXPORT );
@ISA = qw(Exporter);
@EXPORT = qw( benchmark );
}
# Import what we need from the POE namespace
sub POE::Kernel::ASSERT_DEFAULT { 1 }
sub POE::Session::ASSERT_DEFAULT { 1 }
use POE qw( Session Filter::Line Wheel::Run );
use base 'POE::Session::AttributeBased';
# we need hires times
use Time::HiRes qw( time );
# load comparison stuff
use version;
# use the power of YAML
use YAML::Tiny;
# Load our stuff
use POE::Devel::Benchmarker::GetInstalledLoops;
use POE::Devel::Benchmarker::Utils qw( poeloop2load knownloops generateTestfile );
use POE::Devel::Benchmarker::Analyzer;
# Actually run the tests!
sub benchmark {
my $options = shift;
# set default options
my $lite_tests = 1;
my $quiet_mode = 0;
my $forceloops = undef; # default to autoprobe all
my $forcepoe = undef; # default to all found POE versions in poedists/
my $forcenoxsqueue = 0; # default to try and load it
my $forcenoasserts = 0; # default is to run it
my $freshstart = 0; # always resume where we left off
# process our options
if ( defined $options and ref $options and ref( $options ) eq 'HASH' ) {
# process YES for freshstart
if ( exists $options->{'freshstart'} ) {
if ( $options->{'freshstart'} ) {
$freshstart = 1;
}
}
# process NO for XS::Queue::Array
if ( exists $options->{'noxsqueue'} ) {
if ( $options->{'noxsqueue'} ) {
$forcenoxsqueue = 1;
}
}
# process NO for ASSERT
if ( exists $options->{'noasserts'} ) {
if ( $options->{'noasserts'} ) {
$forcenoasserts = 1;
}
}
# process LITE tests
if ( exists $options->{'litetests'} ) {
if ( $options->{'litetests'} ) {
$lite_tests = 1;
} else {
$lite_tests = 0;
}
}
# process quiet mode
if ( exists $options->{'quiet'} ) {
if ( $options->{'quiet'} ) {
$quiet_mode = 1;
} else {
$quiet_mode = 0;
}
}
# process forceloops
if ( exists $options->{'loop'} and defined $options->{'loop'} ) {
if ( ! ref $options->{'loop'} ) {
# split it via CSV
$forceloops = [ split( /,/, $options->{'loop'} ) ];
foreach ( @$forceloops ) {
$_ =~ s/^\s+//; $_ =~ s/\s+$//;
}
} else {
# treat it as array
$forceloops = $options->{'loop'};
}
# check for !loop modules
my @noloops;
foreach my $l ( @$forceloops ) {
if ( $l =~ /^\!/ ) {
push( @noloops, substr( $l, 1 ) );
}
}
if ( scalar @noloops ) {
# replace the forceloops with ALL known, then subtract noloops from it
my %bad;
@bad{@noloops} = () x @noloops;
@$forceloops = grep { !exists $bad{$_} } @{ knownloops() };
}
}
# process the poe versions
if ( exists $options->{'poe'} and defined $options->{'poe'} ) {
if ( ! ref $options->{'poe'} ) {
# split it via CSV
$forcepoe = [ split( /,/, $options->{'poe'} ) ];
foreach ( @$forcepoe ) {
$_ =~ s/^\s+//; $_ =~ s/\s+$//;
}
} else {
# treat it as array
$forcepoe = $options->{'poe'};
}
}
}
# do some sanity checks
if ( ! -d 'poedists' ) {
die "The 'poedists' directory is not found in the working directory!";
}
if ( ! -d 'results' ) {
die "The 'results' directory is not found in the working directory!";
}
if ( ! $quiet_mode ) {
print "[BENCHMARKER] Starting up...\n";
}
# Create our session
POE::Session->create(
__PACKAGE__->inline_states(),
'heap' => {
# misc stuff
'quiet_mode' => $quiet_mode,
# override our testing behavior
'lite_tests' => $lite_tests,
'forceloops' => $forceloops,
'forcepoe' => $forcepoe,
'forcenoxsqueue' => $forcenoxsqueue,
'forcenoasserts' => $forcenoasserts,
'freshstart' => $freshstart,
},
);
# Fire 'er up!
POE::Kernel->run();
return;
}
# Starts up our session
sub _start : State {
# okay, get all the dists we can!
my @versions;
if ( opendir( DISTS, 'poedists' ) ) {
foreach my $d ( readdir( DISTS ) ) {
if ( $d =~ /^POE\-(.+)$/ and $d !~ /\.tar\.gz$/ ) {
- push( @versions, $1 );
+ # FIXME skip POE < 0.13 because I can't get it to work
+ my $ver = version->new( $1 );
+ if ( $ver > v0.13 ) {
+ push( @versions, $ver->stringify );
+ }
}
}
closedir( DISTS ) or die $!;
} else {
print "[BENCHMARKER] Unable to open 'poedists' for reading: $!\n";
return;
}
- # sanity
- if ( ! scalar @versions ) {
- print "[BENCHMARKER] Unable to find any POE version in the 'poedists' directory!\n";
- return;
- }
-
# should we munge the versions list?
if ( defined $_[HEAP]->{'forcepoe'} ) {
# check for !poe versions
my @nopoe;
foreach my $p ( @{ $_[HEAP]->{'forcepoe'} } ) {
if ( $p =~ /^\!/ ) {
push( @nopoe, substr( $p, 1 ) );
}
}
if ( scalar @nopoe ) {
# remove the nopoe versions from the found
my %bad;
@bad{@nopoe} = () x @nopoe;
@versions = grep { !exists $bad{$_} } @versions;
} else {
# make sure the @versions contains only what we specified
my %good;
@good{ @{ $_[HEAP]->{'forcepoe'} } } = () x @{ $_[HEAP]->{'forcepoe'} };
@versions = grep { exists $good{$_} } @versions;
}
+ }
- # again, make sure we have at least a version, ha!
- if ( ! scalar @versions ) {
- print "[BENCHMARKER] Unable to find any POE version in the 'poedists' directory!\n";
- return;
- }
+ # sanity
+ if ( ! scalar @versions ) {
+ print "[BENCHMARKER] Unable to find any POE version in the 'poedists' directory!\n";
+ return;
}
# set our alias
$_[KERNEL]->alias_set( 'Benchmarker' );
# sanely handle some signals
$_[KERNEL]->sig( 'INT', 'handle_kill' );
$_[KERNEL]->sig( 'TERM', 'handle_kill' );
# okay, go through all the dists in version order
@versions = sort { $b <=> $a }
map { version->new( $_ ) } @versions;
# Store the versions in our heap
$_[HEAP]->{'VERSIONS'} = \@versions;
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Detected available POE versions -> " . join( " ", @versions ) . "\n";
}
# First of all, we need to find out what loop libraries are installed
getPOEloops( $_[HEAP]->{'quiet_mode'}, $_[HEAP]->{'forceloops'} );
return;
}
sub _stop : State {
# tell the wheel to kill itself
if ( defined $_[HEAP]->{'WHEEL'} ) {
$_[HEAP]->{'WHEEL'}->kill( 9 );
undef $_[HEAP]->{'WHEEL'};
}
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Shutting down...\n";
}
return;
}
# misc POE handlers
sub _child : State {
return;
}
sub handle_kill : State {
return;
}
# we received list of loops from GetInstalledLoops
sub found_loops : State {
$_[HEAP]->{'installed_loops'} = [ sort { $a cmp $b } @{ $_[ARG0] } ];
# sanity check
if ( scalar @{ $_[HEAP]->{'installed_loops'} } == 0 ) {
print "[BENCHMARKER] Detected no available POE::Loop, check your configuration?!?\n";
return;
}
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Detected available POE::Loops -> " . join( " ", @{ $_[HEAP]->{'installed_loops'} } ) . "\n";
}
# Okay, do we have XS::Queue installed?
if ( ! $_[HEAP]->{'forcenoxsqueue'} ) {
eval { require POE::XS::Queue::Array };
if ( $@ ) {
$_[HEAP]->{'forcenoxsqueue'} = 1;
}
}
# Fire up the analyzer
initAnalyzer( $_[HEAP]->{'quiet_mode'} );
+ if ( ! $_[HEAP]->{'quiet_mode'} ) {
+ print "[BENCHMARKER] Starting the benchmarks!" .
+ ( $_[HEAP]->{'forcenoxsqueue'} ? ' Skipping XS::Queue Tests!' : '' ) .
+ ( $_[HEAP]->{'forcenoasserts'} ? ' Skipping ASSERT Tests!' : '' ) .
+ "\n";
+ }
+
# start the benchmark!
$_[KERNEL]->yield( 'run_benchmark' );
return;
}
# Runs one benchmark
sub run_benchmark : State {
# Grab the version from the top of the array
$_[HEAP]->{'current_version'} = shift @{ $_[HEAP]->{'VERSIONS'} };
# did we run out of versions?
if ( ! defined $_[HEAP]->{'current_version'} ) {
# We're done, let POE die...
$_[KERNEL]->alias_remove( 'Benchmarker' );
} else {
$_[HEAP]->{'loops'} = [ @{ $_[HEAP]->{'installed_loops'} } ];
# okay, fire off the first loop
$_[KERNEL]->yield( 'bench_loop' );
}
return;
}
# runs one loop
sub bench_loop : State {
# select our current loop
$_[HEAP]->{'current_loop'} = shift @{ $_[HEAP]->{'loops'} };
# are we done with all loops?
if ( ! defined $_[HEAP]->{'current_loop'} ) {
# yay, go back to the main handler
$_[KERNEL]->yield( 'run_benchmark' );
} else {
# Start the assert test
if ( $_[HEAP]->{'forcenoasserts'} ) {
$_[HEAP]->{'assertions'} = [ qw( 0 ) ];
} else {
$_[HEAP]->{'assertions'} = [ qw( 0 1 ) ];
}
$_[KERNEL]->yield( 'bench_asserts' );
}
return;
}
# runs an assertion
sub bench_asserts : State {
# select our current assert state
$_[HEAP]->{'current_assertions'} = shift @{ $_[HEAP]->{'assertions'} };
# are we done?
if ( ! defined $_[HEAP]->{'current_assertions'} ) {
# yay, go back to the loop handler
$_[KERNEL]->yield( 'bench_loop' );
} else {
# Start the xsqueue test
if ( $_[HEAP]->{'forcenoxsqueue'} ) {
$_[HEAP]->{'noxsqueue'} = [ qw( 1 ) ];
} else {
$_[HEAP]->{'noxsqueue'} = [ qw( 0 1 ) ];
}
$_[KERNEL]->yield( 'bench_xsqueue' );
}
return;
}
# runs test with or without xsqueue
sub bench_xsqueue : State {
# select our current noxsqueue state
$_[HEAP]->{'current_noxsqueue'} = shift @{ $_[HEAP]->{'noxsqueue'} };
# are we done?
if ( ! defined $_[HEAP]->{'current_noxsqueue'} ) {
# yay, go back to the assert handler
$_[KERNEL]->yield( 'bench_asserts' );
} else {
# do some careful analysis
$_[KERNEL]->yield( 'bench_checkprevioustest' );
}
return;
}
# Checks to see if this test was run in the past
sub bench_checkprevioustest : State {
# okay, do we need to check and see if we already did this test?
if ( ! $_[HEAP]->{'freshstart'} ) {
# determine the file used
my $file = generateTestfile( $_[HEAP] );
# does it exist?
if ( -e "results/$file.yml" and -f _ and -s _ ) {
# okay, sanity check it
my $yaml = YAML::Tiny->read( "results/$file.yml" );
if ( defined $yaml ) {
# inrospect it!
my $isvalid = 0;
eval {
# the version must at least match us
$isvalid = ( $yaml->[0]->{'benchmarker'} eq $POE::Devel::Benchmarker::VERSION ? 1 : 0 );
if ( $isvalid ) {
# simple sanity check: the "uname" param is at the end of the YML, so if it loads fine we know it's there
if ( ! exists $yaml->[0]->{'uname'} ) {
$isvalid = undef;
}
}
};
if ( $isvalid ) {
# yay, this test is A-OK!
$_[KERNEL]->yield( 'bench_xsqueue' );
return;
} else {
# was it truncated?
if ( ! defined $isvalid ) {
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] YAML file($file) from previous test was corrupt!\n";
}
}
}
} else {
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Unable to load YAML file($file) from previous test run: " . YAML::Tiny->errstr . "\n";
}
}
}
}
# could not find previous file or FRESHSTART, proceed normally
$_[KERNEL]->yield( 'create_subprocess' );
return;
}
# actually runs the subprocess
sub create_subprocess : State {
# Okay, start testing this specific combo!
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "Testing " . generateTestfile( $_[HEAP] ) . "\n";
}
# save the starttime
$_[HEAP]->{'current_starttime'} = time();
$_[HEAP]->{'current_starttimes'} = [ times() ];
# Okay, create the wheel::run to handle this
my $looploader = poeloop2load( $_[HEAP]->{'current_loop'} );
$_[HEAP]->{'WHEEL'} = POE::Wheel::Run->new(
'Program' => $^X,
'ProgramArgs' => [ '-Ipoedists/POE-' . $_[HEAP]->{'current_version'},
'-Ipoedists/POE-' . $_[HEAP]->{'current_version'} . '/lib',
( defined $looploader ? "-M$looploader" : () ),
'-MPOE::Devel::Benchmarker::SubProcess',
'-e',
'POE::Devel::Benchmarker::SubProcess::benchmark',
$_[HEAP]->{'current_version'},
$_[HEAP]->{'current_loop'},
$_[HEAP]->{'current_assertions'},
$_[HEAP]->{'lite_tests'},
$_[HEAP]->{'current_noxsqueue'},
],
# Kill off existing FD's
'CloseOnCall' => 1,
# setup our data handlers
'StdoutEvent' => 'Got_STDOUT',
'StderrEvent' => 'Got_STDERR',
# the error handler
'ErrorEvent' => 'Got_ERROR',
'CloseEvent' => 'Got_CLOSED',
# set our filters
'StderrFilter' => POE::Filter::Line->new(),
'StdoutFilter' => POE::Filter::Line->new(),
);
if ( ! defined $_[HEAP]->{'WHEEL'} ) {
die 'Unable to create a new wheel!';
} else {
# smart CHLD handling
if ( $_[KERNEL]->can( "sig_child" ) ) {
$_[KERNEL]->sig_child( $_[HEAP]->{'WHEEL'}->PID => 'Got_CHLD' );
} else {
$_[KERNEL]->sig( 'CHLD', 'Got_CHLD' );
}
}
# setup our data we received from the subprocess
$_[HEAP]->{'current_data'} = '';
# Okay, we timeout this test after some time for sanity
$_[HEAP]->{'test_timedout'} = 0;
if ( $_[HEAP]->{'lite_tests'} ) {
# on my core2duo 1.2ghz laptop, running Gtk+LITE+assert+noxsqueue takes approx 45s
$_[HEAP]->{'TIMER'} = $_[KERNEL]->delay_set( 'test_timedout' => 60 * 2 );
} else {
# on my core2duo 1.2ghz laptop, running Gtk+HEAVY+assert+noxsqueue takes all day long :(
$_[HEAP]->{'TIMER'} = $_[KERNEL]->delay_set( 'test_timedout' => 60 * 15 );
}
return;
}
# Got a CHLD event!
sub Got_CHLD : State {
$_[KERNEL]->sig_handled();
return;
}
# Handles child STDERR output
sub Got_STDERR : State {
my $input = $_[ARG0];
- # save it!
- $_[HEAP]->{'current_data'} .= '!STDERR: ' . $input . "\n";
+ # skip empty lines
+ if ( $input ne '' ) {
+ # save it!
+ $_[HEAP]->{'current_data'} .= '!STDERR: ' . $input . "\n";
+ }
return;
}
# Handles child STDOUT output
sub Got_STDOUT : State {
my $input = $_[ARG0];
# save it!
$_[HEAP]->{'current_data'} .= $input . "\n";
return;
}
# Handles child error
sub Got_ERROR : State {
# Copied from POE::Wheel::Run manpage
my ( $operation, $errnum, $errstr ) = @_[ ARG0 .. ARG2 ];
# ignore exit 0 errors
if ( $errnum != 0 ) {
print "[BENCHMARKER] Wheel::Run got an $operation error $errnum: $errstr\n";
}
return;
}
# Handles child DIE'ing
sub Got_CLOSED : State {
# Get rid of the wheel
undef $_[HEAP]->{'WHEEL'};
# get rid of the delay
$_[KERNEL]->alarm_remove( $_[HEAP]->{'TIMER'} );
undef $_[HEAP]->{'TIMER'};
# wrap up this test
$_[KERNEL]->yield( 'wrapup_test' );
return;
}
# a test timed out, unfortunately!
sub test_timedout : State {
# tell the wheel to kill itself
$_[HEAP]->{'WHEEL'}->kill( 9 );
undef $_[HEAP]->{'WHEEL'};
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Test Timed Out!\n";
}
$_[HEAP]->{'test_timedout'} = 1;
# wrap up this test
$_[KERNEL]->yield( 'wrapup_test' );
return;
}
# finalizes a test
sub wrapup_test : State {
# we're done with this benchmark!
$_[HEAP]->{'current_endtime'} = time();
$_[HEAP]->{'current_endtimes'} = [ times() ];
# store the data
my $file = generateTestfile( $_[HEAP] );
if ( open( my $fh, '>', "results/$file" ) ) {
print $fh "STARTTIME: " . $_[HEAP]->{'current_starttime'} . " -> TIMES " . join( " ", @{ $_[HEAP]->{'current_starttimes'} } ) . "\n";
print $fh "$file\n";
print $fh $_[HEAP]->{'current_data'} . "\n";
if ( $_[HEAP]->{'test_timedout'} ) {
print $fh "\nTEST TERMINATED DUE TO TIMEOUT\n";
}
print $fh "ENDTIME: " . $_[HEAP]->{'current_endtime'} . " -> TIMES " . join( " ", @{ $_[HEAP]->{'current_endtimes'} } ) . "\n";
close( $fh ) or die $!;
} else {
print "[BENCHMARKER] Unable to open results/$file for writing -> $!\n";
}
# Send the data to the Analyzer to process
$_[KERNEL]->post( 'Benchmarker::Analyzer', 'analyze', {
- 'poe_version' => $_[HEAP]->{'current_version'}->stringify, # YAML::Tiny doesn't like version objects :(
- 'poe_loop' => 'POE::Loop::' . $_[HEAP]->{'current_loop'},
- 'asserts' => $_[HEAP]->{'current_assertions'},
- 'noxsqueue' => $_[HEAP]->{'current_noxsqueue'},
- 'litetests' => $_[HEAP]->{'lite_tests'},
- 'start_time' => $_[HEAP]->{'current_starttime'},
- 'start_times' => [ @{ $_[HEAP]->{'current_starttimes'} } ],
- 'end_time' => $_[HEAP]->{'current_endtime'},
- 'end_times' => [ @{ $_[HEAP]->{'current_endtimes'} } ],
- 'timedout' => $_[HEAP]->{'test_timedout'},
- 'rawdata' => $_[HEAP]->{'current_data'},
- 'test_file' => $file,
+ 'poe' => {
+ 'v' => $_[HEAP]->{'current_version'}->stringify, # YAML::Tiny doesn't like version objects :(
+ 'loop' => 'POE::Loop::' . $_[HEAP]->{'current_loop'},
+ },
+ 't' => {
+ 's_ts' => $_[HEAP]->{'current_starttime'},
+ 'e_ts' => $_[HEAP]->{'current_endtime'},
+ 'd' => $_[HEAP]->{'current_endtime'} - $_[HEAP]->{'current_starttime'},
+ 's_t' => [ @{ $_[HEAP]->{'current_starttimes'} } ],
+ 'e_t' => [ @{ $_[HEAP]->{'current_endtimes'} } ],
+ },
+ 'raw' => $_[HEAP]->{'current_data'},
+ 'test' => $file,
'benchmarker' => $POE::Devel::Benchmarker::VERSION,
+ ( $_[HEAP]->{'test_timedout'} ? ( 'timedout' => 1 ) : () ),
+ ( $_[HEAP]->{'lite_tests'} ? ( 'litetests' => 1 ) : () ),
+ ( $_[HEAP]->{'current_assertions'} ? ( 'asserts' => 1 ) : () ),
+ ( $_[HEAP]->{'current_noxsqueue'} ? ( 'noxsqueue' => 1 ) : () ),
} );
# process the next test
$_[KERNEL]->yield( 'bench_xsqueue' );
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker - Benchmarking POE's performance ( acts more like a smoker )
=head1 SYNOPSIS
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker -e 'benchmark()'
=head1 ABSTRACT
This package of tools is designed to benchmark POE's performace across different
configurations. The current "tests" are:
=over 4
=item posts
This tests how long it takes to post() N times
This tests how long it took to dispatch/deliver all the posts enqueued in the post() test
This tests how long it took to yield() between 2 states for N times
=item calls
This tests how long it took to call() N times
=item alarms
This tests how long it took to add N alarms via alarm(), overwriting each other
This tests how long it took to add N alarms via alarm_add() and how long it took to delete them all
NOTE: alarm_add is not available on all versions of POE!
=item sessions
This tests how long it took to create N sessions, and how long it took to destroy them all
=item filehandles
This tests how long it took to toggle select_read N times on STDIN and a real filehandle via open()
This tests how long it took to toggle select_write N times on STDIN and a real filehandle via open()
=item POE startup time
This tests how long it took to start + close N instances of a "virgin" POE without any sessions/etc
=item POE Loops
This is actually a "super" test where all of the specific tests is ran against various POE::Loop::XYZ/FOO for comparison
=item POE Assertions
This is actually a "super" test where all of the specific tests is ran against POE with/without assertions enabled
=item POE::XS::Queue::Array
This is actually a "super" test where all of the specific tests is ran against POE with XS goodness enabled/disabled
=back
=head1 DESCRIPTION
This module is poorly documented now. Please give me some time to properly document it over time :)
=head2 INSTALLATION
Here's a simple outline to get you up to speed quickly. ( and smoking! )
=over 4
=item Install CPAN package + dependencies
Download+install the POE::Devel::Benchmarker package from CPAN
apoc@apoc-x300:~$ cpanp -i POE::Devel::Benchmarker
=item Setup initial directories
Go anywhere, and create the "parent" directory where you'll be storing test results + stuff. For this example,
I have chosen to use ~/poe-benchmarker:
apoc@apoc-x300:~$ mkdir poe-benchmarker
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ mkdir poedists results images
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker::GetPOEdists -e 'getPOEdists( 1 )'
( go get a coffee while it downloads if you're on a slow link, ha! )
=item Let 'er rip!
At this point you can start running the benchmark!
NOTE: the Benchmarker expects everything to be in the "local" directory!
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker -e 'benchmark()'
( go sleep or something, this will take a while! )
=back
=head2 BENCHMARKING
On startup the Benchmarker will look in the "poedists" directory and load all the distributions it sees untarred there. Once
that is done it will begin autoprobing for available POE::Loop packages. Once it determines what's available, it will begin
the benchmarks.
As the Benchmarker goes through the combinations of POE + Eventloop + Assertions + XS::Queue it will dump data into
the results directory. The Analyzer module also dumps YAML output in the same place, with the suffix of ".yml"
This module exposes only one subroutine, the benchmark() one. You can pass a hashref to it to set various options. Here is
a list of the valid options:
=over 4
=item freshstart => boolean
This will tell the Benchmarker to ignore any previous test runs stored in the 'results' directory.
benchmark( { freshstart => 1 } );
default: false
=item noxsqueue => boolean
This will tell the Benchmarker to force the unavailability of POE::XS::Queue::Array and skip those tests.
NOTE: The Benchmarker will set this automatically if it cannot load the module!
benchmark( { noxsqueue => 1 } );
default: false
=item noasserts => boolean
This will tell the Benchmarker to not run the ASSERT tests.
benchmark( { noasserts => 1 } );
default: false
=item litetests => boolean
This enables the "lite" tests which will not take up too much time.
benchmark( { litetests => 0 } );
default: true
=item quiet => boolean
This enables quiet mode which will not print anything to the console except for errors.
benchmark( { 'quiet' => 1 } );
default: false
=item loop => csv list or array
This overrides the built-in loop detection algorithm which searches for all known loops.
There is some "magic" here where you can put a negative sign in front of a loop and we will NOT run that.
NOTE: Capitalization is important!
benchmark( { 'loop' => 'IO_Poll,Select' } ); # runs only IO::Poll and Select
benchmark( { 'loop' => [ qw( Tk Gtk ) ] } ); # runs only Tk and Gtk
benchmark( { 'loop' => '-Tk' } ); # runs all available loops EXCEPT for TK
-Known loops: Event_Lib EV Glib Prima Gtk Wx Kqueue Tk Select IO_Poll
+Known loops: Event_Lib EV Glib Prima Gtk Kqueue Tk Select IO_Poll
=item poe => csv list or array
This overrides the built-in POE version detection algorithm which pulls the POE versions from the 'poedists' directory.
There is some "magic" here where you can put a negative sign in front of a version and we will NOT run that.
NOTE: The Benchmarker will ignore versions that wasn't found in the directory!
benchmark( { 'poe' => '0.35,1.003' } ); # runs on 0.35 and 1.003
benchmark( { 'poe' => [ qw( 0.3009 0.12 ) ] } ); # runs on 0.3009 and 0.12
benchmark( { 'poe' => '-0.35' } ); # runs ALL tests except 0.35
=back
=head2 ANALYZING RESULTS
Please look at the pretty charts generated by the L<POE::Devel::Benchmarker::Imager> module.
=head1 EXPORT
Automatically exports the benchmark() subroutine.
=head1 TODO
=over 4
=item Perl version smoking
We should be able to run the benchmark over different Perl versions. This would require some fiddling with our
layout + logic. It's not that urgent because the workaround is to simply execute the benchmarker under a different
perl binary. It's smart enough to use $^X to be consistent across tests/subprocesses :)
=item Select the EV backend
<Khisanth> and if you are benchmarking, try it with POE using EV with EV using Glib? :P
<Apocalypse> I'm not sure how to configure the EV "backend" yet
<Apocalypse> too much docs for me to read hah
<Khisanth> Apocalypse: use EV::Glib; use Glib; use POE; :)
=item Be smarter in smoking timeouts
Currently we depend on the litetests option and hardcode some values including the timeout. If your machine is incredibly
slow, there's a chance that it could timeout unnecessarily. Please look at the outputs and check to see if there are unusual
failures, and inform me.
Also, some loops perform badly and take almost forever! /me glares at Gtk...
=item More benchmarks!
As usual, me and the crowd in #poe have plenty of ideas for tests. We'll be adding them over time, but if you have an idea please
drop me a line and let me know!
dngor said there was some benchmarks in the POE svn under trunk/queue...
I want a bench that actually tests socket traffic - stream 10MB of traffic over localhost, and time it?
LotR and Tapout contributed some samples, let's see if I can integrate them...
=item Add SQLite/DBI/etc support to the Analyzer
It would be nice if we could have a local SQLite db to dump our stats into. This would make arbitrary reports much easier than
loading raw YAML files and trying to make sense of them, ha! Also, this means somebody can do the smoking and send the SQLite
db to another person to generate the graphs, cool!
=item Kqueue loop support
As I don't have access to a *BSD box, I cannot really test this. Furthermore, it isn't clear on how I can force/unload this
module from POE...
=item Wx loop support
I have Wx installed, but it doesn't work. Obviously I don't know how to use Wx ;)
If you have experience, please drop me a line on how to do the "right" thing to get Wx loaded under POE. Here's the error:
Can't call method "MainLoop" on an undefined value at /usr/local/share/perl/5.8.8/POE/Loop/Wx.pm line 91.
=item XS::Loop support
The POE::XS::Loop::* modules theoretically could be tested too. However, they will only work in POE >= 1.003! This renders
the concept somewhat moot. Maybe, after POE has progressed some versions we can implement this...
=back
=head1 SEE ALSO
L<POE>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
BIG THANKS goes to Rocco Caputo E<lt>rcaputo@cpan.orgE<gt> for the first benchmarks!
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/Analyzer.pm b/lib/POE/Devel/Benchmarker/Analyzer.pm
index 66af13a..08bf7aa 100644
--- a/lib/POE/Devel/Benchmarker/Analyzer.pm
+++ b/lib/POE/Devel/Benchmarker/Analyzer.pm
@@ -1,458 +1,458 @@
# Declare our package
package POE::Devel::Benchmarker::Analyzer;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.04';
# auto-export the only sub we have
BEGIN {
require Exporter;
use vars qw( @ISA @EXPORT );
@ISA = qw(Exporter);
@EXPORT = qw( initAnalyzer );
}
# Import what we need from the POE namespace
use POE qw( Session );
use base 'POE::Session::AttributeBased';
# use the power of YAML
use YAML::Tiny qw( Dump );
# Load the utils
use POE::Devel::Benchmarker::Utils qw( beautify_times );
# fires up the engine
sub initAnalyzer {
my $quiet_mode = shift;
# create our session!
POE::Session->create(
__PACKAGE__->inline_states(),
'heap' => {
'quiet_mode' => $quiet_mode,
},
);
}
# Starts up our session
sub _start : State {
# set our alias
$_[KERNEL]->alias_set( 'Benchmarker::Analyzer' );
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[ANALYZER] Starting up...\n";
}
return;
}
sub _stop : State {
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[ANALYZER] Shutting down...\n";
}
return;
}
sub _child : State {
return;
}
sub analyze : State {
# get the data
my $test = $_[ARG0];
# clean up the times() stuff
- $test->{'times'} = beautify_times(
- join( " ", @{ delete $test->{'start_times'} } ) .
+ $test->{'t'}->{'t'} = beautify_times(
+ join( " ", @{ delete $test->{'t'}->{'s_t'} } ) .
" " .
- join( " ", @{ delete $test->{'end_times'} } )
+ join( " ", @{ delete $test->{'t'}->{'e_t'} } )
);
# setup the perl version
- $test->{'perlconfig'}->{'v'} = sprintf( "%vd", $^V );
+ $test->{'perl'}->{'v'} = sprintf( "%vd", $^V );
# Okay, break it down into our data struct
- $test->{'benchmark'} = {};
- my $d = $test->{'benchmark'};
+ $test->{'metrics'} = {};
+ my $d = $test->{'metrics'};
my @unknown;
- foreach my $l ( split( /(?:\n|\r)/, $test->{'rawdata'} ) ) {
+ foreach my $l ( split( /(?:\n|\r)/, $test->{'raw'} ) ) {
# skip empty lines
if ( $l eq '' ) { next }
# usual test benchmark output
# 10 startups in 0.885 seconds ( 11.302 per second)
# 10000 posts in 0.497 seconds ( 20101.112 per second)
- if ( $l =~ /^\s+(\d+)\s+(\w+)\s+in\s+([\d\.]+)\s+seconds\s+\(\s+([\d\.]+)\s+per\s+second\)$/ ) {
- $d->{ $2 }->{'loops'} = $1;
- $d->{ $2 }->{'time'} = $3;
- $d->{ $2 }->{'iterations_per_second'} = $4;
+ if ( $l =~ /^\s+\d+\s+(\w+)\s+in\s+([\d\.]+)\s+seconds\s+\(\s+([\d\.]+)\s+per\s+second\)$/ ) {
+ $d->{ $1 }->{'d'} = $2; # duration in seconds
+ $d->{ $1 }->{'i'} = $3; # iterations per second
# usual test benchmark times output
# startup times: 0.1 0 0 0 0.1 0 0.76 0.09
} elsif ( $l =~ /^(\w+)\s+times:\s+(.+)$/ ) {
- $d->{ $1 }->{'times'} = beautify_times( $2 );
+ $d->{ $1 }->{'t'} = beautify_times( $2 ); # the times hash
# parse the memory footprint stuff
} elsif ( $l =~ /^pidinfo:\s+(.+)$/ ) {
# what should we analyze?
my $pidinfo = $1;
# VmPeak: 16172 kB
if ( $pidinfo =~ /^VmPeak:\s+(.+)$/ ) {
- $test->{'pidinfo'}->{'vmpeak'} = $1;
+ $test->{'pid'}->{'vmpeak'} = $1;
# voluntary_ctxt_switches: 10
} elsif ( $pidinfo =~ /^voluntary_ctxt_switches:\s+(.+)$/ ) {
- $test->{'pidinfo'}->{'voluntary_ctxt'} = $1;
+ $test->{'pid'}->{'vol_ctxt'} = $1;
# nonvoluntary_ctxt_switches: 1221
} elsif ( $pidinfo =~ /^nonvoluntary_ctxt_switches:\s+(.+)$/ ) {
- $test->{'pidinfo'}->{'nonvoluntary_ctxt'} = $1;
+ $test->{'pid'}->{'nonvol_ctxt'} = $1;
} else {
# ignore the rest of the fluff
}
# parse the perl binary stuff
} elsif ( $l =~ /^perlconfig:\s+(.+)$/ ) {
# what should we analyze?
my $perlconfig = $1;
# Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
if ( $perlconfig =~ /^Summary\s+of\s+my\s+perl\d\s+\(([^\)]+)\)/ ) {
- $test->{'perlconfig'}->{'version'} = $1;
+ $test->{'perl'}->{'version'} = $1;
} else {
# ignore the rest of the fluff
}
# parse the CPU info
} elsif ( $l =~ /^cpuinfo:\s+(.+)$/ ) {
# what should we analyze?
my $cpuinfo = $1;
# FIXME if this is on a multiproc system, we will overwrite the data per processor ( harmless? )
# cpu MHz : 1201.000
if ( $cpuinfo =~ /^cpu\s+MHz\s+:\s+(.+)$/ ) {
- $test->{'cpuinfo'}->{'mhz'} = $1;
+ $test->{'cpu'}->{'mhz'} = $1;
# model name : Intel(R) Core(TM)2 Duo CPU L7100 @ 1.20GHz
} elsif ( $cpuinfo =~ /^model\s+name\s+:\s+(.+)$/ ) {
- $test->{'cpuinfo'}->{'name'} = $1;
+ $test->{'cpu'}->{'name'} = $1;
# bogomips : 2397.58
} elsif ( $cpuinfo =~ /^bogomips\s+:\s+(.+)$/ ) {
- $test->{'cpuinfo'}->{'bogomips'} = $1;
+ $test->{'cpu'}->{'bogo'} = $1;
} else {
# ignore the rest of the fluff
}
# data that we can safely throw away
} elsif ( $l eq 'Using NO Assertions!' or
$l eq 'Using FULL Assertions!' or
$l eq 'Using the LITE tests' or
$l eq 'Using the HEAVY tests' or
$l eq 'DISABLING POE::XS::Queue::Array' or
$l eq '!STDERR: Devel::Hide hides POE/XS/Queue/Array.pm' or
$l eq 'LETTING POE find POE::XS::Queue::Array' or
$l eq 'UNABLE TO GET /proc/self/status' or
$l eq 'UNABLE TO GET /proc/cpuinfo' or
$l eq '!STDERR: POE::Kernel\'s run() method was never called.' or # to ignore old POEs that threw this warning
$l eq 'TEST TERMINATED DUE TO TIMEOUT' ) {
# ignore them
# parse the perl binary stuff
} elsif ( $l =~ /^Running\s+under\s+perl\s+binary:\s+(.+)$/ ) {
- $test->{'perlconfig'}->{'binary'} = $1;
+ $test->{'perl'}->{'binary'} = $1;
# the master loop version ( what the POE::Loop::XYZ actually uses )
# Using loop: EV-3.49
} elsif ( $l =~ /^Using\s+master\s+loop:\s+(.+)$/ ) {
- $test->{'poe_loop_master'} = $1;
+ $test->{'poe'}->{'loop_m'} = $1;
# the real POE version that was loaded
# Using POE-1.001
} elsif ( $l =~ /^Using\s+POE-(.+)$/ ) {
- $test->{'poe_version_loaded'} = $1;
+ $test->{'poe'}->{'v_real'} = $1;
# the various queue/loop modules we loaded
# POE is using: POE::XS::Queue::Array v0.005
# POE is using: POE::Queue v1.2328
# POE is using: POE::Loop::EV v0.06
} elsif ( $l =~ /^POE\s+is\s+using:\s+([^\s]+)\s+v(.+)$/ ) {
- $test->{'poe_modules'}->{ $1 } = $2;
+ $test->{'poe'}->{'modules'}->{ $1 } = $2;
# get the uname info
# Running under machine: Linux apoc-x300 2.6.24-21-generic #1 SMP Tue Oct 21 23:43:45 UTC 2008 i686 GNU/Linux
} elsif ( $l =~ /^Running\s+under\s+machine:\s+(.+)$/ ) {
$test->{'uname'} = $1;
# parse the SKIP tests
# SKIPPING MYFH tests on broken loop: Event_Lib
# SKIPPING STDIN tests on broken loop: Tk
} elsif ( $l =~ /^SKIPPING\s+(\w+)\s+tests\s+on\s+broken/ ) {
my $fh = $1;
# nullify the data struct for that
foreach my $type ( qw( select_read select_write ) ) {
- $d->{ $type . $fh }->{'loops'} = undef;
- $d->{ $type . $fh }->{'time'} = undef;
- $d->{ $type . $fh }->{'times'} = undef;
- $d->{ $type . $fh }->{'iterations_per_second'} = undef;
+ $d->{ $type . $fh }->{'d'} = undef;
+ $d->{ $type . $fh }->{'t'} = undef;
+ $d->{ $type . $fh }->{'i'} = undef;
}
# parse the FH/STDIN failures
# filehandle select_read on STDIN FAILED: error
# filehandle select_write on MYFH FAILED: foo
} elsif ( $l =~ /^filehandle\s+(\w+)\s+on\s+(\w+)\s+FAILED:/ ) {
my( $mode, $type ) = ( $1, $2 );
# nullify the data struct for that
- $d->{ $mode . $type }->{'loops'} = undef;
- $d->{ $mode . $type }->{'time'} = undef;
- $d->{ $mode . $type }->{'times'} = undef;
- $d->{ $mode . $type }->{'iterations_per_second'} = undef;
+ $d->{ $mode . $type }->{'d'} = undef;
+ $d->{ $mode . $type }->{'t'} = undef;
+ $d->{ $mode . $type }->{'i'} = undef;
# parse the alarm_add skip
# alarm_add NOT SUPPORTED on this version of POE, skipping alarm_adds/alarm_clears tests!
} elsif ( $l =~ /^alarm_add\s+NOT\s+SUPPORTED\s+on/ ) {
# nullify the data struct for that
foreach my $type ( qw( alarm_adds alarm_clears ) ) {
- $d->{ $type }->{'loops'} = undef;
- $d->{ $type }->{'time'} = undef;
- $d->{ $type }->{'times'} = undef;
- $d->{ $type }->{'iterations_per_second'} = undef;
+ $d->{ $type }->{'d'} = undef;
+ $d->{ $type }->{'t'} = undef;
+ $d->{ $type }->{'i'} = undef;
}
# parse any STDERR output
# !STDERR: unable to foo
} elsif ( $l =~ /^\!STDERR:\s+(.+)$/ ) {
push( @{ $test->{'stderr'} }, $1 );
} else {
# unknown line :(
push( @unknown, $l );
}
}
# Get rid of the rawdata
- delete $test->{'rawdata'};
+ delete $test->{'raw'};
# Dump the unknowns
if ( @unknown ) {
print "[ANALYZER] Unknown output from benchmark -> " . Dump( \@unknown );
}
# Dump the data struct we have to the file.yml
- my $yaml_file = 'results/' . delete $test->{'test_file'};
+ my $yaml_file = 'results/' . delete $test->{'test'};
$yaml_file .= '.yml';
my $ret = open( my $fh, '>', $yaml_file );
if ( defined $ret ) {
print $fh Dump( $test );
if ( ! close( $fh ) ) {
print "[ANALYZER] Unable to close $yaml_file -> " . $! . "\n";
}
} else {
print "[ANALYZER] Unable to open $yaml_file for writing -> " . $! . "\n";
}
# all done!
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::Analyzer - Analyzes the output from the benchmarks
=head1 SYNOPSIS
Don't use this module directly. Please see L<POE::Devel::Benchmarker>
=head1 ABSTRACT
This package implements the guts of converting the raw data into a machine-readable format. Furthermore, it dumps the data
in YAML format.
+=head1 DESCRIPTION
+
+I promise you that once I've stabilized the YAML format I'll have it documented here :)
+
=head1 EXPORT
Automatically exports the initAnalyzer() sub
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
# sample test output ( from SubProcess v0.02 )
STARTTIME: 1229232743.49131 -> TIMES 0.24 0.01 11.2 0.32
POE-1.003-Select-LITE-assert-xsqueue
Using master loop: Select-BUILTIN
Using FULL Assertions!
Using the LITE tests
LETTING POE find POE::XS::Queue::Array
Using POE-1.003
POE is using: POE::Loop::Select v1.2355
POE is using: POE::XS::Queue::Array v0.005
POE is using: POE::Queue v1.2328
POE is using: POE::Loop::PerlSignals v1.2329
10 startups in 0.853 seconds ( 11.723 per second)
startups times: 0.09 0 0 0 0.09 0 0.73 0.11
10000 posts in 0.495 seconds ( 20211.935 per second)
posts times: 0.1 0 0.73 0.11 0.53 0.06 0.73 0.11
10000 dispatches in 1.113 seconds ( 8984.775 per second)
dispatches times: 0.53 0.06 0.73 0.11 1.64 0.06 0.73 0.11
10000 alarms in 1.017 seconds ( 9829.874 per second)
alarms times: 1.64 0.06 0.73 0.11 2.66 0.06 0.73 0.11
10000 alarm_adds in 0.523 seconds ( 19102.416 per second)
alarm_adds times: 2.66 0.06 0.73 0.11 3.18 0.06 0.73 0.11
10000 alarm_clears in 0.377 seconds ( 26540.332 per second)
alarm_clears times: 3.18 0.06 0.73 0.11 3.55 0.07 0.73 0.11
500 session_creates in 0.130 seconds ( 3858.918 per second)
session_creates times: 3.55 0.07 0.73 0.11 3.68 0.08 0.73 0.11
500 session_destroys in 0.172 seconds ( 2901.191 per second)
session_destroys times: 3.68 0.08 0.73 0.11 3.85 0.08 0.73 0.11
10000 select_read_STDIN in 1.823 seconds ( 5485.878 per second)
select_read_STDIN times: 3.85 0.08 0.73 0.11 5.66 0.08 0.73 0.11
10000 select_write_STDIN in 1.827 seconds ( 5472.283 per second)
select_write_STDIN times: 5.66 0.08 0.73 0.11 7.47 0.08 0.73 0.11
10000 select_read_MYFH in 1.662 seconds ( 6016.387 per second)
select_read_MYFH times: 7.47 0.08 0.73 0.11 9.12 0.1 0.73 0.11
10000 select_write_MYFH in 1.704 seconds ( 5868.537 per second)
select_write_MYFH times: 9.12 0.1 0.73 0.11 10.78 0.11 0.73 0.11
10000 calls in 0.222 seconds ( 45038.974 per second)
calls times: 10.78 0.11 0.73 0.11 11 0.11 0.73 0.11
10000 single_posts in 1.999 seconds ( 5003.473 per second)
single_posts times: 11 0.11 0.73 0.11 12.86 0.22 0.73 0.11
pidinfo: Name: perl
pidinfo: State: R (running)
pidinfo: Tgid: 16643
pidinfo: Pid: 16643
pidinfo: PPid: 16600
pidinfo: TracerPid: 0
pidinfo: Uid: 1000 1000 1000 1000
pidinfo: Gid: 1000 1000 1000 1000
pidinfo: FDSize: 32
pidinfo: Groups: 4 20 24 25 29 30 44 46 107 109 115 127 1000 1001
pidinfo: VmPeak: 14376 kB
pidinfo: VmSize: 14216 kB
pidinfo: VmLck: 0 kB
pidinfo: VmHWM: 11440 kB
pidinfo: VmRSS: 11292 kB
pidinfo: VmData: 9908 kB
pidinfo: VmStk: 84 kB
pidinfo: VmExe: 1044 kB
pidinfo: VmLib: 1872 kB
pidinfo: VmPTE: 24 kB
pidinfo: Threads: 1
pidinfo: SigQ: 0/16182
pidinfo: SigPnd: 0000000000000000
pidinfo: ShdPnd: 0000000000000000
pidinfo: SigBlk: 0000000000000000
pidinfo: SigIgn: 0000000000001000
pidinfo: SigCgt: 0000000180000000
pidinfo: CapInh: 0000000000000000
pidinfo: CapPrm: 0000000000000000
pidinfo: CapEff: 0000000000000000
pidinfo: Cpus_allowed: 03
pidinfo: Mems_allowed: 1
pidinfo: voluntary_ctxt_switches: 10
pidinfo: nonvoluntary_ctxt_switches: 512
Running under perl binary: /usr/bin/perl
perlconfig: Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
perlconfig: Platform:
perlconfig: osname=linux, osvers=2.6.15.7, archname=i486-linux-gnu-thread-multi
perlconfig: uname='linux palmer 2.6.15.7 #1 smp thu sep 7 19:42:20 utc 2006 i686 gnulinux '
perlconfig: config_args='-Dusethreads -Duselargefiles -Dccflags=-DDEBIAN -Dcccdlflags=-fPIC -Darchname=i486-linux-gnu -Dprefix=/usr -Dprivlib=/usr/share/perl/5.8 -Darchlib=/usr/lib/perl/5.8 -Dvendorprefix=/usr -Dvendorlib=/usr/share/perl5 -Dvendorarch=/usr/lib/perl5 -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl/5.8.8 -Dsitearch=/usr/local/lib/perl/5.8.8 -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 -Dsiteman1dir=/usr/local/man/man1 -Dsiteman3dir=/usr/local/man/man3 -Dman1ext=1 -Dman3ext=3perl -Dpager=/usr/bin/sensible-pager -Uafs -Ud_csh -Ud_ualarm -Uusesfio -Uusenm -Duseshrplib -Dlibperl=libperl.so.5.8.8 -Dd_dosuid -des'
perlconfig: hint=recommended, useposix=true, d_sigaction=define
perlconfig: usethreads=define use5005threads=undef useithreads=define usemultiplicity=define
perlconfig: useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
perlconfig: use64bitint=undef use64bitall=undef uselongdouble=undef
perlconfig: usemymalloc=n, bincompat5005=undef
perlconfig: Compiler:
perlconfig: cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBIAN -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
perlconfig: optimize='-O2',
perlconfig: cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBIAN -fno-strict-aliasing -pipe -I/usr/local/include'
perlconfig: ccversion='', gccversion='4.2.3 20071123 (prerelease) (Ubuntu 4.2.2-3ubuntu4)', gccosandvers=''
perlconfig: intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
perlconfig: d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
perlconfig: ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
perlconfig: alignbytes=4, prototype=define
perlconfig: Linker and Libraries:
perlconfig: ld='cc', ldflags =' -L/usr/local/lib'
perlconfig: libpth=/usr/local/lib /lib /usr/lib
perlconfig: libs=-lgdbm -lgdbm_compat -ldb -ldl -lm -lpthread -lc -lcrypt
perlconfig: perllibs=-ldl -lm -lpthread -lc -lcrypt
perlconfig: libc=/lib/libc-2.6.1.so, so=so, useshrplib=true, libperl=libperl.so.5.8.8
perlconfig: gnulibc_version='2.6.1'
perlconfig: Dynamic Linking:
perlconfig: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
perlconfig: cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib'
Running under machine: Linux apoc-x300 2.6.24-21-generic #1 SMP Tue Oct 21 23:43:45 UTC 2008 i686 GNU/Linux
cpuinfo: processor : 0
cpuinfo: vendor_id : GenuineIntel
cpuinfo: cpu family : 6
cpuinfo: model : 15
cpuinfo: model name : Intel(R) Core(TM)2 Duo CPU L7100 @ 1.20GHz
cpuinfo: stepping : 11
cpuinfo: cpu MHz : 1201.000
cpuinfo: cache size : 4096 KB
cpuinfo: physical id : 0
cpuinfo: siblings : 2
cpuinfo: core id : 0
cpuinfo: cpu cores : 2
cpuinfo: fdiv_bug : no
cpuinfo: hlt_bug : no
cpuinfo: f00f_bug : no
cpuinfo: coma_bug : no
cpuinfo: fpu : yes
cpuinfo: fpu_exception : yes
cpuinfo: cpuid level : 10
cpuinfo: wp : yes
cpuinfo: flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc arch_perfmon pebs bts pni monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr lahf_lm ida
cpuinfo: bogomips : 2397.58
cpuinfo: clflush size : 64
cpuinfo: processor : 1
cpuinfo: vendor_id : GenuineIntel
cpuinfo: cpu family : 6
cpuinfo: model : 15
cpuinfo: model name : Intel(R) Core(TM)2 Duo CPU L7100 @ 1.20GHz
cpuinfo: stepping : 11
cpuinfo: cpu MHz : 1201.000
cpuinfo: cache size : 4096 KB
cpuinfo: physical id : 0
cpuinfo: siblings : 2
cpuinfo: core id : 1
cpuinfo: cpu cores : 2
cpuinfo: fdiv_bug : no
cpuinfo: hlt_bug : no
cpuinfo: f00f_bug : no
cpuinfo: coma_bug : no
cpuinfo: fpu : yes
cpuinfo: fpu_exception : yes
cpuinfo: cpuid level : 10
cpuinfo: wp : yes
cpuinfo: flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc arch_perfmon pebs bts pni monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr lahf_lm ida
cpuinfo: bogomips : 2394.02
cpuinfo: clflush size : 64
ENDTIME: 1229232757.53804 -> TIMES 0.27 0.01 23.1 0.62
diff --git a/lib/POE/Devel/Benchmarker/Imager.pm b/lib/POE/Devel/Benchmarker/Imager.pm
index aa92df2..e5a2a29 100644
--- a/lib/POE/Devel/Benchmarker/Imager.pm
+++ b/lib/POE/Devel/Benchmarker/Imager.pm
@@ -1,165 +1,182 @@
# Declare our package
package POE::Devel::Benchmarker::Imager;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.04';
# auto-export the only sub we have
require Exporter;
use vars qw( @ISA @EXPORT );
@ISA = qw(Exporter);
@EXPORT = qw( imager );
# import the helper modules
use YAML::Tiny;
use Chart::Clicker;
use Chart::Clicker::Data::Series;
use Chart::Clicker::Data::DataSet;
# olds our data structure
my %data;
# debug or not?
my $debug = 0;
# starts the work of converting our data to images
sub imager {
# should we debug?
$debug = shift;
if ( $debug ) {
$debug = 1;
} else {
$debug = 0;
}
# some sanity tests
if ( ! -d 'results' ) {
die "The 'results' directory is not found in the working directory!";
}
if ( ! -d 'images' ) {
die "The 'images' directory is not found in the working directory!";
}
if ( $debug ) {
print "[IMAGER] Starting up...\n";
}
# parse all of our YAML modules!
parse_yaml();
# Do some processing of the data
process_data();
# generate the images!
generate_images();
+ # for now, we simply freeze up
+ sleep 30;
+
return;
}
# starts the process of loading all of our YAML images
sub parse_yaml {
# gather all the YAML dumps
my @versions;
if ( opendir( DUMPS, 'results' ) ) {
foreach my $d ( readdir( DUMPS ) ) {
if ( $d =~ /\.yml$/ ) {
push( @versions, $d );
}
}
closedir( DUMPS ) or die "[IMAGER] Unable to read from 'results' -> " . $!;
} else {
die "[IMAGER] Unable to open 'results' for reading -> " . $!;
}
# sanity
if ( ! scalar @versions ) {
die "[IMAGER] Unable to find any POE test result(s) in the 'results' directory!\n";
}
+ # FIXME allow selective loading of tests, so we can control what to image, etc
+
# Parse every one of them!
foreach my $v ( @versions ) {
load_yaml( "results/$v" );
}
+ if ( $debug ) {
+ print "[IMAGER] Done with parsing the YAML files...\n";
+ }
+
return;
}
# loads the yaml of a specific file
sub load_yaml {
my $file = shift;
my $yaml = YAML::Tiny->read( $file );
if ( ! defined $yaml ) {
die "[IMAGER] Unable to load YAML file $file -> " . YAML::Tiny->errstr . "\n";
} else {
# store it in the global hash
$data{ $file } = $yaml->[0];
}
return;
}
# mangles the data we've collected so far
sub process_data {
# FIXME okay what should we do?
+ if ( $debug ) {
+ print "[IMAGER] Done with processing the test statistics...\n";
+ }
+
return;
}
sub generate_images {
# FIXME okay what should we do?
+ if ( $debug ) {
+ print "[IMAGER] Done with generating images...\n";
+ }
+
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::Imager - Automatically converts the benchmark data into images
=head1 SYNOPSIS
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker::Imager -e 'imager()'
=head1 ABSTRACT
This package automatically parses the benchmark data and generates pretty charts.
=head1 DESCRIPTION
This package uses the excellent L<Chart::Clicker> module to generate the images
=head2 imager
Normally you should pass nothing to this sub. However, if you want to debug the processing you should pass a true
value as the first argument.
perl -MPOE::Devel::Benchmarker::Imager -e 'imager( 1 )'
=head1 EXPORT
Automatically exports the imager() sub
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
L<Chart::Clicker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/Utils.pm b/lib/POE/Devel/Benchmarker/Utils.pm
index 3c0cc64..191d70c 100644
--- a/lib/POE/Devel/Benchmarker/Utils.pm
+++ b/lib/POE/Devel/Benchmarker/Utils.pm
@@ -1,210 +1,211 @@
# Declare our package
package POE::Devel::Benchmarker::Utils;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.04';
# auto-export the only sub we have
require Exporter;
use vars qw( @ISA @EXPORT_OK );
@ISA = qw(Exporter);
@EXPORT_OK = qw( poeloop2load loop2realversion beautify_times knownloops generateTestfile );
# returns the filename for a particular test
sub generateTestfile {
my $heap = shift;
return 'POE-' . $heap->{'current_version'} .
'-' . $heap->{'current_loop'} .
'-' . ( $heap->{'lite_tests'} ? 'LITE' : 'HEAVY' ) .
'-' . ( $heap->{'current_assertions'} ? 'assert' : 'noassert' ) .
'-' . ( $heap->{'current_noxsqueue'} ? 'noxsqueue' : 'xsqueue' );
}
# returns the proper "load" stuff for a specific loop
sub poeloop2load {
my $eventloop = shift;
# Decide which event loop to use
# Event_Lib EV Glib Prima Gtk Wx Kqueue Tk Select IO_Poll
if ( $eventloop eq 'Event' ) {
return 'Event';
} elsif ( $eventloop eq 'IO_Poll' ) {
return 'IO::Poll';
} elsif ( $eventloop eq 'Event_Lib' ) {
return 'Event::Lib';
} elsif ( $eventloop eq 'EV' ) {
return 'EV';
} elsif ( $eventloop eq 'Glib' ) {
return 'Glib';
} elsif ( $eventloop eq 'Tk' ) {
return 'Tk',
} elsif ( $eventloop eq 'Gtk' ) {
return 'Gtk';
} elsif ( $eventloop eq 'Prima' ) {
return 'Prima';
} elsif ( $eventloop eq 'Wx' ) {
return 'Wx';
} elsif ( $eventloop eq 'Kqueue' ) {
# FIXME dunno what to do here!
return;
} elsif ( $eventloop eq 'Select' ) {
return;
} else {
die "Unknown event loop!";
}
}
# returns the version of the "real" installed module that the loop uses
sub loop2realversion {
my $eventloop = shift;
# Decide which event loop to use
if ( ! defined $eventloop ) {
return;
} elsif ( $eventloop eq 'Event' ) {
return $Event::VERSION;
} elsif ( $eventloop eq 'IO_Poll' ) {
return $IO::Poll::VERSION;
} elsif ( $eventloop eq 'Event_Lib' ) {
return $Event::Lib::VERSION;
} elsif ( $eventloop eq 'EV' ) {
return $EV::VERSION;
} elsif ( $eventloop eq 'Glib' ) {
return $Glib::VERSION;
} elsif ( $eventloop eq 'Tk' ) {
return $Tk::VERSION;
} elsif ( $eventloop eq 'Gtk' ) {
return $Gtk::VERSION;
} elsif ( $eventloop eq 'Prima' ) {
return $Prima::VERSION;
} elsif ( $eventloop eq 'Wx' ) {
return $Wx::VERSION;
} elsif ( $eventloop eq 'Kqueue' ) {
# FIXME how do I do this?
return;
} elsif ( $eventloop eq 'Select' ) {
return 'BUILTIN';
} else {
die "Unknown event loop!";
}
}
# helper routine to parse times() output
sub beautify_times {
my $string = shift;
my $origdata = shift;
# split it up
$string =~ s/^\s+//; $string =~ s/\s+$//;
my @times = split( /\s+/, $string );
# make the data struct
# ($user,$system,$cuser,$csystem) = times;
my $data = {
- 'user' => $times[4] - $times[0],
- 'sys' => $times[5] - $times[1],
- 'cuser' => $times[6] - $times[2],
- 'csys' => $times[7] - $times[3],
+ 'u' => $times[4] - $times[0],
+ 's' => $times[5] - $times[1],
+ 'cu' => $times[6] - $times[2],
+ 'cs' => $times[7] - $times[3],
};
# add original data?
if ( $origdata ) {
$data->{'s_user'} = $times[0];
$data->{'s_sys'} = $times[1];
$data->{'s_cuser'} = $times[2];
$data->{'s_csys'} = $times[3];
$data->{'e_user'} = $times[4];
$data->{'e_sys'} = $times[5];
$data->{'e_cuser'} = $times[6];
$data->{'e_csys'} = $times[7];
}
# send it back!
return $data;
}
# returns a list of "known" POE loops
sub knownloops {
- return [ qw( Event_Lib EV Glib Prima Gtk Wx Kqueue Tk Select IO_Poll ) ];
+ # FIXME we remove Wx because I suck.
+ return [ qw( Event_Lib EV Glib Prima Gtk Kqueue Tk Select IO_Poll ) ];
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::Utils - Various utility routines for POE::Devel::Benchmarker
=head1 SYNOPSIS
perl -MPOE::Devel::Benchmarker::Utils -e 'print poeloop2load( "IO_Poll" )'
=head1 ABSTRACT
This package contains the utility routines and constants that POE::Devel::Benchmarker needs.
=head1 EXPORT
This package exports those subs via @EXPORT_OK:
=over 4
=item knownloops()
Returns an arrayref of the "known" POE loops as of this version of the Benchmarker
=item poeloop2load()
Returns the "parent" class to load for a specific loop. An example is:
$real = poeloop2load( 'IO_Poll' ); # $real now contains "IO::Poll"
=item loop2realversion()
Returns the version of the "parent" class for a specific loop. An example is:
$ver = loop2realversion( 'IO_Poll' ); # $ver now contains $IO::Poll::VERSION
=item beautify_times()
Returns a hashref of data from parsing 2 consecutive times() structures in a string. You can pass an additional parameter
( boolean ) to include the original data. An example is:
print Data::Dumper::Dumper( beautify_times( '0.1 0 0 0 0.1 0 0.76 0.09', 1 ) );
{
"sys" => 0, # total system time
"user" => 0, # total user time
"csys" => 0.76 # total children system time
"cuser" => 0.08 # total children user time
"e_csys" => "0.09", # end children system time ( optional )
"e_cuser" => "0.76", # end children user time ( optional )
"e_sys" => 0, # end system time ( optional )
"e_user" => "0.1", # end user time ( optional )
"s_csys" => 0, # start children system time ( optional )
"s_cuser" => 0, # start children user time ( optional )
"s_sys" => 0, # start system time ( optional )
"s_user" => "0.1" # start user time ( optional )
}
=back
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
|
apocalypse/perl-poe-benchmarker
|
8213f1b94fb9ab69b2288f077f2aaee807940492
|
start of work on Imager
|
diff --git a/Build.PL b/Build.PL
index ac7ac95..9758a94 100755
--- a/Build.PL
+++ b/Build.PL
@@ -1,97 +1,100 @@
# Build.PL
use Module::Build;
my $build = Module::Build->new(
# look up Module::Build::API for the info!
'dynamic_config' => 0,
'module_name' => 'POE::Devel::Benchmarker',
'license' => 'perl',
'dist_abstract' => "Benchmarking POE's performance ( acts more like a smoker )",
'dist_author' => 'Apocalypse <APOCAL@cpan.org>',
'create_packlist' => 1,
'create_makefile_pl' => 'traditional',
'create_readme' => 1,
'test_files' => 't/*.t',
'add_to_cleanup' => [ 'META.yml', 'Makefile.PL', 'README' ], # automatically generated
'requires' => {
# POE Stuff
'POE' => 0,
'POE::Session::AttributeBased' => 0,
# misc perl stuff
'Time::HiRes' => 0,
'version' => 0,
'Devel::Hide' => 0,
# Analyzer reqs
'YAML::Tiny' => 0,
#'POE::Component::SimpleDBI' => 0,
# GetPOEdists reqs
'LWP::UserAgent' => 0,
'HTML::LinkExtor' => 0,
'URI::URL' => 0,
'Archive::Tar' => 0,
+
+ # Imager reqs
+ 'Chart::Clicker' => 0,
},
'recommends' => {
# Test stuff
'Test::More' => '0.86', # require latest for note() support in t/a_is_prereq_outdated.t
# our POE loops!
'POE::Loop::Event' => 0,
'POE::Loop::Event_Lib' => 0,
'POE::Loop::EV' => 0,
'POE::Loop::Glib' => 0,
'POE::Loop::Prima' => 0,
'POE::Loop::Gtk' => 0,
'POE::Loop::Wx' => 0,
'POE::Loop::Kqueue' => 0,
# included in POE ( listed here for completeness )
#'POE::Loop::Tk' => 0,
#'POE::Loop::Select' => 0,
#'POE::Loop::IO_Poll' => 0,
# the loops' dependencies
'Event' => 0,
'Event::Lib' => 0,
'EV' => 0,
'Glib' => 0,
'Prima' => 0,
'Gtk' => 0,
'Wx' => 0,
'Tk' => 0,
# the XS queue
'POE::XS::Queue::Array' => 0,
},
# FIXME wishlist...
# 'test_requires' => {
# # Test stuff
# 'Test::Compile' => 0,
# 'Test::Perl::Critic' => 0,
# 'Test::Dependencies' => 0,
# 'Test::Distribution' => 0,
# 'Test::Fixme' => 0,
# 'Test::HasVersion' => 0,
# 'Test::Kwalitee' => 0,
# 'Test::CheckManifest' => 0,
# 'Test::MinimumVersion' => 0,
# 'Test::Pod::Coverage' => 0,
# 'Test::Spelling' => 0,
# 'Test::Pod' => 0,
# 'Test::Prereq' => 0,
# 'Test::Strict' => 0,
# 'Test::UseAllModules' => 0,
# },
);
# all done!
$build->create_build_script;
diff --git a/Changes b/Changes
index f769f3b..9e9e474 100755
--- a/Changes
+++ b/Changes
@@ -1,21 +1,28 @@
Revision history for Perl extension POE::Devel::Benchmarker
+* 0.04
+
+ Started work on the image generator ( Imager )
+ Added automatic "pick up where we left off" to the benchmarker
+ Added the freshstart option to benchmark()
+ Tweaked the GetPOEdists sub so it will work in the "work directory" and in the poedists dir
+
* 0.03
Added the loop option to benchmark(), thanks dngor!
Added the poe option to benchmark(), thanks dngor!
Added the noxsqueue option to benchmark()
Added the noasserts option to benchmark()
Automatically enable noxsqueue option if we cannot load POE::XS::Queue::Array, saving time
Bump Test::More version requirement because some people reported failures with note()
Fixed bug in SubProcess where it crashed on old POEs that didn't load IO::Handle
More documentation additions/tweaks
* 0.02
Added the Analyzer module ( and dump YAML files, yay! )
A lot of minor changes+tweaks to get a better dump format
* 0.01
initial release
diff --git a/MANIFEST b/MANIFEST
index 1116983..bb66c92 100755
--- a/MANIFEST
+++ b/MANIFEST
@@ -1,34 +1,35 @@
Makefile.PL
Build.PL
MANIFEST
MANIFEST.SKIP
README
lib/POE/Devel/Benchmarker.pm
lib/POE/Devel/Benchmarker/GetInstalledLoops.pm
lib/POE/Devel/Benchmarker/GetPOEdists.pm
lib/POE/Devel/Benchmarker/SubProcess.pm
lib/POE/Devel/Benchmarker/Utils.pm
lib/POE/Devel/Benchmarker/Analyzer.pm
+lib/POE/Devel/Benchmarker/Imager.pm
META.yml
Changes
t/1_load.t
t/a_critic.t
t/a_kwalitee.t
t/a_pod.t
t/a_pod_spelling.t
t/a_pod_coverage.t
t/a_strict.t
t/a_hasversion.t
t/a_minimumversion.t
t/a_manifest.t
t/a_distribution.t
t/a_compile.t
t/a_dependencies.t
t/a_fixme.t
t/a_prereq.t
t/a_prereq_build.t
t/a_dosnewline.t
t/a_perlmetrics.t
t/a_is_prereq_outdated.t
diff --git a/lib/POE/Devel/Benchmarker.pm b/lib/POE/Devel/Benchmarker.pm
index f2fd8a3..6fbbdc0 100644
--- a/lib/POE/Devel/Benchmarker.pm
+++ b/lib/POE/Devel/Benchmarker.pm
@@ -1,840 +1,884 @@
# Declare our package
package POE::Devel::Benchmarker;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
-$VERSION = '0.03';
+$VERSION = '0.04';
# auto-export the only sub we have
BEGIN {
require Exporter;
use vars qw( @ISA @EXPORT );
@ISA = qw(Exporter);
@EXPORT = qw( benchmark );
}
# Import what we need from the POE namespace
sub POE::Kernel::ASSERT_DEFAULT { 1 }
sub POE::Session::ASSERT_DEFAULT { 1 }
use POE qw( Session Filter::Line Wheel::Run );
use base 'POE::Session::AttributeBased';
# we need hires times
use Time::HiRes qw( time );
# load comparison stuff
use version;
+# use the power of YAML
+use YAML::Tiny;
+
# Load our stuff
use POE::Devel::Benchmarker::GetInstalledLoops;
-use POE::Devel::Benchmarker::Utils qw( poeloop2load knownloops );
+use POE::Devel::Benchmarker::Utils qw( poeloop2load knownloops generateTestfile );
use POE::Devel::Benchmarker::Analyzer;
# Actually run the tests!
sub benchmark {
my $options = shift;
# set default options
my $lite_tests = 1;
my $quiet_mode = 0;
my $forceloops = undef; # default to autoprobe all
my $forcepoe = undef; # default to all found POE versions in poedists/
my $forcenoxsqueue = 0; # default to try and load it
my $forcenoasserts = 0; # default is to run it
+ my $freshstart = 0; # always resume where we left off
# process our options
if ( defined $options and ref $options and ref( $options ) eq 'HASH' ) {
+ # process YES for freshstart
+ if ( exists $options->{'freshstart'} ) {
+ if ( $options->{'freshstart'} ) {
+ $freshstart = 1;
+ }
+ }
+
# process NO for XS::Queue::Array
if ( exists $options->{'noxsqueue'} ) {
if ( $options->{'noxsqueue'} ) {
$forcenoxsqueue = 1;
}
}
# process NO for ASSERT
if ( exists $options->{'noasserts'} ) {
if ( $options->{'noasserts'} ) {
$forcenoasserts = 1;
}
}
# process LITE tests
if ( exists $options->{'litetests'} ) {
if ( $options->{'litetests'} ) {
$lite_tests = 1;
} else {
$lite_tests = 0;
}
}
# process quiet mode
if ( exists $options->{'quiet'} ) {
if ( $options->{'quiet'} ) {
$quiet_mode = 1;
} else {
$quiet_mode = 0;
}
}
# process forceloops
if ( exists $options->{'loop'} and defined $options->{'loop'} ) {
if ( ! ref $options->{'loop'} ) {
# split it via CSV
$forceloops = [ split( /,/, $options->{'loop'} ) ];
foreach ( @$forceloops ) {
$_ =~ s/^\s+//; $_ =~ s/\s+$//;
}
} else {
# treat it as array
$forceloops = $options->{'loop'};
}
# check for !loop modules
my @noloops;
foreach my $l ( @$forceloops ) {
if ( $l =~ /^\!/ ) {
push( @noloops, substr( $l, 1 ) );
}
}
if ( scalar @noloops ) {
# replace the forceloops with ALL known, then subtract noloops from it
my %bad;
@bad{@noloops} = () x @noloops;
@$forceloops = grep { !exists $bad{$_} } @{ knownloops() };
}
}
# process the poe versions
if ( exists $options->{'poe'} and defined $options->{'poe'} ) {
if ( ! ref $options->{'poe'} ) {
# split it via CSV
$forcepoe = [ split( /,/, $options->{'poe'} ) ];
foreach ( @$forcepoe ) {
$_ =~ s/^\s+//; $_ =~ s/\s+$//;
}
} else {
# treat it as array
$forcepoe = $options->{'poe'};
}
}
}
# do some sanity checks
if ( ! -d 'poedists' ) {
die "The 'poedists' directory is not found in the working directory!";
}
if ( ! -d 'results' ) {
die "The 'results' directory is not found in the working directory!";
}
if ( ! $quiet_mode ) {
print "[BENCHMARKER] Starting up...\n";
}
# Create our session
POE::Session->create(
__PACKAGE__->inline_states(),
'heap' => {
# misc stuff
'quiet_mode' => $quiet_mode,
# override our testing behavior
'lite_tests' => $lite_tests,
'forceloops' => $forceloops,
'forcepoe' => $forcepoe,
'forcenoxsqueue' => $forcenoxsqueue,
'forcenoasserts' => $forcenoasserts,
+ 'freshstart' => $freshstart,
},
);
# Fire 'er up!
POE::Kernel->run();
return;
}
# Starts up our session
sub _start : State {
# okay, get all the dists we can!
my @versions;
if ( opendir( DISTS, 'poedists' ) ) {
foreach my $d ( readdir( DISTS ) ) {
if ( $d =~ /^POE\-(.+)$/ and $d !~ /\.tar\.gz$/ ) {
push( @versions, $1 );
}
}
closedir( DISTS ) or die $!;
} else {
print "[BENCHMARKER] Unable to open 'poedists' for reading: $!\n";
return;
}
# sanity
if ( ! scalar @versions ) {
print "[BENCHMARKER] Unable to find any POE version in the 'poedists' directory!\n";
return;
}
# should we munge the versions list?
if ( defined $_[HEAP]->{'forcepoe'} ) {
# check for !poe versions
my @nopoe;
foreach my $p ( @{ $_[HEAP]->{'forcepoe'} } ) {
if ( $p =~ /^\!/ ) {
push( @nopoe, substr( $p, 1 ) );
}
}
if ( scalar @nopoe ) {
# remove the nopoe versions from the found
my %bad;
@bad{@nopoe} = () x @nopoe;
@versions = grep { !exists $bad{$_} } @versions;
} else {
# make sure the @versions contains only what we specified
my %good;
@good{ @{ $_[HEAP]->{'forcepoe'} } } = () x @{ $_[HEAP]->{'forcepoe'} };
@versions = grep { exists $good{$_} } @versions;
}
# again, make sure we have at least a version, ha!
if ( ! scalar @versions ) {
print "[BENCHMARKER] Unable to find any POE version in the 'poedists' directory!\n";
return;
}
}
# set our alias
$_[KERNEL]->alias_set( 'Benchmarker' );
# sanely handle some signals
$_[KERNEL]->sig( 'INT', 'handle_kill' );
$_[KERNEL]->sig( 'TERM', 'handle_kill' );
# okay, go through all the dists in version order
@versions = sort { $b <=> $a }
map { version->new( $_ ) } @versions;
# Store the versions in our heap
$_[HEAP]->{'VERSIONS'} = \@versions;
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Detected available POE versions -> " . join( " ", @versions ) . "\n";
}
# First of all, we need to find out what loop libraries are installed
getPOEloops( $_[HEAP]->{'quiet_mode'}, $_[HEAP]->{'forceloops'} );
return;
}
sub _stop : State {
# tell the wheel to kill itself
if ( defined $_[HEAP]->{'WHEEL'} ) {
$_[HEAP]->{'WHEEL'}->kill( 9 );
undef $_[HEAP]->{'WHEEL'};
}
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Shutting down...\n";
}
return;
}
# misc POE handlers
sub _child : State {
return;
}
sub handle_kill : State {
return;
}
# we received list of loops from GetInstalledLoops
sub found_loops : State {
$_[HEAP]->{'installed_loops'} = [ sort { $a cmp $b } @{ $_[ARG0] } ];
# sanity check
if ( scalar @{ $_[HEAP]->{'installed_loops'} } == 0 ) {
print "[BENCHMARKER] Detected no available POE::Loop, check your configuration?!?\n";
return;
}
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Detected available POE::Loops -> " . join( " ", @{ $_[HEAP]->{'installed_loops'} } ) . "\n";
}
# Okay, do we have XS::Queue installed?
if ( ! $_[HEAP]->{'forcenoxsqueue'} ) {
eval { require POE::XS::Queue::Array };
if ( $@ ) {
$_[HEAP]->{'forcenoxsqueue'} = 1;
}
}
# Fire up the analyzer
initAnalyzer( $_[HEAP]->{'quiet_mode'} );
# start the benchmark!
$_[KERNEL]->yield( 'run_benchmark' );
return;
}
# Runs one benchmark
sub run_benchmark : State {
# Grab the version from the top of the array
$_[HEAP]->{'current_version'} = shift @{ $_[HEAP]->{'VERSIONS'} };
# did we run out of versions?
if ( ! defined $_[HEAP]->{'current_version'} ) {
# We're done, let POE die...
$_[KERNEL]->alias_remove( 'Benchmarker' );
} else {
$_[HEAP]->{'loops'} = [ @{ $_[HEAP]->{'installed_loops'} } ];
# okay, fire off the first loop
$_[KERNEL]->yield( 'bench_loop' );
}
return;
}
# runs one loop
sub bench_loop : State {
# select our current loop
$_[HEAP]->{'current_loop'} = shift @{ $_[HEAP]->{'loops'} };
# are we done with all loops?
if ( ! defined $_[HEAP]->{'current_loop'} ) {
# yay, go back to the main handler
$_[KERNEL]->yield( 'run_benchmark' );
} else {
# Start the assert test
if ( $_[HEAP]->{'forcenoasserts'} ) {
$_[HEAP]->{'assertions'} = [ qw( 0 ) ];
} else {
$_[HEAP]->{'assertions'} = [ qw( 0 1 ) ];
}
$_[KERNEL]->yield( 'bench_asserts' );
}
return;
}
# runs an assertion
sub bench_asserts : State {
# select our current assert state
$_[HEAP]->{'current_assertions'} = shift @{ $_[HEAP]->{'assertions'} };
# are we done?
if ( ! defined $_[HEAP]->{'current_assertions'} ) {
# yay, go back to the loop handler
$_[KERNEL]->yield( 'bench_loop' );
} else {
# Start the xsqueue test
if ( $_[HEAP]->{'forcenoxsqueue'} ) {
$_[HEAP]->{'noxsqueue'} = [ qw( 1 ) ];
} else {
$_[HEAP]->{'noxsqueue'} = [ qw( 0 1 ) ];
}
$_[KERNEL]->yield( 'bench_xsqueue' );
}
return;
}
# runs test with or without xsqueue
sub bench_xsqueue : State {
# select our current noxsqueue state
$_[HEAP]->{'current_noxsqueue'} = shift @{ $_[HEAP]->{'noxsqueue'} };
# are we done?
if ( ! defined $_[HEAP]->{'current_noxsqueue'} ) {
# yay, go back to the assert handler
$_[KERNEL]->yield( 'bench_asserts' );
} else {
- # actually fire off the subprocess, ha!
- $_[KERNEL]->yield( 'create_subprocess' );
+ # do some careful analysis
+ $_[KERNEL]->yield( 'bench_checkprevioustest' );
+ }
+
+ return;
+}
+
+# Checks to see if this test was run in the past
+sub bench_checkprevioustest : State {
+ # okay, do we need to check and see if we already did this test?
+ if ( ! $_[HEAP]->{'freshstart'} ) {
+ # determine the file used
+ my $file = generateTestfile( $_[HEAP] );
+
+ # does it exist?
+ if ( -e "results/$file.yml" and -f _ and -s _ ) {
+ # okay, sanity check it
+ my $yaml = YAML::Tiny->read( "results/$file.yml" );
+ if ( defined $yaml ) {
+ # inrospect it!
+ my $isvalid = 0;
+ eval {
+ # the version must at least match us
+ $isvalid = ( $yaml->[0]->{'benchmarker'} eq $POE::Devel::Benchmarker::VERSION ? 1 : 0 );
+ if ( $isvalid ) {
+ # simple sanity check: the "uname" param is at the end of the YML, so if it loads fine we know it's there
+ if ( ! exists $yaml->[0]->{'uname'} ) {
+ $isvalid = undef;
+ }
+ }
+ };
+ if ( $isvalid ) {
+ # yay, this test is A-OK!
+ $_[KERNEL]->yield( 'bench_xsqueue' );
+ return;
+ } else {
+ # was it truncated?
+ if ( ! defined $isvalid ) {
+ if ( ! $_[HEAP]->{'quiet_mode'} ) {
+ print "[BENCHMARKER] YAML file($file) from previous test was corrupt!\n";
+ }
+ }
+ }
+ } else {
+ if ( ! $_[HEAP]->{'quiet_mode'} ) {
+ print "[BENCHMARKER] Unable to load YAML file($file) from previous test run: " . YAML::Tiny->errstr . "\n";
+ }
+ }
+ }
}
+ # could not find previous file or FRESHSTART, proceed normally
+ $_[KERNEL]->yield( 'create_subprocess' );
+
return;
}
# actually runs the subprocess
sub create_subprocess : State {
# Okay, start testing this specific combo!
if ( ! $_[HEAP]->{'quiet_mode'} ) {
- print "Testing POE v" . $_[HEAP]->{'current_version'} .
- " loop(" . $_[HEAP]->{'current_loop'} . ')' .
- " assertions(" . ( $_[HEAP]->{'current_assertions'} ? 'ENABLED' : 'DISABLED' ) . ')' .
- " xsqueue(" . ( $_[HEAP]->{'current_noxsqueue'} ? 'DISABLED' : 'ENABLED' ) . ')' .
- "\n";
+ print "Testing " . generateTestfile( $_[HEAP] ) . "\n";
}
# save the starttime
$_[HEAP]->{'current_starttime'} = time();
$_[HEAP]->{'current_starttimes'} = [ times() ];
# Okay, create the wheel::run to handle this
my $looploader = poeloop2load( $_[HEAP]->{'current_loop'} );
$_[HEAP]->{'WHEEL'} = POE::Wheel::Run->new(
'Program' => $^X,
'ProgramArgs' => [ '-Ipoedists/POE-' . $_[HEAP]->{'current_version'},
'-Ipoedists/POE-' . $_[HEAP]->{'current_version'} . '/lib',
( defined $looploader ? "-M$looploader" : () ),
'-MPOE::Devel::Benchmarker::SubProcess',
'-e',
'POE::Devel::Benchmarker::SubProcess::benchmark',
$_[HEAP]->{'current_version'},
$_[HEAP]->{'current_loop'},
$_[HEAP]->{'current_assertions'},
$_[HEAP]->{'lite_tests'},
$_[HEAP]->{'current_noxsqueue'},
],
# Kill off existing FD's
'CloseOnCall' => 1,
# setup our data handlers
'StdoutEvent' => 'Got_STDOUT',
'StderrEvent' => 'Got_STDERR',
# the error handler
'ErrorEvent' => 'Got_ERROR',
'CloseEvent' => 'Got_CLOSED',
# set our filters
'StderrFilter' => POE::Filter::Line->new(),
'StdoutFilter' => POE::Filter::Line->new(),
);
if ( ! defined $_[HEAP]->{'WHEEL'} ) {
die 'Unable to create a new wheel!';
} else {
# smart CHLD handling
if ( $_[KERNEL]->can( "sig_child" ) ) {
$_[KERNEL]->sig_child( $_[HEAP]->{'WHEEL'}->PID => 'Got_CHLD' );
} else {
$_[KERNEL]->sig( 'CHLD', 'Got_CHLD' );
}
}
# setup our data we received from the subprocess
$_[HEAP]->{'current_data'} = '';
# Okay, we timeout this test after some time for sanity
$_[HEAP]->{'test_timedout'} = 0;
if ( $_[HEAP]->{'lite_tests'} ) {
# on my core2duo 1.2ghz laptop, running Gtk+LITE+assert+noxsqueue takes approx 45s
$_[HEAP]->{'TIMER'} = $_[KERNEL]->delay_set( 'test_timedout' => 60 * 2 );
} else {
# on my core2duo 1.2ghz laptop, running Gtk+HEAVY+assert+noxsqueue takes all day long :(
$_[HEAP]->{'TIMER'} = $_[KERNEL]->delay_set( 'test_timedout' => 60 * 15 );
}
return;
}
# Got a CHLD event!
sub Got_CHLD : State {
$_[KERNEL]->sig_handled();
return;
}
# Handles child STDERR output
sub Got_STDERR : State {
my $input = $_[ARG0];
# save it!
$_[HEAP]->{'current_data'} .= '!STDERR: ' . $input . "\n";
return;
}
# Handles child STDOUT output
sub Got_STDOUT : State {
my $input = $_[ARG0];
# save it!
$_[HEAP]->{'current_data'} .= $input . "\n";
return;
}
# Handles child error
sub Got_ERROR : State {
# Copied from POE::Wheel::Run manpage
my ( $operation, $errnum, $errstr ) = @_[ ARG0 .. ARG2 ];
# ignore exit 0 errors
if ( $errnum != 0 ) {
print "[BENCHMARKER] Wheel::Run got an $operation error $errnum: $errstr\n";
}
return;
}
# Handles child DIE'ing
sub Got_CLOSED : State {
# Get rid of the wheel
undef $_[HEAP]->{'WHEEL'};
# get rid of the delay
$_[KERNEL]->alarm_remove( $_[HEAP]->{'TIMER'} );
undef $_[HEAP]->{'TIMER'};
# wrap up this test
$_[KERNEL]->yield( 'wrapup_test' );
return;
}
# a test timed out, unfortunately!
sub test_timedout : State {
# tell the wheel to kill itself
$_[HEAP]->{'WHEEL'}->kill( 9 );
undef $_[HEAP]->{'WHEEL'};
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Test Timed Out!\n";
}
$_[HEAP]->{'test_timedout'} = 1;
# wrap up this test
$_[KERNEL]->yield( 'wrapup_test' );
return;
}
# finalizes a test
sub wrapup_test : State {
# we're done with this benchmark!
$_[HEAP]->{'current_endtime'} = time();
$_[HEAP]->{'current_endtimes'} = [ times() ];
# store the data
- my $file = 'POE-' . $_[HEAP]->{'current_version'} .
- '-' . $_[HEAP]->{'current_loop'} .
- ( $_[HEAP]->{'current_assertions'} ? '-assert' : '-noassert' ) .
- ( $_[HEAP]->{'current_noxsqueue'} ? '-noxsqueue' : '-xsqueue' );
-
+ my $file = generateTestfile( $_[HEAP] );
if ( open( my $fh, '>', "results/$file" ) ) {
print $fh "STARTTIME: " . $_[HEAP]->{'current_starttime'} . " -> TIMES " . join( " ", @{ $_[HEAP]->{'current_starttimes'} } ) . "\n";
print $fh "$file\n";
print $fh $_[HEAP]->{'current_data'} . "\n";
if ( $_[HEAP]->{'test_timedout'} ) {
print $fh "\nTEST TERMINATED DUE TO TIMEOUT\n";
}
print $fh "ENDTIME: " . $_[HEAP]->{'current_endtime'} . " -> TIMES " . join( " ", @{ $_[HEAP]->{'current_endtimes'} } ) . "\n";
close( $fh ) or die $!;
} else {
print "[BENCHMARKER] Unable to open results/$file for writing -> $!\n";
}
# Send the data to the Analyzer to process
$_[KERNEL]->post( 'Benchmarker::Analyzer', 'analyze', {
'poe_version' => $_[HEAP]->{'current_version'}->stringify, # YAML::Tiny doesn't like version objects :(
'poe_loop' => 'POE::Loop::' . $_[HEAP]->{'current_loop'},
'asserts' => $_[HEAP]->{'current_assertions'},
'noxsqueue' => $_[HEAP]->{'current_noxsqueue'},
'litetests' => $_[HEAP]->{'lite_tests'},
'start_time' => $_[HEAP]->{'current_starttime'},
'start_times' => [ @{ $_[HEAP]->{'current_starttimes'} } ],
'end_time' => $_[HEAP]->{'current_endtime'},
'end_times' => [ @{ $_[HEAP]->{'current_endtimes'} } ],
'timedout' => $_[HEAP]->{'test_timedout'},
'rawdata' => $_[HEAP]->{'current_data'},
'test_file' => $file,
+ 'benchmarker' => $POE::Devel::Benchmarker::VERSION,
} );
# process the next test
$_[KERNEL]->yield( 'bench_xsqueue' );
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker - Benchmarking POE's performance ( acts more like a smoker )
=head1 SYNOPSIS
- perl -MPOE::Devel::Benchmarker -e 'benchmark()'
+ apoc@apoc-x300:~$ cd poe-benchmarker
+ apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker -e 'benchmark()'
=head1 ABSTRACT
This package of tools is designed to benchmark POE's performace across different
configurations. The current "tests" are:
=over 4
=item posts
This tests how long it takes to post() N times
This tests how long it took to dispatch/deliver all the posts enqueued in the post() test
This tests how long it took to yield() between 2 states for N times
=item calls
This tests how long it took to call() N times
=item alarms
This tests how long it took to add N alarms via alarm(), overwriting each other
This tests how long it took to add N alarms via alarm_add() and how long it took to delete them all
NOTE: alarm_add is not available on all versions of POE!
=item sessions
This tests how long it took to create N sessions, and how long it took to destroy them all
=item filehandles
This tests how long it took to toggle select_read N times on STDIN and a real filehandle via open()
This tests how long it took to toggle select_write N times on STDIN and a real filehandle via open()
=item POE startup time
This tests how long it took to start + close N instances of a "virgin" POE without any sessions/etc
=item POE Loops
This is actually a "super" test where all of the specific tests is ran against various POE::Loop::XYZ/FOO for comparison
=item POE Assertions
This is actually a "super" test where all of the specific tests is ran against POE with/without assertions enabled
=item POE::XS::Queue::Array
This is actually a "super" test where all of the specific tests is ran against POE with XS goodness enabled/disabled
=back
=head1 DESCRIPTION
This module is poorly documented now. Please give me some time to properly document it over time :)
=head2 INSTALLATION
Here's a simple outline to get you up to speed quickly. ( and smoking! )
=over 4
=item Install CPAN package + dependencies
Download+install the POE::Devel::Benchmarker package from CPAN
apoc@apoc-x300:~$ cpanp -i POE::Devel::Benchmarker
=item Setup initial directories
Go anywhere, and create the "parent" directory where you'll be storing test results + stuff. For this example,
I have chosen to use ~/poe-benchmarker:
apoc@apoc-x300:~$ mkdir poe-benchmarker
apoc@apoc-x300:~$ cd poe-benchmarker
- apoc@apoc-x300:~/poe-benchmarker$ mkdir poedists
- apoc@apoc-x300:~/poe-benchmarker$ mkdir results
- apoc@apoc-x300:~/poe-benchmarker$ cd poedists/
- apoc@apoc-x300:~/poe-benchmarker/poedists$ perl -MPOE::Devel::Benchmarker::GetPOEdists -e 'getPOEdists( 1 )'
+ apoc@apoc-x300:~/poe-benchmarker$ mkdir poedists results images
+ apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker::GetPOEdists -e 'getPOEdists( 1 )'
( go get a coffee while it downloads if you're on a slow link, ha! )
=item Let 'er rip!
At this point you can start running the benchmark!
NOTE: the Benchmarker expects everything to be in the "local" directory!
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker -e 'benchmark()'
( go sleep or something, this will take a while! )
=back
=head2 BENCHMARKING
On startup the Benchmarker will look in the "poedists" directory and load all the distributions it sees untarred there. Once
that is done it will begin autoprobing for available POE::Loop packages. Once it determines what's available, it will begin
the benchmarks.
As the Benchmarker goes through the combinations of POE + Eventloop + Assertions + XS::Queue it will dump data into
the results directory. The Analyzer module also dumps YAML output in the same place, with the suffix of ".yml"
This module exposes only one subroutine, the benchmark() one. You can pass a hashref to it to set various options. Here is
a list of the valid options:
=over 4
+=item freshstart => boolean
+
+This will tell the Benchmarker to ignore any previous test runs stored in the 'results' directory.
+
+ benchmark( { freshstart => 1 } );
+
+default: false
+
=item noxsqueue => boolean
This will tell the Benchmarker to force the unavailability of POE::XS::Queue::Array and skip those tests.
NOTE: The Benchmarker will set this automatically if it cannot load the module!
benchmark( { noxsqueue => 1 } );
default: false
=item noasserts => boolean
This will tell the Benchmarker to not run the ASSERT tests.
benchmark( { noasserts => 1 } );
default: false
=item litetests => boolean
This enables the "lite" tests which will not take up too much time.
benchmark( { litetests => 0 } );
default: true
=item quiet => boolean
This enables quiet mode which will not print anything to the console except for errors.
benchmark( { 'quiet' => 1 } );
default: false
=item loop => csv list or array
This overrides the built-in loop detection algorithm which searches for all known loops.
There is some "magic" here where you can put a negative sign in front of a loop and we will NOT run that.
NOTE: Capitalization is important!
benchmark( { 'loop' => 'IO_Poll,Select' } ); # runs only IO::Poll and Select
benchmark( { 'loop' => [ qw( Tk Gtk ) ] } ); # runs only Tk and Gtk
benchmark( { 'loop' => '-Tk' } ); # runs all available loops EXCEPT for TK
Known loops: Event_Lib EV Glib Prima Gtk Wx Kqueue Tk Select IO_Poll
=item poe => csv list or array
This overrides the built-in POE version detection algorithm which pulls the POE versions from the 'poedists' directory.
There is some "magic" here where you can put a negative sign in front of a version and we will NOT run that.
NOTE: The Benchmarker will ignore versions that wasn't found in the directory!
benchmark( { 'poe' => '0.35,1.003' } ); # runs on 0.35 and 1.003
benchmark( { 'poe' => [ qw( 0.3009 0.12 ) ] } ); # runs on 0.3009 and 0.12
benchmark( { 'poe' => '-0.35' } ); # runs ALL tests except 0.35
=back
=head2 ANALYZING RESULTS
-Please look at the L<POE::Devel::Benchmarker::Analyzer> module.
-
-=head2 HOW DO I?
-
-This section will explain the miscellaneous questions and preemptively answer any concerns :)
-
-=head3 Skip a specific benchmark
-
-Why would you want to? That's the whole point of this suite!
-
-=head3 Create graphs
-
-This will be added to the module soon. However if you have the time+energy, please feel free to dig into the YAML output
-that Benchmarker::Analyzer outputs.
-
-=head3 Restarting where the Benchmarker left off
-
-This isn't implemented yet. You could always manually delete the POE versions that was tested and proceed with the rest. Or,
-use the 'poe' option to benchmark() and tweak the values.
+Please look at the pretty charts generated by the L<POE::Devel::Benchmarker::Imager> module.
=head1 EXPORT
Automatically exports the benchmark() subroutine.
=head1 TODO
=over 4
=item Perl version smoking
We should be able to run the benchmark over different Perl versions. This would require some fiddling with our
layout + logic. It's not that urgent because the workaround is to simply execute the benchmarker under a different
perl binary. It's smart enough to use $^X to be consistent across tests/subprocesses :)
=item Select the EV backend
<Khisanth> and if you are benchmarking, try it with POE using EV with EV using Glib? :P
<Apocalypse> I'm not sure how to configure the EV "backend" yet
<Apocalypse> too much docs for me to read hah
<Khisanth> Apocalypse: use EV::Glib; use Glib; use POE; :)
=item Be smarter in smoking timeouts
Currently we depend on the litetests option and hardcode some values including the timeout. If your machine is incredibly
slow, there's a chance that it could timeout unnecessarily. Please look at the outputs and check to see if there are unusual
failures, and inform me.
Also, some loops perform badly and take almost forever! /me glares at Gtk...
=item More benchmarks!
As usual, me and the crowd in #poe have plenty of ideas for tests. We'll be adding them over time, but if you have an idea please
drop me a line and let me know!
dngor said there was some benchmarks in the POE svn under trunk/queue...
I want a bench that actually tests socket traffic - stream 10MB of traffic over localhost, and time it?
LotR and Tapout contributed some samples, let's see if I can integrate them...
=item Add SQLite/DBI/etc support to the Analyzer
It would be nice if we could have a local SQLite db to dump our stats into. This would make arbitrary reports much easier than
loading raw YAML files and trying to make sense of them, ha! Also, this means somebody can do the smoking and send the SQLite
db to another person to generate the graphs, cool!
=item Kqueue loop support
As I don't have access to a *BSD box, I cannot really test this. Furthermore, it isn't clear on how I can force/unload this
module from POE...
=item Wx loop support
I have Wx installed, but it doesn't work. Obviously I don't know how to use Wx ;)
If you have experience, please drop me a line on how to do the "right" thing to get Wx loaded under POE. Here's the error:
Can't call method "MainLoop" on an undefined value at /usr/local/share/perl/5.8.8/POE/Loop/Wx.pm line 91.
=item XS::Loop support
The POE::XS::Loop::* modules theoretically could be tested too. However, they will only work in POE >= 1.003! This renders
the concept somewhat moot. Maybe, after POE has progressed some versions we can implement this...
=back
=head1 SEE ALSO
L<POE>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
BIG THANKS goes to Rocco Caputo E<lt>rcaputo@cpan.orgE<gt> for the first benchmarks!
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/Analyzer.pm b/lib/POE/Devel/Benchmarker/Analyzer.pm
index 7536be5..66af13a 100644
--- a/lib/POE/Devel/Benchmarker/Analyzer.pm
+++ b/lib/POE/Devel/Benchmarker/Analyzer.pm
@@ -1,456 +1,458 @@
# Declare our package
package POE::Devel::Benchmarker::Analyzer;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
-$VERSION = '0.03';
+$VERSION = '0.04';
# auto-export the only sub we have
BEGIN {
require Exporter;
use vars qw( @ISA @EXPORT );
@ISA = qw(Exporter);
@EXPORT = qw( initAnalyzer );
}
# Import what we need from the POE namespace
use POE qw( Session );
use base 'POE::Session::AttributeBased';
# use the power of YAML
use YAML::Tiny qw( Dump );
# Load the utils
use POE::Devel::Benchmarker::Utils qw( beautify_times );
# fires up the engine
sub initAnalyzer {
my $quiet_mode = shift;
# create our session!
POE::Session->create(
- POE::Devel::Benchmarker::Analyzer->inline_states(),
+ __PACKAGE__->inline_states(),
'heap' => {
'quiet_mode' => $quiet_mode,
},
);
}
# Starts up our session
sub _start : State {
# set our alias
$_[KERNEL]->alias_set( 'Benchmarker::Analyzer' );
- # TODO connect to SQLite db via SimpleDBI?
+ if ( ! $_[HEAP]->{'quiet_mode'} ) {
+ print "[ANALYZER] Starting up...\n";
+ }
return;
}
sub _stop : State {
+ if ( ! $_[HEAP]->{'quiet_mode'} ) {
+ print "[ANALYZER] Shutting down...\n";
+ }
+
return;
}
sub _child : State {
return;
}
sub analyze : State {
# get the data
my $test = $_[ARG0];
# clean up the times() stuff
$test->{'times'} = beautify_times(
join( " ", @{ delete $test->{'start_times'} } ) .
" " .
join( " ", @{ delete $test->{'end_times'} } )
);
# setup the perl version
$test->{'perlconfig'}->{'v'} = sprintf( "%vd", $^V );
# Okay, break it down into our data struct
$test->{'benchmark'} = {};
my $d = $test->{'benchmark'};
my @unknown;
foreach my $l ( split( /(?:\n|\r)/, $test->{'rawdata'} ) ) {
# skip empty lines
if ( $l eq '' ) { next }
# usual test benchmark output
# 10 startups in 0.885 seconds ( 11.302 per second)
# 10000 posts in 0.497 seconds ( 20101.112 per second)
if ( $l =~ /^\s+(\d+)\s+(\w+)\s+in\s+([\d\.]+)\s+seconds\s+\(\s+([\d\.]+)\s+per\s+second\)$/ ) {
$d->{ $2 }->{'loops'} = $1;
$d->{ $2 }->{'time'} = $3;
$d->{ $2 }->{'iterations_per_second'} = $4;
# usual test benchmark times output
# startup times: 0.1 0 0 0 0.1 0 0.76 0.09
} elsif ( $l =~ /^(\w+)\s+times:\s+(.+)$/ ) {
$d->{ $1 }->{'times'} = beautify_times( $2 );
# parse the memory footprint stuff
} elsif ( $l =~ /^pidinfo:\s+(.+)$/ ) {
# what should we analyze?
my $pidinfo = $1;
# VmPeak: 16172 kB
if ( $pidinfo =~ /^VmPeak:\s+(.+)$/ ) {
$test->{'pidinfo'}->{'vmpeak'} = $1;
# voluntary_ctxt_switches: 10
} elsif ( $pidinfo =~ /^voluntary_ctxt_switches:\s+(.+)$/ ) {
$test->{'pidinfo'}->{'voluntary_ctxt'} = $1;
# nonvoluntary_ctxt_switches: 1221
} elsif ( $pidinfo =~ /^nonvoluntary_ctxt_switches:\s+(.+)$/ ) {
$test->{'pidinfo'}->{'nonvoluntary_ctxt'} = $1;
} else {
# ignore the rest of the fluff
}
# parse the perl binary stuff
} elsif ( $l =~ /^perlconfig:\s+(.+)$/ ) {
# what should we analyze?
my $perlconfig = $1;
# Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
if ( $perlconfig =~ /^Summary\s+of\s+my\s+perl\d\s+\(([^\)]+)\)/ ) {
$test->{'perlconfig'}->{'version'} = $1;
} else {
# ignore the rest of the fluff
}
# parse the CPU info
} elsif ( $l =~ /^cpuinfo:\s+(.+)$/ ) {
# what should we analyze?
my $cpuinfo = $1;
# FIXME if this is on a multiproc system, we will overwrite the data per processor ( harmless? )
# cpu MHz : 1201.000
if ( $cpuinfo =~ /^cpu\s+MHz\s+:\s+(.+)$/ ) {
$test->{'cpuinfo'}->{'mhz'} = $1;
# model name : Intel(R) Core(TM)2 Duo CPU L7100 @ 1.20GHz
} elsif ( $cpuinfo =~ /^model\s+name\s+:\s+(.+)$/ ) {
$test->{'cpuinfo'}->{'name'} = $1;
# bogomips : 2397.58
} elsif ( $cpuinfo =~ /^bogomips\s+:\s+(.+)$/ ) {
$test->{'cpuinfo'}->{'bogomips'} = $1;
} else {
# ignore the rest of the fluff
}
# data that we can safely throw away
} elsif ( $l eq 'Using NO Assertions!' or
$l eq 'Using FULL Assertions!' or
$l eq 'Using the LITE tests' or
$l eq 'Using the HEAVY tests' or
$l eq 'DISABLING POE::XS::Queue::Array' or
$l eq '!STDERR: Devel::Hide hides POE/XS/Queue/Array.pm' or
$l eq 'LETTING POE find POE::XS::Queue::Array' or
$l eq 'UNABLE TO GET /proc/self/status' or
$l eq 'UNABLE TO GET /proc/cpuinfo' or
$l eq '!STDERR: POE::Kernel\'s run() method was never called.' or # to ignore old POEs that threw this warning
$l eq 'TEST TERMINATED DUE TO TIMEOUT' ) {
# ignore them
# parse the perl binary stuff
} elsif ( $l =~ /^Running\s+under\s+perl\s+binary:\s+(.+)$/ ) {
$test->{'perlconfig'}->{'binary'} = $1;
# the master loop version ( what the POE::Loop::XYZ actually uses )
# Using loop: EV-3.49
} elsif ( $l =~ /^Using\s+master\s+loop:\s+(.+)$/ ) {
$test->{'poe_loop_master'} = $1;
# the real POE version that was loaded
# Using POE-1.001
} elsif ( $l =~ /^Using\s+POE-(.+)$/ ) {
$test->{'poe_version_loaded'} = $1;
# the various queue/loop modules we loaded
# POE is using: POE::XS::Queue::Array v0.005
# POE is using: POE::Queue v1.2328
# POE is using: POE::Loop::EV v0.06
} elsif ( $l =~ /^POE\s+is\s+using:\s+([^\s]+)\s+v(.+)$/ ) {
$test->{'poe_modules'}->{ $1 } = $2;
# get the uname info
# Running under machine: Linux apoc-x300 2.6.24-21-generic #1 SMP Tue Oct 21 23:43:45 UTC 2008 i686 GNU/Linux
} elsif ( $l =~ /^Running\s+under\s+machine:\s+(.+)$/ ) {
$test->{'uname'} = $1;
- # the SubProcess version
- } elsif ( $l =~ /^SubProcess-(.+)$/ ) {
- $test->{'benchmarker_version'} = $1;
-
# parse the SKIP tests
# SKIPPING MYFH tests on broken loop: Event_Lib
# SKIPPING STDIN tests on broken loop: Tk
} elsif ( $l =~ /^SKIPPING\s+(\w+)\s+tests\s+on\s+broken/ ) {
my $fh = $1;
# nullify the data struct for that
foreach my $type ( qw( select_read select_write ) ) {
$d->{ $type . $fh }->{'loops'} = undef;
$d->{ $type . $fh }->{'time'} = undef;
$d->{ $type . $fh }->{'times'} = undef;
$d->{ $type . $fh }->{'iterations_per_second'} = undef;
}
# parse the FH/STDIN failures
# filehandle select_read on STDIN FAILED: error
# filehandle select_write on MYFH FAILED: foo
} elsif ( $l =~ /^filehandle\s+(\w+)\s+on\s+(\w+)\s+FAILED:/ ) {
my( $mode, $type ) = ( $1, $2 );
# nullify the data struct for that
$d->{ $mode . $type }->{'loops'} = undef;
$d->{ $mode . $type }->{'time'} = undef;
$d->{ $mode . $type }->{'times'} = undef;
$d->{ $mode . $type }->{'iterations_per_second'} = undef;
# parse the alarm_add skip
# alarm_add NOT SUPPORTED on this version of POE, skipping alarm_adds/alarm_clears tests!
} elsif ( $l =~ /^alarm_add\s+NOT\s+SUPPORTED\s+on/ ) {
# nullify the data struct for that
foreach my $type ( qw( alarm_adds alarm_clears ) ) {
$d->{ $type }->{'loops'} = undef;
$d->{ $type }->{'time'} = undef;
$d->{ $type }->{'times'} = undef;
$d->{ $type }->{'iterations_per_second'} = undef;
}
# parse any STDERR output
# !STDERR: unable to foo
} elsif ( $l =~ /^\!STDERR:\s+(.+)$/ ) {
push( @{ $test->{'stderr'} }, $1 );
} else {
# unknown line :(
push( @unknown, $l );
}
}
# Get rid of the rawdata
delete $test->{'rawdata'};
# Dump the unknowns
if ( @unknown ) {
print "[ANALYZER] Unknown output from benchmark -> " . Dump( \@unknown );
}
# Dump the data struct we have to the file.yml
my $yaml_file = 'results/' . delete $test->{'test_file'};
$yaml_file .= '.yml';
my $ret = open( my $fh, '>', $yaml_file );
if ( defined $ret ) {
print $fh Dump( $test );
if ( ! close( $fh ) ) {
print "[ANALYZER] Unable to close $yaml_file -> " . $! . "\n";
}
} else {
print "[ANALYZER] Unable to open $yaml_file for writing -> " . $! . "\n";
}
- # TODO send the $test data struct to a DB
-
+ # all done!
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::Analyzer - Analyzes the output from the benchmarks
=head1 SYNOPSIS
- Don't use this module directly. Please use POE::Devel::Benchmarker.
+ Don't use this module directly. Please see L<POE::Devel::Benchmarker>
=head1 ABSTRACT
This package implements the guts of converting the raw data into a machine-readable format. Furthermore, it dumps the data
in YAML format.
=head1 EXPORT
Automatically exports the initAnalyzer() sub
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
# sample test output ( from SubProcess v0.02 )
-STARTTIME: 1229173634.36228 -> TIMES 0.17 0.02 0.76 0.12
-POE-1.003-Event_Lib-noassert-noxsqueue
-
-Using master loop: Event_Lib-1.03
-Using NO Assertions!
+STARTTIME: 1229232743.49131 -> TIMES 0.24 0.01 11.2 0.32
+POE-1.003-Select-LITE-assert-xsqueue
+Using master loop: Select-BUILTIN
+Using FULL Assertions!
Using the LITE tests
LETTING POE find POE::XS::Queue::Array
Using POE-1.003
+POE is using: POE::Loop::Select v1.2355
POE is using: POE::XS::Queue::Array v0.005
POE is using: POE::Queue v1.2328
-POE is using: POE::Loop::Event_Lib v0.001_01
-
-
- 10 startups in 0.898 seconds ( 11.134 per second)
-startup times: 0.1 0.01 0 0 0.1 0.01 0.81 0.09
- 10000 posts in 0.372 seconds ( 26896.254 per second)
-posts times: 0.1 0.01 0.81 0.09 0.42 0.06 0.81 0.09
- 10000 dispatches in 0.658 seconds ( 15196.902 per second)
-dispatches times: 0.42 0.06 0.81 0.09 1.06 0.06 0.81 0.09
- 10000 alarms in 1.020 seconds ( 9802.144 per second)
-alarms times: 1.07 0.06 0.81 0.09 1.89 0.26 0.81 0.09
- 10000 alarm_adds in 0.415 seconds ( 24111.902 per second)
-alarm_adds times: 1.89 0.26 0.81 0.09 2.3 0.26 0.81 0.09
- 10000 alarm_clears in 0.221 seconds ( 45239.068 per second)
-alarm_clears times: 2.3 0.26 0.81 0.09 2.52 0.26 0.81 0.09
- 500 session_creates in 0.114 seconds ( 4367.120 per second)
-session_creates times: 2.52 0.26 0.81 0.09 2.63 0.27 0.81 0.09
- 500 session destroys in 0.116 seconds ( 4311.978 per second)
-session_destroys times: 2.63 0.27 0.81 0.09 2.74 0.28 0.81 0.09
- 10000 select_read_STDIN in 2.003 seconds ( 4992.736 per second)
-select_read_STDIN times: 2.74 0.28 0.81 0.09 4.66 0.35 0.81 0.09
- 10000 select_write_STDIN in 1.971 seconds ( 5074.097 per second)
-select_write_STDIN times: 4.66 0.35 0.81 0.09 6.56 0.39 0.81 0.09
-SKIPPING MYFH tests on broken loop: Event_Lib
- 10000 calls in 0.213 seconds ( 46963.378 per second)
-calls times: 6.56 0.39 0.81 0.09 6.78 0.39 0.81 0.09
- 10000 single_posts in 1.797 seconds ( 5565.499 per second)
-single_posts times: 6.78 0.39 0.81 0.09 8.13 0.83 0.81 0.09
+POE is using: POE::Loop::PerlSignals v1.2329
+
+
+ 10 startups in 0.853 seconds ( 11.723 per second)
+startups times: 0.09 0 0 0 0.09 0 0.73 0.11
+ 10000 posts in 0.495 seconds ( 20211.935 per second)
+posts times: 0.1 0 0.73 0.11 0.53 0.06 0.73 0.11
+ 10000 dispatches in 1.113 seconds ( 8984.775 per second)
+dispatches times: 0.53 0.06 0.73 0.11 1.64 0.06 0.73 0.11
+ 10000 alarms in 1.017 seconds ( 9829.874 per second)
+alarms times: 1.64 0.06 0.73 0.11 2.66 0.06 0.73 0.11
+ 10000 alarm_adds in 0.523 seconds ( 19102.416 per second)
+alarm_adds times: 2.66 0.06 0.73 0.11 3.18 0.06 0.73 0.11
+ 10000 alarm_clears in 0.377 seconds ( 26540.332 per second)
+alarm_clears times: 3.18 0.06 0.73 0.11 3.55 0.07 0.73 0.11
+ 500 session_creates in 0.130 seconds ( 3858.918 per second)
+session_creates times: 3.55 0.07 0.73 0.11 3.68 0.08 0.73 0.11
+ 500 session_destroys in 0.172 seconds ( 2901.191 per second)
+session_destroys times: 3.68 0.08 0.73 0.11 3.85 0.08 0.73 0.11
+ 10000 select_read_STDIN in 1.823 seconds ( 5485.878 per second)
+select_read_STDIN times: 3.85 0.08 0.73 0.11 5.66 0.08 0.73 0.11
+ 10000 select_write_STDIN in 1.827 seconds ( 5472.283 per second)
+select_write_STDIN times: 5.66 0.08 0.73 0.11 7.47 0.08 0.73 0.11
+ 10000 select_read_MYFH in 1.662 seconds ( 6016.387 per second)
+select_read_MYFH times: 7.47 0.08 0.73 0.11 9.12 0.1 0.73 0.11
+ 10000 select_write_MYFH in 1.704 seconds ( 5868.537 per second)
+select_write_MYFH times: 9.12 0.1 0.73 0.11 10.78 0.11 0.73 0.11
+ 10000 calls in 0.222 seconds ( 45038.974 per second)
+calls times: 10.78 0.11 0.73 0.11 11 0.11 0.73 0.11
+ 10000 single_posts in 1.999 seconds ( 5003.473 per second)
+single_posts times: 11 0.11 0.73 0.11 12.86 0.22 0.73 0.11
pidinfo: Name: perl
pidinfo: State: R (running)
-pidinfo: Tgid: 6750
-pidinfo: Pid: 6750
-pidinfo: PPid: 6739
+pidinfo: Tgid: 16643
+pidinfo: Pid: 16643
+pidinfo: PPid: 16600
pidinfo: TracerPid: 0
pidinfo: Uid: 1000 1000 1000 1000
pidinfo: Gid: 1000 1000 1000 1000
pidinfo: FDSize: 32
pidinfo: Groups: 4 20 24 25 29 30 44 46 107 109 115 127 1000 1001
-pidinfo: VmPeak: 14916 kB
-pidinfo: VmSize: 14756 kB
+pidinfo: VmPeak: 14376 kB
+pidinfo: VmSize: 14216 kB
pidinfo: VmLck: 0 kB
-pidinfo: VmHWM: 11976 kB
-pidinfo: VmRSS: 11828 kB
-pidinfo: VmData: 10104 kB
+pidinfo: VmHWM: 11440 kB
+pidinfo: VmRSS: 11292 kB
+pidinfo: VmData: 9908 kB
pidinfo: VmStk: 84 kB
pidinfo: VmExe: 1044 kB
-pidinfo: VmLib: 2180 kB
+pidinfo: VmLib: 1872 kB
pidinfo: VmPTE: 24 kB
pidinfo: Threads: 1
pidinfo: SigQ: 0/16182
pidinfo: SigPnd: 0000000000000000
pidinfo: ShdPnd: 0000000000000000
pidinfo: SigBlk: 0000000000000000
-pidinfo: SigIgn: 0000000000001080
+pidinfo: SigIgn: 0000000000001000
pidinfo: SigCgt: 0000000180000000
pidinfo: CapInh: 0000000000000000
pidinfo: CapPrm: 0000000000000000
pidinfo: CapEff: 0000000000000000
pidinfo: Cpus_allowed: 03
pidinfo: Mems_allowed: 1
-pidinfo: voluntary_ctxt_switches: 11
-pidinfo: nonvoluntary_ctxt_switches: 697
+pidinfo: voluntary_ctxt_switches: 10
+pidinfo: nonvoluntary_ctxt_switches: 512
Running under perl binary: /usr/bin/perl
perlconfig: Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
perlconfig: Platform:
perlconfig: osname=linux, osvers=2.6.15.7, archname=i486-linux-gnu-thread-multi
perlconfig: uname='linux palmer 2.6.15.7 #1 smp thu sep 7 19:42:20 utc 2006 i686 gnulinux '
perlconfig: config_args='-Dusethreads -Duselargefiles -Dccflags=-DDEBIAN -Dcccdlflags=-fPIC -Darchname=i486-linux-gnu -Dprefix=/usr -Dprivlib=/usr/share/perl/5.8 -Darchlib=/usr/lib/perl/5.8 -Dvendorprefix=/usr -Dvendorlib=/usr/share/perl5 -Dvendorarch=/usr/lib/perl5 -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl/5.8.8 -Dsitearch=/usr/local/lib/perl/5.8.8 -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 -Dsiteman1dir=/usr/local/man/man1 -Dsiteman3dir=/usr/local/man/man3 -Dman1ext=1 -Dman3ext=3perl -Dpager=/usr/bin/sensible-pager -Uafs -Ud_csh -Ud_ualarm -Uusesfio -Uusenm -Duseshrplib -Dlibperl=libperl.so.5.8.8 -Dd_dosuid -des'
perlconfig: hint=recommended, useposix=true, d_sigaction=define
perlconfig: usethreads=define use5005threads=undef useithreads=define usemultiplicity=define
perlconfig: useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
perlconfig: use64bitint=undef use64bitall=undef uselongdouble=undef
perlconfig: usemymalloc=n, bincompat5005=undef
perlconfig: Compiler:
perlconfig: cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBIAN -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
perlconfig: optimize='-O2',
perlconfig: cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBIAN -fno-strict-aliasing -pipe -I/usr/local/include'
perlconfig: ccversion='', gccversion='4.2.3 20071123 (prerelease) (Ubuntu 4.2.2-3ubuntu4)', gccosandvers=''
perlconfig: intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
perlconfig: d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
perlconfig: ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
perlconfig: alignbytes=4, prototype=define
perlconfig: Linker and Libraries:
perlconfig: ld='cc', ldflags =' -L/usr/local/lib'
perlconfig: libpth=/usr/local/lib /lib /usr/lib
perlconfig: libs=-lgdbm -lgdbm_compat -ldb -ldl -lm -lpthread -lc -lcrypt
perlconfig: perllibs=-ldl -lm -lpthread -lc -lcrypt
perlconfig: libc=/lib/libc-2.6.1.so, so=so, useshrplib=true, libperl=libperl.so.5.8.8
perlconfig: gnulibc_version='2.6.1'
perlconfig: Dynamic Linking:
perlconfig: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
perlconfig: cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib'
Running under machine: Linux apoc-x300 2.6.24-21-generic #1 SMP Tue Oct 21 23:43:45 UTC 2008 i686 GNU/Linux
cpuinfo: processor : 0
cpuinfo: vendor_id : GenuineIntel
cpuinfo: cpu family : 6
cpuinfo: model : 15
cpuinfo: model name : Intel(R) Core(TM)2 Duo CPU L7100 @ 1.20GHz
cpuinfo: stepping : 11
cpuinfo: cpu MHz : 1201.000
cpuinfo: cache size : 4096 KB
cpuinfo: physical id : 0
cpuinfo: siblings : 2
cpuinfo: core id : 0
cpuinfo: cpu cores : 2
cpuinfo: fdiv_bug : no
cpuinfo: hlt_bug : no
cpuinfo: f00f_bug : no
cpuinfo: coma_bug : no
cpuinfo: fpu : yes
cpuinfo: fpu_exception : yes
cpuinfo: cpuid level : 10
cpuinfo: wp : yes
cpuinfo: flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc arch_perfmon pebs bts pni monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr lahf_lm ida
cpuinfo: bogomips : 2397.58
cpuinfo: clflush size : 64
-cpuinfo:
cpuinfo: processor : 1
cpuinfo: vendor_id : GenuineIntel
cpuinfo: cpu family : 6
cpuinfo: model : 15
cpuinfo: model name : Intel(R) Core(TM)2 Duo CPU L7100 @ 1.20GHz
cpuinfo: stepping : 11
cpuinfo: cpu MHz : 1201.000
cpuinfo: cache size : 4096 KB
cpuinfo: physical id : 0
cpuinfo: siblings : 2
cpuinfo: core id : 1
cpuinfo: cpu cores : 2
cpuinfo: fdiv_bug : no
cpuinfo: hlt_bug : no
cpuinfo: f00f_bug : no
cpuinfo: coma_bug : no
cpuinfo: fpu : yes
cpuinfo: fpu_exception : yes
cpuinfo: cpuid level : 10
cpuinfo: wp : yes
cpuinfo: flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc arch_perfmon pebs bts pni monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr lahf_lm ida
cpuinfo: bogomips : 2394.02
cpuinfo: clflush size : 64
-cpuinfo:
-ENDTIME: 1229173644.30093 -> TIMES 0.19 0.02 1.08 0.16
+ENDTIME: 1229232757.53804 -> TIMES 0.27 0.01 23.1 0.62
diff --git a/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm b/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm
index d2e5e9f..f70065b 100644
--- a/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm
+++ b/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm
@@ -1,211 +1,211 @@
# Declare our package
package POE::Devel::Benchmarker::GetInstalledLoops;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
-$VERSION = '0.03';
+$VERSION = '0.04';
# auto-export the only sub we have
BEGIN {
require Exporter;
use vars qw( @ISA @EXPORT );
@ISA = qw(Exporter);
@EXPORT = qw( getPOEloops );
}
# Import what we need from the POE namespace
use POE qw( Session Filter::Line Wheel::Run );
use base 'POE::Session::AttributeBased';
# Get the utils
use POE::Devel::Benchmarker::Utils qw ( knownloops );
# analyzes the installed perl directory for available loops
sub getPOEloops {
my $quiet_mode = shift;
my $forceloops = shift;
# create our session!
POE::Session->create(
POE::Devel::Benchmarker::GetInstalledLoops->inline_states(),
'heap' => {
'quiet_mode' => $quiet_mode,
'loops' => $forceloops,
},
);
}
# Starts up our session
sub _start : State {
# set our alias
$_[KERNEL]->alias_set( 'Benchmarker::GetInstalledLoops' );
# load our known list of loops
# known impossible loops:
# XS::EPoll ( must be POE > 1.003 and weird way of loading )
# XS::Poll ( must be POE > 1.003 and weird way of loading )
if ( ! defined $_[HEAP]->{'loops'} ) {
$_[HEAP]->{'loops'} = knownloops();
}
# First of all, we need to find out what loop libraries are installed
$_[HEAP]->{'found_loops'} = [];
$_[KERNEL]->yield( 'find_loops' );
return;
}
sub _stop : State {
# tell the wheel to kill itself
if ( defined $_[HEAP]->{'WHEEL'} ) {
$_[HEAP]->{'WHEEL'}->kill( 9 );
undef $_[HEAP]->{'WHEEL'};
}
return;
}
# loops over the "known" loops and sees if they are installed
sub find_loops : State {
# get the loop to test
$_[HEAP]->{'current_loop'} = shift @{ $_[HEAP]->{'loops'} };
# do we have something to test?
if ( ! defined $_[HEAP]->{'current_loop'} ) {
# we're done!
$_[KERNEL]->alias_remove( 'Benchmarker::GetInstalledLoops' );
$_[KERNEL]->post( 'Benchmarker', 'found_loops', $_[HEAP]->{'found_loops'} );
return;
} else {
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[LOOPSEARCH] Trying to find if POE::Loop::" . $_[HEAP]->{'current_loop'} . " is installed...\n";
}
# set the flag
$_[HEAP]->{'test_failure'} = 0;
}
# Okay, create the wheel::run to handle this
$_[HEAP]->{'WHEEL'} = POE::Wheel::Run->new(
'Program' => $^X,
'ProgramArgs' => [ '-MPOE',
'-MPOE::Loop::' . $_[HEAP]->{'current_loop'},
'-e',
'1',
],
# Kill off existing FD's
'CloseOnCall' => 1,
# setup our data handlers
'StdoutEvent' => 'Got_STDOUT',
'StderrEvent' => 'Got_STDERR',
# the error handler
'ErrorEvent' => 'Got_ERROR',
'CloseEvent' => 'Got_CLOSED',
# set our filters
'StderrFilter' => POE::Filter::Line->new(),
'StdoutFilter' => POE::Filter::Line->new(),
);
if ( ! defined $_[HEAP]->{'WHEEL'} ) {
die '[LOOPSEARCH] Unable to create a new wheel!';
} else {
# smart CHLD handling
if ( $_[KERNEL]->can( "sig_child" ) ) {
$_[KERNEL]->sig_child( $_[HEAP]->{'WHEEL'}->PID => 'Got_CHLD' );
} else {
$_[KERNEL]->sig( 'CHLD', 'Got_CHLD' );
}
}
return;
}
# Got a CHLD event!
sub Got_CHLD : State {
$_[KERNEL]->sig_handled();
return;
}
# Handles child STDERR output
sub Got_STDERR : State {
my $input = $_[ARG0];
# since we got an error, must be a failure
$_[HEAP]->{'test_failure'} = 1;
return;
}
# Handles child STDOUT output
sub Got_STDOUT : State {
my $input = $_[ARG0];
return;
}
# Handles child error
sub Got_ERROR : State {
# Copied from POE::Wheel::Run manpage
my ( $operation, $errnum, $errstr ) = @_[ ARG0 .. ARG2 ];
# ignore exit 0 errors
if ( $errnum != 0 ) {
warn "Wheel::Run got an $operation error $errnum: $errstr\n";
}
return;
}
# Handles child DIE'ing
sub Got_CLOSED : State {
# Get rid of the wheel
undef $_[HEAP]->{'WHEEL'};
# Did we pass this test or not?
if ( ! $_[HEAP]->{'test_failure'} ) {
push( @{ $_[HEAP]->{'found_loops'} }, $_[HEAP]->{'current_loop'} );
}
# move on to the next loop
$_[KERNEL]->yield( 'find_loops' );
return;
}
1;
__END__
=head1 NAME
+POE::Devel::Benchmarker::GetInstalledLoops - Automatically detects the installed POE loops
+
=head1 SYNOPSIS
Don't use this module directly. Please use POE::Devel::Benchmarker.
-POE::Devel::Benchmarker::GetInstalledLoops - Automatically detects the installed POE loops
-
=head1 ABSTRACT
This package implements the guts of searching for POE loops via fork/exec.
=head1 EXPORT
Automatically exports the getPOEloops() sub
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/GetPOEdists.pm b/lib/POE/Devel/Benchmarker/GetPOEdists.pm
index 9f65da4..7f10f39 100644
--- a/lib/POE/Devel/Benchmarker/GetPOEdists.pm
+++ b/lib/POE/Devel/Benchmarker/GetPOEdists.pm
@@ -1,126 +1,142 @@
# Declare our package
package POE::Devel::Benchmarker::GetPOEdists;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
-$VERSION = '0.03';
+$VERSION = '0.04';
# auto-export the only sub we have
require Exporter;
use vars qw( @ISA @EXPORT );
@ISA = qw(Exporter);
@EXPORT = qw( getPOEdists );
# import the helper modules
use LWP::UserAgent;
use HTML::LinkExtor;
use URI::URL;
use Archive::Tar;
# actually retrieves the dists!
sub getPOEdists {
# should we debug?
my $debug = shift;
+ # okay, should we change directory?
+ if ( -d 'poedists' ) {
+ if ( $debug ) {
+ print "[GETPOEDISTS] chdir( 'poedists' )\n";
+ }
+
+ if ( ! chdir( 'poedists' ) ) {
+ die "Unable to chdir to 'poedists' dir: $!";
+ }
+ } else {
+ if ( $debug ) {
+ print "[GETPOEDISTS] downloading to current directory\n";
+ }
+ }
+
# set the default URL
my $url = "http://backpan.cpan.org/authors/id/R/RC/RCAPUTO/";
# create our objects
my $ua = LWP::UserAgent->new;
my $p = HTML::LinkExtor->new;
my $tar = Archive::Tar->new;
# Request document and parse it as it arrives
print "Getting $url via LWP\n" if $debug;
my $res = $ua->request( HTTP::Request->new( GET => $url ),
sub { $p->parse( $_[0] ) },
);
# did we successfully download?
if ( $res->is_error ) {
die "unable to download directory index on BACKPAN: " . $res->status_line;
}
# Download every one!
foreach my $link ( $p->links ) {
# skip IMG stuff
if ( $link->[0] eq 'a' and $link->[1] eq 'href' ) {
# get the actual POE dists!
if ( $link->[2] =~ /^POE\-\d/ and $link->[2] =~ /\.tar\.gz$/ ) {
# download the tarball!
print "Mirroring $link->[2] via LWP\n" if $debug;
my $mirror_result = $ua->mirror( $url . $link->[2], $link->[2] );
if ( $mirror_result->is_error ) {
warn "unable to mirror $link->[2]: " . $mirror_result->status_line;
next;
}
# did we already untar this one?
my $dir = $link->[2];
$dir =~ s/\.tar\.gz$//;
if ( ! -d $dir ) {
# extract it!
print "Extracting $link->[2] via Tar\n" if $debug;
my $files = $tar->read( $link->[2], undef, { 'extract' => 'true' } );
if ( $files == 0 ) {
warn "unable to extract $link->[2]";
}
}
}
}
}
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::GetPOEdists - Automatically download all POE tarballs
=head1 SYNOPSIS
- perl -MPOE::Devel::Benchmarker::GetPOEdists -e 'getPOEdists()'
+ apoc@apoc-x300:~$ cd poe-benchmarker
+ apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker::GetPOEdists -e 'getPOEdists()'
=head1 ABSTRACT
This package automatically downloads all the POE tarballs from BACKPAN.
=head1 DESCRIPTION
This uses LWP + HTML::LinkExtor to retrieve POE tarballs from BACKPAN.
The tarballs are automatically downloaded to the current directory. Then, we use Archive::Tar to extract them all!
NOTE: we use LWP's useful mirror() sub which doesn't re-download files if they already exist!
=head2 getPOEdists
Normally you should pass nothing to this sub. However, if you want to debug the downloads+extractions you should pass
a true value as the first argument.
perl -MPOE::Devel::Benchmarker::GetPOEdists -e 'getPOEdists( 1 )'
=head1 EXPORT
Automatically exports the getPOEdists() sub
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/Imager.pm b/lib/POE/Devel/Benchmarker/Imager.pm
new file mode 100644
index 0000000..aa92df2
--- /dev/null
+++ b/lib/POE/Devel/Benchmarker/Imager.pm
@@ -0,0 +1,165 @@
+# Declare our package
+package POE::Devel::Benchmarker::Imager;
+use strict; use warnings;
+
+# Initialize our version
+use vars qw( $VERSION );
+$VERSION = '0.04';
+
+# auto-export the only sub we have
+require Exporter;
+use vars qw( @ISA @EXPORT );
+@ISA = qw(Exporter);
+@EXPORT = qw( imager );
+
+# import the helper modules
+use YAML::Tiny;
+use Chart::Clicker;
+use Chart::Clicker::Data::Series;
+use Chart::Clicker::Data::DataSet;
+
+# olds our data structure
+my %data;
+
+# debug or not?
+my $debug = 0;
+
+# starts the work of converting our data to images
+sub imager {
+ # should we debug?
+ $debug = shift;
+ if ( $debug ) {
+ $debug = 1;
+ } else {
+ $debug = 0;
+ }
+
+ # some sanity tests
+ if ( ! -d 'results' ) {
+ die "The 'results' directory is not found in the working directory!";
+ }
+ if ( ! -d 'images' ) {
+ die "The 'images' directory is not found in the working directory!";
+ }
+
+ if ( $debug ) {
+ print "[IMAGER] Starting up...\n";
+ }
+
+ # parse all of our YAML modules!
+ parse_yaml();
+
+ # Do some processing of the data
+ process_data();
+
+ # generate the images!
+ generate_images();
+
+ return;
+}
+
+# starts the process of loading all of our YAML images
+sub parse_yaml {
+ # gather all the YAML dumps
+ my @versions;
+ if ( opendir( DUMPS, 'results' ) ) {
+ foreach my $d ( readdir( DUMPS ) ) {
+ if ( $d =~ /\.yml$/ ) {
+ push( @versions, $d );
+ }
+ }
+ closedir( DUMPS ) or die "[IMAGER] Unable to read from 'results' -> " . $!;
+ } else {
+ die "[IMAGER] Unable to open 'results' for reading -> " . $!;
+ }
+
+ # sanity
+ if ( ! scalar @versions ) {
+ die "[IMAGER] Unable to find any POE test result(s) in the 'results' directory!\n";
+ }
+
+ # Parse every one of them!
+ foreach my $v ( @versions ) {
+ load_yaml( "results/$v" );
+ }
+
+ return;
+}
+
+# loads the yaml of a specific file
+sub load_yaml {
+ my $file = shift;
+
+ my $yaml = YAML::Tiny->read( $file );
+ if ( ! defined $yaml ) {
+ die "[IMAGER] Unable to load YAML file $file -> " . YAML::Tiny->errstr . "\n";
+ } else {
+ # store it in the global hash
+ $data{ $file } = $yaml->[0];
+ }
+
+ return;
+}
+
+# mangles the data we've collected so far
+sub process_data {
+ # FIXME okay what should we do?
+
+ return;
+}
+
+sub generate_images {
+ # FIXME okay what should we do?
+
+ return;
+}
+
+1;
+__END__
+=head1 NAME
+
+POE::Devel::Benchmarker::Imager - Automatically converts the benchmark data into images
+
+=head1 SYNOPSIS
+
+ apoc@apoc-x300:~$ cd poe-benchmarker
+ apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker::Imager -e 'imager()'
+
+=head1 ABSTRACT
+
+This package automatically parses the benchmark data and generates pretty charts.
+
+=head1 DESCRIPTION
+
+This package uses the excellent L<Chart::Clicker> module to generate the images
+
+=head2 imager
+
+Normally you should pass nothing to this sub. However, if you want to debug the processing you should pass a true
+value as the first argument.
+
+ perl -MPOE::Devel::Benchmarker::Imager -e 'imager( 1 )'
+
+=head1 EXPORT
+
+Automatically exports the imager() sub
+
+=head1 SEE ALSO
+
+L<POE::Devel::Benchmarker>
+
+L<Chart::Clicker>
+
+=head1 AUTHOR
+
+Apocalypse E<lt>apocal@cpan.orgE<gt>
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright 2008 by Apocalypse
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
+
diff --git a/lib/POE/Devel/Benchmarker/SubProcess.pm b/lib/POE/Devel/Benchmarker/SubProcess.pm
index 5e2d2cb..b49c950 100644
--- a/lib/POE/Devel/Benchmarker/SubProcess.pm
+++ b/lib/POE/Devel/Benchmarker/SubProcess.pm
@@ -1,656 +1,656 @@
# Declare our package
package POE::Devel::Benchmarker::SubProcess;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
-$VERSION = '0.03';
+$VERSION = '0.04';
# Import Time::HiRes's time()
use Time::HiRes qw( time );
# FIXME UGLY HACK here
BEGIN {
# should we enable assertions?
if ( defined $ARGV[2] and $ARGV[2] ) {
## no critic
eval "sub POE::Kernel::ASSERT_DEFAULT () { 1 }";
eval "sub POE::Session::ASSERT_STATES () { 1 }";
## use critic
}
# should we "hide" XS::Queue::Array?
if ( defined $ARGV[4] and $ARGV[4] ) {
## no critic
eval "use Devel::Hide qw( POE/XS/Queue/Array.pm )";
## use critic
}
}
# load POE
use POE;
use POE::Session;
use IO::Handle;
# load our utility stuff
use POE::Devel::Benchmarker::Utils qw( loop2realversion poeloop2load );
# init our global variables ( bad, haha )
my( $version, $eventloop, $asserts, $lite_tests, $pocosession );
my( $post_limit, $alarm_limit, $alarm_add_limit, $session_limit, $select_limit, $through_limit, $call_limit, $start_limit );
# the main routine which will load everything + start
sub benchmark {
# autoflush our STDOUT for sanity
STDOUT->autoflush( 1 );
- # print our banner
- print "SubProcess-" . __PACKAGE__->VERSION . "\n";
-
# process the version
process_version();
# process the eventloop
process_eventloop();
# process the assertions
process_assertions();
# process the test mode
process_testmode();
# process the XS::Queue hiding
process_xsqueue();
# actually import POE!
process_POE();
# actually run the benchmarks!
run_benchmarks();
# all done!
return;
}
sub process_version {
# Get the desired POE version
$version = $ARGV[0];
# Decide what to do
if ( ! defined $version ) {
die "Please supply a version to test!";
} elsif ( ! -d 'poedists/POE-' . $version ) {
die "That specified version does not exist!";
} else {
# we're happy...
}
return;
}
sub process_eventloop {
# Get the desired mode
$eventloop = $ARGV[1];
# print out the loop info
if ( ! defined $eventloop ) {
die "Please supply an event loop!";
} else {
my $loop = poeloop2load( $eventloop );
if ( ! defined $loop ) {
$loop = $eventloop;
}
my $v = loop2realversion( $eventloop );
if ( ! defined $v ) {
$v = 'UNKNOWN';
}
print "Using master loop: $loop-$v\n";
}
return;
}
sub process_assertions {
# Get the desired assert mode
$asserts = $ARGV[2];
if ( defined $asserts and $asserts ) {
print "Using FULL Assertions!\n";
} else {
print "Using NO Assertions!\n";
}
return;
}
sub process_testmode {
# get the desired test mode
$lite_tests = $ARGV[3];
if ( defined $lite_tests and $lite_tests ) {
print "Using the LITE tests\n";
$post_limit = 10_000;
$alarm_limit = 10_000;
$alarm_add_limit = 10_000;
$session_limit = 500;
$select_limit = 10_000;
$through_limit = 10_000;
$call_limit = 10_000;
$start_limit = 10;
} else {
print "Using the HEAVY tests\n";
$post_limit = 100_000;
$alarm_limit = 100_000;
$alarm_add_limit = 100_000;
$session_limit = 5_000;
$select_limit = 100_000;
$through_limit = 100_000;
$call_limit = 100_000;
$start_limit = 100;
}
return;
}
sub process_xsqueue {
# should we "hide" XS::Queue::Array?
if ( defined $ARGV[4] and $ARGV[4] ) {
print "DISABLING POE::XS::Queue::Array\n";
} else {
print "LETTING POE find POE::XS::Queue::Array\n";
}
return;
}
sub process_POE {
# Print the POE info
print "Using POE-" . $POE::VERSION . "\n";
# Actually print what loop POE is using
foreach my $m ( keys %INC ) {
if ( $m =~ /^POE\/(?:Loop|XS|Queue)/ ) {
# try to be smart and get version?
my $module = $m;
$module =~ s|/|::|g;
$module =~ s/\.pm$//g;
print "POE is using: $module ";
if ( defined $module->VERSION ) {
print "v" . $module->VERSION . "\n";
} else {
print "vUNKNOWN\n";
}
}
}
return;
}
sub run_benchmarks {
# run the startup test before we actually run POE
bench_startup();
# load the POE session + do the tests there
bench_poe();
# dump some misc info
dump_pidinfo();
dump_perlinfo();
dump_sysinfo();
# all done!
return;
}
sub bench_startup {
# Add the eventloop?
my $looploader = poeloop2load( $eventloop );
my @start_times = times();
my $start = time();
for (my $i = 0; $i < $start_limit; $i++) {
# FIXME should we add assertions?
# finally, fire it up!
CORE::system(
$^X,
'-Ipoedists/POE-' . $version,
'-Ipoedists/POE-' . $version . '/lib',
( defined $looploader ? "-M$looploader" : () ),
'-MPOE',
'-e',
1,
);
}
my @end_times = times();
my $elapsed = time() - $start;
printf( "\n\n% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $start_limit, 'startups', $elapsed, $start_limit/$elapsed );
print "startups times: @start_times @end_times\n";
return;
}
sub bench_poe {
# figure out POE::Session->create or POE::Session->new or what?
$pocosession = POE::Session->can( 'create' );
if ( defined $pocosession ) {
$pocosession = 'create';
} else {
$pocosession = POE::Session->can( 'spawn' );
if ( defined $pocosession ) {
$pocosession = 'spawn';
} else {
$pocosession = 'new';
}
}
# create the master sesssion + run POE!
POE::Session->$pocosession(
'inline_states' => {
# basic POE states
'_start' => \&poe__start,
'_default' => \&poe__default,
'_stop' => \&poe__stop,
'null' => \&poe_null,
# our test states
'posts' => \&poe_posts,
'posts_start' => \&poe_posts_start,
'posts_end' => \&poe_posts_end,
'alarms' => \&poe_alarms,
'manyalarms' => \&poe_manyalarms,
'sessions' => \&poe_sessions,
'sessions_end' => \&poe_sessions_end,
'stdin_read' => \&poe_stdin_read,
'stdin_write' => \&poe_stdin_write,
'myfh_read' => \&poe_myfh_read,
'myfh_write' => \&poe_myfh_write,
'calls' => \&poe_calls,
'eventsquirt' => \&poe_eventsquirt,
'eventsquirt_done' => \&poe_eventsquirt_done,
},
);
# start the kernel!
POE::Kernel->run();
return;
}
# inits our session
sub poe__start {
# fire off the first test!
$_[KERNEL]->yield( 'posts' );
return;
}
sub poe__stop {
}
sub poe__default {
return 0;
}
# a state that does nothing
sub poe_null {
return 1;
}
# How many posts per second? Post a bunch of events, keeping track of the time it takes.
sub poe_posts {
$_[KERNEL]->yield( 'posts_start' );
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $post_limit; $i++) {
$_[KERNEL]->yield( 'null' );
}
my @end_times = times();
my $elapsed = time() - $start;
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $post_limit, 'posts', $elapsed, $post_limit/$elapsed );
print "posts times: @start_times @end_times\n";
$_[KERNEL]->yield( 'posts_end' );
return;
}
sub poe_posts_start {
$_[HEAP]->{start} = time();
$_[HEAP]->{starttimes} = [ times() ];
return;
}
sub poe_posts_end {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $post_limit, 'dispatches', $elapsed, $post_limit/$elapsed );
print "dispatches times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
$_[KERNEL]->yield( 'alarms' );
return;
}
# How many alarms per second? Set a bunch of alarms and find out.
sub poe_alarms {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $alarm_limit; $i++) {
$_[KERNEL]->alarm( whee => rand(1_000_000) );
}
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $alarm_limit, 'alarms', $elapsed, $alarm_limit/$elapsed );
print "alarms times: @start_times @end_times\n";
$_[KERNEL]->alarm( 'whee' => undef );
$_[KERNEL]->yield( 'manyalarms' );
return;
}
# How many repetitive alarms per second? Set a bunch of
# additional alarms and find out. Also see how quickly they can
# be cleared.
sub poe_manyalarms {
# can this POE::Kernel support this?
if ( $_[KERNEL]->can( 'alarm_add' ) ) {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $alarm_add_limit; $i++) {
$_[KERNEL]->alarm_add( whee => rand(1_000_000) );
}
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $alarm_add_limit, 'alarm_adds', $elapsed, $alarm_add_limit/$elapsed );
print "alarm_adds times: @start_times @end_times\n";
$start = time();
@start_times = times();
$_[KERNEL]->alarm( whee => undef );
$elapsed = time() - $start;
@end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $alarm_add_limit, 'alarm_clears', $elapsed, $alarm_add_limit/$elapsed );
print "alarm_clears times: @start_times @end_times\n";
} else {
print "alarm_add NOT SUPPORTED on this version of POE, skipping alarm_adds/alarm_clears tests!\n";
}
$_[KERNEL]->yield( 'sessions' );
return;
}
# How many sessions can we create and destroy per second?
# Create a bunch of sessions, and track that time. Let them
# self-destruct, and track that as well.
sub poe_sessions {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $session_limit; $i++) {
POE::Session->$pocosession( 'inline_states' => { _start => sub {}, _stop => sub {}, _default => sub { return 0 } } );
}
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $session_limit, 'session_creates', $elapsed, $session_limit/$elapsed );
print "session_creates times: @start_times @end_times\n";
$_[KERNEL]->yield( 'sessions_end' );
$_[HEAP]->{start} = time();
$_[HEAP]->{starttimes} = [ times() ];
return;
}
sub poe_sessions_end {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $session_limit, 'session_destroys', $elapsed, $session_limit/$elapsed );
print "session_destroys times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
$_[KERNEL]->yield( 'stdin_read' );
return;
}
# How many times can we select/unselect READ a from STDIN filehandle per second?
sub poe_stdin_read {
# stupid, but we have to skip those tests
if ( $eventloop eq 'Tk' or $eventloop eq 'Prima' ) {
print "SKIPPING STDIN tests on broken loop: $eventloop\n";
$_[KERNEL]->yield( 'myfh_read' );
return;
}
my $start = time();
my @start_times = times();
eval {
for (my $i = 0; $i < $select_limit; $i++) {
$_[KERNEL]->select_read( *STDIN, 'whee' );
$_[KERNEL]->select_read( *STDIN );
}
};
if ( $@ ) {
print "filehandle select_read on STDIN FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $select_limit, 'select_read_STDIN', $elapsed, $select_limit/$elapsed );
print "select_read_STDIN times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'stdin_write' );
return;
}
# How many times can we select/unselect WRITE a from STDIN filehandle per second?
sub poe_stdin_write {
my $start = time();
my @start_times = times();
eval {
for (my $i = 0; $i < $select_limit; $i++) {
$_[KERNEL]->select_write( *STDIN, 'whee' );
$_[KERNEL]->select_write( *STDIN );
}
};
if ( $@ ) {
print "filehandle select_write on STDIN FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $select_limit, 'select_write_STDIN', $elapsed, $select_limit/$elapsed );
print "select_write_STDIN times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'myfh_read' );
return;
}
# How many times can we select/unselect READ a real filehandle?
sub poe_myfh_read {
# stupid, but we have to skip those tests
if ( $eventloop eq 'Event_Lib' or $eventloop eq 'Tk' or $eventloop eq 'Prima' ) {
print "SKIPPING MYFH tests on broken loop: $eventloop\n";
$_[KERNEL]->yield( 'calls' );
return;
}
my $start = time();
my @start_times = times();
eval {
open( my $fh, '+>', 'poebench' ) or die $!;
for (my $i = 0; $i < $select_limit; $i++) {
$_[KERNEL]->select_read( $fh, 'whee' );
$_[KERNEL]->select_read( $fh );
}
close( $fh ) or die $!;
unlink( 'poebench' ) or die $!;
};
if ( $@ ) {
print "filehandle select_read on MYFH FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $select_limit, 'select_read_MYFH', $elapsed, $select_limit/$elapsed );
print "select_read_MYFH times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'myfh_write' );
return;
}
# How many times can we select/unselect WRITE a real filehandle?
sub poe_myfh_write {
my $start = time();
my @start_times = times();
eval {
open( my $fh, '+>', 'poebench' ) or die $!;
for (my $i = 0; $i < $select_limit; $i++) {
$_[KERNEL]->select_write( $fh, 'whee' );
$_[KERNEL]->select_write( $fh );
}
close( $fh ) or die $!;
unlink( 'poebench' ) or die $!;
};
if ( $@ ) {
print "filehandle select_write on MYFH FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $select_limit, 'select_write_MYFH', $elapsed, $select_limit/$elapsed );
print "select_write_MYFH times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'calls' );
return;
}
# How many times can we call a state?
sub poe_calls {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $call_limit; $i++) {
$_[KERNEL]->call( $_[SESSION], 'null' );
}
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $call_limit, 'calls', $elapsed, $call_limit/$elapsed );
print "calls times: @start_times @end_times\n";
$_[KERNEL]->yield( 'eventsquirt' );
return;
}
# How many events can we squirt through POE, one at a time?
sub poe_eventsquirt {
$_[HEAP]->{start} = time();
$_[HEAP]->{starttimes} = [ times() ];
$_[HEAP]->{yield_count} = $through_limit;
$_[KERNEL]->yield( 'eventsquirt_done' );
return;
}
sub poe_eventsquirt_done {
if (--$_[HEAP]->{yield_count}) {
$_[KERNEL]->yield( 'eventsquirt_done' );
} else {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $through_limit, 'single_posts', $elapsed, $through_limit/$elapsed );
print "single_posts times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
}
# reached end of tests!
return;
}
# Get the memory footprint
sub dump_pidinfo {
my $ret = open( my $fh, '<', '/proc/self/status' );
if ( defined $ret ) {
while ( <$fh> ) {
- print "pidinfo: $_";
+ chomp;
+ if ( $_ ne '' ) {
+ print "pidinfo: $_\n";
+ }
}
close( $fh ) or die $!;
} else {
print "UNABLE TO GET /proc/self/status\n";
}
return;
}
# print the local Perl info
sub dump_perlinfo {
print "Running under perl binary: " . $^X . "\n";
require Config;
my $config = Config::myconfig();
foreach my $l ( split( /\n/, $config ) ) {
print "perlconfig: $l\n";
}
return;
}
# print the local system information
sub dump_sysinfo {
print "Running under machine: " . `uname -a` . "\n";
# get cpuinfo
my $ret = open( my $fh, '<', '/proc/cpuinfo' );
if ( defined $ret ) {
while ( <$fh> ) {
chomp;
if ( $_ ne '' ) {
print "cpuinfo: $_\n";
}
}
close( $fh ) or die $!;
} else {
print "UNABLE TO GET /proc/cpuinfo\n";
}
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::SubProcess - Implements the actual POE benchmarks
=head1 SYNOPSIS
perl -MPOE::Devel::Benchmarker::SubProcess -e 'benchmark()'
=head1 ABSTRACT
This package is responsible for implementing the guts of the benchmarks, and timing them.
=head1 EXPORT
Nothing.
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/Utils.pm b/lib/POE/Devel/Benchmarker/Utils.pm
index 4093cca..3c0cc64 100644
--- a/lib/POE/Devel/Benchmarker/Utils.pm
+++ b/lib/POE/Devel/Benchmarker/Utils.pm
@@ -1,199 +1,210 @@
# Declare our package
package POE::Devel::Benchmarker::Utils;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
-$VERSION = '0.03';
+$VERSION = '0.04';
# auto-export the only sub we have
require Exporter;
use vars qw( @ISA @EXPORT_OK );
@ISA = qw(Exporter);
-@EXPORT_OK = qw( poeloop2load loop2realversion beautify_times knownloops );
+@EXPORT_OK = qw( poeloop2load loop2realversion beautify_times knownloops generateTestfile );
+
+# returns the filename for a particular test
+sub generateTestfile {
+ my $heap = shift;
+
+ return 'POE-' . $heap->{'current_version'} .
+ '-' . $heap->{'current_loop'} .
+ '-' . ( $heap->{'lite_tests'} ? 'LITE' : 'HEAVY' ) .
+ '-' . ( $heap->{'current_assertions'} ? 'assert' : 'noassert' ) .
+ '-' . ( $heap->{'current_noxsqueue'} ? 'noxsqueue' : 'xsqueue' );
+}
# returns the proper "load" stuff for a specific loop
sub poeloop2load {
my $eventloop = shift;
# Decide which event loop to use
# Event_Lib EV Glib Prima Gtk Wx Kqueue Tk Select IO_Poll
if ( $eventloop eq 'Event' ) {
return 'Event';
} elsif ( $eventloop eq 'IO_Poll' ) {
return 'IO::Poll';
} elsif ( $eventloop eq 'Event_Lib' ) {
return 'Event::Lib';
} elsif ( $eventloop eq 'EV' ) {
return 'EV';
} elsif ( $eventloop eq 'Glib' ) {
return 'Glib';
} elsif ( $eventloop eq 'Tk' ) {
return 'Tk',
} elsif ( $eventloop eq 'Gtk' ) {
return 'Gtk';
} elsif ( $eventloop eq 'Prima' ) {
return 'Prima';
} elsif ( $eventloop eq 'Wx' ) {
return 'Wx';
} elsif ( $eventloop eq 'Kqueue' ) {
# FIXME dunno what to do here!
return;
} elsif ( $eventloop eq 'Select' ) {
return;
} else {
die "Unknown event loop!";
}
}
# returns the version of the "real" installed module that the loop uses
sub loop2realversion {
my $eventloop = shift;
# Decide which event loop to use
if ( ! defined $eventloop ) {
return;
} elsif ( $eventloop eq 'Event' ) {
return $Event::VERSION;
} elsif ( $eventloop eq 'IO_Poll' ) {
return $IO::Poll::VERSION;
} elsif ( $eventloop eq 'Event_Lib' ) {
return $Event::Lib::VERSION;
} elsif ( $eventloop eq 'EV' ) {
return $EV::VERSION;
} elsif ( $eventloop eq 'Glib' ) {
return $Glib::VERSION;
} elsif ( $eventloop eq 'Tk' ) {
return $Tk::VERSION;
} elsif ( $eventloop eq 'Gtk' ) {
return $Gtk::VERSION;
} elsif ( $eventloop eq 'Prima' ) {
return $Prima::VERSION;
} elsif ( $eventloop eq 'Wx' ) {
return $Wx::VERSION;
} elsif ( $eventloop eq 'Kqueue' ) {
# FIXME how do I do this?
return;
} elsif ( $eventloop eq 'Select' ) {
return 'BUILTIN';
} else {
die "Unknown event loop!";
}
}
# helper routine to parse times() output
sub beautify_times {
my $string = shift;
my $origdata = shift;
# split it up
$string =~ s/^\s+//; $string =~ s/\s+$//;
my @times = split( /\s+/, $string );
# make the data struct
# ($user,$system,$cuser,$csystem) = times;
my $data = {
'user' => $times[4] - $times[0],
'sys' => $times[5] - $times[1],
'cuser' => $times[6] - $times[2],
'csys' => $times[7] - $times[3],
};
# add original data?
if ( $origdata ) {
$data->{'s_user'} = $times[0];
$data->{'s_sys'} = $times[1];
$data->{'s_cuser'} = $times[2];
$data->{'s_csys'} = $times[3];
$data->{'e_user'} = $times[4];
$data->{'e_sys'} = $times[5];
$data->{'e_cuser'} = $times[6];
$data->{'e_csys'} = $times[7];
}
# send it back!
return $data;
}
# returns a list of "known" POE loops
sub knownloops {
return [ qw( Event_Lib EV Glib Prima Gtk Wx Kqueue Tk Select IO_Poll ) ];
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::Utils - Various utility routines for POE::Devel::Benchmarker
=head1 SYNOPSIS
perl -MPOE::Devel::Benchmarker::Utils -e 'print poeloop2load( "IO_Poll" )'
=head1 ABSTRACT
This package contains the utility routines and constants that POE::Devel::Benchmarker needs.
=head1 EXPORT
This package exports those subs via @EXPORT_OK:
=over 4
=item knownloops()
Returns an arrayref of the "known" POE loops as of this version of the Benchmarker
=item poeloop2load()
Returns the "parent" class to load for a specific loop. An example is:
$real = poeloop2load( 'IO_Poll' ); # $real now contains "IO::Poll"
=item loop2realversion()
Returns the version of the "parent" class for a specific loop. An example is:
$ver = loop2realversion( 'IO_Poll' ); # $ver now contains $IO::Poll::VERSION
=item beautify_times()
Returns a hashref of data from parsing 2 consecutive times() structures in a string. You can pass an additional parameter
( boolean ) to include the original data. An example is:
print Data::Dumper::Dumper( beautify_times( '0.1 0 0 0 0.1 0 0.76 0.09', 1 ) );
{
"sys" => 0, # total system time
"user" => 0, # total user time
"csys" => 0.76 # total children system time
"cuser" => 0.08 # total children user time
"e_csys" => "0.09", # end children system time ( optional )
"e_cuser" => "0.76", # end children user time ( optional )
"e_sys" => 0, # end system time ( optional )
"e_user" => "0.1", # end user time ( optional )
"s_csys" => 0, # start children system time ( optional )
"s_cuser" => 0, # start children user time ( optional )
"s_sys" => 0, # start system time ( optional )
"s_user" => "0.1" # start user time ( optional )
}
=back
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
|
apocalypse/perl-poe-benchmarker
|
b3cdd9ba0811eb1c9043a2c9706910b60adaf254
|
pushing changes for 0.03
|
diff --git a/Build.PL b/Build.PL
index bd6131b..ac7ac95 100755
--- a/Build.PL
+++ b/Build.PL
@@ -1,94 +1,97 @@
# Build.PL
use Module::Build;
my $build = Module::Build->new(
# look up Module::Build::API for the info!
'dynamic_config' => 0,
'module_name' => 'POE::Devel::Benchmarker',
'license' => 'perl',
'dist_abstract' => "Benchmarking POE's performance ( acts more like a smoker )",
'dist_author' => 'Apocalypse <APOCAL@cpan.org>',
'create_packlist' => 1,
'create_makefile_pl' => 'traditional',
'create_readme' => 1,
'test_files' => 't/*.t',
'add_to_cleanup' => [ 'META.yml', 'Makefile.PL', 'README' ], # automatically generated
'requires' => {
# POE Stuff
'POE' => 0,
'POE::Session::AttributeBased' => 0,
# misc perl stuff
'Time::HiRes' => 0,
'version' => 0,
'Devel::Hide' => 0,
# Analyzer reqs
'YAML::Tiny' => 0,
#'POE::Component::SimpleDBI' => 0,
# GetPOEdists reqs
'LWP::UserAgent' => 0,
'HTML::LinkExtor' => 0,
'URI::URL' => 0,
'Archive::Tar' => 0,
},
'recommends' => {
# Test stuff
'Test::More' => '0.86', # require latest for note() support in t/a_is_prereq_outdated.t
# our POE loops!
'POE::Loop::Event' => 0,
'POE::Loop::Event_Lib' => 0,
'POE::Loop::EV' => 0,
'POE::Loop::Glib' => 0,
'POE::Loop::Prima' => 0,
'POE::Loop::Gtk' => 0,
'POE::Loop::Wx' => 0,
'POE::Loop::Kqueue' => 0,
# included in POE ( listed here for completeness )
#'POE::Loop::Tk' => 0,
#'POE::Loop::Select' => 0,
#'POE::Loop::IO_Poll' => 0,
# the loops' dependencies
'Event' => 0,
'Event::Lib' => 0,
'EV' => 0,
'Glib' => 0,
'Prima' => 0,
'Gtk' => 0,
'Wx' => 0,
'Tk' => 0,
+
+ # the XS queue
+ 'POE::XS::Queue::Array' => 0,
},
# FIXME wishlist...
# 'test_requires' => {
# # Test stuff
# 'Test::Compile' => 0,
# 'Test::Perl::Critic' => 0,
# 'Test::Dependencies' => 0,
# 'Test::Distribution' => 0,
# 'Test::Fixme' => 0,
# 'Test::HasVersion' => 0,
# 'Test::Kwalitee' => 0,
# 'Test::CheckManifest' => 0,
# 'Test::MinimumVersion' => 0,
# 'Test::Pod::Coverage' => 0,
# 'Test::Spelling' => 0,
# 'Test::Pod' => 0,
# 'Test::Prereq' => 0,
# 'Test::Strict' => 0,
# 'Test::UseAllModules' => 0,
# },
);
# all done!
$build->create_build_script;
diff --git a/Changes b/Changes
index fff05b7..f769f3b 100755
--- a/Changes
+++ b/Changes
@@ -1,16 +1,21 @@
Revision history for Perl extension POE::Devel::Benchmarker
* 0.03
Added the loop option to benchmark(), thanks dngor!
- More redocumentation
+ Added the poe option to benchmark(), thanks dngor!
+ Added the noxsqueue option to benchmark()
+ Added the noasserts option to benchmark()
+ Automatically enable noxsqueue option if we cannot load POE::XS::Queue::Array, saving time
Bump Test::More version requirement because some people reported failures with note()
+ Fixed bug in SubProcess where it crashed on old POEs that didn't load IO::Handle
+ More documentation additions/tweaks
* 0.02
Added the Analyzer module ( and dump YAML files, yay! )
A lot of minor changes+tweaks to get a better dump format
* 0.01
initial release
diff --git a/POE-Devel-Benchmarker-0.03.tar.gz b/POE-Devel-Benchmarker-0.03.tar.gz
new file mode 100644
index 0000000..1b39258
Binary files /dev/null and b/POE-Devel-Benchmarker-0.03.tar.gz differ
diff --git a/lib/POE/Devel/Benchmarker.pm b/lib/POE/Devel/Benchmarker.pm
index efd3d56..f2fd8a3 100644
--- a/lib/POE/Devel/Benchmarker.pm
+++ b/lib/POE/Devel/Benchmarker.pm
@@ -1,714 +1,840 @@
# Declare our package
package POE::Devel::Benchmarker;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.03';
# auto-export the only sub we have
BEGIN {
require Exporter;
use vars qw( @ISA @EXPORT );
@ISA = qw(Exporter);
@EXPORT = qw( benchmark );
}
# Import what we need from the POE namespace
sub POE::Kernel::ASSERT_DEFAULT { 1 }
sub POE::Session::ASSERT_DEFAULT { 1 }
use POE qw( Session Filter::Line Wheel::Run );
use base 'POE::Session::AttributeBased';
# we need hires times
use Time::HiRes qw( time );
# load comparison stuff
use version;
# Load our stuff
use POE::Devel::Benchmarker::GetInstalledLoops;
-use POE::Devel::Benchmarker::Utils qw( poeloop2load );
+use POE::Devel::Benchmarker::Utils qw( poeloop2load knownloops );
use POE::Devel::Benchmarker::Analyzer;
# Actually run the tests!
sub benchmark {
my $options = shift;
# set default options
my $lite_tests = 1;
my $quiet_mode = 0;
- my $forceloops = undef; # default to all known loops in GetInstalledLoops
+ my $forceloops = undef; # default to autoprobe all
+ my $forcepoe = undef; # default to all found POE versions in poedists/
+ my $forcenoxsqueue = 0; # default to try and load it
+ my $forcenoasserts = 0; # default is to run it
# process our options
if ( defined $options and ref $options and ref( $options ) eq 'HASH' ) {
+ # process NO for XS::Queue::Array
+ if ( exists $options->{'noxsqueue'} ) {
+ if ( $options->{'noxsqueue'} ) {
+ $forcenoxsqueue = 1;
+ }
+ }
+
+ # process NO for ASSERT
+ if ( exists $options->{'noasserts'} ) {
+ if ( $options->{'noasserts'} ) {
+ $forcenoasserts = 1;
+ }
+ }
+
# process LITE tests
if ( exists $options->{'litetests'} ) {
if ( $options->{'litetests'} ) {
$lite_tests = 1;
} else {
$lite_tests = 0;
}
}
# process quiet mode
if ( exists $options->{'quiet'} ) {
if ( $options->{'quiet'} ) {
$quiet_mode = 1;
} else {
$quiet_mode = 0;
}
}
# process forceloops
if ( exists $options->{'loop'} and defined $options->{'loop'} ) {
if ( ! ref $options->{'loop'} ) {
# split it via CSV
$forceloops = [ split( /,/, $options->{'loop'} ) ];
foreach ( @$forceloops ) {
$_ =~ s/^\s+//; $_ =~ s/\s+$//;
}
} else {
# treat it as array
$forceloops = $options->{'loop'};
}
+
+ # check for !loop modules
+ my @noloops;
+ foreach my $l ( @$forceloops ) {
+ if ( $l =~ /^\!/ ) {
+ push( @noloops, substr( $l, 1 ) );
+ }
+ }
+ if ( scalar @noloops ) {
+ # replace the forceloops with ALL known, then subtract noloops from it
+ my %bad;
+ @bad{@noloops} = () x @noloops;
+ @$forceloops = grep { !exists $bad{$_} } @{ knownloops() };
+ }
+ }
+
+ # process the poe versions
+ if ( exists $options->{'poe'} and defined $options->{'poe'} ) {
+ if ( ! ref $options->{'poe'} ) {
+ # split it via CSV
+ $forcepoe = [ split( /,/, $options->{'poe'} ) ];
+ foreach ( @$forcepoe ) {
+ $_ =~ s/^\s+//; $_ =~ s/\s+$//;
+ }
+ } else {
+ # treat it as array
+ $forcepoe = $options->{'poe'};
+ }
}
}
# do some sanity checks
if ( ! -d 'poedists' ) {
die "The 'poedists' directory is not found in the working directory!";
}
if ( ! -d 'results' ) {
die "The 'results' directory is not found in the working directory!";
}
if ( ! $quiet_mode ) {
print "[BENCHMARKER] Starting up...\n";
}
# Create our session
POE::Session->create(
__PACKAGE__->inline_states(),
'heap' => {
- 'lite_tests' => $lite_tests,
- 'quiet_mode' => $quiet_mode,
- 'forceloops' => $forceloops,
+ # misc stuff
+ 'quiet_mode' => $quiet_mode,
+
+ # override our testing behavior
+ 'lite_tests' => $lite_tests,
+ 'forceloops' => $forceloops,
+ 'forcepoe' => $forcepoe,
+ 'forcenoxsqueue' => $forcenoxsqueue,
+ 'forcenoasserts' => $forcenoasserts,
},
);
# Fire 'er up!
POE::Kernel->run();
return;
}
# Starts up our session
sub _start : State {
# okay, get all the dists we can!
my @versions;
if ( opendir( DISTS, 'poedists' ) ) {
foreach my $d ( readdir( DISTS ) ) {
if ( $d =~ /^POE\-(.+)$/ and $d !~ /\.tar\.gz$/ ) {
push( @versions, $1 );
}
}
closedir( DISTS ) or die $!;
} else {
print "[BENCHMARKER] Unable to open 'poedists' for reading: $!\n";
return;
}
+ # sanity
+ if ( ! scalar @versions ) {
+ print "[BENCHMARKER] Unable to find any POE version in the 'poedists' directory!\n";
+ return;
+ }
+
+ # should we munge the versions list?
+ if ( defined $_[HEAP]->{'forcepoe'} ) {
+ # check for !poe versions
+ my @nopoe;
+ foreach my $p ( @{ $_[HEAP]->{'forcepoe'} } ) {
+ if ( $p =~ /^\!/ ) {
+ push( @nopoe, substr( $p, 1 ) );
+ }
+ }
+ if ( scalar @nopoe ) {
+ # remove the nopoe versions from the found
+ my %bad;
+ @bad{@nopoe} = () x @nopoe;
+ @versions = grep { !exists $bad{$_} } @versions;
+ } else {
+ # make sure the @versions contains only what we specified
+ my %good;
+ @good{ @{ $_[HEAP]->{'forcepoe'} } } = () x @{ $_[HEAP]->{'forcepoe'} };
+ @versions = grep { exists $good{$_} } @versions;
+ }
+
+ # again, make sure we have at least a version, ha!
+ if ( ! scalar @versions ) {
+ print "[BENCHMARKER] Unable to find any POE version in the 'poedists' directory!\n";
+ return;
+ }
+ }
+
# set our alias
$_[KERNEL]->alias_set( 'Benchmarker' );
# sanely handle some signals
$_[KERNEL]->sig( 'INT', 'handle_kill' );
$_[KERNEL]->sig( 'TERM', 'handle_kill' );
# okay, go through all the dists in version order
@versions = sort { $b <=> $a }
map { version->new( $_ ) } @versions;
# Store the versions in our heap
$_[HEAP]->{'VERSIONS'} = \@versions;
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Detected available POE versions -> " . join( " ", @versions ) . "\n";
}
# First of all, we need to find out what loop libraries are installed
getPOEloops( $_[HEAP]->{'quiet_mode'}, $_[HEAP]->{'forceloops'} );
return;
}
sub _stop : State {
# tell the wheel to kill itself
if ( defined $_[HEAP]->{'WHEEL'} ) {
$_[HEAP]->{'WHEEL'}->kill( 9 );
undef $_[HEAP]->{'WHEEL'};
}
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Shutting down...\n";
}
return;
}
# misc POE handlers
sub _child : State {
return;
}
sub handle_kill : State {
return;
}
# we received list of loops from GetInstalledLoops
sub found_loops : State {
$_[HEAP]->{'installed_loops'} = [ sort { $a cmp $b } @{ $_[ARG0] } ];
# sanity check
if ( scalar @{ $_[HEAP]->{'installed_loops'} } == 0 ) {
print "[BENCHMARKER] Detected no available POE::Loop, check your configuration?!?\n";
return;
}
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Detected available POE::Loops -> " . join( " ", @{ $_[HEAP]->{'installed_loops'} } ) . "\n";
}
+ # Okay, do we have XS::Queue installed?
+ if ( ! $_[HEAP]->{'forcenoxsqueue'} ) {
+ eval { require POE::XS::Queue::Array };
+ if ( $@ ) {
+ $_[HEAP]->{'forcenoxsqueue'} = 1;
+ }
+ }
+
# Fire up the analyzer
initAnalyzer( $_[HEAP]->{'quiet_mode'} );
# start the benchmark!
$_[KERNEL]->yield( 'run_benchmark' );
return;
}
# Runs one benchmark
sub run_benchmark : State {
# Grab the version from the top of the array
$_[HEAP]->{'current_version'} = shift @{ $_[HEAP]->{'VERSIONS'} };
# did we run out of versions?
if ( ! defined $_[HEAP]->{'current_version'} ) {
# We're done, let POE die...
$_[KERNEL]->alias_remove( 'Benchmarker' );
} else {
$_[HEAP]->{'loops'} = [ @{ $_[HEAP]->{'installed_loops'} } ];
# okay, fire off the first loop
$_[KERNEL]->yield( 'bench_loop' );
}
return;
}
# runs one loop
sub bench_loop : State {
# select our current loop
$_[HEAP]->{'current_loop'} = shift @{ $_[HEAP]->{'loops'} };
# are we done with all loops?
if ( ! defined $_[HEAP]->{'current_loop'} ) {
# yay, go back to the main handler
$_[KERNEL]->yield( 'run_benchmark' );
} else {
# Start the assert test
- $_[HEAP]->{'assertions'} = [ qw( 0 1 ) ];
+ if ( $_[HEAP]->{'forcenoasserts'} ) {
+ $_[HEAP]->{'assertions'} = [ qw( 0 ) ];
+ } else {
+ $_[HEAP]->{'assertions'} = [ qw( 0 1 ) ];
+ }
$_[KERNEL]->yield( 'bench_asserts' );
}
return;
}
# runs an assertion
sub bench_asserts : State {
# select our current assert state
$_[HEAP]->{'current_assertions'} = shift @{ $_[HEAP]->{'assertions'} };
# are we done?
if ( ! defined $_[HEAP]->{'current_assertions'} ) {
# yay, go back to the loop handler
$_[KERNEL]->yield( 'bench_loop' );
} else {
# Start the xsqueue test
- $_[HEAP]->{'xsqueue'} = [ qw( 0 1 ) ];
+ if ( $_[HEAP]->{'forcenoxsqueue'} ) {
+ $_[HEAP]->{'noxsqueue'} = [ qw( 1 ) ];
+ } else {
+ $_[HEAP]->{'noxsqueue'} = [ qw( 0 1 ) ];
+ }
$_[KERNEL]->yield( 'bench_xsqueue' );
}
return;
}
# runs test with or without xsqueue
sub bench_xsqueue : State {
- # select our current xsqueue state
- $_[HEAP]->{'current_xsqueue'} = shift @{ $_[HEAP]->{'xsqueue'} };
+ # select our current noxsqueue state
+ $_[HEAP]->{'current_noxsqueue'} = shift @{ $_[HEAP]->{'noxsqueue'} };
# are we done?
- if ( ! defined $_[HEAP]->{'current_xsqueue'} ) {
+ if ( ! defined $_[HEAP]->{'current_noxsqueue'} ) {
# yay, go back to the assert handler
$_[KERNEL]->yield( 'bench_asserts' );
} else {
# actually fire off the subprocess, ha!
$_[KERNEL]->yield( 'create_subprocess' );
}
return;
}
# actually runs the subprocess
sub create_subprocess : State {
# Okay, start testing this specific combo!
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "Testing POE v" . $_[HEAP]->{'current_version'} .
" loop(" . $_[HEAP]->{'current_loop'} . ')' .
" assertions(" . ( $_[HEAP]->{'current_assertions'} ? 'ENABLED' : 'DISABLED' ) . ')' .
- " xsqueue(" . ( $_[HEAP]->{'current_xsqueue'} ? 'ENABLED' : 'DISABLED' ) . ')' .
+ " xsqueue(" . ( $_[HEAP]->{'current_noxsqueue'} ? 'DISABLED' : 'ENABLED' ) . ')' .
"\n";
}
# save the starttime
$_[HEAP]->{'current_starttime'} = time();
$_[HEAP]->{'current_starttimes'} = [ times() ];
# Okay, create the wheel::run to handle this
my $looploader = poeloop2load( $_[HEAP]->{'current_loop'} );
$_[HEAP]->{'WHEEL'} = POE::Wheel::Run->new(
'Program' => $^X,
'ProgramArgs' => [ '-Ipoedists/POE-' . $_[HEAP]->{'current_version'},
'-Ipoedists/POE-' . $_[HEAP]->{'current_version'} . '/lib',
( defined $looploader ? "-M$looploader" : () ),
'-MPOE::Devel::Benchmarker::SubProcess',
'-e',
'POE::Devel::Benchmarker::SubProcess::benchmark',
$_[HEAP]->{'current_version'},
$_[HEAP]->{'current_loop'},
$_[HEAP]->{'current_assertions'},
$_[HEAP]->{'lite_tests'},
- $_[HEAP]->{'current_xsqueue'},
+ $_[HEAP]->{'current_noxsqueue'},
],
# Kill off existing FD's
'CloseOnCall' => 1,
# setup our data handlers
'StdoutEvent' => 'Got_STDOUT',
'StderrEvent' => 'Got_STDERR',
# the error handler
'ErrorEvent' => 'Got_ERROR',
'CloseEvent' => 'Got_CLOSED',
# set our filters
'StderrFilter' => POE::Filter::Line->new(),
'StdoutFilter' => POE::Filter::Line->new(),
);
if ( ! defined $_[HEAP]->{'WHEEL'} ) {
die 'Unable to create a new wheel!';
} else {
# smart CHLD handling
if ( $_[KERNEL]->can( "sig_child" ) ) {
$_[KERNEL]->sig_child( $_[HEAP]->{'WHEEL'}->PID => 'Got_CHLD' );
} else {
$_[KERNEL]->sig( 'CHLD', 'Got_CHLD' );
}
}
# setup our data we received from the subprocess
$_[HEAP]->{'current_data'} = '';
# Okay, we timeout this test after some time for sanity
$_[HEAP]->{'test_timedout'} = 0;
if ( $_[HEAP]->{'lite_tests'} ) {
# on my core2duo 1.2ghz laptop, running Gtk+LITE+assert+noxsqueue takes approx 45s
$_[HEAP]->{'TIMER'} = $_[KERNEL]->delay_set( 'test_timedout' => 60 * 2 );
} else {
# on my core2duo 1.2ghz laptop, running Gtk+HEAVY+assert+noxsqueue takes all day long :(
$_[HEAP]->{'TIMER'} = $_[KERNEL]->delay_set( 'test_timedout' => 60 * 15 );
}
return;
}
# Got a CHLD event!
sub Got_CHLD : State {
$_[KERNEL]->sig_handled();
return;
}
# Handles child STDERR output
sub Got_STDERR : State {
my $input = $_[ARG0];
# save it!
$_[HEAP]->{'current_data'} .= '!STDERR: ' . $input . "\n";
return;
}
# Handles child STDOUT output
sub Got_STDOUT : State {
my $input = $_[ARG0];
# save it!
$_[HEAP]->{'current_data'} .= $input . "\n";
return;
}
# Handles child error
sub Got_ERROR : State {
# Copied from POE::Wheel::Run manpage
my ( $operation, $errnum, $errstr ) = @_[ ARG0 .. ARG2 ];
# ignore exit 0 errors
if ( $errnum != 0 ) {
print "[BENCHMARKER] Wheel::Run got an $operation error $errnum: $errstr\n";
}
return;
}
# Handles child DIE'ing
sub Got_CLOSED : State {
# Get rid of the wheel
undef $_[HEAP]->{'WHEEL'};
# get rid of the delay
$_[KERNEL]->alarm_remove( $_[HEAP]->{'TIMER'} );
undef $_[HEAP]->{'TIMER'};
# wrap up this test
$_[KERNEL]->yield( 'wrapup_test' );
return;
}
# a test timed out, unfortunately!
sub test_timedout : State {
# tell the wheel to kill itself
$_[HEAP]->{'WHEEL'}->kill( 9 );
undef $_[HEAP]->{'WHEEL'};
if ( ! $_[HEAP]->{'quiet_mode'} ) {
- print "[BENCHMARKER] Test TimedOut!\n";
+ print "[BENCHMARKER] Test Timed Out!\n";
}
$_[HEAP]->{'test_timedout'} = 1;
# wrap up this test
$_[KERNEL]->yield( 'wrapup_test' );
return;
}
# finalizes a test
sub wrapup_test : State {
# we're done with this benchmark!
$_[HEAP]->{'current_endtime'} = time();
$_[HEAP]->{'current_endtimes'} = [ times() ];
# store the data
my $file = 'POE-' . $_[HEAP]->{'current_version'} .
'-' . $_[HEAP]->{'current_loop'} .
( $_[HEAP]->{'current_assertions'} ? '-assert' : '-noassert' ) .
- ( $_[HEAP]->{'current_xsqueue'} ? '-xsqueue' : '-noxsqueue' );
+ ( $_[HEAP]->{'current_noxsqueue'} ? '-noxsqueue' : '-xsqueue' );
if ( open( my $fh, '>', "results/$file" ) ) {
print $fh "STARTTIME: " . $_[HEAP]->{'current_starttime'} . " -> TIMES " . join( " ", @{ $_[HEAP]->{'current_starttimes'} } ) . "\n";
print $fh "$file\n";
print $fh $_[HEAP]->{'current_data'} . "\n";
if ( $_[HEAP]->{'test_timedout'} ) {
print $fh "\nTEST TERMINATED DUE TO TIMEOUT\n";
}
print $fh "ENDTIME: " . $_[HEAP]->{'current_endtime'} . " -> TIMES " . join( " ", @{ $_[HEAP]->{'current_endtimes'} } ) . "\n";
close( $fh ) or die $!;
} else {
print "[BENCHMARKER] Unable to open results/$file for writing -> $!\n";
}
# Send the data to the Analyzer to process
$_[KERNEL]->post( 'Benchmarker::Analyzer', 'analyze', {
'poe_version' => $_[HEAP]->{'current_version'}->stringify, # YAML::Tiny doesn't like version objects :(
'poe_loop' => 'POE::Loop::' . $_[HEAP]->{'current_loop'},
'asserts' => $_[HEAP]->{'current_assertions'},
- 'xsqueue' => $_[HEAP]->{'current_xsqueue'},
+ 'noxsqueue' => $_[HEAP]->{'current_noxsqueue'},
'litetests' => $_[HEAP]->{'lite_tests'},
'start_time' => $_[HEAP]->{'current_starttime'},
'start_times' => [ @{ $_[HEAP]->{'current_starttimes'} } ],
'end_time' => $_[HEAP]->{'current_endtime'},
'end_times' => [ @{ $_[HEAP]->{'current_endtimes'} } ],
'timedout' => $_[HEAP]->{'test_timedout'},
'rawdata' => $_[HEAP]->{'current_data'},
'test_file' => $file,
} );
# process the next test
$_[KERNEL]->yield( 'bench_xsqueue' );
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker - Benchmarking POE's performance ( acts more like a smoker )
=head1 SYNOPSIS
perl -MPOE::Devel::Benchmarker -e 'benchmark()'
=head1 ABSTRACT
This package of tools is designed to benchmark POE's performace across different
configurations. The current "tests" are:
=over 4
=item posts
This tests how long it takes to post() N times
This tests how long it took to dispatch/deliver all the posts enqueued in the post() test
This tests how long it took to yield() between 2 states for N times
=item calls
This tests how long it took to call() N times
=item alarms
This tests how long it took to add N alarms via alarm(), overwriting each other
This tests how long it took to add N alarms via alarm_add() and how long it took to delete them all
NOTE: alarm_add is not available on all versions of POE!
=item sessions
This tests how long it took to create N sessions, and how long it took to destroy them all
=item filehandles
This tests how long it took to toggle select_read N times on STDIN and a real filehandle via open()
This tests how long it took to toggle select_write N times on STDIN and a real filehandle via open()
=item POE startup time
This tests how long it took to start + close N instances of a "virgin" POE without any sessions/etc
=item POE Loops
This is actually a "super" test where all of the specific tests is ran against various POE::Loop::XYZ/FOO for comparison
=item POE Assertions
This is actually a "super" test where all of the specific tests is ran against POE with/without assertions enabled
=item POE::XS::Queue::Array
This is actually a "super" test where all of the specific tests is ran against POE with XS goodness enabled/disabled
=back
=head1 DESCRIPTION
This module is poorly documented now. Please give me some time to properly document it over time :)
=head2 INSTALLATION
Here's a simple outline to get you up to speed quickly. ( and smoking! )
=over 4
=item Install CPAN package + dependencies
Download+install the POE::Devel::Benchmarker package from CPAN
apoc@apoc-x300:~$ cpanp -i POE::Devel::Benchmarker
=item Setup initial directories
Go anywhere, and create the "parent" directory where you'll be storing test results + stuff. For this example,
I have chosen to use ~/poe-benchmarker:
apoc@apoc-x300:~$ mkdir poe-benchmarker
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ mkdir poedists
apoc@apoc-x300:~/poe-benchmarker$ mkdir results
apoc@apoc-x300:~/poe-benchmarker$ cd poedists/
apoc@apoc-x300:~/poe-benchmarker/poedists$ perl -MPOE::Devel::Benchmarker::GetPOEdists -e 'getPOEdists( 1 )'
( go get a coffee while it downloads if you're on a slow link, ha! )
=item Let 'er rip!
At this point you can start running the benchmark!
NOTE: the Benchmarker expects everything to be in the "local" directory!
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker -e 'benchmark()'
( go sleep or something, this will take a while! )
=back
=head2 BENCHMARKING
+On startup the Benchmarker will look in the "poedists" directory and load all the distributions it sees untarred there. Once
+that is done it will begin autoprobing for available POE::Loop packages. Once it determines what's available, it will begin
+the benchmarks.
+
+As the Benchmarker goes through the combinations of POE + Eventloop + Assertions + XS::Queue it will dump data into
+the results directory. The Analyzer module also dumps YAML output in the same place, with the suffix of ".yml"
+
This module exposes only one subroutine, the benchmark() one. You can pass a hashref to it to set various options. Here is
a list of the valid options:
=over 4
+=item noxsqueue => boolean
+
+This will tell the Benchmarker to force the unavailability of POE::XS::Queue::Array and skip those tests.
+
+NOTE: The Benchmarker will set this automatically if it cannot load the module!
+
+ benchmark( { noxsqueue => 1 } );
+
+default: false
+
+=item noasserts => boolean
+
+This will tell the Benchmarker to not run the ASSERT tests.
+
+ benchmark( { noasserts => 1 } );
+
+default: false
+
=item litetests => boolean
This enables the "lite" tests which will not take up too much time.
benchmark( { litetests => 0 } );
default: true
=item quiet => boolean
This enables quiet mode which will not print anything to the console except for errors.
benchmark( { 'quiet' => 1 } );
default: false
=item loop => csv list or array
-This overrides the built-in loop detection algorithm and tries to locate the specified loops.
+This overrides the built-in loop detection algorithm which searches for all known loops.
+
+There is some "magic" here where you can put a negative sign in front of a loop and we will NOT run that.
NOTE: Capitalization is important!
- benchmark( { 'loop' => 'IO_Poll,Select' } );
- benchmark( { 'loop' => [ qw( Tk Gtk ) ] } );
+ benchmark( { 'loop' => 'IO_Poll,Select' } ); # runs only IO::Poll and Select
+ benchmark( { 'loop' => [ qw( Tk Gtk ) ] } ); # runs only Tk and Gtk
+ benchmark( { 'loop' => '-Tk' } ); # runs all available loops EXCEPT for TK
Known loops: Event_Lib EV Glib Prima Gtk Wx Kqueue Tk Select IO_Poll
-=back
+=item poe => csv list or array
-As the Benchmarker goes through the combinations of POE + Eventloop + Assertions + XS::Queue it will dump data into
-the results directory. The Analyzer module also dumps YAML output in the same place, with the suffix of ".yml"
+This overrides the built-in POE version detection algorithm which pulls the POE versions from the 'poedists' directory.
+
+There is some "magic" here where you can put a negative sign in front of a version and we will NOT run that.
+
+NOTE: The Benchmarker will ignore versions that wasn't found in the directory!
+
+ benchmark( { 'poe' => '0.35,1.003' } ); # runs on 0.35 and 1.003
+ benchmark( { 'poe' => [ qw( 0.3009 0.12 ) ] } ); # runs on 0.3009 and 0.12
+ benchmark( { 'poe' => '-0.35' } ); # runs ALL tests except 0.35
+
+=back
=head2 ANALYZING RESULTS
Please look at the L<POE::Devel::Benchmarker::Analyzer> module.
=head2 HOW DO I?
This section will explain the miscellaneous questions and preemptively answer any concerns :)
-=head3 Skip a POE version
-
-Simply delete it from the poedists directory. The Benchmarker will automatically look in that and load POE versions. If
-you wanted to test only 1 version - just delete all directories except for that one.
-
-Keep in mind that the Benchmarker will not automatically untar archives, only the Benchmarker::GetPOEdists module
-does that!
-
=head3 Skip a specific benchmark
Why would you want to? That's the whole point of this suite!
=head3 Create graphs
This will be added to the module soon. However if you have the time+energy, please feel free to dig into the YAML output
that Benchmarker::Analyzer outputs.
=head3 Restarting where the Benchmarker left off
-This isn't implemented yet. You could always manually delete the POE versions that was tested and proceed with the rest.
+This isn't implemented yet. You could always manually delete the POE versions that was tested and proceed with the rest. Or,
+use the 'poe' option to benchmark() and tweak the values.
=head1 EXPORT
Automatically exports the benchmark() subroutine.
=head1 TODO
=over 4
=item Perl version smoking
We should be able to run the benchmark over different Perl versions. This would require some fiddling with our
layout + logic. It's not that urgent because the workaround is to simply execute the benchmarker under a different
perl binary. It's smart enough to use $^X to be consistent across tests/subprocesses :)
=item Select the EV backend
<Khisanth> and if you are benchmarking, try it with POE using EV with EV using Glib? :P
<Apocalypse> I'm not sure how to configure the EV "backend" yet
<Apocalypse> too much docs for me to read hah
<Khisanth> Apocalypse: use EV::Glib; use Glib; use POE; :)
-=item Disable POE::XS::Queue::Array tests if not found
-
-Currently we blindly move on and test with/without this. We should be smarter and not waste one extra test per iteration
-if it isn't installed!
-
=item Be smarter in smoking timeouts
Currently we depend on the litetests option and hardcode some values including the timeout. If your machine is incredibly
slow, there's a chance that it could timeout unnecessarily. Please look at the outputs and check to see if there are unusual
failures, and inform me.
Also, some loops perform badly and take almost forever! /me glares at Gtk...
=item More benchmarks!
As usual, me and the crowd in #poe have plenty of ideas for tests. We'll be adding them over time, but if you have an idea please
drop me a line and let me know!
dngor said there was some benchmarks in the POE svn under trunk/queue...
I want a bench that actually tests socket traffic - stream 10MB of traffic over localhost, and time it?
LotR and Tapout contributed some samples, let's see if I can integrate them...
=item Add SQLite/DBI/etc support to the Analyzer
It would be nice if we could have a local SQLite db to dump our stats into. This would make arbitrary reports much easier than
loading raw YAML files and trying to make sense of them, ha! Also, this means somebody can do the smoking and send the SQLite
db to another person to generate the graphs, cool!
=item Kqueue loop support
As I don't have access to a *BSD box, I cannot really test this. Furthermore, it isn't clear on how I can force/unload this
module from POE...
=item Wx loop support
I have Wx installed, but it doesn't work. Obviously I don't know how to use Wx ;)
If you have experience, please drop me a line on how to do the "right" thing to get Wx loaded under POE. Here's the error:
Can't call method "MainLoop" on an undefined value at /usr/local/share/perl/5.8.8/POE/Loop/Wx.pm line 91.
-=item XS loop support
+=item XS::Loop support
The POE::XS::Loop::* modules theoretically could be tested too. However, they will only work in POE >= 1.003! This renders
the concept somewhat moot. Maybe, after POE has progressed some versions we can implement this...
=back
=head1 SEE ALSO
L<POE>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
BIG THANKS goes to Rocco Caputo E<lt>rcaputo@cpan.orgE<gt> for the first benchmarks!
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/Analyzer.pm b/lib/POE/Devel/Benchmarker/Analyzer.pm
index 69a60c6..7536be5 100644
--- a/lib/POE/Devel/Benchmarker/Analyzer.pm
+++ b/lib/POE/Devel/Benchmarker/Analyzer.pm
@@ -1,455 +1,456 @@
# Declare our package
package POE::Devel::Benchmarker::Analyzer;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
-$VERSION = '0.01';
+$VERSION = '0.03';
# auto-export the only sub we have
BEGIN {
require Exporter;
use vars qw( @ISA @EXPORT );
@ISA = qw(Exporter);
@EXPORT = qw( initAnalyzer );
}
# Import what we need from the POE namespace
use POE qw( Session );
use base 'POE::Session::AttributeBased';
# use the power of YAML
use YAML::Tiny qw( Dump );
# Load the utils
use POE::Devel::Benchmarker::Utils qw( beautify_times );
# fires up the engine
sub initAnalyzer {
my $quiet_mode = shift;
# create our session!
POE::Session->create(
POE::Devel::Benchmarker::Analyzer->inline_states(),
'heap' => {
'quiet_mode' => $quiet_mode,
},
);
}
# Starts up our session
sub _start : State {
# set our alias
$_[KERNEL]->alias_set( 'Benchmarker::Analyzer' );
# TODO connect to SQLite db via SimpleDBI?
return;
}
sub _stop : State {
return;
}
sub _child : State {
return;
}
sub analyze : State {
# get the data
my $test = $_[ARG0];
# clean up the times() stuff
$test->{'times'} = beautify_times(
join( " ", @{ delete $test->{'start_times'} } ) .
" " .
join( " ", @{ delete $test->{'end_times'} } )
);
# setup the perl version
$test->{'perlconfig'}->{'v'} = sprintf( "%vd", $^V );
# Okay, break it down into our data struct
$test->{'benchmark'} = {};
my $d = $test->{'benchmark'};
my @unknown;
foreach my $l ( split( /(?:\n|\r)/, $test->{'rawdata'} ) ) {
# skip empty lines
if ( $l eq '' ) { next }
# usual test benchmark output
# 10 startups in 0.885 seconds ( 11.302 per second)
# 10000 posts in 0.497 seconds ( 20101.112 per second)
if ( $l =~ /^\s+(\d+)\s+(\w+)\s+in\s+([\d\.]+)\s+seconds\s+\(\s+([\d\.]+)\s+per\s+second\)$/ ) {
$d->{ $2 }->{'loops'} = $1;
$d->{ $2 }->{'time'} = $3;
$d->{ $2 }->{'iterations_per_second'} = $4;
# usual test benchmark times output
# startup times: 0.1 0 0 0 0.1 0 0.76 0.09
} elsif ( $l =~ /^(\w+)\s+times:\s+(.+)$/ ) {
$d->{ $1 }->{'times'} = beautify_times( $2 );
# parse the memory footprint stuff
} elsif ( $l =~ /^pidinfo:\s+(.+)$/ ) {
# what should we analyze?
my $pidinfo = $1;
# VmPeak: 16172 kB
if ( $pidinfo =~ /^VmPeak:\s+(.+)$/ ) {
$test->{'pidinfo'}->{'vmpeak'} = $1;
# voluntary_ctxt_switches: 10
} elsif ( $pidinfo =~ /^voluntary_ctxt_switches:\s+(.+)$/ ) {
$test->{'pidinfo'}->{'voluntary_ctxt'} = $1;
# nonvoluntary_ctxt_switches: 1221
} elsif ( $pidinfo =~ /^nonvoluntary_ctxt_switches:\s+(.+)$/ ) {
$test->{'pidinfo'}->{'nonvoluntary_ctxt'} = $1;
} else {
# ignore the rest of the fluff
}
# parse the perl binary stuff
} elsif ( $l =~ /^perlconfig:\s+(.+)$/ ) {
# what should we analyze?
my $perlconfig = $1;
# Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
if ( $perlconfig =~ /^Summary\s+of\s+my\s+perl\d\s+\(([^\)]+)\)/ ) {
$test->{'perlconfig'}->{'version'} = $1;
} else {
# ignore the rest of the fluff
}
# parse the CPU info
} elsif ( $l =~ /^cpuinfo:\s+(.+)$/ ) {
# what should we analyze?
my $cpuinfo = $1;
# FIXME if this is on a multiproc system, we will overwrite the data per processor ( harmless? )
# cpu MHz : 1201.000
if ( $cpuinfo =~ /^cpu\s+MHz\s+:\s+(.+)$/ ) {
$test->{'cpuinfo'}->{'mhz'} = $1;
# model name : Intel(R) Core(TM)2 Duo CPU L7100 @ 1.20GHz
} elsif ( $cpuinfo =~ /^model\s+name\s+:\s+(.+)$/ ) {
$test->{'cpuinfo'}->{'name'} = $1;
# bogomips : 2397.58
} elsif ( $cpuinfo =~ /^bogomips\s+:\s+(.+)$/ ) {
$test->{'cpuinfo'}->{'bogomips'} = $1;
} else {
# ignore the rest of the fluff
}
# data that we can safely throw away
- } elsif ( $l eq 'TEST TERMINATED DUE TO TIMEOUT' or
- $l eq 'Using NO Assertions!' or
+ } elsif ( $l eq 'Using NO Assertions!' or
$l eq 'Using FULL Assertions!' or
$l eq 'Using the LITE tests' or
$l eq 'Using the HEAVY tests' or
$l eq 'DISABLING POE::XS::Queue::Array' or
$l eq '!STDERR: Devel::Hide hides POE/XS/Queue/Array.pm' or
$l eq 'LETTING POE find POE::XS::Queue::Array' or
$l eq 'UNABLE TO GET /proc/self/status' or
- $l eq 'UNABLE TO GET /proc/cpuinfo' ) {
+ $l eq 'UNABLE TO GET /proc/cpuinfo' or
+ $l eq '!STDERR: POE::Kernel\'s run() method was never called.' or # to ignore old POEs that threw this warning
+ $l eq 'TEST TERMINATED DUE TO TIMEOUT' ) {
# ignore them
# parse the perl binary stuff
} elsif ( $l =~ /^Running\s+under\s+perl\s+binary:\s+(.+)$/ ) {
$test->{'perlconfig'}->{'binary'} = $1;
# the master loop version ( what the POE::Loop::XYZ actually uses )
# Using loop: EV-3.49
} elsif ( $l =~ /^Using\s+master\s+loop:\s+(.+)$/ ) {
$test->{'poe_loop_master'} = $1;
# the real POE version that was loaded
# Using POE-1.001
} elsif ( $l =~ /^Using\s+POE-(.+)$/ ) {
$test->{'poe_version_loaded'} = $1;
# the various queue/loop modules we loaded
# POE is using: POE::XS::Queue::Array v0.005
# POE is using: POE::Queue v1.2328
# POE is using: POE::Loop::EV v0.06
} elsif ( $l =~ /^POE\s+is\s+using:\s+([^\s]+)\s+v(.+)$/ ) {
$test->{'poe_modules'}->{ $1 } = $2;
# get the uname info
# Running under machine: Linux apoc-x300 2.6.24-21-generic #1 SMP Tue Oct 21 23:43:45 UTC 2008 i686 GNU/Linux
} elsif ( $l =~ /^Running\s+under\s+machine:\s+(.+)$/ ) {
$test->{'uname'} = $1;
# the SubProcess version
} elsif ( $l =~ /^SubProcess-(.+)$/ ) {
$test->{'benchmarker_version'} = $1;
# parse the SKIP tests
# SKIPPING MYFH tests on broken loop: Event_Lib
# SKIPPING STDIN tests on broken loop: Tk
} elsif ( $l =~ /^SKIPPING\s+(\w+)\s+tests\s+on\s+broken/ ) {
my $fh = $1;
# nullify the data struct for that
foreach my $type ( qw( select_read select_write ) ) {
$d->{ $type . $fh }->{'loops'} = undef;
$d->{ $type . $fh }->{'time'} = undef;
$d->{ $type . $fh }->{'times'} = undef;
$d->{ $type . $fh }->{'iterations_per_second'} = undef;
}
# parse the FH/STDIN failures
# filehandle select_read on STDIN FAILED: error
# filehandle select_write on MYFH FAILED: foo
} elsif ( $l =~ /^filehandle\s+(\w+)\s+on\s+(\w+)\s+FAILED:/ ) {
my( $mode, $type ) = ( $1, $2 );
# nullify the data struct for that
$d->{ $mode . $type }->{'loops'} = undef;
$d->{ $mode . $type }->{'time'} = undef;
$d->{ $mode . $type }->{'times'} = undef;
$d->{ $mode . $type }->{'iterations_per_second'} = undef;
# parse the alarm_add skip
# alarm_add NOT SUPPORTED on this version of POE, skipping alarm_adds/alarm_clears tests!
} elsif ( $l =~ /^alarm_add\s+NOT\s+SUPPORTED\s+on/ ) {
# nullify the data struct for that
foreach my $type ( qw( alarm_adds alarm_clears ) ) {
$d->{ $type }->{'loops'} = undef;
$d->{ $type }->{'time'} = undef;
$d->{ $type }->{'times'} = undef;
$d->{ $type }->{'iterations_per_second'} = undef;
}
# parse any STDERR output
# !STDERR: unable to foo
} elsif ( $l =~ /^\!STDERR:\s+(.+)$/ ) {
push( @{ $test->{'stderr'} }, $1 );
} else {
# unknown line :(
push( @unknown, $l );
}
}
# Get rid of the rawdata
delete $test->{'rawdata'};
# Dump the unknowns
if ( @unknown ) {
print "[ANALYZER] Unknown output from benchmark -> " . Dump( \@unknown );
}
# Dump the data struct we have to the file.yml
my $yaml_file = 'results/' . delete $test->{'test_file'};
$yaml_file .= '.yml';
my $ret = open( my $fh, '>', $yaml_file );
if ( defined $ret ) {
print $fh Dump( $test );
if ( ! close( $fh ) ) {
print "[ANALYZER] Unable to close $yaml_file -> " . $! . "\n";
}
} else {
print "[ANALYZER] Unable to open $yaml_file for writing -> " . $! . "\n";
}
# TODO send the $test data struct to a DB
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::Analyzer - Analyzes the output from the benchmarks
=head1 SYNOPSIS
Don't use this module directly. Please use POE::Devel::Benchmarker.
=head1 ABSTRACT
This package implements the guts of converting the raw data into a machine-readable format. Furthermore, it dumps the data
in YAML format.
=head1 EXPORT
Automatically exports the initAnalyzer() sub
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
# sample test output ( from SubProcess v0.02 )
STARTTIME: 1229173634.36228 -> TIMES 0.17 0.02 0.76 0.12
POE-1.003-Event_Lib-noassert-noxsqueue
Using master loop: Event_Lib-1.03
Using NO Assertions!
Using the LITE tests
LETTING POE find POE::XS::Queue::Array
Using POE-1.003
POE is using: POE::XS::Queue::Array v0.005
POE is using: POE::Queue v1.2328
POE is using: POE::Loop::Event_Lib v0.001_01
10 startups in 0.898 seconds ( 11.134 per second)
startup times: 0.1 0.01 0 0 0.1 0.01 0.81 0.09
10000 posts in 0.372 seconds ( 26896.254 per second)
posts times: 0.1 0.01 0.81 0.09 0.42 0.06 0.81 0.09
10000 dispatches in 0.658 seconds ( 15196.902 per second)
dispatches times: 0.42 0.06 0.81 0.09 1.06 0.06 0.81 0.09
10000 alarms in 1.020 seconds ( 9802.144 per second)
alarms times: 1.07 0.06 0.81 0.09 1.89 0.26 0.81 0.09
10000 alarm_adds in 0.415 seconds ( 24111.902 per second)
alarm_adds times: 1.89 0.26 0.81 0.09 2.3 0.26 0.81 0.09
10000 alarm_clears in 0.221 seconds ( 45239.068 per second)
alarm_clears times: 2.3 0.26 0.81 0.09 2.52 0.26 0.81 0.09
500 session_creates in 0.114 seconds ( 4367.120 per second)
session_creates times: 2.52 0.26 0.81 0.09 2.63 0.27 0.81 0.09
500 session destroys in 0.116 seconds ( 4311.978 per second)
session_destroys times: 2.63 0.27 0.81 0.09 2.74 0.28 0.81 0.09
10000 select_read_STDIN in 2.003 seconds ( 4992.736 per second)
select_read_STDIN times: 2.74 0.28 0.81 0.09 4.66 0.35 0.81 0.09
10000 select_write_STDIN in 1.971 seconds ( 5074.097 per second)
select_write_STDIN times: 4.66 0.35 0.81 0.09 6.56 0.39 0.81 0.09
SKIPPING MYFH tests on broken loop: Event_Lib
10000 calls in 0.213 seconds ( 46963.378 per second)
calls times: 6.56 0.39 0.81 0.09 6.78 0.39 0.81 0.09
10000 single_posts in 1.797 seconds ( 5565.499 per second)
single_posts times: 6.78 0.39 0.81 0.09 8.13 0.83 0.81 0.09
pidinfo: Name: perl
pidinfo: State: R (running)
pidinfo: Tgid: 6750
pidinfo: Pid: 6750
pidinfo: PPid: 6739
pidinfo: TracerPid: 0
pidinfo: Uid: 1000 1000 1000 1000
pidinfo: Gid: 1000 1000 1000 1000
pidinfo: FDSize: 32
pidinfo: Groups: 4 20 24 25 29 30 44 46 107 109 115 127 1000 1001
pidinfo: VmPeak: 14916 kB
pidinfo: VmSize: 14756 kB
pidinfo: VmLck: 0 kB
pidinfo: VmHWM: 11976 kB
pidinfo: VmRSS: 11828 kB
pidinfo: VmData: 10104 kB
pidinfo: VmStk: 84 kB
pidinfo: VmExe: 1044 kB
pidinfo: VmLib: 2180 kB
pidinfo: VmPTE: 24 kB
pidinfo: Threads: 1
pidinfo: SigQ: 0/16182
pidinfo: SigPnd: 0000000000000000
pidinfo: ShdPnd: 0000000000000000
pidinfo: SigBlk: 0000000000000000
pidinfo: SigIgn: 0000000000001080
pidinfo: SigCgt: 0000000180000000
pidinfo: CapInh: 0000000000000000
pidinfo: CapPrm: 0000000000000000
pidinfo: CapEff: 0000000000000000
pidinfo: Cpus_allowed: 03
pidinfo: Mems_allowed: 1
pidinfo: voluntary_ctxt_switches: 11
pidinfo: nonvoluntary_ctxt_switches: 697
Running under perl binary: /usr/bin/perl
perlconfig: Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
perlconfig: Platform:
perlconfig: osname=linux, osvers=2.6.15.7, archname=i486-linux-gnu-thread-multi
perlconfig: uname='linux palmer 2.6.15.7 #1 smp thu sep 7 19:42:20 utc 2006 i686 gnulinux '
perlconfig: config_args='-Dusethreads -Duselargefiles -Dccflags=-DDEBIAN -Dcccdlflags=-fPIC -Darchname=i486-linux-gnu -Dprefix=/usr -Dprivlib=/usr/share/perl/5.8 -Darchlib=/usr/lib/perl/5.8 -Dvendorprefix=/usr -Dvendorlib=/usr/share/perl5 -Dvendorarch=/usr/lib/perl5 -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl/5.8.8 -Dsitearch=/usr/local/lib/perl/5.8.8 -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 -Dsiteman1dir=/usr/local/man/man1 -Dsiteman3dir=/usr/local/man/man3 -Dman1ext=1 -Dman3ext=3perl -Dpager=/usr/bin/sensible-pager -Uafs -Ud_csh -Ud_ualarm -Uusesfio -Uusenm -Duseshrplib -Dlibperl=libperl.so.5.8.8 -Dd_dosuid -des'
perlconfig: hint=recommended, useposix=true, d_sigaction=define
perlconfig: usethreads=define use5005threads=undef useithreads=define usemultiplicity=define
perlconfig: useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
perlconfig: use64bitint=undef use64bitall=undef uselongdouble=undef
perlconfig: usemymalloc=n, bincompat5005=undef
perlconfig: Compiler:
perlconfig: cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBIAN -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
perlconfig: optimize='-O2',
perlconfig: cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBIAN -fno-strict-aliasing -pipe -I/usr/local/include'
perlconfig: ccversion='', gccversion='4.2.3 20071123 (prerelease) (Ubuntu 4.2.2-3ubuntu4)', gccosandvers=''
perlconfig: intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
perlconfig: d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
perlconfig: ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
perlconfig: alignbytes=4, prototype=define
perlconfig: Linker and Libraries:
perlconfig: ld='cc', ldflags =' -L/usr/local/lib'
perlconfig: libpth=/usr/local/lib /lib /usr/lib
perlconfig: libs=-lgdbm -lgdbm_compat -ldb -ldl -lm -lpthread -lc -lcrypt
perlconfig: perllibs=-ldl -lm -lpthread -lc -lcrypt
perlconfig: libc=/lib/libc-2.6.1.so, so=so, useshrplib=true, libperl=libperl.so.5.8.8
perlconfig: gnulibc_version='2.6.1'
perlconfig: Dynamic Linking:
perlconfig: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
perlconfig: cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib'
Running under machine: Linux apoc-x300 2.6.24-21-generic #1 SMP Tue Oct 21 23:43:45 UTC 2008 i686 GNU/Linux
cpuinfo: processor : 0
cpuinfo: vendor_id : GenuineIntel
cpuinfo: cpu family : 6
cpuinfo: model : 15
cpuinfo: model name : Intel(R) Core(TM)2 Duo CPU L7100 @ 1.20GHz
cpuinfo: stepping : 11
cpuinfo: cpu MHz : 1201.000
cpuinfo: cache size : 4096 KB
cpuinfo: physical id : 0
cpuinfo: siblings : 2
cpuinfo: core id : 0
cpuinfo: cpu cores : 2
cpuinfo: fdiv_bug : no
cpuinfo: hlt_bug : no
cpuinfo: f00f_bug : no
cpuinfo: coma_bug : no
cpuinfo: fpu : yes
cpuinfo: fpu_exception : yes
cpuinfo: cpuid level : 10
cpuinfo: wp : yes
cpuinfo: flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc arch_perfmon pebs bts pni monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr lahf_lm ida
cpuinfo: bogomips : 2397.58
cpuinfo: clflush size : 64
cpuinfo:
cpuinfo: processor : 1
cpuinfo: vendor_id : GenuineIntel
cpuinfo: cpu family : 6
cpuinfo: model : 15
cpuinfo: model name : Intel(R) Core(TM)2 Duo CPU L7100 @ 1.20GHz
cpuinfo: stepping : 11
cpuinfo: cpu MHz : 1201.000
cpuinfo: cache size : 4096 KB
cpuinfo: physical id : 0
cpuinfo: siblings : 2
cpuinfo: core id : 1
cpuinfo: cpu cores : 2
cpuinfo: fdiv_bug : no
cpuinfo: hlt_bug : no
cpuinfo: f00f_bug : no
cpuinfo: coma_bug : no
cpuinfo: fpu : yes
cpuinfo: fpu_exception : yes
cpuinfo: cpuid level : 10
cpuinfo: wp : yes
cpuinfo: flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc arch_perfmon pebs bts pni monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr lahf_lm ida
cpuinfo: bogomips : 2394.02
cpuinfo: clflush size : 64
cpuinfo:
ENDTIME: 1229173644.30093 -> TIMES 0.19 0.02 1.08 0.16
diff --git a/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm b/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm
index 7646c79..d2e5e9f 100644
--- a/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm
+++ b/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm
@@ -1,211 +1,211 @@
# Declare our package
package POE::Devel::Benchmarker::GetInstalledLoops;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
-$VERSION = '0.02';
+$VERSION = '0.03';
# auto-export the only sub we have
BEGIN {
require Exporter;
use vars qw( @ISA @EXPORT );
@ISA = qw(Exporter);
@EXPORT = qw( getPOEloops );
}
# Import what we need from the POE namespace
use POE qw( Session Filter::Line Wheel::Run );
use base 'POE::Session::AttributeBased';
# Get the utils
use POE::Devel::Benchmarker::Utils qw ( knownloops );
# analyzes the installed perl directory for available loops
sub getPOEloops {
my $quiet_mode = shift;
my $forceloops = shift;
# create our session!
POE::Session->create(
POE::Devel::Benchmarker::GetInstalledLoops->inline_states(),
'heap' => {
'quiet_mode' => $quiet_mode,
'loops' => $forceloops,
},
);
}
# Starts up our session
sub _start : State {
# set our alias
$_[KERNEL]->alias_set( 'Benchmarker::GetInstalledLoops' );
# load our known list of loops
# known impossible loops:
# XS::EPoll ( must be POE > 1.003 and weird way of loading )
# XS::Poll ( must be POE > 1.003 and weird way of loading )
if ( ! defined $_[HEAP]->{'loops'} ) {
$_[HEAP]->{'loops'} = knownloops();
}
# First of all, we need to find out what loop libraries are installed
$_[HEAP]->{'found_loops'} = [];
$_[KERNEL]->yield( 'find_loops' );
return;
}
sub _stop : State {
# tell the wheel to kill itself
if ( defined $_[HEAP]->{'WHEEL'} ) {
$_[HEAP]->{'WHEEL'}->kill( 9 );
undef $_[HEAP]->{'WHEEL'};
}
return;
}
# loops over the "known" loops and sees if they are installed
sub find_loops : State {
# get the loop to test
$_[HEAP]->{'current_loop'} = shift @{ $_[HEAP]->{'loops'} };
# do we have something to test?
if ( ! defined $_[HEAP]->{'current_loop'} ) {
# we're done!
$_[KERNEL]->alias_remove( 'Benchmarker::GetInstalledLoops' );
$_[KERNEL]->post( 'Benchmarker', 'found_loops', $_[HEAP]->{'found_loops'} );
return;
} else {
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[LOOPSEARCH] Trying to find if POE::Loop::" . $_[HEAP]->{'current_loop'} . " is installed...\n";
}
# set the flag
$_[HEAP]->{'test_failure'} = 0;
}
# Okay, create the wheel::run to handle this
$_[HEAP]->{'WHEEL'} = POE::Wheel::Run->new(
'Program' => $^X,
'ProgramArgs' => [ '-MPOE',
'-MPOE::Loop::' . $_[HEAP]->{'current_loop'},
'-e',
'1',
],
# Kill off existing FD's
'CloseOnCall' => 1,
# setup our data handlers
'StdoutEvent' => 'Got_STDOUT',
'StderrEvent' => 'Got_STDERR',
# the error handler
'ErrorEvent' => 'Got_ERROR',
'CloseEvent' => 'Got_CLOSED',
# set our filters
'StderrFilter' => POE::Filter::Line->new(),
'StdoutFilter' => POE::Filter::Line->new(),
);
if ( ! defined $_[HEAP]->{'WHEEL'} ) {
die '[LOOPSEARCH] Unable to create a new wheel!';
} else {
# smart CHLD handling
if ( $_[KERNEL]->can( "sig_child" ) ) {
$_[KERNEL]->sig_child( $_[HEAP]->{'WHEEL'}->PID => 'Got_CHLD' );
} else {
$_[KERNEL]->sig( 'CHLD', 'Got_CHLD' );
}
}
return;
}
# Got a CHLD event!
sub Got_CHLD : State {
$_[KERNEL]->sig_handled();
return;
}
# Handles child STDERR output
sub Got_STDERR : State {
my $input = $_[ARG0];
# since we got an error, must be a failure
$_[HEAP]->{'test_failure'} = 1;
return;
}
# Handles child STDOUT output
sub Got_STDOUT : State {
my $input = $_[ARG0];
return;
}
# Handles child error
sub Got_ERROR : State {
# Copied from POE::Wheel::Run manpage
my ( $operation, $errnum, $errstr ) = @_[ ARG0 .. ARG2 ];
# ignore exit 0 errors
if ( $errnum != 0 ) {
warn "Wheel::Run got an $operation error $errnum: $errstr\n";
}
return;
}
# Handles child DIE'ing
sub Got_CLOSED : State {
# Get rid of the wheel
undef $_[HEAP]->{'WHEEL'};
# Did we pass this test or not?
if ( ! $_[HEAP]->{'test_failure'} ) {
push( @{ $_[HEAP]->{'found_loops'} }, $_[HEAP]->{'current_loop'} );
}
# move on to the next loop
$_[KERNEL]->yield( 'find_loops' );
return;
}
1;
__END__
=head1 NAME
=head1 SYNOPSIS
Don't use this module directly. Please use POE::Devel::Benchmarker.
POE::Devel::Benchmarker::GetInstalledLoops - Automatically detects the installed POE loops
=head1 ABSTRACT
This package implements the guts of searching for POE loops via fork/exec.
=head1 EXPORT
Automatically exports the getPOEloops() sub
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/GetPOEdists.pm b/lib/POE/Devel/Benchmarker/GetPOEdists.pm
index 7d81b67..9f65da4 100644
--- a/lib/POE/Devel/Benchmarker/GetPOEdists.pm
+++ b/lib/POE/Devel/Benchmarker/GetPOEdists.pm
@@ -1,126 +1,126 @@
# Declare our package
package POE::Devel::Benchmarker::GetPOEdists;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
-$VERSION = '0.01';
+$VERSION = '0.03';
# auto-export the only sub we have
require Exporter;
use vars qw( @ISA @EXPORT );
@ISA = qw(Exporter);
@EXPORT = qw( getPOEdists );
# import the helper modules
use LWP::UserAgent;
use HTML::LinkExtor;
use URI::URL;
use Archive::Tar;
# actually retrieves the dists!
sub getPOEdists {
# should we debug?
my $debug = shift;
# set the default URL
my $url = "http://backpan.cpan.org/authors/id/R/RC/RCAPUTO/";
# create our objects
my $ua = LWP::UserAgent->new;
my $p = HTML::LinkExtor->new;
my $tar = Archive::Tar->new;
# Request document and parse it as it arrives
print "Getting $url via LWP\n" if $debug;
my $res = $ua->request( HTTP::Request->new( GET => $url ),
sub { $p->parse( $_[0] ) },
);
# did we successfully download?
if ( $res->is_error ) {
die "unable to download directory index on BACKPAN: " . $res->status_line;
}
# Download every one!
foreach my $link ( $p->links ) {
# skip IMG stuff
if ( $link->[0] eq 'a' and $link->[1] eq 'href' ) {
# get the actual POE dists!
if ( $link->[2] =~ /^POE\-\d/ and $link->[2] =~ /\.tar\.gz$/ ) {
# download the tarball!
print "Mirroring $link->[2] via LWP\n" if $debug;
my $mirror_result = $ua->mirror( $url . $link->[2], $link->[2] );
if ( $mirror_result->is_error ) {
warn "unable to mirror $link->[2]: " . $mirror_result->status_line;
next;
}
# did we already untar this one?
my $dir = $link->[2];
$dir =~ s/\.tar\.gz$//;
if ( ! -d $dir ) {
# extract it!
print "Extracting $link->[2] via Tar\n" if $debug;
my $files = $tar->read( $link->[2], undef, { 'extract' => 'true' } );
if ( $files == 0 ) {
warn "unable to extract $link->[2]";
}
}
}
}
}
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::GetPOEdists - Automatically download all POE tarballs
=head1 SYNOPSIS
perl -MPOE::Devel::Benchmarker::GetPOEdists -e 'getPOEdists()'
=head1 ABSTRACT
This package automatically downloads all the POE tarballs from BACKPAN.
=head1 DESCRIPTION
This uses LWP + HTML::LinkExtor to retrieve POE tarballs from BACKPAN.
The tarballs are automatically downloaded to the current directory. Then, we use Archive::Tar to extract them all!
NOTE: we use LWP's useful mirror() sub which doesn't re-download files if they already exist!
=head2 getPOEdists
Normally you should pass nothing to this sub. However, if you want to debug the downloads+extractions you should pass
a true value as the first argument.
perl -MPOE::Devel::Benchmarker::GetPOEdists -e 'getPOEdists( 1 )'
=head1 EXPORT
Automatically exports the getPOEdists() sub
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/SubProcess.pm b/lib/POE/Devel/Benchmarker/SubProcess.pm
index d2469b6..5e2d2cb 100644
--- a/lib/POE/Devel/Benchmarker/SubProcess.pm
+++ b/lib/POE/Devel/Benchmarker/SubProcess.pm
@@ -1,543 +1,545 @@
# Declare our package
package POE::Devel::Benchmarker::SubProcess;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
-$VERSION = '0.02';
+$VERSION = '0.03';
# Import Time::HiRes's time()
use Time::HiRes qw( time );
# FIXME UGLY HACK here
BEGIN {
# should we enable assertions?
if ( defined $ARGV[2] and $ARGV[2] ) {
## no critic
eval "sub POE::Kernel::ASSERT_DEFAULT () { 1 }";
eval "sub POE::Session::ASSERT_STATES () { 1 }";
## use critic
}
# should we "hide" XS::Queue::Array?
if ( defined $ARGV[4] and $ARGV[4] ) {
## no critic
eval "use Devel::Hide qw( POE/XS/Queue/Array.pm )";
## use critic
}
}
# load POE
use POE;
+use POE::Session;
+use IO::Handle;
# load our utility stuff
use POE::Devel::Benchmarker::Utils qw( loop2realversion poeloop2load );
# init our global variables ( bad, haha )
my( $version, $eventloop, $asserts, $lite_tests, $pocosession );
my( $post_limit, $alarm_limit, $alarm_add_limit, $session_limit, $select_limit, $through_limit, $call_limit, $start_limit );
# the main routine which will load everything + start
sub benchmark {
# autoflush our STDOUT for sanity
STDOUT->autoflush( 1 );
# print our banner
print "SubProcess-" . __PACKAGE__->VERSION . "\n";
# process the version
process_version();
# process the eventloop
process_eventloop();
# process the assertions
process_assertions();
# process the test mode
process_testmode();
# process the XS::Queue hiding
process_xsqueue();
# actually import POE!
process_POE();
# actually run the benchmarks!
run_benchmarks();
# all done!
return;
}
sub process_version {
# Get the desired POE version
$version = $ARGV[0];
# Decide what to do
if ( ! defined $version ) {
die "Please supply a version to test!";
} elsif ( ! -d 'poedists/POE-' . $version ) {
die "That specified version does not exist!";
} else {
# we're happy...
}
return;
}
sub process_eventloop {
# Get the desired mode
$eventloop = $ARGV[1];
# print out the loop info
if ( ! defined $eventloop ) {
die "Please supply an event loop!";
} else {
my $loop = poeloop2load( $eventloop );
if ( ! defined $loop ) {
$loop = $eventloop;
}
my $v = loop2realversion( $eventloop );
if ( ! defined $v ) {
$v = 'UNKNOWN';
}
print "Using master loop: $loop-$v\n";
}
return;
}
sub process_assertions {
# Get the desired assert mode
$asserts = $ARGV[2];
if ( defined $asserts and $asserts ) {
print "Using FULL Assertions!\n";
} else {
print "Using NO Assertions!\n";
}
return;
}
sub process_testmode {
# get the desired test mode
$lite_tests = $ARGV[3];
if ( defined $lite_tests and $lite_tests ) {
print "Using the LITE tests\n";
$post_limit = 10_000;
$alarm_limit = 10_000;
$alarm_add_limit = 10_000;
$session_limit = 500;
$select_limit = 10_000;
$through_limit = 10_000;
$call_limit = 10_000;
$start_limit = 10;
} else {
print "Using the HEAVY tests\n";
$post_limit = 100_000;
$alarm_limit = 100_000;
$alarm_add_limit = 100_000;
$session_limit = 5_000;
$select_limit = 100_000;
$through_limit = 100_000;
$call_limit = 100_000;
$start_limit = 100;
}
return;
}
sub process_xsqueue {
# should we "hide" XS::Queue::Array?
if ( defined $ARGV[4] and $ARGV[4] ) {
print "DISABLING POE::XS::Queue::Array\n";
} else {
print "LETTING POE find POE::XS::Queue::Array\n";
}
return;
}
sub process_POE {
# Print the POE info
print "Using POE-" . $POE::VERSION . "\n";
# Actually print what loop POE is using
foreach my $m ( keys %INC ) {
if ( $m =~ /^POE\/(?:Loop|XS|Queue)/ ) {
# try to be smart and get version?
my $module = $m;
$module =~ s|/|::|g;
$module =~ s/\.pm$//g;
print "POE is using: $module ";
if ( defined $module->VERSION ) {
print "v" . $module->VERSION . "\n";
} else {
print "vUNKNOWN\n";
}
}
}
return;
}
sub run_benchmarks {
# run the startup test before we actually run POE
bench_startup();
# load the POE session + do the tests there
bench_poe();
# dump some misc info
dump_pidinfo();
dump_perlinfo();
dump_sysinfo();
# all done!
return;
}
sub bench_startup {
# Add the eventloop?
my $looploader = poeloop2load( $eventloop );
my @start_times = times();
my $start = time();
for (my $i = 0; $i < $start_limit; $i++) {
# FIXME should we add assertions?
# finally, fire it up!
CORE::system(
$^X,
'-Ipoedists/POE-' . $version,
'-Ipoedists/POE-' . $version . '/lib',
( defined $looploader ? "-M$looploader" : () ),
'-MPOE',
'-e',
1,
);
}
my @end_times = times();
my $elapsed = time() - $start;
printf( "\n\n% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $start_limit, 'startups', $elapsed, $start_limit/$elapsed );
print "startups times: @start_times @end_times\n";
return;
}
sub bench_poe {
# figure out POE::Session->create or POE::Session->new or what?
$pocosession = POE::Session->can( 'create' );
if ( defined $pocosession ) {
$pocosession = 'create';
} else {
$pocosession = POE::Session->can( 'spawn' );
if ( defined $pocosession ) {
$pocosession = 'spawn';
} else {
$pocosession = 'new';
}
}
# create the master sesssion + run POE!
POE::Session->$pocosession(
'inline_states' => {
# basic POE states
'_start' => \&poe__start,
'_default' => \&poe__default,
'_stop' => \&poe__stop,
'null' => \&poe_null,
# our test states
'posts' => \&poe_posts,
'posts_start' => \&poe_posts_start,
'posts_end' => \&poe_posts_end,
'alarms' => \&poe_alarms,
'manyalarms' => \&poe_manyalarms,
'sessions' => \&poe_sessions,
'sessions_end' => \&poe_sessions_end,
'stdin_read' => \&poe_stdin_read,
'stdin_write' => \&poe_stdin_write,
'myfh_read' => \&poe_myfh_read,
'myfh_write' => \&poe_myfh_write,
'calls' => \&poe_calls,
'eventsquirt' => \&poe_eventsquirt,
'eventsquirt_done' => \&poe_eventsquirt_done,
},
);
# start the kernel!
POE::Kernel->run();
return;
}
# inits our session
sub poe__start {
# fire off the first test!
$_[KERNEL]->yield( 'posts' );
return;
}
sub poe__stop {
}
sub poe__default {
return 0;
}
# a state that does nothing
sub poe_null {
return 1;
}
# How many posts per second? Post a bunch of events, keeping track of the time it takes.
sub poe_posts {
$_[KERNEL]->yield( 'posts_start' );
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $post_limit; $i++) {
$_[KERNEL]->yield( 'null' );
}
my @end_times = times();
my $elapsed = time() - $start;
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $post_limit, 'posts', $elapsed, $post_limit/$elapsed );
print "posts times: @start_times @end_times\n";
$_[KERNEL]->yield( 'posts_end' );
return;
}
sub poe_posts_start {
$_[HEAP]->{start} = time();
$_[HEAP]->{starttimes} = [ times() ];
return;
}
sub poe_posts_end {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $post_limit, 'dispatches', $elapsed, $post_limit/$elapsed );
print "dispatches times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
$_[KERNEL]->yield( 'alarms' );
return;
}
# How many alarms per second? Set a bunch of alarms and find out.
sub poe_alarms {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $alarm_limit; $i++) {
$_[KERNEL]->alarm( whee => rand(1_000_000) );
}
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $alarm_limit, 'alarms', $elapsed, $alarm_limit/$elapsed );
print "alarms times: @start_times @end_times\n";
$_[KERNEL]->alarm( 'whee' => undef );
$_[KERNEL]->yield( 'manyalarms' );
return;
}
# How many repetitive alarms per second? Set a bunch of
# additional alarms and find out. Also see how quickly they can
# be cleared.
sub poe_manyalarms {
# can this POE::Kernel support this?
if ( $_[KERNEL]->can( 'alarm_add' ) ) {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $alarm_add_limit; $i++) {
$_[KERNEL]->alarm_add( whee => rand(1_000_000) );
}
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $alarm_add_limit, 'alarm_adds', $elapsed, $alarm_add_limit/$elapsed );
print "alarm_adds times: @start_times @end_times\n";
$start = time();
@start_times = times();
$_[KERNEL]->alarm( whee => undef );
$elapsed = time() - $start;
@end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $alarm_add_limit, 'alarm_clears', $elapsed, $alarm_add_limit/$elapsed );
print "alarm_clears times: @start_times @end_times\n";
} else {
print "alarm_add NOT SUPPORTED on this version of POE, skipping alarm_adds/alarm_clears tests!\n";
}
$_[KERNEL]->yield( 'sessions' );
return;
}
# How many sessions can we create and destroy per second?
# Create a bunch of sessions, and track that time. Let them
# self-destruct, and track that as well.
sub poe_sessions {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $session_limit; $i++) {
POE::Session->$pocosession( 'inline_states' => { _start => sub {}, _stop => sub {}, _default => sub { return 0 } } );
}
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $session_limit, 'session_creates', $elapsed, $session_limit/$elapsed );
print "session_creates times: @start_times @end_times\n";
$_[KERNEL]->yield( 'sessions_end' );
$_[HEAP]->{start} = time();
$_[HEAP]->{starttimes} = [ times() ];
return;
}
sub poe_sessions_end {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $session_limit, 'session_destroys', $elapsed, $session_limit/$elapsed );
print "session_destroys times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
$_[KERNEL]->yield( 'stdin_read' );
return;
}
# How many times can we select/unselect READ a from STDIN filehandle per second?
sub poe_stdin_read {
# stupid, but we have to skip those tests
if ( $eventloop eq 'Tk' or $eventloop eq 'Prima' ) {
print "SKIPPING STDIN tests on broken loop: $eventloop\n";
$_[KERNEL]->yield( 'myfh_read' );
return;
}
my $start = time();
my @start_times = times();
eval {
for (my $i = 0; $i < $select_limit; $i++) {
$_[KERNEL]->select_read( *STDIN, 'whee' );
$_[KERNEL]->select_read( *STDIN );
}
};
if ( $@ ) {
print "filehandle select_read on STDIN FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $select_limit, 'select_read_STDIN', $elapsed, $select_limit/$elapsed );
print "select_read_STDIN times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'stdin_write' );
return;
}
# How many times can we select/unselect WRITE a from STDIN filehandle per second?
sub poe_stdin_write {
my $start = time();
my @start_times = times();
eval {
for (my $i = 0; $i < $select_limit; $i++) {
$_[KERNEL]->select_write( *STDIN, 'whee' );
$_[KERNEL]->select_write( *STDIN );
}
};
if ( $@ ) {
print "filehandle select_write on STDIN FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $select_limit, 'select_write_STDIN', $elapsed, $select_limit/$elapsed );
print "select_write_STDIN times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'myfh_read' );
return;
}
# How many times can we select/unselect READ a real filehandle?
sub poe_myfh_read {
# stupid, but we have to skip those tests
if ( $eventloop eq 'Event_Lib' or $eventloop eq 'Tk' or $eventloop eq 'Prima' ) {
print "SKIPPING MYFH tests on broken loop: $eventloop\n";
$_[KERNEL]->yield( 'calls' );
return;
}
my $start = time();
my @start_times = times();
eval {
open( my $fh, '+>', 'poebench' ) or die $!;
for (my $i = 0; $i < $select_limit; $i++) {
$_[KERNEL]->select_read( $fh, 'whee' );
$_[KERNEL]->select_read( $fh );
}
close( $fh ) or die $!;
unlink( 'poebench' ) or die $!;
};
if ( $@ ) {
print "filehandle select_read on MYFH FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $select_limit, 'select_read_MYFH', $elapsed, $select_limit/$elapsed );
print "select_read_MYFH times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'myfh_write' );
return;
}
# How many times can we select/unselect WRITE a real filehandle?
sub poe_myfh_write {
my $start = time();
my @start_times = times();
eval {
open( my $fh, '+>', 'poebench' ) or die $!;
for (my $i = 0; $i < $select_limit; $i++) {
$_[KERNEL]->select_write( $fh, 'whee' );
$_[KERNEL]->select_write( $fh );
}
close( $fh ) or die $!;
unlink( 'poebench' ) or die $!;
};
if ( $@ ) {
print "filehandle select_write on MYFH FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $select_limit, 'select_write_MYFH', $elapsed, $select_limit/$elapsed );
print "select_write_MYFH times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'calls' );
return;
}
# How many times can we call a state?
sub poe_calls {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $call_limit; $i++) {
$_[KERNEL]->call( $_[SESSION], 'null' );
}
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $call_limit, 'calls', $elapsed, $call_limit/$elapsed );
print "calls times: @start_times @end_times\n";
$_[KERNEL]->yield( 'eventsquirt' );
diff --git a/lib/POE/Devel/Benchmarker/Utils.pm b/lib/POE/Devel/Benchmarker/Utils.pm
index fea4a97..4093cca 100644
--- a/lib/POE/Devel/Benchmarker/Utils.pm
+++ b/lib/POE/Devel/Benchmarker/Utils.pm
@@ -1,199 +1,199 @@
# Declare our package
package POE::Devel::Benchmarker::Utils;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
-$VERSION = '0.02';
+$VERSION = '0.03';
# auto-export the only sub we have
require Exporter;
use vars qw( @ISA @EXPORT_OK );
@ISA = qw(Exporter);
@EXPORT_OK = qw( poeloop2load loop2realversion beautify_times knownloops );
# returns the proper "load" stuff for a specific loop
sub poeloop2load {
my $eventloop = shift;
# Decide which event loop to use
# Event_Lib EV Glib Prima Gtk Wx Kqueue Tk Select IO_Poll
if ( $eventloop eq 'Event' ) {
return 'Event';
} elsif ( $eventloop eq 'IO_Poll' ) {
return 'IO::Poll';
} elsif ( $eventloop eq 'Event_Lib' ) {
return 'Event::Lib';
} elsif ( $eventloop eq 'EV' ) {
return 'EV';
} elsif ( $eventloop eq 'Glib' ) {
return 'Glib';
} elsif ( $eventloop eq 'Tk' ) {
return 'Tk',
} elsif ( $eventloop eq 'Gtk' ) {
return 'Gtk';
} elsif ( $eventloop eq 'Prima' ) {
return 'Prima';
} elsif ( $eventloop eq 'Wx' ) {
return 'Wx';
} elsif ( $eventloop eq 'Kqueue' ) {
# FIXME dunno what to do here!
return;
} elsif ( $eventloop eq 'Select' ) {
return;
} else {
die "Unknown event loop!";
}
}
# returns the version of the "real" installed module that the loop uses
sub loop2realversion {
my $eventloop = shift;
# Decide which event loop to use
if ( ! defined $eventloop ) {
return;
} elsif ( $eventloop eq 'Event' ) {
return $Event::VERSION;
} elsif ( $eventloop eq 'IO_Poll' ) {
return $IO::Poll::VERSION;
} elsif ( $eventloop eq 'Event_Lib' ) {
return $Event::Lib::VERSION;
} elsif ( $eventloop eq 'EV' ) {
return $EV::VERSION;
} elsif ( $eventloop eq 'Glib' ) {
return $Glib::VERSION;
} elsif ( $eventloop eq 'Tk' ) {
return $Tk::VERSION;
} elsif ( $eventloop eq 'Gtk' ) {
return $Gtk::VERSION;
} elsif ( $eventloop eq 'Prima' ) {
return $Prima::VERSION;
} elsif ( $eventloop eq 'Wx' ) {
return $Wx::VERSION;
} elsif ( $eventloop eq 'Kqueue' ) {
# FIXME how do I do this?
return;
} elsif ( $eventloop eq 'Select' ) {
return 'BUILTIN';
} else {
die "Unknown event loop!";
}
}
# helper routine to parse times() output
sub beautify_times {
my $string = shift;
my $origdata = shift;
# split it up
$string =~ s/^\s+//; $string =~ s/\s+$//;
my @times = split( /\s+/, $string );
# make the data struct
# ($user,$system,$cuser,$csystem) = times;
my $data = {
'user' => $times[4] - $times[0],
'sys' => $times[5] - $times[1],
'cuser' => $times[6] - $times[2],
'csys' => $times[7] - $times[3],
};
# add original data?
if ( $origdata ) {
$data->{'s_user'} = $times[0];
$data->{'s_sys'} = $times[1];
$data->{'s_cuser'} = $times[2];
$data->{'s_csys'} = $times[3];
$data->{'e_user'} = $times[4];
$data->{'e_sys'} = $times[5];
$data->{'e_cuser'} = $times[6];
$data->{'e_csys'} = $times[7];
}
# send it back!
return $data;
}
# returns a list of "known" POE loops
sub knownloops {
return [ qw( Event_Lib EV Glib Prima Gtk Wx Kqueue Tk Select IO_Poll ) ];
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::Utils - Various utility routines for POE::Devel::Benchmarker
=head1 SYNOPSIS
perl -MPOE::Devel::Benchmarker::Utils -e 'print poeloop2load( "IO_Poll" )'
=head1 ABSTRACT
This package contains the utility routines and constants that POE::Devel::Benchmarker needs.
=head1 EXPORT
This package exports those subs via @EXPORT_OK:
=over 4
=item knownloops()
Returns an arrayref of the "known" POE loops as of this version of the Benchmarker
=item poeloop2load()
Returns the "parent" class to load for a specific loop. An example is:
$real = poeloop2load( 'IO_Poll' ); # $real now contains "IO::Poll"
=item loop2realversion()
Returns the version of the "parent" class for a specific loop. An example is:
$ver = loop2realversion( 'IO_Poll' ); # $ver now contains $IO::Poll::VERSION
=item beautify_times()
Returns a hashref of data from parsing 2 consecutive times() structures in a string. You can pass an additional parameter
( boolean ) to include the original data. An example is:
print Data::Dumper::Dumper( beautify_times( '0.1 0 0 0 0.1 0 0.76 0.09', 1 ) );
{
"sys" => 0, # total system time
"user" => 0, # total user time
"csys" => 0.76 # total children system time
"cuser" => 0.08 # total children user time
"e_csys" => "0.09", # end children system time ( optional )
"e_cuser" => "0.76", # end children user time ( optional )
"e_sys" => 0, # end system time ( optional )
"e_user" => "0.1", # end user time ( optional )
"s_csys" => 0, # start children system time ( optional )
"s_cuser" => 0, # start children user time ( optional )
"s_sys" => 0, # start system time ( optional )
"s_user" => "0.1" # start user time ( optional )
}
=back
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
|
apocalypse/perl-poe-benchmarker
|
0fb6e7fe42e28c030cf71fed7e769b7f17404ab2
|
more doc updates
|
diff --git a/Build.PL b/Build.PL
index 66b8692..bd6131b 100755
--- a/Build.PL
+++ b/Build.PL
@@ -1,94 +1,94 @@
# Build.PL
use Module::Build;
my $build = Module::Build->new(
# look up Module::Build::API for the info!
'dynamic_config' => 0,
'module_name' => 'POE::Devel::Benchmarker',
'license' => 'perl',
'dist_abstract' => "Benchmarking POE's performance ( acts more like a smoker )",
'dist_author' => 'Apocalypse <APOCAL@cpan.org>',
'create_packlist' => 1,
'create_makefile_pl' => 'traditional',
'create_readme' => 1,
'test_files' => 't/*.t',
'add_to_cleanup' => [ 'META.yml', 'Makefile.PL', 'README' ], # automatically generated
'requires' => {
# POE Stuff
'POE' => 0,
'POE::Session::AttributeBased' => 0,
# misc perl stuff
'Time::HiRes' => 0,
'version' => 0,
'Devel::Hide' => 0,
# Analyzer reqs
'YAML::Tiny' => 0,
#'POE::Component::SimpleDBI' => 0,
# GetPOEdists reqs
'LWP::UserAgent' => 0,
'HTML::LinkExtor' => 0,
'URI::URL' => 0,
'Archive::Tar' => 0,
},
'recommends' => {
# Test stuff
- 'Test::More' => 0,
+ 'Test::More' => '0.86', # require latest for note() support in t/a_is_prereq_outdated.t
# our POE loops!
'POE::Loop::Event' => 0,
'POE::Loop::Event_Lib' => 0,
'POE::Loop::EV' => 0,
'POE::Loop::Glib' => 0,
'POE::Loop::Prima' => 0,
'POE::Loop::Gtk' => 0,
'POE::Loop::Wx' => 0,
'POE::Loop::Kqueue' => 0,
# included in POE ( listed here for completeness )
#'POE::Loop::Tk' => 0,
#'POE::Loop::Select' => 0,
#'POE::Loop::IO_Poll' => 0,
# the loops' dependencies
'Event' => 0,
'Event::Lib' => 0,
'EV' => 0,
'Glib' => 0,
'Prima' => 0,
'Gtk' => 0,
'Wx' => 0,
'Tk' => 0,
},
# FIXME wishlist...
# 'test_requires' => {
# # Test stuff
# 'Test::Compile' => 0,
# 'Test::Perl::Critic' => 0,
# 'Test::Dependencies' => 0,
# 'Test::Distribution' => 0,
# 'Test::Fixme' => 0,
# 'Test::HasVersion' => 0,
# 'Test::Kwalitee' => 0,
# 'Test::CheckManifest' => 0,
# 'Test::MinimumVersion' => 0,
# 'Test::Pod::Coverage' => 0,
# 'Test::Spelling' => 0,
# 'Test::Pod' => 0,
# 'Test::Prereq' => 0,
# 'Test::Strict' => 0,
# 'Test::UseAllModules' => 0,
# },
);
# all done!
$build->create_build_script;
diff --git a/Changes b/Changes
index affe9bd..fff05b7 100755
--- a/Changes
+++ b/Changes
@@ -1,14 +1,16 @@
Revision history for Perl extension POE::Devel::Benchmarker
* 0.03
Added the loop option to benchmark(), thanks dngor!
+ More redocumentation
+ Bump Test::More version requirement because some people reported failures with note()
* 0.02
Added the Analyzer module ( and dump YAML files, yay! )
A lot of minor changes+tweaks to get a better dump format
* 0.01
initial release
diff --git a/lib/POE/Devel/Benchmarker.pm b/lib/POE/Devel/Benchmarker.pm
index ab74b17..efd3d56 100644
--- a/lib/POE/Devel/Benchmarker.pm
+++ b/lib/POE/Devel/Benchmarker.pm
@@ -1,682 +1,714 @@
# Declare our package
package POE::Devel::Benchmarker;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.03';
# auto-export the only sub we have
BEGIN {
require Exporter;
use vars qw( @ISA @EXPORT );
@ISA = qw(Exporter);
@EXPORT = qw( benchmark );
}
# Import what we need from the POE namespace
sub POE::Kernel::ASSERT_DEFAULT { 1 }
sub POE::Session::ASSERT_DEFAULT { 1 }
use POE qw( Session Filter::Line Wheel::Run );
use base 'POE::Session::AttributeBased';
# we need hires times
use Time::HiRes qw( time );
# load comparison stuff
use version;
# Load our stuff
use POE::Devel::Benchmarker::GetInstalledLoops;
use POE::Devel::Benchmarker::Utils qw( poeloop2load );
use POE::Devel::Benchmarker::Analyzer;
# Actually run the tests!
sub benchmark {
my $options = shift;
# set default options
my $lite_tests = 1;
my $quiet_mode = 0;
my $forceloops = undef; # default to all known loops in GetInstalledLoops
# process our options
if ( defined $options and ref $options and ref( $options ) eq 'HASH' ) {
# process LITE tests
if ( exists $options->{'litetests'} ) {
if ( $options->{'litetests'} ) {
$lite_tests = 1;
} else {
$lite_tests = 0;
}
}
# process quiet mode
if ( exists $options->{'quiet'} ) {
if ( $options->{'quiet'} ) {
$quiet_mode = 1;
} else {
$quiet_mode = 0;
}
}
# process forceloops
if ( exists $options->{'loop'} and defined $options->{'loop'} ) {
if ( ! ref $options->{'loop'} ) {
# split it via CSV
$forceloops = [ split( /,/, $options->{'loop'} ) ];
foreach ( @$forceloops ) {
$_ =~ s/^\s+//; $_ =~ s/\s+$//;
}
} else {
# treat it as array
$forceloops = $options->{'loop'};
}
}
}
# do some sanity checks
if ( ! -d 'poedists' ) {
die "The 'poedists' directory is not found in the working directory!";
}
if ( ! -d 'results' ) {
die "The 'results' directory is not found in the working directory!";
}
if ( ! $quiet_mode ) {
print "[BENCHMARKER] Starting up...\n";
}
# Create our session
POE::Session->create(
__PACKAGE__->inline_states(),
'heap' => {
'lite_tests' => $lite_tests,
'quiet_mode' => $quiet_mode,
'forceloops' => $forceloops,
},
);
# Fire 'er up!
POE::Kernel->run();
return;
}
# Starts up our session
sub _start : State {
# okay, get all the dists we can!
my @versions;
if ( opendir( DISTS, 'poedists' ) ) {
foreach my $d ( readdir( DISTS ) ) {
if ( $d =~ /^POE\-(.+)$/ and $d !~ /\.tar\.gz$/ ) {
push( @versions, $1 );
}
}
closedir( DISTS ) or die $!;
} else {
print "[BENCHMARKER] Unable to open 'poedists' for reading: $!\n";
return;
}
# set our alias
$_[KERNEL]->alias_set( 'Benchmarker' );
# sanely handle some signals
$_[KERNEL]->sig( 'INT', 'handle_kill' );
$_[KERNEL]->sig( 'TERM', 'handle_kill' );
# okay, go through all the dists in version order
@versions = sort { $b <=> $a }
map { version->new( $_ ) } @versions;
# Store the versions in our heap
$_[HEAP]->{'VERSIONS'} = \@versions;
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Detected available POE versions -> " . join( " ", @versions ) . "\n";
}
# First of all, we need to find out what loop libraries are installed
getPOEloops( $_[HEAP]->{'quiet_mode'}, $_[HEAP]->{'forceloops'} );
return;
}
sub _stop : State {
# tell the wheel to kill itself
if ( defined $_[HEAP]->{'WHEEL'} ) {
$_[HEAP]->{'WHEEL'}->kill( 9 );
undef $_[HEAP]->{'WHEEL'};
}
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Shutting down...\n";
}
return;
}
# misc POE handlers
sub _child : State {
return;
}
sub handle_kill : State {
return;
}
# we received list of loops from GetInstalledLoops
sub found_loops : State {
$_[HEAP]->{'installed_loops'} = [ sort { $a cmp $b } @{ $_[ARG0] } ];
# sanity check
if ( scalar @{ $_[HEAP]->{'installed_loops'} } == 0 ) {
print "[BENCHMARKER] Detected no available POE::Loop, check your configuration?!?\n";
return;
}
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Detected available POE::Loops -> " . join( " ", @{ $_[HEAP]->{'installed_loops'} } ) . "\n";
}
# Fire up the analyzer
initAnalyzer( $_[HEAP]->{'quiet_mode'} );
# start the benchmark!
$_[KERNEL]->yield( 'run_benchmark' );
return;
}
# Runs one benchmark
sub run_benchmark : State {
# Grab the version from the top of the array
$_[HEAP]->{'current_version'} = shift @{ $_[HEAP]->{'VERSIONS'} };
# did we run out of versions?
if ( ! defined $_[HEAP]->{'current_version'} ) {
# We're done, let POE die...
$_[KERNEL]->alias_remove( 'Benchmarker' );
} else {
$_[HEAP]->{'loops'} = [ @{ $_[HEAP]->{'installed_loops'} } ];
# okay, fire off the first loop
$_[KERNEL]->yield( 'bench_loop' );
}
return;
}
# runs one loop
sub bench_loop : State {
# select our current loop
$_[HEAP]->{'current_loop'} = shift @{ $_[HEAP]->{'loops'} };
# are we done with all loops?
if ( ! defined $_[HEAP]->{'current_loop'} ) {
# yay, go back to the main handler
$_[KERNEL]->yield( 'run_benchmark' );
} else {
# Start the assert test
$_[HEAP]->{'assertions'} = [ qw( 0 1 ) ];
$_[KERNEL]->yield( 'bench_asserts' );
}
return;
}
# runs an assertion
sub bench_asserts : State {
# select our current assert state
$_[HEAP]->{'current_assertions'} = shift @{ $_[HEAP]->{'assertions'} };
# are we done?
if ( ! defined $_[HEAP]->{'current_assertions'} ) {
# yay, go back to the loop handler
$_[KERNEL]->yield( 'bench_loop' );
} else {
# Start the xsqueue test
$_[HEAP]->{'xsqueue'} = [ qw( 0 1 ) ];
$_[KERNEL]->yield( 'bench_xsqueue' );
}
return;
}
# runs test with or without xsqueue
sub bench_xsqueue : State {
# select our current xsqueue state
$_[HEAP]->{'current_xsqueue'} = shift @{ $_[HEAP]->{'xsqueue'} };
# are we done?
if ( ! defined $_[HEAP]->{'current_xsqueue'} ) {
# yay, go back to the assert handler
$_[KERNEL]->yield( 'bench_asserts' );
} else {
# actually fire off the subprocess, ha!
$_[KERNEL]->yield( 'create_subprocess' );
}
return;
}
# actually runs the subprocess
sub create_subprocess : State {
# Okay, start testing this specific combo!
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "Testing POE v" . $_[HEAP]->{'current_version'} .
" loop(" . $_[HEAP]->{'current_loop'} . ')' .
" assertions(" . ( $_[HEAP]->{'current_assertions'} ? 'ENABLED' : 'DISABLED' ) . ')' .
" xsqueue(" . ( $_[HEAP]->{'current_xsqueue'} ? 'ENABLED' : 'DISABLED' ) . ')' .
"\n";
}
# save the starttime
$_[HEAP]->{'current_starttime'} = time();
$_[HEAP]->{'current_starttimes'} = [ times() ];
# Okay, create the wheel::run to handle this
my $looploader = poeloop2load( $_[HEAP]->{'current_loop'} );
$_[HEAP]->{'WHEEL'} = POE::Wheel::Run->new(
'Program' => $^X,
'ProgramArgs' => [ '-Ipoedists/POE-' . $_[HEAP]->{'current_version'},
'-Ipoedists/POE-' . $_[HEAP]->{'current_version'} . '/lib',
( defined $looploader ? "-M$looploader" : () ),
'-MPOE::Devel::Benchmarker::SubProcess',
'-e',
'POE::Devel::Benchmarker::SubProcess::benchmark',
$_[HEAP]->{'current_version'},
$_[HEAP]->{'current_loop'},
$_[HEAP]->{'current_assertions'},
$_[HEAP]->{'lite_tests'},
$_[HEAP]->{'current_xsqueue'},
],
# Kill off existing FD's
'CloseOnCall' => 1,
# setup our data handlers
'StdoutEvent' => 'Got_STDOUT',
'StderrEvent' => 'Got_STDERR',
# the error handler
'ErrorEvent' => 'Got_ERROR',
'CloseEvent' => 'Got_CLOSED',
# set our filters
'StderrFilter' => POE::Filter::Line->new(),
'StdoutFilter' => POE::Filter::Line->new(),
);
if ( ! defined $_[HEAP]->{'WHEEL'} ) {
die 'Unable to create a new wheel!';
} else {
# smart CHLD handling
if ( $_[KERNEL]->can( "sig_child" ) ) {
$_[KERNEL]->sig_child( $_[HEAP]->{'WHEEL'}->PID => 'Got_CHLD' );
} else {
$_[KERNEL]->sig( 'CHLD', 'Got_CHLD' );
}
}
# setup our data we received from the subprocess
$_[HEAP]->{'current_data'} = '';
# Okay, we timeout this test after some time for sanity
$_[HEAP]->{'test_timedout'} = 0;
if ( $_[HEAP]->{'lite_tests'} ) {
# on my core2duo 1.2ghz laptop, running Gtk+LITE+assert+noxsqueue takes approx 45s
$_[HEAP]->{'TIMER'} = $_[KERNEL]->delay_set( 'test_timedout' => 60 * 2 );
} else {
# on my core2duo 1.2ghz laptop, running Gtk+HEAVY+assert+noxsqueue takes all day long :(
$_[HEAP]->{'TIMER'} = $_[KERNEL]->delay_set( 'test_timedout' => 60 * 15 );
}
return;
}
# Got a CHLD event!
sub Got_CHLD : State {
$_[KERNEL]->sig_handled();
return;
}
# Handles child STDERR output
sub Got_STDERR : State {
my $input = $_[ARG0];
# save it!
$_[HEAP]->{'current_data'} .= '!STDERR: ' . $input . "\n";
return;
}
# Handles child STDOUT output
sub Got_STDOUT : State {
my $input = $_[ARG0];
# save it!
$_[HEAP]->{'current_data'} .= $input . "\n";
return;
}
# Handles child error
sub Got_ERROR : State {
# Copied from POE::Wheel::Run manpage
my ( $operation, $errnum, $errstr ) = @_[ ARG0 .. ARG2 ];
# ignore exit 0 errors
if ( $errnum != 0 ) {
print "[BENCHMARKER] Wheel::Run got an $operation error $errnum: $errstr\n";
}
return;
}
# Handles child DIE'ing
sub Got_CLOSED : State {
# Get rid of the wheel
undef $_[HEAP]->{'WHEEL'};
# get rid of the delay
$_[KERNEL]->alarm_remove( $_[HEAP]->{'TIMER'} );
undef $_[HEAP]->{'TIMER'};
# wrap up this test
$_[KERNEL]->yield( 'wrapup_test' );
return;
}
# a test timed out, unfortunately!
sub test_timedout : State {
# tell the wheel to kill itself
$_[HEAP]->{'WHEEL'}->kill( 9 );
undef $_[HEAP]->{'WHEEL'};
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Test TimedOut!\n";
}
$_[HEAP]->{'test_timedout'} = 1;
# wrap up this test
$_[KERNEL]->yield( 'wrapup_test' );
return;
}
# finalizes a test
sub wrapup_test : State {
# we're done with this benchmark!
$_[HEAP]->{'current_endtime'} = time();
$_[HEAP]->{'current_endtimes'} = [ times() ];
# store the data
my $file = 'POE-' . $_[HEAP]->{'current_version'} .
'-' . $_[HEAP]->{'current_loop'} .
( $_[HEAP]->{'current_assertions'} ? '-assert' : '-noassert' ) .
( $_[HEAP]->{'current_xsqueue'} ? '-xsqueue' : '-noxsqueue' );
if ( open( my $fh, '>', "results/$file" ) ) {
print $fh "STARTTIME: " . $_[HEAP]->{'current_starttime'} . " -> TIMES " . join( " ", @{ $_[HEAP]->{'current_starttimes'} } ) . "\n";
print $fh "$file\n";
print $fh $_[HEAP]->{'current_data'} . "\n";
if ( $_[HEAP]->{'test_timedout'} ) {
print $fh "\nTEST TERMINATED DUE TO TIMEOUT\n";
}
print $fh "ENDTIME: " . $_[HEAP]->{'current_endtime'} . " -> TIMES " . join( " ", @{ $_[HEAP]->{'current_endtimes'} } ) . "\n";
close( $fh ) or die $!;
} else {
print "[BENCHMARKER] Unable to open results/$file for writing -> $!\n";
}
# Send the data to the Analyzer to process
$_[KERNEL]->post( 'Benchmarker::Analyzer', 'analyze', {
'poe_version' => $_[HEAP]->{'current_version'}->stringify, # YAML::Tiny doesn't like version objects :(
'poe_loop' => 'POE::Loop::' . $_[HEAP]->{'current_loop'},
'asserts' => $_[HEAP]->{'current_assertions'},
'xsqueue' => $_[HEAP]->{'current_xsqueue'},
'litetests' => $_[HEAP]->{'lite_tests'},
'start_time' => $_[HEAP]->{'current_starttime'},
'start_times' => [ @{ $_[HEAP]->{'current_starttimes'} } ],
'end_time' => $_[HEAP]->{'current_endtime'},
'end_times' => [ @{ $_[HEAP]->{'current_endtimes'} } ],
'timedout' => $_[HEAP]->{'test_timedout'},
'rawdata' => $_[HEAP]->{'current_data'},
'test_file' => $file,
} );
# process the next test
$_[KERNEL]->yield( 'bench_xsqueue' );
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker - Benchmarking POE's performance ( acts more like a smoker )
=head1 SYNOPSIS
perl -MPOE::Devel::Benchmarker -e 'benchmark()'
=head1 ABSTRACT
This package of tools is designed to benchmark POE's performace across different
configurations. The current "tests" are:
=over 4
=item posts
+This tests how long it takes to post() N times
+
+This tests how long it took to dispatch/deliver all the posts enqueued in the post() test
+
+This tests how long it took to yield() between 2 states for N times
+
=item calls
-=item alarm_adds
+This tests how long it took to call() N times
+
+=item alarms
+
+This tests how long it took to add N alarms via alarm(), overwriting each other
+
+This tests how long it took to add N alarms via alarm_add() and how long it took to delete them all
+
+NOTE: alarm_add is not available on all versions of POE!
+
+=item sessions
-=item session creation
+This tests how long it took to create N sessions, and how long it took to destroy them all
-=item session destruction
+=item filehandles
-=item select_read toggles
+This tests how long it took to toggle select_read N times on STDIN and a real filehandle via open()
-=item select_write toggles
+This tests how long it took to toggle select_write N times on STDIN and a real filehandle via open()
=item POE startup time
+This tests how long it took to start + close N instances of a "virgin" POE without any sessions/etc
+
+=item POE Loops
+
+This is actually a "super" test where all of the specific tests is ran against various POE::Loop::XYZ/FOO for comparison
+
+=item POE Assertions
+
+This is actually a "super" test where all of the specific tests is ran against POE with/without assertions enabled
+
+=item POE::XS::Queue::Array
+
+This is actually a "super" test where all of the specific tests is ran against POE with XS goodness enabled/disabled
+
=back
=head1 DESCRIPTION
This module is poorly documented now. Please give me some time to properly document it over time :)
=head2 INSTALLATION
Here's a simple outline to get you up to speed quickly. ( and smoking! )
=over 4
=item Install CPAN package + dependencies
Download+install the POE::Devel::Benchmarker package from CPAN
apoc@apoc-x300:~$ cpanp -i POE::Devel::Benchmarker
=item Setup initial directories
Go anywhere, and create the "parent" directory where you'll be storing test results + stuff. For this example,
I have chosen to use ~/poe-benchmarker:
apoc@apoc-x300:~$ mkdir poe-benchmarker
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ mkdir poedists
apoc@apoc-x300:~/poe-benchmarker$ mkdir results
apoc@apoc-x300:~/poe-benchmarker$ cd poedists/
apoc@apoc-x300:~/poe-benchmarker/poedists$ perl -MPOE::Devel::Benchmarker::GetPOEdists -e 'getPOEdists( 1 )'
( go get a coffee while it downloads if you're on a slow link, ha! )
=item Let 'er rip!
At this point you can start running the benchmark!
NOTE: the Benchmarker expects everything to be in the "local" directory!
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker -e 'benchmark()'
( go sleep or something, this will take a while! )
=back
=head2 BENCHMARKING
This module exposes only one subroutine, the benchmark() one. You can pass a hashref to it to set various options. Here is
a list of the valid options:
=over 4
=item litetests => boolean
This enables the "lite" tests which will not take up too much time.
benchmark( { litetests => 0 } );
default: true
=item quiet => boolean
This enables quiet mode which will not print anything to the console except for errors.
benchmark( { 'quiet' => 1 } );
default: false
=item loop => csv list or array
This overrides the built-in loop detection algorithm and tries to locate the specified loops.
NOTE: Capitalization is important!
benchmark( { 'loop' => 'IO_Poll,Select' } );
benchmark( { 'loop' => [ qw( Tk Gtk ) ] } );
Known loops: Event_Lib EV Glib Prima Gtk Wx Kqueue Tk Select IO_Poll
=back
As the Benchmarker goes through the combinations of POE + Eventloop + Assertions + XS::Queue it will dump data into
the results directory. The Analyzer module also dumps YAML output in the same place, with the suffix of ".yml"
=head2 ANALYZING RESULTS
Please look at the L<POE::Devel::Benchmarker::Analyzer> module.
=head2 HOW DO I?
This section will explain the miscellaneous questions and preemptively answer any concerns :)
=head3 Skip a POE version
Simply delete it from the poedists directory. The Benchmarker will automatically look in that and load POE versions. If
you wanted to test only 1 version - just delete all directories except for that one.
Keep in mind that the Benchmarker will not automatically untar archives, only the Benchmarker::GetPOEdists module
does that!
=head3 Skip a specific benchmark
Why would you want to? That's the whole point of this suite!
=head3 Create graphs
This will be added to the module soon. However if you have the time+energy, please feel free to dig into the YAML output
that Benchmarker::Analyzer outputs.
=head3 Restarting where the Benchmarker left off
This isn't implemented yet. You could always manually delete the POE versions that was tested and proceed with the rest.
=head1 EXPORT
Automatically exports the benchmark() subroutine.
=head1 TODO
=over 4
=item Perl version smoking
We should be able to run the benchmark over different Perl versions. This would require some fiddling with our
-layout + logic. It's not that urgent because the workaround is to simply execute the smoke suite under a different
-perl binary. It's smart enough to use $^X to be consistent across tests :)
+layout + logic. It's not that urgent because the workaround is to simply execute the benchmarker under a different
+perl binary. It's smart enough to use $^X to be consistent across tests/subprocesses :)
=item Select the EV backend
<Khisanth> and if you are benchmarking, try it with POE using EV with EV using Glib? :P
<Apocalypse> I'm not sure how to configure the EV "backend" yet
<Apocalypse> too much docs for me to read hah
<Khisanth> Apocalypse: use EV::Glib; use Glib; use POE; :)
=item Disable POE::XS::Queue::Array tests if not found
Currently we blindly move on and test with/without this. We should be smarter and not waste one extra test per iteration
if it isn't installed!
=item Be smarter in smoking timeouts
Currently we depend on the litetests option and hardcode some values including the timeout. If your machine is incredibly
slow, there's a chance that it could timeout unnecessarily. Please look at the outputs and check to see if there are unusual
failures, and inform me.
Also, some loops perform badly and take almost forever! /me glares at Gtk...
=item More benchmarks!
As usual, me and the crowd in #poe have plenty of ideas for tests. We'll be adding them over time, but if you have an idea please
drop me a line and let me know!
dngor said there was some benchmarks in the POE svn under trunk/queue...
I want a bench that actually tests socket traffic - stream 10MB of traffic over localhost, and time it?
+LotR and Tapout contributed some samples, let's see if I can integrate them...
+
=item Add SQLite/DBI/etc support to the Analyzer
It would be nice if we could have a local SQLite db to dump our stats into. This would make arbitrary reports much easier than
loading raw YAML files and trying to make sense of them, ha! Also, this means somebody can do the smoking and send the SQLite
db to another person to generate the graphs, cool!
=item Kqueue loop support
As I don't have access to a *BSD box, I cannot really test this. Furthermore, it isn't clear on how I can force/unload this
module from POE...
=item Wx loop support
I have Wx installed, but it doesn't work. Obviously I don't know how to use Wx ;)
If you have experience, please drop me a line on how to do the "right" thing to get Wx loaded under POE. Here's the error:
Can't call method "MainLoop" on an undefined value at /usr/local/share/perl/5.8.8/POE/Loop/Wx.pm line 91.
=item XS loop support
The POE::XS::Loop::* modules theoretically could be tested too. However, they will only work in POE >= 1.003! This renders
the concept somewhat moot. Maybe, after POE has progressed some versions we can implement this...
=back
=head1 SEE ALSO
L<POE>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
BIG THANKS goes to Rocco Caputo E<lt>rcaputo@cpan.orgE<gt> for the first benchmarks!
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm b/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm
index f909573..7646c79 100644
--- a/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm
+++ b/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm
@@ -1,208 +1,211 @@
# Declare our package
package POE::Devel::Benchmarker::GetInstalledLoops;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.02';
# auto-export the only sub we have
BEGIN {
require Exporter;
use vars qw( @ISA @EXPORT );
@ISA = qw(Exporter);
@EXPORT = qw( getPOEloops );
}
# Import what we need from the POE namespace
use POE qw( Session Filter::Line Wheel::Run );
use base 'POE::Session::AttributeBased';
+# Get the utils
+use POE::Devel::Benchmarker::Utils qw ( knownloops );
+
# analyzes the installed perl directory for available loops
sub getPOEloops {
my $quiet_mode = shift;
my $forceloops = shift;
# create our session!
POE::Session->create(
POE::Devel::Benchmarker::GetInstalledLoops->inline_states(),
'heap' => {
'quiet_mode' => $quiet_mode,
'loops' => $forceloops,
},
);
}
# Starts up our session
sub _start : State {
# set our alias
$_[KERNEL]->alias_set( 'Benchmarker::GetInstalledLoops' );
# load our known list of loops
# known impossible loops:
# XS::EPoll ( must be POE > 1.003 and weird way of loading )
# XS::Poll ( must be POE > 1.003 and weird way of loading )
if ( ! defined $_[HEAP]->{'loops'} ) {
- $_[HEAP]->{'loops'} = [ qw( Event_Lib EV Glib Prima Gtk Wx Kqueue Tk Select IO_Poll ) ];
+ $_[HEAP]->{'loops'} = knownloops();
}
# First of all, we need to find out what loop libraries are installed
$_[HEAP]->{'found_loops'} = [];
$_[KERNEL]->yield( 'find_loops' );
return;
}
sub _stop : State {
# tell the wheel to kill itself
if ( defined $_[HEAP]->{'WHEEL'} ) {
$_[HEAP]->{'WHEEL'}->kill( 9 );
undef $_[HEAP]->{'WHEEL'};
}
return;
}
# loops over the "known" loops and sees if they are installed
sub find_loops : State {
# get the loop to test
$_[HEAP]->{'current_loop'} = shift @{ $_[HEAP]->{'loops'} };
# do we have something to test?
if ( ! defined $_[HEAP]->{'current_loop'} ) {
# we're done!
$_[KERNEL]->alias_remove( 'Benchmarker::GetInstalledLoops' );
$_[KERNEL]->post( 'Benchmarker', 'found_loops', $_[HEAP]->{'found_loops'} );
return;
} else {
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[LOOPSEARCH] Trying to find if POE::Loop::" . $_[HEAP]->{'current_loop'} . " is installed...\n";
}
# set the flag
$_[HEAP]->{'test_failure'} = 0;
}
# Okay, create the wheel::run to handle this
$_[HEAP]->{'WHEEL'} = POE::Wheel::Run->new(
'Program' => $^X,
'ProgramArgs' => [ '-MPOE',
'-MPOE::Loop::' . $_[HEAP]->{'current_loop'},
'-e',
'1',
],
# Kill off existing FD's
'CloseOnCall' => 1,
# setup our data handlers
'StdoutEvent' => 'Got_STDOUT',
'StderrEvent' => 'Got_STDERR',
# the error handler
'ErrorEvent' => 'Got_ERROR',
'CloseEvent' => 'Got_CLOSED',
# set our filters
'StderrFilter' => POE::Filter::Line->new(),
'StdoutFilter' => POE::Filter::Line->new(),
);
if ( ! defined $_[HEAP]->{'WHEEL'} ) {
die '[LOOPSEARCH] Unable to create a new wheel!';
} else {
# smart CHLD handling
if ( $_[KERNEL]->can( "sig_child" ) ) {
$_[KERNEL]->sig_child( $_[HEAP]->{'WHEEL'}->PID => 'Got_CHLD' );
} else {
$_[KERNEL]->sig( 'CHLD', 'Got_CHLD' );
}
}
return;
}
# Got a CHLD event!
sub Got_CHLD : State {
$_[KERNEL]->sig_handled();
return;
}
# Handles child STDERR output
sub Got_STDERR : State {
my $input = $_[ARG0];
# since we got an error, must be a failure
$_[HEAP]->{'test_failure'} = 1;
return;
}
# Handles child STDOUT output
sub Got_STDOUT : State {
my $input = $_[ARG0];
return;
}
# Handles child error
sub Got_ERROR : State {
# Copied from POE::Wheel::Run manpage
my ( $operation, $errnum, $errstr ) = @_[ ARG0 .. ARG2 ];
# ignore exit 0 errors
if ( $errnum != 0 ) {
warn "Wheel::Run got an $operation error $errnum: $errstr\n";
}
return;
}
# Handles child DIE'ing
sub Got_CLOSED : State {
# Get rid of the wheel
undef $_[HEAP]->{'WHEEL'};
# Did we pass this test or not?
if ( ! $_[HEAP]->{'test_failure'} ) {
push( @{ $_[HEAP]->{'found_loops'} }, $_[HEAP]->{'current_loop'} );
}
# move on to the next loop
$_[KERNEL]->yield( 'find_loops' );
return;
}
1;
__END__
=head1 NAME
=head1 SYNOPSIS
Don't use this module directly. Please use POE::Devel::Benchmarker.
POE::Devel::Benchmarker::GetInstalledLoops - Automatically detects the installed POE loops
=head1 ABSTRACT
This package implements the guts of searching for POE loops via fork/exec.
=head1 EXPORT
Automatically exports the getPOEloops() sub
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/Utils.pm b/lib/POE/Devel/Benchmarker/Utils.pm
index 42703ad..fea4a97 100644
--- a/lib/POE/Devel/Benchmarker/Utils.pm
+++ b/lib/POE/Devel/Benchmarker/Utils.pm
@@ -1,190 +1,199 @@
# Declare our package
package POE::Devel::Benchmarker::Utils;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.02';
# auto-export the only sub we have
require Exporter;
use vars qw( @ISA @EXPORT_OK );
@ISA = qw(Exporter);
-@EXPORT_OK = qw( poeloop2load loop2realversion beautify_times );
+@EXPORT_OK = qw( poeloop2load loop2realversion beautify_times knownloops );
# returns the proper "load" stuff for a specific loop
sub poeloop2load {
my $eventloop = shift;
# Decide which event loop to use
# Event_Lib EV Glib Prima Gtk Wx Kqueue Tk Select IO_Poll
if ( $eventloop eq 'Event' ) {
return 'Event';
} elsif ( $eventloop eq 'IO_Poll' ) {
return 'IO::Poll';
} elsif ( $eventloop eq 'Event_Lib' ) {
return 'Event::Lib';
} elsif ( $eventloop eq 'EV' ) {
return 'EV';
} elsif ( $eventloop eq 'Glib' ) {
return 'Glib';
} elsif ( $eventloop eq 'Tk' ) {
return 'Tk',
} elsif ( $eventloop eq 'Gtk' ) {
return 'Gtk';
} elsif ( $eventloop eq 'Prima' ) {
return 'Prima';
} elsif ( $eventloop eq 'Wx' ) {
return 'Wx';
} elsif ( $eventloop eq 'Kqueue' ) {
# FIXME dunno what to do here!
return;
} elsif ( $eventloop eq 'Select' ) {
return;
} else {
die "Unknown event loop!";
}
}
# returns the version of the "real" installed module that the loop uses
sub loop2realversion {
my $eventloop = shift;
# Decide which event loop to use
if ( ! defined $eventloop ) {
return;
} elsif ( $eventloop eq 'Event' ) {
return $Event::VERSION;
} elsif ( $eventloop eq 'IO_Poll' ) {
return $IO::Poll::VERSION;
} elsif ( $eventloop eq 'Event_Lib' ) {
return $Event::Lib::VERSION;
} elsif ( $eventloop eq 'EV' ) {
return $EV::VERSION;
} elsif ( $eventloop eq 'Glib' ) {
return $Glib::VERSION;
} elsif ( $eventloop eq 'Tk' ) {
return $Tk::VERSION;
} elsif ( $eventloop eq 'Gtk' ) {
return $Gtk::VERSION;
} elsif ( $eventloop eq 'Prima' ) {
return $Prima::VERSION;
} elsif ( $eventloop eq 'Wx' ) {
return $Wx::VERSION;
} elsif ( $eventloop eq 'Kqueue' ) {
# FIXME how do I do this?
return;
} elsif ( $eventloop eq 'Select' ) {
return 'BUILTIN';
} else {
die "Unknown event loop!";
}
}
# helper routine to parse times() output
sub beautify_times {
my $string = shift;
my $origdata = shift;
# split it up
$string =~ s/^\s+//; $string =~ s/\s+$//;
my @times = split( /\s+/, $string );
# make the data struct
# ($user,$system,$cuser,$csystem) = times;
my $data = {
'user' => $times[4] - $times[0],
'sys' => $times[5] - $times[1],
'cuser' => $times[6] - $times[2],
'csys' => $times[7] - $times[3],
};
# add original data?
if ( $origdata ) {
$data->{'s_user'} = $times[0];
$data->{'s_sys'} = $times[1];
$data->{'s_cuser'} = $times[2];
$data->{'s_csys'} = $times[3];
$data->{'e_user'} = $times[4];
$data->{'e_sys'} = $times[5];
$data->{'e_cuser'} = $times[6];
$data->{'e_csys'} = $times[7];
}
# send it back!
return $data;
}
+# returns a list of "known" POE loops
+sub knownloops {
+ return [ qw( Event_Lib EV Glib Prima Gtk Wx Kqueue Tk Select IO_Poll ) ];
+}
+
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::Utils - Various utility routines for POE::Devel::Benchmarker
=head1 SYNOPSIS
perl -MPOE::Devel::Benchmarker::Utils -e 'print poeloop2load( "IO_Poll" )'
=head1 ABSTRACT
This package contains the utility routines and constants that POE::Devel::Benchmarker needs.
=head1 EXPORT
This package exports those subs via @EXPORT_OK:
=over 4
+=item knownloops()
+
+Returns an arrayref of the "known" POE loops as of this version of the Benchmarker
+
=item poeloop2load()
Returns the "parent" class to load for a specific loop. An example is:
$real = poeloop2load( 'IO_Poll' ); # $real now contains "IO::Poll"
=item loop2realversion()
Returns the version of the "parent" class for a specific loop. An example is:
$ver = loop2realversion( 'IO_Poll' ); # $ver now contains $IO::Poll::VERSION
=item beautify_times()
Returns a hashref of data from parsing 2 consecutive times() structures in a string. You can pass an additional parameter
( boolean ) to include the original data. An example is:
print Data::Dumper::Dumper( beautify_times( '0.1 0 0 0 0.1 0 0.76 0.09', 1 ) );
{
"sys" => 0, # total system time
"user" => 0, # total user time
"csys" => 0.76 # total children system time
"cuser" => 0.08 # total children user time
"e_csys" => "0.09", # end children system time ( optional )
"e_cuser" => "0.76", # end children user time ( optional )
"e_sys" => 0, # end system time ( optional )
"e_user" => "0.1", # end user time ( optional )
"s_csys" => 0, # start children system time ( optional )
"s_cuser" => 0, # start children user time ( optional )
"s_sys" => 0, # start system time ( optional )
"s_user" => "0.1" # start user time ( optional )
}
=back
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/scripts/tapout_script b/scripts/tapout_script
new file mode 100644
index 0000000..c34ffeb
--- /dev/null
+++ b/scripts/tapout_script
@@ -0,0 +1,75 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use IO::Poll;
+use POE qw( Component::Client::Keepalive Component::Client::HTTP );
+use HTTP::Request;
+
+my $url = "http://localhost/";
+
+POE::Session->create (
+ inline_states => {
+ _start => \&start,
+ process => \&process,
+ response => \&response,
+ halt => \&halt,
+ },
+);
+
+
+POE::Kernel->run();
+
+sub start {
+ my ($kernel,$heap) = @_[KERNEL,HEAP];
+ print "Starting\n";
+
+ $kernel->alias_set('master');
+
+ foreach (1..512) {
+
+ my $useragent = "ua_$_";
+
+ POE::Component::Client::HTTP->spawn (
+ Alias => $useragent,
+ Timeout => 30,
+ Agent => "Test",
+ );
+ $kernel->yield('process',$useragent);
+ }
+ $kernel->delay(halt=>30);
+}
+
+sub process {
+ my ($kernel,$heap,$useragent) = @_[KERNEL,HEAP,ARG0];
+
+ my $uri = HTTP::Request->new(GET => $url);
+
+ $kernel->post($useragent,'request','response',$uri,$useragent);
+ return;
+}
+
+sub response {
+ my ($kernel,$heap,$request_packet,$response_packet) = @_[KERNEL,HEAP,ARG0,ARG1];
+
+ my $request = $request_packet->[0];
+ my $response = $response_packet->[0];
+ my $useragent = $request_packet->[1]; ## this is passed with the request call
+ if ($response->is_success()) {
+ $heap->{responses}++;
+ } else {
+ $heap->{unsuccessful}++;
+ }
+ $kernel->yield('process', $useragent);
+ return;
+}
+
+sub halt {
+ my ($kernel,$heap) = @_[KERNEL,HEAP];
+
+ print "debug success($heap->{responses}) unsuccessful($heap->{unsuccessful}) ... " . $kernel->poe_kernel_loop() . "\n";
+exit;
+
+ return;
+}
+
+1;
|
apocalypse/perl-poe-benchmarker
|
b29d2ad6d887d16ccfeafad9cae90110c6d294c0
|
added loop option, thanks dngor
|
diff --git a/Changes b/Changes
index 74d8ecb..affe9bd 100755
--- a/Changes
+++ b/Changes
@@ -1,10 +1,14 @@
Revision history for Perl extension POE::Devel::Benchmarker
+* 0.03
+
+ Added the loop option to benchmark(), thanks dngor!
+
* 0.02
Added the Analyzer module ( and dump YAML files, yay! )
A lot of minor changes+tweaks to get a better dump format
* 0.01
initial release
diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP
index 7af46a2..57df5f5 100755
--- a/MANIFEST.SKIP
+++ b/MANIFEST.SKIP
@@ -1,28 +1,31 @@
^.includepath
^.project
^.settings/
# Avoid version control files.
\B\.svn\b
\B\.git\b
# Avoid Makemaker generated and utility files.
\bMANIFEST\.SKIP
\bMakefile$
\bblib/
\bMakeMaker-\d
\bpm_to_blib$
# Avoid Module::Build generated and utility files.
\bBuild$
\b_build/
# Avoid temp and backup files.
~$
\.old$
\#$
\b\.#
\.bak$
# our tarballs
\.tar\.gz$
+
+# skip the local scripts directory where I store snippets of benchmarks
+scripts/
diff --git a/lib/POE/Devel/Benchmarker.pm b/lib/POE/Devel/Benchmarker.pm
index 0655fa8..ab74b17 100644
--- a/lib/POE/Devel/Benchmarker.pm
+++ b/lib/POE/Devel/Benchmarker.pm
@@ -1,650 +1,682 @@
# Declare our package
package POE::Devel::Benchmarker;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
-$VERSION = '0.02';
+$VERSION = '0.03';
# auto-export the only sub we have
BEGIN {
require Exporter;
use vars qw( @ISA @EXPORT );
@ISA = qw(Exporter);
@EXPORT = qw( benchmark );
}
# Import what we need from the POE namespace
sub POE::Kernel::ASSERT_DEFAULT { 1 }
sub POE::Session::ASSERT_DEFAULT { 1 }
use POE qw( Session Filter::Line Wheel::Run );
use base 'POE::Session::AttributeBased';
# we need hires times
use Time::HiRes qw( time );
# load comparison stuff
use version;
# Load our stuff
use POE::Devel::Benchmarker::GetInstalledLoops;
use POE::Devel::Benchmarker::Utils qw( poeloop2load );
use POE::Devel::Benchmarker::Analyzer;
# Actually run the tests!
sub benchmark {
my $options = shift;
# set default options
my $lite_tests = 1;
my $quiet_mode = 0;
+ my $forceloops = undef; # default to all known loops in GetInstalledLoops
# process our options
if ( defined $options and ref $options and ref( $options ) eq 'HASH' ) {
# process LITE tests
if ( exists $options->{'litetests'} ) {
if ( $options->{'litetests'} ) {
$lite_tests = 1;
} else {
$lite_tests = 0;
}
}
# process quiet mode
if ( exists $options->{'quiet'} ) {
if ( $options->{'quiet'} ) {
$quiet_mode = 1;
} else {
$quiet_mode = 0;
}
}
+
+ # process forceloops
+ if ( exists $options->{'loop'} and defined $options->{'loop'} ) {
+ if ( ! ref $options->{'loop'} ) {
+ # split it via CSV
+ $forceloops = [ split( /,/, $options->{'loop'} ) ];
+ foreach ( @$forceloops ) {
+ $_ =~ s/^\s+//; $_ =~ s/\s+$//;
+ }
+ } else {
+ # treat it as array
+ $forceloops = $options->{'loop'};
+ }
+ }
}
# do some sanity checks
if ( ! -d 'poedists' ) {
die "The 'poedists' directory is not found in the working directory!";
}
if ( ! -d 'results' ) {
die "The 'results' directory is not found in the working directory!";
}
if ( ! $quiet_mode ) {
print "[BENCHMARKER] Starting up...\n";
}
# Create our session
POE::Session->create(
__PACKAGE__->inline_states(),
'heap' => {
'lite_tests' => $lite_tests,
'quiet_mode' => $quiet_mode,
+ 'forceloops' => $forceloops,
},
);
# Fire 'er up!
POE::Kernel->run();
return;
}
# Starts up our session
sub _start : State {
# okay, get all the dists we can!
my @versions;
if ( opendir( DISTS, 'poedists' ) ) {
foreach my $d ( readdir( DISTS ) ) {
if ( $d =~ /^POE\-(.+)$/ and $d !~ /\.tar\.gz$/ ) {
push( @versions, $1 );
}
}
closedir( DISTS ) or die $!;
} else {
print "[BENCHMARKER] Unable to open 'poedists' for reading: $!\n";
return;
}
# set our alias
$_[KERNEL]->alias_set( 'Benchmarker' );
# sanely handle some signals
$_[KERNEL]->sig( 'INT', 'handle_kill' );
$_[KERNEL]->sig( 'TERM', 'handle_kill' );
# okay, go through all the dists in version order
@versions = sort { $b <=> $a }
map { version->new( $_ ) } @versions;
# Store the versions in our heap
$_[HEAP]->{'VERSIONS'} = \@versions;
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Detected available POE versions -> " . join( " ", @versions ) . "\n";
}
# First of all, we need to find out what loop libraries are installed
- getPOEloops( $_[HEAP]->{'quiet_mode'} );
+ getPOEloops( $_[HEAP]->{'quiet_mode'}, $_[HEAP]->{'forceloops'} );
return;
}
sub _stop : State {
# tell the wheel to kill itself
if ( defined $_[HEAP]->{'WHEEL'} ) {
$_[HEAP]->{'WHEEL'}->kill( 9 );
undef $_[HEAP]->{'WHEEL'};
}
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Shutting down...\n";
}
return;
}
# misc POE handlers
sub _child : State {
return;
}
sub handle_kill : State {
return;
}
# we received list of loops from GetInstalledLoops
sub found_loops : State {
$_[HEAP]->{'installed_loops'} = [ sort { $a cmp $b } @{ $_[ARG0] } ];
# sanity check
if ( scalar @{ $_[HEAP]->{'installed_loops'} } == 0 ) {
print "[BENCHMARKER] Detected no available POE::Loop, check your configuration?!?\n";
return;
}
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Detected available POE::Loops -> " . join( " ", @{ $_[HEAP]->{'installed_loops'} } ) . "\n";
}
# Fire up the analyzer
initAnalyzer( $_[HEAP]->{'quiet_mode'} );
# start the benchmark!
$_[KERNEL]->yield( 'run_benchmark' );
return;
}
# Runs one benchmark
sub run_benchmark : State {
# Grab the version from the top of the array
$_[HEAP]->{'current_version'} = shift @{ $_[HEAP]->{'VERSIONS'} };
# did we run out of versions?
if ( ! defined $_[HEAP]->{'current_version'} ) {
# We're done, let POE die...
$_[KERNEL]->alias_remove( 'Benchmarker' );
} else {
$_[HEAP]->{'loops'} = [ @{ $_[HEAP]->{'installed_loops'} } ];
# okay, fire off the first loop
$_[KERNEL]->yield( 'bench_loop' );
}
return;
}
# runs one loop
sub bench_loop : State {
# select our current loop
$_[HEAP]->{'current_loop'} = shift @{ $_[HEAP]->{'loops'} };
# are we done with all loops?
if ( ! defined $_[HEAP]->{'current_loop'} ) {
# yay, go back to the main handler
$_[KERNEL]->yield( 'run_benchmark' );
} else {
# Start the assert test
$_[HEAP]->{'assertions'} = [ qw( 0 1 ) ];
$_[KERNEL]->yield( 'bench_asserts' );
}
return;
}
# runs an assertion
sub bench_asserts : State {
# select our current assert state
$_[HEAP]->{'current_assertions'} = shift @{ $_[HEAP]->{'assertions'} };
# are we done?
if ( ! defined $_[HEAP]->{'current_assertions'} ) {
# yay, go back to the loop handler
$_[KERNEL]->yield( 'bench_loop' );
} else {
# Start the xsqueue test
$_[HEAP]->{'xsqueue'} = [ qw( 0 1 ) ];
$_[KERNEL]->yield( 'bench_xsqueue' );
}
return;
}
# runs test with or without xsqueue
sub bench_xsqueue : State {
# select our current xsqueue state
$_[HEAP]->{'current_xsqueue'} = shift @{ $_[HEAP]->{'xsqueue'} };
# are we done?
if ( ! defined $_[HEAP]->{'current_xsqueue'} ) {
# yay, go back to the assert handler
$_[KERNEL]->yield( 'bench_asserts' );
} else {
# actually fire off the subprocess, ha!
$_[KERNEL]->yield( 'create_subprocess' );
}
return;
}
# actually runs the subprocess
sub create_subprocess : State {
# Okay, start testing this specific combo!
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "Testing POE v" . $_[HEAP]->{'current_version'} .
" loop(" . $_[HEAP]->{'current_loop'} . ')' .
" assertions(" . ( $_[HEAP]->{'current_assertions'} ? 'ENABLED' : 'DISABLED' ) . ')' .
" xsqueue(" . ( $_[HEAP]->{'current_xsqueue'} ? 'ENABLED' : 'DISABLED' ) . ')' .
"\n";
}
# save the starttime
$_[HEAP]->{'current_starttime'} = time();
$_[HEAP]->{'current_starttimes'} = [ times() ];
# Okay, create the wheel::run to handle this
my $looploader = poeloop2load( $_[HEAP]->{'current_loop'} );
$_[HEAP]->{'WHEEL'} = POE::Wheel::Run->new(
'Program' => $^X,
'ProgramArgs' => [ '-Ipoedists/POE-' . $_[HEAP]->{'current_version'},
'-Ipoedists/POE-' . $_[HEAP]->{'current_version'} . '/lib',
( defined $looploader ? "-M$looploader" : () ),
'-MPOE::Devel::Benchmarker::SubProcess',
'-e',
'POE::Devel::Benchmarker::SubProcess::benchmark',
$_[HEAP]->{'current_version'},
$_[HEAP]->{'current_loop'},
$_[HEAP]->{'current_assertions'},
$_[HEAP]->{'lite_tests'},
$_[HEAP]->{'current_xsqueue'},
],
# Kill off existing FD's
'CloseOnCall' => 1,
# setup our data handlers
'StdoutEvent' => 'Got_STDOUT',
'StderrEvent' => 'Got_STDERR',
# the error handler
'ErrorEvent' => 'Got_ERROR',
'CloseEvent' => 'Got_CLOSED',
# set our filters
'StderrFilter' => POE::Filter::Line->new(),
'StdoutFilter' => POE::Filter::Line->new(),
);
if ( ! defined $_[HEAP]->{'WHEEL'} ) {
die 'Unable to create a new wheel!';
} else {
# smart CHLD handling
if ( $_[KERNEL]->can( "sig_child" ) ) {
$_[KERNEL]->sig_child( $_[HEAP]->{'WHEEL'}->PID => 'Got_CHLD' );
} else {
$_[KERNEL]->sig( 'CHLD', 'Got_CHLD' );
}
}
# setup our data we received from the subprocess
$_[HEAP]->{'current_data'} = '';
# Okay, we timeout this test after some time for sanity
$_[HEAP]->{'test_timedout'} = 0;
if ( $_[HEAP]->{'lite_tests'} ) {
# on my core2duo 1.2ghz laptop, running Gtk+LITE+assert+noxsqueue takes approx 45s
$_[HEAP]->{'TIMER'} = $_[KERNEL]->delay_set( 'test_timedout' => 60 * 2 );
} else {
# on my core2duo 1.2ghz laptop, running Gtk+HEAVY+assert+noxsqueue takes all day long :(
$_[HEAP]->{'TIMER'} = $_[KERNEL]->delay_set( 'test_timedout' => 60 * 15 );
}
return;
}
# Got a CHLD event!
sub Got_CHLD : State {
$_[KERNEL]->sig_handled();
return;
}
# Handles child STDERR output
sub Got_STDERR : State {
my $input = $_[ARG0];
# save it!
$_[HEAP]->{'current_data'} .= '!STDERR: ' . $input . "\n";
return;
}
# Handles child STDOUT output
sub Got_STDOUT : State {
my $input = $_[ARG0];
# save it!
$_[HEAP]->{'current_data'} .= $input . "\n";
return;
}
# Handles child error
sub Got_ERROR : State {
# Copied from POE::Wheel::Run manpage
my ( $operation, $errnum, $errstr ) = @_[ ARG0 .. ARG2 ];
# ignore exit 0 errors
if ( $errnum != 0 ) {
print "[BENCHMARKER] Wheel::Run got an $operation error $errnum: $errstr\n";
}
return;
}
# Handles child DIE'ing
sub Got_CLOSED : State {
# Get rid of the wheel
undef $_[HEAP]->{'WHEEL'};
# get rid of the delay
$_[KERNEL]->alarm_remove( $_[HEAP]->{'TIMER'} );
undef $_[HEAP]->{'TIMER'};
# wrap up this test
$_[KERNEL]->yield( 'wrapup_test' );
return;
}
# a test timed out, unfortunately!
sub test_timedout : State {
# tell the wheel to kill itself
$_[HEAP]->{'WHEEL'}->kill( 9 );
undef $_[HEAP]->{'WHEEL'};
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Test TimedOut!\n";
}
$_[HEAP]->{'test_timedout'} = 1;
# wrap up this test
$_[KERNEL]->yield( 'wrapup_test' );
return;
}
# finalizes a test
sub wrapup_test : State {
# we're done with this benchmark!
$_[HEAP]->{'current_endtime'} = time();
$_[HEAP]->{'current_endtimes'} = [ times() ];
# store the data
my $file = 'POE-' . $_[HEAP]->{'current_version'} .
'-' . $_[HEAP]->{'current_loop'} .
( $_[HEAP]->{'current_assertions'} ? '-assert' : '-noassert' ) .
( $_[HEAP]->{'current_xsqueue'} ? '-xsqueue' : '-noxsqueue' );
if ( open( my $fh, '>', "results/$file" ) ) {
print $fh "STARTTIME: " . $_[HEAP]->{'current_starttime'} . " -> TIMES " . join( " ", @{ $_[HEAP]->{'current_starttimes'} } ) . "\n";
print $fh "$file\n";
print $fh $_[HEAP]->{'current_data'} . "\n";
if ( $_[HEAP]->{'test_timedout'} ) {
print $fh "\nTEST TERMINATED DUE TO TIMEOUT\n";
}
print $fh "ENDTIME: " . $_[HEAP]->{'current_endtime'} . " -> TIMES " . join( " ", @{ $_[HEAP]->{'current_endtimes'} } ) . "\n";
close( $fh ) or die $!;
} else {
print "[BENCHMARKER] Unable to open results/$file for writing -> $!\n";
}
# Send the data to the Analyzer to process
$_[KERNEL]->post( 'Benchmarker::Analyzer', 'analyze', {
'poe_version' => $_[HEAP]->{'current_version'}->stringify, # YAML::Tiny doesn't like version objects :(
'poe_loop' => 'POE::Loop::' . $_[HEAP]->{'current_loop'},
'asserts' => $_[HEAP]->{'current_assertions'},
'xsqueue' => $_[HEAP]->{'current_xsqueue'},
'litetests' => $_[HEAP]->{'lite_tests'},
'start_time' => $_[HEAP]->{'current_starttime'},
'start_times' => [ @{ $_[HEAP]->{'current_starttimes'} } ],
'end_time' => $_[HEAP]->{'current_endtime'},
'end_times' => [ @{ $_[HEAP]->{'current_endtimes'} } ],
'timedout' => $_[HEAP]->{'test_timedout'},
'rawdata' => $_[HEAP]->{'current_data'},
'test_file' => $file,
} );
# process the next test
$_[KERNEL]->yield( 'bench_xsqueue' );
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker - Benchmarking POE's performance ( acts more like a smoker )
=head1 SYNOPSIS
perl -MPOE::Devel::Benchmarker -e 'benchmark()'
=head1 ABSTRACT
This package of tools is designed to benchmark POE's performace across different
configurations. The current "tests" are:
=over 4
=item posts
=item calls
=item alarm_adds
=item session creation
=item session destruction
=item select_read toggles
=item select_write toggles
=item POE startup time
=back
=head1 DESCRIPTION
This module is poorly documented now. Please give me some time to properly document it over time :)
=head2 INSTALLATION
Here's a simple outline to get you up to speed quickly. ( and smoking! )
=over 4
=item Install CPAN package + dependencies
Download+install the POE::Devel::Benchmarker package from CPAN
apoc@apoc-x300:~$ cpanp -i POE::Devel::Benchmarker
=item Setup initial directories
Go anywhere, and create the "parent" directory where you'll be storing test results + stuff. For this example,
I have chosen to use ~/poe-benchmarker:
apoc@apoc-x300:~$ mkdir poe-benchmarker
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ mkdir poedists
apoc@apoc-x300:~/poe-benchmarker$ mkdir results
apoc@apoc-x300:~/poe-benchmarker$ cd poedists/
apoc@apoc-x300:~/poe-benchmarker/poedists$ perl -MPOE::Devel::Benchmarker::GetPOEdists -e 'getPOEdists( 1 )'
( go get a coffee while it downloads if you're on a slow link, ha! )
=item Let 'er rip!
At this point you can start running the benchmark!
NOTE: the Benchmarker expects everything to be in the "local" directory!
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker -e 'benchmark()'
( go sleep or something, this will take a while! )
=back
=head2 BENCHMARKING
This module exposes only one subroutine, the benchmark() one. You can pass a hashref to it to set various options. Here is
a list of the valid options:
=over 4
=item litetests => boolean
This enables the "lite" tests which will not take up too much time.
+ benchmark( { litetests => 0 } );
+
default: true
=item quiet => boolean
This enables quiet mode which will not print anything to the console except for errors.
+ benchmark( { 'quiet' => 1 } );
+
default: false
+=item loop => csv list or array
+
+This overrides the built-in loop detection algorithm and tries to locate the specified loops.
+
+NOTE: Capitalization is important!
+
+ benchmark( { 'loop' => 'IO_Poll,Select' } );
+ benchmark( { 'loop' => [ qw( Tk Gtk ) ] } );
+
+Known loops: Event_Lib EV Glib Prima Gtk Wx Kqueue Tk Select IO_Poll
+
=back
As the Benchmarker goes through the combinations of POE + Eventloop + Assertions + XS::Queue it will dump data into
the results directory. The Analyzer module also dumps YAML output in the same place, with the suffix of ".yml"
=head2 ANALYZING RESULTS
Please look at the L<POE::Devel::Benchmarker::Analyzer> module.
=head2 HOW DO I?
This section will explain the miscellaneous questions and preemptively answer any concerns :)
=head3 Skip a POE version
Simply delete it from the poedists directory. The Benchmarker will automatically look in that and load POE versions. If
you wanted to test only 1 version - just delete all directories except for that one.
Keep in mind that the Benchmarker will not automatically untar archives, only the Benchmarker::GetPOEdists module
does that!
-=head3 Skip an eventloop
-
-This isn't implemented yet. As a temporary work-around you could uninstall the POE::Loop::XYZ module from your system :)
-
=head3 Skip a specific benchmark
Why would you want to? That's the whole point of this suite!
=head3 Create graphs
This will be added to the module soon. However if you have the time+energy, please feel free to dig into the YAML output
that Benchmarker::Analyzer outputs.
=head3 Restarting where the Benchmarker left off
This isn't implemented yet. You could always manually delete the POE versions that was tested and proceed with the rest.
=head1 EXPORT
Automatically exports the benchmark() subroutine.
=head1 TODO
=over 4
=item Perl version smoking
We should be able to run the benchmark over different Perl versions. This would require some fiddling with our
layout + logic. It's not that urgent because the workaround is to simply execute the smoke suite under a different
perl binary. It's smart enough to use $^X to be consistent across tests :)
=item Select the EV backend
<Khisanth> and if you are benchmarking, try it with POE using EV with EV using Glib? :P
<Apocalypse> I'm not sure how to configure the EV "backend" yet
<Apocalypse> too much docs for me to read hah
<Khisanth> Apocalypse: use EV::Glib; use Glib; use POE; :)
=item Disable POE::XS::Queue::Array tests if not found
Currently we blindly move on and test with/without this. We should be smarter and not waste one extra test per iteration
if it isn't installed!
=item Be smarter in smoking timeouts
Currently we depend on the litetests option and hardcode some values including the timeout. If your machine is incredibly
slow, there's a chance that it could timeout unnecessarily. Please look at the outputs and check to see if there are unusual
failures, and inform me.
Also, some loops perform badly and take almost forever! /me glares at Gtk...
=item More benchmarks!
As usual, me and the crowd in #poe have plenty of ideas for tests. We'll be adding them over time, but if you have an idea please
drop me a line and let me know!
dngor said there was some benchmarks in the POE svn under trunk/queue...
I want a bench that actually tests socket traffic - stream 10MB of traffic over localhost, and time it?
=item Add SQLite/DBI/etc support to the Analyzer
It would be nice if we could have a local SQLite db to dump our stats into. This would make arbitrary reports much easier than
loading raw YAML files and trying to make sense of them, ha! Also, this means somebody can do the smoking and send the SQLite
db to another person to generate the graphs, cool!
=item Kqueue loop support
As I don't have access to a *BSD box, I cannot really test this. Furthermore, it isn't clear on how I can force/unload this
module from POE...
=item Wx loop support
I have Wx installed, but it doesn't work. Obviously I don't know how to use Wx ;)
If you have experience, please drop me a line on how to do the "right" thing to get Wx loaded under POE. Here's the error:
Can't call method "MainLoop" on an undefined value at /usr/local/share/perl/5.8.8/POE/Loop/Wx.pm line 91.
+=item XS loop support
+
+The POE::XS::Loop::* modules theoretically could be tested too. However, they will only work in POE >= 1.003! This renders
+the concept somewhat moot. Maybe, after POE has progressed some versions we can implement this...
+
=back
=head1 SEE ALSO
L<POE>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
BIG THANKS goes to Rocco Caputo E<lt>rcaputo@cpan.orgE<gt> for the first benchmarks!
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm b/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm
index dad0f61..f909573 100644
--- a/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm
+++ b/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm
@@ -1,204 +1,208 @@
# Declare our package
package POE::Devel::Benchmarker::GetInstalledLoops;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
-$VERSION = '0.01';
+$VERSION = '0.02';
# auto-export the only sub we have
BEGIN {
require Exporter;
use vars qw( @ISA @EXPORT );
@ISA = qw(Exporter);
@EXPORT = qw( getPOEloops );
}
# Import what we need from the POE namespace
use POE qw( Session Filter::Line Wheel::Run );
use base 'POE::Session::AttributeBased';
# analyzes the installed perl directory for available loops
sub getPOEloops {
my $quiet_mode = shift;
+ my $forceloops = shift;
# create our session!
POE::Session->create(
POE::Devel::Benchmarker::GetInstalledLoops->inline_states(),
'heap' => {
'quiet_mode' => $quiet_mode,
+ 'loops' => $forceloops,
},
);
}
# Starts up our session
sub _start : State {
# set our alias
$_[KERNEL]->alias_set( 'Benchmarker::GetInstalledLoops' );
# load our known list of loops
# known impossible loops:
# XS::EPoll ( must be POE > 1.003 and weird way of loading )
# XS::Poll ( must be POE > 1.003 and weird way of loading )
- $_[HEAP]->{'loops'} = [ qw( Event_Lib EV Glib Prima Gtk Wx Kqueue Tk Select IO_Poll ) ];
+ if ( ! defined $_[HEAP]->{'loops'} ) {
+ $_[HEAP]->{'loops'} = [ qw( Event_Lib EV Glib Prima Gtk Wx Kqueue Tk Select IO_Poll ) ];
+ }
# First of all, we need to find out what loop libraries are installed
$_[HEAP]->{'found_loops'} = [];
$_[KERNEL]->yield( 'find_loops' );
return;
}
sub _stop : State {
# tell the wheel to kill itself
if ( defined $_[HEAP]->{'WHEEL'} ) {
$_[HEAP]->{'WHEEL'}->kill( 9 );
undef $_[HEAP]->{'WHEEL'};
}
return;
}
# loops over the "known" loops and sees if they are installed
sub find_loops : State {
# get the loop to test
$_[HEAP]->{'current_loop'} = shift @{ $_[HEAP]->{'loops'} };
# do we have something to test?
if ( ! defined $_[HEAP]->{'current_loop'} ) {
# we're done!
$_[KERNEL]->alias_remove( 'Benchmarker::GetInstalledLoops' );
$_[KERNEL]->post( 'Benchmarker', 'found_loops', $_[HEAP]->{'found_loops'} );
return;
} else {
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[LOOPSEARCH] Trying to find if POE::Loop::" . $_[HEAP]->{'current_loop'} . " is installed...\n";
}
# set the flag
$_[HEAP]->{'test_failure'} = 0;
}
# Okay, create the wheel::run to handle this
$_[HEAP]->{'WHEEL'} = POE::Wheel::Run->new(
'Program' => $^X,
'ProgramArgs' => [ '-MPOE',
'-MPOE::Loop::' . $_[HEAP]->{'current_loop'},
'-e',
'1',
],
# Kill off existing FD's
'CloseOnCall' => 1,
# setup our data handlers
'StdoutEvent' => 'Got_STDOUT',
'StderrEvent' => 'Got_STDERR',
# the error handler
'ErrorEvent' => 'Got_ERROR',
'CloseEvent' => 'Got_CLOSED',
# set our filters
'StderrFilter' => POE::Filter::Line->new(),
'StdoutFilter' => POE::Filter::Line->new(),
);
if ( ! defined $_[HEAP]->{'WHEEL'} ) {
die '[LOOPSEARCH] Unable to create a new wheel!';
} else {
# smart CHLD handling
if ( $_[KERNEL]->can( "sig_child" ) ) {
$_[KERNEL]->sig_child( $_[HEAP]->{'WHEEL'}->PID => 'Got_CHLD' );
} else {
$_[KERNEL]->sig( 'CHLD', 'Got_CHLD' );
}
}
return;
}
# Got a CHLD event!
sub Got_CHLD : State {
$_[KERNEL]->sig_handled();
return;
}
# Handles child STDERR output
sub Got_STDERR : State {
my $input = $_[ARG0];
# since we got an error, must be a failure
$_[HEAP]->{'test_failure'} = 1;
return;
}
# Handles child STDOUT output
sub Got_STDOUT : State {
my $input = $_[ARG0];
return;
}
# Handles child error
sub Got_ERROR : State {
# Copied from POE::Wheel::Run manpage
my ( $operation, $errnum, $errstr ) = @_[ ARG0 .. ARG2 ];
# ignore exit 0 errors
if ( $errnum != 0 ) {
warn "Wheel::Run got an $operation error $errnum: $errstr\n";
}
return;
}
# Handles child DIE'ing
sub Got_CLOSED : State {
# Get rid of the wheel
undef $_[HEAP]->{'WHEEL'};
# Did we pass this test or not?
if ( ! $_[HEAP]->{'test_failure'} ) {
push( @{ $_[HEAP]->{'found_loops'} }, $_[HEAP]->{'current_loop'} );
}
# move on to the next loop
$_[KERNEL]->yield( 'find_loops' );
return;
}
1;
__END__
=head1 NAME
=head1 SYNOPSIS
Don't use this module directly. Please use POE::Devel::Benchmarker.
POE::Devel::Benchmarker::GetInstalledLoops - Automatically detects the installed POE loops
=head1 ABSTRACT
This package implements the guts of searching for POE loops via fork/exec.
=head1 EXPORT
Automatically exports the getPOEloops() sub
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/scripts/lotr_tests b/scripts/lotr_tests
new file mode 100644
index 0000000..1193892
--- /dev/null
+++ b/scripts/lotr_tests
@@ -0,0 +1,168 @@
+format options below
+
+===== test.sh ======
+# select (default)
+NYTPROF="file=Select-single.out" \
+perl -d:NYTProf echo-single.pl 'Loop::Select' &
+perl stress.pl
+
+wait
+
+# Event
+NYTPROF="file=Event-single.out" \
+perl -MEvent -d:NYTProf echo-single.pl 'Loop::Event' &
+perl stress.pl
+
+wait
+
+#IO::Poll
+perl -MIO::Poll -d:NYTProf echo-single.pl 'Loop::IO_Poll' &
+perl stress.pl
+
+wait
+
+# EV
+perl -MEV -d:NYTProf echo-single.pl 'Loop::EV' &
+perl stress.pl
+
+wait
+
+# Glib
+perl -d:NYTProf -MGlib echo-single.pl 'Loop::Glib' &
+perl stress.pl
+
+wait
+
+#XS Poll
+NYTPROF="file=XSPoll-single.out" \
+perl -d:NYTProf echo-single.pl 'XS::Loop::Poll' &
+perl stress.pl
+
+wait
+
+#XS EPoll
+NYTPROF="file=XSEPoll-single.out" \
+perl -d:NYTProf echo-single.pl 'XS::Loop::EPoll' &
+perl stress.pl
+
+wait
+
+===== echo-single.pl ======
+use strict;
+use warnings;
+
+my $loop;
+BEGIN {
+ $loop = shift @ARGV;
+}
+use POE ('Filter::Stream', $loop);
+use Test::POE::Server::TCP;
+
+POE::Session->create (
+ inline_states => {
+ _start => sub {
+ warn $_[KERNEL]->poe_kernel_loop;
+ $_[HEAP]->{testd} = Test::POE::Server::TCP->spawn(
+ filter => POE::Filter::Stream->new,
+ address => 'localhost',
+ port => 12345,
+ );
+ },
+ testd_client_input => sub {
+ $_[HEAP]->{testd}->send_to_client(@_[ARG0, ARG1]);
+ },
+ testd_disconnected => sub {
+ $_[KERNEL]->delay('end', 3);
+ },
+ end => sub {
+ $_[HEAP]->{testd}->shutdown;
+ }
+ }
+);
+
+$poe_kernel->run;
+===== stress.pl =======
+use strict;
+use warnings;
+use Scalar::Util qw(blessed);
+# Select Event IO_Poll XS::Poll Glib
+use Event;
+use POE qw(
+ Loop::Event
+ Wheel::ReadWrite
+ Filter::Stream
+ Component::Client::TCP
+);
+
+$| = 1;
+
+for my $i (1..500) {
+
+POE::Component::Client::TCP->new (
+ RemoteAddress => "localhost",
+ RemotePort => "12345",
+ #Filter => POE::Filter::SSL->new(),
+ Filter => POE::Filter::Stream->new(),
+
+ InlineStates => {
+ bar => sub {
+ my ($kernel, $heap) = @_[KERNEL, HEAP];
+
+ if ($heap->{count}-- > 0) {
+ $heap->{server}->put("$i -- " . $heap->{count});
+ $kernel->delay(bar => 0.01);
+ } else {
+ $kernel->delay('shutdown' => 1);
+ }
+ },
+ },
+ Connected => sub {
+ my ($kernel, $heap) = @_[KERNEL, HEAP];
+
+ $heap->{count} = 50;
+ $kernel->yield('bar');
+ },
+ ServerInput => sub {
+ my ($kernel, $heap, $input) = @_[KERNEL, HEAP, ARG0];
+
+ #print "$input\n";
+ },
+);
+
+}
+
+$poe_kernel->run;
+exit 0;
+
+
+---- without Test::POE::Server::TCP -----
+use strict;
+use warnings;
+
+my $loop;
+
+BEGIN {
+ $loop = shift @ARGV;
+}
+use POE ($loop, qw(
+
+ Component::Server::TCP
+ Wheel::ReadWrite
+ Filter::Stream
+));
+
+my $s = POE::Component::Server::TCP->new(
+ Port => 12345,
+ ClientFilter => POE::Filter::Stream->new,
+ Started => sub {
+ warn $_[KERNEL]->poe_kernel_loop;
+ $_[KERNEL]->delay('shutdown', 180);
+ },
+ ClientInput => sub {
+ my ($heap, $input) = @_[HEAP, ARG0];
+
+ $heap->{client}->put($input);
+ },
+);
+
+$poe_kernel->run;
|
apocalypse/perl-poe-benchmarker
|
35e2837b948b6f82d36b4aa460f6d73156ccfe33
|
finalize 0.02 release
|
diff --git a/Build.PL b/Build.PL
index 03d7fdd..66b8692 100755
--- a/Build.PL
+++ b/Build.PL
@@ -1,95 +1,94 @@
# Build.PL
use Module::Build;
my $build = Module::Build->new(
# look up Module::Build::API for the info!
'dynamic_config' => 0,
'module_name' => 'POE::Devel::Benchmarker',
'license' => 'perl',
'dist_abstract' => "Benchmarking POE's performance ( acts more like a smoker )",
'dist_author' => 'Apocalypse <APOCAL@cpan.org>',
'create_packlist' => 1,
'create_makefile_pl' => 'traditional',
'create_readme' => 1,
'test_files' => 't/*.t',
'add_to_cleanup' => [ 'META.yml', 'Makefile.PL', 'README' ], # automatically generated
'requires' => {
# POE Stuff
'POE' => 0,
'POE::Session::AttributeBased' => 0,
- # FIXME POE stuff that Test::Dependencies needs to see
- #'POE::Session' => 0,
- #'POE::Filter::Line' => 0,
- #'POE::Wheel::Run' => 0,
-
# misc perl stuff
'Time::HiRes' => 0,
'version' => 0,
'Devel::Hide' => 0,
+ # Analyzer reqs
+ 'YAML::Tiny' => 0,
+ #'POE::Component::SimpleDBI' => 0,
+
# GetPOEdists reqs
'LWP::UserAgent' => 0,
'HTML::LinkExtor' => 0,
'URI::URL' => 0,
'Archive::Tar' => 0,
},
'recommends' => {
# Test stuff
'Test::More' => 0,
# our POE loops!
'POE::Loop::Event' => 0,
'POE::Loop::Event_Lib' => 0,
'POE::Loop::EV' => 0,
'POE::Loop::Glib' => 0,
'POE::Loop::Prima' => 0,
'POE::Loop::Gtk' => 0,
'POE::Loop::Wx' => 0,
'POE::Loop::Kqueue' => 0,
# included in POE ( listed here for completeness )
#'POE::Loop::Tk' => 0,
#'POE::Loop::Select' => 0,
#'POE::Loop::IO_Poll' => 0,
# the loops' dependencies
'Event' => 0,
'Event::Lib' => 0,
'EV' => 0,
'Glib' => 0,
'Prima' => 0,
'Gtk' => 0,
'Wx' => 0,
'Tk' => 0,
},
# FIXME wishlist...
# 'test_requires' => {
# # Test stuff
# 'Test::Compile' => 0,
# 'Test::Perl::Critic' => 0,
# 'Test::Dependencies' => 0,
# 'Test::Distribution' => 0,
# 'Test::Fixme' => 0,
# 'Test::HasVersion' => 0,
# 'Test::Kwalitee' => 0,
# 'Test::CheckManifest' => 0,
# 'Test::MinimumVersion' => 0,
# 'Test::Pod::Coverage' => 0,
# 'Test::Spelling' => 0,
# 'Test::Pod' => 0,
# 'Test::Prereq' => 0,
# 'Test::Strict' => 0,
# 'Test::UseAllModules' => 0,
# },
);
# all done!
$build->create_build_script;
diff --git a/Changes b/Changes
index 853ac02..74d8ecb 100755
--- a/Changes
+++ b/Changes
@@ -1,5 +1,10 @@
Revision history for Perl extension POE::Devel::Benchmarker
+* 0.02
+
+ Added the Analyzer module ( and dump YAML files, yay! )
+ A lot of minor changes+tweaks to get a better dump format
+
* 0.01
initial release
diff --git a/MANIFEST b/MANIFEST
index e2e5f32..1116983 100755
--- a/MANIFEST
+++ b/MANIFEST
@@ -1,33 +1,34 @@
Makefile.PL
Build.PL
MANIFEST
MANIFEST.SKIP
README
lib/POE/Devel/Benchmarker.pm
lib/POE/Devel/Benchmarker/GetInstalledLoops.pm
lib/POE/Devel/Benchmarker/GetPOEdists.pm
lib/POE/Devel/Benchmarker/SubProcess.pm
lib/POE/Devel/Benchmarker/Utils.pm
+lib/POE/Devel/Benchmarker/Analyzer.pm
META.yml
Changes
t/1_load.t
t/a_critic.t
t/a_kwalitee.t
t/a_pod.t
t/a_pod_spelling.t
t/a_pod_coverage.t
t/a_strict.t
t/a_hasversion.t
t/a_minimumversion.t
t/a_manifest.t
t/a_distribution.t
t/a_compile.t
t/a_dependencies.t
t/a_fixme.t
t/a_prereq.t
t/a_prereq_build.t
t/a_dosnewline.t
t/a_perlmetrics.t
t/a_is_prereq_outdated.t
diff --git a/POE-Devel-Benchmarker-0.02.tar.gz b/POE-Devel-Benchmarker-0.02.tar.gz
new file mode 100644
index 0000000..d8d2829
Binary files /dev/null and b/POE-Devel-Benchmarker-0.02.tar.gz differ
diff --git a/lib/POE/Devel/Benchmarker.pm b/lib/POE/Devel/Benchmarker.pm
index e4ceff7..0655fa8 100644
--- a/lib/POE/Devel/Benchmarker.pm
+++ b/lib/POE/Devel/Benchmarker.pm
@@ -1,561 +1,650 @@
# Declare our package
package POE::Devel::Benchmarker;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
-$VERSION = '0.01';
+$VERSION = '0.02';
# auto-export the only sub we have
BEGIN {
require Exporter;
use vars qw( @ISA @EXPORT );
@ISA = qw(Exporter);
@EXPORT = qw( benchmark );
}
# Import what we need from the POE namespace
+sub POE::Kernel::ASSERT_DEFAULT { 1 }
+sub POE::Session::ASSERT_DEFAULT { 1 }
use POE qw( Session Filter::Line Wheel::Run );
use base 'POE::Session::AttributeBased';
# we need hires times
use Time::HiRes qw( time );
# load comparison stuff
use version;
# Load our stuff
use POE::Devel::Benchmarker::GetInstalledLoops;
-use POE::Devel::Benchmarker::Utils;
+use POE::Devel::Benchmarker::Utils qw( poeloop2load );
+use POE::Devel::Benchmarker::Analyzer;
# Actually run the tests!
sub benchmark {
my $options = shift;
# set default options
my $lite_tests = 1;
my $quiet_mode = 0;
# process our options
if ( defined $options and ref $options and ref( $options ) eq 'HASH' ) {
# process LITE tests
if ( exists $options->{'litetests'} ) {
if ( $options->{'litetests'} ) {
$lite_tests = 1;
} else {
$lite_tests = 0;
}
}
# process quiet mode
if ( exists $options->{'quiet'} ) {
if ( $options->{'quiet'} ) {
$quiet_mode = 1;
} else {
$quiet_mode = 0;
}
}
}
# do some sanity checks
if ( ! -d 'poedists' ) {
die "The 'poedists' directory is not found in the working directory!";
}
if ( ! -d 'results' ) {
die "The 'results' directory is not found in the working directory!";
}
if ( ! $quiet_mode ) {
print "[BENCHMARKER] Starting up...\n";
}
# Create our session
POE::Session->create(
__PACKAGE__->inline_states(),
'heap' => {
'lite_tests' => $lite_tests,
'quiet_mode' => $quiet_mode,
},
);
# Fire 'er up!
POE::Kernel->run();
return;
}
# Starts up our session
sub _start : State {
+ # okay, get all the dists we can!
+ my @versions;
+ if ( opendir( DISTS, 'poedists' ) ) {
+ foreach my $d ( readdir( DISTS ) ) {
+ if ( $d =~ /^POE\-(.+)$/ and $d !~ /\.tar\.gz$/ ) {
+ push( @versions, $1 );
+ }
+ }
+ closedir( DISTS ) or die $!;
+ } else {
+ print "[BENCHMARKER] Unable to open 'poedists' for reading: $!\n";
+ return;
+ }
+
# set our alias
$_[KERNEL]->alias_set( 'Benchmarker' );
# sanely handle some signals
$_[KERNEL]->sig( 'INT', 'handle_kill' );
$_[KERNEL]->sig( 'TERM', 'handle_kill' );
- # okay, get all the dists we can!
- my @versions;
- opendir( DISTS, 'poedists' ) or die $!;
- foreach my $d ( readdir( DISTS ) ) {
- if ( $d =~ /^POE\-(.+)$/ and $d !~ /\.tar\.gz$/ ) {
- push( @versions, $1 );
- }
- }
- closedir( DISTS ) or die $!;
-
# okay, go through all the dists in version order
@versions = sort { $b <=> $a }
map { version->new( $_ ) } @versions;
# Store the versions in our heap
$_[HEAP]->{'VERSIONS'} = \@versions;
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Detected available POE versions -> " . join( " ", @versions ) . "\n";
}
# First of all, we need to find out what loop libraries are installed
getPOEloops( $_[HEAP]->{'quiet_mode'} );
return;
}
sub _stop : State {
# tell the wheel to kill itself
if ( defined $_[HEAP]->{'WHEEL'} ) {
$_[HEAP]->{'WHEEL'}->kill( 9 );
undef $_[HEAP]->{'WHEEL'};
}
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Shutting down...\n";
}
return;
}
+# misc POE handlers
+sub _child : State {
+ return;
+}
+sub handle_kill : State {
+ return;
+}
+
# we received list of loops from GetInstalledLoops
sub found_loops : State {
- $_[HEAP]->{'installed_loops'} = [ sort { $a eq $b } @{ $_[ARG0] } ];
+ $_[HEAP]->{'installed_loops'} = [ sort { $a cmp $b } @{ $_[ARG0] } ];
+
+ # sanity check
+ if ( scalar @{ $_[HEAP]->{'installed_loops'} } == 0 ) {
+ print "[BENCHMARKER] Detected no available POE::Loop, check your configuration?!?\n";
+ return;
+ }
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Detected available POE::Loops -> " . join( " ", @{ $_[HEAP]->{'installed_loops'} } ) . "\n";
}
+ # Fire up the analyzer
+ initAnalyzer( $_[HEAP]->{'quiet_mode'} );
+
# start the benchmark!
$_[KERNEL]->yield( 'run_benchmark' );
return;
}
# Runs one benchmark
sub run_benchmark : State {
# Grab the version from the top of the array
$_[HEAP]->{'current_version'} = shift @{ $_[HEAP]->{'VERSIONS'} };
# did we run out of versions?
if ( ! defined $_[HEAP]->{'current_version'} ) {
# We're done, let POE die...
$_[KERNEL]->alias_remove( 'Benchmarker' );
} else {
$_[HEAP]->{'loops'} = [ @{ $_[HEAP]->{'installed_loops'} } ];
# okay, fire off the first loop
$_[KERNEL]->yield( 'bench_loop' );
}
return;
}
# runs one loop
sub bench_loop : State {
# select our current loop
$_[HEAP]->{'current_loop'} = shift @{ $_[HEAP]->{'loops'} };
# are we done with all loops?
if ( ! defined $_[HEAP]->{'current_loop'} ) {
# yay, go back to the main handler
$_[KERNEL]->yield( 'run_benchmark' );
} else {
# Start the assert test
$_[HEAP]->{'assertions'} = [ qw( 0 1 ) ];
$_[KERNEL]->yield( 'bench_asserts' );
}
return;
}
# runs an assertion
sub bench_asserts : State {
# select our current assert state
$_[HEAP]->{'current_assertions'} = shift @{ $_[HEAP]->{'assertions'} };
# are we done?
if ( ! defined $_[HEAP]->{'current_assertions'} ) {
# yay, go back to the loop handler
$_[KERNEL]->yield( 'bench_loop' );
} else {
# Start the xsqueue test
$_[HEAP]->{'xsqueue'} = [ qw( 0 1 ) ];
$_[KERNEL]->yield( 'bench_xsqueue' );
}
return;
}
# runs test with or without xsqueue
sub bench_xsqueue : State {
# select our current xsqueue state
$_[HEAP]->{'current_xsqueue'} = shift @{ $_[HEAP]->{'xsqueue'} };
# are we done?
if ( ! defined $_[HEAP]->{'current_xsqueue'} ) {
# yay, go back to the assert handler
$_[KERNEL]->yield( 'bench_asserts' );
} else {
# actually fire off the subprocess, ha!
$_[KERNEL]->yield( 'create_subprocess' );
}
return;
}
# actually runs the subprocess
sub create_subprocess : State {
# Okay, start testing this specific combo!
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "Testing POE v" . $_[HEAP]->{'current_version'} .
" loop(" . $_[HEAP]->{'current_loop'} . ')' .
" assertions(" . ( $_[HEAP]->{'current_assertions'} ? 'ENABLED' : 'DISABLED' ) . ')' .
" xsqueue(" . ( $_[HEAP]->{'current_xsqueue'} ? 'ENABLED' : 'DISABLED' ) . ')' .
"\n";
}
# save the starttime
$_[HEAP]->{'current_starttime'} = time();
$_[HEAP]->{'current_starttimes'} = [ times() ];
# Okay, create the wheel::run to handle this
my $looploader = poeloop2load( $_[HEAP]->{'current_loop'} );
$_[HEAP]->{'WHEEL'} = POE::Wheel::Run->new(
'Program' => $^X,
'ProgramArgs' => [ '-Ipoedists/POE-' . $_[HEAP]->{'current_version'},
'-Ipoedists/POE-' . $_[HEAP]->{'current_version'} . '/lib',
( defined $looploader ? "-M$looploader" : () ),
'-MPOE::Devel::Benchmarker::SubProcess',
'-e',
'POE::Devel::Benchmarker::SubProcess::benchmark',
$_[HEAP]->{'current_version'},
$_[HEAP]->{'current_loop'},
$_[HEAP]->{'current_assertions'},
$_[HEAP]->{'lite_tests'},
$_[HEAP]->{'current_xsqueue'},
],
# Kill off existing FD's
'CloseOnCall' => 1,
# setup our data handlers
'StdoutEvent' => 'Got_STDOUT',
'StderrEvent' => 'Got_STDERR',
# the error handler
'ErrorEvent' => 'Got_ERROR',
'CloseEvent' => 'Got_CLOSED',
# set our filters
'StderrFilter' => POE::Filter::Line->new(),
'StdoutFilter' => POE::Filter::Line->new(),
);
if ( ! defined $_[HEAP]->{'WHEEL'} ) {
die 'Unable to create a new wheel!';
} else {
# smart CHLD handling
if ( $_[KERNEL]->can( "sig_child" ) ) {
$_[KERNEL]->sig_child( $_[HEAP]->{'WHEEL'}->PID => 'Got_CHLD' );
} else {
$_[KERNEL]->sig( 'CHLD', 'Got_CHLD' );
}
}
# setup our data we received from the subprocess
$_[HEAP]->{'current_data'} = '';
# Okay, we timeout this test after some time for sanity
$_[HEAP]->{'test_timedout'} = 0;
if ( $_[HEAP]->{'lite_tests'} ) {
# on my core2duo 1.2ghz laptop, running Gtk+LITE+assert+noxsqueue takes approx 45s
$_[HEAP]->{'TIMER'} = $_[KERNEL]->delay_set( 'test_timedout' => 60 * 2 );
} else {
# on my core2duo 1.2ghz laptop, running Gtk+HEAVY+assert+noxsqueue takes all day long :(
$_[HEAP]->{'TIMER'} = $_[KERNEL]->delay_set( 'test_timedout' => 60 * 15 );
}
return;
}
# Got a CHLD event!
sub Got_CHLD : State {
$_[KERNEL]->sig_handled();
return;
}
# Handles child STDERR output
sub Got_STDERR : State {
my $input = $_[ARG0];
# save it!
$_[HEAP]->{'current_data'} .= '!STDERR: ' . $input . "\n";
return;
}
# Handles child STDOUT output
sub Got_STDOUT : State {
my $input = $_[ARG0];
# save it!
$_[HEAP]->{'current_data'} .= $input . "\n";
return;
}
# Handles child error
sub Got_ERROR : State {
# Copied from POE::Wheel::Run manpage
my ( $operation, $errnum, $errstr ) = @_[ ARG0 .. ARG2 ];
# ignore exit 0 errors
if ( $errnum != 0 ) {
- warn "Wheel::Run got an $operation error $errnum: $errstr\n";
+ print "[BENCHMARKER] Wheel::Run got an $operation error $errnum: $errstr\n";
}
return;
}
# Handles child DIE'ing
sub Got_CLOSED : State {
# Get rid of the wheel
undef $_[HEAP]->{'WHEEL'};
# get rid of the delay
$_[KERNEL]->alarm_remove( $_[HEAP]->{'TIMER'} );
undef $_[HEAP]->{'TIMER'};
# wrap up this test
$_[KERNEL]->yield( 'wrapup_test' );
return;
}
# a test timed out, unfortunately!
sub test_timedout : State {
# tell the wheel to kill itself
$_[HEAP]->{'WHEEL'}->kill( 9 );
undef $_[HEAP]->{'WHEEL'};
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Test TimedOut!\n";
}
$_[HEAP]->{'test_timedout'} = 1;
# wrap up this test
$_[KERNEL]->yield( 'wrapup_test' );
return;
}
# finalizes a test
sub wrapup_test : State {
# we're done with this benchmark!
$_[HEAP]->{'current_endtime'} = time();
$_[HEAP]->{'current_endtimes'} = [ times() ];
# store the data
my $file = 'POE-' . $_[HEAP]->{'current_version'} .
'-' . $_[HEAP]->{'current_loop'} .
( $_[HEAP]->{'current_assertions'} ? '-assert' : '-noassert' ) .
( $_[HEAP]->{'current_xsqueue'} ? '-xsqueue' : '-noxsqueue' );
- open( my $fh, '>', "results/$file" ) or die $!;
- print $fh "STARTTIME: " . $_[HEAP]->{'current_starttime'} . " -> TIMES " . join( " ", @{ $_[HEAP]->{'current_starttimes'} } ) . "\n";
- print $fh "$file\n\n";
- print $fh $_[HEAP]->{'current_data'} . "\n";
- if ( $_[HEAP]->{'test_timedout'} ) {
- print $fh "\nTEST TERMINATED DUE TO TIMEOUT\n";
+ if ( open( my $fh, '>', "results/$file" ) ) {
+ print $fh "STARTTIME: " . $_[HEAP]->{'current_starttime'} . " -> TIMES " . join( " ", @{ $_[HEAP]->{'current_starttimes'} } ) . "\n";
+ print $fh "$file\n";
+ print $fh $_[HEAP]->{'current_data'} . "\n";
+ if ( $_[HEAP]->{'test_timedout'} ) {
+ print $fh "\nTEST TERMINATED DUE TO TIMEOUT\n";
+ }
+ print $fh "ENDTIME: " . $_[HEAP]->{'current_endtime'} . " -> TIMES " . join( " ", @{ $_[HEAP]->{'current_endtimes'} } ) . "\n";
+ close( $fh ) or die $!;
+ } else {
+ print "[BENCHMARKER] Unable to open results/$file for writing -> $!\n";
}
- print $fh "ENDTIME: " . $_[HEAP]->{'current_endtime'} . " -> TIMES " . join( " ", @{ $_[HEAP]->{'current_endtimes'} } ) . "\n";
- close( $fh ) or die $!;
+
+ # Send the data to the Analyzer to process
+ $_[KERNEL]->post( 'Benchmarker::Analyzer', 'analyze', {
+ 'poe_version' => $_[HEAP]->{'current_version'}->stringify, # YAML::Tiny doesn't like version objects :(
+ 'poe_loop' => 'POE::Loop::' . $_[HEAP]->{'current_loop'},
+ 'asserts' => $_[HEAP]->{'current_assertions'},
+ 'xsqueue' => $_[HEAP]->{'current_xsqueue'},
+ 'litetests' => $_[HEAP]->{'lite_tests'},
+ 'start_time' => $_[HEAP]->{'current_starttime'},
+ 'start_times' => [ @{ $_[HEAP]->{'current_starttimes'} } ],
+ 'end_time' => $_[HEAP]->{'current_endtime'},
+ 'end_times' => [ @{ $_[HEAP]->{'current_endtimes'} } ],
+ 'timedout' => $_[HEAP]->{'test_timedout'},
+ 'rawdata' => $_[HEAP]->{'current_data'},
+ 'test_file' => $file,
+ } );
# process the next test
$_[KERNEL]->yield( 'bench_xsqueue' );
+
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker - Benchmarking POE's performance ( acts more like a smoker )
=head1 SYNOPSIS
perl -MPOE::Devel::Benchmarker -e 'benchmark()'
=head1 ABSTRACT
This package of tools is designed to benchmark POE's performace across different
configurations. The current "tests" are:
=over 4
=item posts
=item calls
=item alarm_adds
=item session creation
=item session destruction
=item select_read toggles
=item select_write toggles
=item POE startup time
=back
=head1 DESCRIPTION
This module is poorly documented now. Please give me some time to properly document it over time :)
=head2 INSTALLATION
Here's a simple outline to get you up to speed quickly. ( and smoking! )
=over 4
=item Install CPAN package + dependencies
Download+install the POE::Devel::Benchmarker package from CPAN
apoc@apoc-x300:~$ cpanp -i POE::Devel::Benchmarker
=item Setup initial directories
Go anywhere, and create the "parent" directory where you'll be storing test results + stuff. For this example,
I have chosen to use ~/poe-benchmarker:
apoc@apoc-x300:~$ mkdir poe-benchmarker
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ mkdir poedists
+ apoc@apoc-x300:~/poe-benchmarker$ mkdir results
apoc@apoc-x300:~/poe-benchmarker$ cd poedists/
apoc@apoc-x300:~/poe-benchmarker/poedists$ perl -MPOE::Devel::Benchmarker::GetPOEdists -e 'getPOEdists( 1 )'
( go get a coffee while it downloads if you're on a slow link, ha! )
- apoc@apoc-x300:~/poe-benchmarker/poedists$ cd..
- apoc@apoc-x300:~/poe-benchmarker$ mkdir results
-
=item Let 'er rip!
At this point you can start running the benchmark!
NOTE: the Benchmarker expects everything to be in the "local" directory!
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker -e 'benchmark()'
( go sleep or something, this will take a while! )
=back
-=head2 ANALYZING RESULTS
-
-This part of the documentation is woefully incomplete. Please look at the L<POE::Devel::Benchmarker::Analyzer> module.
-
=head2 BENCHMARKING
This module exposes only one subroutine, the benchmark() one. You can pass a hashref to it to set various options. Here is
a list of the valid options:
=over 4
=item litetests => boolean
This enables the "lite" tests which will not take up too much time.
default: true
=item quiet => boolean
This enables quiet mode which will not print anything to the console except for errors.
default: false
=back
+As the Benchmarker goes through the combinations of POE + Eventloop + Assertions + XS::Queue it will dump data into
+the results directory. The Analyzer module also dumps YAML output in the same place, with the suffix of ".yml"
+
+=head2 ANALYZING RESULTS
+
+Please look at the L<POE::Devel::Benchmarker::Analyzer> module.
+
+=head2 HOW DO I?
+
+This section will explain the miscellaneous questions and preemptively answer any concerns :)
+
+=head3 Skip a POE version
+
+Simply delete it from the poedists directory. The Benchmarker will automatically look in that and load POE versions. If
+you wanted to test only 1 version - just delete all directories except for that one.
+
+Keep in mind that the Benchmarker will not automatically untar archives, only the Benchmarker::GetPOEdists module
+does that!
+
+=head3 Skip an eventloop
+
+This isn't implemented yet. As a temporary work-around you could uninstall the POE::Loop::XYZ module from your system :)
+
+=head3 Skip a specific benchmark
+
+Why would you want to? That's the whole point of this suite!
+
+=head3 Create graphs
+
+This will be added to the module soon. However if you have the time+energy, please feel free to dig into the YAML output
+that Benchmarker::Analyzer outputs.
+
+=head3 Restarting where the Benchmarker left off
+
+This isn't implemented yet. You could always manually delete the POE versions that was tested and proceed with the rest.
+
=head1 EXPORT
Automatically exports the benchmark() subroutine.
=head1 TODO
=over 4
-=item write POE::Devel::Benchmarker::Analyzer
-
-I need to finish this module so it will dump YAML structures along the raw output. That way we can easily parse the data
-and use it for nifty stuff like graphs or websites :)
-
-BEWARE: please don't write any tools to analyze the dumps as of now, and give me some more time to complete this, because
-I probably will be tweaking the raw output a little to make the regexes less crazy!
-
=item Perl version smoking
We should be able to run the benchmark over different Perl versions. This would require some fiddling with our
layout + logic. It's not that urgent because the workaround is to simply execute the smoke suite under a different
perl binary. It's smart enough to use $^X to be consistent across tests :)
=item Select the EV backend
<Khisanth> and if you are benchmarking, try it with POE using EV with EV using Glib? :P
<Apocalypse> I'm not sure how to configure the EV "backend" yet
<Apocalypse> too much docs for me to read hah
<Khisanth> Apocalypse: use EV::Glib; use Glib; use POE; :)
=item Disable POE::XS::Queue::Array tests if not found
Currently we blindly move on and test with/without this. We should be smarter and not waste one extra test per iteration
if it isn't installed!
-=item Be more smarter in smoking timeouts
+=item Be smarter in smoking timeouts
Currently we depend on the litetests option and hardcode some values including the timeout. If your machine is incredibly
slow, there's a chance that it could timeout unnecessarily. Please look at the outputs and check to see if there are unusual
failures, and inform me.
Also, some loops perform badly and take almost forever! /me glares at Gtk...
-=item Kqueue support
+=item More benchmarks!
+
+As usual, me and the crowd in #poe have plenty of ideas for tests. We'll be adding them over time, but if you have an idea please
+drop me a line and let me know!
+
+dngor said there was some benchmarks in the POE svn under trunk/queue...
+
+I want a bench that actually tests socket traffic - stream 10MB of traffic over localhost, and time it?
+
+=item Add SQLite/DBI/etc support to the Analyzer
+
+It would be nice if we could have a local SQLite db to dump our stats into. This would make arbitrary reports much easier than
+loading raw YAML files and trying to make sense of them, ha! Also, this means somebody can do the smoking and send the SQLite
+db to another person to generate the graphs, cool!
+
+=item Kqueue loop support
As I don't have access to a *BSD box, I cannot really test this. Furthermore, it isn't clear on how I can force/unload this
module from POE...
+=item Wx loop support
+
+I have Wx installed, but it doesn't work. Obviously I don't know how to use Wx ;)
+
+If you have experience, please drop me a line on how to do the "right" thing to get Wx loaded under POE. Here's the error:
+
+ Can't call method "MainLoop" on an undefined value at /usr/local/share/perl/5.8.8/POE/Loop/Wx.pm line 91.
+
=back
=head1 SEE ALSO
L<POE>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
BIG THANKS goes to Rocco Caputo E<lt>rcaputo@cpan.orgE<gt> for the first benchmarks!
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/Analyzer.pm b/lib/POE/Devel/Benchmarker/Analyzer.pm
new file mode 100644
index 0000000..69a60c6
--- /dev/null
+++ b/lib/POE/Devel/Benchmarker/Analyzer.pm
@@ -0,0 +1,455 @@
+# Declare our package
+package POE::Devel::Benchmarker::Analyzer;
+use strict; use warnings;
+
+# Initialize our version
+use vars qw( $VERSION );
+$VERSION = '0.01';
+
+# auto-export the only sub we have
+BEGIN {
+ require Exporter;
+ use vars qw( @ISA @EXPORT );
+ @ISA = qw(Exporter);
+ @EXPORT = qw( initAnalyzer );
+}
+
+# Import what we need from the POE namespace
+use POE qw( Session );
+use base 'POE::Session::AttributeBased';
+
+# use the power of YAML
+use YAML::Tiny qw( Dump );
+
+# Load the utils
+use POE::Devel::Benchmarker::Utils qw( beautify_times );
+
+# fires up the engine
+sub initAnalyzer {
+ my $quiet_mode = shift;
+
+ # create our session!
+ POE::Session->create(
+ POE::Devel::Benchmarker::Analyzer->inline_states(),
+ 'heap' => {
+ 'quiet_mode' => $quiet_mode,
+ },
+ );
+}
+
+# Starts up our session
+sub _start : State {
+ # set our alias
+ $_[KERNEL]->alias_set( 'Benchmarker::Analyzer' );
+
+ # TODO connect to SQLite db via SimpleDBI?
+
+ return;
+}
+
+sub _stop : State {
+ return;
+}
+sub _child : State {
+ return;
+}
+
+sub analyze : State {
+ # get the data
+ my $test = $_[ARG0];
+
+ # clean up the times() stuff
+ $test->{'times'} = beautify_times(
+ join( " ", @{ delete $test->{'start_times'} } ) .
+ " " .
+ join( " ", @{ delete $test->{'end_times'} } )
+ );
+
+ # setup the perl version
+ $test->{'perlconfig'}->{'v'} = sprintf( "%vd", $^V );
+
+ # Okay, break it down into our data struct
+ $test->{'benchmark'} = {};
+ my $d = $test->{'benchmark'};
+ my @unknown;
+ foreach my $l ( split( /(?:\n|\r)/, $test->{'rawdata'} ) ) {
+ # skip empty lines
+ if ( $l eq '' ) { next }
+
+ # usual test benchmark output
+ # 10 startups in 0.885 seconds ( 11.302 per second)
+ # 10000 posts in 0.497 seconds ( 20101.112 per second)
+ if ( $l =~ /^\s+(\d+)\s+(\w+)\s+in\s+([\d\.]+)\s+seconds\s+\(\s+([\d\.]+)\s+per\s+second\)$/ ) {
+ $d->{ $2 }->{'loops'} = $1;
+ $d->{ $2 }->{'time'} = $3;
+ $d->{ $2 }->{'iterations_per_second'} = $4;
+
+ # usual test benchmark times output
+ # startup times: 0.1 0 0 0 0.1 0 0.76 0.09
+ } elsif ( $l =~ /^(\w+)\s+times:\s+(.+)$/ ) {
+ $d->{ $1 }->{'times'} = beautify_times( $2 );
+
+ # parse the memory footprint stuff
+ } elsif ( $l =~ /^pidinfo:\s+(.+)$/ ) {
+ # what should we analyze?
+ my $pidinfo = $1;
+
+ # VmPeak: 16172 kB
+ if ( $pidinfo =~ /^VmPeak:\s+(.+)$/ ) {
+ $test->{'pidinfo'}->{'vmpeak'} = $1;
+
+ # voluntary_ctxt_switches: 10
+ } elsif ( $pidinfo =~ /^voluntary_ctxt_switches:\s+(.+)$/ ) {
+ $test->{'pidinfo'}->{'voluntary_ctxt'} = $1;
+
+ # nonvoluntary_ctxt_switches: 1221
+ } elsif ( $pidinfo =~ /^nonvoluntary_ctxt_switches:\s+(.+)$/ ) {
+ $test->{'pidinfo'}->{'nonvoluntary_ctxt'} = $1;
+
+ } else {
+ # ignore the rest of the fluff
+ }
+ # parse the perl binary stuff
+ } elsif ( $l =~ /^perlconfig:\s+(.+)$/ ) {
+ # what should we analyze?
+ my $perlconfig = $1;
+
+ # Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
+ if ( $perlconfig =~ /^Summary\s+of\s+my\s+perl\d\s+\(([^\)]+)\)/ ) {
+ $test->{'perlconfig'}->{'version'} = $1;
+
+ } else {
+ # ignore the rest of the fluff
+ }
+
+ # parse the CPU info
+ } elsif ( $l =~ /^cpuinfo:\s+(.+)$/ ) {
+ # what should we analyze?
+ my $cpuinfo = $1;
+
+ # FIXME if this is on a multiproc system, we will overwrite the data per processor ( harmless? )
+
+ # cpu MHz : 1201.000
+ if ( $cpuinfo =~ /^cpu\s+MHz\s+:\s+(.+)$/ ) {
+ $test->{'cpuinfo'}->{'mhz'} = $1;
+
+ # model name : Intel(R) Core(TM)2 Duo CPU L7100 @ 1.20GHz
+ } elsif ( $cpuinfo =~ /^model\s+name\s+:\s+(.+)$/ ) {
+ $test->{'cpuinfo'}->{'name'} = $1;
+
+ # bogomips : 2397.58
+ } elsif ( $cpuinfo =~ /^bogomips\s+:\s+(.+)$/ ) {
+ $test->{'cpuinfo'}->{'bogomips'} = $1;
+
+ } else {
+ # ignore the rest of the fluff
+ }
+
+ # data that we can safely throw away
+ } elsif ( $l eq 'TEST TERMINATED DUE TO TIMEOUT' or
+ $l eq 'Using NO Assertions!' or
+ $l eq 'Using FULL Assertions!' or
+ $l eq 'Using the LITE tests' or
+ $l eq 'Using the HEAVY tests' or
+ $l eq 'DISABLING POE::XS::Queue::Array' or
+ $l eq '!STDERR: Devel::Hide hides POE/XS/Queue/Array.pm' or
+ $l eq 'LETTING POE find POE::XS::Queue::Array' or
+ $l eq 'UNABLE TO GET /proc/self/status' or
+ $l eq 'UNABLE TO GET /proc/cpuinfo' ) {
+ # ignore them
+
+ # parse the perl binary stuff
+ } elsif ( $l =~ /^Running\s+under\s+perl\s+binary:\s+(.+)$/ ) {
+ $test->{'perlconfig'}->{'binary'} = $1;
+
+ # the master loop version ( what the POE::Loop::XYZ actually uses )
+ # Using loop: EV-3.49
+ } elsif ( $l =~ /^Using\s+master\s+loop:\s+(.+)$/ ) {
+ $test->{'poe_loop_master'} = $1;
+
+ # the real POE version that was loaded
+ # Using POE-1.001
+ } elsif ( $l =~ /^Using\s+POE-(.+)$/ ) {
+ $test->{'poe_version_loaded'} = $1;
+
+ # the various queue/loop modules we loaded
+ # POE is using: POE::XS::Queue::Array v0.005
+ # POE is using: POE::Queue v1.2328
+ # POE is using: POE::Loop::EV v0.06
+ } elsif ( $l =~ /^POE\s+is\s+using:\s+([^\s]+)\s+v(.+)$/ ) {
+ $test->{'poe_modules'}->{ $1 } = $2;
+
+ # get the uname info
+ # Running under machine: Linux apoc-x300 2.6.24-21-generic #1 SMP Tue Oct 21 23:43:45 UTC 2008 i686 GNU/Linux
+ } elsif ( $l =~ /^Running\s+under\s+machine:\s+(.+)$/ ) {
+ $test->{'uname'} = $1;
+
+ # the SubProcess version
+ } elsif ( $l =~ /^SubProcess-(.+)$/ ) {
+ $test->{'benchmarker_version'} = $1;
+
+ # parse the SKIP tests
+ # SKIPPING MYFH tests on broken loop: Event_Lib
+ # SKIPPING STDIN tests on broken loop: Tk
+ } elsif ( $l =~ /^SKIPPING\s+(\w+)\s+tests\s+on\s+broken/ ) {
+ my $fh = $1;
+
+ # nullify the data struct for that
+ foreach my $type ( qw( select_read select_write ) ) {
+ $d->{ $type . $fh }->{'loops'} = undef;
+ $d->{ $type . $fh }->{'time'} = undef;
+ $d->{ $type . $fh }->{'times'} = undef;
+ $d->{ $type . $fh }->{'iterations_per_second'} = undef;
+ }
+
+ # parse the FH/STDIN failures
+ # filehandle select_read on STDIN FAILED: error
+ # filehandle select_write on MYFH FAILED: foo
+ } elsif ( $l =~ /^filehandle\s+(\w+)\s+on\s+(\w+)\s+FAILED:/ ) {
+ my( $mode, $type ) = ( $1, $2 );
+
+ # nullify the data struct for that
+ $d->{ $mode . $type }->{'loops'} = undef;
+ $d->{ $mode . $type }->{'time'} = undef;
+ $d->{ $mode . $type }->{'times'} = undef;
+ $d->{ $mode . $type }->{'iterations_per_second'} = undef;
+
+ # parse the alarm_add skip
+ # alarm_add NOT SUPPORTED on this version of POE, skipping alarm_adds/alarm_clears tests!
+ } elsif ( $l =~ /^alarm_add\s+NOT\s+SUPPORTED\s+on/ ) {
+ # nullify the data struct for that
+ foreach my $type ( qw( alarm_adds alarm_clears ) ) {
+ $d->{ $type }->{'loops'} = undef;
+ $d->{ $type }->{'time'} = undef;
+ $d->{ $type }->{'times'} = undef;
+ $d->{ $type }->{'iterations_per_second'} = undef;
+ }
+
+ # parse any STDERR output
+ # !STDERR: unable to foo
+ } elsif ( $l =~ /^\!STDERR:\s+(.+)$/ ) {
+ push( @{ $test->{'stderr'} }, $1 );
+
+ } else {
+ # unknown line :(
+ push( @unknown, $l );
+ }
+ }
+
+ # Get rid of the rawdata
+ delete $test->{'rawdata'};
+
+ # Dump the unknowns
+ if ( @unknown ) {
+ print "[ANALYZER] Unknown output from benchmark -> " . Dump( \@unknown );
+ }
+
+ # Dump the data struct we have to the file.yml
+ my $yaml_file = 'results/' . delete $test->{'test_file'};
+ $yaml_file .= '.yml';
+ my $ret = open( my $fh, '>', $yaml_file );
+ if ( defined $ret ) {
+ print $fh Dump( $test );
+ if ( ! close( $fh ) ) {
+ print "[ANALYZER] Unable to close $yaml_file -> " . $! . "\n";
+ }
+ } else {
+ print "[ANALYZER] Unable to open $yaml_file for writing -> " . $! . "\n";
+ }
+
+ # TODO send the $test data struct to a DB
+
+ return;
+}
+
+1;
+__END__
+=head1 NAME
+
+POE::Devel::Benchmarker::Analyzer - Analyzes the output from the benchmarks
+
+=head1 SYNOPSIS
+
+ Don't use this module directly. Please use POE::Devel::Benchmarker.
+
+=head1 ABSTRACT
+
+This package implements the guts of converting the raw data into a machine-readable format. Furthermore, it dumps the data
+in YAML format.
+
+=head1 EXPORT
+
+Automatically exports the initAnalyzer() sub
+
+=head1 SEE ALSO
+
+L<POE::Devel::Benchmarker>
+
+=head1 AUTHOR
+
+Apocalypse E<lt>apocal@cpan.orgE<gt>
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright 2008 by Apocalypse
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
+
+# sample test output ( from SubProcess v0.02 )
+STARTTIME: 1229173634.36228 -> TIMES 0.17 0.02 0.76 0.12
+POE-1.003-Event_Lib-noassert-noxsqueue
+
+Using master loop: Event_Lib-1.03
+Using NO Assertions!
+Using the LITE tests
+LETTING POE find POE::XS::Queue::Array
+Using POE-1.003
+POE is using: POE::XS::Queue::Array v0.005
+POE is using: POE::Queue v1.2328
+POE is using: POE::Loop::Event_Lib v0.001_01
+
+
+ 10 startups in 0.898 seconds ( 11.134 per second)
+startup times: 0.1 0.01 0 0 0.1 0.01 0.81 0.09
+ 10000 posts in 0.372 seconds ( 26896.254 per second)
+posts times: 0.1 0.01 0.81 0.09 0.42 0.06 0.81 0.09
+ 10000 dispatches in 0.658 seconds ( 15196.902 per second)
+dispatches times: 0.42 0.06 0.81 0.09 1.06 0.06 0.81 0.09
+ 10000 alarms in 1.020 seconds ( 9802.144 per second)
+alarms times: 1.07 0.06 0.81 0.09 1.89 0.26 0.81 0.09
+ 10000 alarm_adds in 0.415 seconds ( 24111.902 per second)
+alarm_adds times: 1.89 0.26 0.81 0.09 2.3 0.26 0.81 0.09
+ 10000 alarm_clears in 0.221 seconds ( 45239.068 per second)
+alarm_clears times: 2.3 0.26 0.81 0.09 2.52 0.26 0.81 0.09
+ 500 session_creates in 0.114 seconds ( 4367.120 per second)
+session_creates times: 2.52 0.26 0.81 0.09 2.63 0.27 0.81 0.09
+ 500 session destroys in 0.116 seconds ( 4311.978 per second)
+session_destroys times: 2.63 0.27 0.81 0.09 2.74 0.28 0.81 0.09
+ 10000 select_read_STDIN in 2.003 seconds ( 4992.736 per second)
+select_read_STDIN times: 2.74 0.28 0.81 0.09 4.66 0.35 0.81 0.09
+ 10000 select_write_STDIN in 1.971 seconds ( 5074.097 per second)
+select_write_STDIN times: 4.66 0.35 0.81 0.09 6.56 0.39 0.81 0.09
+SKIPPING MYFH tests on broken loop: Event_Lib
+ 10000 calls in 0.213 seconds ( 46963.378 per second)
+calls times: 6.56 0.39 0.81 0.09 6.78 0.39 0.81 0.09
+ 10000 single_posts in 1.797 seconds ( 5565.499 per second)
+single_posts times: 6.78 0.39 0.81 0.09 8.13 0.83 0.81 0.09
+pidinfo: Name: perl
+pidinfo: State: R (running)
+pidinfo: Tgid: 6750
+pidinfo: Pid: 6750
+pidinfo: PPid: 6739
+pidinfo: TracerPid: 0
+pidinfo: Uid: 1000 1000 1000 1000
+pidinfo: Gid: 1000 1000 1000 1000
+pidinfo: FDSize: 32
+pidinfo: Groups: 4 20 24 25 29 30 44 46 107 109 115 127 1000 1001
+pidinfo: VmPeak: 14916 kB
+pidinfo: VmSize: 14756 kB
+pidinfo: VmLck: 0 kB
+pidinfo: VmHWM: 11976 kB
+pidinfo: VmRSS: 11828 kB
+pidinfo: VmData: 10104 kB
+pidinfo: VmStk: 84 kB
+pidinfo: VmExe: 1044 kB
+pidinfo: VmLib: 2180 kB
+pidinfo: VmPTE: 24 kB
+pidinfo: Threads: 1
+pidinfo: SigQ: 0/16182
+pidinfo: SigPnd: 0000000000000000
+pidinfo: ShdPnd: 0000000000000000
+pidinfo: SigBlk: 0000000000000000
+pidinfo: SigIgn: 0000000000001080
+pidinfo: SigCgt: 0000000180000000
+pidinfo: CapInh: 0000000000000000
+pidinfo: CapPrm: 0000000000000000
+pidinfo: CapEff: 0000000000000000
+pidinfo: Cpus_allowed: 03
+pidinfo: Mems_allowed: 1
+pidinfo: voluntary_ctxt_switches: 11
+pidinfo: nonvoluntary_ctxt_switches: 697
+Running under perl binary: /usr/bin/perl
+perlconfig: Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
+perlconfig: Platform:
+perlconfig: osname=linux, osvers=2.6.15.7, archname=i486-linux-gnu-thread-multi
+perlconfig: uname='linux palmer 2.6.15.7 #1 smp thu sep 7 19:42:20 utc 2006 i686 gnulinux '
+perlconfig: config_args='-Dusethreads -Duselargefiles -Dccflags=-DDEBIAN -Dcccdlflags=-fPIC -Darchname=i486-linux-gnu -Dprefix=/usr -Dprivlib=/usr/share/perl/5.8 -Darchlib=/usr/lib/perl/5.8 -Dvendorprefix=/usr -Dvendorlib=/usr/share/perl5 -Dvendorarch=/usr/lib/perl5 -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl/5.8.8 -Dsitearch=/usr/local/lib/perl/5.8.8 -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 -Dsiteman1dir=/usr/local/man/man1 -Dsiteman3dir=/usr/local/man/man3 -Dman1ext=1 -Dman3ext=3perl -Dpager=/usr/bin/sensible-pager -Uafs -Ud_csh -Ud_ualarm -Uusesfio -Uusenm -Duseshrplib -Dlibperl=libperl.so.5.8.8 -Dd_dosuid -des'
+perlconfig: hint=recommended, useposix=true, d_sigaction=define
+perlconfig: usethreads=define use5005threads=undef useithreads=define usemultiplicity=define
+perlconfig: useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
+perlconfig: use64bitint=undef use64bitall=undef uselongdouble=undef
+perlconfig: usemymalloc=n, bincompat5005=undef
+perlconfig: Compiler:
+perlconfig: cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBIAN -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
+perlconfig: optimize='-O2',
+perlconfig: cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBIAN -fno-strict-aliasing -pipe -I/usr/local/include'
+perlconfig: ccversion='', gccversion='4.2.3 20071123 (prerelease) (Ubuntu 4.2.2-3ubuntu4)', gccosandvers=''
+perlconfig: intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
+perlconfig: d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
+perlconfig: ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
+perlconfig: alignbytes=4, prototype=define
+perlconfig: Linker and Libraries:
+perlconfig: ld='cc', ldflags =' -L/usr/local/lib'
+perlconfig: libpth=/usr/local/lib /lib /usr/lib
+perlconfig: libs=-lgdbm -lgdbm_compat -ldb -ldl -lm -lpthread -lc -lcrypt
+perlconfig: perllibs=-ldl -lm -lpthread -lc -lcrypt
+perlconfig: libc=/lib/libc-2.6.1.so, so=so, useshrplib=true, libperl=libperl.so.5.8.8
+perlconfig: gnulibc_version='2.6.1'
+perlconfig: Dynamic Linking:
+perlconfig: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
+perlconfig: cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib'
+Running under machine: Linux apoc-x300 2.6.24-21-generic #1 SMP Tue Oct 21 23:43:45 UTC 2008 i686 GNU/Linux
+
+cpuinfo: processor : 0
+cpuinfo: vendor_id : GenuineIntel
+cpuinfo: cpu family : 6
+cpuinfo: model : 15
+cpuinfo: model name : Intel(R) Core(TM)2 Duo CPU L7100 @ 1.20GHz
+cpuinfo: stepping : 11
+cpuinfo: cpu MHz : 1201.000
+cpuinfo: cache size : 4096 KB
+cpuinfo: physical id : 0
+cpuinfo: siblings : 2
+cpuinfo: core id : 0
+cpuinfo: cpu cores : 2
+cpuinfo: fdiv_bug : no
+cpuinfo: hlt_bug : no
+cpuinfo: f00f_bug : no
+cpuinfo: coma_bug : no
+cpuinfo: fpu : yes
+cpuinfo: fpu_exception : yes
+cpuinfo: cpuid level : 10
+cpuinfo: wp : yes
+cpuinfo: flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc arch_perfmon pebs bts pni monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr lahf_lm ida
+cpuinfo: bogomips : 2397.58
+cpuinfo: clflush size : 64
+cpuinfo:
+cpuinfo: processor : 1
+cpuinfo: vendor_id : GenuineIntel
+cpuinfo: cpu family : 6
+cpuinfo: model : 15
+cpuinfo: model name : Intel(R) Core(TM)2 Duo CPU L7100 @ 1.20GHz
+cpuinfo: stepping : 11
+cpuinfo: cpu MHz : 1201.000
+cpuinfo: cache size : 4096 KB
+cpuinfo: physical id : 0
+cpuinfo: siblings : 2
+cpuinfo: core id : 1
+cpuinfo: cpu cores : 2
+cpuinfo: fdiv_bug : no
+cpuinfo: hlt_bug : no
+cpuinfo: f00f_bug : no
+cpuinfo: coma_bug : no
+cpuinfo: fpu : yes
+cpuinfo: fpu_exception : yes
+cpuinfo: cpuid level : 10
+cpuinfo: wp : yes
+cpuinfo: flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe nx lm constant_tsc arch_perfmon pebs bts pni monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr lahf_lm ida
+cpuinfo: bogomips : 2394.02
+cpuinfo: clflush size : 64
+cpuinfo:
+
+ENDTIME: 1229173644.30093 -> TIMES 0.19 0.02 1.08 0.16
diff --git a/lib/POE/Devel/Benchmarker/SubProcess.pm b/lib/POE/Devel/Benchmarker/SubProcess.pm
index 055712e..d2469b6 100644
--- a/lib/POE/Devel/Benchmarker/SubProcess.pm
+++ b/lib/POE/Devel/Benchmarker/SubProcess.pm
@@ -1,658 +1,654 @@
# Declare our package
package POE::Devel::Benchmarker::SubProcess;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
-$VERSION = '0.01';
+$VERSION = '0.02';
# Import Time::HiRes's time()
use Time::HiRes qw( time );
# FIXME UGLY HACK here
BEGIN {
# should we enable assertions?
if ( defined $ARGV[2] and $ARGV[2] ) {
## no critic
eval "sub POE::Kernel::ASSERT_DEFAULT () { 1 }";
eval "sub POE::Session::ASSERT_STATES () { 1 }";
## use critic
}
# should we "hide" XS::Queue::Array?
if ( defined $ARGV[4] and $ARGV[4] ) {
## no critic
eval "use Devel::Hide qw( POE/XS/Queue/Array.pm )";
## use critic
}
}
# load POE
use POE;
# load our utility stuff
-use POE::Devel::Benchmarker::Utils;
-
-# autoflush our STDOUT for sanity
-use FileHandle;
-autoflush STDOUT 1;
+use POE::Devel::Benchmarker::Utils qw( loop2realversion poeloop2load );
# init our global variables ( bad, haha )
my( $version, $eventloop, $asserts, $lite_tests, $pocosession );
my( $post_limit, $alarm_limit, $alarm_add_limit, $session_limit, $select_limit, $through_limit, $call_limit, $start_limit );
# the main routine which will load everything + start
sub benchmark {
+ # autoflush our STDOUT for sanity
+ STDOUT->autoflush( 1 );
+
+ # print our banner
+ print "SubProcess-" . __PACKAGE__->VERSION . "\n";
+
# process the version
process_version();
# process the eventloop
process_eventloop();
# process the assertions
process_assertions();
# process the test mode
process_testmode();
# process the XS::Queue hiding
process_xsqueue();
# actually import POE!
process_POE();
# actually run the benchmarks!
run_benchmarks();
# all done!
return;
}
sub process_version {
# Get the desired POE version
$version = $ARGV[0];
# Decide what to do
if ( ! defined $version ) {
die "Please supply a version to test!";
} elsif ( ! -d 'poedists/POE-' . $version ) {
die "That specified version does not exist!";
} else {
# we're happy...
}
return;
}
sub process_eventloop {
# Get the desired mode
$eventloop = $ARGV[1];
# print out the loop info
if ( ! defined $eventloop ) {
die "Please supply an event loop!";
} else {
- my $v = loop2realversion( $eventloop ) || 'UNKNOWN';
- print "Using loop: $eventloop-$v\n";
+ my $loop = poeloop2load( $eventloop );
+ if ( ! defined $loop ) {
+ $loop = $eventloop;
+ }
+ my $v = loop2realversion( $eventloop );
+ if ( ! defined $v ) {
+ $v = 'UNKNOWN';
+ }
+ print "Using master loop: $loop-$v\n";
}
return;
}
sub process_assertions {
# Get the desired assert mode
$asserts = $ARGV[2];
if ( defined $asserts and $asserts ) {
print "Using FULL Assertions!\n";
} else {
print "Using NO Assertions!\n";
}
return;
}
sub process_testmode {
# get the desired test mode
$lite_tests = $ARGV[3];
if ( defined $lite_tests and $lite_tests ) {
print "Using the LITE tests\n";
$post_limit = 10_000;
$alarm_limit = 10_000;
$alarm_add_limit = 10_000;
$session_limit = 500;
$select_limit = 10_000;
$through_limit = 10_000;
$call_limit = 10_000;
$start_limit = 10;
} else {
print "Using the HEAVY tests\n";
$post_limit = 100_000;
$alarm_limit = 100_000;
$alarm_add_limit = 100_000;
$session_limit = 5_000;
$select_limit = 100_000;
$through_limit = 100_000;
$call_limit = 100_000;
$start_limit = 100;
}
return;
}
sub process_xsqueue {
# should we "hide" XS::Queue::Array?
if ( defined $ARGV[4] and $ARGV[4] ) {
print "DISABLING POE::XS::Queue::Array\n";
} else {
print "LETTING POE find POE::XS::Queue::Array\n";
}
return;
}
sub process_POE {
# Print the POE info
print "Using POE-" . $POE::VERSION . "\n";
# Actually print what loop POE is using
foreach my $m ( keys %INC ) {
if ( $m =~ /^POE\/(?:Loop|XS|Queue)/ ) {
# try to be smart and get version?
my $module = $m;
$module =~ s|/|::|g;
$module =~ s/\.pm$//g;
print "POE is using: $module ";
if ( defined $module->VERSION ) {
print "v" . $module->VERSION . "\n";
} else {
print "vUNKNOWN\n";
}
}
}
return;
}
sub run_benchmarks {
# run the startup test before we actually run POE
bench_startup();
# load the POE session + do the tests there
bench_poe();
# dump some misc info
- dump_memory();
- dump_times();
+ dump_pidinfo();
dump_perlinfo();
dump_sysinfo();
# all done!
return;
}
sub bench_startup {
# Add the eventloop?
my $looploader = poeloop2load( $eventloop );
my @start_times = times();
my $start = time();
for (my $i = 0; $i < $start_limit; $i++) {
# FIXME should we add assertions?
# finally, fire it up!
CORE::system(
$^X,
'-Ipoedists/POE-' . $version,
'-Ipoedists/POE-' . $version . '/lib',
( defined $looploader ? "-M$looploader" : () ),
'-MPOE',
'-e',
1,
);
}
my @end_times = times();
my $elapsed = time() - $start;
printf( "\n\n% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $start_limit, 'startups', $elapsed, $start_limit/$elapsed );
- print "startup times: @start_times @end_times\n";
+ print "startups times: @start_times @end_times\n";
return;
}
sub bench_poe {
# figure out POE::Session->create or POE::Session->new or what?
$pocosession = POE::Session->can( 'create' );
if ( defined $pocosession ) {
$pocosession = 'create';
} else {
$pocosession = POE::Session->can( 'spawn' );
if ( defined $pocosession ) {
$pocosession = 'spawn';
} else {
$pocosession = 'new';
}
}
# create the master sesssion + run POE!
POE::Session->$pocosession(
'inline_states' => {
# basic POE states
'_start' => \&poe__start,
'_default' => \&poe__default,
'_stop' => \&poe__stop,
'null' => \&poe_null,
# our test states
'posts' => \&poe_posts,
'posts_start' => \&poe_posts_start,
'posts_end' => \&poe_posts_end,
'alarms' => \&poe_alarms,
'manyalarms' => \&poe_manyalarms,
'sessions' => \&poe_sessions,
'sessions_end' => \&poe_sessions_end,
'stdin_read' => \&poe_stdin_read,
'stdin_write' => \&poe_stdin_write,
'myfh_read' => \&poe_myfh_read,
'myfh_write' => \&poe_myfh_write,
'calls' => \&poe_calls,
'eventsquirt' => \&poe_eventsquirt,
'eventsquirt_done' => \&poe_eventsquirt_done,
},
);
# start the kernel!
POE::Kernel->run();
return;
}
# inits our session
sub poe__start {
# fire off the first test!
$_[KERNEL]->yield( 'posts' );
return;
}
sub poe__stop {
}
sub poe__default {
return 0;
}
# a state that does nothing
sub poe_null {
return 1;
}
# How many posts per second? Post a bunch of events, keeping track of the time it takes.
sub poe_posts {
$_[KERNEL]->yield( 'posts_start' );
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $post_limit; $i++) {
$_[KERNEL]->yield( 'null' );
}
my @end_times = times();
my $elapsed = time() - $start;
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $post_limit, 'posts', $elapsed, $post_limit/$elapsed );
print "posts times: @start_times @end_times\n";
$_[KERNEL]->yield( 'posts_end' );
return;
}
sub poe_posts_start {
$_[HEAP]->{start} = time();
$_[HEAP]->{starttimes} = [ times() ];
return;
}
sub poe_posts_end {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $post_limit, 'dispatches', $elapsed, $post_limit/$elapsed );
print "dispatches times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
$_[KERNEL]->yield( 'alarms' );
return;
}
# How many alarms per second? Set a bunch of alarms and find out.
sub poe_alarms {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $alarm_limit; $i++) {
$_[KERNEL]->alarm( whee => rand(1_000_000) );
}
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $alarm_limit, 'alarms', $elapsed, $alarm_limit/$elapsed );
print "alarms times: @start_times @end_times\n";
$_[KERNEL]->alarm( 'whee' => undef );
$_[KERNEL]->yield( 'manyalarms' );
return;
}
# How many repetitive alarms per second? Set a bunch of
# additional alarms and find out. Also see how quickly they can
# be cleared.
sub poe_manyalarms {
# can this POE::Kernel support this?
if ( $_[KERNEL]->can( 'alarm_add' ) ) {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $alarm_add_limit; $i++) {
$_[KERNEL]->alarm_add( whee => rand(1_000_000) );
}
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $alarm_add_limit, 'alarm_adds', $elapsed, $alarm_add_limit/$elapsed );
print "alarm_adds times: @start_times @end_times\n";
$start = time();
@start_times = times();
$_[KERNEL]->alarm( whee => undef );
$elapsed = time() - $start;
@end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $alarm_add_limit, 'alarm_clears', $elapsed, $alarm_add_limit/$elapsed );
print "alarm_clears times: @start_times @end_times\n";
} else {
- print "this version of POE does not support alarm_add, skipping alarm_adds/alarm_clears tests!\n";
+ print "alarm_add NOT SUPPORTED on this version of POE, skipping alarm_adds/alarm_clears tests!\n";
}
$_[KERNEL]->yield( 'sessions' );
return;
}
# How many sessions can we create and destroy per second?
# Create a bunch of sessions, and track that time. Let them
# self-destruct, and track that as well.
sub poe_sessions {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $session_limit; $i++) {
POE::Session->$pocosession( 'inline_states' => { _start => sub {}, _stop => sub {}, _default => sub { return 0 } } );
}
my $elapsed = time() - $start;
my @end_times = times();
- printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $session_limit, 'session creates', $elapsed, $session_limit/$elapsed );
- print "session create times: @start_times @end_times\n";
+ printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $session_limit, 'session_creates', $elapsed, $session_limit/$elapsed );
+ print "session_creates times: @start_times @end_times\n";
$_[KERNEL]->yield( 'sessions_end' );
$_[HEAP]->{start} = time();
$_[HEAP]->{starttimes} = [ times() ];
return;
}
sub poe_sessions_end {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
- printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $session_limit, 'session destroys', $elapsed, $session_limit/$elapsed );
- print "session destroys times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
+ printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $session_limit, 'session_destroys', $elapsed, $session_limit/$elapsed );
+ print "session_destroys times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
$_[KERNEL]->yield( 'stdin_read' );
return;
}
# How many times can we select/unselect READ a from STDIN filehandle per second?
sub poe_stdin_read {
# stupid, but we have to skip those tests
if ( $eventloop eq 'Tk' or $eventloop eq 'Prima' ) {
print "SKIPPING STDIN tests on broken loop: $eventloop\n";
$_[KERNEL]->yield( 'myfh_read' );
return;
}
my $start = time();
my @start_times = times();
eval {
for (my $i = 0; $i < $select_limit; $i++) {
$_[KERNEL]->select_read( *STDIN, 'whee' );
$_[KERNEL]->select_read( *STDIN );
}
};
if ( $@ ) {
- print "filehandle select_read on *STDIN FAILED: $@\n";
+ print "filehandle select_read on STDIN FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
- printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $select_limit, 'select_read STDIN', $elapsed, $select_limit/$elapsed );
- print "select_read STDIN times: @start_times @end_times\n";
+ printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $select_limit, 'select_read_STDIN', $elapsed, $select_limit/$elapsed );
+ print "select_read_STDIN times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'stdin_write' );
return;
}
# How many times can we select/unselect WRITE a from STDIN filehandle per second?
sub poe_stdin_write {
my $start = time();
my @start_times = times();
eval {
for (my $i = 0; $i < $select_limit; $i++) {
$_[KERNEL]->select_write( *STDIN, 'whee' );
$_[KERNEL]->select_write( *STDIN );
}
};
if ( $@ ) {
- print "filehandle select_write on *STDIN FAILED: $@\n";
+ print "filehandle select_write on STDIN FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
- printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $select_limit, 'select_write STDIN', $elapsed, $select_limit/$elapsed );
- print "select_write STDIN times: @start_times @end_times\n";
+ printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $select_limit, 'select_write_STDIN', $elapsed, $select_limit/$elapsed );
+ print "select_write_STDIN times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'myfh_read' );
return;
}
# How many times can we select/unselect READ a real filehandle?
sub poe_myfh_read {
# stupid, but we have to skip those tests
if ( $eventloop eq 'Event_Lib' or $eventloop eq 'Tk' or $eventloop eq 'Prima' ) {
print "SKIPPING MYFH tests on broken loop: $eventloop\n";
$_[KERNEL]->yield( 'calls' );
return;
}
- open( my $fh, '+>', 'poebench' ) or die $!;
my $start = time();
my @start_times = times();
eval {
+ open( my $fh, '+>', 'poebench' ) or die $!;
for (my $i = 0; $i < $select_limit; $i++) {
$_[KERNEL]->select_read( $fh, 'whee' );
$_[KERNEL]->select_read( $fh );
}
+ close( $fh ) or die $!;
+ unlink( 'poebench' ) or die $!;
};
if ( $@ ) {
- print "filehandle select_read on *MYFH FAILED: $@\n";
+ print "filehandle select_read on MYFH FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
- printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $select_limit, 'select_read MYFH', $elapsed, $select_limit/$elapsed );
- print "select_read MYFH times: @start_times @end_times\n";
+ printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $select_limit, 'select_read_MYFH', $elapsed, $select_limit/$elapsed );
+ print "select_read_MYFH times: @start_times @end_times\n";
}
- close( $fh ) or die $!;
- unlink( 'poebench' ) or die $!;
-
$_[KERNEL]->yield( 'myfh_write' );
return;
}
# How many times can we select/unselect WRITE a real filehandle?
sub poe_myfh_write {
- open( my $fh, '+>', 'poebench' ) or die $!;
my $start = time();
my @start_times = times();
eval {
+ open( my $fh, '+>', 'poebench' ) or die $!;
for (my $i = 0; $i < $select_limit; $i++) {
$_[KERNEL]->select_write( $fh, 'whee' );
$_[KERNEL]->select_write( $fh );
}
+ close( $fh ) or die $!;
+ unlink( 'poebench' ) or die $!;
};
if ( $@ ) {
- print "filehandle select_write on *MYFH FAILED: $@\n";
+ print "filehandle select_write on MYFH FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
- printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $select_limit, 'select_write MYFH', $elapsed, $select_limit/$elapsed );
- print "select_write MYFH times: @start_times @end_times\n";
+ printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $select_limit, 'select_write_MYFH', $elapsed, $select_limit/$elapsed );
+ print "select_write_MYFH times: @start_times @end_times\n";
}
- close( $fh ) or die $!;
- unlink( 'poebench' ) or die $!;
-
$_[KERNEL]->yield( 'calls' );
return;
}
# How many times can we call a state?
sub poe_calls {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $call_limit; $i++) {
$_[KERNEL]->call( $_[SESSION], 'null' );
}
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $call_limit, 'calls', $elapsed, $call_limit/$elapsed );
print "calls times: @start_times @end_times\n";
$_[KERNEL]->yield( 'eventsquirt' );
return;
}
# How many events can we squirt through POE, one at a time?
sub poe_eventsquirt {
$_[HEAP]->{start} = time();
$_[HEAP]->{starttimes} = [ times() ];
$_[HEAP]->{yield_count} = $through_limit;
$_[KERNEL]->yield( 'eventsquirt_done' );
return;
}
sub poe_eventsquirt_done {
if (--$_[HEAP]->{yield_count}) {
$_[KERNEL]->yield( 'eventsquirt_done' );
} else {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $through_limit, 'single_posts', $elapsed, $through_limit/$elapsed );
print "single_posts times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
}
# reached end of tests!
return;
}
# Get the memory footprint
-sub dump_memory {
- print "\n\nMemory footprint:\n";
- open( my $fh, '<', '/proc/self/status' ) or die $!;
- while ( <$fh> ) {
- print;
+sub dump_pidinfo {
+ my $ret = open( my $fh, '<', '/proc/self/status' );
+ if ( defined $ret ) {
+ while ( <$fh> ) {
+ print "pidinfo: $_";
+ }
+ close( $fh ) or die $!;
+ } else {
+ print "UNABLE TO GET /proc/self/status\n";
}
- close( $fh ) or die $!;
-
- return;
-}
-
-# print the time it took to execute this program
-sub dump_times {
- my ($wall, $user, $system, $cuser, $csystem) = ( (time-$^T), times() );
- printf( ( "\n\n--- times ---\n" .
- "wall : %9.3f\n" .
- "user : %9.3f cuser: %9.3f\n" .
- "sys : %9.3f csys : %9.3f\n"
- ),
- $wall, $user, $cuser, $system, $csystem,
- );
return;
}
# print the local Perl info
sub dump_perlinfo {
- print "\n\nRunning under perl binary: " . $^X . "\n";
+ print "Running under perl binary: " . $^X . "\n";
require Config;
- print Config::myconfig();
+ my $config = Config::myconfig();
+ foreach my $l ( split( /\n/, $config ) ) {
+ print "perlconfig: $l\n";
+ }
return;
}
# print the local system information
sub dump_sysinfo {
print "Running under machine: " . `uname -a` . "\n";
# get cpuinfo
- print "Running under CPU:\n";
- open( my $fh, '<', '/proc/cpuinfo' ) or die $!;
- while ( <$fh> ) {
- print;
- }
- close( $fh ) or die $!;
-
- # get meminfo
- print "Running under meminfo:\n";
- open( $fh, '<', '/proc/meminfo' ) or die $!;
- while ( <$fh> ) {
- print;
+ my $ret = open( my $fh, '<', '/proc/cpuinfo' );
+ if ( defined $ret ) {
+ while ( <$fh> ) {
+ chomp;
+ if ( $_ ne '' ) {
+ print "cpuinfo: $_\n";
+ }
+ }
+ close( $fh ) or die $!;
+ } else {
+ print "UNABLE TO GET /proc/cpuinfo\n";
}
- close( $fh ) or die $!;
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::SubProcess - Implements the actual POE benchmarks
=head1 SYNOPSIS
perl -MPOE::Devel::Benchmarker::SubProcess -e 'benchmark()'
=head1 ABSTRACT
This package is responsible for implementing the guts of the benchmarks, and timing them.
=head1 EXPORT
Nothing.
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/Utils.pm b/lib/POE/Devel/Benchmarker/Utils.pm
index b7f84a4..42703ad 100644
--- a/lib/POE/Devel/Benchmarker/Utils.pm
+++ b/lib/POE/Devel/Benchmarker/Utils.pm
@@ -1,134 +1,190 @@
# Declare our package
package POE::Devel::Benchmarker::Utils;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
-$VERSION = '0.01';
+$VERSION = '0.02';
# auto-export the only sub we have
require Exporter;
-use vars qw( @ISA @EXPORT );
+use vars qw( @ISA @EXPORT_OK );
@ISA = qw(Exporter);
-@EXPORT = qw( poeloop2load loop2realversion );
+@EXPORT_OK = qw( poeloop2load loop2realversion beautify_times );
# returns the proper "load" stuff for a specific loop
sub poeloop2load {
my $eventloop = shift;
# Decide which event loop to use
# Event_Lib EV Glib Prima Gtk Wx Kqueue Tk Select IO_Poll
if ( $eventloop eq 'Event' ) {
return 'Event';
} elsif ( $eventloop eq 'IO_Poll' ) {
return 'IO::Poll';
} elsif ( $eventloop eq 'Event_Lib' ) {
return 'Event::Lib';
} elsif ( $eventloop eq 'EV' ) {
return 'EV';
} elsif ( $eventloop eq 'Glib' ) {
return 'Glib';
} elsif ( $eventloop eq 'Tk' ) {
return 'Tk',
} elsif ( $eventloop eq 'Gtk' ) {
return 'Gtk';
} elsif ( $eventloop eq 'Prima' ) {
return 'Prima';
} elsif ( $eventloop eq 'Wx' ) {
return 'Wx';
} elsif ( $eventloop eq 'Kqueue' ) {
# FIXME dunno what to do here!
return;
} elsif ( $eventloop eq 'Select' ) {
return;
} else {
die "Unknown event loop!";
}
}
# returns the version of the "real" installed module that the loop uses
sub loop2realversion {
my $eventloop = shift;
# Decide which event loop to use
if ( ! defined $eventloop ) {
return;
} elsif ( $eventloop eq 'Event' ) {
return $Event::VERSION;
} elsif ( $eventloop eq 'IO_Poll' ) {
return $IO::Poll::VERSION;
} elsif ( $eventloop eq 'Event_Lib' ) {
return $Event::Lib::VERSION;
} elsif ( $eventloop eq 'EV' ) {
return $EV::VERSION;
} elsif ( $eventloop eq 'Glib' ) {
return $Glib::VERSION;
} elsif ( $eventloop eq 'Tk' ) {
return $Tk::VERSION;
} elsif ( $eventloop eq 'Gtk' ) {
return $Gtk::VERSION;
} elsif ( $eventloop eq 'Prima' ) {
return $Prima::VERSION;
} elsif ( $eventloop eq 'Wx' ) {
return $Wx::VERSION;
} elsif ( $eventloop eq 'Kqueue' ) {
# FIXME how do I do this?
return;
} elsif ( $eventloop eq 'Select' ) {
return 'BUILTIN';
} else {
die "Unknown event loop!";
}
}
+# helper routine to parse times() output
+sub beautify_times {
+ my $string = shift;
+ my $origdata = shift;
+
+ # split it up
+ $string =~ s/^\s+//; $string =~ s/\s+$//;
+ my @times = split( /\s+/, $string );
+
+ # make the data struct
+ # ($user,$system,$cuser,$csystem) = times;
+ my $data = {
+ 'user' => $times[4] - $times[0],
+ 'sys' => $times[5] - $times[1],
+ 'cuser' => $times[6] - $times[2],
+ 'csys' => $times[7] - $times[3],
+ };
+
+ # add original data?
+ if ( $origdata ) {
+ $data->{'s_user'} = $times[0];
+ $data->{'s_sys'} = $times[1];
+ $data->{'s_cuser'} = $times[2];
+ $data->{'s_csys'} = $times[3];
+ $data->{'e_user'} = $times[4];
+ $data->{'e_sys'} = $times[5];
+ $data->{'e_cuser'} = $times[6];
+ $data->{'e_csys'} = $times[7];
+ }
+
+ # send it back!
+ return $data;
+}
+
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::Utils - Various utility routines for POE::Devel::Benchmarker
=head1 SYNOPSIS
perl -MPOE::Devel::Benchmarker::Utils -e 'print poeloop2load( "IO_Poll" )'
=head1 ABSTRACT
This package contains the utility routines and constants that POE::Devel::Benchmarker needs.
=head1 EXPORT
-Automatically exports those subs:
+This package exports those subs via @EXPORT_OK:
=over 4
=item poeloop2load()
Returns the "parent" class to load for a specific loop. An example is:
$real = poeloop2load( 'IO_Poll' ); # $real now contains "IO::Poll"
=item loop2realversion()
Returns the version of the "parent" class for a specific loop. An example is:
$ver = loop2realversion( 'IO_Poll' ); # $ver now contains $IO::Poll::VERSION
+=item beautify_times()
+
+Returns a hashref of data from parsing 2 consecutive times() structures in a string. You can pass an additional parameter
+( boolean ) to include the original data. An example is:
+
+ print Data::Dumper::Dumper( beautify_times( '0.1 0 0 0 0.1 0 0.76 0.09', 1 ) );
+ {
+ "sys" => 0, # total system time
+ "user" => 0, # total user time
+ "csys" => 0.76 # total children system time
+ "cuser" => 0.08 # total children user time
+
+ "e_csys" => "0.09", # end children system time ( optional )
+ "e_cuser" => "0.76", # end children user time ( optional )
+ "e_sys" => 0, # end system time ( optional )
+ "e_user" => "0.1", # end user time ( optional )
+ "s_csys" => 0, # start children system time ( optional )
+ "s_cuser" => 0, # start children user time ( optional )
+ "s_sys" => 0, # start system time ( optional )
+ "s_user" => "0.1" # start user time ( optional )
+ }
+
=back
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
|
apocalypse/perl-poe-benchmarker
|
f9c0a824379cf1287dff56b865e72715cfab1aaa
|
final distro tarball after tweaks
|
diff --git a/POE-Devel-Benchmarker-0.01.tar.gz b/POE-Devel-Benchmarker-0.01.tar.gz
index 23e145f..ef90bb1 100644
Binary files a/POE-Devel-Benchmarker-0.01.tar.gz and b/POE-Devel-Benchmarker-0.01.tar.gz differ
diff --git a/lib/POE/Devel/Benchmarker.pm b/lib/POE/Devel/Benchmarker.pm
index 9290ac3..e4ceff7 100644
--- a/lib/POE/Devel/Benchmarker.pm
+++ b/lib/POE/Devel/Benchmarker.pm
@@ -1,551 +1,561 @@
# Declare our package
package POE::Devel::Benchmarker;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.01';
# auto-export the only sub we have
BEGIN {
require Exporter;
use vars qw( @ISA @EXPORT );
@ISA = qw(Exporter);
@EXPORT = qw( benchmark );
}
# Import what we need from the POE namespace
use POE qw( Session Filter::Line Wheel::Run );
use base 'POE::Session::AttributeBased';
# we need hires times
use Time::HiRes qw( time );
# load comparison stuff
use version;
# Load our stuff
use POE::Devel::Benchmarker::GetInstalledLoops;
use POE::Devel::Benchmarker::Utils;
# Actually run the tests!
sub benchmark {
my $options = shift;
# set default options
my $lite_tests = 1;
my $quiet_mode = 0;
# process our options
if ( defined $options and ref $options and ref( $options ) eq 'HASH' ) {
# process LITE tests
if ( exists $options->{'litetests'} ) {
if ( $options->{'litetests'} ) {
$lite_tests = 1;
} else {
$lite_tests = 0;
}
}
# process quiet mode
if ( exists $options->{'quiet'} ) {
if ( $options->{'quiet'} ) {
$quiet_mode = 1;
} else {
$quiet_mode = 0;
}
}
}
# do some sanity checks
if ( ! -d 'poedists' ) {
die "The 'poedists' directory is not found in the working directory!";
}
if ( ! -d 'results' ) {
die "The 'results' directory is not found in the working directory!";
}
if ( ! $quiet_mode ) {
print "[BENCHMARKER] Starting up...\n";
}
# Create our session
POE::Session->create(
__PACKAGE__->inline_states(),
'heap' => {
'lite_tests' => $lite_tests,
'quiet_mode' => $quiet_mode,
},
);
# Fire 'er up!
POE::Kernel->run();
return;
}
# Starts up our session
sub _start : State {
# set our alias
$_[KERNEL]->alias_set( 'Benchmarker' );
# sanely handle some signals
$_[KERNEL]->sig( 'INT', 'handle_kill' );
$_[KERNEL]->sig( 'TERM', 'handle_kill' );
# okay, get all the dists we can!
my @versions;
opendir( DISTS, 'poedists' ) or die $!;
foreach my $d ( readdir( DISTS ) ) {
if ( $d =~ /^POE\-(.+)$/ and $d !~ /\.tar\.gz$/ ) {
push( @versions, $1 );
}
}
closedir( DISTS ) or die $!;
# okay, go through all the dists in version order
@versions = sort { $b <=> $a }
map { version->new( $_ ) } @versions;
# Store the versions in our heap
$_[HEAP]->{'VERSIONS'} = \@versions;
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Detected available POE versions -> " . join( " ", @versions ) . "\n";
}
# First of all, we need to find out what loop libraries are installed
getPOEloops( $_[HEAP]->{'quiet_mode'} );
return;
}
sub _stop : State {
# tell the wheel to kill itself
if ( defined $_[HEAP]->{'WHEEL'} ) {
$_[HEAP]->{'WHEEL'}->kill( 9 );
undef $_[HEAP]->{'WHEEL'};
}
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Shutting down...\n";
}
return;
}
# we received list of loops from GetInstalledLoops
sub found_loops : State {
$_[HEAP]->{'installed_loops'} = [ sort { $a eq $b } @{ $_[ARG0] } ];
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Detected available POE::Loops -> " . join( " ", @{ $_[HEAP]->{'installed_loops'} } ) . "\n";
}
# start the benchmark!
$_[KERNEL]->yield( 'run_benchmark' );
return;
}
# Runs one benchmark
sub run_benchmark : State {
# Grab the version from the top of the array
$_[HEAP]->{'current_version'} = shift @{ $_[HEAP]->{'VERSIONS'} };
# did we run out of versions?
if ( ! defined $_[HEAP]->{'current_version'} ) {
# We're done, let POE die...
$_[KERNEL]->alias_remove( 'Benchmarker' );
} else {
$_[HEAP]->{'loops'} = [ @{ $_[HEAP]->{'installed_loops'} } ];
# okay, fire off the first loop
$_[KERNEL]->yield( 'bench_loop' );
}
return;
}
# runs one loop
sub bench_loop : State {
# select our current loop
$_[HEAP]->{'current_loop'} = shift @{ $_[HEAP]->{'loops'} };
# are we done with all loops?
if ( ! defined $_[HEAP]->{'current_loop'} ) {
# yay, go back to the main handler
$_[KERNEL]->yield( 'run_benchmark' );
} else {
# Start the assert test
$_[HEAP]->{'assertions'} = [ qw( 0 1 ) ];
$_[KERNEL]->yield( 'bench_asserts' );
}
return;
}
# runs an assertion
sub bench_asserts : State {
# select our current assert state
$_[HEAP]->{'current_assertions'} = shift @{ $_[HEAP]->{'assertions'} };
# are we done?
if ( ! defined $_[HEAP]->{'current_assertions'} ) {
# yay, go back to the loop handler
$_[KERNEL]->yield( 'bench_loop' );
} else {
# Start the xsqueue test
$_[HEAP]->{'xsqueue'} = [ qw( 0 1 ) ];
$_[KERNEL]->yield( 'bench_xsqueue' );
}
return;
}
# runs test with or without xsqueue
sub bench_xsqueue : State {
# select our current xsqueue state
$_[HEAP]->{'current_xsqueue'} = shift @{ $_[HEAP]->{'xsqueue'} };
# are we done?
if ( ! defined $_[HEAP]->{'current_xsqueue'} ) {
# yay, go back to the assert handler
$_[KERNEL]->yield( 'bench_asserts' );
} else {
# actually fire off the subprocess, ha!
$_[KERNEL]->yield( 'create_subprocess' );
}
return;
}
# actually runs the subprocess
sub create_subprocess : State {
# Okay, start testing this specific combo!
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "Testing POE v" . $_[HEAP]->{'current_version'} .
" loop(" . $_[HEAP]->{'current_loop'} . ')' .
" assertions(" . ( $_[HEAP]->{'current_assertions'} ? 'ENABLED' : 'DISABLED' ) . ')' .
" xsqueue(" . ( $_[HEAP]->{'current_xsqueue'} ? 'ENABLED' : 'DISABLED' ) . ')' .
"\n";
}
# save the starttime
$_[HEAP]->{'current_starttime'} = time();
$_[HEAP]->{'current_starttimes'} = [ times() ];
# Okay, create the wheel::run to handle this
my $looploader = poeloop2load( $_[HEAP]->{'current_loop'} );
$_[HEAP]->{'WHEEL'} = POE::Wheel::Run->new(
'Program' => $^X,
'ProgramArgs' => [ '-Ipoedists/POE-' . $_[HEAP]->{'current_version'},
'-Ipoedists/POE-' . $_[HEAP]->{'current_version'} . '/lib',
( defined $looploader ? "-M$looploader" : () ),
'-MPOE::Devel::Benchmarker::SubProcess',
'-e',
'POE::Devel::Benchmarker::SubProcess::benchmark',
$_[HEAP]->{'current_version'},
$_[HEAP]->{'current_loop'},
$_[HEAP]->{'current_assertions'},
$_[HEAP]->{'lite_tests'},
$_[HEAP]->{'current_xsqueue'},
],
# Kill off existing FD's
'CloseOnCall' => 1,
# setup our data handlers
'StdoutEvent' => 'Got_STDOUT',
'StderrEvent' => 'Got_STDERR',
# the error handler
'ErrorEvent' => 'Got_ERROR',
'CloseEvent' => 'Got_CLOSED',
# set our filters
'StderrFilter' => POE::Filter::Line->new(),
'StdoutFilter' => POE::Filter::Line->new(),
);
if ( ! defined $_[HEAP]->{'WHEEL'} ) {
die 'Unable to create a new wheel!';
} else {
# smart CHLD handling
if ( $_[KERNEL]->can( "sig_child" ) ) {
$_[KERNEL]->sig_child( $_[HEAP]->{'WHEEL'}->PID => 'Got_CHLD' );
} else {
$_[KERNEL]->sig( 'CHLD', 'Got_CHLD' );
}
}
# setup our data we received from the subprocess
$_[HEAP]->{'current_data'} = '';
# Okay, we timeout this test after some time for sanity
$_[HEAP]->{'test_timedout'} = 0;
if ( $_[HEAP]->{'lite_tests'} ) {
# on my core2duo 1.2ghz laptop, running Gtk+LITE+assert+noxsqueue takes approx 45s
$_[HEAP]->{'TIMER'} = $_[KERNEL]->delay_set( 'test_timedout' => 60 * 2 );
} else {
# on my core2duo 1.2ghz laptop, running Gtk+HEAVY+assert+noxsqueue takes all day long :(
$_[HEAP]->{'TIMER'} = $_[KERNEL]->delay_set( 'test_timedout' => 60 * 15 );
}
return;
}
# Got a CHLD event!
sub Got_CHLD : State {
$_[KERNEL]->sig_handled();
return;
}
# Handles child STDERR output
sub Got_STDERR : State {
my $input = $_[ARG0];
# save it!
$_[HEAP]->{'current_data'} .= '!STDERR: ' . $input . "\n";
return;
}
# Handles child STDOUT output
sub Got_STDOUT : State {
my $input = $_[ARG0];
# save it!
$_[HEAP]->{'current_data'} .= $input . "\n";
return;
}
# Handles child error
sub Got_ERROR : State {
# Copied from POE::Wheel::Run manpage
my ( $operation, $errnum, $errstr ) = @_[ ARG0 .. ARG2 ];
# ignore exit 0 errors
if ( $errnum != 0 ) {
warn "Wheel::Run got an $operation error $errnum: $errstr\n";
}
return;
}
# Handles child DIE'ing
sub Got_CLOSED : State {
# Get rid of the wheel
undef $_[HEAP]->{'WHEEL'};
# get rid of the delay
$_[KERNEL]->alarm_remove( $_[HEAP]->{'TIMER'} );
undef $_[HEAP]->{'TIMER'};
# wrap up this test
$_[KERNEL]->yield( 'wrapup_test' );
return;
}
# a test timed out, unfortunately!
sub test_timedout : State {
# tell the wheel to kill itself
$_[HEAP]->{'WHEEL'}->kill( 9 );
undef $_[HEAP]->{'WHEEL'};
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Test TimedOut!\n";
}
$_[HEAP]->{'test_timedout'} = 1;
# wrap up this test
$_[KERNEL]->yield( 'wrapup_test' );
return;
}
# finalizes a test
sub wrapup_test : State {
# we're done with this benchmark!
$_[HEAP]->{'current_endtime'} = time();
$_[HEAP]->{'current_endtimes'} = [ times() ];
# store the data
my $file = 'POE-' . $_[HEAP]->{'current_version'} .
'-' . $_[HEAP]->{'current_loop'} .
( $_[HEAP]->{'current_assertions'} ? '-assert' : '-noassert' ) .
( $_[HEAP]->{'current_xsqueue'} ? '-xsqueue' : '-noxsqueue' );
open( my $fh, '>', "results/$file" ) or die $!;
print $fh "STARTTIME: " . $_[HEAP]->{'current_starttime'} . " -> TIMES " . join( " ", @{ $_[HEAP]->{'current_starttimes'} } ) . "\n";
print $fh "$file\n\n";
print $fh $_[HEAP]->{'current_data'} . "\n";
if ( $_[HEAP]->{'test_timedout'} ) {
print $fh "\nTEST TERMINATED DUE TO TIMEOUT\n";
}
print $fh "ENDTIME: " . $_[HEAP]->{'current_endtime'} . " -> TIMES " . join( " ", @{ $_[HEAP]->{'current_endtimes'} } ) . "\n";
close( $fh ) or die $!;
# process the next test
$_[KERNEL]->yield( 'bench_xsqueue' );
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker - Benchmarking POE's performance ( acts more like a smoker )
=head1 SYNOPSIS
perl -MPOE::Devel::Benchmarker -e 'benchmark()'
=head1 ABSTRACT
This package of tools is designed to benchmark POE's performace across different
configurations. The current "tests" are:
=over 4
=item posts
=item calls
=item alarm_adds
=item session creation
=item session destruction
=item select_read toggles
=item select_write toggles
=item POE startup time
=back
=head1 DESCRIPTION
This module is poorly documented now. Please give me some time to properly document it over time :)
=head2 INSTALLATION
Here's a simple outline to get you up to speed quickly. ( and smoking! )
=over 4
=item Install CPAN package + dependencies
Download+install the POE::Devel::Benchmarker package from CPAN
apoc@apoc-x300:~$ cpanp -i POE::Devel::Benchmarker
=item Setup initial directories
Go anywhere, and create the "parent" directory where you'll be storing test results + stuff. For this example,
I have chosen to use ~/poe-benchmarker:
apoc@apoc-x300:~$ mkdir poe-benchmarker
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ mkdir poedists
apoc@apoc-x300:~/poe-benchmarker$ cd poedists/
apoc@apoc-x300:~/poe-benchmarker/poedists$ perl -MPOE::Devel::Benchmarker::GetPOEdists -e 'getPOEdists( 1 )'
( go get a coffee while it downloads if you're on a slow link, ha! )
apoc@apoc-x300:~/poe-benchmarker/poedists$ cd..
apoc@apoc-x300:~/poe-benchmarker$ mkdir results
=item Let 'er rip!
At this point you can start running the benchmark!
NOTE: the Benchmarker expects everything to be in the "local" directory!
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker -e 'benchmark()'
+ ( go sleep or something, this will take a while! )
+
=back
=head2 ANALYZING RESULTS
This part of the documentation is woefully incomplete. Please look at the L<POE::Devel::Benchmarker::Analyzer> module.
-=head2 SUBROUTINES
+=head2 BENCHMARKING
This module exposes only one subroutine, the benchmark() one. You can pass a hashref to it to set various options. Here is
a list of the valid options:
=over 4
=item litetests => boolean
This enables the "lite" tests which will not take up too much time.
-default: false
+default: true
=item quiet => boolean
This enables quiet mode which will not print anything to the console except for errors.
default: false
=back
-=head2 EXPORT
+=head1 EXPORT
Automatically exports the benchmark() subroutine.
=head1 TODO
=over 4
+=item write POE::Devel::Benchmarker::Analyzer
+
+I need to finish this module so it will dump YAML structures along the raw output. That way we can easily parse the data
+and use it for nifty stuff like graphs or websites :)
+
+BEWARE: please don't write any tools to analyze the dumps as of now, and give me some more time to complete this, because
+I probably will be tweaking the raw output a little to make the regexes less crazy!
+
=item Perl version smoking
We should be able to run the benchmark over different Perl versions. This would require some fiddling with our
layout + logic. It's not that urgent because the workaround is to simply execute the smoke suite under a different
perl binary. It's smart enough to use $^X to be consistent across tests :)
=item Select the EV backend
-<Khisanth> and if you are benchmarking, try it with POE using EV with EV using Glib? :P
-<Apocalypse> I'm not sure how to configure the EV "backend" yet
-<Apocalypse> too much docs for me to read hah
-<Khisanth> Apocalypse: use EV::Glib; use Glib; use POE; :)
+ <Khisanth> and if you are benchmarking, try it with POE using EV with EV using Glib? :P
+ <Apocalypse> I'm not sure how to configure the EV "backend" yet
+ <Apocalypse> too much docs for me to read hah
+ <Khisanth> Apocalypse: use EV::Glib; use Glib; use POE; :)
=item Disable POE::XS::Queue::Array tests if not found
Currently we blindly move on and test with/without this. We should be smarter and not waste one extra test per iteration
if it isn't installed!
=item Be more smarter in smoking timeouts
-Currently we depend on the lite_tests option and hardcode some values including the timeout. If your machine is incredibly
+Currently we depend on the litetests option and hardcode some values including the timeout. If your machine is incredibly
slow, there's a chance that it could timeout unnecessarily. Please look at the outputs and check to see if there are unusual
failures, and inform me.
Also, some loops perform badly and take almost forever! /me glares at Gtk...
=item Kqueue support
As I don't have access to a *BSD box, I cannot really test this. Furthermore, it isn't clear on how I can force/unload this
module from POE...
=back
=head1 SEE ALSO
L<POE>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
BIG THANKS goes to Rocco Caputo E<lt>rcaputo@cpan.orgE<gt> for the first benchmarks!
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm b/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm
index fe8803a..dad0f61 100644
--- a/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm
+++ b/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm
@@ -1,200 +1,204 @@
# Declare our package
package POE::Devel::Benchmarker::GetInstalledLoops;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.01';
# auto-export the only sub we have
BEGIN {
require Exporter;
use vars qw( @ISA @EXPORT );
@ISA = qw(Exporter);
@EXPORT = qw( getPOEloops );
}
# Import what we need from the POE namespace
use POE qw( Session Filter::Line Wheel::Run );
use base 'POE::Session::AttributeBased';
# analyzes the installed perl directory for available loops
sub getPOEloops {
my $quiet_mode = shift;
# create our session!
POE::Session->create(
POE::Devel::Benchmarker::GetInstalledLoops->inline_states(),
'heap' => {
'quiet_mode' => $quiet_mode,
},
);
}
# Starts up our session
sub _start : State {
# set our alias
$_[KERNEL]->alias_set( 'Benchmarker::GetInstalledLoops' );
# load our known list of loops
# known impossible loops:
# XS::EPoll ( must be POE > 1.003 and weird way of loading )
# XS::Poll ( must be POE > 1.003 and weird way of loading )
$_[HEAP]->{'loops'} = [ qw( Event_Lib EV Glib Prima Gtk Wx Kqueue Tk Select IO_Poll ) ];
# First of all, we need to find out what loop libraries are installed
$_[HEAP]->{'found_loops'} = [];
$_[KERNEL]->yield( 'find_loops' );
return;
}
sub _stop : State {
# tell the wheel to kill itself
if ( defined $_[HEAP]->{'WHEEL'} ) {
$_[HEAP]->{'WHEEL'}->kill( 9 );
undef $_[HEAP]->{'WHEEL'};
}
return;
}
# loops over the "known" loops and sees if they are installed
sub find_loops : State {
# get the loop to test
$_[HEAP]->{'current_loop'} = shift @{ $_[HEAP]->{'loops'} };
# do we have something to test?
if ( ! defined $_[HEAP]->{'current_loop'} ) {
# we're done!
$_[KERNEL]->alias_remove( 'Benchmarker::GetInstalledLoops' );
$_[KERNEL]->post( 'Benchmarker', 'found_loops', $_[HEAP]->{'found_loops'} );
return;
} else {
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[LOOPSEARCH] Trying to find if POE::Loop::" . $_[HEAP]->{'current_loop'} . " is installed...\n";
}
# set the flag
$_[HEAP]->{'test_failure'} = 0;
}
# Okay, create the wheel::run to handle this
$_[HEAP]->{'WHEEL'} = POE::Wheel::Run->new(
'Program' => $^X,
'ProgramArgs' => [ '-MPOE',
'-MPOE::Loop::' . $_[HEAP]->{'current_loop'},
'-e',
'1',
],
# Kill off existing FD's
'CloseOnCall' => 1,
# setup our data handlers
'StdoutEvent' => 'Got_STDOUT',
'StderrEvent' => 'Got_STDERR',
# the error handler
'ErrorEvent' => 'Got_ERROR',
'CloseEvent' => 'Got_CLOSED',
# set our filters
'StderrFilter' => POE::Filter::Line->new(),
'StdoutFilter' => POE::Filter::Line->new(),
);
if ( ! defined $_[HEAP]->{'WHEEL'} ) {
die '[LOOPSEARCH] Unable to create a new wheel!';
} else {
# smart CHLD handling
if ( $_[KERNEL]->can( "sig_child" ) ) {
$_[KERNEL]->sig_child( $_[HEAP]->{'WHEEL'}->PID => 'Got_CHLD' );
} else {
$_[KERNEL]->sig( 'CHLD', 'Got_CHLD' );
}
}
return;
}
# Got a CHLD event!
sub Got_CHLD : State {
$_[KERNEL]->sig_handled();
return;
}
# Handles child STDERR output
sub Got_STDERR : State {
my $input = $_[ARG0];
# since we got an error, must be a failure
$_[HEAP]->{'test_failure'} = 1;
return;
}
# Handles child STDOUT output
sub Got_STDOUT : State {
my $input = $_[ARG0];
return;
}
# Handles child error
sub Got_ERROR : State {
# Copied from POE::Wheel::Run manpage
my ( $operation, $errnum, $errstr ) = @_[ ARG0 .. ARG2 ];
# ignore exit 0 errors
if ( $errnum != 0 ) {
warn "Wheel::Run got an $operation error $errnum: $errstr\n";
}
return;
}
# Handles child DIE'ing
sub Got_CLOSED : State {
# Get rid of the wheel
undef $_[HEAP]->{'WHEEL'};
# Did we pass this test or not?
if ( ! $_[HEAP]->{'test_failure'} ) {
push( @{ $_[HEAP]->{'found_loops'} }, $_[HEAP]->{'current_loop'} );
}
# move on to the next loop
$_[KERNEL]->yield( 'find_loops' );
return;
}
1;
__END__
=head1 NAME
+=head1 SYNOPSIS
+
+ Don't use this module directly. Please use POE::Devel::Benchmarker.
+
POE::Devel::Benchmarker::GetInstalledLoops - Automatically detects the installed POE loops
=head1 ABSTRACT
This package implements the guts of searching for POE loops via fork/exec.
-=head2 EXPORT
+=head1 EXPORT
Automatically exports the getPOEloops() sub
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/GetPOEdists.pm b/lib/POE/Devel/Benchmarker/GetPOEdists.pm
index db5d4a4..7d81b67 100644
--- a/lib/POE/Devel/Benchmarker/GetPOEdists.pm
+++ b/lib/POE/Devel/Benchmarker/GetPOEdists.pm
@@ -1,126 +1,126 @@
# Declare our package
package POE::Devel::Benchmarker::GetPOEdists;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.01';
# auto-export the only sub we have
require Exporter;
use vars qw( @ISA @EXPORT );
@ISA = qw(Exporter);
@EXPORT = qw( getPOEdists );
# import the helper modules
use LWP::UserAgent;
use HTML::LinkExtor;
use URI::URL;
use Archive::Tar;
# actually retrieves the dists!
sub getPOEdists {
# should we debug?
my $debug = shift;
# set the default URL
my $url = "http://backpan.cpan.org/authors/id/R/RC/RCAPUTO/";
# create our objects
my $ua = LWP::UserAgent->new;
my $p = HTML::LinkExtor->new;
my $tar = Archive::Tar->new;
# Request document and parse it as it arrives
print "Getting $url via LWP\n" if $debug;
my $res = $ua->request( HTTP::Request->new( GET => $url ),
sub { $p->parse( $_[0] ) },
);
# did we successfully download?
if ( $res->is_error ) {
die "unable to download directory index on BACKPAN: " . $res->status_line;
}
# Download every one!
foreach my $link ( $p->links ) {
# skip IMG stuff
if ( $link->[0] eq 'a' and $link->[1] eq 'href' ) {
# get the actual POE dists!
if ( $link->[2] =~ /^POE\-\d/ and $link->[2] =~ /\.tar\.gz$/ ) {
# download the tarball!
print "Mirroring $link->[2] via LWP\n" if $debug;
my $mirror_result = $ua->mirror( $url . $link->[2], $link->[2] );
if ( $mirror_result->is_error ) {
warn "unable to mirror $link->[2]: " . $mirror_result->status_line;
next;
}
# did we already untar this one?
my $dir = $link->[2];
$dir =~ s/\.tar\.gz$//;
if ( ! -d $dir ) {
# extract it!
print "Extracting $link->[2] via Tar\n" if $debug;
my $files = $tar->read( $link->[2], undef, { 'extract' => 'true' } );
if ( $files == 0 ) {
warn "unable to extract $link->[2]";
}
}
}
}
}
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::GetPOEdists - Automatically download all POE tarballs
=head1 SYNOPSIS
perl -MPOE::Devel::Benchmarker::GetPOEdists -e 'getPOEdists()'
=head1 ABSTRACT
This package automatically downloads all the POE tarballs from BACKPAN.
=head1 DESCRIPTION
This uses LWP + HTML::LinkExtor to retrieve POE tarballs from BACKPAN.
The tarballs are automatically downloaded to the current directory. Then, we use Archive::Tar to extract them all!
NOTE: we use LWP's useful mirror() sub which doesn't re-download files if they already exist!
=head2 getPOEdists
Normally you should pass nothing to this sub. However, if you want to debug the downloads+extractions you should pass
a true value as the first argument.
perl -MPOE::Devel::Benchmarker::GetPOEdists -e 'getPOEdists( 1 )'
-=head2 EXPORT
+=head1 EXPORT
Automatically exports the getPOEdists() sub
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/SubProcess.pm b/lib/POE/Devel/Benchmarker/SubProcess.pm
index 27472cc..055712e 100644
--- a/lib/POE/Devel/Benchmarker/SubProcess.pm
+++ b/lib/POE/Devel/Benchmarker/SubProcess.pm
@@ -126,533 +126,533 @@ sub process_testmode {
$through_limit = 10_000;
$call_limit = 10_000;
$start_limit = 10;
} else {
print "Using the HEAVY tests\n";
$post_limit = 100_000;
$alarm_limit = 100_000;
$alarm_add_limit = 100_000;
$session_limit = 5_000;
$select_limit = 100_000;
$through_limit = 100_000;
$call_limit = 100_000;
$start_limit = 100;
}
return;
}
sub process_xsqueue {
# should we "hide" XS::Queue::Array?
if ( defined $ARGV[4] and $ARGV[4] ) {
print "DISABLING POE::XS::Queue::Array\n";
} else {
print "LETTING POE find POE::XS::Queue::Array\n";
}
return;
}
sub process_POE {
# Print the POE info
print "Using POE-" . $POE::VERSION . "\n";
# Actually print what loop POE is using
foreach my $m ( keys %INC ) {
if ( $m =~ /^POE\/(?:Loop|XS|Queue)/ ) {
# try to be smart and get version?
my $module = $m;
$module =~ s|/|::|g;
$module =~ s/\.pm$//g;
print "POE is using: $module ";
if ( defined $module->VERSION ) {
print "v" . $module->VERSION . "\n";
} else {
print "vUNKNOWN\n";
}
}
}
return;
}
sub run_benchmarks {
# run the startup test before we actually run POE
bench_startup();
# load the POE session + do the tests there
bench_poe();
# dump some misc info
dump_memory();
dump_times();
dump_perlinfo();
dump_sysinfo();
# all done!
return;
}
sub bench_startup {
# Add the eventloop?
my $looploader = poeloop2load( $eventloop );
my @start_times = times();
my $start = time();
for (my $i = 0; $i < $start_limit; $i++) {
# FIXME should we add assertions?
# finally, fire it up!
CORE::system(
$^X,
'-Ipoedists/POE-' . $version,
'-Ipoedists/POE-' . $version . '/lib',
( defined $looploader ? "-M$looploader" : () ),
'-MPOE',
'-e',
1,
);
}
my @end_times = times();
my $elapsed = time() - $start;
printf( "\n\n% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $start_limit, 'startups', $elapsed, $start_limit/$elapsed );
print "startup times: @start_times @end_times\n";
return;
}
sub bench_poe {
# figure out POE::Session->create or POE::Session->new or what?
$pocosession = POE::Session->can( 'create' );
if ( defined $pocosession ) {
$pocosession = 'create';
} else {
$pocosession = POE::Session->can( 'spawn' );
if ( defined $pocosession ) {
$pocosession = 'spawn';
} else {
$pocosession = 'new';
}
}
# create the master sesssion + run POE!
POE::Session->$pocosession(
'inline_states' => {
# basic POE states
'_start' => \&poe__start,
'_default' => \&poe__default,
'_stop' => \&poe__stop,
'null' => \&poe_null,
# our test states
'posts' => \&poe_posts,
'posts_start' => \&poe_posts_start,
'posts_end' => \&poe_posts_end,
'alarms' => \&poe_alarms,
'manyalarms' => \&poe_manyalarms,
'sessions' => \&poe_sessions,
'sessions_end' => \&poe_sessions_end,
'stdin_read' => \&poe_stdin_read,
'stdin_write' => \&poe_stdin_write,
'myfh_read' => \&poe_myfh_read,
'myfh_write' => \&poe_myfh_write,
'calls' => \&poe_calls,
'eventsquirt' => \&poe_eventsquirt,
'eventsquirt_done' => \&poe_eventsquirt_done,
},
);
# start the kernel!
POE::Kernel->run();
return;
}
# inits our session
sub poe__start {
# fire off the first test!
$_[KERNEL]->yield( 'posts' );
return;
}
sub poe__stop {
}
sub poe__default {
return 0;
}
# a state that does nothing
sub poe_null {
return 1;
}
# How many posts per second? Post a bunch of events, keeping track of the time it takes.
sub poe_posts {
$_[KERNEL]->yield( 'posts_start' );
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $post_limit; $i++) {
$_[KERNEL]->yield( 'null' );
}
my @end_times = times();
my $elapsed = time() - $start;
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $post_limit, 'posts', $elapsed, $post_limit/$elapsed );
print "posts times: @start_times @end_times\n";
$_[KERNEL]->yield( 'posts_end' );
return;
}
sub poe_posts_start {
$_[HEAP]->{start} = time();
$_[HEAP]->{starttimes} = [ times() ];
return;
}
sub poe_posts_end {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $post_limit, 'dispatches', $elapsed, $post_limit/$elapsed );
print "dispatches times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
$_[KERNEL]->yield( 'alarms' );
return;
}
# How many alarms per second? Set a bunch of alarms and find out.
sub poe_alarms {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $alarm_limit; $i++) {
$_[KERNEL]->alarm( whee => rand(1_000_000) );
}
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $alarm_limit, 'alarms', $elapsed, $alarm_limit/$elapsed );
print "alarms times: @start_times @end_times\n";
$_[KERNEL]->alarm( 'whee' => undef );
$_[KERNEL]->yield( 'manyalarms' );
return;
}
# How many repetitive alarms per second? Set a bunch of
# additional alarms and find out. Also see how quickly they can
# be cleared.
sub poe_manyalarms {
# can this POE::Kernel support this?
if ( $_[KERNEL]->can( 'alarm_add' ) ) {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $alarm_add_limit; $i++) {
$_[KERNEL]->alarm_add( whee => rand(1_000_000) );
}
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $alarm_add_limit, 'alarm_adds', $elapsed, $alarm_add_limit/$elapsed );
print "alarm_adds times: @start_times @end_times\n";
$start = time();
@start_times = times();
$_[KERNEL]->alarm( whee => undef );
$elapsed = time() - $start;
@end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $alarm_add_limit, 'alarm_clears', $elapsed, $alarm_add_limit/$elapsed );
print "alarm_clears times: @start_times @end_times\n";
} else {
print "this version of POE does not support alarm_add, skipping alarm_adds/alarm_clears tests!\n";
}
$_[KERNEL]->yield( 'sessions' );
return;
}
# How many sessions can we create and destroy per second?
# Create a bunch of sessions, and track that time. Let them
# self-destruct, and track that as well.
sub poe_sessions {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $session_limit; $i++) {
POE::Session->$pocosession( 'inline_states' => { _start => sub {}, _stop => sub {}, _default => sub { return 0 } } );
}
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $session_limit, 'session creates', $elapsed, $session_limit/$elapsed );
print "session create times: @start_times @end_times\n";
$_[KERNEL]->yield( 'sessions_end' );
$_[HEAP]->{start} = time();
$_[HEAP]->{starttimes} = [ times() ];
return;
}
sub poe_sessions_end {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $session_limit, 'session destroys', $elapsed, $session_limit/$elapsed );
print "session destroys times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
$_[KERNEL]->yield( 'stdin_read' );
return;
}
# How many times can we select/unselect READ a from STDIN filehandle per second?
sub poe_stdin_read {
# stupid, but we have to skip those tests
if ( $eventloop eq 'Tk' or $eventloop eq 'Prima' ) {
print "SKIPPING STDIN tests on broken loop: $eventloop\n";
$_[KERNEL]->yield( 'myfh_read' );
return;
}
my $start = time();
my @start_times = times();
eval {
for (my $i = 0; $i < $select_limit; $i++) {
$_[KERNEL]->select_read( *STDIN, 'whee' );
$_[KERNEL]->select_read( *STDIN );
}
};
if ( $@ ) {
print "filehandle select_read on *STDIN FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $select_limit, 'select_read STDIN', $elapsed, $select_limit/$elapsed );
print "select_read STDIN times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'stdin_write' );
return;
}
# How many times can we select/unselect WRITE a from STDIN filehandle per second?
sub poe_stdin_write {
my $start = time();
my @start_times = times();
eval {
for (my $i = 0; $i < $select_limit; $i++) {
$_[KERNEL]->select_write( *STDIN, 'whee' );
$_[KERNEL]->select_write( *STDIN );
}
};
if ( $@ ) {
print "filehandle select_write on *STDIN FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $select_limit, 'select_write STDIN', $elapsed, $select_limit/$elapsed );
print "select_write STDIN times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'myfh_read' );
return;
}
# How many times can we select/unselect READ a real filehandle?
sub poe_myfh_read {
# stupid, but we have to skip those tests
if ( $eventloop eq 'Event_Lib' or $eventloop eq 'Tk' or $eventloop eq 'Prima' ) {
print "SKIPPING MYFH tests on broken loop: $eventloop\n";
$_[KERNEL]->yield( 'calls' );
return;
}
open( my $fh, '+>', 'poebench' ) or die $!;
my $start = time();
my @start_times = times();
eval {
for (my $i = 0; $i < $select_limit; $i++) {
$_[KERNEL]->select_read( $fh, 'whee' );
$_[KERNEL]->select_read( $fh );
}
};
if ( $@ ) {
print "filehandle select_read on *MYFH FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $select_limit, 'select_read MYFH', $elapsed, $select_limit/$elapsed );
print "select_read MYFH times: @start_times @end_times\n";
}
close( $fh ) or die $!;
unlink( 'poebench' ) or die $!;
$_[KERNEL]->yield( 'myfh_write' );
return;
}
# How many times can we select/unselect WRITE a real filehandle?
sub poe_myfh_write {
open( my $fh, '+>', 'poebench' ) or die $!;
my $start = time();
my @start_times = times();
eval {
for (my $i = 0; $i < $select_limit; $i++) {
$_[KERNEL]->select_write( $fh, 'whee' );
$_[KERNEL]->select_write( $fh );
}
};
if ( $@ ) {
print "filehandle select_write on *MYFH FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $select_limit, 'select_write MYFH', $elapsed, $select_limit/$elapsed );
print "select_write MYFH times: @start_times @end_times\n";
}
close( $fh ) or die $!;
unlink( 'poebench' ) or die $!;
$_[KERNEL]->yield( 'calls' );
return;
}
# How many times can we call a state?
sub poe_calls {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $call_limit; $i++) {
$_[KERNEL]->call( $_[SESSION], 'null' );
}
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $call_limit, 'calls', $elapsed, $call_limit/$elapsed );
print "calls times: @start_times @end_times\n";
$_[KERNEL]->yield( 'eventsquirt' );
return;
}
# How many events can we squirt through POE, one at a time?
sub poe_eventsquirt {
$_[HEAP]->{start} = time();
$_[HEAP]->{starttimes} = [ times() ];
$_[HEAP]->{yield_count} = $through_limit;
$_[KERNEL]->yield( 'eventsquirt_done' );
return;
}
sub poe_eventsquirt_done {
if (--$_[HEAP]->{yield_count}) {
$_[KERNEL]->yield( 'eventsquirt_done' );
} else {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $through_limit, 'single_posts', $elapsed, $through_limit/$elapsed );
print "single_posts times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
}
# reached end of tests!
return;
}
# Get the memory footprint
sub dump_memory {
print "\n\nMemory footprint:\n";
open( my $fh, '<', '/proc/self/status' ) or die $!;
while ( <$fh> ) {
print;
}
close( $fh ) or die $!;
return;
}
# print the time it took to execute this program
sub dump_times {
my ($wall, $user, $system, $cuser, $csystem) = ( (time-$^T), times() );
printf( ( "\n\n--- times ---\n" .
"wall : %9.3f\n" .
"user : %9.3f cuser: %9.3f\n" .
"sys : %9.3f csys : %9.3f\n"
),
$wall, $user, $cuser, $system, $csystem,
);
return;
}
# print the local Perl info
sub dump_perlinfo {
print "\n\nRunning under perl binary: " . $^X . "\n";
require Config;
print Config::myconfig();
return;
}
# print the local system information
sub dump_sysinfo {
print "Running under machine: " . `uname -a` . "\n";
# get cpuinfo
print "Running under CPU:\n";
open( my $fh, '<', '/proc/cpuinfo' ) or die $!;
while ( <$fh> ) {
print;
}
close( $fh ) or die $!;
# get meminfo
print "Running under meminfo:\n";
open( $fh, '<', '/proc/meminfo' ) or die $!;
while ( <$fh> ) {
print;
}
close( $fh ) or die $!;
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::SubProcess - Implements the actual POE benchmarks
=head1 SYNOPSIS
perl -MPOE::Devel::Benchmarker::SubProcess -e 'benchmark()'
=head1 ABSTRACT
This package is responsible for implementing the guts of the benchmarks, and timing them.
-=head2 EXPORT
+=head1 EXPORT
Nothing.
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/Utils.pm b/lib/POE/Devel/Benchmarker/Utils.pm
index a6bb557..b7f84a4 100644
--- a/lib/POE/Devel/Benchmarker/Utils.pm
+++ b/lib/POE/Devel/Benchmarker/Utils.pm
@@ -1,134 +1,134 @@
# Declare our package
package POE::Devel::Benchmarker::Utils;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.01';
# auto-export the only sub we have
require Exporter;
use vars qw( @ISA @EXPORT );
@ISA = qw(Exporter);
@EXPORT = qw( poeloop2load loop2realversion );
# returns the proper "load" stuff for a specific loop
sub poeloop2load {
my $eventloop = shift;
# Decide which event loop to use
# Event_Lib EV Glib Prima Gtk Wx Kqueue Tk Select IO_Poll
if ( $eventloop eq 'Event' ) {
return 'Event';
} elsif ( $eventloop eq 'IO_Poll' ) {
return 'IO::Poll';
} elsif ( $eventloop eq 'Event_Lib' ) {
return 'Event::Lib';
} elsif ( $eventloop eq 'EV' ) {
return 'EV';
} elsif ( $eventloop eq 'Glib' ) {
return 'Glib';
} elsif ( $eventloop eq 'Tk' ) {
return 'Tk',
} elsif ( $eventloop eq 'Gtk' ) {
return 'Gtk';
} elsif ( $eventloop eq 'Prima' ) {
return 'Prima';
} elsif ( $eventloop eq 'Wx' ) {
return 'Wx';
} elsif ( $eventloop eq 'Kqueue' ) {
# FIXME dunno what to do here!
return;
} elsif ( $eventloop eq 'Select' ) {
return;
} else {
die "Unknown event loop!";
}
}
# returns the version of the "real" installed module that the loop uses
sub loop2realversion {
my $eventloop = shift;
# Decide which event loop to use
if ( ! defined $eventloop ) {
return;
} elsif ( $eventloop eq 'Event' ) {
return $Event::VERSION;
} elsif ( $eventloop eq 'IO_Poll' ) {
return $IO::Poll::VERSION;
} elsif ( $eventloop eq 'Event_Lib' ) {
return $Event::Lib::VERSION;
} elsif ( $eventloop eq 'EV' ) {
return $EV::VERSION;
} elsif ( $eventloop eq 'Glib' ) {
return $Glib::VERSION;
} elsif ( $eventloop eq 'Tk' ) {
return $Tk::VERSION;
} elsif ( $eventloop eq 'Gtk' ) {
return $Gtk::VERSION;
} elsif ( $eventloop eq 'Prima' ) {
return $Prima::VERSION;
} elsif ( $eventloop eq 'Wx' ) {
return $Wx::VERSION;
} elsif ( $eventloop eq 'Kqueue' ) {
# FIXME how do I do this?
return;
} elsif ( $eventloop eq 'Select' ) {
return 'BUILTIN';
} else {
die "Unknown event loop!";
}
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::Utils - Various utility routines for POE::Devel::Benchmarker
=head1 SYNOPSIS
perl -MPOE::Devel::Benchmarker::Utils -e 'print poeloop2load( "IO_Poll" )'
=head1 ABSTRACT
This package contains the utility routines and constants that POE::Devel::Benchmarker needs.
-=head2 EXPORT
+=head1 EXPORT
Automatically exports those subs:
=over 4
=item poeloop2load()
Returns the "parent" class to load for a specific loop. An example is:
$real = poeloop2load( 'IO_Poll' ); # $real now contains "IO::Poll"
=item loop2realversion()
Returns the version of the "parent" class for a specific loop. An example is:
$ver = loop2realversion( 'IO_Poll' ); # $ver now contains $IO::Poll::VERSION
=back
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
|
apocalypse/perl-poe-benchmarker
|
98c1af98ef71144983d7c50fa2bc303e0e88a7eb
|
first release
|
diff --git a/Build.PL b/Build.PL
index ab01bef..03d7fdd 100755
--- a/Build.PL
+++ b/Build.PL
@@ -1,95 +1,95 @@
# Build.PL
use Module::Build;
my $build = Module::Build->new(
# look up Module::Build::API for the info!
'dynamic_config' => 0,
'module_name' => 'POE::Devel::Benchmarker',
'license' => 'perl',
'dist_abstract' => "Benchmarking POE's performance ( acts more like a smoker )",
'dist_author' => 'Apocalypse <APOCAL@cpan.org>',
'create_packlist' => 1,
'create_makefile_pl' => 'traditional',
'create_readme' => 1,
'test_files' => 't/*.t',
'add_to_cleanup' => [ 'META.yml', 'Makefile.PL', 'README' ], # automatically generated
'requires' => {
# POE Stuff
'POE' => 0,
'POE::Session::AttributeBased' => 0,
# FIXME POE stuff that Test::Dependencies needs to see
- 'POE::Session' => 0,
- 'POE::Filter::Line' => 0,
- 'POE::Wheel::Run' => 0,
+ #'POE::Session' => 0,
+ #'POE::Filter::Line' => 0,
+ #'POE::Wheel::Run' => 0,
# misc perl stuff
'Time::HiRes' => 0,
'version' => 0,
'Devel::Hide' => 0,
# GetPOEdists reqs
'LWP::UserAgent' => 0,
'HTML::LinkExtor' => 0,
'URI::URL' => 0,
'Archive::Tar' => 0,
},
'recommends' => {
# Test stuff
'Test::More' => 0,
# our POE loops!
'POE::Loop::Event' => 0,
'POE::Loop::Event_Lib' => 0,
'POE::Loop::EV' => 0,
'POE::Loop::Glib' => 0,
'POE::Loop::Prima' => 0,
'POE::Loop::Gtk' => 0,
'POE::Loop::Wx' => 0,
'POE::Loop::Kqueue' => 0,
# included in POE ( listed here for completeness )
#'POE::Loop::Tk' => 0,
#'POE::Loop::Select' => 0,
#'POE::Loop::IO_Poll' => 0,
# the loops' dependencies
'Event' => 0,
'Event::Lib' => 0,
'EV' => 0,
'Glib' => 0,
'Prima' => 0,
'Gtk' => 0,
'Wx' => 0,
'Tk' => 0,
},
# FIXME wishlist...
# 'test_requires' => {
# # Test stuff
# 'Test::Compile' => 0,
# 'Test::Perl::Critic' => 0,
# 'Test::Dependencies' => 0,
# 'Test::Distribution' => 0,
# 'Test::Fixme' => 0,
# 'Test::HasVersion' => 0,
# 'Test::Kwalitee' => 0,
# 'Test::CheckManifest' => 0,
# 'Test::MinimumVersion' => 0,
# 'Test::Pod::Coverage' => 0,
# 'Test::Spelling' => 0,
# 'Test::Pod' => 0,
# 'Test::Prereq' => 0,
# 'Test::Strict' => 0,
# 'Test::UseAllModules' => 0,
# },
);
# all done!
$build->create_build_script;
diff --git a/POE-Devel-Benchmarker-0.01.tar.gz b/POE-Devel-Benchmarker-0.01.tar.gz
new file mode 100644
index 0000000..23e145f
Binary files /dev/null and b/POE-Devel-Benchmarker-0.01.tar.gz differ
diff --git a/lib/POE/Devel/Benchmarker.pm b/lib/POE/Devel/Benchmarker.pm
index 1be4898..9290ac3 100644
--- a/lib/POE/Devel/Benchmarker.pm
+++ b/lib/POE/Devel/Benchmarker.pm
@@ -1,532 +1,551 @@
# Declare our package
package POE::Devel::Benchmarker;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.01';
# auto-export the only sub we have
BEGIN {
require Exporter;
use vars qw( @ISA @EXPORT );
@ISA = qw(Exporter);
@EXPORT = qw( benchmark );
}
# Import what we need from the POE namespace
use POE qw( Session Filter::Line Wheel::Run );
use base 'POE::Session::AttributeBased';
# we need hires times
use Time::HiRes qw( time );
# load comparison stuff
use version;
# Load our stuff
use POE::Devel::Benchmarker::GetInstalledLoops;
use POE::Devel::Benchmarker::Utils;
# Actually run the tests!
sub benchmark {
my $options = shift;
# set default options
my $lite_tests = 1;
my $quiet_mode = 0;
# process our options
if ( defined $options and ref $options and ref( $options ) eq 'HASH' ) {
# process LITE tests
if ( exists $options->{'litetests'} ) {
if ( $options->{'litetests'} ) {
$lite_tests = 1;
} else {
$lite_tests = 0;
}
}
# process quiet mode
if ( exists $options->{'quiet'} ) {
if ( $options->{'quiet'} ) {
$quiet_mode = 1;
} else {
$quiet_mode = 0;
}
}
}
# do some sanity checks
if ( ! -d 'poedists' ) {
die "The 'poedists' directory is not found in the working directory!";
}
if ( ! -d 'results' ) {
die "The 'results' directory is not found in the working directory!";
}
if ( ! $quiet_mode ) {
print "[BENCHMARKER] Starting up...\n";
}
# Create our session
POE::Session->create(
__PACKAGE__->inline_states(),
'heap' => {
'lite_tests' => $lite_tests,
'quiet_mode' => $quiet_mode,
},
);
# Fire 'er up!
POE::Kernel->run();
return;
}
# Starts up our session
sub _start : State {
# set our alias
$_[KERNEL]->alias_set( 'Benchmarker' );
# sanely handle some signals
$_[KERNEL]->sig( 'INT', 'handle_kill' );
$_[KERNEL]->sig( 'TERM', 'handle_kill' );
# okay, get all the dists we can!
my @versions;
opendir( DISTS, 'poedists' ) or die $!;
foreach my $d ( readdir( DISTS ) ) {
if ( $d =~ /^POE\-(.+)$/ and $d !~ /\.tar\.gz$/ ) {
push( @versions, $1 );
}
}
closedir( DISTS ) or die $!;
# okay, go through all the dists in version order
@versions = sort { $b <=> $a }
map { version->new( $_ ) } @versions;
# Store the versions in our heap
$_[HEAP]->{'VERSIONS'} = \@versions;
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Detected available POE versions -> " . join( " ", @versions ) . "\n";
}
# First of all, we need to find out what loop libraries are installed
getPOEloops( $_[HEAP]->{'quiet_mode'} );
return;
}
sub _stop : State {
# tell the wheel to kill itself
if ( defined $_[HEAP]->{'WHEEL'} ) {
$_[HEAP]->{'WHEEL'}->kill( 9 );
undef $_[HEAP]->{'WHEEL'};
}
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Shutting down...\n";
}
return;
}
# we received list of loops from GetInstalledLoops
sub found_loops : State {
$_[HEAP]->{'installed_loops'} = [ sort { $a eq $b } @{ $_[ARG0] } ];
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Detected available POE::Loops -> " . join( " ", @{ $_[HEAP]->{'installed_loops'} } ) . "\n";
}
# start the benchmark!
$_[KERNEL]->yield( 'run_benchmark' );
return;
}
# Runs one benchmark
sub run_benchmark : State {
# Grab the version from the top of the array
$_[HEAP]->{'current_version'} = shift @{ $_[HEAP]->{'VERSIONS'} };
# did we run out of versions?
if ( ! defined $_[HEAP]->{'current_version'} ) {
# We're done, let POE die...
$_[KERNEL]->alias_remove( 'Benchmarker' );
} else {
$_[HEAP]->{'loops'} = [ @{ $_[HEAP]->{'installed_loops'} } ];
# okay, fire off the first loop
$_[KERNEL]->yield( 'bench_loop' );
}
return;
}
# runs one loop
sub bench_loop : State {
# select our current loop
$_[HEAP]->{'current_loop'} = shift @{ $_[HEAP]->{'loops'} };
# are we done with all loops?
if ( ! defined $_[HEAP]->{'current_loop'} ) {
# yay, go back to the main handler
$_[KERNEL]->yield( 'run_benchmark' );
} else {
# Start the assert test
$_[HEAP]->{'assertions'} = [ qw( 0 1 ) ];
$_[KERNEL]->yield( 'bench_asserts' );
}
return;
}
# runs an assertion
sub bench_asserts : State {
# select our current assert state
$_[HEAP]->{'current_assertions'} = shift @{ $_[HEAP]->{'assertions'} };
# are we done?
if ( ! defined $_[HEAP]->{'current_assertions'} ) {
# yay, go back to the loop handler
$_[KERNEL]->yield( 'bench_loop' );
} else {
# Start the xsqueue test
$_[HEAP]->{'xsqueue'} = [ qw( 0 1 ) ];
$_[KERNEL]->yield( 'bench_xsqueue' );
}
return;
}
# runs test with or without xsqueue
sub bench_xsqueue : State {
# select our current xsqueue state
$_[HEAP]->{'current_xsqueue'} = shift @{ $_[HEAP]->{'xsqueue'} };
# are we done?
if ( ! defined $_[HEAP]->{'current_xsqueue'} ) {
# yay, go back to the assert handler
$_[KERNEL]->yield( 'bench_asserts' );
} else {
# actually fire off the subprocess, ha!
$_[KERNEL]->yield( 'create_subprocess' );
}
return;
}
# actually runs the subprocess
sub create_subprocess : State {
# Okay, start testing this specific combo!
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "Testing POE v" . $_[HEAP]->{'current_version'} .
" loop(" . $_[HEAP]->{'current_loop'} . ')' .
" assertions(" . ( $_[HEAP]->{'current_assertions'} ? 'ENABLED' : 'DISABLED' ) . ')' .
" xsqueue(" . ( $_[HEAP]->{'current_xsqueue'} ? 'ENABLED' : 'DISABLED' ) . ')' .
"\n";
}
# save the starttime
$_[HEAP]->{'current_starttime'} = time();
$_[HEAP]->{'current_starttimes'} = [ times() ];
# Okay, create the wheel::run to handle this
my $looploader = poeloop2load( $_[HEAP]->{'current_loop'} );
$_[HEAP]->{'WHEEL'} = POE::Wheel::Run->new(
'Program' => $^X,
'ProgramArgs' => [ '-Ipoedists/POE-' . $_[HEAP]->{'current_version'},
'-Ipoedists/POE-' . $_[HEAP]->{'current_version'} . '/lib',
( defined $looploader ? "-M$looploader" : () ),
'-MPOE::Devel::Benchmarker::SubProcess',
'-e',
'POE::Devel::Benchmarker::SubProcess::benchmark',
$_[HEAP]->{'current_version'},
$_[HEAP]->{'current_loop'},
$_[HEAP]->{'current_assertions'},
$_[HEAP]->{'lite_tests'},
$_[HEAP]->{'current_xsqueue'},
],
# Kill off existing FD's
'CloseOnCall' => 1,
# setup our data handlers
'StdoutEvent' => 'Got_STDOUT',
'StderrEvent' => 'Got_STDERR',
# the error handler
'ErrorEvent' => 'Got_ERROR',
'CloseEvent' => 'Got_CLOSED',
# set our filters
'StderrFilter' => POE::Filter::Line->new(),
'StdoutFilter' => POE::Filter::Line->new(),
);
if ( ! defined $_[HEAP]->{'WHEEL'} ) {
die 'Unable to create a new wheel!';
} else {
# smart CHLD handling
if ( $_[KERNEL]->can( "sig_child" ) ) {
$_[KERNEL]->sig_child( $_[HEAP]->{'WHEEL'}->PID => 'Got_CHLD' );
} else {
$_[KERNEL]->sig( 'CHLD', 'Got_CHLD' );
}
}
# setup our data we received from the subprocess
$_[HEAP]->{'current_data'} = '';
# Okay, we timeout this test after some time for sanity
$_[HEAP]->{'test_timedout'} = 0;
if ( $_[HEAP]->{'lite_tests'} ) {
# on my core2duo 1.2ghz laptop, running Gtk+LITE+assert+noxsqueue takes approx 45s
$_[HEAP]->{'TIMER'} = $_[KERNEL]->delay_set( 'test_timedout' => 60 * 2 );
} else {
# on my core2duo 1.2ghz laptop, running Gtk+HEAVY+assert+noxsqueue takes all day long :(
$_[HEAP]->{'TIMER'} = $_[KERNEL]->delay_set( 'test_timedout' => 60 * 15 );
}
return;
}
# Got a CHLD event!
sub Got_CHLD : State {
$_[KERNEL]->sig_handled();
return;
}
# Handles child STDERR output
sub Got_STDERR : State {
my $input = $_[ARG0];
# save it!
$_[HEAP]->{'current_data'} .= '!STDERR: ' . $input . "\n";
return;
}
# Handles child STDOUT output
sub Got_STDOUT : State {
my $input = $_[ARG0];
# save it!
$_[HEAP]->{'current_data'} .= $input . "\n";
return;
}
# Handles child error
sub Got_ERROR : State {
# Copied from POE::Wheel::Run manpage
my ( $operation, $errnum, $errstr ) = @_[ ARG0 .. ARG2 ];
# ignore exit 0 errors
if ( $errnum != 0 ) {
warn "Wheel::Run got an $operation error $errnum: $errstr\n";
}
return;
}
# Handles child DIE'ing
sub Got_CLOSED : State {
# Get rid of the wheel
undef $_[HEAP]->{'WHEEL'};
# get rid of the delay
$_[KERNEL]->alarm_remove( $_[HEAP]->{'TIMER'} );
undef $_[HEAP]->{'TIMER'};
# wrap up this test
$_[KERNEL]->yield( 'wrapup_test' );
return;
}
# a test timed out, unfortunately!
sub test_timedout : State {
# tell the wheel to kill itself
$_[HEAP]->{'WHEEL'}->kill( 9 );
undef $_[HEAP]->{'WHEEL'};
if ( ! $_[HEAP]->{'quiet_mode'} ) {
print "[BENCHMARKER] Test TimedOut!\n";
}
$_[HEAP]->{'test_timedout'} = 1;
# wrap up this test
$_[KERNEL]->yield( 'wrapup_test' );
return;
}
# finalizes a test
sub wrapup_test : State {
# we're done with this benchmark!
$_[HEAP]->{'current_endtime'} = time();
$_[HEAP]->{'current_endtimes'} = [ times() ];
# store the data
my $file = 'POE-' . $_[HEAP]->{'current_version'} .
'-' . $_[HEAP]->{'current_loop'} .
( $_[HEAP]->{'current_assertions'} ? '-assert' : '-noassert' ) .
( $_[HEAP]->{'current_xsqueue'} ? '-xsqueue' : '-noxsqueue' );
- open( RESULT, '>', "results/$file" ) or die $!;
- print RESULT "STARTTIME: " . $_[HEAP]->{'current_starttime'} . " -> TIMES " . join( " ", @{ $_[HEAP]->{'current_starttimes'} } ) . "\n";
- print RESULT "$file\n\n";
- print RESULT $_[HEAP]->{'current_data'} . "\n";
+ open( my $fh, '>', "results/$file" ) or die $!;
+ print $fh "STARTTIME: " . $_[HEAP]->{'current_starttime'} . " -> TIMES " . join( " ", @{ $_[HEAP]->{'current_starttimes'} } ) . "\n";
+ print $fh "$file\n\n";
+ print $fh $_[HEAP]->{'current_data'} . "\n";
if ( $_[HEAP]->{'test_timedout'} ) {
- print RESULT "\nTEST TERMINATED DUE TO TIMEOUT\n";
+ print $fh "\nTEST TERMINATED DUE TO TIMEOUT\n";
}
- print RESULT "ENDTIME: " . $_[HEAP]->{'current_endtime'} . " -> TIMES " . join( " ", @{ $_[HEAP]->{'current_endtimes'} } ) . "\n";
- close( RESULT ) or die $!;
+ print $fh "ENDTIME: " . $_[HEAP]->{'current_endtime'} . " -> TIMES " . join( " ", @{ $_[HEAP]->{'current_endtimes'} } ) . "\n";
+ close( $fh ) or die $!;
# process the next test
$_[KERNEL]->yield( 'bench_xsqueue' );
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker - Benchmarking POE's performance ( acts more like a smoker )
=head1 SYNOPSIS
perl -MPOE::Devel::Benchmarker -e 'benchmark()'
=head1 ABSTRACT
This package of tools is designed to benchmark POE's performace across different
configurations. The current "tests" are:
-=over
+=over 4
+
=item posts
+
=item calls
+
=item alarm_adds
+
=item session creation
+
=item session destruction
+
=item select_read toggles
+
=item select_write toggles
+
=item POE startup time
+
=back
=head1 DESCRIPTION
This module is poorly documented now. Please give me some time to properly document it over time :)
=head2 INSTALLATION
Here's a simple outline to get you up to speed quickly. ( and smoking! )
-=over
+=over 4
+
=item Install CPAN package + dependencies
Download+install the POE::Devel::Benchmarker package from CPAN
apoc@apoc-x300:~$ cpanp -i POE::Devel::Benchmarker
=item Setup initial directories
Go anywhere, and create the "parent" directory where you'll be storing test results + stuff. For this example,
I have chosen to use ~/poe-benchmarker:
apoc@apoc-x300:~$ mkdir poe-benchmarker
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ mkdir poedists
apoc@apoc-x300:~/poe-benchmarker$ cd poedists/
apoc@apoc-x300:~/poe-benchmarker/poedists$ perl -MPOE::Devel::Benchmarker::GetPOEdists -e 'getPOEdists( 1 )'
( go get a coffee while it downloads if you're on a slow link, ha! )
apoc@apoc-x300:~/poe-benchmarker/poedists$ cd..
apoc@apoc-x300:~/poe-benchmarker$ mkdir results
=item Let 'er rip!
At this point you can start running the benchmark!
NOTE: the Benchmarker expects everything to be in the "local" directory!
apoc@apoc-x300:~$ cd poe-benchmarker
apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker -e 'benchmark()'
=back
=head2 ANALYZING RESULTS
This part of the documentation is woefully incomplete. Please look at the L<POE::Devel::Benchmarker::Analyzer> module.
=head2 SUBROUTINES
This module exposes only one subroutine, the benchmark() one. You can pass a hashref to it to set various options. Here is
a list of the valid options:
-=over
+=over 4
+
=item litetests => boolean
This enables the "lite" tests which will not take up too much time.
default: false
=item quiet => boolean
This enables quiet mode which will not print anything to the console except for errors.
default: false
=back
=head2 EXPORT
Automatically exports the benchmark() subroutine.
=head1 TODO
-=over
+=over 4
+
=item Perl version smoking
We should be able to run the benchmark over different Perl versions. This would require some fiddling with our
layout + logic. It's not that urgent because the workaround is to simply execute the smoke suite under a different
perl binary. It's smart enough to use $^X to be consistent across tests :)
=item Select the EV backend
<Khisanth> and if you are benchmarking, try it with POE using EV with EV using Glib? :P
<Apocalypse> I'm not sure how to configure the EV "backend" yet
<Apocalypse> too much docs for me to read hah
<Khisanth> Apocalypse: use EV::Glib; use Glib; use POE; :)
=item Disable POE::XS::Queue::Array tests if not found
Currently we blindly move on and test with/without this. We should be smarter and not waste one extra test per iteration
if it isn't installed!
=item Be more smarter in smoking timeouts
Currently we depend on the lite_tests option and hardcode some values including the timeout. If your machine is incredibly
slow, there's a chance that it could timeout unnecessarily. Please look at the outputs and check to see if there are unusual
failures, and inform me.
+Also, some loops perform badly and take almost forever! /me glares at Gtk...
+
+=item Kqueue support
+
+As I don't have access to a *BSD box, I cannot really test this. Furthermore, it isn't clear on how I can force/unload this
+module from POE...
+
=back
=head1 SEE ALSO
L<POE>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
BIG THANKS goes to Rocco Caputo E<lt>rcaputo@cpan.orgE<gt> for the first benchmarks!
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/SubProcess.pm b/lib/POE/Devel/Benchmarker/SubProcess.pm
index e652ec1..27472cc 100644
--- a/lib/POE/Devel/Benchmarker/SubProcess.pm
+++ b/lib/POE/Devel/Benchmarker/SubProcess.pm
@@ -1,654 +1,658 @@
# Declare our package
package POE::Devel::Benchmarker::SubProcess;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.01';
# Import Time::HiRes's time()
use Time::HiRes qw( time );
# FIXME UGLY HACK here
BEGIN {
# should we enable assertions?
if ( defined $ARGV[2] and $ARGV[2] ) {
+ ## no critic
eval "sub POE::Kernel::ASSERT_DEFAULT () { 1 }";
eval "sub POE::Session::ASSERT_STATES () { 1 }";
+ ## use critic
}
# should we "hide" XS::Queue::Array?
if ( defined $ARGV[4] and $ARGV[4] ) {
+ ## no critic
eval "use Devel::Hide qw( POE/XS/Queue/Array.pm )";
+ ## use critic
}
}
# load POE
use POE;
# load our utility stuff
use POE::Devel::Benchmarker::Utils;
# autoflush our STDOUT for sanity
use FileHandle;
autoflush STDOUT 1;
# init our global variables ( bad, haha )
my( $version, $eventloop, $asserts, $lite_tests, $pocosession );
my( $post_limit, $alarm_limit, $alarm_add_limit, $session_limit, $select_limit, $through_limit, $call_limit, $start_limit );
# the main routine which will load everything + start
sub benchmark {
# process the version
process_version();
# process the eventloop
process_eventloop();
# process the assertions
process_assertions();
# process the test mode
process_testmode();
# process the XS::Queue hiding
process_xsqueue();
# actually import POE!
process_POE();
# actually run the benchmarks!
run_benchmarks();
# all done!
return;
}
sub process_version {
# Get the desired POE version
$version = $ARGV[0];
# Decide what to do
if ( ! defined $version ) {
die "Please supply a version to test!";
} elsif ( ! -d 'poedists/POE-' . $version ) {
die "That specified version does not exist!";
} else {
# we're happy...
}
return;
}
sub process_eventloop {
# Get the desired mode
$eventloop = $ARGV[1];
# print out the loop info
if ( ! defined $eventloop ) {
die "Please supply an event loop!";
} else {
my $v = loop2realversion( $eventloop ) || 'UNKNOWN';
print "Using loop: $eventloop-$v\n";
}
return;
}
sub process_assertions {
# Get the desired assert mode
$asserts = $ARGV[2];
if ( defined $asserts and $asserts ) {
print "Using FULL Assertions!\n";
} else {
print "Using NO Assertions!\n";
}
return;
}
sub process_testmode {
# get the desired test mode
$lite_tests = $ARGV[3];
if ( defined $lite_tests and $lite_tests ) {
print "Using the LITE tests\n";
$post_limit = 10_000;
$alarm_limit = 10_000;
$alarm_add_limit = 10_000;
$session_limit = 500;
$select_limit = 10_000;
$through_limit = 10_000;
$call_limit = 10_000;
$start_limit = 10;
} else {
print "Using the HEAVY tests\n";
$post_limit = 100_000;
$alarm_limit = 100_000;
$alarm_add_limit = 100_000;
$session_limit = 5_000;
$select_limit = 100_000;
$through_limit = 100_000;
$call_limit = 100_000;
$start_limit = 100;
}
return;
}
sub process_xsqueue {
# should we "hide" XS::Queue::Array?
if ( defined $ARGV[4] and $ARGV[4] ) {
print "DISABLING POE::XS::Queue::Array\n";
} else {
print "LETTING POE find POE::XS::Queue::Array\n";
}
return;
}
sub process_POE {
# Print the POE info
print "Using POE-" . $POE::VERSION . "\n";
# Actually print what loop POE is using
foreach my $m ( keys %INC ) {
if ( $m =~ /^POE\/(?:Loop|XS|Queue)/ ) {
# try to be smart and get version?
my $module = $m;
$module =~ s|/|::|g;
$module =~ s/\.pm$//g;
print "POE is using: $module ";
if ( defined $module->VERSION ) {
print "v" . $module->VERSION . "\n";
} else {
print "vUNKNOWN\n";
}
}
}
return;
}
sub run_benchmarks {
# run the startup test before we actually run POE
bench_startup();
# load the POE session + do the tests there
bench_poe();
# dump some misc info
dump_memory();
dump_times();
dump_perlinfo();
dump_sysinfo();
# all done!
return;
}
sub bench_startup {
# Add the eventloop?
my $looploader = poeloop2load( $eventloop );
my @start_times = times();
my $start = time();
for (my $i = 0; $i < $start_limit; $i++) {
# FIXME should we add assertions?
# finally, fire it up!
CORE::system(
$^X,
'-Ipoedists/POE-' . $version,
'-Ipoedists/POE-' . $version . '/lib',
( defined $looploader ? "-M$looploader" : () ),
'-MPOE',
'-e',
1,
);
}
my @end_times = times();
my $elapsed = time() - $start;
printf( "\n\n% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $start_limit, 'startups', $elapsed, $start_limit/$elapsed );
print "startup times: @start_times @end_times\n";
return;
}
sub bench_poe {
# figure out POE::Session->create or POE::Session->new or what?
$pocosession = POE::Session->can( 'create' );
if ( defined $pocosession ) {
$pocosession = 'create';
} else {
$pocosession = POE::Session->can( 'spawn' );
if ( defined $pocosession ) {
$pocosession = 'spawn';
} else {
$pocosession = 'new';
}
}
# create the master sesssion + run POE!
POE::Session->$pocosession(
'inline_states' => {
# basic POE states
'_start' => \&poe__start,
'_default' => \&poe__default,
'_stop' => \&poe__stop,
'null' => \&poe_null,
# our test states
'posts' => \&poe_posts,
'posts_start' => \&poe_posts_start,
'posts_end' => \&poe_posts_end,
'alarms' => \&poe_alarms,
'manyalarms' => \&poe_manyalarms,
'sessions' => \&poe_sessions,
'sessions_end' => \&poe_sessions_end,
'stdin_read' => \&poe_stdin_read,
'stdin_write' => \&poe_stdin_write,
'myfh_read' => \&poe_myfh_read,
'myfh_write' => \&poe_myfh_write,
'calls' => \&poe_calls,
'eventsquirt' => \&poe_eventsquirt,
'eventsquirt_done' => \&poe_eventsquirt_done,
},
);
# start the kernel!
POE::Kernel->run();
return;
}
# inits our session
sub poe__start {
# fire off the first test!
$_[KERNEL]->yield( 'posts' );
return;
}
sub poe__stop {
}
sub poe__default {
return 0;
}
# a state that does nothing
sub poe_null {
return 1;
}
# How many posts per second? Post a bunch of events, keeping track of the time it takes.
sub poe_posts {
$_[KERNEL]->yield( 'posts_start' );
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $post_limit; $i++) {
$_[KERNEL]->yield( 'null' );
}
my @end_times = times();
my $elapsed = time() - $start;
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $post_limit, 'posts', $elapsed, $post_limit/$elapsed );
print "posts times: @start_times @end_times\n";
$_[KERNEL]->yield( 'posts_end' );
return;
}
sub poe_posts_start {
$_[HEAP]->{start} = time();
$_[HEAP]->{starttimes} = [ times() ];
return;
}
sub poe_posts_end {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $post_limit, 'dispatches', $elapsed, $post_limit/$elapsed );
print "dispatches times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
$_[KERNEL]->yield( 'alarms' );
return;
}
# How many alarms per second? Set a bunch of alarms and find out.
sub poe_alarms {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $alarm_limit; $i++) {
$_[KERNEL]->alarm( whee => rand(1_000_000) );
}
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $alarm_limit, 'alarms', $elapsed, $alarm_limit/$elapsed );
print "alarms times: @start_times @end_times\n";
$_[KERNEL]->alarm( 'whee' => undef );
$_[KERNEL]->yield( 'manyalarms' );
return;
}
# How many repetitive alarms per second? Set a bunch of
# additional alarms and find out. Also see how quickly they can
# be cleared.
sub poe_manyalarms {
# can this POE::Kernel support this?
if ( $_[KERNEL]->can( 'alarm_add' ) ) {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $alarm_add_limit; $i++) {
$_[KERNEL]->alarm_add( whee => rand(1_000_000) );
}
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $alarm_add_limit, 'alarm_adds', $elapsed, $alarm_add_limit/$elapsed );
print "alarm_adds times: @start_times @end_times\n";
$start = time();
@start_times = times();
$_[KERNEL]->alarm( whee => undef );
$elapsed = time() - $start;
@end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $alarm_add_limit, 'alarm_clears', $elapsed, $alarm_add_limit/$elapsed );
print "alarm_clears times: @start_times @end_times\n";
} else {
print "this version of POE does not support alarm_add, skipping alarm_adds/alarm_clears tests!\n";
}
$_[KERNEL]->yield( 'sessions' );
return;
}
# How many sessions can we create and destroy per second?
# Create a bunch of sessions, and track that time. Let them
# self-destruct, and track that as well.
sub poe_sessions {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $session_limit; $i++) {
POE::Session->$pocosession( 'inline_states' => { _start => sub {}, _stop => sub {}, _default => sub { return 0 } } );
}
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $session_limit, 'session creates', $elapsed, $session_limit/$elapsed );
print "session create times: @start_times @end_times\n";
$_[KERNEL]->yield( 'sessions_end' );
$_[HEAP]->{start} = time();
$_[HEAP]->{starttimes} = [ times() ];
return;
}
sub poe_sessions_end {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $session_limit, 'session destroys', $elapsed, $session_limit/$elapsed );
print "session destroys times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
$_[KERNEL]->yield( 'stdin_read' );
return;
}
# How many times can we select/unselect READ a from STDIN filehandle per second?
sub poe_stdin_read {
# stupid, but we have to skip those tests
if ( $eventloop eq 'Tk' or $eventloop eq 'Prima' ) {
print "SKIPPING STDIN tests on broken loop: $eventloop\n";
$_[KERNEL]->yield( 'myfh_read' );
return;
}
my $start = time();
my @start_times = times();
eval {
for (my $i = 0; $i < $select_limit; $i++) {
$_[KERNEL]->select_read( *STDIN, 'whee' );
$_[KERNEL]->select_read( *STDIN );
}
};
if ( $@ ) {
print "filehandle select_read on *STDIN FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $select_limit, 'select_read STDIN', $elapsed, $select_limit/$elapsed );
print "select_read STDIN times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'stdin_write' );
return;
}
# How many times can we select/unselect WRITE a from STDIN filehandle per second?
sub poe_stdin_write {
my $start = time();
my @start_times = times();
eval {
for (my $i = 0; $i < $select_limit; $i++) {
$_[KERNEL]->select_write( *STDIN, 'whee' );
$_[KERNEL]->select_write( *STDIN );
}
};
if ( $@ ) {
print "filehandle select_write on *STDIN FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $select_limit, 'select_write STDIN', $elapsed, $select_limit/$elapsed );
print "select_write STDIN times: @start_times @end_times\n";
}
$_[KERNEL]->yield( 'myfh_read' );
return;
}
# How many times can we select/unselect READ a real filehandle?
sub poe_myfh_read {
# stupid, but we have to skip those tests
if ( $eventloop eq 'Event_Lib' or $eventloop eq 'Tk' or $eventloop eq 'Prima' ) {
print "SKIPPING MYFH tests on broken loop: $eventloop\n";
$_[KERNEL]->yield( 'calls' );
return;
}
- open( MYFH, '+>', 'poebench' ) or die $!;
+ open( my $fh, '+>', 'poebench' ) or die $!;
my $start = time();
my @start_times = times();
eval {
for (my $i = 0; $i < $select_limit; $i++) {
- $_[KERNEL]->select_read( *MYFH, 'whee' );
- $_[KERNEL]->select_read( *MYFH );
+ $_[KERNEL]->select_read( $fh, 'whee' );
+ $_[KERNEL]->select_read( $fh );
}
};
if ( $@ ) {
print "filehandle select_read on *MYFH FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $select_limit, 'select_read MYFH', $elapsed, $select_limit/$elapsed );
print "select_read MYFH times: @start_times @end_times\n";
}
- close( MYFH ) or die $!;
+ close( $fh ) or die $!;
unlink( 'poebench' ) or die $!;
$_[KERNEL]->yield( 'myfh_write' );
return;
}
# How many times can we select/unselect WRITE a real filehandle?
sub poe_myfh_write {
- open( MYFH, '+>', 'poebench' ) or die $!;
+ open( my $fh, '+>', 'poebench' ) or die $!;
my $start = time();
my @start_times = times();
eval {
for (my $i = 0; $i < $select_limit; $i++) {
- $_[KERNEL]->select_write( *MYFH, 'whee' );
- $_[KERNEL]->select_write( *MYFH );
+ $_[KERNEL]->select_write( $fh, 'whee' );
+ $_[KERNEL]->select_write( $fh );
}
};
if ( $@ ) {
print "filehandle select_write on *MYFH FAILED: $@\n";
} else {
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $select_limit, 'select_write MYFH', $elapsed, $select_limit/$elapsed );
print "select_write MYFH times: @start_times @end_times\n";
}
- close( MYFH ) or die $!;
+ close( $fh ) or die $!;
unlink( 'poebench' ) or die $!;
$_[KERNEL]->yield( 'calls' );
return;
}
# How many times can we call a state?
sub poe_calls {
my $start = time();
my @start_times = times();
for (my $i = 0; $i < $call_limit; $i++) {
$_[KERNEL]->call( $_[SESSION], 'null' );
}
my $elapsed = time() - $start;
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $call_limit, 'calls', $elapsed, $call_limit/$elapsed );
print "calls times: @start_times @end_times\n";
$_[KERNEL]->yield( 'eventsquirt' );
return;
}
# How many events can we squirt through POE, one at a time?
sub poe_eventsquirt {
$_[HEAP]->{start} = time();
$_[HEAP]->{starttimes} = [ times() ];
$_[HEAP]->{yield_count} = $through_limit;
$_[KERNEL]->yield( 'eventsquirt_done' );
return;
}
sub poe_eventsquirt_done {
if (--$_[HEAP]->{yield_count}) {
$_[KERNEL]->yield( 'eventsquirt_done' );
} else {
my $elapsed = time() - $_[HEAP]->{start};
my @end_times = times();
printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $through_limit, 'single_posts', $elapsed, $through_limit/$elapsed );
print "single_posts times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
}
# reached end of tests!
return;
}
# Get the memory footprint
sub dump_memory {
print "\n\nMemory footprint:\n";
- open( MEMORY, '/proc/self/status' ) or die $!;
- while ( <MEMORY> ) {
+ open( my $fh, '<', '/proc/self/status' ) or die $!;
+ while ( <$fh> ) {
print;
}
- close( MEMORY ) or die $!;
+ close( $fh ) or die $!;
return;
}
# print the time it took to execute this program
sub dump_times {
my ($wall, $user, $system, $cuser, $csystem) = ( (time-$^T), times() );
printf( ( "\n\n--- times ---\n" .
"wall : %9.3f\n" .
"user : %9.3f cuser: %9.3f\n" .
"sys : %9.3f csys : %9.3f\n"
),
$wall, $user, $cuser, $system, $csystem,
);
return;
}
# print the local Perl info
sub dump_perlinfo {
print "\n\nRunning under perl binary: " . $^X . "\n";
require Config;
print Config::myconfig();
return;
}
# print the local system information
sub dump_sysinfo {
print "Running under machine: " . `uname -a` . "\n";
# get cpuinfo
print "Running under CPU:\n";
- open( CPUINFO, '/proc/cpuinfo' ) or die $!;
- while ( <CPUINFO> ) {
+ open( my $fh, '<', '/proc/cpuinfo' ) or die $!;
+ while ( <$fh> ) {
print;
}
- close( CPUINFO ) or die $!;
+ close( $fh ) or die $!;
# get meminfo
print "Running under meminfo:\n";
- open( MEMINFO, '/proc/meminfo' ) or die $!;
- while ( <MEMINFO> ) {
+ open( $fh, '<', '/proc/meminfo' ) or die $!;
+ while ( <$fh> ) {
print;
}
- close( MEMINFO ) or die $!;
+ close( $fh ) or die $!;
return;
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::SubProcess - Implements the actual POE benchmarks
=head1 SYNOPSIS
perl -MPOE::Devel::Benchmarker::SubProcess -e 'benchmark()'
=head1 ABSTRACT
This package is responsible for implementing the guts of the benchmarks, and timing them.
=head2 EXPORT
Nothing.
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/lib/POE/Devel/Benchmarker/Utils.pm b/lib/POE/Devel/Benchmarker/Utils.pm
index 234d1c4..a6bb557 100644
--- a/lib/POE/Devel/Benchmarker/Utils.pm
+++ b/lib/POE/Devel/Benchmarker/Utils.pm
@@ -1,133 +1,134 @@
# Declare our package
package POE::Devel::Benchmarker::Utils;
use strict; use warnings;
# Initialize our version
use vars qw( $VERSION );
$VERSION = '0.01';
# auto-export the only sub we have
require Exporter;
use vars qw( @ISA @EXPORT );
@ISA = qw(Exporter);
@EXPORT = qw( poeloop2load loop2realversion );
# returns the proper "load" stuff for a specific loop
sub poeloop2load {
my $eventloop = shift;
# Decide which event loop to use
# Event_Lib EV Glib Prima Gtk Wx Kqueue Tk Select IO_Poll
if ( $eventloop eq 'Event' ) {
return 'Event';
} elsif ( $eventloop eq 'IO_Poll' ) {
return 'IO::Poll';
} elsif ( $eventloop eq 'Event_Lib' ) {
return 'Event::Lib';
} elsif ( $eventloop eq 'EV' ) {
return 'EV';
} elsif ( $eventloop eq 'Glib' ) {
return 'Glib';
} elsif ( $eventloop eq 'Tk' ) {
return 'Tk',
} elsif ( $eventloop eq 'Gtk' ) {
return 'Gtk';
} elsif ( $eventloop eq 'Prima' ) {
return 'Prima';
} elsif ( $eventloop eq 'Wx' ) {
return 'Wx';
} elsif ( $eventloop eq 'Kqueue' ) {
# FIXME dunno what to do here!
return;
} elsif ( $eventloop eq 'Select' ) {
return;
} else {
die "Unknown event loop!";
}
}
# returns the version of the "real" installed module that the loop uses
sub loop2realversion {
my $eventloop = shift;
# Decide which event loop to use
if ( ! defined $eventloop ) {
return;
} elsif ( $eventloop eq 'Event' ) {
return $Event::VERSION;
} elsif ( $eventloop eq 'IO_Poll' ) {
return $IO::Poll::VERSION;
} elsif ( $eventloop eq 'Event_Lib' ) {
return $Event::Lib::VERSION;
} elsif ( $eventloop eq 'EV' ) {
return $EV::VERSION;
} elsif ( $eventloop eq 'Glib' ) {
return $Glib::VERSION;
} elsif ( $eventloop eq 'Tk' ) {
return $Tk::VERSION;
} elsif ( $eventloop eq 'Gtk' ) {
return $Gtk::VERSION;
} elsif ( $eventloop eq 'Prima' ) {
return $Prima::VERSION;
} elsif ( $eventloop eq 'Wx' ) {
return $Wx::VERSION;
} elsif ( $eventloop eq 'Kqueue' ) {
# FIXME how do I do this?
return;
} elsif ( $eventloop eq 'Select' ) {
return 'BUILTIN';
} else {
die "Unknown event loop!";
}
}
1;
__END__
=head1 NAME
POE::Devel::Benchmarker::Utils - Various utility routines for POE::Devel::Benchmarker
=head1 SYNOPSIS
perl -MPOE::Devel::Benchmarker::Utils -e 'print poeloop2load( "IO_Poll" )'
=head1 ABSTRACT
This package contains the utility routines and constants that POE::Devel::Benchmarker needs.
=head2 EXPORT
Automatically exports those subs:
-=over
+=over 4
+
=item poeloop2load()
Returns the "parent" class to load for a specific loop. An example is:
$real = poeloop2load( 'IO_Poll' ); # $real now contains "IO::Poll"
=item loop2realversion()
Returns the version of the "parent" class for a specific loop. An example is:
$ver = loop2realversion( 'IO_Poll' ); # $ver now contains $IO::Poll::VERSION
=back
=head1 SEE ALSO
L<POE::Devel::Benchmarker>
=head1 AUTHOR
Apocalypse E<lt>apocal@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright 2008 by Apocalypse
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
diff --git a/t/a_dosnewline.t b/t/a_dosnewline.t
index cde6be6..89bcd54 100644
--- a/t/a_dosnewline.t
+++ b/t/a_dosnewline.t
@@ -1,35 +1,35 @@
#!/usr/bin/perl
use Test::More;
# AUTHOR test
if ( not $ENV{TEST_AUTHOR} ) {
plan skip_all => 'Author test. Sent $ENV{TEST_AUTHOR} to a true value to run.';
} else {
eval "use File::Find::Rule";
if ( $@ ) {
plan skip_all => 'File::Find::Rule required for checking for presence of DOS newlines';
} else {
plan tests => 1;
# generate the file list
my $rule = File::Find::Rule->new;
$rule->grep( qr/\r\n/ );
- my @files = $rule->in( qw( lib t scripts ) );
+ my @files = $rule->in( qw( lib t ) );
# FIXME read in MANIFEST.SKIP and use it!
# for now, we skip SVN + git stuff
@files = grep { $_ !~ /(?:\/\.svn\/|\/\.git\/)/ } @files;
# do we have any?
if ( scalar @files ) {
fail( 'newline check' );
diag( 'DOS newlines found in these files:' );
foreach my $f ( @files ) {
diag( ' ' . $f );
}
} else {
pass( 'newline check' );
}
}
}
|
apocalypse/perl-poe-benchmarker
|
73b2ea70ae1023023c711d880d83b75d5ac4ab36
|
more work smoothing things out
|
diff --git a/.project b/.project
index 75eb52d..c4485a3 100644
--- a/.project
+++ b/.project
@@ -1,18 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
- <name>perl-poe-simpledbi</name>
+ <name>perl-poe-benchmarker</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.epic.perleditor.perlbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.epic.perleditor.perlnature</nature>
</natures>
</projectDescription>
-
diff --git a/Build.PL b/Build.PL
index 6a02c4a..ab01bef 100755
--- a/Build.PL
+++ b/Build.PL
@@ -1,61 +1,95 @@
# Build.PL
use Module::Build;
my $build = Module::Build->new(
# look up Module::Build::API for the info!
'dynamic_config' => 0,
'module_name' => 'POE::Devel::Benchmarker',
'license' => 'perl',
- 'dist_abstract' => 'Benchmarking POE\'s performance ( acts more like a smoker )',
+ 'dist_abstract' => "Benchmarking POE's performance ( acts more like a smoker )",
'dist_author' => 'Apocalypse <APOCAL@cpan.org>',
'create_packlist' => 1,
'create_makefile_pl' => 'traditional',
'create_readme' => 1,
'test_files' => 't/*.t',
'add_to_cleanup' => [ 'META.yml', 'Makefile.PL', 'README' ], # automatically generated
'requires' => {
# POE Stuff
'POE' => 0,
+ 'POE::Session::AttributeBased' => 0,
# FIXME POE stuff that Test::Dependencies needs to see
'POE::Session' => 0,
'POE::Filter::Line' => 0,
'POE::Wheel::Run' => 0,
- # DB access
- 'DBI' => '1.30',
+ # misc perl stuff
+ 'Time::HiRes' => 0,
+ 'version' => 0,
+ 'Devel::Hide' => 0,
+
+ # GetPOEdists reqs
+ 'LWP::UserAgent' => 0,
+ 'HTML::LinkExtor' => 0,
+ 'URI::URL' => 0,
+ 'Archive::Tar' => 0,
},
'recommends' => {
# Test stuff
'Test::More' => 0,
+
+ # our POE loops!
+ 'POE::Loop::Event' => 0,
+ 'POE::Loop::Event_Lib' => 0,
+ 'POE::Loop::EV' => 0,
+ 'POE::Loop::Glib' => 0,
+ 'POE::Loop::Prima' => 0,
+ 'POE::Loop::Gtk' => 0,
+ 'POE::Loop::Wx' => 0,
+ 'POE::Loop::Kqueue' => 0,
+
+ # included in POE ( listed here for completeness )
+ #'POE::Loop::Tk' => 0,
+ #'POE::Loop::Select' => 0,
+ #'POE::Loop::IO_Poll' => 0,
+
+ # the loops' dependencies
+ 'Event' => 0,
+ 'Event::Lib' => 0,
+ 'EV' => 0,
+ 'Glib' => 0,
+ 'Prima' => 0,
+ 'Gtk' => 0,
+ 'Wx' => 0,
+ 'Tk' => 0,
},
# FIXME wishlist...
# 'test_requires' => {
# # Test stuff
# 'Test::Compile' => 0,
# 'Test::Perl::Critic' => 0,
# 'Test::Dependencies' => 0,
# 'Test::Distribution' => 0,
# 'Test::Fixme' => 0,
# 'Test::HasVersion' => 0,
# 'Test::Kwalitee' => 0,
# 'Test::CheckManifest' => 0,
# 'Test::MinimumVersion' => 0,
# 'Test::Pod::Coverage' => 0,
# 'Test::Spelling' => 0,
# 'Test::Pod' => 0,
# 'Test::Prereq' => 0,
# 'Test::Strict' => 0,
# 'Test::UseAllModules' => 0,
# },
);
# all done!
$build->create_build_script;
diff --git a/Changes b/Changes
index 6eec582..853ac02 100755
--- a/Changes
+++ b/Changes
@@ -1,172 +1,5 @@
-Revision history for Perl extension POE::Component::SimpleDBI.
+Revision history for Perl extension POE::Devel::Benchmarker
-* 1.23
+* 0.01
- Switched to Build.PL for the build system
- Fixed the stupid test dependencies, thanks BiNGOs!
- Added the new EXPERIMENTAL 'ATOMIC' support, please let me know if it's broken on your setup!
- Added some more author tests
- Added AUTO_COMMIT argument to CONNECT to control the DBI variable ( defaults to true )
-
-* 1.22
-
- Kwalitee-related fixes
-
-* 1.21
-
- silence warnings when used with DBD::SQLite - thanks to Sjors Gielen for tracking this down!
-
-* 1.20
-
- Added the INSERT_ID to control $dbh->last_insert_id usage
-
-* 1.19
-
- Added the PREPARE_CACHED argument to control caching
-
-* 1.18
-
- Ignore the DBI error for last_insert_id and default to undef
-
-* 1.17
-
- Added "INSERTID" to the result of DO
-
-* 1.16
-
- Noticed a glaring documentation bug
- - SINGLE queries return mixedCaps rows ( not lowercase! )
- - MULTIPLE queries return lowercase rows
-
- This makes me *VERY* tempted to fix SINGLE to return lowercase, is this a good idea? Let me know!
-
- Fixed SimpleDBI failure on Win32 - thanks RT #23851
-
-* 1.15
-
- Thanks to Fred Castellano, who stumbled on a DEADLOCK bug, fixed!
- Added sanity tests to CONNECT/DISCONNECT
-
-* 1.14
-
- learned about the difference between ref $self and ref( $self )
- Kwalitee-related fixes
-
-* 1.13
-
- Finally use a Changes file - thanks RT #18981
- Fixed a bug in SINGLE if returned_rows = 0 it will not return undef, but give us blank rows!
- Documentation tweaks
-
-* 1.12
-
- In the SubProcess, added a binmode() to STDIN and STDERR, for the windows attempt
- Added code to make SimpleDBI work in Win32 boxes, thanks to the recent Wheel::Run patches!
- Documentation tweaks as usual
-
-* 1.11
-
- Hannes had a problem:
- His IRC bot logs events to a database, and sometimes there is no events to log after
- hours and hours of inactivity ( must be a boring channel haha ), the db server disconnected!
-
- The solution was to do a $dbh->ping() before each query, if your DBI driver does it inefficiently, go yell at them!
- In the event that a reconnect is not possible, an error will be sent to the CONNECT event handler, look at the updated pod.
-
-* 1.10
-
- Fixed a bug in the DO routine, thanks to Hannes!
-
-* 1.09
-
- Removed the abstract LIMIT 1 to the SINGLE query
-
- Removed the silly 5.8.x requirement in Makefile.PL
-
- Made the SubProcess use less memory by exec()ing itself
-
- Added the new CONNECT/DISCONNECT commands
-
- Removed the db connection information from new()
-
- Minor tweaks here and there to not stupidly call() the queue checker when there is nothing to check :)
-
- Added the sysreaderr debugging output
-
- More intelligent SQL/PLACEHOLDERS/BAGGAGE handling
-
- Made the command arguments more stricter, it will only accept valid arguments, instead of just extracting what it needs
-
- Made sure all return data have ID/EVENT/SESSION/ACTION in them for easy debugging
-
- Added the SESSION parameter to all commands for easy redirection
-
- Updated the POD and generally made it better :)
-
- Added a new command -> Clear_Queue ( clears the queue )
-
-* 1.08
-
- In the SubProcess, removed the select statement requirement
-
-* 1.07
-
- In the SubProcess, fixed a silly mistake in DO's execution of placeholders
-
- Cleaned up a few error messages in the SubProcess
-
- Peppered the code with *more* DEBUG statements :)
-
- Replaced a croak() with a die() when it couldn't connect to the database
-
- Documented the _child events
-
-* 1.06
-
- Fixed some typos in the POD
-
- Added the BAGGAGE option
-
-* 1.05
-
- Fixed some typos in the POD
-
- Fixed the DEBUG + MAX_RETRIES "Subroutine redefined" foolishness
-
-* 1.04
-
- Got rid of the EVENT_S and EVENT_E handlers, replaced with a single EVENT handler
-
- Internal changes to get rid of some stuff -> Send_Query / Send_Wheel
-
- Added the Delete_Query event -> Deletes an query via ID
-
- Changed the DO/MULTIPLE/SINGLE/QUOTE events to return an ID ( Only usable if call'ed )
-
- Made sure that the ACTION key is sent back to the EVENT handler every time
-
- Added some DEBUG stuff :)
-
- Added the CHANGES section
-
- Fixed some typos in the POD
-
-* 1.03
-
- Increments refcount for querying sessions so they don't go away
-
- POD formatting
-
- Consolidated shutdown and shutdown_NOW into one single event
-
- General formatting in program
-
- DB connection error handling
-
- Renamed the result hash: RESULTS to RESULT for better readability
-
- SubProcess -> added DBI connect failure handling
-
-* 1.02
-
- Initial release
+ initial release
diff --git a/MANIFEST b/MANIFEST
index 53531db..e2e5f32 100755
--- a/MANIFEST
+++ b/MANIFEST
@@ -1,31 +1,33 @@
Makefile.PL
Build.PL
MANIFEST
MANIFEST.SKIP
README
lib/POE/Devel/Benchmarker.pm
+lib/POE/Devel/Benchmarker/GetInstalledLoops.pm
+lib/POE/Devel/Benchmarker/GetPOEdists.pm
lib/POE/Devel/Benchmarker/SubProcess.pm
-META.yml Module meta-data (added by MakeMaker)
+lib/POE/Devel/Benchmarker/Utils.pm
+META.yml
Changes
-scripts/getdists.pl
t/1_load.t
t/a_critic.t
t/a_kwalitee.t
t/a_pod.t
t/a_pod_spelling.t
t/a_pod_coverage.t
t/a_strict.t
t/a_hasversion.t
t/a_minimumversion.t
t/a_manifest.t
t/a_distribution.t
t/a_compile.t
t/a_dependencies.t
t/a_fixme.t
t/a_prereq.t
t/a_prereq_build.t
t/a_dosnewline.t
t/a_perlmetrics.t
t/a_is_prereq_outdated.t
diff --git a/lib/POE/Devel/Benchmarker.pm b/lib/POE/Devel/Benchmarker.pm
index e69de29..1be4898 100644
--- a/lib/POE/Devel/Benchmarker.pm
+++ b/lib/POE/Devel/Benchmarker.pm
@@ -0,0 +1,532 @@
+# Declare our package
+package POE::Devel::Benchmarker;
+use strict; use warnings;
+
+# Initialize our version
+use vars qw( $VERSION );
+$VERSION = '0.01';
+
+# auto-export the only sub we have
+BEGIN {
+ require Exporter;
+ use vars qw( @ISA @EXPORT );
+ @ISA = qw(Exporter);
+ @EXPORT = qw( benchmark );
+}
+
+# Import what we need from the POE namespace
+use POE qw( Session Filter::Line Wheel::Run );
+use base 'POE::Session::AttributeBased';
+
+# we need hires times
+use Time::HiRes qw( time );
+
+# load comparison stuff
+use version;
+
+# Load our stuff
+use POE::Devel::Benchmarker::GetInstalledLoops;
+use POE::Devel::Benchmarker::Utils;
+
+# Actually run the tests!
+sub benchmark {
+ my $options = shift;
+
+ # set default options
+ my $lite_tests = 1;
+ my $quiet_mode = 0;
+
+ # process our options
+ if ( defined $options and ref $options and ref( $options ) eq 'HASH' ) {
+ # process LITE tests
+ if ( exists $options->{'litetests'} ) {
+ if ( $options->{'litetests'} ) {
+ $lite_tests = 1;
+ } else {
+ $lite_tests = 0;
+ }
+ }
+
+ # process quiet mode
+ if ( exists $options->{'quiet'} ) {
+ if ( $options->{'quiet'} ) {
+ $quiet_mode = 1;
+ } else {
+ $quiet_mode = 0;
+ }
+ }
+ }
+
+ # do some sanity checks
+ if ( ! -d 'poedists' ) {
+ die "The 'poedists' directory is not found in the working directory!";
+ }
+ if ( ! -d 'results' ) {
+ die "The 'results' directory is not found in the working directory!";
+ }
+
+ if ( ! $quiet_mode ) {
+ print "[BENCHMARKER] Starting up...\n";
+ }
+
+ # Create our session
+ POE::Session->create(
+ __PACKAGE__->inline_states(),
+ 'heap' => {
+ 'lite_tests' => $lite_tests,
+ 'quiet_mode' => $quiet_mode,
+ },
+ );
+
+ # Fire 'er up!
+ POE::Kernel->run();
+ return;
+}
+
+# Starts up our session
+sub _start : State {
+ # set our alias
+ $_[KERNEL]->alias_set( 'Benchmarker' );
+
+ # sanely handle some signals
+ $_[KERNEL]->sig( 'INT', 'handle_kill' );
+ $_[KERNEL]->sig( 'TERM', 'handle_kill' );
+
+ # okay, get all the dists we can!
+ my @versions;
+ opendir( DISTS, 'poedists' ) or die $!;
+ foreach my $d ( readdir( DISTS ) ) {
+ if ( $d =~ /^POE\-(.+)$/ and $d !~ /\.tar\.gz$/ ) {
+ push( @versions, $1 );
+ }
+ }
+ closedir( DISTS ) or die $!;
+
+ # okay, go through all the dists in version order
+ @versions = sort { $b <=> $a }
+ map { version->new( $_ ) } @versions;
+
+ # Store the versions in our heap
+ $_[HEAP]->{'VERSIONS'} = \@versions;
+
+ if ( ! $_[HEAP]->{'quiet_mode'} ) {
+ print "[BENCHMARKER] Detected available POE versions -> " . join( " ", @versions ) . "\n";
+ }
+
+ # First of all, we need to find out what loop libraries are installed
+ getPOEloops( $_[HEAP]->{'quiet_mode'} );
+
+ return;
+}
+
+sub _stop : State {
+ # tell the wheel to kill itself
+ if ( defined $_[HEAP]->{'WHEEL'} ) {
+ $_[HEAP]->{'WHEEL'}->kill( 9 );
+ undef $_[HEAP]->{'WHEEL'};
+ }
+
+ if ( ! $_[HEAP]->{'quiet_mode'} ) {
+ print "[BENCHMARKER] Shutting down...\n";
+ }
+
+ return;
+}
+
+# we received list of loops from GetInstalledLoops
+sub found_loops : State {
+ $_[HEAP]->{'installed_loops'} = [ sort { $a eq $b } @{ $_[ARG0] } ];
+
+ if ( ! $_[HEAP]->{'quiet_mode'} ) {
+ print "[BENCHMARKER] Detected available POE::Loops -> " . join( " ", @{ $_[HEAP]->{'installed_loops'} } ) . "\n";
+ }
+
+ # start the benchmark!
+ $_[KERNEL]->yield( 'run_benchmark' );
+ return;
+}
+
+# Runs one benchmark
+sub run_benchmark : State {
+ # Grab the version from the top of the array
+ $_[HEAP]->{'current_version'} = shift @{ $_[HEAP]->{'VERSIONS'} };
+
+ # did we run out of versions?
+ if ( ! defined $_[HEAP]->{'current_version'} ) {
+ # We're done, let POE die...
+ $_[KERNEL]->alias_remove( 'Benchmarker' );
+ } else {
+ $_[HEAP]->{'loops'} = [ @{ $_[HEAP]->{'installed_loops'} } ];
+
+ # okay, fire off the first loop
+ $_[KERNEL]->yield( 'bench_loop' );
+ }
+
+ return;
+}
+
+# runs one loop
+sub bench_loop : State {
+ # select our current loop
+ $_[HEAP]->{'current_loop'} = shift @{ $_[HEAP]->{'loops'} };
+
+ # are we done with all loops?
+ if ( ! defined $_[HEAP]->{'current_loop'} ) {
+ # yay, go back to the main handler
+ $_[KERNEL]->yield( 'run_benchmark' );
+ } else {
+ # Start the assert test
+ $_[HEAP]->{'assertions'} = [ qw( 0 1 ) ];
+ $_[KERNEL]->yield( 'bench_asserts' );
+ }
+
+ return;
+}
+
+# runs an assertion
+sub bench_asserts : State {
+ # select our current assert state
+ $_[HEAP]->{'current_assertions'} = shift @{ $_[HEAP]->{'assertions'} };
+
+ # are we done?
+ if ( ! defined $_[HEAP]->{'current_assertions'} ) {
+ # yay, go back to the loop handler
+ $_[KERNEL]->yield( 'bench_loop' );
+ } else {
+ # Start the xsqueue test
+ $_[HEAP]->{'xsqueue'} = [ qw( 0 1 ) ];
+ $_[KERNEL]->yield( 'bench_xsqueue' );
+ }
+
+ return;
+}
+
+# runs test with or without xsqueue
+sub bench_xsqueue : State {
+ # select our current xsqueue state
+ $_[HEAP]->{'current_xsqueue'} = shift @{ $_[HEAP]->{'xsqueue'} };
+
+ # are we done?
+ if ( ! defined $_[HEAP]->{'current_xsqueue'} ) {
+ # yay, go back to the assert handler
+ $_[KERNEL]->yield( 'bench_asserts' );
+ } else {
+ # actually fire off the subprocess, ha!
+ $_[KERNEL]->yield( 'create_subprocess' );
+ }
+
+ return;
+}
+
+# actually runs the subprocess
+sub create_subprocess : State {
+ # Okay, start testing this specific combo!
+ if ( ! $_[HEAP]->{'quiet_mode'} ) {
+ print "Testing POE v" . $_[HEAP]->{'current_version'} .
+ " loop(" . $_[HEAP]->{'current_loop'} . ')' .
+ " assertions(" . ( $_[HEAP]->{'current_assertions'} ? 'ENABLED' : 'DISABLED' ) . ')' .
+ " xsqueue(" . ( $_[HEAP]->{'current_xsqueue'} ? 'ENABLED' : 'DISABLED' ) . ')' .
+ "\n";
+ }
+
+ # save the starttime
+ $_[HEAP]->{'current_starttime'} = time();
+ $_[HEAP]->{'current_starttimes'} = [ times() ];
+
+ # Okay, create the wheel::run to handle this
+ my $looploader = poeloop2load( $_[HEAP]->{'current_loop'} );
+ $_[HEAP]->{'WHEEL'} = POE::Wheel::Run->new(
+ 'Program' => $^X,
+ 'ProgramArgs' => [ '-Ipoedists/POE-' . $_[HEAP]->{'current_version'},
+ '-Ipoedists/POE-' . $_[HEAP]->{'current_version'} . '/lib',
+ ( defined $looploader ? "-M$looploader" : () ),
+ '-MPOE::Devel::Benchmarker::SubProcess',
+ '-e',
+ 'POE::Devel::Benchmarker::SubProcess::benchmark',
+ $_[HEAP]->{'current_version'},
+ $_[HEAP]->{'current_loop'},
+ $_[HEAP]->{'current_assertions'},
+ $_[HEAP]->{'lite_tests'},
+ $_[HEAP]->{'current_xsqueue'},
+ ],
+
+ # Kill off existing FD's
+ 'CloseOnCall' => 1,
+
+ # setup our data handlers
+ 'StdoutEvent' => 'Got_STDOUT',
+ 'StderrEvent' => 'Got_STDERR',
+
+ # the error handler
+ 'ErrorEvent' => 'Got_ERROR',
+ 'CloseEvent' => 'Got_CLOSED',
+
+ # set our filters
+ 'StderrFilter' => POE::Filter::Line->new(),
+ 'StdoutFilter' => POE::Filter::Line->new(),
+ );
+ if ( ! defined $_[HEAP]->{'WHEEL'} ) {
+ die 'Unable to create a new wheel!';
+ } else {
+ # smart CHLD handling
+ if ( $_[KERNEL]->can( "sig_child" ) ) {
+ $_[KERNEL]->sig_child( $_[HEAP]->{'WHEEL'}->PID => 'Got_CHLD' );
+ } else {
+ $_[KERNEL]->sig( 'CHLD', 'Got_CHLD' );
+ }
+ }
+
+ # setup our data we received from the subprocess
+ $_[HEAP]->{'current_data'} = '';
+
+ # Okay, we timeout this test after some time for sanity
+ $_[HEAP]->{'test_timedout'} = 0;
+ if ( $_[HEAP]->{'lite_tests'} ) {
+ # on my core2duo 1.2ghz laptop, running Gtk+LITE+assert+noxsqueue takes approx 45s
+ $_[HEAP]->{'TIMER'} = $_[KERNEL]->delay_set( 'test_timedout' => 60 * 2 );
+ } else {
+ # on my core2duo 1.2ghz laptop, running Gtk+HEAVY+assert+noxsqueue takes all day long :(
+ $_[HEAP]->{'TIMER'} = $_[KERNEL]->delay_set( 'test_timedout' => 60 * 15 );
+ }
+
+ return;
+}
+
+# Got a CHLD event!
+sub Got_CHLD : State {
+ $_[KERNEL]->sig_handled();
+ return;
+}
+
+# Handles child STDERR output
+sub Got_STDERR : State {
+ my $input = $_[ARG0];
+
+ # save it!
+ $_[HEAP]->{'current_data'} .= '!STDERR: ' . $input . "\n";
+ return;
+}
+
+# Handles child STDOUT output
+sub Got_STDOUT : State {
+ my $input = $_[ARG0];
+
+ # save it!
+ $_[HEAP]->{'current_data'} .= $input . "\n";
+ return;
+}
+
+# Handles child error
+sub Got_ERROR : State {
+ # Copied from POE::Wheel::Run manpage
+ my ( $operation, $errnum, $errstr ) = @_[ ARG0 .. ARG2 ];
+
+ # ignore exit 0 errors
+ if ( $errnum != 0 ) {
+ warn "Wheel::Run got an $operation error $errnum: $errstr\n";
+ }
+
+ return;
+}
+
+# Handles child DIE'ing
+sub Got_CLOSED : State {
+ # Get rid of the wheel
+ undef $_[HEAP]->{'WHEEL'};
+
+ # get rid of the delay
+ $_[KERNEL]->alarm_remove( $_[HEAP]->{'TIMER'} );
+ undef $_[HEAP]->{'TIMER'};
+
+ # wrap up this test
+ $_[KERNEL]->yield( 'wrapup_test' );
+ return;
+}
+
+# a test timed out, unfortunately!
+sub test_timedout : State {
+ # tell the wheel to kill itself
+ $_[HEAP]->{'WHEEL'}->kill( 9 );
+ undef $_[HEAP]->{'WHEEL'};
+
+ if ( ! $_[HEAP]->{'quiet_mode'} ) {
+ print "[BENCHMARKER] Test TimedOut!\n";
+ }
+
+ $_[HEAP]->{'test_timedout'} = 1;
+
+ # wrap up this test
+ $_[KERNEL]->yield( 'wrapup_test' );
+ return;
+}
+
+# finalizes a test
+sub wrapup_test : State {
+ # we're done with this benchmark!
+ $_[HEAP]->{'current_endtime'} = time();
+ $_[HEAP]->{'current_endtimes'} = [ times() ];
+
+ # store the data
+ my $file = 'POE-' . $_[HEAP]->{'current_version'} .
+ '-' . $_[HEAP]->{'current_loop'} .
+ ( $_[HEAP]->{'current_assertions'} ? '-assert' : '-noassert' ) .
+ ( $_[HEAP]->{'current_xsqueue'} ? '-xsqueue' : '-noxsqueue' );
+
+ open( RESULT, '>', "results/$file" ) or die $!;
+ print RESULT "STARTTIME: " . $_[HEAP]->{'current_starttime'} . " -> TIMES " . join( " ", @{ $_[HEAP]->{'current_starttimes'} } ) . "\n";
+ print RESULT "$file\n\n";
+ print RESULT $_[HEAP]->{'current_data'} . "\n";
+ if ( $_[HEAP]->{'test_timedout'} ) {
+ print RESULT "\nTEST TERMINATED DUE TO TIMEOUT\n";
+ }
+ print RESULT "ENDTIME: " . $_[HEAP]->{'current_endtime'} . " -> TIMES " . join( " ", @{ $_[HEAP]->{'current_endtimes'} } ) . "\n";
+ close( RESULT ) or die $!;
+
+ # process the next test
+ $_[KERNEL]->yield( 'bench_xsqueue' );
+ return;
+}
+
+1;
+__END__
+=head1 NAME
+
+POE::Devel::Benchmarker - Benchmarking POE's performance ( acts more like a smoker )
+
+=head1 SYNOPSIS
+
+ perl -MPOE::Devel::Benchmarker -e 'benchmark()'
+
+=head1 ABSTRACT
+
+This package of tools is designed to benchmark POE's performace across different
+configurations. The current "tests" are:
+
+=over
+=item posts
+=item calls
+=item alarm_adds
+=item session creation
+=item session destruction
+=item select_read toggles
+=item select_write toggles
+=item POE startup time
+=back
+
+=head1 DESCRIPTION
+
+This module is poorly documented now. Please give me some time to properly document it over time :)
+
+=head2 INSTALLATION
+
+Here's a simple outline to get you up to speed quickly. ( and smoking! )
+
+=over
+=item Install CPAN package + dependencies
+
+Download+install the POE::Devel::Benchmarker package from CPAN
+
+ apoc@apoc-x300:~$ cpanp -i POE::Devel::Benchmarker
+
+=item Setup initial directories
+
+Go anywhere, and create the "parent" directory where you'll be storing test results + stuff. For this example,
+I have chosen to use ~/poe-benchmarker:
+
+ apoc@apoc-x300:~$ mkdir poe-benchmarker
+ apoc@apoc-x300:~$ cd poe-benchmarker
+ apoc@apoc-x300:~/poe-benchmarker$ mkdir poedists
+ apoc@apoc-x300:~/poe-benchmarker$ cd poedists/
+ apoc@apoc-x300:~/poe-benchmarker/poedists$ perl -MPOE::Devel::Benchmarker::GetPOEdists -e 'getPOEdists( 1 )'
+
+ ( go get a coffee while it downloads if you're on a slow link, ha! )
+
+ apoc@apoc-x300:~/poe-benchmarker/poedists$ cd..
+ apoc@apoc-x300:~/poe-benchmarker$ mkdir results
+
+=item Let 'er rip!
+
+At this point you can start running the benchmark!
+
+NOTE: the Benchmarker expects everything to be in the "local" directory!
+
+ apoc@apoc-x300:~$ cd poe-benchmarker
+ apoc@apoc-x300:~/poe-benchmarker$ perl -MPOE::Devel::Benchmarker -e 'benchmark()'
+
+=back
+
+=head2 ANALYZING RESULTS
+
+This part of the documentation is woefully incomplete. Please look at the L<POE::Devel::Benchmarker::Analyzer> module.
+
+=head2 SUBROUTINES
+
+This module exposes only one subroutine, the benchmark() one. You can pass a hashref to it to set various options. Here is
+a list of the valid options:
+
+=over
+=item litetests => boolean
+
+This enables the "lite" tests which will not take up too much time.
+
+default: false
+
+=item quiet => boolean
+
+This enables quiet mode which will not print anything to the console except for errors.
+
+default: false
+
+=back
+
+=head2 EXPORT
+
+Automatically exports the benchmark() subroutine.
+
+=head1 TODO
+
+=over
+=item Perl version smoking
+
+We should be able to run the benchmark over different Perl versions. This would require some fiddling with our
+layout + logic. It's not that urgent because the workaround is to simply execute the smoke suite under a different
+perl binary. It's smart enough to use $^X to be consistent across tests :)
+
+=item Select the EV backend
+
+<Khisanth> and if you are benchmarking, try it with POE using EV with EV using Glib? :P
+<Apocalypse> I'm not sure how to configure the EV "backend" yet
+<Apocalypse> too much docs for me to read hah
+<Khisanth> Apocalypse: use EV::Glib; use Glib; use POE; :)
+
+=item Disable POE::XS::Queue::Array tests if not found
+
+Currently we blindly move on and test with/without this. We should be smarter and not waste one extra test per iteration
+if it isn't installed!
+
+=item Be more smarter in smoking timeouts
+
+Currently we depend on the lite_tests option and hardcode some values including the timeout. If your machine is incredibly
+slow, there's a chance that it could timeout unnecessarily. Please look at the outputs and check to see if there are unusual
+failures, and inform me.
+
+=back
+
+=head1 SEE ALSO
+
+L<POE>
+
+=head1 AUTHOR
+
+Apocalypse E<lt>apocal@cpan.orgE<gt>
+
+BIG THANKS goes to Rocco Caputo E<lt>rcaputo@cpan.orgE<gt> for the first benchmarks!
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright 2008 by Apocalypse
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
diff --git a/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm b/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm
new file mode 100644
index 0000000..fe8803a
--- /dev/null
+++ b/lib/POE/Devel/Benchmarker/GetInstalledLoops.pm
@@ -0,0 +1,200 @@
+# Declare our package
+package POE::Devel::Benchmarker::GetInstalledLoops;
+use strict; use warnings;
+
+# Initialize our version
+use vars qw( $VERSION );
+$VERSION = '0.01';
+
+# auto-export the only sub we have
+BEGIN {
+ require Exporter;
+ use vars qw( @ISA @EXPORT );
+ @ISA = qw(Exporter);
+ @EXPORT = qw( getPOEloops );
+}
+
+# Import what we need from the POE namespace
+use POE qw( Session Filter::Line Wheel::Run );
+use base 'POE::Session::AttributeBased';
+
+# analyzes the installed perl directory for available loops
+sub getPOEloops {
+ my $quiet_mode = shift;
+
+ # create our session!
+ POE::Session->create(
+ POE::Devel::Benchmarker::GetInstalledLoops->inline_states(),
+ 'heap' => {
+ 'quiet_mode' => $quiet_mode,
+ },
+ );
+}
+
+# Starts up our session
+sub _start : State {
+ # set our alias
+ $_[KERNEL]->alias_set( 'Benchmarker::GetInstalledLoops' );
+
+ # load our known list of loops
+ # known impossible loops:
+ # XS::EPoll ( must be POE > 1.003 and weird way of loading )
+ # XS::Poll ( must be POE > 1.003 and weird way of loading )
+ $_[HEAP]->{'loops'} = [ qw( Event_Lib EV Glib Prima Gtk Wx Kqueue Tk Select IO_Poll ) ];
+
+ # First of all, we need to find out what loop libraries are installed
+ $_[HEAP]->{'found_loops'} = [];
+ $_[KERNEL]->yield( 'find_loops' );
+
+ return;
+}
+
+sub _stop : State {
+ # tell the wheel to kill itself
+ if ( defined $_[HEAP]->{'WHEEL'} ) {
+ $_[HEAP]->{'WHEEL'}->kill( 9 );
+ undef $_[HEAP]->{'WHEEL'};
+ }
+
+ return;
+}
+
+# loops over the "known" loops and sees if they are installed
+sub find_loops : State {
+ # get the loop to test
+ $_[HEAP]->{'current_loop'} = shift @{ $_[HEAP]->{'loops'} };
+
+ # do we have something to test?
+ if ( ! defined $_[HEAP]->{'current_loop'} ) {
+ # we're done!
+ $_[KERNEL]->alias_remove( 'Benchmarker::GetInstalledLoops' );
+ $_[KERNEL]->post( 'Benchmarker', 'found_loops', $_[HEAP]->{'found_loops'} );
+ return;
+ } else {
+ if ( ! $_[HEAP]->{'quiet_mode'} ) {
+ print "[LOOPSEARCH] Trying to find if POE::Loop::" . $_[HEAP]->{'current_loop'} . " is installed...\n";
+ }
+
+ # set the flag
+ $_[HEAP]->{'test_failure'} = 0;
+ }
+
+ # Okay, create the wheel::run to handle this
+ $_[HEAP]->{'WHEEL'} = POE::Wheel::Run->new(
+ 'Program' => $^X,
+ 'ProgramArgs' => [ '-MPOE',
+ '-MPOE::Loop::' . $_[HEAP]->{'current_loop'},
+ '-e',
+ '1',
+ ],
+
+ # Kill off existing FD's
+ 'CloseOnCall' => 1,
+
+ # setup our data handlers
+ 'StdoutEvent' => 'Got_STDOUT',
+ 'StderrEvent' => 'Got_STDERR',
+
+ # the error handler
+ 'ErrorEvent' => 'Got_ERROR',
+ 'CloseEvent' => 'Got_CLOSED',
+
+ # set our filters
+ 'StderrFilter' => POE::Filter::Line->new(),
+ 'StdoutFilter' => POE::Filter::Line->new(),
+ );
+ if ( ! defined $_[HEAP]->{'WHEEL'} ) {
+ die '[LOOPSEARCH] Unable to create a new wheel!';
+ } else {
+ # smart CHLD handling
+ if ( $_[KERNEL]->can( "sig_child" ) ) {
+ $_[KERNEL]->sig_child( $_[HEAP]->{'WHEEL'}->PID => 'Got_CHLD' );
+ } else {
+ $_[KERNEL]->sig( 'CHLD', 'Got_CHLD' );
+ }
+ }
+ return;
+}
+
+# Got a CHLD event!
+sub Got_CHLD : State {
+ $_[KERNEL]->sig_handled();
+ return;
+}
+
+# Handles child STDERR output
+sub Got_STDERR : State {
+ my $input = $_[ARG0];
+
+ # since we got an error, must be a failure
+ $_[HEAP]->{'test_failure'} = 1;
+
+ return;
+}
+
+# Handles child STDOUT output
+sub Got_STDOUT : State {
+ my $input = $_[ARG0];
+
+ return;
+}
+
+# Handles child error
+sub Got_ERROR : State {
+ # Copied from POE::Wheel::Run manpage
+ my ( $operation, $errnum, $errstr ) = @_[ ARG0 .. ARG2 ];
+
+ # ignore exit 0 errors
+ if ( $errnum != 0 ) {
+ warn "Wheel::Run got an $operation error $errnum: $errstr\n";
+ }
+
+ return;
+}
+
+# Handles child DIE'ing
+sub Got_CLOSED : State {
+ # Get rid of the wheel
+ undef $_[HEAP]->{'WHEEL'};
+
+ # Did we pass this test or not?
+ if ( ! $_[HEAP]->{'test_failure'} ) {
+ push( @{ $_[HEAP]->{'found_loops'} }, $_[HEAP]->{'current_loop'} );
+ }
+
+ # move on to the next loop
+ $_[KERNEL]->yield( 'find_loops' );
+ return;
+}
+
+1;
+__END__
+=head1 NAME
+
+POE::Devel::Benchmarker::GetInstalledLoops - Automatically detects the installed POE loops
+
+=head1 ABSTRACT
+
+This package implements the guts of searching for POE loops via fork/exec.
+
+=head2 EXPORT
+
+Automatically exports the getPOEloops() sub
+
+=head1 SEE ALSO
+
+L<POE::Devel::Benchmarker>
+
+=head1 AUTHOR
+
+Apocalypse E<lt>apocal@cpan.orgE<gt>
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright 2008 by Apocalypse
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
+
diff --git a/lib/POE/Devel/Benchmarker/GetPOEdists.pm b/lib/POE/Devel/Benchmarker/GetPOEdists.pm
new file mode 100644
index 0000000..db5d4a4
--- /dev/null
+++ b/lib/POE/Devel/Benchmarker/GetPOEdists.pm
@@ -0,0 +1,126 @@
+# Declare our package
+package POE::Devel::Benchmarker::GetPOEdists;
+use strict; use warnings;
+
+# Initialize our version
+use vars qw( $VERSION );
+$VERSION = '0.01';
+
+# auto-export the only sub we have
+require Exporter;
+use vars qw( @ISA @EXPORT );
+@ISA = qw(Exporter);
+@EXPORT = qw( getPOEdists );
+
+# import the helper modules
+use LWP::UserAgent;
+use HTML::LinkExtor;
+use URI::URL;
+use Archive::Tar;
+
+# actually retrieves the dists!
+sub getPOEdists {
+ # should we debug?
+ my $debug = shift;
+
+ # set the default URL
+ my $url = "http://backpan.cpan.org/authors/id/R/RC/RCAPUTO/";
+
+ # create our objects
+ my $ua = LWP::UserAgent->new;
+ my $p = HTML::LinkExtor->new;
+ my $tar = Archive::Tar->new;
+
+ # Request document and parse it as it arrives
+ print "Getting $url via LWP\n" if $debug;
+ my $res = $ua->request( HTTP::Request->new( GET => $url ),
+ sub { $p->parse( $_[0] ) },
+ );
+
+ # did we successfully download?
+ if ( $res->is_error ) {
+ die "unable to download directory index on BACKPAN: " . $res->status_line;
+ }
+
+ # Download every one!
+ foreach my $link ( $p->links ) {
+ # skip IMG stuff
+ if ( $link->[0] eq 'a' and $link->[1] eq 'href' ) {
+ # get the actual POE dists!
+ if ( $link->[2] =~ /^POE\-\d/ and $link->[2] =~ /\.tar\.gz$/ ) {
+ # download the tarball!
+ print "Mirroring $link->[2] via LWP\n" if $debug;
+ my $mirror_result = $ua->mirror( $url . $link->[2], $link->[2] );
+ if ( $mirror_result->is_error ) {
+ warn "unable to mirror $link->[2]: " . $mirror_result->status_line;
+ next;
+ }
+
+ # did we already untar this one?
+ my $dir = $link->[2];
+ $dir =~ s/\.tar\.gz$//;
+ if ( ! -d $dir ) {
+ # extract it!
+ print "Extracting $link->[2] via Tar\n" if $debug;
+ my $files = $tar->read( $link->[2], undef, { 'extract' => 'true' } );
+ if ( $files == 0 ) {
+ warn "unable to extract $link->[2]";
+ }
+ }
+ }
+ }
+ }
+
+ return;
+}
+
+1;
+__END__
+=head1 NAME
+
+POE::Devel::Benchmarker::GetPOEdists - Automatically download all POE tarballs
+
+=head1 SYNOPSIS
+
+ perl -MPOE::Devel::Benchmarker::GetPOEdists -e 'getPOEdists()'
+
+=head1 ABSTRACT
+
+This package automatically downloads all the POE tarballs from BACKPAN.
+
+=head1 DESCRIPTION
+
+This uses LWP + HTML::LinkExtor to retrieve POE tarballs from BACKPAN.
+
+The tarballs are automatically downloaded to the current directory. Then, we use Archive::Tar to extract them all!
+
+NOTE: we use LWP's useful mirror() sub which doesn't re-download files if they already exist!
+
+=head2 getPOEdists
+
+Normally you should pass nothing to this sub. However, if you want to debug the downloads+extractions you should pass
+a true value as the first argument.
+
+ perl -MPOE::Devel::Benchmarker::GetPOEdists -e 'getPOEdists( 1 )'
+
+=head2 EXPORT
+
+Automatically exports the getPOEdists() sub
+
+=head1 SEE ALSO
+
+L<POE::Devel::Benchmarker>
+
+=head1 AUTHOR
+
+Apocalypse E<lt>apocal@cpan.orgE<gt>
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright 2008 by Apocalypse
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
+
diff --git a/lib/POE/Devel/Benchmarker/SubProcess.pm b/lib/POE/Devel/Benchmarker/SubProcess.pm
new file mode 100644
index 0000000..e652ec1
--- /dev/null
+++ b/lib/POE/Devel/Benchmarker/SubProcess.pm
@@ -0,0 +1,654 @@
+# Declare our package
+package POE::Devel::Benchmarker::SubProcess;
+use strict; use warnings;
+
+# Initialize our version
+use vars qw( $VERSION );
+$VERSION = '0.01';
+
+# Import Time::HiRes's time()
+use Time::HiRes qw( time );
+
+# FIXME UGLY HACK here
+BEGIN {
+ # should we enable assertions?
+ if ( defined $ARGV[2] and $ARGV[2] ) {
+ eval "sub POE::Kernel::ASSERT_DEFAULT () { 1 }";
+ eval "sub POE::Session::ASSERT_STATES () { 1 }";
+ }
+
+ # should we "hide" XS::Queue::Array?
+ if ( defined $ARGV[4] and $ARGV[4] ) {
+ eval "use Devel::Hide qw( POE/XS/Queue/Array.pm )";
+ }
+}
+
+# load POE
+use POE;
+
+# load our utility stuff
+use POE::Devel::Benchmarker::Utils;
+
+# autoflush our STDOUT for sanity
+use FileHandle;
+autoflush STDOUT 1;
+
+# init our global variables ( bad, haha )
+my( $version, $eventloop, $asserts, $lite_tests, $pocosession );
+my( $post_limit, $alarm_limit, $alarm_add_limit, $session_limit, $select_limit, $through_limit, $call_limit, $start_limit );
+
+# the main routine which will load everything + start
+sub benchmark {
+ # process the version
+ process_version();
+
+ # process the eventloop
+ process_eventloop();
+
+ # process the assertions
+ process_assertions();
+
+ # process the test mode
+ process_testmode();
+
+ # process the XS::Queue hiding
+ process_xsqueue();
+
+ # actually import POE!
+ process_POE();
+
+ # actually run the benchmarks!
+ run_benchmarks();
+
+ # all done!
+ return;
+}
+
+sub process_version {
+ # Get the desired POE version
+ $version = $ARGV[0];
+
+ # Decide what to do
+ if ( ! defined $version ) {
+ die "Please supply a version to test!";
+ } elsif ( ! -d 'poedists/POE-' . $version ) {
+ die "That specified version does not exist!";
+ } else {
+ # we're happy...
+ }
+
+ return;
+}
+
+sub process_eventloop {
+ # Get the desired mode
+ $eventloop = $ARGV[1];
+
+ # print out the loop info
+ if ( ! defined $eventloop ) {
+ die "Please supply an event loop!";
+ } else {
+ my $v = loop2realversion( $eventloop ) || 'UNKNOWN';
+ print "Using loop: $eventloop-$v\n";
+ }
+
+ return;
+}
+
+sub process_assertions {
+ # Get the desired assert mode
+ $asserts = $ARGV[2];
+
+ if ( defined $asserts and $asserts ) {
+ print "Using FULL Assertions!\n";
+ } else {
+ print "Using NO Assertions!\n";
+ }
+
+ return;
+}
+
+sub process_testmode {
+ # get the desired test mode
+ $lite_tests = $ARGV[3];
+ if ( defined $lite_tests and $lite_tests ) {
+ print "Using the LITE tests\n";
+
+ $post_limit = 10_000;
+ $alarm_limit = 10_000;
+ $alarm_add_limit = 10_000;
+ $session_limit = 500;
+ $select_limit = 10_000;
+ $through_limit = 10_000;
+ $call_limit = 10_000;
+ $start_limit = 10;
+ } else {
+ print "Using the HEAVY tests\n";
+
+ $post_limit = 100_000;
+ $alarm_limit = 100_000;
+ $alarm_add_limit = 100_000;
+ $session_limit = 5_000;
+ $select_limit = 100_000;
+ $through_limit = 100_000;
+ $call_limit = 100_000;
+ $start_limit = 100;
+ }
+
+ return;
+}
+
+sub process_xsqueue {
+ # should we "hide" XS::Queue::Array?
+ if ( defined $ARGV[4] and $ARGV[4] ) {
+ print "DISABLING POE::XS::Queue::Array\n";
+ } else {
+ print "LETTING POE find POE::XS::Queue::Array\n";
+ }
+
+ return;
+}
+
+sub process_POE {
+ # Print the POE info
+ print "Using POE-" . $POE::VERSION . "\n";
+
+ # Actually print what loop POE is using
+ foreach my $m ( keys %INC ) {
+ if ( $m =~ /^POE\/(?:Loop|XS|Queue)/ ) {
+ # try to be smart and get version?
+ my $module = $m;
+ $module =~ s|/|::|g;
+ $module =~ s/\.pm$//g;
+ print "POE is using: $module ";
+ if ( defined $module->VERSION ) {
+ print "v" . $module->VERSION . "\n";
+ } else {
+ print "vUNKNOWN\n";
+ }
+ }
+ }
+
+ return;
+}
+
+sub run_benchmarks {
+ # run the startup test before we actually run POE
+ bench_startup();
+
+ # load the POE session + do the tests there
+ bench_poe();
+
+ # dump some misc info
+ dump_memory();
+ dump_times();
+ dump_perlinfo();
+ dump_sysinfo();
+
+ # all done!
+ return;
+}
+
+sub bench_startup {
+ # Add the eventloop?
+ my $looploader = poeloop2load( $eventloop );
+
+ my @start_times = times();
+ my $start = time();
+ for (my $i = 0; $i < $start_limit; $i++) {
+ # FIXME should we add assertions?
+
+ # finally, fire it up!
+ CORE::system(
+ $^X,
+ '-Ipoedists/POE-' . $version,
+ '-Ipoedists/POE-' . $version . '/lib',
+ ( defined $looploader ? "-M$looploader" : () ),
+ '-MPOE',
+ '-e',
+ 1,
+ );
+ }
+ my @end_times = times();
+ my $elapsed = time() - $start;
+ printf( "\n\n% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $start_limit, 'startups', $elapsed, $start_limit/$elapsed );
+ print "startup times: @start_times @end_times\n";
+
+ return;
+}
+
+sub bench_poe {
+ # figure out POE::Session->create or POE::Session->new or what?
+ $pocosession = POE::Session->can( 'create' );
+ if ( defined $pocosession ) {
+ $pocosession = 'create';
+ } else {
+ $pocosession = POE::Session->can( 'spawn' );
+ if ( defined $pocosession ) {
+ $pocosession = 'spawn';
+ } else {
+ $pocosession = 'new';
+ }
+ }
+
+ # create the master sesssion + run POE!
+ POE::Session->$pocosession(
+ 'inline_states' => {
+ # basic POE states
+ '_start' => \&poe__start,
+ '_default' => \&poe__default,
+ '_stop' => \&poe__stop,
+ 'null' => \&poe_null,
+
+ # our test states
+ 'posts' => \&poe_posts,
+ 'posts_start' => \&poe_posts_start,
+ 'posts_end' => \&poe_posts_end,
+ 'alarms' => \&poe_alarms,
+ 'manyalarms' => \&poe_manyalarms,
+ 'sessions' => \&poe_sessions,
+ 'sessions_end' => \&poe_sessions_end,
+ 'stdin_read' => \&poe_stdin_read,
+ 'stdin_write' => \&poe_stdin_write,
+ 'myfh_read' => \&poe_myfh_read,
+ 'myfh_write' => \&poe_myfh_write,
+ 'calls' => \&poe_calls,
+ 'eventsquirt' => \&poe_eventsquirt,
+ 'eventsquirt_done' => \&poe_eventsquirt_done,
+ },
+ );
+
+ # start the kernel!
+ POE::Kernel->run();
+
+ return;
+}
+
+# inits our session
+sub poe__start {
+ # fire off the first test!
+ $_[KERNEL]->yield( 'posts' );
+
+ return;
+}
+
+sub poe__stop {
+}
+
+sub poe__default {
+ return 0;
+}
+
+# a state that does nothing
+sub poe_null {
+ return 1;
+}
+
+# How many posts per second? Post a bunch of events, keeping track of the time it takes.
+sub poe_posts {
+ $_[KERNEL]->yield( 'posts_start' );
+ my $start = time();
+ my @start_times = times();
+ for (my $i = 0; $i < $post_limit; $i++) {
+ $_[KERNEL]->yield( 'null' );
+ }
+ my @end_times = times();
+ my $elapsed = time() - $start;
+ printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $post_limit, 'posts', $elapsed, $post_limit/$elapsed );
+ print "posts times: @start_times @end_times\n";
+ $_[KERNEL]->yield( 'posts_end' );
+
+ return;
+}
+
+sub poe_posts_start {
+ $_[HEAP]->{start} = time();
+ $_[HEAP]->{starttimes} = [ times() ];
+
+ return;
+}
+
+sub poe_posts_end {
+ my $elapsed = time() - $_[HEAP]->{start};
+ my @end_times = times();
+ printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $post_limit, 'dispatches', $elapsed, $post_limit/$elapsed );
+ print "dispatches times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
+ $_[KERNEL]->yield( 'alarms' );
+
+ return;
+}
+
+# How many alarms per second? Set a bunch of alarms and find out.
+sub poe_alarms {
+ my $start = time();
+ my @start_times = times();
+ for (my $i = 0; $i < $alarm_limit; $i++) {
+ $_[KERNEL]->alarm( whee => rand(1_000_000) );
+ }
+ my $elapsed = time() - $start;
+ my @end_times = times();
+ printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $alarm_limit, 'alarms', $elapsed, $alarm_limit/$elapsed );
+ print "alarms times: @start_times @end_times\n";
+ $_[KERNEL]->alarm( 'whee' => undef );
+ $_[KERNEL]->yield( 'manyalarms' );
+
+ return;
+}
+
+# How many repetitive alarms per second? Set a bunch of
+# additional alarms and find out. Also see how quickly they can
+# be cleared.
+sub poe_manyalarms {
+ # can this POE::Kernel support this?
+ if ( $_[KERNEL]->can( 'alarm_add' ) ) {
+ my $start = time();
+ my @start_times = times();
+ for (my $i = 0; $i < $alarm_add_limit; $i++) {
+ $_[KERNEL]->alarm_add( whee => rand(1_000_000) );
+ }
+ my $elapsed = time() - $start;
+ my @end_times = times();
+ printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $alarm_add_limit, 'alarm_adds', $elapsed, $alarm_add_limit/$elapsed );
+ print "alarm_adds times: @start_times @end_times\n";
+
+ $start = time();
+ @start_times = times();
+ $_[KERNEL]->alarm( whee => undef );
+ $elapsed = time() - $start;
+ @end_times = times();
+ printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $alarm_add_limit, 'alarm_clears', $elapsed, $alarm_add_limit/$elapsed );
+ print "alarm_clears times: @start_times @end_times\n";
+ } else {
+ print "this version of POE does not support alarm_add, skipping alarm_adds/alarm_clears tests!\n";
+ }
+
+ $_[KERNEL]->yield( 'sessions' );
+
+ return;
+}
+
+# How many sessions can we create and destroy per second?
+# Create a bunch of sessions, and track that time. Let them
+# self-destruct, and track that as well.
+sub poe_sessions {
+ my $start = time();
+ my @start_times = times();
+ for (my $i = 0; $i < $session_limit; $i++) {
+ POE::Session->$pocosession( 'inline_states' => { _start => sub {}, _stop => sub {}, _default => sub { return 0 } } );
+ }
+ my $elapsed = time() - $start;
+ my @end_times = times();
+ printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $session_limit, 'session creates', $elapsed, $session_limit/$elapsed );
+ print "session create times: @start_times @end_times\n";
+
+ $_[KERNEL]->yield( 'sessions_end' );
+ $_[HEAP]->{start} = time();
+ $_[HEAP]->{starttimes} = [ times() ];
+
+ return;
+}
+
+sub poe_sessions_end {
+ my $elapsed = time() - $_[HEAP]->{start};
+ my @end_times = times();
+ printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $session_limit, 'session destroys', $elapsed, $session_limit/$elapsed );
+ print "session destroys times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
+
+ $_[KERNEL]->yield( 'stdin_read' );
+
+ return;
+}
+
+# How many times can we select/unselect READ a from STDIN filehandle per second?
+sub poe_stdin_read {
+ # stupid, but we have to skip those tests
+ if ( $eventloop eq 'Tk' or $eventloop eq 'Prima' ) {
+ print "SKIPPING STDIN tests on broken loop: $eventloop\n";
+ $_[KERNEL]->yield( 'myfh_read' );
+ return;
+ }
+
+ my $start = time();
+ my @start_times = times();
+ eval {
+ for (my $i = 0; $i < $select_limit; $i++) {
+ $_[KERNEL]->select_read( *STDIN, 'whee' );
+ $_[KERNEL]->select_read( *STDIN );
+ }
+ };
+ if ( $@ ) {
+ print "filehandle select_read on *STDIN FAILED: $@\n";
+ } else {
+ my $elapsed = time() - $start;
+ my @end_times = times();
+ printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $select_limit, 'select_read STDIN', $elapsed, $select_limit/$elapsed );
+ print "select_read STDIN times: @start_times @end_times\n";
+ }
+
+ $_[KERNEL]->yield( 'stdin_write' );
+
+ return;
+}
+
+# How many times can we select/unselect WRITE a from STDIN filehandle per second?
+sub poe_stdin_write {
+ my $start = time();
+ my @start_times = times();
+ eval {
+ for (my $i = 0; $i < $select_limit; $i++) {
+ $_[KERNEL]->select_write( *STDIN, 'whee' );
+ $_[KERNEL]->select_write( *STDIN );
+ }
+ };
+ if ( $@ ) {
+ print "filehandle select_write on *STDIN FAILED: $@\n";
+ } else {
+ my $elapsed = time() - $start;
+ my @end_times = times();
+ printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $select_limit, 'select_write STDIN', $elapsed, $select_limit/$elapsed );
+ print "select_write STDIN times: @start_times @end_times\n";
+ }
+
+ $_[KERNEL]->yield( 'myfh_read' );
+
+ return;
+}
+
+# How many times can we select/unselect READ a real filehandle?
+sub poe_myfh_read {
+ # stupid, but we have to skip those tests
+ if ( $eventloop eq 'Event_Lib' or $eventloop eq 'Tk' or $eventloop eq 'Prima' ) {
+ print "SKIPPING MYFH tests on broken loop: $eventloop\n";
+ $_[KERNEL]->yield( 'calls' );
+ return;
+ }
+
+ open( MYFH, '+>', 'poebench' ) or die $!;
+ my $start = time();
+ my @start_times = times();
+ eval {
+ for (my $i = 0; $i < $select_limit; $i++) {
+ $_[KERNEL]->select_read( *MYFH, 'whee' );
+ $_[KERNEL]->select_read( *MYFH );
+ }
+ };
+ if ( $@ ) {
+ print "filehandle select_read on *MYFH FAILED: $@\n";
+ } else {
+ my $elapsed = time() - $start;
+ my @end_times = times();
+ printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $select_limit, 'select_read MYFH', $elapsed, $select_limit/$elapsed );
+ print "select_read MYFH times: @start_times @end_times\n";
+ }
+
+ close( MYFH ) or die $!;
+ unlink( 'poebench' ) or die $!;
+
+ $_[KERNEL]->yield( 'myfh_write' );
+
+ return;
+}
+
+# How many times can we select/unselect WRITE a real filehandle?
+sub poe_myfh_write {
+ open( MYFH, '+>', 'poebench' ) or die $!;
+ my $start = time();
+ my @start_times = times();
+ eval {
+ for (my $i = 0; $i < $select_limit; $i++) {
+ $_[KERNEL]->select_write( *MYFH, 'whee' );
+ $_[KERNEL]->select_write( *MYFH );
+ }
+ };
+ if ( $@ ) {
+ print "filehandle select_write on *MYFH FAILED: $@\n";
+ } else {
+ my $elapsed = time() - $start;
+ my @end_times = times();
+ printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $select_limit, 'select_write MYFH', $elapsed, $select_limit/$elapsed );
+ print "select_write MYFH times: @start_times @end_times\n";
+ }
+
+ close( MYFH ) or die $!;
+ unlink( 'poebench' ) or die $!;
+
+ $_[KERNEL]->yield( 'calls' );
+
+ return;
+}
+
+# How many times can we call a state?
+sub poe_calls {
+ my $start = time();
+ my @start_times = times();
+ for (my $i = 0; $i < $call_limit; $i++) {
+ $_[KERNEL]->call( $_[SESSION], 'null' );
+ }
+ my $elapsed = time() - $start;
+ my @end_times = times();
+ printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $call_limit, 'calls', $elapsed, $call_limit/$elapsed );
+ print "calls times: @start_times @end_times\n";
+
+ $_[KERNEL]->yield( 'eventsquirt' );
+
+ return;
+}
+
+# How many events can we squirt through POE, one at a time?
+sub poe_eventsquirt {
+ $_[HEAP]->{start} = time();
+ $_[HEAP]->{starttimes} = [ times() ];
+ $_[HEAP]->{yield_count} = $through_limit;
+ $_[KERNEL]->yield( 'eventsquirt_done' );
+
+ return;
+}
+
+sub poe_eventsquirt_done {
+ if (--$_[HEAP]->{yield_count}) {
+ $_[KERNEL]->yield( 'eventsquirt_done' );
+ } else {
+ my $elapsed = time() - $_[HEAP]->{start};
+ my @end_times = times();
+ printf( "% 9d %-20.20s in % 9.3f seconds (% 11.3f per second)\n", $through_limit, 'single_posts', $elapsed, $through_limit/$elapsed );
+ print "single_posts times: " . join( " ", @{ $_[HEAP]->{starttimes} } ) . " @end_times\n";
+ }
+
+ # reached end of tests!
+ return;
+}
+
+# Get the memory footprint
+sub dump_memory {
+ print "\n\nMemory footprint:\n";
+ open( MEMORY, '/proc/self/status' ) or die $!;
+ while ( <MEMORY> ) {
+ print;
+ }
+ close( MEMORY ) or die $!;
+
+ return;
+}
+
+# print the time it took to execute this program
+sub dump_times {
+ my ($wall, $user, $system, $cuser, $csystem) = ( (time-$^T), times() );
+ printf( ( "\n\n--- times ---\n" .
+ "wall : %9.3f\n" .
+ "user : %9.3f cuser: %9.3f\n" .
+ "sys : %9.3f csys : %9.3f\n"
+ ),
+ $wall, $user, $cuser, $system, $csystem,
+ );
+
+ return;
+}
+
+# print the local Perl info
+sub dump_perlinfo {
+ print "\n\nRunning under perl binary: " . $^X . "\n";
+
+ require Config;
+ print Config::myconfig();
+
+ return;
+}
+
+# print the local system information
+sub dump_sysinfo {
+ print "Running under machine: " . `uname -a` . "\n";
+
+ # get cpuinfo
+ print "Running under CPU:\n";
+ open( CPUINFO, '/proc/cpuinfo' ) or die $!;
+ while ( <CPUINFO> ) {
+ print;
+ }
+ close( CPUINFO ) or die $!;
+
+ # get meminfo
+ print "Running under meminfo:\n";
+ open( MEMINFO, '/proc/meminfo' ) or die $!;
+ while ( <MEMINFO> ) {
+ print;
+ }
+ close( MEMINFO ) or die $!;
+
+ return;
+}
+
+1;
+__END__
+=head1 NAME
+
+POE::Devel::Benchmarker::SubProcess - Implements the actual POE benchmarks
+
+=head1 SYNOPSIS
+
+ perl -MPOE::Devel::Benchmarker::SubProcess -e 'benchmark()'
+
+=head1 ABSTRACT
+
+This package is responsible for implementing the guts of the benchmarks, and timing them.
+
+=head2 EXPORT
+
+Nothing.
+
+=head1 SEE ALSO
+
+L<POE::Devel::Benchmarker>
+
+=head1 AUTHOR
+
+Apocalypse E<lt>apocal@cpan.orgE<gt>
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright 2008 by Apocalypse
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
+
diff --git a/lib/POE/Devel/Benchmarker/Subprocess.pm b/lib/POE/Devel/Benchmarker/Subprocess.pm
deleted file mode 100644
index e69de29..0000000
diff --git a/lib/POE/Devel/Benchmarker/Utils.pm b/lib/POE/Devel/Benchmarker/Utils.pm
new file mode 100644
index 0000000..234d1c4
--- /dev/null
+++ b/lib/POE/Devel/Benchmarker/Utils.pm
@@ -0,0 +1,133 @@
+# Declare our package
+package POE::Devel::Benchmarker::Utils;
+use strict; use warnings;
+
+# Initialize our version
+use vars qw( $VERSION );
+$VERSION = '0.01';
+
+# auto-export the only sub we have
+require Exporter;
+use vars qw( @ISA @EXPORT );
+@ISA = qw(Exporter);
+@EXPORT = qw( poeloop2load loop2realversion );
+
+# returns the proper "load" stuff for a specific loop
+sub poeloop2load {
+ my $eventloop = shift;
+
+ # Decide which event loop to use
+ # Event_Lib EV Glib Prima Gtk Wx Kqueue Tk Select IO_Poll
+ if ( $eventloop eq 'Event' ) {
+ return 'Event';
+ } elsif ( $eventloop eq 'IO_Poll' ) {
+ return 'IO::Poll';
+ } elsif ( $eventloop eq 'Event_Lib' ) {
+ return 'Event::Lib';
+ } elsif ( $eventloop eq 'EV' ) {
+ return 'EV';
+ } elsif ( $eventloop eq 'Glib' ) {
+ return 'Glib';
+ } elsif ( $eventloop eq 'Tk' ) {
+ return 'Tk',
+ } elsif ( $eventloop eq 'Gtk' ) {
+ return 'Gtk';
+ } elsif ( $eventloop eq 'Prima' ) {
+ return 'Prima';
+ } elsif ( $eventloop eq 'Wx' ) {
+ return 'Wx';
+ } elsif ( $eventloop eq 'Kqueue' ) {
+ # FIXME dunno what to do here!
+ return;
+ } elsif ( $eventloop eq 'Select' ) {
+ return;
+ } else {
+ die "Unknown event loop!";
+ }
+}
+
+# returns the version of the "real" installed module that the loop uses
+sub loop2realversion {
+ my $eventloop = shift;
+
+ # Decide which event loop to use
+ if ( ! defined $eventloop ) {
+ return;
+ } elsif ( $eventloop eq 'Event' ) {
+ return $Event::VERSION;
+ } elsif ( $eventloop eq 'IO_Poll' ) {
+ return $IO::Poll::VERSION;
+ } elsif ( $eventloop eq 'Event_Lib' ) {
+ return $Event::Lib::VERSION;
+ } elsif ( $eventloop eq 'EV' ) {
+ return $EV::VERSION;
+ } elsif ( $eventloop eq 'Glib' ) {
+ return $Glib::VERSION;
+ } elsif ( $eventloop eq 'Tk' ) {
+ return $Tk::VERSION;
+ } elsif ( $eventloop eq 'Gtk' ) {
+ return $Gtk::VERSION;
+ } elsif ( $eventloop eq 'Prima' ) {
+ return $Prima::VERSION;
+ } elsif ( $eventloop eq 'Wx' ) {
+ return $Wx::VERSION;
+ } elsif ( $eventloop eq 'Kqueue' ) {
+ # FIXME how do I do this?
+ return;
+ } elsif ( $eventloop eq 'Select' ) {
+ return 'BUILTIN';
+ } else {
+ die "Unknown event loop!";
+ }
+}
+
+1;
+__END__
+=head1 NAME
+
+POE::Devel::Benchmarker::Utils - Various utility routines for POE::Devel::Benchmarker
+
+=head1 SYNOPSIS
+
+ perl -MPOE::Devel::Benchmarker::Utils -e 'print poeloop2load( "IO_Poll" )'
+
+=head1 ABSTRACT
+
+This package contains the utility routines and constants that POE::Devel::Benchmarker needs.
+
+=head2 EXPORT
+
+Automatically exports those subs:
+
+=over
+=item poeloop2load()
+
+Returns the "parent" class to load for a specific loop. An example is:
+
+ $real = poeloop2load( 'IO_Poll' ); # $real now contains "IO::Poll"
+
+=item loop2realversion()
+
+Returns the version of the "parent" class for a specific loop. An example is:
+
+ $ver = loop2realversion( 'IO_Poll' ); # $ver now contains $IO::Poll::VERSION
+
+=back
+
+=head1 SEE ALSO
+
+L<POE::Devel::Benchmarker>
+
+=head1 AUTHOR
+
+Apocalypse E<lt>apocal@cpan.orgE<gt>
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright 2008 by Apocalypse
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
+
diff --git a/t/1_load.t b/t/1_load.t
index bd98894..38d0393 100755
--- a/t/1_load.t
+++ b/t/1_load.t
@@ -1,10 +1,13 @@
#!/usr/bin/perl
# Import the stuff
# XXX no idea why this is broken for this particular dist!
#use Test::UseAllModules;
#BEGIN { all_uses_ok(); }
-use Test::More tests => 2;
+use Test::More tests => 5;
use_ok( 'POE::Devel::Benchmarker' );
use_ok( 'POE::Devel::Benchmarker::SubProcess' );
+use_ok( 'POE::Devel::Benchmarker::GetInstalledLoops' );
+use_ok( 'POE::Devel::Benchmarker::GetPOEdists' );
+use_ok( 'POE::Devel::Benchmarker::Utils' );
|
apocalypse/perl-poe-benchmarker
|
884eaff1fc4b1ac5a4e79494f305b3a03bf43381
|
initial import
|
diff --git a/.project b/.project
new file mode 100644
index 0000000..75eb52d
--- /dev/null
+++ b/.project
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>perl-poe-simpledbi</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.epic.perleditor.perlbuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.epic.perleditor.perlnature</nature>
+ </natures>
+</projectDescription>
+
diff --git a/Build.PL b/Build.PL
new file mode 100755
index 0000000..6a02c4a
--- /dev/null
+++ b/Build.PL
@@ -0,0 +1,61 @@
+# Build.PL
+use Module::Build;
+
+my $build = Module::Build->new(
+ # look up Module::Build::API for the info!
+ 'dynamic_config' => 0,
+ 'module_name' => 'POE::Devel::Benchmarker',
+ 'license' => 'perl',
+
+ 'dist_abstract' => 'Benchmarking POE\'s performance ( acts more like a smoker )',
+ 'dist_author' => 'Apocalypse <APOCAL@cpan.org>',
+
+ 'create_packlist' => 1,
+ 'create_makefile_pl' => 'traditional',
+ 'create_readme' => 1,
+
+ 'test_files' => 't/*.t',
+
+ 'add_to_cleanup' => [ 'META.yml', 'Makefile.PL', 'README' ], # automatically generated
+
+ 'requires' => {
+ # POE Stuff
+ 'POE' => 0,
+
+ # FIXME POE stuff that Test::Dependencies needs to see
+ 'POE::Session' => 0,
+ 'POE::Filter::Line' => 0,
+ 'POE::Wheel::Run' => 0,
+
+ # DB access
+ 'DBI' => '1.30',
+ },
+
+ 'recommends' => {
+ # Test stuff
+ 'Test::More' => 0,
+ },
+
+ # FIXME wishlist...
+# 'test_requires' => {
+# # Test stuff
+# 'Test::Compile' => 0,
+# 'Test::Perl::Critic' => 0,
+# 'Test::Dependencies' => 0,
+# 'Test::Distribution' => 0,
+# 'Test::Fixme' => 0,
+# 'Test::HasVersion' => 0,
+# 'Test::Kwalitee' => 0,
+# 'Test::CheckManifest' => 0,
+# 'Test::MinimumVersion' => 0,
+# 'Test::Pod::Coverage' => 0,
+# 'Test::Spelling' => 0,
+# 'Test::Pod' => 0,
+# 'Test::Prereq' => 0,
+# 'Test::Strict' => 0,
+# 'Test::UseAllModules' => 0,
+# },
+);
+
+# all done!
+$build->create_build_script;
diff --git a/Changes b/Changes
new file mode 100755
index 0000000..6eec582
--- /dev/null
+++ b/Changes
@@ -0,0 +1,172 @@
+Revision history for Perl extension POE::Component::SimpleDBI.
+
+* 1.23
+
+ Switched to Build.PL for the build system
+ Fixed the stupid test dependencies, thanks BiNGOs!
+ Added the new EXPERIMENTAL 'ATOMIC' support, please let me know if it's broken on your setup!
+ Added some more author tests
+ Added AUTO_COMMIT argument to CONNECT to control the DBI variable ( defaults to true )
+
+* 1.22
+
+ Kwalitee-related fixes
+
+* 1.21
+
+ silence warnings when used with DBD::SQLite - thanks to Sjors Gielen for tracking this down!
+
+* 1.20
+
+ Added the INSERT_ID to control $dbh->last_insert_id usage
+
+* 1.19
+
+ Added the PREPARE_CACHED argument to control caching
+
+* 1.18
+
+ Ignore the DBI error for last_insert_id and default to undef
+
+* 1.17
+
+ Added "INSERTID" to the result of DO
+
+* 1.16
+
+ Noticed a glaring documentation bug
+ - SINGLE queries return mixedCaps rows ( not lowercase! )
+ - MULTIPLE queries return lowercase rows
+
+ This makes me *VERY* tempted to fix SINGLE to return lowercase, is this a good idea? Let me know!
+
+ Fixed SimpleDBI failure on Win32 - thanks RT #23851
+
+* 1.15
+
+ Thanks to Fred Castellano, who stumbled on a DEADLOCK bug, fixed!
+ Added sanity tests to CONNECT/DISCONNECT
+
+* 1.14
+
+ learned about the difference between ref $self and ref( $self )
+ Kwalitee-related fixes
+
+* 1.13
+
+ Finally use a Changes file - thanks RT #18981
+ Fixed a bug in SINGLE if returned_rows = 0 it will not return undef, but give us blank rows!
+ Documentation tweaks
+
+* 1.12
+
+ In the SubProcess, added a binmode() to STDIN and STDERR, for the windows attempt
+ Added code to make SimpleDBI work in Win32 boxes, thanks to the recent Wheel::Run patches!
+ Documentation tweaks as usual
+
+* 1.11
+
+ Hannes had a problem:
+ His IRC bot logs events to a database, and sometimes there is no events to log after
+ hours and hours of inactivity ( must be a boring channel haha ), the db server disconnected!
+
+ The solution was to do a $dbh->ping() before each query, if your DBI driver does it inefficiently, go yell at them!
+ In the event that a reconnect is not possible, an error will be sent to the CONNECT event handler, look at the updated pod.
+
+* 1.10
+
+ Fixed a bug in the DO routine, thanks to Hannes!
+
+* 1.09
+
+ Removed the abstract LIMIT 1 to the SINGLE query
+
+ Removed the silly 5.8.x requirement in Makefile.PL
+
+ Made the SubProcess use less memory by exec()ing itself
+
+ Added the new CONNECT/DISCONNECT commands
+
+ Removed the db connection information from new()
+
+ Minor tweaks here and there to not stupidly call() the queue checker when there is nothing to check :)
+
+ Added the sysreaderr debugging output
+
+ More intelligent SQL/PLACEHOLDERS/BAGGAGE handling
+
+ Made the command arguments more stricter, it will only accept valid arguments, instead of just extracting what it needs
+
+ Made sure all return data have ID/EVENT/SESSION/ACTION in them for easy debugging
+
+ Added the SESSION parameter to all commands for easy redirection
+
+ Updated the POD and generally made it better :)
+
+ Added a new command -> Clear_Queue ( clears the queue )
+
+* 1.08
+
+ In the SubProcess, removed the select statement requirement
+
+* 1.07
+
+ In the SubProcess, fixed a silly mistake in DO's execution of placeholders
+
+ Cleaned up a few error messages in the SubProcess
+
+ Peppered the code with *more* DEBUG statements :)
+
+ Replaced a croak() with a die() when it couldn't connect to the database
+
+ Documented the _child events
+
+* 1.06
+
+ Fixed some typos in the POD
+
+ Added the BAGGAGE option
+
+* 1.05
+
+ Fixed some typos in the POD
+
+ Fixed the DEBUG + MAX_RETRIES "Subroutine redefined" foolishness
+
+* 1.04
+
+ Got rid of the EVENT_S and EVENT_E handlers, replaced with a single EVENT handler
+
+ Internal changes to get rid of some stuff -> Send_Query / Send_Wheel
+
+ Added the Delete_Query event -> Deletes an query via ID
+
+ Changed the DO/MULTIPLE/SINGLE/QUOTE events to return an ID ( Only usable if call'ed )
+
+ Made sure that the ACTION key is sent back to the EVENT handler every time
+
+ Added some DEBUG stuff :)
+
+ Added the CHANGES section
+
+ Fixed some typos in the POD
+
+* 1.03
+
+ Increments refcount for querying sessions so they don't go away
+
+ POD formatting
+
+ Consolidated shutdown and shutdown_NOW into one single event
+
+ General formatting in program
+
+ DB connection error handling
+
+ Renamed the result hash: RESULTS to RESULT for better readability
+
+ SubProcess -> added DBI connect failure handling
+
+* 1.02
+
+ Initial release
diff --git a/MANIFEST b/MANIFEST
new file mode 100755
index 0000000..53531db
--- /dev/null
+++ b/MANIFEST
@@ -0,0 +1,31 @@
+Makefile.PL
+Build.PL
+MANIFEST
+MANIFEST.SKIP
+README
+lib/POE/Devel/Benchmarker.pm
+lib/POE/Devel/Benchmarker/SubProcess.pm
+META.yml Module meta-data (added by MakeMaker)
+Changes
+scripts/getdists.pl
+
+t/1_load.t
+
+t/a_critic.t
+t/a_kwalitee.t
+t/a_pod.t
+t/a_pod_spelling.t
+t/a_pod_coverage.t
+t/a_strict.t
+t/a_hasversion.t
+t/a_minimumversion.t
+t/a_manifest.t
+t/a_distribution.t
+t/a_compile.t
+t/a_dependencies.t
+t/a_fixme.t
+t/a_prereq.t
+t/a_prereq_build.t
+t/a_dosnewline.t
+t/a_perlmetrics.t
+t/a_is_prereq_outdated.t
diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP
new file mode 100755
index 0000000..7af46a2
--- /dev/null
+++ b/MANIFEST.SKIP
@@ -0,0 +1,28 @@
+^.includepath
+^.project
+^.settings/
+
+# Avoid version control files.
+\B\.svn\b
+\B\.git\b
+
+# Avoid Makemaker generated and utility files.
+\bMANIFEST\.SKIP
+\bMakefile$
+\bblib/
+\bMakeMaker-\d
+\bpm_to_blib$
+
+# Avoid Module::Build generated and utility files.
+\bBuild$
+\b_build/
+
+# Avoid temp and backup files.
+~$
+\.old$
+\#$
+\b\.#
+\.bak$
+
+# our tarballs
+\.tar\.gz$
diff --git a/lib/POE/Devel/Benchmarker.pm b/lib/POE/Devel/Benchmarker.pm
new file mode 100644
index 0000000..e69de29
diff --git a/lib/POE/Devel/Benchmarker/Subprocess.pm b/lib/POE/Devel/Benchmarker/Subprocess.pm
new file mode 100644
index 0000000..e69de29
diff --git a/t/1_load.t b/t/1_load.t
new file mode 100755
index 0000000..bd98894
--- /dev/null
+++ b/t/1_load.t
@@ -0,0 +1,10 @@
+#!/usr/bin/perl
+
+# Import the stuff
+# XXX no idea why this is broken for this particular dist!
+#use Test::UseAllModules;
+#BEGIN { all_uses_ok(); }
+
+use Test::More tests => 2;
+use_ok( 'POE::Devel::Benchmarker' );
+use_ok( 'POE::Devel::Benchmarker::SubProcess' );
diff --git a/t/a_compile.t b/t/a_compile.t
new file mode 100644
index 0000000..4b1abfc
--- /dev/null
+++ b/t/a_compile.t
@@ -0,0 +1,15 @@
+#!/usr/bin/perl
+
+use Test::More;
+
+# AUTHOR test
+if ( not $ENV{TEST_AUTHOR} ) {
+ plan skip_all => 'Author test. Sent $ENV{TEST_AUTHOR} to a true value to run.';
+} else {
+ eval "use Test::Compile";
+ if ( $@ ) {
+ plan skip_all => 'Test::Compile required for validating the perl files';
+ } else {
+ all_pm_files_ok();
+ }
+}
diff --git a/t/a_critic.t b/t/a_critic.t
new file mode 100644
index 0000000..7e30808
--- /dev/null
+++ b/t/a_critic.t
@@ -0,0 +1,26 @@
+#!/usr/bin/perl
+
+use Test::More;
+
+# AUTHOR test
+if ( not $ENV{TEST_AUTHOR} ) {
+ plan skip_all => 'Author test. Sent $ENV{TEST_AUTHOR} to a true value to run.';
+} else {
+ if ( not $ENV{PERL_TEST_CRITIC} ) {
+ plan skip_all => 'PerlCritic test. Sent $ENV{PERL_TEST_CRITIC} to a true value to run.';
+ } else {
+ # did we get a severity level?
+ if ( length $ENV{PERL_TEST_CRITIC} > 1 ) {
+ eval "use Test::Perl::Critic ( -severity => \"$ENV{PERL_TEST_CRITIC}\" );";
+ } else {
+ eval "use Test::Perl::Critic;";
+ #eval "use Test::Perl::Critic ( -severity => 'stern' );";
+ }
+
+ if ( $@ ) {
+ plan skip_all => 'Test::Perl::Critic required to criticise perl files';
+ } else {
+ all_critic_ok( 'lib/' );
+ }
+ }
+}
diff --git a/t/a_dependencies.t b/t/a_dependencies.t
new file mode 100644
index 0000000..a27f64a
--- /dev/null
+++ b/t/a_dependencies.t
@@ -0,0 +1,15 @@
+#!/usr/bin/perl
+
+use Test::More;
+
+# AUTHOR test
+if ( not $ENV{TEST_AUTHOR} ) {
+ plan skip_all => 'Author test. Sent $ENV{TEST_AUTHOR} to a true value to run.';
+} else {
+ eval "use Test::Dependencies exclude => [ qw/ POE::Devel::Benchmarker Module::Build / ], style => 'light';";
+ if ( $@ ) {
+ plan skip_all => 'Test::Dependencies required to test perl module deps';
+ } else {
+ ok_dependencies();
+ }
+}
diff --git a/t/a_distribution.t b/t/a_distribution.t
new file mode 100755
index 0000000..27f7831
--- /dev/null
+++ b/t/a_distribution.t
@@ -0,0 +1,15 @@
+#!/usr/bin/perl
+
+use Test::More;
+
+# AUTHOR test
+if ( not $ENV{TEST_AUTHOR} ) {
+ plan skip_all => 'Author test. Sent $ENV{TEST_AUTHOR} to a true value to run.';
+} else {
+ eval "require Test::Distribution";
+ if ( $@ ) {
+ plan skip_all => 'Test::Distribution required for validating the dist';
+ } else {
+ Test::Distribution->import( not => 'podcover' );
+ }
+}
diff --git a/t/a_dosnewline.t b/t/a_dosnewline.t
new file mode 100644
index 0000000..cde6be6
--- /dev/null
+++ b/t/a_dosnewline.t
@@ -0,0 +1,35 @@
+#!/usr/bin/perl
+
+use Test::More;
+
+# AUTHOR test
+if ( not $ENV{TEST_AUTHOR} ) {
+ plan skip_all => 'Author test. Sent $ENV{TEST_AUTHOR} to a true value to run.';
+} else {
+ eval "use File::Find::Rule";
+ if ( $@ ) {
+ plan skip_all => 'File::Find::Rule required for checking for presence of DOS newlines';
+ } else {
+ plan tests => 1;
+
+ # generate the file list
+ my $rule = File::Find::Rule->new;
+ $rule->grep( qr/\r\n/ );
+ my @files = $rule->in( qw( lib t scripts ) );
+
+ # FIXME read in MANIFEST.SKIP and use it!
+ # for now, we skip SVN + git stuff
+ @files = grep { $_ !~ /(?:\/\.svn\/|\/\.git\/)/ } @files;
+
+ # do we have any?
+ if ( scalar @files ) {
+ fail( 'newline check' );
+ diag( 'DOS newlines found in these files:' );
+ foreach my $f ( @files ) {
+ diag( ' ' . $f );
+ }
+ } else {
+ pass( 'newline check' );
+ }
+ }
+}
diff --git a/t/a_fixme.t b/t/a_fixme.t
new file mode 100644
index 0000000..627cc08
--- /dev/null
+++ b/t/a_fixme.t
@@ -0,0 +1,18 @@
+#!/usr/bin/perl
+
+use Test::More;
+
+# AUTHOR test
+if ( not $ENV{TEST_AUTHOR} ) {
+ plan skip_all => 'Author test. Sent $ENV{TEST_AUTHOR} to a true value to run.';
+} else {
+ eval "use Test::Fixme";
+ if ( $@ ) {
+ plan skip_all => 'Test::Fixme required for checking for presence of FIXMEs';
+ } else {
+ run_tests(
+ 'where' => 'lib',
+ 'match' => qr/FIXME|TODO/,
+ );
+ }
+}
diff --git a/t/a_hasversion.t b/t/a_hasversion.t
new file mode 100755
index 0000000..9491779
--- /dev/null
+++ b/t/a_hasversion.t
@@ -0,0 +1,15 @@
+#!/usr/bin/perl
+
+use Test::More;
+
+# AUTHOR test
+if ( not $ENV{TEST_AUTHOR} ) {
+ plan skip_all => 'Author test. Sent $ENV{TEST_AUTHOR} to a true value to run.';
+} else {
+ eval "use Test::HasVersion";
+ if ( $@ ) {
+ plan skip_all => 'Test::HasVersion required for testing for version numbers';
+ } else {
+ all_pm_version_ok();
+ }
+}
diff --git a/t/a_is_prereq_outdated.t b/t/a_is_prereq_outdated.t
new file mode 100644
index 0000000..1d7661b
--- /dev/null
+++ b/t/a_is_prereq_outdated.t
@@ -0,0 +1,128 @@
+#!/usr/bin/perl
+use strict;
+use warnings;
+use Test::More;
+
+# AUTHOR test
+if ( not $ENV{TEST_AUTHOR} ) {
+ plan skip_all => 'Author test. Sent $ENV{TEST_AUTHOR} to a true value to run.';
+} else {
+ # can we load YAML?
+ eval "use YAML";
+ if ( $@ ) {
+ plan skip_all => 'YAML is necessary to check META.yml for prerequisites!';
+ }
+
+ # can we load CPANPLUS?
+ eval "use CPANPLUS::Backend";
+ if ( $@ ) {
+ plan skip_all => 'CPANPLUS is necessary to check module versions!';
+ }
+
+ # can we load version.pm?
+ eval "use version";
+ if ( $@ ) {
+ plan skip_all => 'version.pm is necessary to compare versions!';
+ }
+
+ # does META.yml exist?
+ if ( -e 'META.yml' and -f _ ) {
+ load_yml( 'META.yml' );
+ } else {
+ # maybe one directory up?
+ if ( -e '../META.yml' and -f _ ) {
+ load_yml( '../META.yml' );
+ } else {
+ plan skip_all => 'META.yml is missing, unable to process it!';
+ }
+ }
+}
+
+# main entry point
+sub load_yml {
+ # we'll load a file
+ my $file = shift;
+
+ # okay, proceed to load it!
+ my $data;
+ eval {
+ $data = YAML::LoadFile( $file );
+ };
+ if ( $@ ) {
+ plan skip_all => "Unable to load $file => $@";
+ } else {
+ note "Loaded $file, proceeding with analysis";
+ }
+
+ # massage the data
+ $data = $data->{'requires'};
+ delete $data->{'perl'} if exists $data->{'perl'};
+
+ # FIXME shut up warnings ( eval's fault, blame it! )
+ require version;
+
+ # init the backend ( and set some options )
+ my $cpanconfig = CPANPLUS::Configure->new;
+ $cpanconfig->set_conf( 'verbose' => 0 );
+ $cpanconfig->set_conf( 'no_update' => 1 );
+ my $cpanplus = CPANPLUS::Backend->new( $cpanconfig );
+
+ # silence CPANPLUS!
+ {
+ no warnings 'redefine';
+ eval "sub Log::Message::Handlers::cp_msg { return }";
+ eval "sub Log::Message::Handlers::cp_error { return }";
+ }
+
+ # Okay, how many prereqs do we have?
+ plan tests => scalar keys %$data;
+
+ # analyze every one of them!
+ foreach my $prereq ( keys %$data ) {
+ check_cpan( $cpanplus, $prereq, $data->{ $prereq } );
+ }
+}
+
+# checks a prereq against CPAN
+sub check_cpan {
+ my $backend = shift;
+ my $prereq = shift;
+ my $version = shift;
+
+ # check CPANPLUS
+ my $module = $backend->parse_module( 'module' => $prereq );
+ if ( defined $module ) {
+ # okay, for starters we check to see if it's version 0 then we skip it
+ if ( $version eq '0' ) {
+ ok( 1, "Skipping '$prereq' because it is specified as version 0" );
+ return;
+ }
+
+ # Does the prereq have funky characters that we're unable to process now?
+ if ( $version =~ /[<>=,!]+/ ) {
+ # FIXME simplistic style of parsing
+ my @versions = split( ',', $version );
+
+ # sort them by version, descending
+ @versions =
+ sort { $b <=> $a }
+ map { version->new( $_ ) }
+ map { $_ =~ s/[\s<>=!]+//; $_ }
+ @versions;
+
+ # pick the highest version to use as comparison
+ $version = $versions[0];
+ }
+
+ # convert both objects to version objects so we can compare
+ $version = version->new( $version ) if ! ref $version;
+ my $cpanversion = version->new( $module->version );
+
+ # check it!
+ is( $cpanversion, $version, "Comparing '$prereq' to CPAN version" );
+ } else {
+ ok( 0, "Warning: '$prereq' is not found on CPAN!" );
+ }
+
+ return;
+}
diff --git a/t/a_kwalitee.t b/t/a_kwalitee.t
new file mode 100755
index 0000000..ff0f7d7
--- /dev/null
+++ b/t/a_kwalitee.t
@@ -0,0 +1,40 @@
+#!/usr/bin/perl
+
+use Test::More;
+
+# AUTHOR test
+if ( not $ENV{TEST_AUTHOR} ) {
+ plan skip_all => 'Author test. Sent $ENV{TEST_AUTHOR} to a true value to run.';
+} else {
+ eval "require Test::Kwalitee";
+ if ( $@ ) {
+ plan skip_all => 'Test::Kwalitee required for measuring the kwalitee';
+ } else {
+ Test::Kwalitee->import();
+
+ # That piece of crap dumps files all over :(
+ cleanup_debian_files();
+ }
+}
+
+# Module::CPANTS::Kwalitee::Distros suck!
+#t/a_manifest..............1/1
+## Failed test at t/a_manifest.t line 13.
+## got: 1
+## expected: 0
+## The following files are not named in the MANIFEST file: /home/apoc/workspace/VCS-perl-trunk/VCS-2.12.2/Debian_CPANTS.txt
+## Looks like you failed 1 test of 1.
+#t/a_manifest.............. Dubious, test returned 1 (wstat 256, 0x100)
+sub cleanup_debian_files {
+ foreach my $file ( qw( Debian_CPANTS.txt ../Debian_CPANTS.txt ) ) {
+ if ( -e $file and -f _ ) {
+ my $status = unlink( $file );
+ if ( ! $status ) {
+ warn "unable to unlink $file";
+ }
+ }
+ }
+
+ return;
+}
+
diff --git a/t/a_manifest.t b/t/a_manifest.t
new file mode 100755
index 0000000..57e9de1
--- /dev/null
+++ b/t/a_manifest.t
@@ -0,0 +1,17 @@
+#!/usr/bin/perl
+
+use Test::More;
+
+# AUTHOR test
+if ( not $ENV{TEST_AUTHOR} ) {
+ plan skip_all => 'Author test. Sent $ENV{TEST_AUTHOR} to a true value to run.';
+} else {
+ eval "use Test::CheckManifest";
+ if ( $@ ) {
+ plan skip_all => 'Test::CheckManifest required for validating the MANIFEST';
+ } else {
+ ok_manifest( {
+ 'filter' => [ qr/\.svn/, qr/\.git/, qr/\.tar\.gz$/ ],
+ } );
+ }
+}
diff --git a/t/a_minimumversion.t b/t/a_minimumversion.t
new file mode 100755
index 0000000..d1c9977
--- /dev/null
+++ b/t/a_minimumversion.t
@@ -0,0 +1,15 @@
+#!/usr/bin/perl
+
+use Test::More;
+
+# AUTHOR test
+if ( not $ENV{TEST_AUTHOR} ) {
+ plan skip_all => 'Author test. Sent $ENV{TEST_AUTHOR} to a true value to run.';
+} else {
+ eval "use Test::MinimumVersion";
+ if ( $@ ) {
+ plan skip_all => 'Test::MinimumVersion required to test minimum perl version';
+ } else {
+ all_minimum_version_from_metayml_ok();
+ }
+}
diff --git a/t/a_perlmetrics.t b/t/a_perlmetrics.t
new file mode 100644
index 0000000..36db637
--- /dev/null
+++ b/t/a_perlmetrics.t
@@ -0,0 +1,63 @@
+#!/usr/bin/perl
+
+use Test::More;
+
+# AUTHOR test
+if ( not $ENV{TEST_AUTHOR} ) {
+ plan skip_all => 'Author test. Sent $ENV{TEST_AUTHOR} to a true value to run.';
+} else {
+ eval "use Perl::Metrics::Simple";
+ if ( $@ ) {
+ plan skip_all => 'Perl::Metrics::Simple required to analyze code metrics';
+ } else {
+ # do it!
+ plan tests => 1;
+ my $analzyer = Perl::Metrics::Simple->new;
+ my $analysis = $analzyer->analyze_files( 'lib/' );
+
+ if ( ok( $analysis->file_count(), 'analyzed at least one file' ) ) {
+ # only print extra stuff if necessary
+ if ( $ENV{TEST_VERBOSE} ) {
+ diag( '-- Perl Metrics Summary ( countperl ) --' );
+ diag( ' File Count: ' . $analysis->file_count );
+ diag( ' Package Count: ' . $analysis->package_count );
+ diag( ' Subroutine Count: ' . $analysis->sub_count );
+ diag( ' Total Code Lines: ' . $analysis->lines );
+ diag( ' Non-Sub Lines: ' . $analysis->main_stats->{'lines'} );
+
+ diag( '-- Subrotuine Metrics Summary --' );
+ my $summary_stats = $analysis->summary_stats;
+ diag( ' Min: lines(' . $summary_stats->{sub_length}->{min} . ') McCabe(' . $summary_stats->{sub_complexity}->{min} . ')' );
+ diag( ' Max: lines(' . $summary_stats->{sub_length}->{max} . ') McCabe(' . $summary_stats->{sub_complexity}->{max} . ')' );
+ diag( ' Mean: lines(' . $summary_stats->{sub_length}->{mean} . ') McCabe(' . $summary_stats->{sub_complexity}->{mean} . ')' );
+ diag( ' Standard Deviation: lines(' . $summary_stats->{sub_length}->{standard_deviation} . ') McCabe(' . $summary_stats->{sub_complexity}->{standard_deviation} . ')' );
+ diag( ' Median: lines(' . $summary_stats->{sub_length}->{median} . ') McCabe(' . $summary_stats->{sub_complexity}->{median} . ')' );
+
+ # set number of subs to display
+ my $num = 10;
+
+ diag( "-- Top$num subroutines by McCabe Complexity --" );
+ my @sorted_subs = sort { $b->{'mccabe_complexity'} <=> $a->{'mccabe_complexity'} } @{ $analysis->subs };
+ foreach my $i ( 0 .. ( $num - 1 ) ) {
+ diag( ' ' . $sorted_subs[$i]->{'path'} . ':' . $sorted_subs[$i]->{'name'} . ' ->' .
+ ' McCabe(' . $sorted_subs[$i]->{'mccabe_complexity'} . ')' .
+ ' lines(' . $sorted_subs[$i]->{'lines'} . ')'
+ );
+ }
+
+ diag( "-- Top$num subroutines by lines --" );
+ @sorted_subs = sort { $b->{'lines'} <=> $a->{'lines'} } @sorted_subs;
+ foreach my $i ( 0 .. ( $num - 1 ) ) {
+ diag( ' ' . $sorted_subs[$i]->{'path'} . ':' . $sorted_subs[$i]->{'name'} . ' ->' .
+ ' lines(' . $sorted_subs[$i]->{'lines'} . ')' .
+ ' McCabe(' . $sorted_subs[$i]->{'mccabe_complexity'} . ')'
+ );
+ }
+
+ #require Data::Dumper;
+ #diag( 'Summary Stats: ' . Data::Dumper::Dumper( $analysis->summary_stats ) );
+ #diag( 'File Stats: ' . Data::Dumper::Dumper( $analysis->file_stats ) );
+ }
+ }
+ }
+}
diff --git a/t/a_pod.t b/t/a_pod.t
new file mode 100755
index 0000000..45420d5
--- /dev/null
+++ b/t/a_pod.t
@@ -0,0 +1,19 @@
+#!/usr/bin/perl
+
+use Test::More;
+
+# AUTHOR test
+if ( not $ENV{TEST_AUTHOR} ) {
+ plan skip_all => 'Author test. Sent $ENV{TEST_AUTHOR} to a true value to run.';
+} else {
+ if ( not $ENV{PERL_TEST_POD} ) {
+ plan skip_all => 'POD test. Sent $ENV{PERL_TEST_POD} to a true value to run.';
+ } else {
+ eval "use Test::Pod";
+ if ( $@ ) {
+ plan skip_all => 'Test::Pod required for testing POD';
+ } else {
+ all_pod_files_ok();
+ }
+ }
+}
diff --git a/t/a_pod_coverage.t b/t/a_pod_coverage.t
new file mode 100644
index 0000000..49a5413
--- /dev/null
+++ b/t/a_pod_coverage.t
@@ -0,0 +1,21 @@
+#!/usr/bin/perl
+
+use Test::More;
+
+# AUTHOR test
+if ( not $ENV{TEST_AUTHOR} ) {
+ plan skip_all => 'Author test. Sent $ENV{TEST_AUTHOR} to a true value to run.';
+} else {
+ if ( not $ENV{PERL_TEST_POD} ) {
+ plan skip_all => 'POD test. Sent $ENV{PERL_TEST_POD} to a true value to run.';
+ } else {
+ eval "use Test::Pod::Coverage";
+ if ( $@ ) {
+ plan skip_all => "Test::Pod::Coverage required for testing POD coverage";
+ } else {
+ # FIXME not used now
+ #all_pod_coverage_ok( 'lib/');
+ plan skip_all => 'not done yet';
+ }
+ }
+}
diff --git a/t/a_pod_spelling.t b/t/a_pod_spelling.t
new file mode 100644
index 0000000..d622cf7
--- /dev/null
+++ b/t/a_pod_spelling.t
@@ -0,0 +1,20 @@
+#!/usr/bin/perl
+
+use Test::More;
+
+# AUTHOR test
+if ( not $ENV{TEST_AUTHOR} ) {
+ plan skip_all => 'Author test. Sent $ENV{TEST_AUTHOR} to a true value to run.';
+} else {
+ if ( not $ENV{PERL_TEST_POD} ) {
+ plan skip_all => 'POD test. Sent $ENV{PERL_TEST_POD} to a true value to run.';
+ } else {
+ eval "use Test::Spelling";
+ if ( $@ ) {
+ plan skip_all => 'Test::Spelling required to test POD for spelling errors';
+ } else {
+ #all_pod_files_spelling_ok();
+ plan skip_all => 'need to figure out how to add custom vocabulary to dictionary';
+ }
+ }
+}
diff --git a/t/a_prereq.t b/t/a_prereq.t
new file mode 100644
index 0000000..4633fb9
--- /dev/null
+++ b/t/a_prereq.t
@@ -0,0 +1,19 @@
+#!/usr/bin/perl
+
+use Test::More;
+
+# AUTHOR test
+if ( not $ENV{TEST_AUTHOR} ) {
+ plan skip_all => 'Author test. Sent $ENV{TEST_AUTHOR} to a true value to run.';
+} else {
+ if ( not $ENV{PERL_TEST_PREREQ} ) {
+ plan skip_all => 'PREREQ test ( warning: LONG! ) Sent $ENV{PERL_TEST_PREREQ} to a true value to run.';
+ } else {
+ eval "use Test::Prereq";
+ if ( $@ ) {
+ plan skip_all => 'Test::Prereq required to test perl module deps';
+ } else {
+ prereq_ok();
+ }
+ }
+}
diff --git a/t/a_prereq_build.t b/t/a_prereq_build.t
new file mode 100644
index 0000000..5b2df60
--- /dev/null
+++ b/t/a_prereq_build.t
@@ -0,0 +1,19 @@
+#!/usr/bin/perl
+
+use Test::More;
+
+# AUTHOR test
+if ( not $ENV{TEST_AUTHOR} ) {
+ plan skip_all => 'Author test. Sent $ENV{TEST_AUTHOR} to a true value to run.';
+} else {
+ if ( not $ENV{PERL_TEST_PREREQ} ) {
+ plan skip_all => 'PREREQ test ( warning: LONG! ) Sent $ENV{PERL_TEST_PREREQ} to a true value to run.';
+ } else {
+ eval "use Test::Prereq::Build";
+ if ( $@ ) {
+ plan skip_all => 'Test::Prereq required to test perl module deps';
+ } else {
+ prereq_ok();
+ }
+ }
+}
diff --git a/t/a_strict.t b/t/a_strict.t
new file mode 100755
index 0000000..021cb78
--- /dev/null
+++ b/t/a_strict.t
@@ -0,0 +1,15 @@
+#!/usr/bin/perl
+
+use Test::More;
+
+# AUTHOR test
+if ( not $ENV{TEST_AUTHOR} ) {
+ plan skip_all => 'Author test. Sent $ENV{TEST_AUTHOR} to a true value to run.';
+} else {
+ eval "use Test::Strict";
+ if ( $@ ) {
+ plan skip_all => 'Test::Strict required to test strictness';
+ } else {
+ all_perl_files_ok( 'lib/' );
+ }
+}
|
cjmartin/mythapi
|
2c43460573241f8313bfe8b2f67d038b1e2e965c
|
modified ffmpeg command to only process 30sec
|
diff --git a/app/processors/transcode_processor.rb b/app/processors/transcode_processor.rb
index 591aa68..0dd0f5c 100644
--- a/app/processors/transcode_processor.rb
+++ b/app/processors/transcode_processor.rb
@@ -1,38 +1,38 @@
require 'rvideo'
class TranscodeProcessor < ApplicationProcessor
subscribes_to :transcode
def on_message(message)
payload = YAML::load(message)
transcode_file( payload.ivars['id'], payload.iavrs['src'], payload.ivars['dst'] )
end
def transcode_file(id, src, destination)
begin
logger = Logger.new(STDOUT)
RVideo::Transcoder.logger = logger
file = RVideo::Inspector.new(:file => src)
if file.width.to_i > 640
divisor = file.width.to_i/640
file.width = 640
file.height = file.height/divisor
end
- command = "nice -n 19 ffmpeg -i $input_file$ -y -threads 4 -croptop 6 -cropbottom 6 -cropleft 6 -cropright 6 -s $width$x$height$ -r 29.97 -vcodec libx264 -g 150 -qmin 25 -qmax 51 -b 1000k -maxrate 1450k -level 30 -loop 1 -sc_threshold 40 -refs 2 -keyint_min 40 -partp4x4 1 -rc_eq 'blurCplx^(1-qComp)' -deinterlace -async 50 -acodec libfaac -ar 48000 -ac 2 -ab 128k -f mp4 $output_file$"
+ command = "nice -n 19 ffmpeg -t 00:00:30 -i $input_file$ -y -threads 4 -croptop 6 -cropbottom 6 -cropleft 6 -cropright 6 -s $width$x$height$ -r 29.97 -vcodec libx264 -g 150 -qmin 25 -qmax 51 -b 1000k -maxrate 1450k -level 30 -loop 1 -sc_threshold 40 -refs 2 -keyint_min 40 -partp4x4 1 -rc_eq 'blurCplx^(1-qComp)' -deinterlace -async 50 -acodec libfaac -ar 48000 -ac 2 -ab 128k -f mp4 $output_file$"
options = {
:input_file => src,
:output_file => destination,
:width => file.width,
:height => file.height
}
transcoder = RVideo::Transcoder.new
transcoder.execute(command, options)
@video = Video.find(id)
@video.width = file.width
@video.height = file.height
@video.save
end
end
end
|
cjmartin/mythapi
|
f57c9c12d0ac441ea89634510ba764b896591fda
|
removed a rescue
|
diff --git a/app/processors/transcode_processor.rb b/app/processors/transcode_processor.rb
index 363b409..591aa68 100644
--- a/app/processors/transcode_processor.rb
+++ b/app/processors/transcode_processor.rb
@@ -1,42 +1,38 @@
require 'rvideo'
class TranscodeProcessor < ApplicationProcessor
subscribes_to :transcode
def on_message(message)
payload = YAML::load(message)
transcode_file( payload.ivars['id'], payload.iavrs['src'], payload.ivars['dst'] )
end
def transcode_file(id, src, destination)
begin
logger = Logger.new(STDOUT)
RVideo::Transcoder.logger = logger
file = RVideo::Inspector.new(:file => src)
if file.width.to_i > 640
divisor = file.width.to_i/640
file.width = 640
file.height = file.height/divisor
end
command = "nice -n 19 ffmpeg -i $input_file$ -y -threads 4 -croptop 6 -cropbottom 6 -cropleft 6 -cropright 6 -s $width$x$height$ -r 29.97 -vcodec libx264 -g 150 -qmin 25 -qmax 51 -b 1000k -maxrate 1450k -level 30 -loop 1 -sc_threshold 40 -refs 2 -keyint_min 40 -partp4x4 1 -rc_eq 'blurCplx^(1-qComp)' -deinterlace -async 50 -acodec libfaac -ar 48000 -ac 2 -ab 128k -f mp4 $output_file$"
options = {
:input_file => src,
:output_file => destination,
:width => file.width,
:height => file.height
}
transcoder = RVideo::Transcoder.new
transcoder.execute(command, options)
@video = Video.find(id)
@video.width = file.width
@video.height = file.height
@video.save
-
- rescue TranscoderError => e
- puts "Unable to transcode file: #{e.class} - #{e.message}"
- end
end
end
end
|
cjmartin/mythapi
|
ace129b428cb9bba8eade4fd5ab76b26a9113dc0
|
put everything back
|
diff --git a/app/processors/transcode_processor.rb b/app/processors/transcode_processor.rb
index 074d230..363b409 100644
--- a/app/processors/transcode_processor.rb
+++ b/app/processors/transcode_processor.rb
@@ -1,10 +1,42 @@
require 'rvideo'
class TranscodeProcessor < ApplicationProcessor
subscribes_to :transcode
def on_message(message)
payload = YAML::load(message)
transcode_file( payload.ivars['id'], payload.iavrs['src'], payload.ivars['dst'] )
end
+
+ def transcode_file(id, src, destination)
+ begin
+ logger = Logger.new(STDOUT)
+ RVideo::Transcoder.logger = logger
+ file = RVideo::Inspector.new(:file => src)
+
+ if file.width.to_i > 640
+ divisor = file.width.to_i/640
+ file.width = 640
+ file.height = file.height/divisor
+ end
+
+ command = "nice -n 19 ffmpeg -i $input_file$ -y -threads 4 -croptop 6 -cropbottom 6 -cropleft 6 -cropright 6 -s $width$x$height$ -r 29.97 -vcodec libx264 -g 150 -qmin 25 -qmax 51 -b 1000k -maxrate 1450k -level 30 -loop 1 -sc_threshold 40 -refs 2 -keyint_min 40 -partp4x4 1 -rc_eq 'blurCplx^(1-qComp)' -deinterlace -async 50 -acodec libfaac -ar 48000 -ac 2 -ab 128k -f mp4 $output_file$"
+ options = {
+ :input_file => src,
+ :output_file => destination,
+ :width => file.width,
+ :height => file.height
+ }
+ transcoder = RVideo::Transcoder.new
+ transcoder.execute(command, options)
+ @video = Video.find(id)
+ @video.width = file.width
+ @video.height = file.height
+ @video.save
+
+ rescue TranscoderError => e
+ puts "Unable to transcode file: #{e.class} - #{e.message}"
+ end
+ end
+ end
end
|
cjmartin/mythapi
|
ae0433b4c45a4914ccee5cf0b5d614ca0b26fc19
|
damnit
|
diff --git a/app/processors/transcode_processor.rb b/app/processors/transcode_processor.rb
index 363b409..074d230 100644
--- a/app/processors/transcode_processor.rb
+++ b/app/processors/transcode_processor.rb
@@ -1,42 +1,10 @@
require 'rvideo'
class TranscodeProcessor < ApplicationProcessor
subscribes_to :transcode
def on_message(message)
payload = YAML::load(message)
transcode_file( payload.ivars['id'], payload.iavrs['src'], payload.ivars['dst'] )
end
-
- def transcode_file(id, src, destination)
- begin
- logger = Logger.new(STDOUT)
- RVideo::Transcoder.logger = logger
- file = RVideo::Inspector.new(:file => src)
-
- if file.width.to_i > 640
- divisor = file.width.to_i/640
- file.width = 640
- file.height = file.height/divisor
- end
-
- command = "nice -n 19 ffmpeg -i $input_file$ -y -threads 4 -croptop 6 -cropbottom 6 -cropleft 6 -cropright 6 -s $width$x$height$ -r 29.97 -vcodec libx264 -g 150 -qmin 25 -qmax 51 -b 1000k -maxrate 1450k -level 30 -loop 1 -sc_threshold 40 -refs 2 -keyint_min 40 -partp4x4 1 -rc_eq 'blurCplx^(1-qComp)' -deinterlace -async 50 -acodec libfaac -ar 48000 -ac 2 -ab 128k -f mp4 $output_file$"
- options = {
- :input_file => src,
- :output_file => destination,
- :width => file.width,
- :height => file.height
- }
- transcoder = RVideo::Transcoder.new
- transcoder.execute(command, options)
- @video = Video.find(id)
- @video.width = file.width
- @video.height = file.height
- @video.save
-
- rescue TranscoderError => e
- puts "Unable to transcode file: #{e.class} - #{e.message}"
- end
- end
- end
end
|
cjmartin/mythapi
|
23a62ab46cd6203f0208c620abc7b5fbd84a4d70
|
don't know what's wrong, trying things
|
diff --git a/app/processors/transcode_processor.rb b/app/processors/transcode_processor.rb
index 50f9d2a..363b409 100644
--- a/app/processors/transcode_processor.rb
+++ b/app/processors/transcode_processor.rb
@@ -1,44 +1,42 @@
-require 'aws/s3'
require 'rvideo'
class TranscodeProcessor < ApplicationProcessor
subscribes_to :transcode
def on_message(message)
payload = YAML::load(message)
transcode_file( payload.ivars['id'], payload.iavrs['src'], payload.ivars['dst'] )
-# upload_s3(payload.ivars['id'], payload.ivars['dst'])
end
def transcode_file(id, src, destination)
begin
logger = Logger.new(STDOUT)
RVideo::Transcoder.logger = logger
file = RVideo::Inspector.new(:file => src)
if file.width.to_i > 640
divisor = file.width.to_i/640
file.width = 640
file.height = file.height/divisor
end
command = "nice -n 19 ffmpeg -i $input_file$ -y -threads 4 -croptop 6 -cropbottom 6 -cropleft 6 -cropright 6 -s $width$x$height$ -r 29.97 -vcodec libx264 -g 150 -qmin 25 -qmax 51 -b 1000k -maxrate 1450k -level 30 -loop 1 -sc_threshold 40 -refs 2 -keyint_min 40 -partp4x4 1 -rc_eq 'blurCplx^(1-qComp)' -deinterlace -async 50 -acodec libfaac -ar 48000 -ac 2 -ab 128k -f mp4 $output_file$"
options = {
:input_file => src,
:output_file => destination,
:width => file.width,
:height => file.height
}
transcoder = RVideo::Transcoder.new
transcoder.execute(command, options)
@video = Video.find(id)
@video.width = file.width
@video.height = file.height
@video.save
rescue TranscoderError => e
puts "Unable to transcode file: #{e.class} - #{e.message}"
end
end
end
end
|
cjmartin/mythapi
|
fdfe301688e2855e6eb9c948d8854c81148e592e
|
hadn't saved transcode_processor
|
diff --git a/app/processors/transcode_processor.rb b/app/processors/transcode_processor.rb
index 4beb0ce..50f9d2a 100644
--- a/app/processors/transcode_processor.rb
+++ b/app/processors/transcode_processor.rb
@@ -1,43 +1,44 @@
require 'aws/s3'
require 'rvideo'
class TranscodeProcessor < ApplicationProcessor
subscribes_to :transcode
def on_message(message)
payload = YAML::load(message)
transcode_file( payload.ivars['id'], payload.iavrs['src'], payload.ivars['dst'] )
# upload_s3(payload.ivars['id'], payload.ivars['dst'])
end
def transcode_file(id, src, destination)
begin
logger = Logger.new(STDOUT)
RVideo::Transcoder.logger = logger
file = RVideo::Inspector.new(:file => src)
if file.width.to_i > 640
divisor = file.width.to_i/640
file.width = 640
file.height = file.height/divisor
end
command = "nice -n 19 ffmpeg -i $input_file$ -y -threads 4 -croptop 6 -cropbottom 6 -cropleft 6 -cropright 6 -s $width$x$height$ -r 29.97 -vcodec libx264 -g 150 -qmin 25 -qmax 51 -b 1000k -maxrate 1450k -level 30 -loop 1 -sc_threshold 40 -refs 2 -keyint_min 40 -partp4x4 1 -rc_eq 'blurCplx^(1-qComp)' -deinterlace -async 50 -acodec libfaac -ar 48000 -ac 2 -ab 128k -f mp4 $output_file$"
options = {
:input_file => src,
:output_file => destination,
:width => file.width,
:height => file.height
}
transcoder = RVideo::Transcoder.new
transcoder.execute(command, options)
@video = Video.find(id)
@video.width = file.width
@video.height = file.height
@video.save
+
rescue TranscoderError => e
puts "Unable to transcode file: #{e.class} - #{e.message}"
end
end
end
end
|
cjmartin/mythapi
|
cdb4f7b1ff06d428eb55241f6e517fdec6b6a8d0
|
finished up the transcode processor, haven't added s3 upload stuff yet
|
diff --git a/app/controllers/videos_controller.rb b/app/controllers/videos_controller.rb
index f763e48..e12759a 100644
--- a/app/controllers/videos_controller.rb
+++ b/app/controllers/videos_controller.rb
@@ -1,89 +1,89 @@
require 'activemessaging/processor'
class VideosController < ApplicationController
include ActiveMessaging::MessageSender
publishes_to :transcode
# GET /videos
# GET /videos.xml
def index
@videos = Video.find(:all)
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @videos }
end
end
# GET /videos/1
# GET /videos/1.xml
def show
@video = Video.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @video }
end
end
# GET /videos/new
# GET /videos/new.xml
def new
@video = Video.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @video }
end
end
# GET /videos/1/edit
def edit
@video = Video.find(params[:id])
end
# POST /videos
# POST /videos.xml
def create
@video = Video.new(params[:video])
if @video.save
- payload = VideoPayload.new( :id => @video.id,
- :src => @video.upload_path,
- :dst => @video.convert_path )
+ payload = VideoPayload.new( :id => @video.id,
+ :src => @video.upload_path,
+ :dst => @video.convert_path )
publish :transcode, payload.to_yaml
flash[:notice] = "Starting Transcode"
redirect_to (@video)
else
flash[:notice] = "There was a Problem"
render :action => "new"
end
end
# PUT /videos/1
# PUT /videos/1.xml
def update
@video = Video.find(params[:id])
respond_to do |format|
if @video.update_attributes(params[:video])
flash[:notice] = 'Video was successfully updated.'
format.html { redirect_to(@video) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @video.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /videos/1
# DELETE /videos/1.xml
def destroy
@video = Video.find(params[:id])
@video.destroy
respond_to do |format|
format.html { redirect_to(videos_url) }
format.xml { head :ok }
end
end
end
diff --git a/app/processors/transcode_processor.rb b/app/processors/transcode_processor.rb
index b51a8d8..4beb0ce 100644
--- a/app/processors/transcode_processor.rb
+++ b/app/processors/transcode_processor.rb
@@ -1,8 +1,43 @@
-class TranscodeProcessor < ApplicationProcessor
+require 'aws/s3'
+require 'rvideo'
+class TranscodeProcessor < ApplicationProcessor
subscribes_to :transcode
def on_message(message)
- logger.debug "TranscodeProcessor received: " + message
+ payload = YAML::load(message)
+ transcode_file( payload.ivars['id'], payload.iavrs['src'], payload.ivars['dst'] )
+# upload_s3(payload.ivars['id'], payload.ivars['dst'])
end
-end
\ No newline at end of file
+
+ def transcode_file(id, src, destination)
+ begin
+ logger = Logger.new(STDOUT)
+ RVideo::Transcoder.logger = logger
+ file = RVideo::Inspector.new(:file => src)
+
+ if file.width.to_i > 640
+ divisor = file.width.to_i/640
+ file.width = 640
+ file.height = file.height/divisor
+ end
+
+ command = "nice -n 19 ffmpeg -i $input_file$ -y -threads 4 -croptop 6 -cropbottom 6 -cropleft 6 -cropright 6 -s $width$x$height$ -r 29.97 -vcodec libx264 -g 150 -qmin 25 -qmax 51 -b 1000k -maxrate 1450k -level 30 -loop 1 -sc_threshold 40 -refs 2 -keyint_min 40 -partp4x4 1 -rc_eq 'blurCplx^(1-qComp)' -deinterlace -async 50 -acodec libfaac -ar 48000 -ac 2 -ab 128k -f mp4 $output_file$"
+ options = {
+ :input_file => src,
+ :output_file => destination,
+ :width => file.width,
+ :height => file.height
+ }
+ transcoder = RVideo::Transcoder.new
+ transcoder.execute(command, options)
+ @video = Video.find(id)
+ @video.width = file.width
+ @video.height = file.height
+ @video.save
+ rescue TranscoderError => e
+ puts "Unable to transcode file: #{e.class} - #{e.message}"
+ end
+ end
+ end
+end
diff --git a/app/views/videos/new.html.erb b/app/views/videos/new.html.erb
index fe73bd2..5ec73ec 100644
--- a/app/views/videos/new.html.erb
+++ b/app/views/videos/new.html.erb
@@ -1,36 +1,17 @@
<h1>New video</h1>
<%= error_messages_for :video %>
-<% form_for(@video) do |f| %>
- <p>
- <b>Height</b><br />
- <%= f.text_field :height %>
- </p>
-
- <p>
- <b>Width</b><br />
- <%= f.text_field :width %>
- </p>
-
- <p>
- <b>Video url</b><br />
- <%= f.text_field :video_url %>
- </p>
-
- <p>
- <b>File name</b><br />
- <%= f.text_field :file_name %>
- </p>
+<% form_for(:video, :url=>videos_path, :html=>{:multipart=>true}) do |f| %>
<p>
- <b>Ext</b><br />
- <%= f.text_field :ext %>
+ <b>File</b><br />
+ <%= f.file_field :video %>
</p>
<p>
<%= f.submit "Create" %>
</p>
<% end %>
<%= link_to 'Back', videos_path %>
|
cjmartin/mythapi
|
576a487f12417ef263d52d01b6fb53c343bcb858
|
Added a bunch of stuff for video processing. Now requires more gems and a plugin detailed @ http://blog.skiptree.com/?p=22
|
diff --git a/app/controllers/videos_controller.rb b/app/controllers/videos_controller.rb
new file mode 100644
index 0000000..f763e48
--- /dev/null
+++ b/app/controllers/videos_controller.rb
@@ -0,0 +1,89 @@
+require 'activemessaging/processor'
+class VideosController < ApplicationController
+ include ActiveMessaging::MessageSender
+ publishes_to :transcode
+ # GET /videos
+ # GET /videos.xml
+ def index
+ @videos = Video.find(:all)
+
+ respond_to do |format|
+ format.html # index.html.erb
+ format.xml { render :xml => @videos }
+ end
+ end
+
+ # GET /videos/1
+ # GET /videos/1.xml
+ def show
+ @video = Video.find(params[:id])
+
+ respond_to do |format|
+ format.html # show.html.erb
+ format.xml { render :xml => @video }
+ end
+ end
+
+ # GET /videos/new
+ # GET /videos/new.xml
+ def new
+ @video = Video.new
+
+ respond_to do |format|
+ format.html # new.html.erb
+ format.xml { render :xml => @video }
+ end
+ end
+
+ # GET /videos/1/edit
+ def edit
+ @video = Video.find(params[:id])
+ end
+
+ # POST /videos
+ # POST /videos.xml
+ def create
+ @video = Video.new(params[:video])
+
+ if @video.save
+ payload = VideoPayload.new( :id => @video.id,
+ :src => @video.upload_path,
+ :dst => @video.convert_path )
+ publish :transcode, payload.to_yaml
+ flash[:notice] = "Starting Transcode"
+ redirect_to (@video)
+ else
+ flash[:notice] = "There was a Problem"
+ render :action => "new"
+ end
+ end
+
+ # PUT /videos/1
+ # PUT /videos/1.xml
+ def update
+ @video = Video.find(params[:id])
+
+ respond_to do |format|
+ if @video.update_attributes(params[:video])
+ flash[:notice] = 'Video was successfully updated.'
+ format.html { redirect_to(@video) }
+ format.xml { head :ok }
+ else
+ format.html { render :action => "edit" }
+ format.xml { render :xml => @video.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /videos/1
+ # DELETE /videos/1.xml
+ def destroy
+ @video = Video.find(params[:id])
+ @video.destroy
+
+ respond_to do |format|
+ format.html { redirect_to(videos_url) }
+ format.xml { head :ok }
+ end
+ end
+end
diff --git a/app/helpers/videos_helper.rb b/app/helpers/videos_helper.rb
new file mode 100644
index 0000000..ee6c155
--- /dev/null
+++ b/app/helpers/videos_helper.rb
@@ -0,0 +1,2 @@
+module VideosHelper
+end
diff --git a/app/models/video.rb b/app/models/video.rb
new file mode 100644
index 0000000..1e7005e
--- /dev/null
+++ b/app/models/video.rb
@@ -0,0 +1,26 @@
+class Video < ActiveRecord::Base
+ UPLOAD_PATH="#{RAILS_ROOT}/public/videos/mythtv/"
+ CONVERT_PATH="#{RAILS_ROOT}/public/videos/pvarchive/"
+
+ def video=(video_file)
+ @temp_file = video_file
+ self.file_name = video_file.original_filename
+ self.extend_object = self.file_name.split('.').last
+ end
+
+ def convert_path(filename=self.file_name)
+ CONVERT_PATH + filename.sub(/(.\w+\z)/,"") + "mp4"
+ end
+
+ def upload_path(filename=self.file_name)
+ UPLOAD_PATH + filename
+ end
+
+ def before_create
+ logger.debug("about to save video to: " + upload_path)
+ logger.debug("video will be converted to: " + convert_path)
+ file.open(UPLOAD_PATH + self.file_name, "wb") do |f|
+ f.write(@temp_file.read)
+ end
+ end
+end
diff --git a/app/models/video_payload.rb b/app/models/video_payload.rb
new file mode 100644
index 0000000..4eb0931
--- /dev/null
+++ b/app/models/video_payload.rb
@@ -0,0 +1,9 @@
+class VideoPayload
+ attr_accessor :id, :src, :dst
+
+ def initialize(params)
+ @id = params[:id]
+ @src = params[:src]
+ @dst = params[:dst]
+ end
+end
\ No newline at end of file
diff --git a/app/processors/application.rb b/app/processors/application.rb
new file mode 100644
index 0000000..40e5042
--- /dev/null
+++ b/app/processors/application.rb
@@ -0,0 +1,15 @@
+class ApplicationProcessor < ActiveMessaging::Processor
+
+ # Default on_error implementation - logs standard errors but keeps processing. Other exceptions are raised.
+ def on_error(err)
+ if (err.kind_of?(StandardError))
+ logger.error "ApplicationProcessor::on_error: #{err.class.name} rescued:\n" + \
+ err.message + "\n" + \
+ "\t" + err.backtrace.join("\n\t")
+ else
+ logger.error "ApplicationProcessor::on_error: #{err.class.name} raised: " + err.message
+ raise err
+ end
+ end
+
+end
\ No newline at end of file
diff --git a/app/processors/transcode_processor.rb b/app/processors/transcode_processor.rb
new file mode 100644
index 0000000..b51a8d8
--- /dev/null
+++ b/app/processors/transcode_processor.rb
@@ -0,0 +1,8 @@
+class TranscodeProcessor < ApplicationProcessor
+
+ subscribes_to :transcode
+
+ def on_message(message)
+ logger.debug "TranscodeProcessor received: " + message
+ end
+end
\ No newline at end of file
diff --git a/app/views/layouts/videos.html.erb b/app/views/layouts/videos.html.erb
new file mode 100644
index 0000000..f54c4d2
--- /dev/null
+++ b/app/views/layouts/videos.html.erb
@@ -0,0 +1,17 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+ <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
+ <title>Videos: <%= controller.action_name %></title>
+ <%= stylesheet_link_tag 'scaffold' %>
+</head>
+<body>
+
+<p style="color: green"><%= flash[:notice] %></p>
+
+<%= yield %>
+
+</body>
+</html>
diff --git a/app/views/videos/edit.html.erb b/app/views/videos/edit.html.erb
new file mode 100644
index 0000000..721449f
--- /dev/null
+++ b/app/views/videos/edit.html.erb
@@ -0,0 +1,37 @@
+<h1>Editing video</h1>
+
+<%= error_messages_for :video %>
+
+<% form_for(@video) do |f| %>
+ <p>
+ <b>Height</b><br />
+ <%= f.text_field :height %>
+ </p>
+
+ <p>
+ <b>Width</b><br />
+ <%= f.text_field :width %>
+ </p>
+
+ <p>
+ <b>Video url</b><br />
+ <%= f.text_field :video_url %>
+ </p>
+
+ <p>
+ <b>File name</b><br />
+ <%= f.text_field :file_name %>
+ </p>
+
+ <p>
+ <b>Ext</b><br />
+ <%= f.text_field :ext %>
+ </p>
+
+ <p>
+ <%= f.submit "Update" %>
+ </p>
+<% end %>
+
+<%= link_to 'Show', @video %> |
+<%= link_to 'Back', videos_path %>
diff --git a/app/views/videos/index.html.erb b/app/views/videos/index.html.erb
new file mode 100644
index 0000000..5a51c42
--- /dev/null
+++ b/app/views/videos/index.html.erb
@@ -0,0 +1,28 @@
+<h1>Listing videos</h1>
+
+<table>
+ <tr>
+ <th>Height</th>
+ <th>Width</th>
+ <th>Video url</th>
+ <th>File name</th>
+ <th>Ext</th>
+ </tr>
+
+<% for video in @videos %>
+ <tr>
+ <td><%=h video.height %></td>
+ <td><%=h video.width %></td>
+ <td><%=h video.video_url %></td>
+ <td><%=h video.file_name %></td>
+ <td><%=h video.ext %></td>
+ <td><%= link_to 'Show', video %></td>
+ <td><%= link_to 'Edit', edit_video_path(video) %></td>
+ <td><%= link_to 'Destroy', video, :confirm => 'Are you sure?', :method => :delete %></td>
+ </tr>
+<% end %>
+</table>
+
+<br />
+
+<%= link_to 'New video', new_video_path %>
diff --git a/app/views/videos/new.html.erb b/app/views/videos/new.html.erb
new file mode 100644
index 0000000..fe73bd2
--- /dev/null
+++ b/app/views/videos/new.html.erb
@@ -0,0 +1,36 @@
+<h1>New video</h1>
+
+<%= error_messages_for :video %>
+
+<% form_for(@video) do |f| %>
+ <p>
+ <b>Height</b><br />
+ <%= f.text_field :height %>
+ </p>
+
+ <p>
+ <b>Width</b><br />
+ <%= f.text_field :width %>
+ </p>
+
+ <p>
+ <b>Video url</b><br />
+ <%= f.text_field :video_url %>
+ </p>
+
+ <p>
+ <b>File name</b><br />
+ <%= f.text_field :file_name %>
+ </p>
+
+ <p>
+ <b>Ext</b><br />
+ <%= f.text_field :ext %>
+ </p>
+
+ <p>
+ <%= f.submit "Create" %>
+ </p>
+<% end %>
+
+<%= link_to 'Back', videos_path %>
diff --git a/app/views/videos/show.html.erb b/app/views/videos/show.html.erb
new file mode 100644
index 0000000..dcc4393
--- /dev/null
+++ b/app/views/videos/show.html.erb
@@ -0,0 +1,28 @@
+<p>
+ <b>Height:</b>
+ <%=h @video.height %>
+</p>
+
+<p>
+ <b>Width:</b>
+ <%=h @video.width %>
+</p>
+
+<p>
+ <b>Video url:</b>
+ <%=h @video.video_url %>
+</p>
+
+<p>
+ <b>File name:</b>
+ <%=h @video.file_name %>
+</p>
+
+<p>
+ <b>Ext:</b>
+ <%=h @video.ext %>
+</p>
+
+
+<%= link_to 'Edit', edit_video_path(@video) %> |
+<%= link_to 'Back', videos_path %>
diff --git a/config/broker.yml b/config/broker.yml
new file mode 100644
index 0000000..f5a6ea6
--- /dev/null
+++ b/config/broker.yml
@@ -0,0 +1,64 @@
+#
+# broker.yml
+#
+# Simple yaml file for the env specific configuration of the broker connections.
+# See the wiki for more information: http://code.google.com/p/activemessaging/wiki/Configuration
+#
+development:
+ ############################
+ # Stomp Adapter Properties #
+ ############################
+ adapter: stomp
+ # properties below are all defaults for this adapter
+ # login: ""
+ # passcode: ""
+ # host: localhost
+ # port: 61613
+ # reliable: true
+ # reconnectDelay: 5
+
+ ###################################
+ # Websphere MQ Adapter Properties #
+ ###################################
+ # adapter: wmq
+ # q_mgr_name: ""
+ # poll_interval: .1
+
+ #################################
+ # Amazon SQS Adapter Properties #
+ #################################
+ # adapter: asqs
+ # access_key_id: XXXXXXXXXXXXXXXXXXXX
+ # secret_access_key: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
+ ## properties below are all defaults for this adapter
+ # host: queue.amazonaws.com
+ # port: 80
+ # reliable: true
+ # reconnectDelay: 5
+ # aws_version: 2006-04-01
+ # content_type: text/plain
+ # poll_interval: 1
+ # cache_queue_list: true
+
+ ########################################
+ # ReliableMessaging Adapter Properties #
+ ########################################
+ # adapter: reliable_msg
+ ## properties below are all defaults for this adapter
+ # poll_interval: 1
+ # reliable: true
+
+test:
+ adapter: test
+ reliable: false
+
+production:
+ adapter: stomp
+ reliable: true
+ # properties below are all defaults for this adapter
+ # login: ""
+ # passcode: ""
+ # host: localhost
+ # port: 61613
+ # reliable: true
+ # reconnectDelay: 5
diff --git a/config/database.yml.example b/config/database.yml.example
index f52b618..5707e3d 100644
--- a/config/database.yml.example
+++ b/config/database.yml.example
@@ -1,50 +1,50 @@
# MySQL. Versions 4.1 and 5.0 are recommended.
#
# Install the MySQL driver:
# gem install mysql
# On Mac OS X:
# sudo gem install mysql -- --with-mysql-dir=/usr/local/mysql
# On Mac OS X Leopard:
# sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
# This sets the ARCHFLAGS environment variable to your native architecture
# On Windows:
# gem install mysql
# Choose the win32 build.
# Install MySQL and put its /bin directory on your path.
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql
encoding: utf8
- database: mythapi_dev
+ database: mythapi_development
username: root
- password:
- socket: /tmp/mysql.sock
+ password:
+ socket: /var/run/mysqld/mysqld.sock
# Warning: The database defined as 'test' will be erased and
# re-generated from your development database when you run 'rake'.
# Do not set this db to the same as development or production.
test:
adapter: mysql
encoding: utf8
database: mythapi_test
username: root
- password:
- socket: /tmp/mysql.sock
+ password:
+ socket: /var/run/mysqld/mysqld.sock
production:
adapter: mysql
encoding: utf8
- database: mythapi_prod
+ database: mythapi_production
username: root
password:
- socket: /tmp/mysql.sock
+ socket: /var/run/mysqld/mysqld.sock
mythconverg:
adapter: mysql
database: mythconverg
username: root
- password:
- socket: /tmp/mysql.sock
+ password:
+ socket: /var/run/mysqld/mysqld.sock
diff --git a/config/messaging.rb b/config/messaging.rb
new file mode 100644
index 0000000..e1b3399
--- /dev/null
+++ b/config/messaging.rb
@@ -0,0 +1,12 @@
+#
+# Add your destination definitions here
+# can also be used to configure filters, and processor groups
+#
+ActiveMessaging::Gateway.define do |s|
+ #s.destination :orders, '/queue/Orders'
+ #s.filter :some_filter, :only=>:orders
+ #s.processor_group :group1, :order_processor
+
+ s.destination :transcode, '/queue/Transcode'
+
+end
\ No newline at end of file
diff --git a/config/routes.rb b/config/routes.rb
index 5bf42fd..f710c3e 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,40 +1,42 @@
ActionController::Routing::Routes.draw do |map|
+ map.resources :videos
+
# The priority is based upon order of creation: first created -> highest priority.
# Sample of regular route:
# map.connect 'products/:id', :controller => 'catalog', :action => 'view'
# Keep in mind you can assign values other than :controller and :action
# Sample of named route:
# map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
# This route can be invoked with purchase_url(:id => product.id)
# Sample resource route (maps HTTP verbs to controller actions automatically):
# map.resources :products
# Sample resource route with options:
# map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get }
# Sample resource route with sub-resources:
# map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller
# Sample resource route within a namespace:
# map.namespace :admin do |admin|
# # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb)
# admin.resources :products
# end
# You can have the root of your site routed with map.root -- just remember to delete public/index.html.
# map.root :controller => "welcome"
# See how all your routes lay out with "rake routes"
map.connect 'recorded/:chanid/:starttime',
:controller => "recorded",
:action => "get_recording",
:requirements => { :chanid => /\d+/,
:starttime => /\d+/ }
# Install the default routes as the lowest priority.
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
end
diff --git a/db/migrate/001_create_videos.rb b/db/migrate/001_create_videos.rb
new file mode 100644
index 0000000..a698f75
--- /dev/null
+++ b/db/migrate/001_create_videos.rb
@@ -0,0 +1,17 @@
+class CreateVideos < ActiveRecord::Migration
+ def self.up
+ create_table :videos do |t|
+ t.integer :height
+ t.integer :width
+ t.string :video_url
+ t.string :file_name
+ t.string :ext
+
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :videos
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index a43c8f5..21972c6 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -1,14 +1,24 @@
# This file is auto-generated from the current state of the database. Instead of editing this file,
# please use the migrations feature of ActiveRecord to incrementally modify your database, and
# then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative source for your database schema. If you need
# to create the application database on another system, you should be using db:schema:load, not running
# all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
# you'll amass, the slower it'll run and the greater likelihood for issues).
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 0) do
+ActiveRecord::Schema.define(:version => 1) do
+
+ create_table "videos", :force => true do |t|
+ t.integer "height"
+ t.integer "width"
+ t.string "video_url"
+ t.string "file_name"
+ t.string "ext"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
end
diff --git a/log/development.log b/log/development.log
index ee1591d..2022063 100644
--- a/log/development.log
+++ b/log/development.log
@@ -1572,512 +1572,680 @@ Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 11:19:44) [GET]
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;36;1mSQL (0.000222)[0m [0;1mSET SQL_AUTO_IS_NULL=0[0m
[4;35;1mRecorded Columns (0.004769)[0m [0mSHOW FIELDS FROM `recorded`[0m
[4;36;1mRecorded Load (0.017853)[0m [0;1mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.47058 (2 reqs/sec) | Rendering: 0.42868 (91%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 11:33:38) [GET]
Session ID: a163f96e0387b82eb9b0c2e0d52620c1
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;35;1mSQL (0.000212)[0m [0mSET SQL_AUTO_IS_NULL=0[0m
[4;36;1mRecorded Columns (0.006708)[0m [0;1mSHOW FIELDS FROM `recorded`[0m
[4;35;1mRecorded Load (0.019289)[0m [0mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.50263 (1 reqs/sec) | Rendering: 0.41979 (83%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 11:33:48) [GET]
Session ID: ecd9249008f47b6eb5e2628ba81afd25
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;36;1mSQL (0.000208)[0m [0;1mSET SQL_AUTO_IS_NULL=0[0m
[4;35;1mRecorded Columns (0.006686)[0m [0mSHOW FIELDS FROM `recorded`[0m
[4;36;1mRecorded Load (0.014986)[0m [0;1mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.45161 (2 reqs/sec) | Rendering: 0.41124 (91%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 11:34:50) [GET]
Session ID: d3705297337886a5189d554ec78f91ef
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;35;1mSQL (0.000209)[0m [0mSET SQL_AUTO_IS_NULL=0[0m
[4;36;1mRecorded Columns (0.005303)[0m [0;1mSHOW FIELDS FROM `recorded`[0m
[4;35;1mRecorded Load (0.011890)[0m [0mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.45024 (2 reqs/sec) | Rendering: 0.37536 (83%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 11:35:15) [GET]
Session ID: ba89f27f7725a01a1f2aa51335aa8dd8
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;36;1mSQL (0.000212)[0m [0;1mSET SQL_AUTO_IS_NULL=0[0m
[4;35;1mRecorded Columns (0.006613)[0m [0mSHOW FIELDS FROM `recorded`[0m
[4;36;1mRecorded Load (0.022627)[0m [0;1mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.46104 (2 reqs/sec) | Rendering: 0.41362 (89%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 11:35:26) [GET]
Session ID: cd4be35fe7533cd5d0b87c5ddcc5ad08
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;35;1mSQL (0.000241)[0m [0mSET SQL_AUTO_IS_NULL=0[0m
[4;36;1mRecorded Columns (0.005863)[0m [0;1mSHOW FIELDS FROM `recorded`[0m
[4;35;1mRecorded Load (0.020195)[0m [0mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.54839 (1 reqs/sec) | Rendering: 0.41518 (75%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 11:38:01) [GET]
Session ID: 49446b4f78330701884951b58f700d32
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;36;1mSQL (0.000214)[0m [0;1mSET SQL_AUTO_IS_NULL=0[0m
[4;35;1mRecorded Columns (0.004832)[0m [0mSHOW FIELDS FROM `recorded`[0m
[4;36;1mRecorded Load (0.018171)[0m [0;1mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.50120 (1 reqs/sec) | Rendering: 0.41785 (83%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 11:38:48) [GET]
Session ID: 8bf43ed0b0252ff6f170d8d05f73dff1
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;35;1mSQL (0.000216)[0m [0mSET SQL_AUTO_IS_NULL=0[0m
[4;36;1mRecorded Columns (0.006135)[0m [0;1mSHOW FIELDS FROM `recorded`[0m
[4;35;1mRecorded Load (0.017876)[0m [0mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.46345 (2 reqs/sec) | Rendering: 0.42069 (90%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 11:40:26) [GET]
Session ID: 8925a8a163c9066b5e1c76d19214fa67
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;36;1mSQL (0.000228)[0m [0;1mSET SQL_AUTO_IS_NULL=0[0m
[4;35;1mRecorded Columns (0.006211)[0m [0mSHOW FIELDS FROM `recorded`[0m
[4;36;1mRecorded Load (0.014552)[0m [0;1mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.48774 (2 reqs/sec) | Rendering: 0.41157 (84%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 11:54:57) [GET]
Session ID: d1183825e52e705434c3da163d34afe7
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;35;1mSQL (0.000213)[0m [0mSET SQL_AUTO_IS_NULL=0[0m
[4;36;1mRecorded Columns (0.005114)[0m [0;1mSHOW FIELDS FROM `recorded`[0m
[4;35;1mRecorded Load (0.018523)[0m [0mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.49178 (2 reqs/sec) | Rendering: 0.44385 (90%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 11:55:39) [GET]
Session ID: acee5cf5aabf2a277af117001f94e2d0
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;36;1mSQL (0.000214)[0m [0;1mSET SQL_AUTO_IS_NULL=0[0m
[4;35;1mRecorded Columns (0.013211)[0m [0mSHOW FIELDS FROM `recorded`[0m
[4;36;1mRecorded Load (0.068264)[0m [0;1mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.56224 (1 reqs/sec) | Rendering: 0.46038 (81%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 11:56:26) [GET]
Session ID: 7da484b9bcdd48a2ff38151d862ff1c0
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;35;1mSQL (0.000224)[0m [0mSET SQL_AUTO_IS_NULL=0[0m
[4;36;1mRecorded Columns (0.006564)[0m [0;1mSHOW FIELDS FROM `recorded`[0m
[4;35;1mRecorded Load (0.016775)[0m [0mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.48144 (2 reqs/sec) | Rendering: 0.43910 (91%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 11:59:29) [GET]
Session ID: f697220543e7c4fb071ee00d36536cdb
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;36;1mSQL (0.000267)[0m [0;1mSET SQL_AUTO_IS_NULL=0[0m
[4;35;1mRecorded Columns (0.049539)[0m [0mSHOW FIELDS FROM `recorded`[0m
[4;36;1mRecorded Load (0.084114)[0m [0;1mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 1.73244 (0 reqs/sec) | Rendering: 1.50438 (86%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 12:00:07) [GET]
Session ID: 64b7becdaa9785c81c7d008eefcb6620
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;35;1mSQL (0.000208)[0m [0mSET SQL_AUTO_IS_NULL=0[0m
[4;36;1mRecorded Columns (0.005231)[0m [0;1mSHOW FIELDS FROM `recorded`[0m
[4;35;1mRecorded Load (0.017353)[0m [0mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.57167 (1 reqs/sec) | Rendering: 0.47648 (83%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 12:08:37) [GET]
Session ID: 8e3547287835b37566b1a88347819eb2
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;36;1mSQL (0.000228)[0m [0;1mSET SQL_AUTO_IS_NULL=0[0m
[4;35;1mRecorded Columns (0.007953)[0m [0mSHOW FIELDS FROM `recorded`[0m
[4;36;1mRecorded Load (0.014726)[0m [0;1mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.51595 (1 reqs/sec) | Rendering: 0.47244 (91%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 12:09:35) [GET]
Session ID: 1837217c4669297270d387b8bf53c2bd
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;35;1mSQL (0.000213)[0m [0mSET SQL_AUTO_IS_NULL=0[0m
[4;36;1mRecorded Columns (0.006788)[0m [0;1mSHOW FIELDS FROM `recorded`[0m
[4;35;1mRecorded Load (0.013579)[0m [0mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.53481 (1 reqs/sec) | Rendering: 0.45632 (85%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 12:11:07) [GET]
Session ID: 1ef306a47f939cd4ab0b54291069c45f
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;36;1mSQL (0.000211)[0m [0;1mSET SQL_AUTO_IS_NULL=0[0m
[4;35;1mRecorded Columns (0.004976)[0m [0mSHOW FIELDS FROM `recorded`[0m
[4;36;1mRecorded Load (0.015357)[0m [0;1mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.45968 (2 reqs/sec) | Rendering: 0.42083 (91%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 12:13:32) [GET]
Session ID: 102cd1e65004b9b939b00f6d517e7fed
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;35;1mSQL (0.000217)[0m [0mSET SQL_AUTO_IS_NULL=0[0m
[4;36;1mRecorded Columns (0.007190)[0m [0;1mSHOW FIELDS FROM `recorded`[0m
[4;35;1mRecorded Load (0.013665)[0m [0mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.50814 (1 reqs/sec) | Rendering: 0.42954 (84%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 12:14:29) [GET]
Session ID: 93000d4167b99f6a4cd576674d85c7b6
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;36;1mSQL (0.000213)[0m [0;1mSET SQL_AUTO_IS_NULL=0[0m
[4;35;1mRecorded Columns (0.006791)[0m [0mSHOW FIELDS FROM `recorded`[0m
[4;36;1mRecorded Load (0.020211)[0m [0;1mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.47141 (2 reqs/sec) | Rendering: 0.42513 (90%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 12:15:54) [GET]
Session ID: aa415310940bedb1b6b0343669508165
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;35;1mSQL (0.000217)[0m [0mSET SQL_AUTO_IS_NULL=0[0m
[4;36;1mRecorded Columns (0.007235)[0m [0;1mSHOW FIELDS FROM `recorded`[0m
[4;35;1mRecorded Load (0.065507)[0m [0mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.48170 (2 reqs/sec) | Rendering: 0.38996 (80%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 12:17:00) [GET]
Session ID: 8a3c035ee27c0ffaad8bf37ff0e2cc53
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;36;1mSQL (0.000214)[0m [0;1mSET SQL_AUTO_IS_NULL=0[0m
[4;35;1mRecorded Columns (0.005192)[0m [0mSHOW FIELDS FROM `recorded`[0m
[4;36;1mRecorded Load (0.015370)[0m [0;1mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.53494 (1 reqs/sec) | Rendering: 0.49652 (92%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 12:18:32) [GET]
Session ID: 145163c4bc6acaf2d0ebdd5313cda2c2
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;35;1mSQL (0.000267)[0m [0mSET SQL_AUTO_IS_NULL=0[0m
[4;36;1mRecorded Columns (0.004702)[0m [0;1mSHOW FIELDS FROM `recorded`[0m
[4;35;1mRecorded Load (0.051252)[0m [0mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.52361 (1 reqs/sec) | Rendering: 0.44962 (85%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 12:19:34) [GET]
Session ID: 87189a0be0a58035fa6c6d0c95c14db0
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;36;1mSQL (0.000212)[0m [0;1mSET SQL_AUTO_IS_NULL=0[0m
[4;35;1mRecorded Columns (0.004732)[0m [0mSHOW FIELDS FROM `recorded`[0m
[4;36;1mRecorded Load (0.012270)[0m [0;1mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.46296 (2 reqs/sec) | Rendering: 0.42707 (92%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 12:21:29) [GET]
Session ID: a64ed05aafb15b31e88949cf12d9e95d
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;35;1mSQL (0.000212)[0m [0mSET SQL_AUTO_IS_NULL=0[0m
[4;36;1mRecorded Columns (0.006758)[0m [0;1mSHOW FIELDS FROM `recorded`[0m
[4;35;1mRecorded Load (0.012161)[0m [0mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.45735 (2 reqs/sec) | Rendering: 0.42061 (91%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 12:22:51) [GET]
Session ID: 272fd9797ddffc50575c43bf3a754d3e
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;36;1mSQL (0.000211)[0m [0;1mSET SQL_AUTO_IS_NULL=0[0m
[4;35;1mRecorded Columns (0.012048)[0m [0mSHOW FIELDS FROM `recorded`[0m
[4;36;1mRecorded Load (0.011918)[0m [0;1mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.49845 (2 reqs/sec) | Rendering: 0.41553 (83%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 12:25:21) [GET]
Session ID: aa942c28a21a64174bc8928b7a25cc05
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;35;1mSQL (0.000212)[0m [0mSET SQL_AUTO_IS_NULL=0[0m
[4;36;1mRecorded Columns (0.019553)[0m [0;1mSHOW FIELDS FROM `recorded`[0m
[4;35;1mRecorded Load (0.157259)[0m [0mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.62083 (1 reqs/sec) | Rendering: 0.42581 (68%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#get_recording (for 127.0.0.1 at 2008-04-15 12:26:57) [GET]
Session ID: c697e90d271b6b7c0a3a6d251c55fb72
Parameters: {"chanid"=>"1009", "action"=>"get_recording", "controller"=>"recorded", "starttime"=>"1208127600"}
[4;36;1mSQL (0.000227)[0m [0;1mSET SQL_AUTO_IS_NULL=0[0m
[4;35;1mRecorded Columns (0.044844)[0m [0mSHOW FIELDS FROM `recorded`[0m
[4;36;1mRecorded Load (0.003854)[0m [0;1mSELECT * FROM `recorded` WHERE (`recorded`.`chanid` = '1009' AND `recorded`.`starttime` = '2008-04-13 19:00:00') LIMIT 1[0m
Completed in 0.09422 (10 reqs/sec) | Rendering: 0.01076 (11%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/1009/1208127600]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 12:33:20) [GET]
Session ID: 7eedfe0755da273f8b9782dc16a726cc
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;35;1mSQL (0.000254)[0m [0mSET SQL_AUTO_IS_NULL=0[0m
[4;36;1mRecorded Columns (0.004756)[0m [0;1mSHOW FIELDS FROM `recorded`[0m
[4;35;1mRecorded Load (0.015237)[0m [0mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.58914 (1 reqs/sec) | Rendering: 0.53884 (91%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 12:48:40) [GET]
Session ID: 6a78f3d104382103232923fb3e6fca7f
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;36;1mSQL (0.000225)[0m [0;1mSET SQL_AUTO_IS_NULL=0[0m
[4;35;1mRecorded Columns (0.005773)[0m [0mSHOW FIELDS FROM `recorded`[0m
[4;36;1mRecorded Load (0.021231)[0m [0;1mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.55205 (1 reqs/sec) | Rendering: 0.42917 (77%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 12:51:20) [GET]
Session ID: 0b35fec36647caf7f98a9afe0df0441c
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;35;1mSQL (0.000259)[0m [0mSET SQL_AUTO_IS_NULL=0[0m
[4;36;1mRecorded Columns (0.005948)[0m [0;1mSHOW FIELDS FROM `recorded`[0m
[4;35;1mRecorded Load (0.016111)[0m [0mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.51094 (1 reqs/sec) | Rendering: 0.46552 (91%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 12:55:44) [GET]
Session ID: daf60f904e342cc4a434014b361f0c2f
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;36;1mSQL (0.000233)[0m [0;1mSET SQL_AUTO_IS_NULL=0[0m
[4;35;1mRecorded Columns (0.007239)[0m [0mSHOW FIELDS FROM `recorded`[0m
[4;36;1mRecorded Load (0.059568)[0m [0;1mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.49084 (2 reqs/sec) | Rendering: 0.40463 (82%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 12:57:44) [GET]
Session ID: 56de1c6c07afc796a469c37daaed2769
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;35;1mSQL (0.000213)[0m [0mSET SQL_AUTO_IS_NULL=0[0m
[4;36;1mRecorded Columns (0.006592)[0m [0;1mSHOW FIELDS FROM `recorded`[0m
[4;35;1mRecorded Load (0.020025)[0m [0mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.53679 (1 reqs/sec) | Rendering: 0.48845 (90%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 12:59:25) [GET]
Session ID: d9c0b9bd6848c77daa03fe9e2a7767c3
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;36;1mSQL (0.000213)[0m [0;1mSET SQL_AUTO_IS_NULL=0[0m
[4;35;1mRecorded Columns (0.005529)[0m [0mSHOW FIELDS FROM `recorded`[0m
[4;36;1mRecorded Load (0.018344)[0m [0;1mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.47828 (2 reqs/sec) | Rendering: 0.43564 (91%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 13:00:05) [GET]
Session ID: ac50303889b657157e8ea27c7dd0fcd7
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;35;1mSQL (0.000268)[0m [0mSET SQL_AUTO_IS_NULL=0[0m
[4;36;1mRecorded Columns (0.005403)[0m [0;1mSHOW FIELDS FROM `recorded`[0m
[4;35;1mRecorded Load (0.014499)[0m [0mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.62542 (1 reqs/sec) | Rendering: 0.54179 (86%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 13:01:51) [GET]
Session ID: 5482de9753d9b2e8a6d523e5c185e891
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;36;1mSQL (0.000326)[0m [0;1mSET SQL_AUTO_IS_NULL=0[0m
[4;35;1mRecorded Columns (0.006715)[0m [0mSHOW FIELDS FROM `recorded`[0m
[4;36;1mRecorded Load (0.025794)[0m [0;1mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.49629 (2 reqs/sec) | Rendering: 0.44330 (89%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 13:02:09) [GET]
Session ID: b5520d02807b4c51392bd5fb2dc2d174
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;35;1mSQL (0.000210)[0m [0mSET SQL_AUTO_IS_NULL=0[0m
[4;36;1mRecorded Columns (0.007137)[0m [0;1mSHOW FIELDS FROM `recorded`[0m
[4;35;1mRecorded Load (0.014336)[0m [0mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.52401 (1 reqs/sec) | Rendering: 0.43916 (83%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 13:03:14) [GET]
Session ID: 94ee5c0d5a811b184889e71767e7a571
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;36;1mSQL (0.000212)[0m [0;1mSET SQL_AUTO_IS_NULL=0[0m
[4;35;1mRecorded Columns (0.006428)[0m [0mSHOW FIELDS FROM `recorded`[0m
[4;36;1mRecorded Load (0.024135)[0m [0;1mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.52006 (1 reqs/sec) | Rendering: 0.46943 (90%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 13:03:58) [GET]
Session ID: 302d9a27f61cfc0cd3b5a0277b0a3634
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;35;1mSQL (0.000321)[0m [0mSET SQL_AUTO_IS_NULL=0[0m
[4;36;1mRecorded Columns (0.006941)[0m [0;1mSHOW FIELDS FROM `recorded`[0m
[4;35;1mRecorded Load (0.023033)[0m [0mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.54527 (1 reqs/sec) | Rendering: 0.45304 (83%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 13:04:46) [GET]
Session ID: 928ad75e020c67bb365c3908ef1d48fc
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;36;1mSQL (0.000254)[0m [0;1mSET SQL_AUTO_IS_NULL=0[0m
[4;35;1mRecorded Columns (0.007597)[0m [0mSHOW FIELDS FROM `recorded`[0m
[4;36;1mRecorded Load (0.019036)[0m [0;1mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.50284 (1 reqs/sec) | Rendering: 0.45807 (91%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 13:05:15) [GET]
Session ID: a8090098ec41be2eabd7d2215aa03574
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;35;1mSQL (0.000211)[0m [0mSET SQL_AUTO_IS_NULL=0[0m
[4;36;1mRecorded Columns (0.005114)[0m [0;1mSHOW FIELDS FROM `recorded`[0m
[4;35;1mRecorded Load (0.015182)[0m [0mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 1.14284 (0 reqs/sec) | Rendering: 0.56257 (49%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 15:03:55) [GET]
Session ID: 33cdbe1c6b2b55dcc267d4b10c234fcd
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
WARNING: You're using the Ruby-based MySQL library that ships with Rails. This library is not suited for production. Please install the C-based MySQL library instead (gem install mysql).
[4;36;1mSQL (0.000206)[0m [0;1mSET NAMES 'utf8'[0m
[4;35;1mSQL (0.000170)[0m [0mSET SQL_AUTO_IS_NULL=0[0m
[4;36;1mSQL (0.000258)[0m [0;1mSET SQL_AUTO_IS_NULL=0[0m
[4;35;1mRecorded Columns (0.006056)[0m [0mSHOW FIELDS FROM `recorded`[0m
[4;36;1mRecorded Load (0.014423)[0m [0;1mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.44647 (2 reqs/sec) | Rendering: 0.38600 (86%) | DB: 0.00038 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 15:15:31) [GET]
Session ID: a6441c5d90072bae974cf5eed16ddc89
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;35;1mSQL (0.000210)[0m [0mSET SQL_AUTO_IS_NULL=0[0m
[4;36;1mRecorded Columns (0.004652)[0m [0;1mSHOW FIELDS FROM `recorded`[0m
[4;35;1mRecorded Load (0.014483)[0m [0mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.48094 (2 reqs/sec) | Rendering: 0.42055 (87%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#get_recording (for 127.0.0.1 at 2008-04-15 15:16:07) [GET]
Session ID: 7d2e8a65c19640a6528d546ed45519a3
Parameters: {"chanid"=>"1003", "action"=>"get_recording", "controller"=>"recorded", "starttime"=>"1208138520"}
[4;36;1mSQL (0.000210)[0m [0;1mSET SQL_AUTO_IS_NULL=0[0m
[4;35;1mRecorded Columns (0.004561)[0m [0mSHOW FIELDS FROM `recorded`[0m
[4;36;1mRecorded Load (0.002411)[0m [0;1mSELECT * FROM `recorded` WHERE (`recorded`.`starttime` = '2008-04-13 22:02:00' AND `recorded`.`chanid` = '1003') LIMIT 1[0m
Completed in 0.03757 (26 reqs/sec) | Rendering: 0.01532 (40%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/1003/1208138520]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 15:16:13) [GET]
Session ID: 0ee08b809867dc3c059ccde387530fcc
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;35;1mSQL (0.000213)[0m [0mSET SQL_AUTO_IS_NULL=0[0m
[4;36;1mRecorded Columns (0.006212)[0m [0;1mSHOW FIELDS FROM `recorded`[0m
[4;35;1mRecorded Load (0.013816)[0m [0mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.46581 (2 reqs/sec) | Rendering: 0.38904 (83%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 15:17:13) [GET]
Session ID: 24b719d5482fac57f26ceac1577944ba
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;36;1mSQL (0.000248)[0m [0;1mSET SQL_AUTO_IS_NULL=0[0m
[4;35;1mRecorded Columns (0.006188)[0m [0mSHOW FIELDS FROM `recorded`[0m
[4;36;1mRecorded Load (0.014812)[0m [0;1mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.46875 (2 reqs/sec) | Rendering: 0.42925 (91%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 15:20:52) [GET]
Session ID: cb6cc940338e7f58c7cda088a2a03d0e
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;35;1mSQL (0.000216)[0m [0mSET SQL_AUTO_IS_NULL=0[0m
[4;36;1mRecorded Columns (0.004568)[0m [0;1mSHOW FIELDS FROM `recorded`[0m
[4;35;1mRecorded Load (0.011564)[0m [0mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.46678 (2 reqs/sec) | Rendering: 0.43231 (92%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 15:24:11) [GET]
Session ID: 9248b2a0816b2409c560cc6f974fa2f0
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;36;1mSQL (0.000210)[0m [0;1mSET SQL_AUTO_IS_NULL=0[0m
[4;35;1mRecorded Columns (0.004609)[0m [0mSHOW FIELDS FROM `recorded`[0m
[4;36;1mRecorded Load (0.049392)[0m [0;1mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.46664 (2 reqs/sec) | Rendering: 0.39409 (84%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 15:24:52) [GET]
Session ID: 2f6108f5bcab18857e85551f745e785e
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;35;1mSQL (0.000217)[0m [0mSET SQL_AUTO_IS_NULL=0[0m
[4;36;1mRecorded Columns (0.004741)[0m [0;1mSHOW FIELDS FROM `recorded`[0m
[4;35;1mRecorded Load (0.015023)[0m [0mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.46167 (2 reqs/sec) | Rendering: 0.38614 (83%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 15:25:06) [GET]
Session ID: 1ee776137b7925bfd53550676bdaf9fd
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;36;1mSQL (0.000538)[0m [0;1mSET SQL_AUTO_IS_NULL=0[0m
[4;35;1mRecorded Columns (0.006599)[0m [0mSHOW FIELDS FROM `recorded`[0m
[4;36;1mRecorded Load (0.015674)[0m [0;1mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.57671 (1 reqs/sec) | Rendering: 0.53449 (92%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 16:08:28) [GET]
Session ID: d7db726f04e867a09feab8a138ba5ccf
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;35;1mSQL (0.000215)[0m [0mSET SQL_AUTO_IS_NULL=0[0m
[4;36;1mRecorded Columns (0.004626)[0m [0;1mSHOW FIELDS FROM `recorded`[0m
[4;35;1mRecorded Load (0.011644)[0m [0mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.46232 (2 reqs/sec) | Rendering: 0.42808 (92%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 16:08:34) [GET]
Session ID: a1feee64057af89ffb20ac557b96a876
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;36;1mSQL (0.000213)[0m [0;1mSET SQL_AUTO_IS_NULL=0[0m
[4;35;1mRecorded Columns (0.004622)[0m [0mSHOW FIELDS FROM `recorded`[0m
[4;36;1mRecorded Load (0.011990)[0m [0;1mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.46147 (2 reqs/sec) | Rendering: 0.42616 (92%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 17:05:08) [GET]
Session ID: 332cb763e461941eac4f71b9cff6f053
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;35;1mSQL (0.000311)[0m [0mSET SQL_AUTO_IS_NULL=0[0m
[4;36;1mRecorded Columns (0.005967)[0m [0;1mSHOW FIELDS FROM `recorded`[0m
[4;35;1mRecorded Load (0.016123)[0m [0mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.46425 (2 reqs/sec) | Rendering: 0.38356 (82%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 19:44:30) [GET]
Session ID: d7a4cc310b1dae902c19801d132f4bdf
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;36;1mSQL (0.000262)[0m [0;1mSET SQL_AUTO_IS_NULL=0[0m
[4;35;1mRecorded Columns (0.005834)[0m [0mSHOW FIELDS FROM `recorded`[0m
[4;36;1mRecorded Load (0.014632)[0m [0;1mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.49230 (2 reqs/sec) | Rendering: 0.43222 (87%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 20:10:03) [GET]
Session ID: 2d0ea5ebd66f3c6b049ad31b4ad0f4ef
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;35;1mSQL (0.000221)[0m [0mSET SQL_AUTO_IS_NULL=0[0m
[4;36;1mRecorded Columns (0.004677)[0m [0;1mSHOW FIELDS FROM `recorded`[0m
[4;35;1mRecorded Load (0.014531)[0m [0mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.50681 (1 reqs/sec) | Rendering: 0.44726 (88%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 20:14:52) [GET]
Session ID: abde5b8706ac77ba84226c25066f38ff
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;36;1mSQL (0.000276)[0m [0;1mSET SQL_AUTO_IS_NULL=0[0m
[4;35;1mRecorded Columns (0.006808)[0m [0mSHOW FIELDS FROM `recorded`[0m
[4;36;1mRecorded Load (0.013298)[0m [0;1mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.52507 (1 reqs/sec) | Rendering: 0.42052 (80%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 20:15:26) [GET]
Session ID: 4c2da06fe19b3d41a3b31293c686ae3a
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;35;1mSQL (0.000218)[0m [0mSET SQL_AUTO_IS_NULL=0[0m
[4;36;1mRecorded Columns (0.006193)[0m [0;1mSHOW FIELDS FROM `recorded`[0m
[4;35;1mRecorded Load (0.015748)[0m [0mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.46971 (2 reqs/sec) | Rendering: 0.38872 (82%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
Processing RecordedController#list (for 127.0.0.1 at 2008-04-15 20:29:54) [GET]
Session ID: 14a1f88810446acb2a7f335591e81bad
Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
[4;36;1mSQL (0.000214)[0m [0;1mSET SQL_AUTO_IS_NULL=0[0m
[4;35;1mRecorded Columns (0.006202)[0m [0mSHOW FIELDS FROM `recorded`[0m
[4;36;1mRecorded Load (0.024766)[0m [0;1mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
Completed in 0.48820 (2 reqs/sec) | Rendering: 0.43759 (89%) | DB: 0.00000 (0%) | 200 OK [http://localhost/recorded/list?order=starttime+DESC]
+ [4;36;1mSQL (0.000172)[0m [0;1mSET NAMES 'utf8'[0m
+ [4;35;1mSQL (0.000087)[0m [0mSET SQL_AUTO_IS_NULL=0[0m
+ [4;36;1mSQL (0.004762)[0m [0;1mCREATE TABLE `schema_info` (version int(11))[0m
+ [4;35;1mSQL (0.000419)[0m [0mINSERT INTO `schema_info` (version) VALUES(0)[0m
+ [4;36;1mSQL (0.000000)[0m [0;1mMysql::Error: Table 'schema_info' already exists: CREATE TABLE `schema_info` (version int(11))[0m
+ [4;35;1mSQL (0.000408)[0m [0mSELECT * FROM schema_info[0m
+ [4;36;1mSQL (0.000347)[0m [0;1mSHOW TABLES[0m
+
+
+Processing RecordedController#list (for 192.168.1.128 at 2008-04-15 22:13:22) [GET]
+ Session ID: ba22922c8bfb2d914d0dbf974d8dfe60
+ Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
+ [4;36;1mSQL (0.000166)[0m [0;1mSET NAMES 'utf8'[0m
+ [4;35;1mSQL (0.000089)[0m [0mSET SQL_AUTO_IS_NULL=0[0m
+ [4;36;1mSQL (0.000129)[0m [0;1mSET SQL_AUTO_IS_NULL=0[0m
+ [4;35;1mRecorded Columns (0.002872)[0m [0mSHOW FIELDS FROM `recorded`[0m
+ [4;36;1mRecorded Load (0.002098)[0m [0;1mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
+Completed in 0.60907 (1 reqs/sec) | Rendering: 0.57784 (94%) | DB: 0.00026 (0%) | 200 OK [http://192.168.1.120/recorded/list?order=starttime+DESC]
+
+
+Processing RecordedController#list (for 192.168.1.128 at 2008-04-15 22:47:33) [GET]
+ Session ID: ed5fb0eb1f4d9ec95491655670c742cf
+ Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
+ [4;35;1mSQL (0.000130)[0m [0mSET SQL_AUTO_IS_NULL=0[0m
+ [4;36;1mRecorded Columns (0.002868)[0m [0;1mSHOW FIELDS FROM `recorded`[0m
+ [4;35;1mRecorded Load (0.000417)[0m [0mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
+Completed in 0.71818 (1 reqs/sec) | Rendering: 0.60573 (84%) | DB: 0.00000 (0%) | 200 OK [http://192.168.1.120/recorded/list?order=starttime+DESC]
+
+
+Processing RecordedController#list (for 192.168.1.128 at 2008-04-15 22:48:14) [GET]
+ Session ID: 460d00aa52419b1693927bea8f202fab
+ Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
+ [4;36;1mSQL (0.000129)[0m [0;1mSET SQL_AUTO_IS_NULL=0[0m
+ [4;35;1mRecorded Columns (0.002971)[0m [0mSHOW FIELDS FROM `recorded`[0m
+ [4;36;1mRecorded Load (0.000416)[0m [0;1mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
+Completed in 0.61123 (1 reqs/sec) | Rendering: 0.58043 (94%) | DB: 0.00000 (0%) | 200 OK [http://192.168.1.120/recorded/list?order=starttime+DESC]
+ActiveMessaging: adapter reliable_msg not loaded: no such file to load -- reliable-msg
+ActiveMessaging: adapter wmq not loaded: no such file to load -- wmq/wmq
+ActiveMessaging: no '/home/cjmartin/Rails/mythapi/config/messaging.rb' file to load
+ActiveMessaging: Loading /home/cjmartin/Rails/mythapi/app/processors/application.rb
+ActiveMessaging: adapter reliable_msg not loaded: no such file to load -- reliable-msg
+ActiveMessaging: adapter wmq not loaded: no such file to load -- wmq/wmq
+ActiveMessaging: no '/home/cjmartin/Rails/mythapi/config/messaging.rb' file to load
+ActiveMessaging: Loading /home/cjmartin/Rails/mythapi/app/processors/application.rb
+ [4;36;1mSQL (0.000163)[0m [0;1mSET NAMES 'utf8'[0m
+ [4;35;1mSQL (0.000084)[0m [0mSET SQL_AUTO_IS_NULL=0[0m
+ [4;36;1mSQL (0.000000)[0m [0;1mMysql::Error: Table 'schema_info' already exists: CREATE TABLE `schema_info` (version int(11))[0m
+ [4;35;1mSQL (0.000000)[0m [0mMysql::Error: Table 'schema_info' already exists: CREATE TABLE `schema_info` (version int(11))[0m
+ [4;36;1mSQL (0.000637)[0m [0;1mSELECT version FROM schema_info[0m
+Migrating to CreateVideos (1)
+ [4;35;1mSQL (0.004751)[0m [0mCREATE TABLE `videos` (`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY, `height` int(11) DEFAULT NULL, `width` int(11) DEFAULT NULL, `video_url` varchar(255) DEFAULT NULL, `file_name` varchar(255) DEFAULT NULL, `ext` varchar(255) DEFAULT NULL, `created_at` datetime DEFAULT NULL, `updated_at` datetime DEFAULT NULL) ENGINE=InnoDB[0m
+ [4;36;1mSQL (0.000344)[0m [0;1mUPDATE schema_info SET version = 1[0m
+ [4;35;1mSQL (0.000386)[0m [0mSELECT * FROM schema_info[0m
+ [4;36;1mSQL (0.000344)[0m [0;1mSHOW TABLES[0m
+ [4;35;1mSQL (0.004869)[0m [0mSHOW FIELDS FROM `videos`[0m
+ [4;36;1mSQL (0.001367)[0m [0;1mdescribe `videos`[0m
+ [4;35;1mSQL (0.000490)[0m [0mSHOW KEYS FROM `videos`[0m
+
+
+Processing ApplicationController#index (for 127.0.0.1 at 2008-04-15 23:21:48) [GET]
+ Session ID: 7ea48a3a82f92b1f50c18dd32b893899
+ Parameters: {}
+
+
+ActionController::RoutingError (No route matches "/video" with {:method=>:get}):
+ /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/routing.rb:1441:in `recognize_path'
+ /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/routing.rb:1424:in `recognize'
+ /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:170:in `handle_request'
+ /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:115:in `dispatch'
+ /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:126:in `dispatch_cgi'
+ /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:9:in `dispatch'
+ /var/lib/gems/1.8/gems/mongrel-1.1.4/bin/../lib/mongrel/rails.rb:76:in `process'
+ /var/lib/gems/1.8/gems/mongrel-1.1.4/bin/../lib/mongrel/rails.rb:74:in `synchronize'
+ /var/lib/gems/1.8/gems/mongrel-1.1.4/bin/../lib/mongrel/rails.rb:74:in `process'
+ /var/lib/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:159:in `process_client'
+ /var/lib/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:158:in `each'
+ /var/lib/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:158:in `process_client'
+ /var/lib/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in `run'
+ /var/lib/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in `initialize'
+ /var/lib/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in `new'
+ /var/lib/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in `run'
+ /var/lib/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:268:in `initialize'
+ /var/lib/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:268:in `new'
+ /var/lib/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:268:in `run'
+ /var/lib/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/configurator.rb:282:in `run'
+ /var/lib/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/configurator.rb:281:in `each'
+ /var/lib/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/configurator.rb:281:in `run'
+ /var/lib/gems/1.8/gems/mongrel-1.1.4/bin/mongrel_rails:128:in `run'
+ /var/lib/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/command.rb:212:in `run'
+ /var/lib/gems/1.8/gems/mongrel-1.1.4/bin/mongrel_rails:281
+ /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load'
+ /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load'
+ /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
+ /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:489:in `load'
+ /var/lib/gems/1.8/gems/rails-2.0.2/lib/commands/servers/mongrel.rb:64
+ /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
+ /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `require'
+ /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
+ /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
+ /var/lib/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `require'
+ /var/lib/gems/1.8/gems/rails-2.0.2/lib/commands/server.rb:39
+ /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
+ /usr/lib/ruby/1.8/rubygems/custom_require.rb:27:in `require'
+ script/server:3
+
+Rendering /var/lib/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/templates/rescues/layout.erb (not_found)
+
+
+Processing VideosController#index (for 127.0.0.1 at 2008-04-15 23:21:53) [GET]
+ Session ID: BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo%0ASGFzaHsABjoKQHVzZWR7AA%3D%3D--e76f6d93fca0b972d1beaf36ae1016b387cedcd4
+ Parameters: {"action"=>"index", "controller"=>"videos"}
+ [4;36;1mSQL (0.000421)[0m [0;1mSET NAMES 'utf8'[0m
+ [4;35;1mSQL (0.002602)[0m [0mSET SQL_AUTO_IS_NULL=0[0m
+ [4;36;1mVideo Load (0.000529)[0m [0;1mSELECT * FROM `videos` [0m
+Rendering template within layouts/videos
+Rendering videos/index
+Completed in 0.03610 (27 reqs/sec) | Rendering: 0.01293 (35%) | DB: 0.00355 (9%) | 200 OK [http://localhost/videos]
+
+
+Processing VideosController#new (for 127.0.0.1 at 2008-04-15 23:22:02) [GET]
+ Session ID: BAh7BiIKZmxhc2hJQzonQWN0aW9uQ29udHJvbGxlcjo6Rmxhc2g6OkZsYXNo%0ASGFzaHsABjoKQHVzZWR7AA%3D%3D--e76f6d93fca0b972d1beaf36ae1016b387cedcd4
+ Parameters: {"action"=>"new", "controller"=>"videos"}
+ [4;35;1mVideo Columns (0.001477)[0m [0mSHOW FIELDS FROM `videos`[0m
+Rendering template within layouts/videos
+Rendering videos/new
+Completed in 0.02194 (45 reqs/sec) | Rendering: 0.00975 (44%) | DB: 0.00148 (6%) | 200 OK [http://localhost/videos/new]
+ActiveMessaging: adapter reliable_msg not loaded: no such file to load -- reliable-msg
+ActiveMessaging: adapter wmq not loaded: no such file to load -- wmq/wmq
+ActiveMessaging: no '/home/cjmartin/Rails/mythapi/config/messaging.rb' file to load
+ActiveMessaging: Loading /home/cjmartin/Rails/mythapi/app/processors/application.rb
+ [4;36;1mSQL (0.000119)[0m [0;1mSET NAMES 'utf8'[0m
+ [4;35;1mSQL (0.000086)[0m [0mSET SQL_AUTO_IS_NULL=0[0m
+
+
+Processing RecordedController#list (for 128.61.18.130 at 2008-04-16 10:02:01) [GET]
+ Session ID: 1a02e08f5afccdc145926739d07a2d31
+ Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
+ [4;36;1mSQL (0.000151)[0m [0;1mSET SQL_AUTO_IS_NULL=0[0m
+ [4;35;1mRecorded Columns (0.003001)[0m [0mSHOW FIELDS FROM `recorded`[0m
+ [4;36;1mRecorded Load (0.002102)[0m [0;1mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
+Completed in 0.81370 (1 reqs/sec) | Rendering: 0.72266 (88%) | DB: 0.00020 (0%) | 200 OK [http://home.cjmart.in/recorded/list?order=starttime+DESC]
+
+
+Processing RecordedController#list (for 128.61.18.130 at 2008-04-16 10:05:30) [GET]
+ Session ID: 45459b15d54305f15d9502d80b3aa904
+ Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
+ [4;35;1mSQL (0.000130)[0m [0mSET SQL_AUTO_IS_NULL=0[0m
+ [4;36;1mRecorded Columns (0.003869)[0m [0;1mSHOW FIELDS FROM `recorded`[0m
+ [4;35;1mRecorded Load (0.000420)[0m [0mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
+Completed in 0.64326 (1 reqs/sec) | Rendering: 0.61247 (95%) | DB: 0.00000 (0%) | 200 OK [http://home.cjmart.in/recorded/list?order=starttime+DESC]
+
+
+Processing RecordedController#list (for 128.61.18.130 at 2008-04-16 10:05:39) [GET]
+ Session ID: 6df1ecc2cdb7e8666af336e8e4c8be3f
+ Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
+ [4;36;1mSQL (0.000132)[0m [0;1mSET SQL_AUTO_IS_NULL=0[0m
+ [4;35;1mRecorded Columns (0.002879)[0m [0mSHOW FIELDS FROM `recorded`[0m
+ [4;36;1mRecorded Load (0.000415)[0m [0;1mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
+Completed in 0.74697 (1 reqs/sec) | Rendering: 0.71808 (96%) | DB: 0.00000 (0%) | 200 OK [http://home.cjmart.in/recorded/list?order=starttime+DESC]
+
+
+Processing RecordedController#list (for 128.61.18.130 at 2008-04-16 10:06:29) [GET]
+ Session ID: 8fdaa1328957ace8194a8f26a94b64ba
+ Parameters: {"order"=>"starttime DESC", "action"=>"list", "controller"=>"recorded"}
+ [4;35;1mSQL (0.000131)[0m [0mSET SQL_AUTO_IS_NULL=0[0m
+ [4;36;1mRecorded Columns (0.002816)[0m [0;1mSHOW FIELDS FROM `recorded`[0m
+ [4;35;1mRecorded Load (0.000414)[0m [0mSELECT * FROM `recorded` ORDER BY starttime DESC[0m
+Completed in 0.71895 (1 reqs/sec) | Rendering: 0.69014 (95%) | DB: 0.00000 (0%) | 200 OK [http://home.cjmart.in/recorded/list?order=starttime+DESC]
diff --git a/public/stylesheets/scaffold.css b/public/stylesheets/scaffold.css
new file mode 100644
index 0000000..879e85b
--- /dev/null
+++ b/public/stylesheets/scaffold.css
@@ -0,0 +1,74 @@
+body { background-color: #fff; color: #333; }
+
+body, p, ol, ul, td {
+ font-family: verdana, arial, helvetica, sans-serif;
+ font-size: 13px;
+ line-height: 18px;
+}
+
+pre {
+ background-color: #eee;
+ padding: 10px;
+ font-size: 11px;
+}
+
+a { color: #000; }
+a:visited { color: #666; }
+a:hover { color: #fff; background-color:#000; }
+
+.fieldWithErrors {
+ padding: 2px;
+ background-color: red;
+ display: table;
+}
+
+#errorExplanation {
+ width: 400px;
+ border: 2px solid red;
+ padding: 7px;
+ padding-bottom: 12px;
+ margin-bottom: 20px;
+ background-color: #f0f0f0;
+}
+
+#errorExplanation h2 {
+ text-align: left;
+ font-weight: bold;
+ padding: 5px 5px 5px 15px;
+ font-size: 12px;
+ margin: -7px;
+ background-color: #c00;
+ color: #fff;
+}
+
+#errorExplanation p {
+ color: #333;
+ margin-bottom: 0;
+ padding: 5px;
+}
+
+#errorExplanation ul li {
+ font-size: 12px;
+ list-style: square;
+}
+
+div.uploadStatus {
+ margin: 5px;
+}
+
+div.progressBar {
+ margin: 5px;
+}
+
+div.progressBar div.border {
+ background-color: #fff;
+ border: 1px solid gray;
+ width: 100%;
+}
+
+div.progressBar div.background {
+ background-color: #333;
+ height: 18px;
+ width: 0%;
+}
+
diff --git a/script/poller b/script/poller
new file mode 100755
index 0000000..4d13bbb
--- /dev/null
+++ b/script/poller
@@ -0,0 +1,21 @@
+#!/usr/bin/env ruby
+require 'rubygems'
+require 'daemons'
+
+APP_ROOT = File.expand_path(File.dirname(__FILE__) + '/..')
+script_file = File.join(File.expand_path(APP_ROOT),'vendor','plugins','activemessaging','poller.rb')
+tmp_dir = File.join(File.expand_path(APP_ROOT), 'tmp')
+
+options = {
+ :app_name => "poller",
+ :dir_mode => :normal,
+ :dir => tmp_dir,
+ :multiple => true,
+ :ontop => false,
+ :mode => :load,
+ :backtrace => true,
+ :monitor => true,
+ :log_output => true
+}
+
+Daemons.run(script_file,options)
diff --git a/test/fixtures/videos.yml b/test/fixtures/videos.yml
new file mode 100644
index 0000000..9d52f4a
--- /dev/null
+++ b/test/fixtures/videos.yml
@@ -0,0 +1,15 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+
+one:
+ height: 1
+ width: 1
+ video_url: MyString
+ file_name: MyString
+ ext: MyString
+
+two:
+ height: 1
+ width: 1
+ video_url: MyString
+ file_name: MyString
+ ext: MyString
diff --git a/test/functional/transcode_processor_test.rb b/test/functional/transcode_processor_test.rb
new file mode 100644
index 0000000..e752e47
--- /dev/null
+++ b/test/functional/transcode_processor_test.rb
@@ -0,0 +1,19 @@
+require File.dirname(__FILE__) + '/../test_helper'
+require File.dirname(__FILE__) + '/../../vendor/plugins/activemessaging/lib/activemessaging/test_helper'
+require File.dirname(__FILE__) + '/../../app/processors/application'
+
+class TranscodeProcessorTest < Test::Unit::TestCase
+ include ActiveMessaging::TestHelper
+
+ def setup
+ @processor = TranscodeProcessor.new
+ end
+
+ def teardown
+ @processor = nil
+ end
+
+ def test_transcode_processor
+ @processor.on_message('Your test message here!')
+ end
+end
\ No newline at end of file
diff --git a/test/functional/videos_controller_test.rb b/test/functional/videos_controller_test.rb
new file mode 100644
index 0000000..8b2010b
--- /dev/null
+++ b/test/functional/videos_controller_test.rb
@@ -0,0 +1,45 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class VideosControllerTest < ActionController::TestCase
+ def test_should_get_index
+ get :index
+ assert_response :success
+ assert_not_nil assigns(:videos)
+ end
+
+ def test_should_get_new
+ get :new
+ assert_response :success
+ end
+
+ def test_should_create_video
+ assert_difference('Video.count') do
+ post :create, :video => { }
+ end
+
+ assert_redirected_to video_path(assigns(:video))
+ end
+
+ def test_should_show_video
+ get :show, :id => videos(:one).id
+ assert_response :success
+ end
+
+ def test_should_get_edit
+ get :edit, :id => videos(:one).id
+ assert_response :success
+ end
+
+ def test_should_update_video
+ put :update, :id => videos(:one).id, :video => { }
+ assert_redirected_to video_path(assigns(:video))
+ end
+
+ def test_should_destroy_video
+ assert_difference('Video.count', -1) do
+ delete :destroy, :id => videos(:one).id
+ end
+
+ assert_redirected_to videos_path
+ end
+end
diff --git a/test/unit/video_test.rb b/test/unit/video_test.rb
new file mode 100644
index 0000000..0746473
--- /dev/null
+++ b/test/unit/video_test.rb
@@ -0,0 +1,8 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class VideoTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ def test_truth
+ assert true
+ end
+end
diff --git a/vendor/plugins/activemessaging/Rakefile b/vendor/plugins/activemessaging/Rakefile
new file mode 100644
index 0000000..ae5de03
--- /dev/null
+++ b/vendor/plugins/activemessaging/Rakefile
@@ -0,0 +1,20 @@
+require 'rake'
+require 'rake/testtask'
+require 'rdoc/rdoc'
+
+desc 'Default: run unit tests.'
+task :default => :test
+
+desc 'Test the ActiveMessaging plugin.'
+Rake::TestTask.new(:test) do |t|
+
+ t.libs << 'lib'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
+end
+
+desc 'Generate documentation for the ActiveMessaging plugin.'
+task :rdoc do
+ rm_rf 'doc'
+ RDoc::RDoc.new.document(%w(--line-numbers --inline-source --title ActiveMessaging README lib))
+end
diff --git a/vendor/plugins/activemessaging/generators/a13g_test_harness/a13g_test_harness_generator.rb b/vendor/plugins/activemessaging/generators/a13g_test_harness/a13g_test_harness_generator.rb
new file mode 100644
index 0000000..dc7cc46
--- /dev/null
+++ b/vendor/plugins/activemessaging/generators/a13g_test_harness/a13g_test_harness_generator.rb
@@ -0,0 +1,19 @@
+class A13gTestHarnessGenerator < Rails::Generator::Base
+ def manifest
+ record do |m|
+
+ controller_path = 'app/controllers'
+ m.directory controller_path
+ m.file 'active_messaging_test_controller.rb', File.join(controller_path, 'active_messaging_test_controller.rb')
+
+ view_path = 'app/views/active_messaging_test'
+ m.directory view_path
+ m.file 'index.rhtml', File.join(view_path, 'index.rhtml')
+
+ view_path = 'app/views/layouts'
+ m.directory view_path
+ m.file 'active_messaging_test.rhtml', File.join(view_path, 'active_messaging_test.rhtml')
+
+ end
+ end
+end
diff --git a/vendor/plugins/activemessaging/generators/a13g_test_harness/templates/active_messaging_test.rhtml b/vendor/plugins/activemessaging/generators/a13g_test_harness/templates/active_messaging_test.rhtml
new file mode 100644
index 0000000..3701762
--- /dev/null
+++ b/vendor/plugins/activemessaging/generators/a13g_test_harness/templates/active_messaging_test.rhtml
@@ -0,0 +1,13 @@
+<html>
+<head>
+ <title>ActiveMessaging Test Harness: <%= controller.action_name %></title>
+ <%= stylesheet_link_tag 'scaffold' %>
+</head>
+<body>
+
+<p style="color: green"><%= flash[:notice] %></p>
+
+<%= yield %>
+
+</body>
+</html>
diff --git a/vendor/plugins/activemessaging/generators/a13g_test_harness/templates/active_messaging_test_controller.rb b/vendor/plugins/activemessaging/generators/a13g_test_harness/templates/active_messaging_test_controller.rb
new file mode 100644
index 0000000..06dd70d
--- /dev/null
+++ b/vendor/plugins/activemessaging/generators/a13g_test_harness/templates/active_messaging_test_controller.rb
@@ -0,0 +1,29 @@
+class ActiveMessagingTestController < ApplicationController
+
+ include ActiveMessaging::MessageSender
+
+ def index
+ @destinations = ActiveMessaging::Gateway.named_destinations.values
+
+ if request.post?
+ @message = params[:message]
+
+ if params[:destination].nil? || params[:destination].empty?
+ flash[:notice] = "Please specify a destination."
+ return
+ else
+ @destination = params[:destination].intern
+ end
+
+ if @message.nil? || @message.empty?
+ flash[:notice] = "Please specify a message."
+ return
+ end
+
+ puts "#{@destination} : #{@message}"
+ publish @destination, @message
+ flash[:notice] = "'#{@message}' sent to #{@destination}"
+ end
+ end
+
+end
diff --git a/vendor/plugins/activemessaging/generators/a13g_test_harness/templates/index.rhtml b/vendor/plugins/activemessaging/generators/a13g_test_harness/templates/index.rhtml
new file mode 100644
index 0000000..64ed495
--- /dev/null
+++ b/vendor/plugins/activemessaging/generators/a13g_test_harness/templates/index.rhtml
@@ -0,0 +1,17 @@
+<h1>ActiveMessaging Test Harness</h1>
+
+<% form_tag :action => 'index' do |f| %>
+<p>
+ <label for="destination">Destination:</label><br/>
+ (broker: name => 'destination')<br/>
+ <select name="destination">
+ <option value=""></option>
+ <%= options_from_collection_for_select @destinations, 'name', 'to_s', @destination %>
+ </select>
+</p>
+<p>
+ <label for="message">Message:</label><br/>
+ <%= text_area_tag :message, @message, :size=>'50x10' %>
+</p>
+<%= submit_tag "submit" %>
+<% end -%>
diff --git a/vendor/plugins/activemessaging/generators/filter/USAGE b/vendor/plugins/activemessaging/generators/filter/USAGE
new file mode 100644
index 0000000..e69de29
diff --git a/vendor/plugins/activemessaging/generators/filter/filter_generator.rb b/vendor/plugins/activemessaging/generators/filter/filter_generator.rb
new file mode 100644
index 0000000..decc884
--- /dev/null
+++ b/vendor/plugins/activemessaging/generators/filter/filter_generator.rb
@@ -0,0 +1,19 @@
+class FilterGenerator < Rails::Generator::NamedBase
+ def manifest
+ record do |m|
+ path = 'app/processors'
+ test_path = 'test/functional'
+
+ # Check for class naming collisions
+ m.class_collisions class_path, "#{class_name}Controller", "#{class_name}ControllerTest", "#{class_name}Helper"
+
+ # filter and test directories
+ m.directory File.join(path, class_path)
+ m.directory File.join(test_path, class_path)
+
+ # filter and test templates
+ m.template 'filter.rb', File.join(path, class_path, "#{file_name}_filter.rb")
+ m.template 'filter_test.rb', File.join(test_path, class_path, "#{file_name}_filter_test.rb")
+ end
+ end
+end
diff --git a/vendor/plugins/activemessaging/generators/filter/templates/filter.rb b/vendor/plugins/activemessaging/generators/filter/templates/filter.rb
new file mode 100644
index 0000000..2476462
--- /dev/null
+++ b/vendor/plugins/activemessaging/generators/filter/templates/filter.rb
@@ -0,0 +1,12 @@
+class <%= class_name %>Filter < ActiveMessaging::Filter
+
+ attr_accessor :options
+
+ def initialize(options={})
+ @options = options
+ end
+
+ def process(message, routing)
+ logger.debug "<%= class_name %>Filter filtering message: #{message.inspect} with routing: #{routing.inspect}"
+ end
+end
\ No newline at end of file
diff --git a/vendor/plugins/activemessaging/generators/filter/templates/filter_test.rb b/vendor/plugins/activemessaging/generators/filter/templates/filter_test.rb
new file mode 100644
index 0000000..42737ca
--- /dev/null
+++ b/vendor/plugins/activemessaging/generators/filter/templates/filter_test.rb
@@ -0,0 +1,28 @@
+require File.dirname(__FILE__) + '/../test_helper'
+require File.dirname(__FILE__) + '/../../vendor/plugins/activemessaging/lib/activemessaging/test_helper'
+
+class <%= class_name %>FilterTest < Test::Unit::TestCase
+ include ActiveMessaging::TestHelper
+
+ def setup
+ # if you want to write code to tests against the filter directly
+ load File.dirname(__FILE__) + "/../../app/processors/<%= file_name %>_filter.rb"
+ @options = {:direction=>:incoming, :only=>:<%= file_name %>_test}
+ @filter = <%= class_name %>Filter.new(@options)
+ @destination = ActiveMessaging::Gateway.destination :<%= file_name %>_test, '/queue/<%= file_name %>.test.queue'
+ end
+
+ def teardown
+ ActiveMessaging::Gateway.reset
+ @filter = nil
+ @destination = nil
+ @options = nil
+ end
+
+ def test_<%= file_name %>_filter
+ @message = ActiveMessaging::TestMessage.new(@destination.value, {'message-id'=>'test-message-id-header'}, 'message body')
+ @routing = {:direction=>:incoming, :destination=>@destination}
+ @filter.process(@message, @routing)
+ end
+
+end
\ No newline at end of file
diff --git a/vendor/plugins/activemessaging/generators/processor/USAGE b/vendor/plugins/activemessaging/generators/processor/USAGE
new file mode 100644
index 0000000..481cd05
--- /dev/null
+++ b/vendor/plugins/activemessaging/generators/processor/USAGE
@@ -0,0 +1,8 @@
+Description:
+ Generates a stub ActiveMessaging Processor and associated test.
+
+Examples:
+ ./script/generate processor HelloWorld
+ will create:
+ /app/processors/hello_world_processor.rb
+ /test/functional/hello_world_processor_test.rb
diff --git a/vendor/plugins/activemessaging/generators/processor/processor_generator.rb b/vendor/plugins/activemessaging/generators/processor/processor_generator.rb
new file mode 100644
index 0000000..690ec86
--- /dev/null
+++ b/vendor/plugins/activemessaging/generators/processor/processor_generator.rb
@@ -0,0 +1,28 @@
+class ProcessorGenerator < Rails::Generator::NamedBase
+ def manifest
+ record do |m|
+ path = 'app/processors'
+ test_path = 'test/functional'
+
+ # Check for class naming collisions.
+ m.class_collisions class_path, "#{class_name}Controller", "#{class_name}ControllerTest", "#{class_name}Helper"
+
+ # processor and test directories
+ m.directory File.join(path, class_path)
+ m.directory File.join(test_path, class_path)
+
+ # processor and test templates
+ m.template 'processor.rb', File.join(path, class_path, "#{file_name}_processor.rb")
+ m.template 'processor_test.rb', File.join(test_path, class_path, "#{file_name}_processor_test.rb")
+
+ m.template 'messaging.rb', File.join('config', "messaging.rb")
+ m.file 'broker.yml', File.join('config', "broker.yml")
+ m.file 'application.rb', File.join(path, "application.rb")
+ if defined?(JRUBY_VERSION)
+ m.file 'jruby_poller', File.join('script', "jruby_poller"), { :chmod => 0755 }
+ else
+ m.file 'poller', File.join('script', "poller"), { :chmod => 0755 }
+ end
+ end
+ end
+end
diff --git a/vendor/plugins/activemessaging/generators/processor/templates/application.rb b/vendor/plugins/activemessaging/generators/processor/templates/application.rb
new file mode 100644
index 0000000..40e5042
--- /dev/null
+++ b/vendor/plugins/activemessaging/generators/processor/templates/application.rb
@@ -0,0 +1,15 @@
+class ApplicationProcessor < ActiveMessaging::Processor
+
+ # Default on_error implementation - logs standard errors but keeps processing. Other exceptions are raised.
+ def on_error(err)
+ if (err.kind_of?(StandardError))
+ logger.error "ApplicationProcessor::on_error: #{err.class.name} rescued:\n" + \
+ err.message + "\n" + \
+ "\t" + err.backtrace.join("\n\t")
+ else
+ logger.error "ApplicationProcessor::on_error: #{err.class.name} raised: " + err.message
+ raise err
+ end
+ end
+
+end
\ No newline at end of file
diff --git a/vendor/plugins/activemessaging/generators/processor/templates/broker.yml b/vendor/plugins/activemessaging/generators/processor/templates/broker.yml
new file mode 100644
index 0000000..f5a6ea6
--- /dev/null
+++ b/vendor/plugins/activemessaging/generators/processor/templates/broker.yml
@@ -0,0 +1,64 @@
+#
+# broker.yml
+#
+# Simple yaml file for the env specific configuration of the broker connections.
+# See the wiki for more information: http://code.google.com/p/activemessaging/wiki/Configuration
+#
+development:
+ ############################
+ # Stomp Adapter Properties #
+ ############################
+ adapter: stomp
+ # properties below are all defaults for this adapter
+ # login: ""
+ # passcode: ""
+ # host: localhost
+ # port: 61613
+ # reliable: true
+ # reconnectDelay: 5
+
+ ###################################
+ # Websphere MQ Adapter Properties #
+ ###################################
+ # adapter: wmq
+ # q_mgr_name: ""
+ # poll_interval: .1
+
+ #################################
+ # Amazon SQS Adapter Properties #
+ #################################
+ # adapter: asqs
+ # access_key_id: XXXXXXXXXXXXXXXXXXXX
+ # secret_access_key: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
+ ## properties below are all defaults for this adapter
+ # host: queue.amazonaws.com
+ # port: 80
+ # reliable: true
+ # reconnectDelay: 5
+ # aws_version: 2006-04-01
+ # content_type: text/plain
+ # poll_interval: 1
+ # cache_queue_list: true
+
+ ########################################
+ # ReliableMessaging Adapter Properties #
+ ########################################
+ # adapter: reliable_msg
+ ## properties below are all defaults for this adapter
+ # poll_interval: 1
+ # reliable: true
+
+test:
+ adapter: test
+ reliable: false
+
+production:
+ adapter: stomp
+ reliable: true
+ # properties below are all defaults for this adapter
+ # login: ""
+ # passcode: ""
+ # host: localhost
+ # port: 61613
+ # reliable: true
+ # reconnectDelay: 5
diff --git a/vendor/plugins/activemessaging/generators/processor/templates/jruby_poller b/vendor/plugins/activemessaging/generators/processor/templates/jruby_poller
new file mode 100644
index 0000000..df91909
--- /dev/null
+++ b/vendor/plugins/activemessaging/generators/processor/templates/jruby_poller
@@ -0,0 +1,117 @@
+#!/bin/sh
+
+JRUBY_CMD=`which jruby`
+RAILS_ROOT="$(dirname $0)/.."
+POLLER_RB="$RAILS_ROOT/vendor/plugins/activemessaging/poller.rb"
+OUT="$RAILS_ROOT/tmp/poller.output"
+PID_FILE="$RAILS_ROOT/tmp/poller0.pid"
+
+if [ -z "$JRUBY_CMD" ] ; then
+ echo "Could not find jruby on your path."
+ exit 1
+fi
+
+if [ ! -f $POLLER_RB ] ; then
+ echo "Could not find the poller file at: $POLLER_RB"
+ exit 1
+fi
+
+function start() {
+ if [[ -s $PID_FILE && -n "$(ps -A | grep "^[ \t]*$(< $PID_FILE)")" ]] ; then
+ PID=$(< $PID_FILE)
+ echo "Poller already running with pid $PID."
+ exit 1
+ fi
+ $JRUBY_CMD $POLLER_RB "$@" >> $OUT 2>&1 &
+ PID=$!
+ echo $PID > $PID_FILE
+ echo "Poller started with pid=$PID"
+}
+
+function stop() {
+ if [[ -z "$(ps -A | grep "^[ \t]*$(< $PID_FILE)")" ]] ; then
+ echo "Poller is not currently running."
+ exit 1
+ fi
+ if [ -z "$FORCE" ] ; then
+ echo "Sending TERM signal to poller."
+ kill -TERM $(< $PID_FILE)
+ else
+ echo "Sending KILL signal to poller."
+ kill -KILL $(< $PID_FILE)
+ fi
+ rm $PID_FILE
+}
+
+function restart() {
+ stop
+ start
+}
+
+function run() {
+ exec $JRUBY_CMD $POLLER_RB "$@"
+}
+
+function zap() {
+ echo "Resetting to stopped state."
+ [ -f $PID_FILE ] && rm $PID_FILE
+}
+
+function usage() {
+ cat <<EOF
+Usage: poller <command> <options> -- <application options>
+
+* where <command> is one of:
+ start start an instance of the application
+ stop stop all instances of the application
+ restart stop all instances and restart them afterwards
+ run start the application and stay on top
+ zap set the application to a stopped state
+
+* and where <options> may contain several of the following:
+
+ -t, --ontop Stay on top (does not daemonize)
+ -f, --force Force operation
+EOF
+
+}
+
+CMD=$1
+shift
+
+for i in "1" "2" ; do
+ case "$1" in
+ "-f"|"--force")
+ FORCE="true"
+ shift
+ ;;
+ "-t"|"--ontop")
+ ONTOP="true"
+ shift
+ ;;
+ esac
+done
+
+[ "$1" == "--" ] && shift
+
+case "$CMD" in
+ "start")
+ start
+ ;;
+ "stop")
+ stop
+ ;;
+ "run")
+ run
+ ;;
+ "restart")
+ restart
+ ;;
+ "zap")
+ zap
+ ;;
+ "usage"|*)
+ usage
+ exit 1
+ ;;
+esac
\ No newline at end of file
diff --git a/vendor/plugins/activemessaging/generators/processor/templates/messaging.rb b/vendor/plugins/activemessaging/generators/processor/templates/messaging.rb
new file mode 100644
index 0000000..8027e2e
--- /dev/null
+++ b/vendor/plugins/activemessaging/generators/processor/templates/messaging.rb
@@ -0,0 +1,12 @@
+#
+# Add your destination definitions here
+# can also be used to configure filters, and processor groups
+#
+ActiveMessaging::Gateway.define do |s|
+ #s.destination :orders, '/queue/Orders'
+ #s.filter :some_filter, :only=>:orders
+ #s.processor_group :group1, :order_processor
+
+ s.destination :<%= singular_name %>, '/queue/<%= class_name %>'
+
+end
\ No newline at end of file
diff --git a/vendor/plugins/activemessaging/generators/processor/templates/poller b/vendor/plugins/activemessaging/generators/processor/templates/poller
new file mode 100644
index 0000000..4d13bbb
--- /dev/null
+++ b/vendor/plugins/activemessaging/generators/processor/templates/poller
@@ -0,0 +1,21 @@
+#!/usr/bin/env ruby
+require 'rubygems'
+require 'daemons'
+
+APP_ROOT = File.expand_path(File.dirname(__FILE__) + '/..')
+script_file = File.join(File.expand_path(APP_ROOT),'vendor','plugins','activemessaging','poller.rb')
+tmp_dir = File.join(File.expand_path(APP_ROOT), 'tmp')
+
+options = {
+ :app_name => "poller",
+ :dir_mode => :normal,
+ :dir => tmp_dir,
+ :multiple => true,
+ :ontop => false,
+ :mode => :load,
+ :backtrace => true,
+ :monitor => true,
+ :log_output => true
+}
+
+Daemons.run(script_file,options)
diff --git a/vendor/plugins/activemessaging/generators/processor/templates/processor.rb b/vendor/plugins/activemessaging/generators/processor/templates/processor.rb
new file mode 100644
index 0000000..1a13563
--- /dev/null
+++ b/vendor/plugins/activemessaging/generators/processor/templates/processor.rb
@@ -0,0 +1,8 @@
+class <%= class_name %>Processor < ApplicationProcessor
+
+ subscribes_to :<%= singular_name %>
+
+ def on_message(message)
+ logger.debug "<%= class_name %>Processor received: " + message
+ end
+end
\ No newline at end of file
diff --git a/vendor/plugins/activemessaging/generators/processor/templates/processor_test.rb b/vendor/plugins/activemessaging/generators/processor/templates/processor_test.rb
new file mode 100644
index 0000000..67dc5f0
--- /dev/null
+++ b/vendor/plugins/activemessaging/generators/processor/templates/processor_test.rb
@@ -0,0 +1,19 @@
+require File.dirname(__FILE__) + '/../test_helper'
+require File.dirname(__FILE__) + '/../../vendor/plugins/activemessaging/lib/activemessaging/test_helper'
+require File.dirname(__FILE__) + '/../../app/processors/application'
+
+class <%= class_name %>ProcessorTest < Test::Unit::TestCase
+ include ActiveMessaging::TestHelper
+
+ def setup
+ @processor = <%= class_name %>Processor.new
+ end
+
+ def teardown
+ @processor = nil
+ end
+
+ def test_<%= file_name %>_processor
+ @processor.on_message('Your test message here!')
+ end
+end
\ No newline at end of file
diff --git a/vendor/plugins/activemessaging/generators/tracer/USAGE b/vendor/plugins/activemessaging/generators/tracer/USAGE
new file mode 100644
index 0000000..e4e1edc
--- /dev/null
+++ b/vendor/plugins/activemessaging/generators/tracer/USAGE
@@ -0,0 +1,8 @@
+Description:
+ Generates a stub ActiveMessaging Tracing Controller.
+
+Examples:
+ ./script/generate tracer Tracer
+ will create:
+ /app/processors/tracer_processor.rb
+ /app/views/tracer/index.rhtml
diff --git a/vendor/plugins/activemessaging/generators/tracer/templates/controller.rb b/vendor/plugins/activemessaging/generators/tracer/templates/controller.rb
new file mode 100644
index 0000000..462b251
--- /dev/null
+++ b/vendor/plugins/activemessaging/generators/tracer/templates/controller.rb
@@ -0,0 +1,14 @@
+class <%= class_name %>Controller < ApplicationController
+ include ActiveMessaging::MessageSender
+
+ publishes_to :trace
+
+ def index
+ end
+
+ def clear
+ publish :trace, "<trace-control>clear</trace-control>"
+ redirect_to :action=>'index'
+ end
+
+end
diff --git a/vendor/plugins/activemessaging/generators/tracer/templates/helper.rb b/vendor/plugins/activemessaging/generators/tracer/templates/helper.rb
new file mode 100644
index 0000000..3fe2ecd
--- /dev/null
+++ b/vendor/plugins/activemessaging/generators/tracer/templates/helper.rb
@@ -0,0 +1,2 @@
+module <%= class_name %>Helper
+end
diff --git a/vendor/plugins/activemessaging/generators/tracer/templates/index.rhtml b/vendor/plugins/activemessaging/generators/tracer/templates/index.rhtml
new file mode 100644
index 0000000..c7a1205
--- /dev/null
+++ b/vendor/plugins/activemessaging/generators/tracer/templates/index.rhtml
@@ -0,0 +1,4 @@
+<%=button_to 'Clear', :action=>'clear'%>
+
+<%=image_tag '../trace.png', :id => 'graph' %>
+
diff --git a/vendor/plugins/activemessaging/generators/tracer/templates/layout.rhtml b/vendor/plugins/activemessaging/generators/tracer/templates/layout.rhtml
new file mode 100644
index 0000000..bee08a6
--- /dev/null
+++ b/vendor/plugins/activemessaging/generators/tracer/templates/layout.rhtml
@@ -0,0 +1,16 @@
+<html>
+ <head>
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
+ <title>Tracer</title>
+ <%=javascript_include_tag :defaults %>
+ </head>
+ <body>
+ <h2>Tracer</h2>
+
+ <% if @flash[:note] -%>
+ <div id="flash"><%= @flash[:note] %></div>
+ <% end -%>
+
+ <%= @content_for_layout %>
+ </body>
+</html>
\ No newline at end of file
diff --git a/vendor/plugins/activemessaging/generators/tracer/templates/trace_processor.rb b/vendor/plugins/activemessaging/generators/tracer/templates/trace_processor.rb
new file mode 100644
index 0000000..cfb2d0e
--- /dev/null
+++ b/vendor/plugins/activemessaging/generators/tracer/templates/trace_processor.rb
@@ -0,0 +1,100 @@
+require 'mpath'
+require 'active_support'
+
+class Dot
+
+ attr_accessor :name, :nodes, :edges, :clean_names
+
+ def initialize name
+ @name = name
+ @nodes = {}
+ @clean_names = {}
+ @edges = []
+ yield self
+ end
+
+ def node name, params = {}
+ @nodes[clean_name(name)] = params.stringify_keys.reverse_merge "label"=>name
+ end
+
+ def clean_name name
+ @clean_names[name] = "node#{@clean_names.length+1}" if @clean_names[name].nil?
+ @clean_names[name]
+ end
+
+ def edge from, to
+ edge = [clean_name(from), clean_name(to)]
+ @edges << edge unless @edges.member? edge
+ end
+
+ def to_s
+ dot = "digraph #{@name} {\n"
+ @nodes.each do |node_name, options|
+ dot += "\t#{node_name.to_s}"
+ optionstrings = []
+ options.keys.sort.each do |key|
+ optionstrings << "#{key}=\"#{options[key]}\""
+ end
+ dot += " [#{optionstrings.join(', ')}]" if optionstrings.length>0
+ dot += ";\n"
+ end
+ @edges.each {|e| dot += "\t#{e[0].to_s}->#{e[1].to_s};\n"}
+ dot += "}\n"
+ end
+
+ def == other
+ (other.name == name) && (other.nodes == nodes) && (other.edges == edges) && (other.clean_names == clean_names)
+ end
+end
+
+class TraceProcessor < ActiveMessaging::Processor
+ subscribes_to :trace
+
+ @@dot = Dot.new("Trace") {}
+
+ class << self
+
+ end
+
+ def dot
+ @@dot
+ end
+
+ def on_message(message)
+ xml = Mpath.parse(message)
+ if (xml.sent?) then
+ from = xml.sent.from.to_s
+ queue = xml.sent.queue.to_s
+
+ @@dot.node from
+ @@dot.node queue, "shape" => 'box'
+ @@dot.edge from, queue #hah - could do from => to
+ elsif (xml.received?) then
+ by = xml.received.by.to_s
+ queue = xml.received.queue.to_s
+
+ @@dot.node queue, "shape" => 'box'
+ @@dot.node by
+ @@dot.edge queue, by
+ elsif (xml.trace_control) then
+ command = xml.trace_control.to_s
+ begin
+ send command
+ rescue
+ puts "TraceProcessor: I don't understand the command #{command}"
+ end
+ end
+ create_image
+ end
+
+ def create_image
+ File.open(DOT_FILE, "w") {|f| f.puts @@dot.to_s }
+ output_file = RAILS_ROOT + "/public/trace.png"
+ `dot -Tpng -o #{output_file} #{DOT_FILE}`
+ end
+
+ def clear
+ @@dot = Dot.new("Trace") {}
+ end
+
+end
\ No newline at end of file
diff --git a/vendor/plugins/activemessaging/generators/tracer/tracer_generator.rb b/vendor/plugins/activemessaging/generators/tracer/tracer_generator.rb
new file mode 100644
index 0000000..3ed4ef8
--- /dev/null
+++ b/vendor/plugins/activemessaging/generators/tracer/tracer_generator.rb
@@ -0,0 +1,25 @@
+class TracerGenerator < Rails::Generator::NamedBase
+ def manifest
+ record do |m|
+ path = 'app/controllers'
+ m.directory path
+ m.template 'controller.rb', File.join(path, "#{file_name}_controller.rb")
+
+ path = 'app/processors'
+ m.directory path
+ m.template 'trace_processor.rb', File.join(path, "#{file_name}_processor.rb")
+
+ path = 'app/helpers'
+ m.directory path
+ m.template 'helper.rb', File.join(path, "#{file_name}_helper.rb")
+
+ path = 'app/views/layouts'
+ m.directory path
+ m.file 'layout.rhtml', File.join(path, "#{file_name}.rhtml")
+
+ path = "app/views/#{file_name}"
+ m.directory path
+ m.file 'index.rhtml', File.join(path, "index.rhtml")
+ end
+ end
+end
diff --git a/vendor/plugins/activemessaging/init.rb b/vendor/plugins/activemessaging/init.rb
new file mode 100644
index 0000000..62f9404
--- /dev/null
+++ b/vendor/plugins/activemessaging/init.rb
@@ -0,0 +1,2 @@
+require 'ostruct'
+require 'activemessaging'
diff --git a/vendor/plugins/activemessaging/lib/activemessaging.rb b/vendor/plugins/activemessaging/lib/activemessaging.rb
new file mode 100644
index 0000000..63c0f28
--- /dev/null
+++ b/vendor/plugins/activemessaging/lib/activemessaging.rb
@@ -0,0 +1,125 @@
+module ActiveMessaging
+
+ VERSION = "0.5" #maybe this should be higher, but I'll let others judge :)
+
+ # Used to indicate that the processing for a thread shoud complete
+ class StopProcessingException < Interrupt #:nodoc:
+ end
+
+ # Used to indicate that the processing on a message should cease,
+ # and the message should be returned back to the broker as best it can be
+ class AbortMessageException < Exception #:nodoc:
+ end
+
+ # Used to indicate that the processing on a message should cease,
+ # but no further action is required
+ class StopFilterException < Exception #:nodoc:
+ end
+
+ def ActiveMessaging.logger
+ @@logger = ActiveRecord::Base.logger unless defined?(@@logger)
+ @@logger = Logger.new(STDOUT) unless defined?(@@logger)
+ @@logger
+ end
+
+ # DEPRECATED, so I understand, but I'm using it nicely below.
+ def self.load_extensions
+ require 'logger'
+ require 'activemessaging/support'
+ require 'activemessaging/gateway'
+ require 'activemessaging/adapter'
+ require 'activemessaging/message_sender'
+ require 'activemessaging/processor'
+ require 'activemessaging/filter'
+ require 'activemessaging/trace_filter'
+
+ # load all under the adapters dir
+ Dir[RAILS_ROOT + '/vendor/plugins/activemessaging/lib/activemessaging/adapters/*.rb'].each{|a|
+ begin
+ adapter_name = File.basename(a, ".rb")
+ require 'activemessaging/adapters/' + adapter_name
+ rescue RuntimeError, LoadError => e
+ logger.debug "ActiveMessaging: adapter #{adapter_name} not loaded: #{ e.message }"
+ end
+ }
+ end
+
+ def self.load_config
+ path = File.expand_path("#{RAILS_ROOT}/config/messaging.rb")
+ begin
+ load path
+ rescue MissingSourceFile
+ logger.debug "ActiveMessaging: no '#{path}' file to load"
+ rescue
+ raise $!, " ActiveMessaging: problems trying to load '#{path}': \n\t#{$!.message}"
+ end
+ end
+
+ def self.load_processors(first=true)
+ #Load the parent processor.rb, then all child processor classes
+ load RAILS_ROOT + '/vendor/plugins/activemessaging/lib/activemessaging/message_sender.rb' unless defined?(ActiveMessaging::MessageSender)
+ load RAILS_ROOT + '/vendor/plugins/activemessaging/lib/activemessaging/processor.rb' unless defined?(ActiveMessaging::Processor)
+ load RAILS_ROOT + '/vendor/plugins/activemessaging/lib/activemessaging/filter.rb' unless defined?(ActiveMessaging::Filter)
+ logger.debug "ActiveMessaging: Loading #{RAILS_ROOT + '/app/processors/application.rb'}" if first
+ load RAILS_ROOT + '/app/processors/application.rb' if File.exist?("#{RAILS_ROOT}/app/processors/application.rb")
+ Dir[RAILS_ROOT + '/app/processors/*.rb'].each do |f|
+ unless f.match(/\/application.rb/)
+ logger.debug "ActiveMessaging: Loading #{f}" if first
+ load f
+ end
+ end
+ end
+
+ def self.reload_activemessaging
+ # this is resetting the messaging.rb
+ ActiveMessaging::Gateway.filters = []
+ ActiveMessaging::Gateway.named_destinations = {}
+ ActiveMessaging::Gateway.processor_groups = {}
+
+ # now load the config
+ load_config
+ load_processors(false)
+ end
+
+ def self.load_activemessaging
+ load_extensions
+ load_config
+ load_processors
+ end
+
+ def self.start
+ if ActiveMessaging::Gateway.subscriptions.empty?
+ err_msg = <<EOM
+
+ActiveMessaging Error: No subscriptions.
+If you have no processor classes in app/processors, add them using the command:
+ script/generate processor DoSomething"
+
+If you have processor classes, make sure they include in the class a call to 'subscribes_to':
+ class DoSomethingProcessor < ActiveMessaging::Processor
+ subscribes_to :do_something
+
+EOM
+ puts err_msg
+ logger.error err_msg
+ exit
+ end
+
+ Gateway.start
+ end
+
+end
+
+#load these once to start with
+ActiveMessaging.load_activemessaging
+
+
+# reload these on each request - leveraging Dispatcher semantics for consistency
+require 'dispatcher' unless defined?(::Dispatcher)
+
+# add processors and config to on_prepare if supported (rails 1.2+)
+if ::Dispatcher.respond_to? :to_prepare
+ ::Dispatcher.to_prepare :activemessaging do
+ ActiveMessaging.reload_activemessaging
+ end
+end
diff --git a/vendor/plugins/activemessaging/lib/activemessaging/adapter.rb b/vendor/plugins/activemessaging/lib/activemessaging/adapter.rb
new file mode 100644
index 0000000..e08d675
--- /dev/null
+++ b/vendor/plugins/activemessaging/lib/activemessaging/adapter.rb
@@ -0,0 +1,21 @@
+module ActiveMessaging
+
+ # include this module to make a new adapter - will register the adapter w/gateway so an be used in connection config
+ module Adapter
+
+ def self.included(included_by)
+ class << included_by
+ def register adapter_name
+ Gateway.register_adapter adapter_name, self
+ end
+ end
+ end
+
+ def logger()
+ @@logger = ActiveMessaging.logger unless defined?(@@logger)
+ @@logger
+ end
+
+ end
+
+end
\ No newline at end of file
diff --git a/vendor/plugins/activemessaging/lib/activemessaging/adapters/asqs.rb b/vendor/plugins/activemessaging/lib/activemessaging/adapters/asqs.rb
new file mode 100644
index 0000000..b3655e1
--- /dev/null
+++ b/vendor/plugins/activemessaging/lib/activemessaging/adapters/asqs.rb
@@ -0,0 +1,391 @@
+require 'rubygems'
+require 'net/http'
+require 'openssl'
+require 'base64'
+require 'cgi'
+require 'time'
+
+module ActiveMessaging
+ module Adapters
+ module AmazonSQS
+
+ class Connection
+ include ActiveMessaging::Adapter
+
+ register :asqs
+
+ QUEUE_NAME_LENGTH = 1..80
+ MESSAGE_SIZE = 1..(256 * 1024)
+ VISIBILITY_TIMEOUT = 0..(24 * 60 * 60)
+ NUMBER_OF_MESSAGES = 1..255
+ GET_QUEUE_ATTRIBUTES = ['All', 'ApproximateNumberOfMessages', 'VisibilityTimeout']
+ SET_QUEUE_ATTRIBUTES = ['VisibilityTimeout']
+
+ #configurable params
+ attr_accessor :reliable, :reconnectDelay, :access_key_id, :secret_access_key, :aws_version, :content_type, :host, :port, :poll_interval, :cache_queue_list
+
+ #generic init method needed by a13g
+ def initialize cfg
+ raise "Must specify a access_key_id" if (cfg[:access_key_id].nil? || cfg[:access_key_id].empty?)
+ raise "Must specify a secret_access_key" if (cfg[:secret_access_key].nil? || cfg[:secret_access_key].empty?)
+
+ @access_key_id=cfg[:access_key_id]
+ @secret_access_key=cfg[:secret_access_key]
+ @request_expires = cfg[:requestExpires] || 10
+ @request_retry_count = cfg[:requestRetryCount] || 5
+ @aws_version = cfg[:aws_version] || '2008-01-01'
+ @content_type = cfg[:content_type] || 'text/plain'
+ @host = cfg[:host] || 'queue.amazonaws.com'
+ @port = cfg[:port] || 80
+ @protocol = cfg[:protocol] || 'http'
+ @poll_interval = cfg[:poll_interval] || 1
+ @reconnect_delay = cfg[:reconnectDelay] || 5
+ @aws_url="#{@protocol}://#{@host}"
+
+ @cache_queue_list = cfg[:cache_queue_list].nil? ? true : cfg[:cache_queue_list]
+ @reliable = cfg[:reliable].nil? ? true : cfg[:reliable]
+
+ #initialize the subscriptions and queues
+ @subscriptions = {}
+ @current_subscription = 0
+ queues
+ end
+
+ def disconnect
+ #it's an http request - there is no disconnect - ha!
+ end
+
+ # queue_name string, headers hash
+ # for sqs, make sure queue exists, if not create, then add to list of polled queues
+ def subscribe queue_name, message_headers={}
+ # look at the existing queues, create any that are missing
+ queue = get_or_create_queue queue_name
+ if @subscriptions.has_key? queue.name
+ @subscriptions[queue.name] += 1
+ else
+ @subscriptions[queue.name] = 1
+ end
+ end
+
+ # queue_name string, headers hash
+ # for sqs, attempt delete the queues, won't work if not empty, that's ok
+ def unsubscribe queue_name, message_headers={}
+ if @subscriptions[queue_name]
+ @subscriptions[queue_name] -= 1
+ @subscriptions.delete(queue_name) if @subscriptions[queue_name] <= 0
+ end
+ end
+
+ # queue_name string, body string, headers hash
+ # send a single message to a queue
+ def send queue_name, message_body, message_headers={}
+ queue = get_or_create_queue queue_name
+ send_messsage queue, message_body
+ end
+
+ # receive a single message from any of the subscribed queues
+ # check each queue once, then sleep for poll_interval
+ def receive
+ raise "No subscriptions to receive messages from." if (@subscriptions.nil? || @subscriptions.empty?)
+ start = @current_subscription
+ while true
+ # puts "calling receive..."
+ @current_subscription = ((@current_subscription < @subscriptions.length-1) ? @current_subscription + 1 : 0)
+ sleep poll_interval if (@current_subscription == start)
+ queue_name = @subscriptions.keys.sort[@current_subscription]
+ queue = queues[queue_name]
+ unless queue.nil?
+ messages = retrieve_messsages queue, 1
+ return messages[0] unless (messages.nil? or messages.empty? or messages[0].nil?)
+ end
+ end
+ end
+
+ def received message, headers={}
+ begin
+ delete_message message
+ rescue Object=>exception
+ logger.error "Exception in ActiveMessaging::Adapters::AmazonSQS::Connection.received() logged and ignored: "
+ logger.error exception
+ end
+ end
+
+ def unreceive message, headers={}
+ # do nothing; by not deleting the message will eventually become visible again
+ return true
+ end
+
+ protected
+
+ def create_queue(name)
+ validate_new_queue name
+ response = make_request('CreateQueue', nil, {'QueueName'=>name})
+ add_queue response.get_text("//QueueUrl") unless response.nil?
+ end
+
+ def delete_queue queue
+ validate_queue queue
+ response = make_request('DeleteQueue', "#{queue.queue_url}")
+ end
+
+ def list_queues(queue_name_prefix=nil)
+ validate_queue_name queue_name_prefix unless queue_name_prefix.nil?
+ params = queue_name_prefix.nil? ? {} : {"QueueNamePrefix"=>queue_name_prefix}
+ response = make_request('ListQueues', nil, params)
+ response.nil? ? [] : response.nodes("//QueueUrl").collect{ |n| add_queue(n.text) }
+ end
+
+ def get_queue_attributes(queue, attribute='All')
+ validate_get_queue_attribute(attribute)
+ params = {'AttributeName'=>attribute}
+ response = make_request('GetQueueAttributes', "#{queue.queue_url}")
+ attributes = {}
+ response.each_node('/GetQueueAttributesResponse/GetQueueAttributesResult/Attribute') { |n|
+ n = n.elements['Name'].text
+ v = n.elements['Value'].text
+ attributes[n] = v
+ }
+ if attribute != 'All'
+ attributes[attribute]
+ else
+ attributes
+ end
+ end
+
+ def set_queue_attribute(queue, attribute, value)
+ validate_set_queue_attribute(attribute)
+ params = {'Attribute.Name'=>attribute, 'Attribute.Value'=>value.to_s}
+ response = make_request('SetQueueAttributes', "#{queue.queue_url}", params)
+ end
+
+ def delete_queue queue
+ validate_queue queue
+ response = make_request('DeleteQueue', "#{queue.queue_url}")
+ end
+
+ # in progress
+ def send_messsage queue, message
+ validate_queue queue
+ validate_message message
+ response = make_request('SendMessage', queue.queue_url, {'MessageBody'=>message})
+ response.get_text("//MessageId") unless response.nil?
+ end
+
+ def retrieve_messsages queue, num_messages=1, timeout=nil
+ validate_queue queue
+ validate_number_of_messages num_messages
+ validate_timeout timeout if timeout
+
+ params = {'MaxNumberOfMessages'=>num_messages.to_s}
+ params['VisibilityTimeout'] = timeout.to_s if timeout
+
+ response = make_request('ReceiveMessage', "#{queue.queue_url}", params)
+ response.nodes("//Message").collect{ |n| Message.from_element n, response, queue } unless response.nil?
+ end
+
+ def delete_message message
+ response = make_request('DeleteMessage', "#{message.queue.queue_url}", {'ReceiptHandle'=>message.receipt_handle})
+ end
+
+ def make_request(action, url=nil, params = {})
+ # puts "make_request a=#{action} u=#{url} p=#{params}"
+ url ||= @aws_url
+
+ # Add Actions
+ params['Action'] = action
+ params['Version'] = @aws_version
+ params['AWSAccessKeyId'] = @access_key_id
+ params['Expires']= (Time.now + @request_expires).gmtime.iso8601
+ params['SignatureVersion'] = '1'
+
+ # Sign the string
+ sorted_params = params.sort_by { |key,value| key.downcase }
+ joined_params = sorted_params.collect { |key, value| key.to_s + value.to_s }
+ string_to_sign = joined_params.to_s
+ digest = OpenSSL::Digest::Digest.new('sha1')
+ hmac = OpenSSL::HMAC.digest(digest, @secret_access_key, string_to_sign)
+ params['Signature'] = Base64.encode64(hmac).chomp
+
+ # Construct request
+ query_params = params.collect { |key, value| key + "=" + CGI.escape(value.to_s) }.join("&")
+
+ # Put these together to get the request query string
+ request_url = "#{url}?#{query_params}"
+ # puts "request_url = #{request_url}"
+ request = Net::HTTP::Get.new(request_url)
+
+ retry_count = 0
+ while retry_count < @request_retry_count.to_i
+ retry_count = retry_count + 1
+ # puts "make_request try retry_count=#{retry_count}"
+ begin
+ response = SQSResponse.new(http_request(host,port,request))
+ check_errors(response)
+ return response
+ rescue Object=>ex
+ # puts "make_request caught #{ex}"
+ raise ex unless reliable
+ sleep(@reconnect_delay)
+ end
+ end
+ end
+
+ # I wrap this so I can move to a different client, or easily mock for testing
+ def http_request h, p, r
+ return Net::HTTP.start(h, p){ |http| http.request(r) }
+ end
+
+ def check_errors(response)
+ raise "http response was nil" if (response.nil?)
+ raise response.errors if (response && response.errors?)
+ response
+ end
+
+ private
+
+ # internal data structure methods
+ def add_queue(url)
+ q = Queue.from_url url
+ queues[q.name] = q if self.cache_queue_list
+ return q
+ end
+
+ def get_or_create_queue queue_name
+ qs = queues
+ qs.has_key?(queue_name) ? qs[queue_name] : create_queue(queue_name)
+ end
+
+ def queues
+ return @queues if (@queues && cache_queue_list)
+ @queues = {}
+ list_queues.each{|q| @queues[q.name]=q }
+ return @queues
+ end
+
+ # validation methods
+ def validate_queue_name qn
+ raise "Queue name, '#{qn}', must be between #{QUEUE_NAME_LENGTH.min} and #{QUEUE_NAME_LENGTH.max} characters." unless QUEUE_NAME_LENGTH.include?(qn.length)
+ raise "Queue name, '#{qn}', must be alphanumeric only." if (qn =~ /[^\w\-\_]/ )
+ end
+
+ def validate_new_queue qn
+ validate_queue_name qn
+ raise "Queue already exists: #{qn}" if queues.has_key? qn
+ end
+
+ def validate_queue q
+ raise "Never heard of queue, can't use it: #{q.name}" unless queues.has_key? q.name
+ end
+
+ def validate_message m
+ raise "Message cannot be nil." if m.nil?
+ raise "Message length, #{m.length}, must be between #{MESSAGE_SIZE.min} and #{MESSAGE_SIZE.max}." unless MESSAGE_SIZE.include?(m.length)
+ end
+
+ def validate_timeout to
+ raise "Timeout, #{to}, must be between #{VISIBILITY_TIMEOUT.min} and #{VISIBILITY_TIMEOUT.max}." unless VISIBILITY_TIMEOUT.include?(to)
+ end
+
+ def validate_get_queue_attribute qa
+ raise "Queue Attribute name, #{qa}, not in list of valid attributes to get: #{GET_QUEUE_ATTRIBUTES.to_sentence}." unless GET_QUEUE_ATTRIBUTES.include?(qa)
+ end
+
+ def validate_set_queue_attribute qa
+ raise "Queue Attribute name, #{qa}, not in list of valid attributes to set: #{SET_QUEUE_ATTRIBUTES.to_sentence}." unless SET_QUEUE_ATTRIBUTES.include?(qa)
+ end
+
+ def validate_number_of_messages nom
+ raise "Number of messages, #{nom}, must be between #{NUMBER_OF_MESSAGES.min} and #{NUMBER_OF_MESSAGES.max}." unless NUMBER_OF_MESSAGES.include?(nom)
+ end
+
+ end
+
+ class SQSResponse
+ attr_accessor :headers, :doc, :http_response
+
+ def initialize response
+ # puts "response.body = #{response.body}"
+ @http_response = response
+ @headers = response.to_hash()
+ @doc = REXML::Document.new(response.body)
+ end
+
+ def message_type
+ return doc ? doc.root.name : ''
+ end
+
+ def errors?
+ (not http_response.kind_of?(Net::HTTPSuccess)) or (message_type == "ErrorResponse")
+ end
+
+ def errors
+ return "HTTP Error: #{http_response.code} : #{http_response.message}" unless http_response.kind_of?(Net::HTTPSuccess)
+
+ msg = nil
+ each_node('//Error') { |n|
+ msg ||= ""
+ c = n.elements['Code'].text
+ m = n.elements['Message'].text
+ msg << ", " if msg != ""
+ msg << "#{c} : #{m}"
+ }
+
+ return msg
+ end
+
+ def get_text(xpath,default='')
+ e = REXML::XPath.first( doc, xpath)
+ e.nil? ? default : e.text
+ end
+
+ def each_node(xp)
+ REXML::XPath.each(doc.root, xp) {|n| yield n}
+ end
+
+ def nodes(xp)
+ doc.elements.to_a(xp)
+ end
+ end
+
+ class Queue
+ attr_accessor :name, :pathinfo, :domain, :visibility_timeout
+
+ def self.from_url url
+ return Queue.new($2,$1) if (url =~ /^http:\/\/(.+)\/([-a-zA-Z0-9_]+)$/)
+ raise "Bad Queue URL: #{url}"
+ end
+
+ def queue_url
+ "#{pathinfo}/#{name}"
+ end
+
+ def initialize name, domain, vt=nil
+ @name, @pathinfo, @domain, @visibility_timeout = name, pathinfo, domain, vt
+ end
+
+ def to_s
+ "<AmazonSQS::Queue name='#{name}' url='#{queue_url}' domain='#{domain}'>"
+ end
+ end
+
+ # based on stomp message, has pointer to the SQSResponseObject
+ class Message
+ attr_accessor :headers, :id, :body, :command, :response, :queue, :md5_of_body, :receipt_handle
+
+ def self.from_element e, response, queue
+ Message.new(response.headers, e.elements['MessageId'].text, e.elements['Body'].text, e.elements['MD5OfBody'].text, e.elements['ReceiptHandle'].text, response, queue)
+ end
+
+ def initialize headers, id, body, md5_of_body, receipt_handle, response, queue, command='MESSAGE'
+ @headers, @id, @body, @md5_of_body, @receipt_handle, @response, @queue, @command = headers, id, body, md5_of_body, receipt_handle, response, queue, command
+ headers['destination'] = queue.name
+ end
+
+ def to_s
+ "<AmazonSQS::Message id='#{id}' body='#{body}' headers='#{headers.inspect}' command='#{command}' response='#{response}'>"
+ end
+ end
+
+ end
+ end
+end
\ No newline at end of file
diff --git a/vendor/plugins/activemessaging/lib/activemessaging/adapters/base.rb b/vendor/plugins/activemessaging/lib/activemessaging/adapters/base.rb
new file mode 100644
index 0000000..874cd69
--- /dev/null
+++ b/vendor/plugins/activemessaging/lib/activemessaging/adapters/base.rb
@@ -0,0 +1,82 @@
+module ActiveMessaging
+ module Adapters
+ module Base
+
+
+ # use this as a base for implementing new connections
+ class Connection
+ include ActiveMessaging::Adapter
+
+ #use the register method to add the adapter to the configurable list of supported adapters
+ # register :generic
+
+ #configurable params
+ attr_accessor :reliable
+
+ #generic init method needed by a13g
+ def initialize cfg
+ end
+
+ # called to cleanly get rid of connection
+ def disconnect
+ end
+
+ # destination_name string, headers hash
+ # subscribe to listen on a destination
+ def subscribe destination_name, message_headers={}
+ end
+
+ # destination_name string, headers hash
+ # unsubscribe to listen on a destination
+ def unsubscribe destination_name, message_headers={}
+ end
+
+ # destination_name string, body string, headers hash
+ # send a single message to a destination
+ def send destination_name, message_body, message_headers={}
+ end
+
+ # receive a single message from any of the subscribed destinations
+ # check each destination once, then sleep for poll_interval
+ def receive
+ end
+
+ # called after a message is successfully received and processed
+ def received message, headers={}
+ end
+
+ # called after a message is successfully received but unsuccessfully processed
+ # purpose is to return the message to the destination so receiving and processing and be attempted again
+ def unreceive message, headers={}
+ end
+
+ end
+
+ # I recommend having a destination object to represent each subscribed destination
+ class Destination
+ attr_accessor :name
+
+ def to_s
+ "<Base::Destination name='#{name}'>"
+ end
+ end
+
+ # based on stomp message
+ # command = MESSAGE for successful message from adapter, ERROR for problem from adapter
+ # !!!! must have headers['destination'] = subscription.destination in order to match message to subscription in gateway!!!!
+ class Message
+ attr_accessor :headers, :body, :command
+
+ def initialize headers, id, body, response, destination, command='MESSAGE'
+ @headers, @body, @command = headers, body, command
+ headers['destination'] = destination.name
+ end
+
+ def to_s
+ "<Base::Message body='#{body}' headers='#{headers.inspect}' command='#{command}' >"
+ end
+ end
+
+ end
+ end
+end
\ No newline at end of file
diff --git a/vendor/plugins/activemessaging/lib/activemessaging/adapters/jms.rb b/vendor/plugins/activemessaging/lib/activemessaging/adapters/jms.rb
new file mode 100644
index 0000000..6b4b544
--- /dev/null
+++ b/vendor/plugins/activemessaging/lib/activemessaging/adapters/jms.rb
@@ -0,0 +1,237 @@
+
+if defined?(JRUBY_VERSION)
+#require 'java'
+include Java
+
+import javax.naming.InitialContext
+import javax.jms.MessageListener
+
+module ActiveMessaging
+ module Adapters
+ module Jms
+
+ class Connection
+ include ActiveMessaging::Adapter
+ register :jms
+
+ attr_accessor :reliable, :connection, :session, :producers, :consumers
+
+ def initialize cfg={}
+ @url = cfg[:url]
+ @login = cfg[:login]
+ @passcode = cfg[:passcode]
+ #initialize our connection factory
+ if cfg.has_key? :connection_factory
+ #this initialize is probably activemq specific. There might be a more generic
+ #way of getting this without resorting to jndi lookup.
+ eval <<-end_eval
+ @connection_factory = Java::#{cfg[:connection_factory]}.new(@login, @password, @url)
+ end_eval
+ elsif cfg.has_key? :jndi
+ @connection_factory = javax.naming.InitialContext.new().lookup(cfg[:jndi])
+ else
+ raise "Either jndi or connection_factory has to be set in the config."
+ end
+ raise "Connection factory could not be initialized." if @connection_factory.nil?
+
+ @connection = @connection_factory.create_connection()
+ @session = @connection.createSession(false, 1)
+ @destinations = []
+ @producers = {}
+ @consumers = {}
+ @connection.start
+ end
+
+ def subscribe queue_name, headers={}
+ queue_name = check_destination_type queue_name, headers
+ find_or_create_consumer queue_name, headers
+ end
+
+ def unsubscribe queue_name, headers={}
+ queue_name = check_destination_type queue_name, headers
+ consumer = @consumers[queue_name]
+ unless consumer.nil?
+ consumer.close
+ @consumers.delete queue_name
+ end
+ end
+
+ def send queue_name, body, headers={}
+ queue_name = check_destination_type queue_name, headers
+ producer = find_or_create_producer queue_name, headers.symbolize_keys
+ message = @session.create_text_message body
+ headers.stringify_keys.each do |key, value|
+ if ['id', 'message-id', 'JMSMessageID'].include? key
+ message.setJMSMessageID value.to_s
+ elsif ['correlation-id', 'JMSCorrelationID'].include? key
+ message.setJMSCorrelationID value.to_s
+ elsif ['expires', 'JMSExpiration'].include? key
+ message.setJMSExpiration value.to_i
+ elsif ['persistent', 'JMSDeliveryMode'].include? key
+ message.setJMSDeliveryMode(value ? 2 : 1)
+ elsif ['priority', 'JMSPriority'].include? key
+ message.setJMSPriority value.to_i
+ elsif ['reply-to', 'JMSReplyTo'].include? key
+ message.setJMSReplyTo value.to_s
+ elsif ['type', 'JMSType'].include? key
+ message.setJMSType value.to_s
+ else #is this the most appropriate thing to do here?
+ message.set_string_property key, value.to_s
+ end
+ end
+ producer.send message
+ end
+
+ def receive_any
+ @consumers.find do |k, c|
+ message = c.receive(1)
+ return condition_message(message) unless message.nil?
+ end
+ end
+
+ def receive queue_name=nil, headers={}
+ if queue_name.nil?
+ receive_any
+ else
+ consumer = subscribe queue_name, headers
+ message = consumer.receive(1)
+ unsubscribe queue_name, headers
+ condition_message message
+ end
+ end
+
+ def received message, headers={}
+ #do nothing
+ end
+
+ def unreceive message, headers={}
+ # do nothing
+ end
+
+ def close
+ @consumers.each {|k, c| c.stop }
+ @connection.stop
+ @session.close
+ @connection.close
+ @connection = nil
+ @session = nil
+ @consumers = {}
+ @producers = {}
+ end
+
+ def find_or_create_producer queue_name, headers={}
+ producer = @producers[queue_name]
+ if producer.nil?
+ destination = find_or_create_destination queue_name, headers
+ producer = @session.create_producer destination
+ end
+ producer
+ end
+
+ def find_or_create_consumer queue_name, headers={}
+ consumer = @consumers[queue_name]
+ if consumer.nil?
+ destination = find_or_create_destination queue_name, headers
+ if headers.symbolize_keys.has_key? :selector
+ consumer = @session.create_consumer destination, headers.symbolize_keys[:selector]
+ else
+ consumer = @session.create_consumer destination
+ end
+
+ @consumers[queue_name] = consumer
+ end
+ consumer
+ end
+
+ def find_or_create_destination queue_name, headers={}
+ destination = find_destination queue_name, headers[:destination_type]
+ if destination.nil?
+ if headers.symbolize_keys[:destination_type] == :topic
+ destination = @session.create_topic(queue_name.to_s)
+ @destinations << destination
+ elsif headers.symbolize_keys[:destination_type] == :queue
+ destination = @session.create_queue(queue_name.to_s)
+ @destinations << destination
+ else
+ raise "headers[:destination_type] must be either :queue or :topic. was #{headers[:destination_type]}"
+ end
+ end
+ destination
+ end
+
+ protected
+
+ def condition_message message
+ message.class.class_eval {
+ alias_method :body, :text unless method_defined? :body
+
+ def command
+ "MESSAGE"
+ end
+
+ def headers
+ destination.to_s =~ %r{(queue|topic)://(.*)}
+ puts "/#{$1}/#{$2}"
+ {'destination' => "/#{$1}/#{$2}"}
+ end
+
+ } unless message.nil? || message.respond_to?(:command)
+ message
+ end
+
+ def check_destination_type queue_name, headers
+ stringy_h = headers.stringify_keys
+ if queue_name =~ %r{^/(topic|queue)/(.*)$} && !stringy_h.has_key?('destination_type')
+ headers['destination_type'] = $1.to_sym
+ return $2
+ else
+ raise "Must specify destination type either with either 'headers[\'destination_type\']=[:queue|:topic]' or /[topic|queue]/destination_name for queue name '#{queue_name}'" unless [:topic, :queue].include? stringy_h['destination_type']
+ end
+ end
+
+ def find_destination queue_name, type
+ @destinations.find do |d|
+ if d.is_a?(javax.jms.Topic) && type == :topic
+ d.topic_name == queue_name
+ elsif d.is_a?(javax.jms.Queue) && type == :queue
+ d.queue_name == queue_name
+ end
+ end
+ end
+ end
+#
+# class RubyMessageListener
+# include javax.jms.MessageListener
+#
+# def initialize(connection, destination, name)
+# @connection = connection
+# @destination = destination
+# @name = name
+# end
+#
+# def onMessage(msg)
+# headers = {}
+# enm = msg.getPropertyNames
+# while enm.hasMoreElements
+# key = enm.nextElement
+# headers[key.to_s] = msg.getStringProperty(key)
+# end
+# Gateway.dispatch(JMSRecvMessage.new(headers,msg.text,@name))
+# rescue => e
+# STDERR.puts "something went really wrong with a message: #{e.inspect}"
+# end
+# end
+#
+# class JMSRecvMessage < ActiveMessaging::Adapters::Base::Message
+# def initialize(headers, body, name, command='MESSAGE')
+# @headers = headers
+# @body = body
+# @command = command
+# @headers['destination'] = name
+# end
+# end
+ end
+ end
+end
+
+end
\ No newline at end of file
diff --git a/vendor/plugins/activemessaging/lib/activemessaging/adapters/reliable_msg.rb b/vendor/plugins/activemessaging/lib/activemessaging/adapters/reliable_msg.rb
new file mode 100644
index 0000000..55233c5
--- /dev/null
+++ b/vendor/plugins/activemessaging/lib/activemessaging/adapters/reliable_msg.rb
@@ -0,0 +1,174 @@
+require 'reliable-msg'
+
+module ReliableMsg
+
+ class Client
+
+ def queue_manager
+ qm
+ end
+
+ end
+end
+
+
+module ActiveMessaging
+ module Adapters
+ module ReliableMsg
+
+ THREAD_OLD_TXS = :a13g_reliable_msg_old_txs
+
+ class Connection
+ include ActiveMessaging::Adapter
+
+ register :reliable_msg
+
+ #configurable params
+ attr_accessor :reliable, :subscriptions, :destinations, :poll_interval, :current_subscription, :tx_timeout
+
+ #generic init method needed by a13g
+ def initialize cfg
+ @poll_interval = cfg[:poll_interval] || 1
+ @reliable = cfg[:reliable] || true
+ @tx_timeout = cfg[:tx_timeout] || ::ReliableMsg::Client::DEFAULT_TX_TIMEOUT
+
+ @subscriptions = {}
+ @destinations = {}
+ @current_subscription = 0
+ end
+
+ # called to cleanly get rid of connection
+ def disconnect
+ nil
+ end
+
+ # destination_name string, headers hash
+ # subscribe to listen on a destination
+ # use '/destination-type/name' convetion, like stomp
+ def subscribe destination_name, message_headers={}
+ get_or_create_destination(destination_name, message_headers)
+ if subscriptions.has_key? destination_name
+ subscriptions[destination_name].add
+ else
+ subscriptions[destination_name] = Subscription.new(destination_name, message_headers)
+ end
+ end
+
+ # destination_name string, headers hash
+ # unsubscribe to listen on a destination
+ def unsubscribe destination_name, message_headers={}
+ subscriptions[destination_name].remove
+ subscriptions.delete(destination_name) if subscriptions[destination_name].count <= 0
+ end
+
+ # destination_name string, body string, headers hash
+ # send a single message to a destination
+ def send destination_name, message_body, message_headers={}
+ dest = get_or_create_destination(destination_name)
+ begin
+ dest.put message_body, message_headers
+ rescue Object=>err
+ raise err unless reliable
+ puts "send failed, will retry in #{@poll_interval} seconds"
+ sleep @poll_interval
+ end
+ end
+
+ def get_or_create_destination destination_name, message_headers={}
+ return destinations[destination_name] if destinations.has_key? destination_name
+ dd = /^\/(queue|topic)\/(.*)$/.match(destination_name)
+ rm_class = dd[1].titleize
+ message_headers.delete("id")
+ rm_dest = "ReliableMsg::#{rm_class}".constantize.new(dd[2], message_headers)
+ destinations[destination_name] = rm_dest
+ end
+
+ # receive a single message from any of the subscribed destinations
+ # check each destination once, then sleep for poll_interval
+ def receive
+
+ raise "No subscriptions to receive messages from." if (subscriptions.nil? || subscriptions.empty?)
+ start = current_subscription
+ while true
+ self.current_subscription = ((current_subscription < subscriptions.length-1) ? current_subscription + 1 : 0)
+ sleep poll_interval if (current_subscription == start)
+ destination_name = subscriptions.keys.sort[current_subscription]
+ destination = destinations[destination_name]
+ unless destination.nil?
+ # from the way we use this, assume this is the start of a transaction,
+ # there should be no current transaction
+ ctx = Thread.current[::ReliableMsg::Client::THREAD_CURRENT_TX]
+ raise "There should not be an existing reliable-msg transaction. #{ctx.inspect}" if ctx
+
+ # start a new transaction
+ @tx = {:qm=>destination.queue_manager}
+ @tx[:tid] = @tx[:qm].begin @tx_timeout
+ Thread.current[::ReliableMsg::Client::THREAD_CURRENT_TX] = @tx
+ begin
+
+ # now call a get on the destination - it will use the transaction
+ #the commit or the abort will occur in the received or unreceive methods
+ reliable_msg = destination.get subscriptions[destination_name].headers[:selector]
+ @tx[:qm].commit(@tx[:tid]) if reliable_msg.nil?
+
+ rescue Object=>err
+ #abort the transaction on error
+ @tx[:qm].abort(@tx[:tid])
+
+ raise err unless reliable
+ puts "receive failed, will retry in #{@poll_interval} seconds"
+ sleep poll_interval
+ end
+ return Message.new(reliable_msg.id, reliable_msg.object, reliable_msg.headers, destination_name, 'MESSAGE', @tx) if reliable_msg
+
+ Thread.current[::ReliableMsg::Client::THREAD_CURRENT_TX] = nil
+ end
+ end
+ end
+
+ # called after a message is successfully received and processed
+ def received message, headers={}
+ message.transaction[:qm].commit(message.transaction[:tid])
+ Thread.current[::ReliableMsg::Client::THREAD_CURRENT_TX] = nil
+ end
+
+ # called after a message is successfully received and processed
+ def unreceive message, headers={}
+ message.transaction[:qm].abort(message.transaction[:tid])
+ Thread.current[::ReliableMsg::Client::THREAD_CURRENT_TX] = nil
+ end
+ end
+
+ class Subscription
+ attr_accessor :name, :headers, :count
+
+ def initialize(destination, headers={}, count=1)
+ @destination, @headers, @count = destination, headers, count
+ end
+
+ def add
+ @count += 1
+ end
+
+ def remove
+ @count -= 1
+ end
+
+ end
+
+ class Message
+ attr_accessor :id, :body, :headers, :command, :transaction
+
+ def initialize id, body, headers, destination_name, command='MESSAGE', transaction=nil
+ @id, @body, @headers, @command, @transaction = id, body, headers, command, transaction
+ headers['destination'] = destination_name
+ end
+
+ def to_s
+ "<ReliableMessaging::Message id='#{id}' body='#{body}' headers='#{headers.inspect}' command='#{command}' >"
+ end
+ end
+
+ end
+ end
+end
\ No newline at end of file
diff --git a/vendor/plugins/activemessaging/lib/activemessaging/adapters/stomp.rb b/vendor/plugins/activemessaging/lib/activemessaging/adapters/stomp.rb
new file mode 100644
index 0000000..b26c735
--- /dev/null
+++ b/vendor/plugins/activemessaging/lib/activemessaging/adapters/stomp.rb
@@ -0,0 +1,89 @@
+gem 'stomp'
+require 'stomp'
+
+module ActiveMessaging
+ module Adapters
+ module Stomp
+
+ class Connection < ::Stomp::Connection
+ include ActiveMessaging::Adapter
+ register :stomp
+
+ attr_accessor :reliable, :retryMax, :deadLetterQueue
+
+ def initialize(cfg)
+ @retryMax = cfg[:retryMax] || 0
+ @deadLetterQueue = cfg[:deadLetterQueue] || nil
+
+ cfg[:login] ||= ""
+ cfg[:passcode] ||= ""
+ cfg[:host] ||= "localhost"
+ cfg[:port] ||= "61613"
+ cfg[:reliable] ||= TRUE
+ cfg[:reconnectDelay] ||= 5
+ cfg[:clientId] ||= nil
+
+ if cfg[:clientId]
+ super(cfg[:login],cfg[:passcode],cfg[:host],cfg[:port].to_i,cfg[:reliable],cfg[:reconnectDelay],cfg[:clientId])
+ else
+ super(cfg[:login],cfg[:passcode],cfg[:host],cfg[:port].to_i,cfg[:reliable],cfg[:reconnectDelay])
+ end
+
+ end
+
+ def received message, headers={}
+ #check to see if the ack mode for this subscription is auto or client
+ # if the ack mode is client, send an ack
+ if (headers[:ack] === 'client')
+ ack_headers = message.headers.has_key?(:transaction) ? message.headers[:transaction] : {}
+ ack message.headers['message-id'], ack_headers
+ end
+ end
+
+ def unreceive message, headers={}
+ retry_count = message.headers['a13g-retry-count'].to_i || 0
+ transaction_id = "transaction-#{message.headers['message-id']}-#{retry_count}"
+
+ # start a transaction, send the message back to the original destination
+ self.begin(transaction_id)
+ begin
+
+ #check to see if the ack mode is client, and if it is, ack it in this transaction
+ if (headers[:ack] === 'client')
+ # ack the original message
+ self.ack message.headers['message-id'], message.headers.merge(:transaction=>transaction_id)
+ end
+
+ if retry_count < @retryMax
+ # now send the message back to the destination
+ # set the headers for message id, priginal message id, and retry count
+ message.headers['a13g-original-message-id'] = message.headers['message-id'] unless message.headers.has_key?('a13g-original-message-id')
+ message.headers['a13g-original-timestamp'] = message.headers['timestamp'] unless message.headers.has_key?('a13g-original-timestamp')
+ message.headers.delete('message-id')
+ message.headers.delete('timestamp')
+ message.headers['a13g-retry-count'] = retry_count + 1
+
+ # send the updated message to retry in the same transaction
+ self.send message.headers['destination'], message.body, message.headers.merge(:transaction=>transaction_id)
+
+ elsif retry_count >= @retryMax && @deadLetterQueue
+
+ # send the 'poison pill' message to the dead letter queue
+ self.send @deadLetterQueue, message.body, message.headers.merge(:transaction=>transaction_id)
+
+ end
+
+ # now commit the transaction
+ self.commit transaction_id
+ rescue Exception=>exc
+ # if there is an error, try to abort the transaction, then raise the error
+ self.abort transaction_id
+ raise exc
+ end
+ end
+
+ end
+
+ end
+ end
+end
\ No newline at end of file
diff --git a/vendor/plugins/activemessaging/lib/activemessaging/adapters/test.rb b/vendor/plugins/activemessaging/lib/activemessaging/adapters/test.rb
new file mode 100644
index 0000000..868b7e3
--- /dev/null
+++ b/vendor/plugins/activemessaging/lib/activemessaging/adapters/test.rb
@@ -0,0 +1,154 @@
+
+module ActiveMessaging
+ module Adapters
+ module Test
+
+ class Connection
+ include ActiveMessaging::Adapter
+ register :test
+
+ attr_accessor :config, :subscriptions, :destinations, :connected, :received_messages, :unreceived_messages
+
+ def initialize cfg
+ @config = cfg
+ @subscriptions = []
+ @destinations = []
+ @received_messages = []
+ @unreceived_messages = []
+ @connected = true
+ end
+
+ def disconnect
+ @subscriptions = []
+ @destinations = []
+ @received_messages = []
+ @unreceived_messages = []
+ @connected = false
+ end
+
+ def subscribe destination_name, subscribe_headers={}
+ open_destination destination_name
+ unless @subscriptions.find {|s| s.name == destination_name}
+ @subscriptions << Subscription.new(destination_name, subscribe_headers)
+ end
+ @subscriptions.last
+ end
+
+ def unsubscribe destination_name, unsubscribe_headers={}
+ @subscriptions.delete_if {|s| s.name == destination_name}
+ end
+
+ def send destination_name, message_body, message_headers={}
+ open_destination destination_name
+ destination = find_destination destination_name
+ destination.send Message.new(message_headers, nil, message_body, nil, destination)
+ end
+
+ def receive
+ destination = @destinations.find do |q|
+ find_subscription(q.name) && !q.empty?
+ end
+ destination.receive unless destination.nil?
+ end
+
+ # should not be 2 defs for receive, this isn't java, ya know? -Andrew
+ # def receive destination_name, headers={}
+ # subscribe destination_name, headers
+ # destination = find_destination destination_name
+ # message = destination.receive
+ # unsubscribe destination_name, headers
+ # message
+ # end
+
+ def received message, headers={}
+ @received_messages << message
+ end
+
+ def unreceive message, headers={}
+ @unreceived_messages << message
+ end
+
+ #test helper methods
+ def find_message destination_name, body
+ all_messages.find do |m|
+ m.headers['destination'] == destination_name && if body.is_a?(Regexp)
+ m.body =~ body
+ else
+ m.body == body.to_s
+ end
+ end
+ end
+
+ def open_destination destination_name
+ unless find_destination destination_name
+ @destinations << Destination.new(destination_name)
+ end
+ end
+
+ def find_destination destination_name
+ @destinations.find{|q| q.name == destination_name }
+ end
+
+ def find_subscription destination_name
+ @subscriptions.find{|s| s.name == destination_name}
+ end
+
+ def all_messages
+ @destinations.map {|q| q.messages }.flatten
+ end
+ end
+
+ class Destination
+
+ attr_accessor :name, :messages
+
+ def initialize name
+ @name = name
+ @messages = []
+ end
+
+ def receive
+ @messages.shift
+ end
+
+ def send message
+ @messages << message
+ end
+
+ def empty?
+ @messages.empty?
+ end
+
+ def to_s
+ "<Test::Destination name='#{name}' messages='#{@messages.inspect}'>"
+ end
+ end
+
+ class Subscription
+ attr_accessor :name, :headers
+
+ def initialize name, headers
+ @name = name
+ @headers = headers
+ end
+
+ def to_s
+ "<Test::Subscription destination='#{name}' headers='#{headers.inspect}' >"
+ end
+ end
+
+ class Message
+ attr_accessor :headers, :body, :command
+
+ def initialize headers, id, body, response, destination, command='MESSAGE'
+ @headers, @body, @command = headers, body, command
+ headers['destination'] = destination.name
+ end
+
+ def to_s
+ "<Test::Message body='#{body}' headers='#{headers.inspect}' command='#{command}' >"
+ end
+ end
+ end
+ end
+end
\ No newline at end of file
diff --git a/vendor/plugins/activemessaging/lib/activemessaging/adapters/wmq.rb b/vendor/plugins/activemessaging/lib/activemessaging/adapters/wmq.rb
new file mode 100644
index 0000000..085aa57
--- /dev/null
+++ b/vendor/plugins/activemessaging/lib/activemessaging/adapters/wmq.rb
@@ -0,0 +1,202 @@
+################################################################################
+# Copyright 2007 S. Perez. RBC Dexia Investor Servies Bank
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+################################################################################
+
+#
+# WebSphere MQ adapter for activemessaging
+#
+require 'wmq/wmq'
+
+module ActiveMessaging
+ module Adapters
+ module Adapter
+
+ # Connection class needed by a13g
+ class Connection
+ include ActiveMessaging::Adapter
+ register :wmq
+
+ # Needed by a13g but never used within this adapter
+ attr_accessor :reliable
+
+ # Generic init method needed by a13g
+ def initialize(cfg)
+ # Set default values
+ cfg[:poll_interval] ||= 0.1
+
+ # Initialize instance members
+ # Trick for the connection_options is to allow settings WMQ constants directly in broker.yml :))
+ @connection_options = cfg.each_pair {|key, value| cfg[key] = instance_eval(value) if (value.instance_of?(String) && value.match("WMQ::")) }
+ @queue_names = []
+ @current_queue = 0
+ @queues = {}
+ end
+
+ # Disconnect method needed by a13g
+ # No need to disconnect from the queue manager since connection and disconnection occurs inside the send and receive methods
+ # headers is never used
+ def disconnect(headers = {})
+ end
+
+ # Receive method needed by a13g
+ def receive
+ raise "No subscription to receive messages from" if (@queue_names.nil? || @queue_names.empty?)
+ start = @current_queue
+ while true
+ @current_queue = ((@current_queue < @queue_names.length-1) ? @current_queue + 1 : 0)
+ sleep(@connection_options[:poll_interval]) if (@current_queue == start)
+ q = @queues[@queue_names[@current_queue]]
+ unless q.nil?
+ message = retrieve_message(q)
+ return message unless message.nil?
+ end
+ end
+ end
+
+ # Send method needed by a13g
+ # headers may contains 2 different hashes to gives more control over the sending process
+ # :descriptor => {...} to populate the descriptor of the message
+ # :put_options => {...} to specify the put options for that message
+ def send(q_name, message_data, headers={})
+ WMQ::QueueManager.connect(@connection_options) do |qmgr|
+ qmgr.open_queue(:q_name => q_name, :mode => :output) do |queue|
+
+ message_descriptor = headers[:descriptor] || {:format => WMQ::MQFMT_STRING}
+ put_options = headers[:put_options].nil? ? {} : headers[:put_options].dup
+
+ wmq_message = WMQ::Message.new(:data => message_data, :descriptor => message_descriptor)
+ queue.put(put_options.merge(:message => wmq_message, :data => nil))
+ return Message.new(wmq_message, q_name)
+ end
+ end
+ end
+
+ # Subscribe method needed by a13g
+ # headers may contains a hash to give more control over the get operation on the queue
+ # :get_options => {...} to specify the get options when receiving messages
+ # Warning : get options are set only on the first queue subscription and are common to all the queue's subscriptions
+ # Any other get options passed with subsequent subscribe on an existing queue will be discarded
+ # subId is never used
+ def subscribe(q_name, headers={}, subId=NIL)
+ if @queues[q_name].nil?
+ get_options = headers[:get_options] || {}
+ q = Queue.new(q_name, get_options)
+ @queues[q_name] = q
+ @queue_names << q.name
+ end
+
+ q.add_subscription
+ end
+
+ # Unsubscribe method needed by a13g
+ # Stop listening the queue only after the last unsubscription
+ # headers is never used
+ # subId is never used
+ def unsubscribe(q_name, headers={}, subId=NIL)
+ q = @queues[q_name]
+ unless q.nil?
+ q.remove_subscription
+ unless q.has_subscription?
+ @queues.delete(q_name)
+ @queue_names.delete(q_name)
+ end
+ end
+ end
+
+ # called after a message is successfully received and processed
+ def received message, headers={}
+ end
+
+ # called after a message is successfully received but unsuccessfully processed
+ # purpose is to return the message to the destination so receiving and processing and be attempted again
+ def unreceive message, headers={}
+ end
+
+ private
+
+ # Retrieve the first available message from the specicied queue
+ # Return nil if queue is empty
+ def retrieve_message(q)
+ WMQ::QueueManager.connect(@connection_options) do |qmgr|
+ qmgr.open_queue(:q_name => q.name, :mode => :input) do |queue|
+
+ get_options = q.get_options.dup
+ wmq_message = WMQ::Message.new
+
+ if queue.get(get_options.merge(:message => wmq_message))
+ return Message.new(wmq_message, q.name)
+ else
+ return nil
+ end
+ end
+ end
+ end
+ end
+
+ # Message class needed by a13g (based on the same Message class in Stomp adapter)
+ # Contains a reference to the MQ message object ;-) !
+ class Message
+ # Accessors needed by a13g
+ attr_accessor :headers, :body, :command, :wmq_message
+
+ def initialize(wmq_message, q_name)
+ @wmq_message = wmq_message
+
+ # Needed by a13g
+ @headers = {'destination' => q_name}
+ @body = wmq_message.data
+ @command = 'MESSAGE'
+ end
+
+ def to_s
+ "<Adapter::Message headers=#{@headers.inspect} body='#{@body}' command='#{@command}' wmq_message=#{@wmq_message}>"
+ end
+ end
+
+ private
+
+ # Queue class is used to keep track of the subscriptions
+ # It contains :
+ # - name of the queue
+ # - options to use when getting from the queue
+ # - number of subscriptions
+ class Queue
+ attr_accessor :name, :get_options, :nb_subscriptions
+
+ def initialize(name, get_options)
+ @name, @get_options = name, get_options
+ @nb_subscriptions = 0
+ end
+
+ def add_subscription
+ @nb_subscriptions += 1
+ end
+
+ def remove_subscription
+ @nb_subscriptions -= 1 unless @nb_subscriptions > 0
+ end
+
+ def has_subscription?
+ @nb_subscriptions > 0
+ end
+
+ def to_s
+ "<Adapter::Queue name='#{@name}' get_options=#{@get_options} nb_subscriptions=#{@nb_subscriptions}>"
+ end
+ end
+
+ end
+ end
+end
\ No newline at end of file
diff --git a/vendor/plugins/activemessaging/lib/activemessaging/filter.rb b/vendor/plugins/activemessaging/lib/activemessaging/filter.rb
new file mode 100644
index 0000000..5fbff82
--- /dev/null
+++ b/vendor/plugins/activemessaging/lib/activemessaging/filter.rb
@@ -0,0 +1,29 @@
+# 'abstract' base class for ActiveMessaging filter classes
+module ActiveMessaging
+ class Filter
+
+ #automatically make it so filters are message senders
+ include MessageSender
+
+ # give filters easy access to the logger
+ def logger()
+ @@logger = ActiveMessaging.logger unless defined?(@@logger)
+ @@logger
+ end
+
+ # these are the headers available for a message from the 'details' hash
+ # :receiver=>processor
+ # :destination=>destination object
+ # :direction => :incoming
+
+ # :publisher => publisher - optional
+ # :destination => destination object
+ # :direction => :outgoing
+
+ # if you raise a StopProcessingException, it will cause this to be the last filter to be processed, and will prevent any further processing
+ def process(message, routing)
+ raise NotImplementedError.new("Implement the process method in your own filter class that extends ActiveMessaging::Filter")
+ end
+
+ end
+end
\ No newline at end of file
diff --git a/vendor/plugins/activemessaging/lib/activemessaging/gateway.rb b/vendor/plugins/activemessaging/lib/activemessaging/gateway.rb
new file mode 100644
index 0000000..1ffc09f
--- /dev/null
+++ b/vendor/plugins/activemessaging/lib/activemessaging/gateway.rb
@@ -0,0 +1,410 @@
+require 'yaml'
+
+module ActiveMessaging
+
+ class Gateway
+ cattr_accessor :adapters, :subscriptions, :named_destinations, :filters, :processor_groups, :connections
+ @@adapters = {}
+ @@subscriptions = {}
+ @@named_destinations = {}
+ @@filters = []
+ @@connections = {}
+ @@processor_groups = {}
+ @@current_processor_group = nil
+
+ # these are used to manage the running connection threads
+ @@running = true
+ @@connection_threads = {}
+ @@guard = Mutex.new
+
+ class <<self
+
+ # Starts up an message listener to start polling for messages on each configured connection, and dispatching processing
+ def start
+
+ # subscribe - creating connections along the way
+ subscribe
+
+ # for each conection, start a thread
+ @@connections.each do |name, conn|
+ @@connection_threads[name] = Thread.start do
+ while @@running
+ begin
+ Thread.current[:message] = nil
+ Thread.current[:message] = conn.receive
+ rescue StopProcessingException
+ ActiveMessaging.logger.error "ActiveMessaging: thread[#{name}]: Processing Stopped - receive interrupted, will process last message if already received"
+ rescue Object=>exception
+ ActiveMessaging.logger.error "ActiveMessaging: thread[#{name}]: Exception from connection.receive: #{exception.message}\n" + exception.backtrace.join("\n\t")
+ ensure
+ dispatch Thread.current[:message] if Thread.current[:message]
+ Thread.current[:message] = nil
+ end
+ Thread.pass
+ end
+ end
+ end
+
+ while @@running
+ trap("TERM", "EXIT")
+ living = false
+ @@connection_threads.each { |name, thread| living ||= thread.alive? }
+ @@running = living
+ sleep 1
+ end
+ ActiveMessaging.logger.error "All connection threads have died..."
+ rescue Interrupt
+ ActiveMessaging.logger.error "\n<<Interrupt received>>\n"
+ rescue Object=>exception
+ ActiveMessaging.logger.error "#{exception.class.name}: #{exception.message}\n\t#{exception.backtrace.join("\n\t")}"
+ raise exception
+ ensure
+ ActiveMessaging.logger.error "Cleaning up..."
+ stop
+ ActiveMessaging.logger.error "=> END"
+ end
+
+ def stop
+ # first tell the threads to stop their looping, so they'll stop when next complete a receive/dispatch cycle
+ @@running = false
+
+ # if they are dispatching (i.e. !thread[:message].nil?), wait for them to finish
+ # if they are receiving (i.e. thread[:message].nil?), stop them by raising exception
+ dispatching = true
+ while dispatching
+ dispatching = false
+ @@connection_threads.each do |name, thread|
+ if thread[:message]
+ dispatching = true
+ # if thread got killed, but dispatch not done, try it again
+ if thread.alive?
+ ActiveMessaging.logger.error "Waiting on thread #{name} to finish processing last message..."
+ else
+ ActiveMessaging.logger.error "Starting thread #{name} to finish processing last message..."
+ msg = thread[:message]
+ thread.exit
+ thread = Thread.start do
+ begin
+ Thread.current[:message] = msg
+ dispatch Thread.current[:message]
+ ensure
+ Thread.current[:message] = nil
+ end
+ end
+ end
+ else
+ thread.raise StopProcessingException, "Time to stop." if thread.alive?
+ end
+ end
+ sleep(1)
+ end
+ unsubscribe
+ disconnect
+ end
+
+ def connection broker_name='default'
+ return @@connections[broker_name] if @@connections.has_key?(broker_name)
+ config = load_connection_configuration(broker_name)
+ @@connections[broker_name] = Gateway.adapters[config[:adapter]].new(config)
+ end
+
+ def register_adapter adapter_name, adapter_class
+ adapters[adapter_name] = adapter_class
+ end
+
+ def filter filter, options = {}
+ options[:direction] = :bidirectional if options[:direction].nil?
+ filters << [filter, options]
+ end
+
+ def subscribe
+ subscriptions.each { |key, subscription| subscription.subscribe }
+ end
+
+ def unsubscribe
+ subscriptions.each { |key, subscription| subscription.unsubscribe }
+ end
+
+ def disconnect
+ @@connections.each { |key,connection| connection.disconnect }
+ @@connections = {}
+ end
+
+ def execute_filter_chain(direction, message, details={})
+ filters.each do |filter, options|
+ if apply_filter?(direction, details, options)
+ begin
+ filter_obj = create_filter(filter, options)
+ filter_obj.process(message, details)
+ rescue ActiveMessaging::StopFilterException => sfe
+ ActiveMessaging.logger.error "Filter: #{filter_obj.inspect} threw StopProcessingException: #{sfe.message}"
+ return
+ end
+ end
+ end
+ yield(message)
+ end
+
+ def apply_filter?(direction, details, options)
+ # check that it is the correct direction
+ result = if direction.to_sym == options[:direction] || options[:direction] == :bidirectional
+ if options.has_key?(:only) && [options[:only]].flatten.include?(details[:destination].name)
+ true
+ elsif options.has_key?(:except) && ![options[:except]].flatten.include?(details[:destination].name)
+ true
+ elsif !options.has_key?(:only) && !options.has_key?(:except)
+ true
+ end
+ end
+ result
+ end
+
+ def create_filter(filter, options)
+ filter_class = if filter.is_a?(String) or filter.is_a?(Symbol)
+ filter.to_s.camelize.constantize
+ elsif filter.is_a?(Class)
+ filter
+ end
+
+ if filter_class
+ if filter_class.respond_to?(:process) && (filter_class.method(:process).arity.abs > 0)
+ filter_class
+ elsif filter_class.instance_method(:initialize).arity.abs == 1
+ filter_class.new(options)
+ elsif filter_class.instance_method(:initialize).arity == 0
+ filter_class.new
+ else
+ raise "Filter #{filter} could not be created, no 'initialize' matched."
+ end
+ else
+ raise "Filter #{filter} could not be loaded, created, or used!"
+ end
+ end
+
+ def prepare_application
+ Dispatcher.prepare_application_for_dispatch
+ end
+
+ def reset_application
+ Dispatcher.reset_application_after_dispatch
+ end
+
+ def dispatch(message)
+ @@guard.synchronize {
+ begin
+ prepare_application
+ _dispatch(message)
+ rescue Object => exc
+ ActiveMessaging.logger.error "Dispatch exception: #{exc}"
+ ActiveMessaging.logger.error exc.backtrace.join("\n\t")
+ raise exc
+ ensure
+ reset_application
+ end
+ }
+ end
+
+ def _dispatch(message)
+ case message.command
+ when 'ERROR'
+ ActiveMessaging.logger.error('Error from messaging infrastructure: ' + message.headers['message'])
+ when 'MESSAGE'
+ abort = false
+ processed = false
+
+ subscriptions.each do |key, subscription|
+ if subscription.matches?(message) then
+ processed = true
+ routing = {
+ :receiver=>subscription.processor_class,
+ :destination=>subscription.destination,
+ :direction => :incoming
+ }
+ begin
+ execute_filter_chain(:incoming, message, routing) do |m|
+ result = subscription.processor_class.new.process!(m)
+ end
+ rescue ActiveMessaging::AbortMessageException
+ abort_message subscription, message
+ abort = true
+ return
+ ensure
+ acknowledge_message subscription, message unless abort
+ end
+ end
+ end
+
+ ActiveMessaging.logger.error("No-one responded to #{message}") unless processed
+ else
+ ActiveMessaging.logger.error('Unknown message command: ' + message.inspect)
+ end
+ end
+
+ # acknowledge_message is called when the message has been processed w/o error by at least one processor
+ def acknowledge_message subscription, message
+ connection(subscription.destination.broker_name).received message, subscription.subscribe_headers
+ end
+
+ # abort_message is called when procesing the message raises a ActiveMessaging::AbortMessageException
+ # indicating the message should be returned to the destination so it can be tried again, later
+ def abort_message subscription, message
+ connection(subscription.destination.broker_name).unreceive message, subscription.subscribe_headers
+ end
+
+ def define
+ #run the rest of messaging.rb
+ yield self
+ end
+
+ def destination destination_name, destination, publish_headers={}, broker='default'
+ raise "You already defined #{destination_name} to #{named_destinations[destination_name].value}" if named_destinations.has_key?(destination_name)
+ named_destinations[destination_name] = Destination.new destination_name, destination, publish_headers, broker
+ end
+
+ alias queue destination
+
+ def find_destination destination_name
+ real_destination = named_destinations[destination_name]
+ raise "You have not yet defined a destination named #{destination_name}. Destinations currently defined are [#{named_destinations.keys.join(',')}]" if real_destination.nil?
+ real_destination
+ end
+
+ alias find_queue find_destination
+
+ def subscribe_to destination_name, processor, headers={}
+ proc_name = processor.name.underscore
+ proc_sym = processor.name.underscore.to_sym
+ if (!current_processor_group || processor_groups[current_processor_group].include?(proc_sym))
+ @@subscriptions["#{proc_name}:#{destination_name}"]= Subscription.new(find_destination(destination_name), processor, headers)
+ end
+ end
+
+ def publish destination_name, body, publisher=nil, headers={}, timeout=10
+ raise "You cannot have a nil or empty destination name." if destination_name.nil?
+ raise "You cannot have a nil or empty message body." if (body.nil? || body.empty?)
+
+ real_destination = find_destination(destination_name)
+ details = {
+ :publisher => publisher,
+ :destination => real_destination,
+ :direction => :outgoing
+ }
+ message = OpenStruct.new(:body => body, :headers => headers.reverse_merge(real_destination.publish_headers))
+ begin
+ Timeout.timeout timeout do
+ execute_filter_chain(:outgoing, message, details) do |message|
+ connection(real_destination.broker_name).send real_destination.value, message.body, message.headers
+ end
+ end
+ rescue Timeout::Error=>toe
+ ActiveMessaging.logger.error("Timed out trying to send the message #{message} to destination #{destination_name} via broker #{real_destination.broker_name}")
+ raise toe
+ end
+ end
+
+ def receive destination_name, receiver=nil, subscribe_headers={}, timeout=10
+ raise "You cannot have a nil or empty destination name." if destination_name.nil?
+ conn = nil
+ dest = find_destination destination_name
+ config = load_connection_configuration(dest.broker_name)
+ subscribe_headers['id'] = receiver.name.underscore unless (receiver.nil? or subscribe_headers.key? 'id')
+ Timeout.timeout timeout do
+ conn = Gateway.adapters[config[:adapter]].new(config)
+ conn.subscribe(dest.value, subscribe_headers)
+ message = conn.receive
+ conn.received message, subscribe_headers
+ return message
+ end
+ rescue Timeout::Error=>toe
+ ActiveMessaging.logger.error("Timed out trying to receive a message on destination #{destination_name}")
+ raise toe
+ ensure
+ conn.disconnect unless conn.nil?
+ end
+
+ def processor_group group_name, *processors
+ if processor_groups.has_key? group_name
+ processor_groups[group_name] = processor_groups[group_name] + processors
+ else
+ processor_groups[group_name] = processors
+ end
+ end
+
+ def current_processor_group
+ if ARGV.length > 0 && !@@current_processor_group
+ ARGV.each {|arg|
+ pair = arg.split('=')
+ if pair[0] == 'process-group'
+ group_sym = pair[1].to_sym
+ if processor_groups.has_key? group_sym
+ @@current_processor_group = group_sym
+ else
+ ActiveMessaging.logger.error "Unrecognized process-group."
+ ActiveMessaging.logger.error "You specified process-group #{pair[1]}, make sure this is specified in config/messaging.rb"
+ ActiveMessaging.logger.error " ActiveMessaging::Gateway.define do |s|"
+ ActiveMessaging.logger.error " s.processor_groups = { :group1 => [:foo_bar1_processor], :group2 => [:foo_bar2_processor] }"
+ ActiveMessaging.logger.error " end"
+ exit
+ end
+ end
+ }
+ end
+ @@current_processor_group
+ end
+
+ def load_connection_configuration(label='default')
+ @broker_yml = YAML::load(ERB.new(IO.read(File.join(RAILS_ROOT, 'config', 'broker.yml'))).result) if @broker_yml.nil?
+ if label == 'default'
+ config = @broker_yml[RAILS_ENV].symbolize_keys
+ else
+ config = @broker_yml[RAILS_ENV][label].symbolize_keys
+ end
+ config[:adapter] = config[:adapter].to_sym if config[:adapter]
+ config[:adapter] ||= :stomp
+ return config
+ end
+
+ end
+
+ end
+
+ class Subscription
+ attr_accessor :destination, :processor_class, :subscribe_headers
+
+ def initialize(destination, processor_class, subscribe_headers = {})
+ @destination, @processor_class, @subscribe_headers = destination, processor_class, subscribe_headers
+ subscribe_headers['id'] = processor_class.name.underscore unless subscribe_headers.key? 'id'
+ end
+
+ def matches?(message)
+ message.headers['destination'].to_s == @destination.value.to_s
+ end
+
+ def subscribe
+ ActiveMessaging.logger.error "=> Subscribing to #{destination.value} (processed by #{processor_class})"
+ Gateway.connection(@destination.broker_name).subscribe(@destination.value, subscribe_headers)
+ end
+
+ def unsubscribe
+ ActiveMessaging.logger.error "=> Unsubscribing from #{destination.value} (processed by #{processor_class})"
+ Gateway.connection(destination.broker_name).unsubscribe(destination.value, subscribe_headers)
+ end
+ end
+
+ class Destination
+ DEFAULT_PUBLISH_HEADERS = { :persistent=>true }
+
+ attr_accessor :name, :value, :publish_headers, :broker_name
+
+ def initialize(name, value, publish_headers, broker_name)
+ @name, @value, @publish_headers, @broker_name = name, value, publish_headers, broker_name
+ @publish_headers.reverse_merge! DEFAULT_PUBLISH_HEADERS
+ end
+
+ def to_s
+ "#{broker_name}: #{name} => '#{value}'"
+ end
+
+ end
+
+end #module
diff --git a/vendor/plugins/activemessaging/lib/activemessaging/message_sender.rb b/vendor/plugins/activemessaging/lib/activemessaging/message_sender.rb
new file mode 100644
index 0000000..c36e879
--- /dev/null
+++ b/vendor/plugins/activemessaging/lib/activemessaging/message_sender.rb
@@ -0,0 +1,30 @@
+require 'logger'
+
+module ActiveMessaging
+
+ # This is a module so that we can send messages from (for example) web page controllers, or can receive a single message
+ module MessageSender
+
+ def self.included(included_by)
+ class << included_by
+ def publishes_to destination_name
+ Gateway.find_destination destination_name
+ end
+
+ def receives_from destination_name
+ Gateway.find_destination destination_name
+ end
+ end
+ end
+
+ def publish destination_name, message, headers={}, timeout=10
+ Gateway.publish(destination_name, message, self.class, headers, timeout)
+ end
+
+ def receive destination_name, headers={}, timeout=10
+ Gateway.receive(destination_name, self.class, headers, timeout)
+ end
+
+ end
+
+end
\ No newline at end of file
diff --git a/vendor/plugins/activemessaging/lib/activemessaging/processor.rb b/vendor/plugins/activemessaging/lib/activemessaging/processor.rb
new file mode 100644
index 0000000..f3f4362
--- /dev/null
+++ b/vendor/plugins/activemessaging/lib/activemessaging/processor.rb
@@ -0,0 +1,45 @@
+# 'abstract' base class for ActiveMessaging processor classes
+module ActiveMessaging
+
+ class Processor
+ include MessageSender
+
+ attr_reader :message
+
+ class<<self
+ def subscribes_to destination_name, headers={}
+ ActiveMessaging::Gateway.subscribe_to destination_name, self, headers
+ end
+ end
+
+ def logger()
+ @@logger = ActiveMessaging.logger unless defined?(@@logger)
+ @@logger
+ end
+
+ def on_message(message)
+ raise NotImplementedError.new("Implement the on_message method in your own processor class that extends ActiveMessaging::Processor")
+ end
+
+ def on_error(exception)
+ raise exception
+ end
+
+ # Bind the processor to the current message so that the processor could
+ # potentially access headers and other attributes of the message
+ def process!(message)
+ @message = message
+ return on_message(message.body)
+ rescue Exception
+ begin
+ on_error($!)
+ rescue ActiveMessaging::AbortMessageException => rpe
+ logger.error "Processor:process! - AbortMessageException caught."
+ raise rpe
+ rescue Exception => ex
+ logger.error "Processor:process! - error in on_error, will propagate no further: #{ex.message}"
+ end
+ end
+
+ end
+end
\ No newline at end of file
diff --git a/vendor/plugins/activemessaging/lib/activemessaging/support.rb b/vendor/plugins/activemessaging/lib/activemessaging/support.rb
new file mode 100644
index 0000000..6a48d60
--- /dev/null
+++ b/vendor/plugins/activemessaging/lib/activemessaging/support.rb
@@ -0,0 +1,20 @@
+require 'dispatcher' unless defined?(::Dispatcher)
+::Dispatcher.class_eval do
+
+ def self.prepare_application_for_dispatch
+ if (self.private_methods.include? "prepare_application")
+ prepare_application
+ else
+ new(STDOUT).prepare_application
+ end
+ end
+
+ def self.reset_application_after_dispatch
+ if (self.private_methods.include? "reset_after_dispatch")
+ reset_after_dispatch
+ else
+ new(STDOUT).cleanup_application
+ end
+ end
+
+end
diff --git a/vendor/plugins/activemessaging/lib/activemessaging/test_helper.rb b/vendor/plugins/activemessaging/lib/activemessaging/test_helper.rb
new file mode 100644
index 0000000..3a2bf67
--- /dev/null
+++ b/vendor/plugins/activemessaging/lib/activemessaging/test_helper.rb
@@ -0,0 +1,159 @@
+require 'test/unit'
+#require "#{File.dirname(__FILE__)}/trace_filter"
+
+
+module ActiveMessaging #:nodoc:
+
+ # def self.reload_activemessaging
+ # end
+
+ class Gateway
+
+ def self.reset
+ unsubscribe
+ disconnect
+ @@filters = []
+ @@subscriptions = {}
+ @@named_destinations = {}
+ @@processor_groups = {}
+ @@current_processor_group = nil
+ @@connections = {}
+ end
+
+ end
+
+ class TestMessage
+ attr_reader :headers
+ attr_accessor :body
+
+ def initialize(destination, headers = {}, body = "")
+ @headers, @body = headers, body
+ @headers['destination'] = destination
+ end
+
+ def command
+ "MESSAGE"
+ end
+ end
+
+ module TestHelper
+
+ #Many thanks must go to the fixture_caching plugin
+ #for showing how to properly alias setup and teardown
+ #from within the tyranny of the fixtures code
+ def self.included(base)
+ base.extend(ClassMethods)
+
+ class << base
+ alias_method_chain :method_added, :a13g_hack
+ end
+
+ base.class_eval do
+ alias_method_chain :setup, :a13g
+ alias_method_chain :teardown, :a13g
+ end
+ end
+
+ module ClassMethods
+ def method_added_with_a13g_hack method
+ return if caller.first.match(/#{__FILE__}/)
+ case method.to_sym
+ when :setup
+ @setup_method = instance_method(:setup)
+ alias_method :setup, :setup_with_a13g
+ when :teardown
+ @teardown_method = instance_method(:teardown)
+ alias_method :teardown, :teardown_with_a13g
+ else
+ method_added_without_a13g_hack(method)
+ end
+ end
+
+ def setup_method
+ @setup_method
+ end
+
+ def teardown_method
+ @teardown_method
+ end
+ end
+
+ def setup_with_a13g
+ setup_without_a13g
+ self.class.setup_method.bind(self).call unless self.class.setup_method.nil?
+ ActiveMessaging.reload_activemessaging
+ end
+
+ def teardown_with_a13g
+ teardown_without_a13g
+ self.class.teardown_method.bind(self).call unless self.class.teardown_method.nil?
+ ActiveMessaging::Gateway.reset
+ end
+
+ def mock_publish destination, body, publisher=nil, headers={}
+ ActiveMessaging::Gateway.publish destination, body, publisher, headers
+ end
+
+ def assert_message destination, body
+ destination = ActiveMessaging::Gateway.find_destination(destination).value
+ error_message = <<-EOF
+ Message for '#{destination}' with '#{body}' is not present.
+ Messages:
+ #{ActiveMessaging::Gateway.connection('default').all_messages.inspect}
+ EOF
+ assert ActiveMessaging::Gateway.connection.find_message(destination, body), error_message
+ end
+
+ def assert_no_message_with destination, body
+ destination = ActiveMessaging::Gateway.find_destination(destination).value
+ error_message = <<-EOF
+ Message for '#{destination}' with '#{body}' is present.
+ Messages:
+ #{ActiveMessaging::Gateway.connection('default').all_messages.inspect}
+ EOF
+ assert_nil ActiveMessaging::Gateway.connection('default').find_message(destination, body), error_message
+ end
+
+ def assert_no_messages destination
+ destination = ActiveMessaging::Gateway.find_destination(destination).value
+ error_message = <<-EOF
+ Expected no messages.
+ Messages:
+ #{ActiveMessaging::Gateway.connection('default').all_messages.inspect}
+ EOF
+ assert_equal [], ActiveMessaging::Gateway.connection('default').all_messages, error_message
+ end
+
+ def assert_subscribed destination
+ destination = ActiveMessaging::Gateway.find_destination(destination).value
+ error_message = <<-EOF
+ Not subscribed to #{destination}.
+ Subscriptions:
+ #{ActiveMessaging::Gateway.connection('default').subscriptions.inspect}
+ EOF
+ assert ActiveMessaging::Gateway.connection('default').find_subscription(destination), error_message
+ end
+
+ def assert_not_subscribed destination
+ destination = ActiveMessaging::Gateway.find_destination(destination).value
+ error_message = <<-EOF
+ Subscribed to #{destination}.
+ Subscriptions:
+ #{ActiveMessaging::Gateway.connection('default').subscriptions.inspect}
+ EOF
+ assert_nil ActiveMessaging::Gateway.connection('default').find_subscription(destination), error_message
+ end
+
+ def assert_has_messages destination
+ destination_name = ActiveMessaging::Gateway.find_destination(destination).value
+ error_message = <<-EOF
+ No messages for #{destination_name}.
+ All messages:
+ #{ActiveMessaging::Gateway.connection('default').all_messages.inspect}
+ EOF
+ destination = ActiveMessaging::Gateway.connection('default').find_destination destination_name
+ assert !destination.nil? && !destination.messages.empty?, error_message
+ end
+ end
+end
+
diff --git a/vendor/plugins/activemessaging/lib/activemessaging/trace_filter.rb b/vendor/plugins/activemessaging/lib/activemessaging/trace_filter.rb
new file mode 100644
index 0000000..4021f28
--- /dev/null
+++ b/vendor/plugins/activemessaging/lib/activemessaging/trace_filter.rb
@@ -0,0 +1,34 @@
+class TraceFilter< ActiveMessaging::Filter
+ include ActiveMessaging::MessageSender
+
+ def initialize(options)
+ @queue = options[:queue]
+ TraceFilter.publishes_to @queue
+ end
+
+ def process message, routing
+
+ unless ( routing[:destination].name == @queue ) then
+ puts "\nTrace: direction = #{routing[:direction]} publisher=#{routing[:publisher]} queue=#{routing[:destination].name} @queue=#{@queue}\n"
+ if routing[:direction].to_sym==:outgoing then
+ "trace from outgoing"
+ publish @queue, "<sent>"+
+ "<from>#{routing[:publisher]}</from>" +
+ "<queue>#{routing[:destination].name}</queue>" +
+ "<message>#{message.body}</message>" +
+ "</sent>"
+ end
+ if routing[:direction].to_sym==:incoming then
+ "trace from incoming"
+ publish @queue, "<received>"+
+ "<by>#{routing[:receiver]}</by>" +
+ "<queue>#{routing[:destination].name}</queue>" +
+ "<message>#{message.body}</message>" +
+ "</received>"
+ end
+ end
+
+ end
+
+end
+
diff --git a/vendor/plugins/activemessaging/messaging.rb.example b/vendor/plugins/activemessaging/messaging.rb.example
new file mode 100644
index 0000000..6e13368
--- /dev/null
+++ b/vendor/plugins/activemessaging/messaging.rb.example
@@ -0,0 +1,5 @@
+
+ActiveMessaging::Dispatcher.define do |s|
+ s.queue :orders, '/queue/Orders'
+ s.queue :completed, '/queue/CompletedItems'
+end
\ No newline at end of file
diff --git a/vendor/plugins/activemessaging/poller.rb b/vendor/plugins/activemessaging/poller.rb
new file mode 100644
index 0000000..6093e36
--- /dev/null
+++ b/vendor/plugins/activemessaging/poller.rb
@@ -0,0 +1,14 @@
+#!/usr/bin/env ruby
+# Make sure stdout and stderr write out without delay for using with daemon like scripts
+STDOUT.sync = true; STDOUT.flush
+STDERR.sync = true; STDERR.flush
+
+# Load Rails
+RAILS_ROOT=File.expand_path(File.join(File.dirname(__FILE__), '..','..','..'))
+load File.join(RAILS_ROOT, 'config', 'environment.rb')
+
+# Load ActiveMessaging processors
+ActiveMessaging::load_processors
+
+# Start it up!
+ActiveMessaging::start
diff --git a/vendor/plugins/activemessaging/tasks/start_consumers.rake b/vendor/plugins/activemessaging/tasks/start_consumers.rake
new file mode 100644
index 0000000..5ec1946
--- /dev/null
+++ b/vendor/plugins/activemessaging/tasks/start_consumers.rake
@@ -0,0 +1,8 @@
+namespace "activemessaging" do
+
+ desc 'Run all consumers'
+ task :start_consumers do
+ load File.dirname(__FILE__) + '/../poller.rb'
+ end
+
+end
\ No newline at end of file
diff --git a/vendor/plugins/activemessaging/test/all_tests.rb b/vendor/plugins/activemessaging/test/all_tests.rb
new file mode 100644
index 0000000..f0608d4
--- /dev/null
+++ b/vendor/plugins/activemessaging/test/all_tests.rb
@@ -0,0 +1,10 @@
+require 'rubygems'
+require_gem 'coverage'
+
+require 'test/unit'
+
+require 'test/config_test'
+require 'test/filter_test'
+require 'test/tracer_test'
+require 'test/jms_test'
+require 'test/asqs_test'
diff --git a/vendor/plugins/activemessaging/test/asqs_test.rb b/vendor/plugins/activemessaging/test/asqs_test.rb
new file mode 100644
index 0000000..4456b62
--- /dev/null
+++ b/vendor/plugins/activemessaging/test/asqs_test.rb
@@ -0,0 +1,98 @@
+require File.dirname(__FILE__) + '/test_helper'
+
+class AsqsTest < Test::Unit::TestCase
+
+ class FakeHTTPResponse
+ attr_accessor :headers, :body
+
+ def to_hash
+ @headers
+ end
+
+ def kind_of? kind
+ true
+ end
+ end
+
+ ActiveMessaging::Adapters::AmazonSQS::Connection.class_eval do
+ attr_accessor :test_response, :test_headers
+
+ DEFAULT_RESPONSE = <<EOM
+ <ListQueuesResponse xmlns='http://queue.amazonaws.com/doc/2007-05-01/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:type='ListQueuesResponse'>
+ <Queues>
+ <QueueUrl>http://queue.amazonaws.com/thisisatestid1/test1</QueueUrl>
+ <QueueUrl>http://queue.amazonaws.com/thisisatestid12/test2</QueueUrl>
+ </Queues>
+ <ResponseStatus><StatusCode>Success</StatusCode><RequestId>cb919c0a-9bce-4afe-9b48-9bdf2412bb67</RequestId></ResponseStatus>
+ </ListQueuesResponse>
+EOM
+
+ def http_request h, p, r
+ raise test_response if test_response.is_a?(Exception)
+
+ resp = FakeHTTPResponse.new
+ resp.body = @test_response || DEFAULT_RESPONSE
+ resp.headers = @test_headers || {}
+ return resp
+ end
+ end
+
+
+ def setup
+ @connection = ActiveMessaging::Adapters::AmazonSQS::Connection.new(:reliable=>false, :access_key_id=>'access_key_id', :secret_access_key=>'secret_access_key', :reconnectDelay=>1)
+ @d = "asqs"
+ @message = "mary had a little lamb"
+ end
+
+ def teardown
+ @connection.disconnect unless @connection.nil?
+ end
+
+ def test_allow_underscore_and_dash
+ assert_nothing_raised do
+ @connection.subscribe 'name-name_dash'
+ end
+ assert_raise(RuntimeError) do
+ @connection.subscribe '!@#$%^&'
+ end
+ end
+
+
+ def test_send_and_receive
+ @connection.subscribe @d
+ @connection.send @d, @message
+
+ @connection.test_headers = {:destination=>@d}
+ @connection.test_response = <<EOM
+ <ReceiveMessageResponse>
+ <Message>
+ <MessageId>11YEJMCHE2DM483NGN40|3H4AA8J7EJKM0DQZR7E1|PT6DRTB278S4MNY77NJ0</MessageId>
+ <MessageBody>#{@message}</MessageBody>
+ </Message>
+ <ResponseStatus>
+ <StatusCode>Success</StatusCode>
+ <RequestId>b5bf2332-e983-4d3e-941a-f64c0d21f00f</RequestId>
+ </ResponseStatus>
+ </ReceiveMessageResponse>
+EOM
+ message = @connection.receive
+ assert_equal @message, message.body
+ end
+
+ def test_receive_timeout
+ @connection.subscribe @d
+ @connection.send @d, @message
+
+ @connection.test_headers = {:destination=>@d}
+ @connection.test_response = TimeoutError.new('test timeout error')
+ @connection.reliable = true
+ begin
+ Timeout.timeout 2 do
+ @connection.receive
+ end
+ rescue Timeout::Error=>toe
+ assert_not_equal toe.message, 'test timeout error'
+ end
+ end
+
+end
diff --git a/vendor/plugins/activemessaging/test/config_test.rb b/vendor/plugins/activemessaging/test/config_test.rb
new file mode 100644
index 0000000..0e49cb9
--- /dev/null
+++ b/vendor/plugins/activemessaging/test/config_test.rb
@@ -0,0 +1,42 @@
+require File.dirname(__FILE__) + '/test_helper'
+
+class TestProcessor < ActiveMessaging::Processor
+end
+
+class ConfigTest < Test::Unit::TestCase
+
+ def setup
+ ActiveMessaging::Gateway.define do |s|
+ s.destination :hello_world, '/queue/helloWorld'
+ end
+ end
+
+ def teardown
+ ActiveMessaging::Gateway.reset
+ end
+
+ def test_can_subscribe_to_named_queue
+ TestProcessor.subscribes_to :hello_world
+ sub = ActiveMessaging::Gateway.subscriptions.values.last
+ assert_equal :hello_world, sub.destination.name
+ assert_equal TestProcessor, sub.processor_class
+ end
+
+ def test_can_publish_to_named_queue
+ TestProcessor.publishes_to :hello_world
+ #no exception - publish just checks to see if the queue exists
+ end
+
+ def test_should_raise_error_if_subscribe_to_queue_that_does_not_exist
+ assert_raises(RuntimeError) do
+ TestProcessor.subscribes_to :queue_that_does_not_exist
+ end
+ end
+
+ def test_should_raise_error_if_publishes_to_queue_that_does_not_exist
+ assert_raises(RuntimeError) do
+ TestProcessor.publishes_to :queue_that_does_not_exist
+ end
+ end
+
+end
\ No newline at end of file
diff --git a/vendor/plugins/activemessaging/test/filter_test.rb b/vendor/plugins/activemessaging/test/filter_test.rb
new file mode 100644
index 0000000..6985acc
--- /dev/null
+++ b/vendor/plugins/activemessaging/test/filter_test.rb
@@ -0,0 +1,130 @@
+require File.dirname(__FILE__) + '/test_helper'
+
+module ActiveMessaging #:nodoc:
+ def self.reload_activemessaging
+ end
+end
+
+class FilterTest < Test::Unit::TestCase
+
+ class MockFilter < ActiveMessaging::Filter
+
+ @@called = {}
+ cattr_reader :called
+
+ attr_reader :options
+
+ def initialize(options)
+ @options = options
+ end
+
+ def process(message, details={})
+ @@called[options[:name]] = {:message=>message, :details=>details}
+ end
+
+ class << self
+ include Test::Unit::Assertions
+
+ def reset
+ @@called = {}
+ end
+
+ def assert_was_called(name=nil)
+ assert @@called.has_key?(name)
+ end
+
+ def assert_was_not_called(name=nil)
+ assert !@@called.has_key?(name)
+ end
+
+ def assert_routing(name, routing)
+ assert_equal routing, @@called[name][:details]
+ end
+ end
+ end
+
+ class TestProcessor < ActiveMessaging::Processor
+ include ActiveMessaging::MessageSender
+ #subscribes_to :testqueue
+
+ @@was_called = false
+ class<<self
+ include Test::Unit::Assertions
+
+ def assert_was_called
+ assert @@was_called
+ @@was_called = false
+ end
+ end
+
+ def on_message(message)
+ @@was_called = true
+ end
+ end
+
+ include ActiveMessaging::TestHelper
+
+ def setup
+ ActiveMessaging::Gateway.define do |d|
+ d.destination :testqueue, '/queue/test.queue'
+ d.filter 'filter_test/mock_filter', :direction=>:bidirectional, :name=>:bidirectional
+ d.filter 'filter_test/mock_filter', :direction=>:incoming, :name=>:incoming
+ d.filter 'filter_test/mock_filter', :direction=>:outgoing, :name=>:outgoing
+
+ d.filter 'filter_test/mock_filter', :direction=>:incoming, :name=>:exclude_only, :only=>:foo
+ d.filter 'filter_test/mock_filter', :direction=>:incoming, :name=>:include_only, :only=>:testqueue
+ d.filter 'filter_test/mock_filter', :direction=>:incoming, :name=>:exclude_except, :except=>:testqueue
+ d.filter 'filter_test/mock_filter', :direction=>:incoming, :name=>:include_except, :except=>:foo
+ end
+
+ TestProcessor.subscribes_to :testqueue
+ MockFilter.reset
+ end
+
+ def teardown
+ ActiveMessaging::Gateway.reset
+ end
+
+ def test_filters_use_include
+ ActiveMessaging::Gateway.dispatch ActiveMessaging::TestMessage.new('/queue/test.queue')
+ MockFilter.assert_was_called(:include_only)
+ MockFilter.assert_was_not_called(:exclude_only)
+ end
+
+ def test_filters_use_exclude
+ ActiveMessaging::Gateway.dispatch ActiveMessaging::TestMessage.new('/queue/test.queue')
+ MockFilter.assert_was_called(:include_except)
+ MockFilter.assert_was_not_called(:exclude_except)
+ end
+
+ def test_filters_and_processor_gets_called_on_receive
+ ActiveMessaging::Gateway.dispatch ActiveMessaging::TestMessage.new('/queue/test.queue')
+ MockFilter.assert_was_called(:bidirectional)
+ MockFilter.assert_was_called(:incoming)
+ MockFilter.assert_was_not_called(:outgoing)
+ TestProcessor.assert_was_called
+ end
+
+ def test_filters_gets_called_on_publish
+ ActiveMessaging::Gateway.publish :testqueue, "blah blah"
+ MockFilter.assert_was_called(:bidirectional)
+ MockFilter.assert_was_not_called(:incoming)
+ MockFilter.assert_was_called(:outgoing)
+ end
+
+ def test_sets_routing_details_on_send
+ sender = TestProcessor.new
+ sender.publish :testqueue, "Hi there!"
+
+ MockFilter.assert_was_called(:outgoing)
+ MockFilter.assert_routing(:outgoing, {:destination=>ActiveMessaging::Gateway.find_queue(:testqueue), :publisher=>FilterTest::TestProcessor, :direction=>:outgoing})
+ end
+
+ def test_sets_routing_details_on_receive
+ ActiveMessaging::Gateway.dispatch ActiveMessaging::TestMessage.new('/queue/test.queue')
+
+ MockFilter.assert_was_called(:incoming)
+ MockFilter.assert_routing(:incoming, {:destination=>ActiveMessaging::Gateway.find_queue(:testqueue), :receiver=>FilterTest::TestProcessor, :direction=>:incoming})
+ end
+
+end
\ No newline at end of file
diff --git a/vendor/plugins/activemessaging/test/gateway_test.rb b/vendor/plugins/activemessaging/test/gateway_test.rb
new file mode 100644
index 0000000..5d96e48
--- /dev/null
+++ b/vendor/plugins/activemessaging/test/gateway_test.rb
@@ -0,0 +1,195 @@
+require File.dirname(__FILE__) + '/test_helper'
+
+class InitializeFilter
+
+ attr_accessor :options
+
+ def initialize(options)
+ @options = options
+ end
+
+ def process(message, details={})
+ puts "ObjectFilter process called!"
+ end
+end
+
+class GatewayTest < Test::Unit::TestCase
+
+
+ class ClassFilter
+
+ def initialize
+ raise "Don't try and construct one of these please"
+ end
+
+ class << self
+ def process(message, details={})
+ puts "ClassFilter process called!"
+ end
+ end
+ end
+
+ class ObjectFilter
+ def process(message, details={})
+ puts "ObjectFilter process called!"
+ end
+ end
+
+ class TestProcessor < ActiveMessaging::Processor
+ include ActiveMessaging::MessageSender
+ #subscribes_to :testqueue
+ def on_message(message)
+ @test_message = true
+ end
+ end
+
+ class TestRetryProcessor < ActiveMessaging::Processor
+ include ActiveMessaging::MessageSender
+ #subscribes_to :testqueue
+ def on_message(message)
+ puts "TestRetryProcessor - about to raise exception"
+ raise ActiveMessaging::AbortMessageException.new("Cause a retry!")
+ end
+ end
+
+ class TestAdapter
+ end
+
+ def setup
+ end
+
+ def teardown
+ ActiveMessaging::Gateway.reset
+ end
+
+
+ def test_create_filter
+ filter_obj = ActiveMessaging::Gateway.create_filter('gateway_test/object_filter', {:direction=>:incoming, :name=>'test1'})
+ assert filter_obj
+ assert filter_obj.is_a?(GatewayTest::ObjectFilter)
+
+ filter_obj = ActiveMessaging::Gateway.create_filter('initialize_filter', {:direction=>:incoming, :name=>'test2'})
+ assert filter_obj
+ assert filter_obj.is_a?(InitializeFilter)
+ assert_equal filter_obj.options, {:direction=>:incoming, :name=>'test2'}
+
+ filter_obj = ActiveMessaging::Gateway.create_filter(:initialize_filter, {:direction=>:incoming, :name=>'test2'})
+ assert filter_obj
+ assert filter_obj.is_a?(InitializeFilter)
+ assert_equal filter_obj.options, {:direction=>:incoming, :name=>'test2'}
+
+ filter_obj = ActiveMessaging::Gateway.create_filter(:'gateway_test/class_filter', {:direction=>:incoming, :name=>'test2'})
+ assert filter_obj
+ assert filter_obj.is_a?(Class)
+ assert_equal filter_obj.name, "GatewayTest::ClassFilter"
+ end
+
+ def test_register_adapter
+ ActiveMessaging::Gateway.register_adapter :test_register_adapter, TestAdapter
+ assert_equal TestAdapter, ActiveMessaging::Gateway.adapters[:test_register_adapter]
+ end
+
+ def test_destination
+ ActiveMessaging::Gateway.destination :hello_world, '/queue/helloWorld'
+ dest = ActiveMessaging::Gateway.named_destinations[:hello_world]
+ assert_equal :hello_world, dest.name
+ end
+
+ def test_destination_duplicates
+ ActiveMessaging::Gateway.destination :hello_world, '/queue/helloWorld'
+ dest = ActiveMessaging::Gateway.named_destinations[:hello_world]
+ assert_equal :hello_world, dest.name
+
+ # make sure a dupe name causes an error
+ assert_raises RuntimeError do
+ ActiveMessaging::Gateway.destination :hello_world, '/queue/helloWorld2'
+ end
+ end
+
+ def test_connection
+ conn = ActiveMessaging::Gateway.connection
+ assert_equal conn.class, ActiveMessaging::Adapters::Test::Connection
+ end
+
+ def test_subscribe_and_unsubscribe
+ ActiveMessaging::Gateway.destination :hello_world, '/queue/helloWorld'
+ ActiveMessaging::Gateway.subscribe_to :hello_world, TestProcessor, headers={}
+ sub = ActiveMessaging::Gateway.subscriptions.values.last
+ assert_equal :hello_world, sub.destination.name
+ assert_equal TestProcessor, sub.processor_class
+
+ ActiveMessaging::Gateway.subscribe
+ assert_not_nil ActiveMessaging::Gateway.connection.find_subscription(sub.destination.value)
+
+ ActiveMessaging::Gateway.unsubscribe
+ assert_nil ActiveMessaging::Gateway.connection.find_subscription(sub.destination.value)
+ end
+
+ def test_disconnect
+ assert_equal 0, ActiveMessaging::Gateway.connections.keys.size
+
+ conn = ActiveMessaging::Gateway.connection
+ assert_equal 1, ActiveMessaging::Gateway.connections.keys.size
+ assert_equal true, conn.connected
+
+ ActiveMessaging::Gateway.disconnect
+
+ assert_equal 0, ActiveMessaging::Gateway.connections.keys.size
+ assert_equal false, conn.connected
+ end
+
+ def test_publish
+ ActiveMessaging::Gateway.destination :hello_world, '/queue/helloWorld'
+ ActiveMessaging::Gateway.publish :hello_world, "test_publish body", self.class, headers={}, timeout=10
+ assert_not_nil ActiveMessaging::Gateway.connection.find_message('/queue/helloWorld', "test_publish body")
+
+ assert_raise(RuntimeError) do
+ ActiveMessaging::Gateway.publish :hello_world, nil, self.class, headers={}, timeout=10
+ end
+ assert_raise(RuntimeError) do
+ ActiveMessaging::Gateway.publish :hello_world, '', self.class, headers={}, timeout=10
+ end
+ end
+
+ def test_acknowledge_message
+ ActiveMessaging::Gateway.destination :hello_world, '/queue/helloWorld'
+ ActiveMessaging::Gateway.subscribe_to :hello_world, TestProcessor, headers={}
+ sub = ActiveMessaging::Gateway.subscriptions.values.last
+ dest = ActiveMessaging::Adapters::Test::Destination.new '/queue/helloWorld'
+ msg = ActiveMessaging::Adapters::Test::Message.new({}, nil, "message_body", nil, dest)
+ ActiveMessaging::Gateway.acknowledge_message sub, msg
+ assert_equal msg, ActiveMessaging::Gateway.connection.received_messages.first
+ end
+
+ def test_abort_message
+ ActiveMessaging::Gateway.destination :hello_world, '/queue/helloWorld'
+ ActiveMessaging::Gateway.subscribe_to :hello_world, TestRetryProcessor, headers={}
+ sub = ActiveMessaging::Gateway.subscriptions.values.last
+ dest = ActiveMessaging::Adapters::Test::Destination.new '/queue/helloWorld'
+ msg = ActiveMessaging::Adapters::Test::Message.new({}, nil, "message_body", nil, dest)
+ ActiveMessaging::Gateway.dispatch(msg)
+ assert_equal msg, ActiveMessaging::Gateway.connection.unreceived_messages.first
+ end
+
+ def test_receive
+ ActiveMessaging::Gateway.destination :hello_world, '/queue/helloWorld'
+ ActiveMessaging::Gateway.publish :hello_world, "test_publish body", self.class, headers={}, timeout=10
+ msg = ActiveMessaging::Gateway.receive :hello_world, self.class, headers={}, timeout=10
+ assert_not_nil ActiveMessaging::Gateway.connection.find_message('/queue/helloWorld', "test_publish body")
+ end
+
+ def test_reload
+ ActiveMessaging.reload_activemessaging
+ size = ActiveMessaging::Gateway.named_destinations.size
+ ActiveMessaging.reload_activemessaging
+ assert_equal size, ActiveMessaging::Gateway.named_destinations.size
+ end
+
+ ## figure out how to test these better - start in a thread perhaps?
+ # def test_start
+ # end
+ #
+ # def test_stop
+ # end
+
+end
diff --git a/vendor/plugins/activemessaging/test/jms_test.rb b/vendor/plugins/activemessaging/test/jms_test.rb
new file mode 100644
index 0000000..c357c4f
--- /dev/null
+++ b/vendor/plugins/activemessaging/test/jms_test.rb
@@ -0,0 +1,61 @@
+require File.dirname(__FILE__) + '/test_helper'
+
+if defined?(JRUBY_VERSION)
+
+class JmsTest < Test::Unit::TestCase
+
+ def setup
+ @test_txt = 'Yo Homie!'
+ @isolation_const = rand(99999999)
+ @connection = ActiveMessaging::Adapters::Jms::Connection.new(:url => 'tcp://localhost:61616',
+ :login => '',
+ :passcode => '',
+ :connection_factory => 'org.apache.activemq.ActiveMQConnectionFactory')
+ end
+
+ def test_send
+ @connection.send "/queue/TestQueue#{@isolation_const}", @test_txt, {}
+ end
+
+ def test_receive_with_one
+ @connection.send "/queue/TestQueue#{@isolation_const}", @test_txt
+ @connection.subscribe "/queue/TestQueue#{@isolation_const}"
+ message = @connection.receive
+ assert_equal @test_txt, message.body
+ end
+
+ def test_receive_multi
+ 10.times do |i|
+ @connection.send "/queue/MultiQueue#{@isolation_const}", @test_txt
+ end
+
+ counter=0
+ @connection.subscribe "/queue/MultiQueue#{@isolation_const}"
+ while message = @connection.receive
+ assert_equal @test_txt, message.body
+ counter += 1
+ end
+ assert_equal 10, counter
+ end
+
+ def test_one_off_receive
+ @connection.send "/queue/OneOff#{@isolation_const}", "one off message"
+ message = @connection.receive "/queue/OneOff#{@isolation_const}"
+ assert_equal "one off message", message.body
+ assert_equal "MESSAGE", message.command
+ assert_equal "/queue/OneOff#{@isolation_const}", message.headers['destination']
+ end
+
+ def test_unsubscribe
+ @connection.subscribe "/queue/TestSubQueue#{@isolation_const}"
+ @connection.unsubscribe "/queue/TestSubQueue#{@isolation_const}"
+ assert_nil @connection.consumers["TestSubQueue#{@isolation_const}"]
+ end
+
+ def teardown
+ @connection.close unless @connection.nil?
+ end
+
+end
+
+end
\ No newline at end of file
diff --git a/vendor/plugins/activemessaging/test/reliable_msg_test.rb b/vendor/plugins/activemessaging/test/reliable_msg_test.rb
new file mode 100644
index 0000000..c016b96
--- /dev/null
+++ b/vendor/plugins/activemessaging/test/reliable_msg_test.rb
@@ -0,0 +1,82 @@
+require File.dirname(__FILE__) + '/test_helper'
+
+loaded = true
+begin
+ require 'reliable-msg'
+rescue Object => e
+ loaded = false
+end
+if loaded
+
+class ReliableMsgTest < Test::Unit::TestCase
+
+ def setup
+ @qm = ReliableMsg::QueueManager.new
+ @qm.start
+ @connection = ActiveMessaging::Adapters::ReliableMsg::Connection.new(:reliable=>false, :poll_interval=>2)
+ @d = "/queue/reliable.msg.test}."
+ @message = "mary had a little lamb"
+ @message2 = "whose fleece was white as snow"
+ end
+
+ def teardown
+ @connection.disconnect unless @connection.nil?
+ @qm.stop unless @qm.nil?
+ end
+
+ def test_subscribe_and_unsubscribe
+ assert_nil @connection.subscriptions["#{@d}test_subscribe"]
+ @connection.subscribe "#{@d}test_subscribe"
+ assert_equal 1, @connection.subscriptions["#{@d}test_subscribe"].count
+ @connection.subscribe "#{@d}test_subscribe"
+ assert_equal 2, @connection.subscriptions["#{@d}test_subscribe"].count
+ @connection.unsubscribe "#{@d}test_subscribe"
+ assert_equal 1, @connection.subscriptions["#{@d}test_subscribe"].count
+ @connection.unsubscribe "#{@d}test_subscribe"
+ assert_nil @connection.subscriptions["#{@d}test_subscribe"]
+ end
+
+ def test_send_and_receive
+ @connection.subscribe "#{@d}test_send_and_receive"
+ @connection.send "#{@d}test_send_and_receive", @message
+ message = @connection.receive
+ @connection.received message
+ assert_equal @message, message.body
+ end
+
+
+ def test_send_and_receive_multiple_subscriptions
+ @connection.subscribe "#{@d}test_send_and_receive1"
+ @connection.subscribe "#{@d}test_send_and_receive2"
+ @connection.subscribe "#{@d}test_send_and_receive3"
+
+ @connection.send "#{@d}test_send_and_receive2", "message2"
+ message = @connection.receive
+ @connection.received message
+ assert_equal "message2", message.body
+
+ @connection.send "#{@d}test_send_and_receive3", "message3"
+ message = @connection.receive
+ @connection.received message
+ assert_equal "message3", message.body
+
+ end
+
+
+ def test_will_cause_sleep
+
+ begin
+ Timeout.timeout 10 do
+ @connection.subscribe "#{@d}test_will_cause_sleep"
+ message = @connection.receive
+ @connection.received message
+ assert false
+ end
+ rescue Timeout::Error=>toe
+ assert true
+ end
+ end
+
+end
+
+end # if loaded
\ No newline at end of file
diff --git a/vendor/plugins/activemessaging/test/test_helper.rb b/vendor/plugins/activemessaging/test/test_helper.rb
new file mode 100644
index 0000000..c59d77d
--- /dev/null
+++ b/vendor/plugins/activemessaging/test/test_helper.rb
@@ -0,0 +1,16 @@
+# load the rails environment
+# TODO currently requires you to run tests as a installed plugin, we should try to fix this
+ENV['RAILS_ENV'] = "test"
+require File.expand_path(File.dirname(__FILE__) + "/../../../../config/environment")
+
+# load other libraries
+require 'test/unit'
+
+# load activemessaging
+# TODO this is already loaded automatically by starting Rails
+# but we may need to do this if we want to run a13g tests without Rails
+#require File.dirname(__FILE__) + '/../lib/activemessaging/processor'
+#require File.dirname(__FILE__) + '/../lib/activemessaging/gateway'
+require File.dirname(__FILE__) + '/../lib/activemessaging/test_helper'
+
+
diff --git a/vendor/plugins/activemessaging/test/tracer_test.rb b/vendor/plugins/activemessaging/test/tracer_test.rb
new file mode 100644
index 0000000..5ec87f1
--- /dev/null
+++ b/vendor/plugins/activemessaging/test/tracer_test.rb
@@ -0,0 +1,68 @@
+require File.dirname(__FILE__) + '/test_helper'
+
+module ActiveMessaging #:nodoc:
+ def self.reload_activemessaging
+ end
+end
+
+class TestProcessor < ActiveMessaging::Processor
+ #subscribes_to :hello_world
+
+ def on_message message
+ #do nothing
+ end
+end
+
+class TestSender < ActiveMessaging::Processor
+ #publishes_to :hello_world
+
+end
+
+class FakeMessage
+ def command
+ 'MESSAGE'
+ end
+ def headers
+ {'destination'=>'/queue/helloWorld'}
+ end
+ def body
+ "Ni hao ma?"
+ end
+end
+
+class TracerTest < Test::Unit::TestCase
+ include ActiveMessaging::TestHelper
+ def setup
+ ActiveMessaging::Gateway.define do |s|
+ s.queue :hello_world, '/queue/helloWorld'
+ s.queue :trace, '/queue/trace'
+
+ s.filter :trace_filter, :queue=>:trace
+ end
+
+ TestProcessor.subscribes_to :hello_world
+ TestSender.publishes_to :hello_world
+ end
+
+ def teardown
+ ActiveMessaging::Gateway.reset
+ end
+
+ def test_should_trace_sent_messages
+ message = "Ni hao ma?"
+
+ sender = TestSender.new
+ sender.publish :hello_world, message
+
+ assert_message :trace, "<sent><from>TestSender</from><queue>hello_world</queue><message>#{message}</message></sent>"
+ assert_message :hello_world, message
+ end
+
+ def test_should_trace_received_messages
+ message = "Ni hao ma?"
+
+ ActiveMessaging::Gateway.dispatch FakeMessage.new
+
+ assert_message :trace, "<received><by>TestProcessor</by><queue>hello_world</queue><message>#{message}</message></received>"
+ end
+end
\ No newline at end of file
|
cjmartin/mythapi
|
a8e368b0b9156b47b05570496a530be080bba422
|
modified README - next commit will add a bunch of stuff for video processing and drastically change the simplicity of this project.
|
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..7c2ac8f
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+config/database.yml
diff --git a/README b/README
index a1db73c..77bdc3e 100644
--- a/README
+++ b/README
@@ -1,203 +1,11 @@
-== Welcome to Rails
+mythapi is generally just a really simple interface to the mythTV database.
-Rails is a web-application and persistence framework that includes everything
-needed to create database-backed web-applications according to the
-Model-View-Control pattern of separation. This pattern splits the view (also
-called the presentation) into "dumb" templates that are primarily responsible
-for inserting pre-built data in between HTML tags. The model contains the
-"smart" domain objects (such as Account, Product, Person, Post) that holds all
-the business logic and knows how to persist themselves to a database. The
-controller handles the incoming requests (such as Save New Account, Update
-Product, Show Post) by manipulating the model and directing data to the view.
+Enter your database information into database.yml under the section mythconverg
+and gem install composite_primary_keys.
-In Rails, the model is handled by what's called an object-relational mapping
-layer entitled Active Record. This layer allows you to present the data from
-database rows as objects and embellish these data objects with business logic
-methods. You can read more about Active Record in
-link:files/vendor/rails/activerecord/README.html.
+XML is returned for RESTful queries ie. /recorded returns an XML dump of
+all the recorded programs.
-The controller and view are handled by the Action Pack, which handles both
-layers by its two parts: Action View and Action Controller. These two layers
-are bundled in a single package due to their heavy interdependence. This is
-unlike the relationship between the Active Record and Action Pack that is much
-more separate. Each of these packages can be used independently outside of
-Rails. You can read more about Action Pack in
-link:files/vendor/rails/actionpack/README.html.
+###############################################################################
-
-== Getting Started
-
-1. At the command prompt, start a new Rails application using the <tt>rails</tt> command
- and your application name. Ex: rails myapp
- (If you've downloaded Rails in a complete tgz or zip, this step is already done)
-2. Change directory into myapp and start the web server: <tt>script/server</tt> (run with --help for options)
-3. Go to http://localhost:3000/ and get "Welcome aboard: Youâre riding the Rails!"
-4. Follow the guidelines to start developing your application
-
-
-== Web Servers
-
-By default, Rails will try to use Mongrel and lighttpd if they are installed, otherwise
-Rails will use WEBrick, the webserver that ships with Ruby. When you run script/server,
-Rails will check if Mongrel exists, then lighttpd and finally fall back to WEBrick. This ensures
-that you can always get up and running quickly.
-
-Mongrel is a Ruby-based webserver with a C component (which requires compilation) that is
-suitable for development and deployment of Rails applications. If you have Ruby Gems installed,
-getting up and running with mongrel is as easy as: <tt>gem install mongrel</tt>.
-More info at: http://mongrel.rubyforge.org
-
-If Mongrel is not installed, Rails will look for lighttpd. It's considerably faster than
-Mongrel and WEBrick and also suited for production use, but requires additional
-installation and currently only works well on OS X/Unix (Windows users are encouraged
-to start with Mongrel). We recommend version 1.4.11 and higher. You can download it from
-http://www.lighttpd.net.
-
-And finally, if neither Mongrel or lighttpd are installed, Rails will use the built-in Ruby
-web server, WEBrick. WEBrick is a small Ruby web server suitable for development, but not
-for production.
-
-But of course its also possible to run Rails on any platform that supports FCGI.
-Apache, LiteSpeed, IIS are just a few. For more information on FCGI,
-please visit: http://wiki.rubyonrails.com/rails/pages/FastCGI
-
-
-== Debugging Rails
-
-Sometimes your application goes wrong. Fortunately there are a lot of tools that
-will help you debug it and get it back on the rails.
-
-First area to check is the application log files. Have "tail -f" commands running
-on the server.log and development.log. Rails will automatically display debugging
-and runtime information to these files. Debugging info will also be shown in the
-browser on requests from 127.0.0.1.
-
-You can also log your own messages directly into the log file from your code using
-the Ruby logger class from inside your controllers. Example:
-
- class WeblogController < ActionController::Base
- def destroy
- @weblog = Weblog.find(params[:id])
- @weblog.destroy
- logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
- end
- end
-
-The result will be a message in your log file along the lines of:
-
- Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1
-
-More information on how to use the logger is at http://www.ruby-doc.org/core/
-
-Also, Ruby documentation can be found at http://www.ruby-lang.org/ including:
-
-* The Learning Ruby (Pickaxe) Book: http://www.ruby-doc.org/docs/ProgrammingRuby/
-* Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
-
-These two online (and free) books will bring you up to speed on the Ruby language
-and also on programming in general.
-
-
-== Debugger
-
-Debugger support is available through the debugger command when you start your Mongrel or
-Webrick server with --debugger. This means that you can break out of execution at any point
-in the code, investigate and change the model, AND then resume execution! Example:
-
- class WeblogController < ActionController::Base
- def index
- @posts = Post.find(:all)
- debugger
- end
- end
-
-So the controller will accept the action, run the first line, then present you
-with a IRB prompt in the server window. Here you can do things like:
-
- >> @posts.inspect
- => "[#<Post:0x14a6be8 @attributes={\"title\"=>nil, \"body\"=>nil, \"id\"=>\"1\"}>,
- #<Post:0x14a6620 @attributes={\"title\"=>\"Rails you know!\", \"body\"=>\"Only ten..\", \"id\"=>\"2\"}>]"
- >> @posts.first.title = "hello from a debugger"
- => "hello from a debugger"
-
-...and even better is that you can examine how your runtime objects actually work:
-
- >> f = @posts.first
- => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
- >> f.
- Display all 152 possibilities? (y or n)
-
-Finally, when you're ready to resume execution, you enter "cont"
-
-
-== Console
-
-You can interact with the domain model by starting the console through <tt>script/console</tt>.
-Here you'll have all parts of the application configured, just like it is when the
-application is running. You can inspect domain models, change values, and save to the
-database. Starting the script without arguments will launch it in the development environment.
-Passing an argument will specify a different environment, like <tt>script/console production</tt>.
-
-To reload your controllers and models after launching the console run <tt>reload!</tt>
-
-
-== Description of Contents
-
-app
- Holds all the code that's specific to this particular application.
-
-app/controllers
- Holds controllers that should be named like weblogs_controller.rb for
- automated URL mapping. All controllers should descend from ApplicationController
- which itself descends from ActionController::Base.
-
-app/models
- Holds models that should be named like post.rb.
- Most models will descend from ActiveRecord::Base.
-
-app/views
- Holds the template files for the view that should be named like
- weblogs/index.erb for the WeblogsController#index action. All views use eRuby
- syntax.
-
-app/views/layouts
- Holds the template files for layouts to be used with views. This models the common
- header/footer method of wrapping views. In your views, define a layout using the
- <tt>layout :default</tt> and create a file named default.erb. Inside default.erb,
- call <% yield %> to render the view using this layout.
-
-app/helpers
- Holds view helpers that should be named like weblogs_helper.rb. These are generated
- for you automatically when using script/generate for controllers. Helpers can be used to
- wrap functionality for your views into methods.
-
-config
- Configuration files for the Rails environment, the routing map, the database, and other dependencies.
-
-db
- Contains the database schema in schema.rb. db/migrate contains all
- the sequence of Migrations for your schema.
-
-doc
- This directory is where your application documentation will be stored when generated
- using <tt>rake doc:app</tt>
-
-lib
- Application specific libraries. Basically, any kind of custom code that doesn't
- belong under controllers, models, or helpers. This directory is in the load path.
-
-public
- The directory available for the web server. Contains subdirectories for images, stylesheets,
- and javascripts. Also contains the dispatchers and the default HTML files. This should be
- set as the DOCUMENT_ROOT of your web server.
-
-script
- Helper scripts for automation and generation.
-
-test
- Unit and functional tests along with fixtures. When using the script/generate scripts, template
- test files will be generated for you and placed in this directory.
-
-vendor
- External libraries that the application depends on. Also includes the plugins subdirectory.
- This directory is in the load path.
+Video processing currently is in development, more soon.
\ No newline at end of file
|
nateware/dotfiles
|
f8e23a88740eda9b8d7720107fcbeb4827dd979b
|
prompt
|
diff --git a/.zprofile b/.zprofile
index a25e653..03aee91 100644
--- a/.zprofile
+++ b/.zprofile
@@ -1,108 +1,110 @@
# Autocomplete
autoload -U +X bashcompinit && bashcompinit
autoload -U +X compinit && compinit
# Homebrew
[ -f /opt/homebrew/bin/brew ] && eval "$(/opt/homebrew/bin/brew shellenv)"
# Node
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
# Ruby
[ -d $HOME/.rbenv ] && export PATH="$HOME/.rbenv/shims:$PATH"
# Change to workspace directory
wd () {
if [ $# -eq 0 ]; then
pushd "$HOME/Workspace"
elif [ -d "$1" ]; then
# tab expansion
pushd "$1"
else
# wildcard
pushd "$HOME/Workspace/$1"*
fi
}
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
[ -f "$HOME/.git-completion.zsh" ] && . "$HOME/.git-completion.zsh"
# Use garnaat's unified CLI
complete -C aws_completer aws # bash tab completion
paws (){
aws "$@" | ruby -rjson -rawesome_print -e "ap JSON.parse(STDIN.read)"
}
complete -C aws_completer paws # bash tab completion
# My approach for ec2 is to launch instances with a custom "root" keypair,
# but the username may change based on AMI, so then just ssh ec2-user@whatevs
# Remember keypairs are mapped to IAM user + region so use both pieces.
ec2keypair () {
local user="${1:-root}"
if [ -z "$AWS_ACCOUNT" -o -z "$AWS_REGION" ]; then
echo "Error: Set awsacct and awsregion before ec2keypair" >&2
return 1
fi
local acctdir=$(awsacctdir $AWS_ACCOUNT)
export EC2_ROOT_KEY="$acctdir/$user-$AWS_REGION.pem"
if [ ! -f "$EC2_ROOT_KEY" ]; then
echo "Warning: EC2 key does not exist: $EC2_ROOT_KEY" >&2
fi
# To override root, use ubuntu@ or ec2-user@ or whatever
local ssh_cmd="ssh -i $EC2_ROOT_KEY -o StrictHostKeyChecking=no -l root"
alias ash=$ssh_cmd
alias async="rsync -av -e '$ssh_cmd'"
}
# Switch AWS regions
awsregion () {
if [ $# -eq 1 ]; then
export AWS_DEFAULT_REGION=$1
export AWS_REGION=$1
# ec2keypair # reset keys when switch regions
fi
[ -t 0 ] && echo "AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION"
}
# Switch between AWS account credentials
awsacct () {
if [ $# -eq 1 ]; then
local acct="$1"
local acctdir="$HOME/.awsacct/$1"
if [ ! -d $acctdir ]; then
echo "Error: No such dir $acctdir" >&2
unset AWS_ACCOUNT AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_DEFAULT_REGION AWS_REGION
return 1
fi
export AWS_ACCOUNT=$acct
# Newer tools and unified CLI
. $acctdir/access_keys.txt
export AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_DEFAULT_REGION AWS_REGION
# ec2keypair # reset keys when switch accounts
fi
[ -t 0 ] && env | grep '^AWS_'
}
[ -d "$HOME/.awsacct/default" ] && awsacct `readlink "$HOME/.awsacct/default"`
# Prompt in zsh
-autoload -U promptinit && promptinit && prompt redhat
+# check PS1 in zshrc
+#autoload -U promptinit && promptinit && prompt redhat
+autoload -U promptinit && promptinit
# Azure autocomplete
# Setting PATH for Python 3.11
# The original version is saved in .zprofile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.11/bin:${PATH}"
export PATH
diff --git a/.zshrc b/.zshrc
index 13fc067..bd29397 100644
--- a/.zshrc
+++ b/.zshrc
@@ -1,91 +1,93 @@
# ~/.zshrc
umask 022
# Add to PATH but only if it exists
add_path () {
err=0
for p
do
if [ -d $p ]; then
PATH="$p:$PATH"
else
err=1
fi
done
return $err
}
# Add to LD_LIB_PATH adjusting for platform
add_lib () {
[ -d "$1" ] || return 0
if [ "$OS" = Darwin ]; then
export DYLD_LIBRARY_PATH="$1:$DYLD_LIBRARY_PATH"
else
export LD_LIBRARY_PATH="$1:$DYLD_LIBRARY_PATH"
fi
return 0
}
# Guess
add_path_and_lib () {
if add_path "$1"; then
lib=${1%/bin}/lib
add_lib $lib
else
return 1
fi
}
# Change to workspace directory
wd () {
if [ $# -eq 0 ]; then
pushd "$HOME/Workspace"
elif [ -d "$1" ]; then
# tab expansion
pushd "$1"
else
# wildcard
pushd "$HOME/Workspace/$1"*
fi
}
# Autocomplete
#source /opt/homebrew/share/zsh-autocomplete/zsh-autocomplete.plugin.zsh
# Aliases
alias ls='\ls -Gh'
alias ll='ls -al'
alias wget='curl -LO'
alias ldd='otool -L'
alias rsync='\rsync --exclude=.svn --exclude=.git --exclude=RCS'
# Don't want to install rubydocs - TOO SLOW!
alias gi='gem install --no-ri --no-rdoc'
alias bi='bundle install --without=production:staging:assets'
alias bu='bundle update'
alias be='bundle exec'
alias ga='git ci -a -m'
alias gd='git pu && git push -f dev'
alias gp='git pu'
# Platform goodness
export OS=`uname`
[ "$OS" = Darwin ] && export JAVA_HOME=/Library/Java/Home
# Ruby version manager
[ -s $HOME/.rvm/scripts/rvm ] && . $HOME/.rvm/scripts/rvm
# Node version manager
[ -s $HOME/.nvm/nvm.sh ] && . $HOME/.nvm/nvm.sh # This loads NVM
export EDITOR='vim'
-export PS1=$'\033[36m%n\033[m@\033[32m%m:\033[33;1m%~\033[m\$ '
+#export PS1=$'\033[36m%n\033[m@\033[32m%m:\033[33;1m%~\033[m\$ '
+#export PS1=$'\033[36m%n\033[m@\033[32m%m:\033[33;1m%~\033[m\$ '
+export PS1='%F{blue}%n%f:%F{yellow}%1~%f%# '
add_path $HOME/Library/Python/3.9/bin
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
# The next line updates PATH for the Google Cloud SDK.
if [ -f '/Users/nateware/google-cloud-sdk/path.zsh.inc' ]; then . '/Users/nateware/google-cloud-sdk/path.zsh.inc'; fi
# The next line enables shell command completion for gcloud.
if [ -f '/Users/nateware/google-cloud-sdk/completion.zsh.inc' ]; then . '/Users/nateware/google-cloud-sdk/completion.zsh.inc'; fi
|
nateware/dotfiles
|
192f2d5e8f9b8e35963589bb0f9d77d5079226f3
|
cool git aliases
|
diff --git a/.gitconfig b/.gitconfig
index a1c95ab..312e12b 100644
--- a/.gitconfig
+++ b/.gitconfig
@@ -1,25 +1,28 @@
[user]
name = Nate Wiger
email = nwiger@gmail.com
[alias]
ci = commit
co = checkout
st = status
up = pull
pu = push -u origin
+ ca = "!f() { git add -A && git commit -m \"$@\"; }; f"
+ cap = "!f() { git add -A && git commit -m \"$@\" && git push; }; f"
+ cmp = "!f() { git commit -m \"$@\" && git push; }; f"
rv = checkout --
br = branch -a
hard = reset --hard origin/master
hist = log --since=1.day --relative-date --stat
mine = log --since=1.day --relative-date --stat --committer=nateware
undo = reset HEAD --
last = log -1 HEAD
#pu = !"git fetch origin -v; git fetch upstream -v; git merge upstream/master"
[color]
diff = auto
status = auto
branch = auto
[push]
default = current
[core]
excludesfile = /Users/nateware/.gitignore_global
diff --git a/.zprofile b/.zprofile
index e1fdc31..d36ab03 100644
--- a/.zprofile
+++ b/.zprofile
@@ -1,110 +1,114 @@
# Aliases
alias ls='\ls -Gh'
alias ll='ls -al'
alias wget='curl -LO'
alias ldd='otool -L'
alias rsync='\rsync --exclude=.svn --exclude=.git --exclude=RCS'
alias vi='vim -b'
# Homebrew
[ -f /opt/homebrew/bin/brew ] && eval "$(/opt/homebrew/bin/brew shellenv)"
# Node
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
# Ruby
[ -d $HOME/.rbenv ] && export PATH="$HOME/.rbenv/shims:$PATH"
# Change to workspace directory
wd () {
if [ $# -eq 0 ]; then
pushd "$HOME/Workspace"
elif [ -d "$1" ]; then
# tab expansion
pushd "$1"
else
# wildcard
pushd "$HOME/Workspace/$1"*
fi
}
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
[ -f "$HOME/.git-completion.zsh" ] && . "$HOME/.git-completion.zsh"
# Use garnaat's unified CLI
complete -C aws_completer aws # bash tab completion
paws (){
aws "$@" | ruby -rjson -rawesome_print -e "ap JSON.parse(STDIN.read)"
}
complete -C aws_completer paws # bash tab completion
# My approach for ec2 is to launch instances with a custom "root" keypair,
# but the username may change based on AMI, so then just ssh ec2-user@whatevs
# Remember keypairs are mapped to IAM user + region so use both pieces.
ec2keypair () {
local user="${1:-root}"
if [ -z "$AWS_ACCOUNT" -o -z "$AWS_REGION" ]; then
echo "Error: Set awsacct and awsregion before ec2keypair" >&2
return 1
fi
local acctdir=$(awsacctdir $AWS_ACCOUNT)
export EC2_ROOT_KEY="$acctdir/$user-$AWS_REGION.pem"
if [ ! -f "$EC2_ROOT_KEY" ]; then
echo "Warning: EC2 key does not exist: $EC2_ROOT_KEY" >&2
fi
# To override root, use ubuntu@ or ec2-user@ or whatever
local ssh_cmd="ssh -i $EC2_ROOT_KEY -o StrictHostKeyChecking=no -l root"
alias ash=$ssh_cmd
alias async="rsync -av -e '$ssh_cmd'"
}
# Switch AWS regions
awsregion () {
if [ $# -eq 1 ]; then
export AWS_DEFAULT_REGION=$1
export AWS_REGION=$1
# ec2keypair # reset keys when switch regions
fi
[ -t 0 ] && echo "AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION"
}
# Switch between AWS account credentials
awsacct () {
if [ $# -eq 1 ]; then
local acct="$1"
local acctdir="$HOME/.awsacct/$1"
if [ ! -d $acctdir ]; then
echo "Error: No such dir $acctdir" >&2
unset AWS_ACCOUNT AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_DEFAULT_REGION AWS_REGION
return 1
fi
export AWS_ACCOUNT=$acct
# Newer tools and unified CLI
. $acctdir/access_keys.txt
export AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_DEFAULT_REGION AWS_REGION
# ec2keypair # reset keys when switch accounts
fi
[ -t 0 ] && env | grep '^AWS_'
}
[ -d "$HOME/.awsacct/default" ] && awsacct `readlink "$HOME/.awsacct/default"`
# Prompt in zsh
autoload -U promptinit && promptinit && prompt redhat
+# Azure autocomplete
+autoload bashcompinit && bashcompinit
+source $(brew --prefix)/etc/bash_completion.d/az
+
# Setting PATH for Python 3.11
# The original version is saved in .zprofile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.11/bin:${PATH}"
export PATH
|
nateware/dotfiles
|
03a199fba2ba334b5138e8bac7a2364f59965ddf
|
changes
|
diff --git a/.zprofile b/.zprofile
index b52fadd..e1fdc31 100644
--- a/.zprofile
+++ b/.zprofile
@@ -1,104 +1,110 @@
# Aliases
alias ls='\ls -Gh'
alias ll='ls -al'
alias wget='curl -LO'
alias ldd='otool -L'
alias rsync='\rsync --exclude=.svn --exclude=.git --exclude=RCS'
alias vi='vim -b'
# Homebrew
[ -f /opt/homebrew/bin/brew ] && eval "$(/opt/homebrew/bin/brew shellenv)"
# Node
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
# Ruby
[ -d $HOME/.rbenv ] && export PATH="$HOME/.rbenv/shims:$PATH"
# Change to workspace directory
wd () {
if [ $# -eq 0 ]; then
pushd "$HOME/Workspace"
elif [ -d "$1" ]; then
# tab expansion
pushd "$1"
else
# wildcard
pushd "$HOME/Workspace/$1"*
fi
}
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
[ -f "$HOME/.git-completion.zsh" ] && . "$HOME/.git-completion.zsh"
# Use garnaat's unified CLI
complete -C aws_completer aws # bash tab completion
paws (){
aws "$@" | ruby -rjson -rawesome_print -e "ap JSON.parse(STDIN.read)"
}
complete -C aws_completer paws # bash tab completion
# My approach for ec2 is to launch instances with a custom "root" keypair,
# but the username may change based on AMI, so then just ssh ec2-user@whatevs
# Remember keypairs are mapped to IAM user + region so use both pieces.
ec2keypair () {
local user="${1:-root}"
if [ -z "$AWS_ACCOUNT" -o -z "$AWS_REGION" ]; then
echo "Error: Set awsacct and awsregion before ec2keypair" >&2
return 1
fi
local acctdir=$(awsacctdir $AWS_ACCOUNT)
export EC2_ROOT_KEY="$acctdir/$user-$AWS_REGION.pem"
if [ ! -f "$EC2_ROOT_KEY" ]; then
echo "Warning: EC2 key does not exist: $EC2_ROOT_KEY" >&2
fi
# To override root, use ubuntu@ or ec2-user@ or whatever
local ssh_cmd="ssh -i $EC2_ROOT_KEY -o StrictHostKeyChecking=no -l root"
alias ash=$ssh_cmd
alias async="rsync -av -e '$ssh_cmd'"
}
# Switch AWS regions
awsregion () {
if [ $# -eq 1 ]; then
export AWS_DEFAULT_REGION=$1
export AWS_REGION=$1
# ec2keypair # reset keys when switch regions
fi
[ -t 0 ] && echo "AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION"
}
# Switch between AWS account credentials
awsacct () {
if [ $# -eq 1 ]; then
local acct="$1"
local acctdir="$HOME/.awsacct/$1"
if [ ! -d $acctdir ]; then
echo "Error: No such dir $acctdir" >&2
unset AWS_ACCOUNT AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_DEFAULT_REGION AWS_REGION
return 1
fi
export AWS_ACCOUNT=$acct
# Newer tools and unified CLI
. $acctdir/access_keys.txt
export AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_DEFAULT_REGION AWS_REGION
# ec2keypair # reset keys when switch accounts
fi
[ -t 0 ] && env | grep '^AWS_'
}
[ -d "$HOME/.awsacct/default" ] && awsacct `readlink "$HOME/.awsacct/default"`
# Prompt in zsh
autoload -U promptinit && promptinit && prompt redhat
+
+# Setting PATH for Python 3.11
+# The original version is saved in .zprofile.pysave
+PATH="/Library/Frameworks/Python.framework/Versions/3.11/bin:${PATH}"
+export PATH
+
diff --git a/.zshrc b/.zshrc
index cb481ca..efb153f 100644
--- a/.zshrc
+++ b/.zshrc
@@ -1,81 +1,88 @@
# ~/.zshrc
umask 022
# Add to PATH but only if it exists
add_path () {
err=0
for p
do
if [ -d $p ]; then
PATH="$p:$PATH"
else
err=1
fi
done
return $err
}
# Add to LD_LIB_PATH adjusting for platform
add_lib () {
[ -d "$1" ] || return 0
if [ "$OS" = Darwin ]; then
export DYLD_LIBRARY_PATH="$1:$DYLD_LIBRARY_PATH"
else
export LD_LIBRARY_PATH="$1:$DYLD_LIBRARY_PATH"
fi
return 0
}
# Guess
add_path_and_lib () {
if add_path "$1"; then
lib=${1%/bin}/lib
add_lib $lib
else
return 1
fi
}
# Change to workspace directory
wd () {
if [ $# -eq 0 ]; then
pushd "$HOME/Workspace"
elif [ -d "$1" ]; then
# tab expansion
pushd "$1"
else
# wildcard
pushd "$HOME/Workspace/$1"*
fi
}
# Aliases
alias ls='\ls -Gh'
alias ll='ls -al'
alias wget='curl -LO'
alias ldd='otool -L'
alias rsync='\rsync --exclude=.svn --exclude=.git --exclude=RCS'
# Don't want to install rubydocs - TOO SLOW!
alias gi='gem install --no-ri --no-rdoc'
alias bi='bundle install --without=production:staging:assets'
alias bu='bundle update'
alias be='bundle exec'
alias ga='git ci -a -m'
alias gd='git pu && git push -f dev'
alias gp='git pu'
# Platform goodness
export OS=`uname`
[ "$OS" = Darwin ] && export JAVA_HOME=/Library/Java/Home
# Ruby version manager
[ -s $HOME/.rvm/scripts/rvm ] && . $HOME/.rvm/scripts/rvm
# Node version manager
[ -s $HOME/.nvm/nvm.sh ] && . $HOME/.nvm/nvm.sh # This loads NVM
export EDITOR='vim'
export PS1=$'\033[36m%n\033[m@\033[32m%m:\033[33;1m%~\033[m\$ '
add_path $HOME/Library/Python/3.9/bin
+[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
+
+# The next line updates PATH for the Google Cloud SDK.
+if [ -f '/Users/nateware/google-cloud-sdk/path.zsh.inc' ]; then . '/Users/nateware/google-cloud-sdk/path.zsh.inc'; fi
+
+# The next line enables shell command completion for gcloud.
+if [ -f '/Users/nateware/google-cloud-sdk/completion.zsh.inc' ]; then . '/Users/nateware/google-cloud-sdk/completion.zsh.inc'; fi
diff --git a/vscode_vim_settings.json b/vscode_vim_settings.json
new file mode 100644
index 0000000..5d2625b
--- /dev/null
+++ b/vscode_vim_settings.json
@@ -0,0 +1,24 @@
+{
+ "workbench.colorTheme": "Default Dark+",
+ "editor.accessibilitySupport": "off",
+ "vim.handleKeys": {
+ "<C-d>": true,
+ "<C-s>": false,
+ "<C-z>": false
+ },
+ "vim.useSystemClipboard": true,
+ "vim.useCtrlKeys": true,
+ "vim.normalModeKeyBindingsNonRecursive": [
+ {
+ "before": ["u"],
+ "commands": ["undo"]
+ },
+ {
+ "before": ["<C-r>"],
+ "commands": ["redo"]
+ }
+ ],
+ "vim.insertModeKeyBindingsNonRecursive": [
+
+ ]
+}
|
nateware/dotfiles
|
84e611e7bc134c02c03281ba09e86f3c8334ab99
|
source on login
|
diff --git a/.zprofile b/.zprofile
index 6f14cda..b52fadd 100644
--- a/.zprofile
+++ b/.zprofile
@@ -1,102 +1,104 @@
# Aliases
alias ls='\ls -Gh'
alias ll='ls -al'
alias wget='curl -LO'
alias ldd='otool -L'
alias rsync='\rsync --exclude=.svn --exclude=.git --exclude=RCS'
alias vi='vim -b'
# Homebrew
[ -f /opt/homebrew/bin/brew ] && eval "$(/opt/homebrew/bin/brew shellenv)"
# Node
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
# Ruby
[ -d $HOME/.rbenv ] && export PATH="$HOME/.rbenv/shims:$PATH"
# Change to workspace directory
wd () {
if [ $# -eq 0 ]; then
pushd "$HOME/Workspace"
elif [ -d "$1" ]; then
# tab expansion
pushd "$1"
else
# wildcard
pushd "$HOME/Workspace/$1"*
fi
}
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
[ -f "$HOME/.git-completion.zsh" ] && . "$HOME/.git-completion.zsh"
# Use garnaat's unified CLI
complete -C aws_completer aws # bash tab completion
paws (){
aws "$@" | ruby -rjson -rawesome_print -e "ap JSON.parse(STDIN.read)"
}
complete -C aws_completer paws # bash tab completion
# My approach for ec2 is to launch instances with a custom "root" keypair,
# but the username may change based on AMI, so then just ssh ec2-user@whatevs
# Remember keypairs are mapped to IAM user + region so use both pieces.
ec2keypair () {
local user="${1:-root}"
if [ -z "$AWS_ACCOUNT" -o -z "$AWS_REGION" ]; then
echo "Error: Set awsacct and awsregion before ec2keypair" >&2
return 1
fi
local acctdir=$(awsacctdir $AWS_ACCOUNT)
export EC2_ROOT_KEY="$acctdir/$user-$AWS_REGION.pem"
if [ ! -f "$EC2_ROOT_KEY" ]; then
echo "Warning: EC2 key does not exist: $EC2_ROOT_KEY" >&2
fi
# To override root, use ubuntu@ or ec2-user@ or whatever
local ssh_cmd="ssh -i $EC2_ROOT_KEY -o StrictHostKeyChecking=no -l root"
alias ash=$ssh_cmd
alias async="rsync -av -e '$ssh_cmd'"
}
# Switch AWS regions
awsregion () {
if [ $# -eq 1 ]; then
export AWS_DEFAULT_REGION=$1
export AWS_REGION=$1
# ec2keypair # reset keys when switch regions
fi
[ -t 0 ] && echo "AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION"
}
# Switch between AWS account credentials
awsacct () {
if [ $# -eq 1 ]; then
local acct="$1"
local acctdir="$HOME/.awsacct/$1"
if [ ! -d $acctdir ]; then
echo "Error: No such dir $acctdir" >&2
unset AWS_ACCOUNT AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_DEFAULT_REGION AWS_REGION
return 1
fi
export AWS_ACCOUNT=$acct
# Newer tools and unified CLI
. $acctdir/access_keys.txt
export AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_DEFAULT_REGION AWS_REGION
# ec2keypair # reset keys when switch accounts
fi
- [ -t 0 ] && echo "AWS_ACCOUNT=$AWS_ACCOUNT"
+ [ -t 0 ] && env | grep '^AWS_'
}
+[ -d "$HOME/.awsacct/default" ] && awsacct `readlink "$HOME/.awsacct/default"`
+
# Prompt in zsh
autoload -U promptinit && promptinit && prompt redhat
|
nateware/dotfiles
|
fff7460062f2456f69f13fbc25b1337d8704acb6
|
tweaks
|
diff --git a/.bash_profile b/.bash_profile
index 7ea3936..acdb492 100644
--- a/.bash_profile
+++ b/.bash_profile
@@ -1,56 +1,56 @@
# Must source manually
[ -f $HOME/.bashrc ] && . $HOME/.bashrc
# Old school 1986 style colors
# c1="\033["
# c2="m"
# c_normal="${c1}0${c2}"
# c_bold="${c1}1${c2}"
# c_black="${c1}0;30${c2}"
# c_blue="${c1}0;34${c2}"
# c_green="${c1}0;32${c2}"
# c_cyan="${c1}0;36${c2}"
# c_red="${c1}0;31${c2}"
# c_purple="${c1}0;35${c2}"
# c_brown="${c1}0;33${c2}"
# c_gray="${c1}0;37${c2}"
# c_dark_gray="${c1}1;30${c2}"
# c_bold_blue="${c1}1;34${c2}"
# c_bold_green="${c1}1;32${c2}"
# c_bold_cyan="${c1}1;36${c2}"
# c_bold_red="${c1}1;31${c2}"
# c_bold_purple="${c1}1;35${c2}"
# c_bold_yellow="${c1}1;33${c2}"
# c_bold_white="${c1}1;37${c2}"
# http://stackoverflow.com/questions/4332478/read-the-current-text-color-in-a-xterm
C_BLACK=$(tput setaf 0)
C_RED=$(tput setaf 1)
C_GREEN=$(tput setaf 2)
C_YELLOW=$(tput setaf 3)
C_LIME_YELLOW=$(tput setaf 190)
C_POWDER_BLUE=$(tput setaf 153)
C_BLUE=$(tput setaf 4)
C_MAGENTA=$(tput setaf 5)
C_CYAN=$(tput setaf 6)
C_WHITE=$(tput setaf 7)
C_BRIGHT=$(tput bold)
C_NORMAL=$(tput sgr0)
C_BLINK=$(tput blink)
C_REVERSE=$(tput smso)
C_UNDERLINE=$(tput smul)
# Prompt
# The \[ \] parts are to fix bash prompt CLI issues
# http://askubuntu.com/questions/111840/ps1-problem-messing-up-cli
export PS1='[\[$C_BLUE\]\W\[$C_NORMAL\]]\[$C_GREEN\]\$\[$C_NORMAL\] '
#printf $C_RED
#type ruby
#printf $C_NORMAL
-# Only sublime on login; vi otherwise
+# Only vim on login; vi otherwise
export EDITOR='vim'
[ -s $HOME/.nvm/nvm.sh ] && . $HOME/.nvm/nvm.sh # This loads NVM
diff --git a/.bashrc b/.bashrc
index 0106d4e..4d4a03d 100644
--- a/.bashrc
+++ b/.bashrc
@@ -1,267 +1,268 @@
# ~/.bashrc
umask 022
# Add to PATH but only if it exists
add_path () {
err=0
for p
do
if [ -d $p ]; then
PATH="$p:$PATH"
else
err=1
fi
done
return $err
}
# Add to LD_LIB_PATH adjusting for platform
add_lib () {
[ -d "$1" ] || return 0
if [ "$OS" = Darwin ]; then
export DYLD_LIBRARY_PATH="$1:$DYLD_LIBRARY_PATH"
else
export LD_LIBRARY_PATH="$1:$DYLD_LIBRARY_PATH"
fi
return 0
}
# Guess
add_path_and_lib () {
if add_path "$1"; then
lib=${1%/bin}/lib
add_lib $lib
else
return 1
fi
}
# Aliases
alias ls='\ls -Gh'
alias ll='ls -al'
alias wget='curl -LO'
alias ldd='otool -L'
alias rsync='\rsync --exclude=.svn --exclude=.git --exclude=RCS'
alias vi='vim -b'
# Don't want to install rubydocs - TOO SLOW!
alias gi='gem install --no-ri --no-rdoc'
alias bi='bundle install --without=production:staging:assets'
alias bu='bundle update'
alias be='bundle exec'
alias ga='git ci -a -m'
alias gd='git pu && git push -f dev'
alias gp='git pu'
gap () {
ga "$*" && gp
}
gapd () {
gap "$*" && cap dev deploy
}
# Change to workspace directory
wd () {
if [ $# -eq 0 ]; then
pushd "$HOME/Workspace"
elif [ -d "$1" ]; then
# tab expansion
pushd "$1"
else
# wildcard
pushd "$HOME/Workspace/$1"*
fi
}
# Platform goodness
export OS=`uname`
[ "$OS" = Darwin ] && export JAVA_HOME=/Library/Java/Home
# Remember add_path unshifts, so the one you want first should be last
add_path \
/usr/local/git/bin \
/usr/local/bin \
/opt/local/sbin \
/opt/local/bin \
$HOME/sbin \
$HOME/bin
# Android tools
add_path $HOME/Workspace/adt-bundle-mac-x86_64-20130522/sdk/platform-tools
# Ruby version manager
[ -s $HOME/.rvm/scripts/rvm ] && . $HOME/.rvm/scripts/rvm
# Node version manager
[ -s $HOME/.nvm/nvm.sh ] && . $HOME/.nvm/nvm.sh
[ -f $NVM_DIR/bash_completion ] && . $NVM_DIR/bash_completion
# rbenv
if type rbenv >/dev/null 2>&1; then
eval "$(rbenv init -)"
fi
# ImageMagick
add_path_and_lib /usr/local/ImageMagick/bin
# MySQL
add_path_and_lib /usr/local/mysql/bin
# Self-contained Postgres.app
add_path /Applications/Postgres.app/Contents/MacOS/bin
# MongoDB
add_path /usr/local/mongodb/bin
# Switch between AWS account credentials
awsacct () {
if [ $# -eq 1 ]; then
local acct="$1"
local acctdir=$(awsacctdir $acct)
if [ ! -d $acctdir ]; then
echo "Error: No such dir $acctdir" >&2
unset AWS_ACCOUNT AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_DEFAULT_REGION AWS_REGION
return 1
fi
export AWS_ACCOUNT=$acct
# Newer tools and unified CLI
. $acctdir/access_keys.txt
export AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_DEFAULT_REGION AWS_REGION
ec2keypair # reset keys when switch accounts
fi
[ -t 0 ] && env "AWS_ACCOUNT=$AWS_ACCOUNT" | grep '^AWS'
}
# Switch AWS regions
awsregion () {
if [ $# -eq 1 ]; then
export AWS_DEFAULT_REGION=$1
ec2keypair # reset keys when switch regions
fi
[ -t 0 ] && echo "AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION"
}
awsacctdir () {
echo "$HOME/.awsacct/$1"
}
# My approach for ec2 is to launch instances with a custom "root" keypair,
# but the username may change based on AMI, so then just ssh ec2-user@whatevs
# Remember keypairs are mapped to IAM user + region so use both pieces.
ec2keypair () {
local user="${1:-root}"
- if [ -z "$AWS_ACCOUNT" -o -z "$AWS_DEFAULT_REGION" ]; then
+ if [ -z "$AWS_ACCOUNT" -o -z "$AWS_REGION" ]; then
echo "Error: Set awsacct and awsregion before ec2keypair" >&2
return 1
fi
local acctdir=$(awsacctdir $AWS_ACCOUNT)
- export EC2_ROOT_KEY="$acctdir/$user-$AWS_DEFAULT_REGION.pem"
+ export EC2_ROOT_KEY="$acctdir/$user-$AWS_REGION.pem"
if [ ! -f "$EC2_ROOT_KEY" ]; then
echo "Warning: EC2 key does not exist: $EC2_ROOT_KEY" >&2
fi
# To override root, use ubuntu@ or ec2-user@ or whatever
local ssh_cmd="ssh -i $EC2_ROOT_KEY -o StrictHostKeyChecking=no -l root"
alias ash=$ssh_cmd
alias async="rsync -av -e '$ssh_cmd'"
}
# Set default AWS region and account
export AWS_DEFAULT_REGION="us-west-2"
if [ -d "$HOME/.awsacct/default" ]; then
what=$(readlink $HOME/.awsacct/default)
awsacct $what
fi
# Use garnaat's unified CLI
complete -C aws_completer aws # bash tab completion
paws (){
aws "$@" | ruby -rjson -rawesome_print -e "ap JSON.parse(STDIN.read)"
}
complete -C aws_completer paws # bash tab completion
[ -f "$HOME/.git-completion.bash" ] && . "$HOME/.git-completion.bash"
# Easy unzipping
untar () {
if [ "$#" -eq 0 ]; then
echo "Usage: untar files ..." >&2
return 1
fi
for f
do
case $f in
*.zip) unzip $f;;
*.tar.gz|*.tgz) tar xzvf $f;;
*.tar.bz|*.tbz) bunzip -c $f | tar xvf -;;
*.tar.bz2|*.tbz2) bunzip2 -c $f | tar xvf -;;
*) echo "Unsupported file type: $f" >&2;;
esac
done
}
# shortcut to kill processes that tend to suck
fuck () {
local pn=
case "$1" in
chr*) pn="Google Chrome";;
cisc*) pn="Cisco AnyConnect Secure Mobility Client";;
esac
killall "$pn"
sleep 2
killall "$pn"
sleep 3
killall -9 "$pn"
}
# Postgres
if add_path /Library/PostgreSQL/9.0/bin; then
. /Library/PostgreSQL/9.0/pg_env.sh
fi
export JVA=209.40.197.81
alias jva="ssh -l janetvanarsdale $JVA"
alias rjva="ssh -l root $JVA"
# Workaround for ruby 2.0.0 rubygems issue
alias chef-solo='unset GEM_HOME GEM_PATH && \chef-solo'
alias knife='unset GEM_HOME GEM_PATH && \knife'
# Still needed for old games
if [ -d "/usr/local/oracle/10.2.0.4/client" ]; then
add_path_and_lib "$ORACLE_HOME/bin"
export ORACLE_HOME="/usr/local/oracle/10.2.0.4/client"
export TNS_ADMIN="$HOME/tnsadmin" # Directory
export NLS_LANG=".AL32UTF8"
fi
# For fucking with "go" the language
if [ -d $HOME/Workspace/go ]; then
export GOROOT=$HOME/Workspace/go
export GOOS=darwin
export GOARCH=386
export GOBIN=$HOME/bin
fi
### Added by the Heroku Toolbelt
add_path /usr/local/heroku/bin
# GCE
if [ -d $HOME/Workspace/google-cloud-sdk ]; then
# The next line updates PATH for the Google Cloud SDK.
. $HOME/Workspace/google-cloud-sdk/path.bash.inc
# The next line enables bash completion for gcloud.
. $HOME/Workspace/google-cloud-sdk/completion.bash.inc
alias gsh="ssh -i $HOME/.ssh/google_compute_engine -o StrictHostKeyChecking=no"
fi
+add_path $HOME/Library/Python/3.9/bin
diff --git a/.zprofile b/.zprofile
index 782dc02..6f14cda 100644
--- a/.zprofile
+++ b/.zprofile
@@ -1,64 +1,102 @@
# Aliases
alias ls='\ls -Gh'
alias ll='ls -al'
alias wget='curl -LO'
alias ldd='otool -L'
alias rsync='\rsync --exclude=.svn --exclude=.git --exclude=RCS'
alias vi='vim -b'
# Homebrew
-eval "$(/opt/homebrew/bin/brew shellenv)"
+[ -f /opt/homebrew/bin/brew ] && eval "$(/opt/homebrew/bin/brew shellenv)"
# Node
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
# Ruby
-export PATH="$HOME/.rbenv/shims:$PATH"
+[ -d $HOME/.rbenv ] && export PATH="$HOME/.rbenv/shims:$PATH"
+
# Change to workspace directory
wd () {
if [ $# -eq 0 ]; then
pushd "$HOME/Workspace"
elif [ -d "$1" ]; then
# tab expansion
pushd "$1"
else
# wildcard
pushd "$HOME/Workspace/$1"*
fi
}
-# Switch between AWS account credentials
-awsacctdir () {
- echo "$HOME/.awsacct/$1"
+[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
+[ -f "$HOME/.git-completion.zsh" ] && . "$HOME/.git-completion.zsh"
+
+# Use garnaat's unified CLI
+complete -C aws_completer aws # bash tab completion
+paws (){
+ aws "$@" | ruby -rjson -rawesome_print -e "ap JSON.parse(STDIN.read)"
+}
+complete -C aws_completer paws # bash tab completion
+
+
+# My approach for ec2 is to launch instances with a custom "root" keypair,
+# but the username may change based on AMI, so then just ssh ec2-user@whatevs
+# Remember keypairs are mapped to IAM user + region so use both pieces.
+ec2keypair () {
+ local user="${1:-root}"
+
+ if [ -z "$AWS_ACCOUNT" -o -z "$AWS_REGION" ]; then
+ echo "Error: Set awsacct and awsregion before ec2keypair" >&2
+ return 1
+ fi
+ local acctdir=$(awsacctdir $AWS_ACCOUNT)
+
+ export EC2_ROOT_KEY="$acctdir/$user-$AWS_REGION.pem"
+ if [ ! -f "$EC2_ROOT_KEY" ]; then
+ echo "Warning: EC2 key does not exist: $EC2_ROOT_KEY" >&2
+ fi
+
+ # To override root, use ubuntu@ or ec2-user@ or whatever
+ local ssh_cmd="ssh -i $EC2_ROOT_KEY -o StrictHostKeyChecking=no -l root"
+ alias ash=$ssh_cmd
+ alias async="rsync -av -e '$ssh_cmd'"
}
+# Switch AWS regions
+awsregion () {
+ if [ $# -eq 1 ]; then
+ export AWS_DEFAULT_REGION=$1
+ export AWS_REGION=$1
+ # ec2keypair # reset keys when switch regions
+ fi
+
+ [ -t 0 ] && echo "AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION"
+}
+
+# Switch between AWS account credentials
awsacct () {
if [ $# -eq 1 ]; then
local acct="$1"
- local acctdir=$(awsacctdir $acct)
+ local acctdir="$HOME/.awsacct/$1"
if [ ! -d $acctdir ]; then
echo "Error: No such dir $acctdir" >&2
- unset AWS_ACCOUNT AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_DEFAULT_REGION
+ unset AWS_ACCOUNT AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_DEFAULT_REGION AWS_REGION
return 1
fi
export AWS_ACCOUNT=$acct
# Newer tools and unified CLI
. $acctdir/access_keys.txt
- export AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_DEFAULT_REGION
+ export AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_DEFAULT_REGION AWS_REGION
- ec2keypair # reset keys when switch accounts
+ # ec2keypair # reset keys when switch accounts
fi
[ -t 0 ] && echo "AWS_ACCOUNT=$AWS_ACCOUNT"
}
-#autoload -U promptinit && promptinit && prompt redhat
-
-# Setting PATH for Python 3.12
-# The original version is saved in .zprofile.pysave
-PATH="/Library/Frameworks/Python.framework/Versions/3.12/bin:${PATH}"
-export PATH
+# Prompt in zsh
+autoload -U promptinit && promptinit && prompt redhat
diff --git a/.zshrc b/.zshrc
index ebb4543..cb481ca 100644
--- a/.zshrc
+++ b/.zshrc
@@ -1,82 +1,81 @@
# ~/.zshrc
umask 022
# Add to PATH but only if it exists
add_path () {
err=0
for p
do
if [ -d $p ]; then
PATH="$p:$PATH"
else
err=1
fi
done
return $err
}
# Add to LD_LIB_PATH adjusting for platform
add_lib () {
[ -d "$1" ] || return 0
if [ "$OS" = Darwin ]; then
export DYLD_LIBRARY_PATH="$1:$DYLD_LIBRARY_PATH"
else
export LD_LIBRARY_PATH="$1:$DYLD_LIBRARY_PATH"
fi
return 0
}
# Guess
add_path_and_lib () {
if add_path "$1"; then
lib=${1%/bin}/lib
add_lib $lib
else
return 1
fi
}
# Change to workspace directory
wd () {
if [ $# -eq 0 ]; then
pushd "$HOME/Workspace"
elif [ -d "$1" ]; then
# tab expansion
pushd "$1"
else
# wildcard
pushd "$HOME/Workspace/$1"*
fi
}
# Aliases
alias ls='\ls -Gh'
alias ll='ls -al'
alias wget='curl -LO'
alias ldd='otool -L'
alias rsync='\rsync --exclude=.svn --exclude=.git --exclude=RCS'
# Don't want to install rubydocs - TOO SLOW!
alias gi='gem install --no-ri --no-rdoc'
alias bi='bundle install --without=production:staging:assets'
alias bu='bundle update'
alias be='bundle exec'
alias ga='git ci -a -m'
alias gd='git pu && git push -f dev'
alias gp='git pu'
# Platform goodness
export OS=`uname`
[ "$OS" = Darwin ] && export JAVA_HOME=/Library/Java/Home
# Ruby version manager
[ -s $HOME/.rvm/scripts/rvm ] && . $HOME/.rvm/scripts/rvm
# Node version manager
[ -s $HOME/.nvm/nvm.sh ] && . $HOME/.nvm/nvm.sh # This loads NVM
export EDITOR='vim'
export PS1=$'\033[36m%n\033[m@\033[32m%m:\033[33;1m%~\033[m\$ '
add_path $HOME/Library/Python/3.9/bin
-[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
|
nateware/dotfiles
|
69e64de58717f25ece9c9392decf32974a7f1f51
|
nvm bash completion
|
diff --git a/.zshrc b/.zshrc
index cb481ca..ebb4543 100644
--- a/.zshrc
+++ b/.zshrc
@@ -1,81 +1,82 @@
# ~/.zshrc
umask 022
# Add to PATH but only if it exists
add_path () {
err=0
for p
do
if [ -d $p ]; then
PATH="$p:$PATH"
else
err=1
fi
done
return $err
}
# Add to LD_LIB_PATH adjusting for platform
add_lib () {
[ -d "$1" ] || return 0
if [ "$OS" = Darwin ]; then
export DYLD_LIBRARY_PATH="$1:$DYLD_LIBRARY_PATH"
else
export LD_LIBRARY_PATH="$1:$DYLD_LIBRARY_PATH"
fi
return 0
}
# Guess
add_path_and_lib () {
if add_path "$1"; then
lib=${1%/bin}/lib
add_lib $lib
else
return 1
fi
}
# Change to workspace directory
wd () {
if [ $# -eq 0 ]; then
pushd "$HOME/Workspace"
elif [ -d "$1" ]; then
# tab expansion
pushd "$1"
else
# wildcard
pushd "$HOME/Workspace/$1"*
fi
}
# Aliases
alias ls='\ls -Gh'
alias ll='ls -al'
alias wget='curl -LO'
alias ldd='otool -L'
alias rsync='\rsync --exclude=.svn --exclude=.git --exclude=RCS'
# Don't want to install rubydocs - TOO SLOW!
alias gi='gem install --no-ri --no-rdoc'
alias bi='bundle install --without=production:staging:assets'
alias bu='bundle update'
alias be='bundle exec'
alias ga='git ci -a -m'
alias gd='git pu && git push -f dev'
alias gp='git pu'
# Platform goodness
export OS=`uname`
[ "$OS" = Darwin ] && export JAVA_HOME=/Library/Java/Home
# Ruby version manager
[ -s $HOME/.rvm/scripts/rvm ] && . $HOME/.rvm/scripts/rvm
# Node version manager
[ -s $HOME/.nvm/nvm.sh ] && . $HOME/.nvm/nvm.sh # This loads NVM
export EDITOR='vim'
export PS1=$'\033[36m%n\033[m@\033[32m%m:\033[33;1m%~\033[m\$ '
add_path $HOME/Library/Python/3.9/bin
+[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
|
nateware/dotfiles
|
f544c4b625f324f1e637e368a46b160ca783fcb9
|
added zprofile
|
diff --git a/.zprofile b/.zprofile
new file mode 100644
index 0000000..782dc02
--- /dev/null
+++ b/.zprofile
@@ -0,0 +1,64 @@
+# Aliases
+alias ls='\ls -Gh'
+alias ll='ls -al'
+alias wget='curl -LO'
+alias ldd='otool -L'
+alias rsync='\rsync --exclude=.svn --exclude=.git --exclude=RCS'
+alias vi='vim -b'
+
+# Homebrew
+eval "$(/opt/homebrew/bin/brew shellenv)"
+
+# Node
+export NVM_DIR="$HOME/.nvm"
+[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
+
+# Ruby
+export PATH="$HOME/.rbenv/shims:$PATH"
+
+# Change to workspace directory
+wd () {
+ if [ $# -eq 0 ]; then
+ pushd "$HOME/Workspace"
+ elif [ -d "$1" ]; then
+ # tab expansion
+ pushd "$1"
+ else
+ # wildcard
+ pushd "$HOME/Workspace/$1"*
+ fi
+}
+
+# Switch between AWS account credentials
+awsacctdir () {
+ echo "$HOME/.awsacct/$1"
+}
+
+awsacct () {
+ if [ $# -eq 1 ]; then
+ local acct="$1"
+ local acctdir=$(awsacctdir $acct)
+ if [ ! -d $acctdir ]; then
+ echo "Error: No such dir $acctdir" >&2
+ unset AWS_ACCOUNT AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_DEFAULT_REGION
+ return 1
+ fi
+
+ export AWS_ACCOUNT=$acct
+
+ # Newer tools and unified CLI
+ . $acctdir/access_keys.txt
+ export AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_DEFAULT_REGION
+
+ ec2keypair # reset keys when switch accounts
+ fi
+
+ [ -t 0 ] && echo "AWS_ACCOUNT=$AWS_ACCOUNT"
+}
+
+#autoload -U promptinit && promptinit && prompt redhat
+
+# Setting PATH for Python 3.12
+# The original version is saved in .zprofile.pysave
+PATH="/Library/Frameworks/Python.framework/Versions/3.12/bin:${PATH}"
+export PATH
diff --git a/.zshrc b/.zshrc
index 77f1a9b..cb481ca 100644
--- a/.zshrc
+++ b/.zshrc
@@ -1,80 +1,81 @@
# ~/.zshrc
umask 022
# Add to PATH but only if it exists
add_path () {
err=0
for p
do
if [ -d $p ]; then
PATH="$p:$PATH"
else
err=1
fi
done
return $err
}
# Add to LD_LIB_PATH adjusting for platform
add_lib () {
[ -d "$1" ] || return 0
if [ "$OS" = Darwin ]; then
export DYLD_LIBRARY_PATH="$1:$DYLD_LIBRARY_PATH"
else
export LD_LIBRARY_PATH="$1:$DYLD_LIBRARY_PATH"
fi
return 0
}
# Guess
add_path_and_lib () {
if add_path "$1"; then
lib=${1%/bin}/lib
add_lib $lib
else
return 1
fi
}
# Change to workspace directory
wd () {
if [ $# -eq 0 ]; then
pushd "$HOME/Workspace"
elif [ -d "$1" ]; then
# tab expansion
pushd "$1"
else
# wildcard
pushd "$HOME/Workspace/$1"*
fi
}
# Aliases
alias ls='\ls -Gh'
alias ll='ls -al'
alias wget='curl -LO'
alias ldd='otool -L'
alias rsync='\rsync --exclude=.svn --exclude=.git --exclude=RCS'
# Don't want to install rubydocs - TOO SLOW!
alias gi='gem install --no-ri --no-rdoc'
alias bi='bundle install --without=production:staging:assets'
alias bu='bundle update'
alias be='bundle exec'
alias ga='git ci -a -m'
alias gd='git pu && git push -f dev'
alias gp='git pu'
# Platform goodness
export OS=`uname`
[ "$OS" = Darwin ] && export JAVA_HOME=/Library/Java/Home
# Ruby version manager
[ -s $HOME/.rvm/scripts/rvm ] && . $HOME/.rvm/scripts/rvm
# Node version manager
[ -s $HOME/.nvm/nvm.sh ] && . $HOME/.nvm/nvm.sh # This loads NVM
export EDITOR='vim'
export PS1=$'\033[36m%n\033[m@\033[32m%m:\033[33;1m%~\033[m\$ '
+add_path $HOME/Library/Python/3.9/bin
|
nateware/dotfiles
|
e4723bf6070e0875ae0672e3d610f91afe21f15e
|
zsh support
|
diff --git a/.zshrc b/.zshrc
new file mode 100644
index 0000000..1a204ab
--- /dev/null
+++ b/.zshrc
@@ -0,0 +1,72 @@
+# ~/.zshrc
+umask 022
+
+# Add to PATH but only if it exists
+add_path () {
+ err=0
+ for p
+ do
+ if [ -d $p ]; then
+ PATH="$p:$PATH"
+ else
+ err=1
+ fi
+ done
+ return $err
+}
+
+# Add to LD_LIB_PATH adjusting for platform
+add_lib () {
+ [ -d "$1" ] || return 0
+ if [ "$OS" = Darwin ]; then
+ export DYLD_LIBRARY_PATH="$1:$DYLD_LIBRARY_PATH"
+ else
+ export LD_LIBRARY_PATH="$1:$DYLD_LIBRARY_PATH"
+ fi
+ return 0
+}
+
+# Guess
+add_path_and_lib () {
+ if add_path "$1"; then
+ lib=${1%/bin}/lib
+ add_lib $lib
+ else
+ return 1
+ fi
+}
+
+# Change to workspace directory
+wd () {
+ if [ $# -eq 0 ]; then
+ pushd "$HOME/Workspace"
+ elif [ -d "$1" ]; then
+ # tab expansion
+ pushd "$1"
+ else
+ # wildcard
+ pushd "$HOME/Workspace/$1"*
+ fi
+}
+
+# Aliases
+alias ls='\ls -Gh'
+alias ll='ls -al'
+alias wget='curl -LO'
+alias ldd='otool -L'
+alias rsync='\rsync --exclude=.svn --exclude=.git --exclude=RCS'
+
+# Don't want to install rubydocs - TOO SLOW!
+alias gi='gem install --no-ri --no-rdoc'
+alias bi='bundle install --without=production:staging:assets'
+alias bu='bundle update'
+alias be='bundle exec'
+alias ga='git ci -a -m'
+alias gd='git pu && git push -f dev'
+alias gp='git pu'
+
+[ -s $HOME/.nvm/nvm.sh ] && . $HOME/.nvm/nvm.sh # This loads NVM
+
+export EDITOR='vim'
+export PS1=$'\033[36m%n\033[m@\033[32m%m:\033[33;1m%~\033[m\$ '
+
|
nateware/dotfiles
|
6739eeadf9f7e1debbf7966babfe2cb504ed9f5d
|
removed linking of .git
|
diff --git a/relink b/relink
index 82b3d70..85e58da 100755
--- a/relink
+++ b/relink
@@ -1,13 +1,14 @@
#!/usr/bin/env ruby
# use ruby to get relative paths
require 'pathname'
Dir['.[a-z]*'].each do |file|
+ next if file == '.git'
path = Pathname.new(Dir.pwd + '/' + file)
home = Pathname.new(ENV['HOME'])
rel = path.relative_path_from home
link = ENV['HOME'] + '/' + file
puts "#{link} -> #{rel}"
system "rm -f #{link} && ln -s #{rel} #{link}"
end
|
nateware/dotfiles
|
57e0e6489f20baf3699029012d9e4010c5ed0161
|
bounds check for GCE
|
diff --git a/.bashrc b/.bashrc
index 280ca79..df6f701 100644
--- a/.bashrc
+++ b/.bashrc
@@ -1,263 +1,267 @@
# ~/.bashrc
umask 022
# Add to PATH but only if it exists
add_path () {
err=0
for p
do
if [ -d $p ]; then
PATH="$p:$PATH"
else
err=1
fi
done
return $err
}
# Add to LD_LIB_PATH adjusting for platform
add_lib () {
[ -d "$1" ] || return 0
if [ "$OS" = Darwin ]; then
export DYLD_LIBRARY_PATH="$1:$DYLD_LIBRARY_PATH"
else
export LD_LIBRARY_PATH="$1:$DYLD_LIBRARY_PATH"
fi
return 0
}
# Guess
add_path_and_lib () {
if add_path "$1"; then
lib=${1%/bin}/lib
add_lib $lib
else
return 1
fi
}
# Aliases
alias ls='\ls -Gh'
alias ll='ls -al'
alias wget='curl -LO'
alias ldd='otool -L'
alias rsync='\rsync --exclude=.svn --exclude=.git --exclude=RCS'
alias vi='vim -b'
# Don't want to install rubydocs - TOO SLOW!
alias gi='gem install --no-ri --no-rdoc'
alias bi='bundle install --without=production:staging:assets'
alias bu='bundle update'
alias be='bundle exec'
alias ga='git ci -a -m'
alias gd='git pu && git push -f dev'
alias gp='git pu'
gap () {
ga "$*" && gp
}
gapd () {
gap "$*" && cap dev deploy
}
# Change to workspace directory
wd () {
if [ $# -eq 0 ]; then
pushd "$HOME/Workspace"
elif [ -d "$1" ]; then
# tab expansion
pushd "$1"
else
# wildcard
pushd "$HOME/Workspace/$1"*
fi
}
# Platform goodness
export OS=`uname`
[ "$OS" = Darwin ] && export JAVA_HOME=/Library/Java/Home
# Remember add_path unshifts, so the one you want first should be last
add_path \
/usr/local/git/bin \
/usr/local/bin \
/opt/local/sbin \
/opt/local/bin \
$HOME/sbin \
$HOME/bin
# Android tools
add_path $HOME/Workspace/adt-bundle-mac-x86_64-20130522/sdk/platform-tools
# Ruby version manager
[ -s $HOME/.rvm/scripts/rvm ] && . $HOME/.rvm/scripts/rvm
# Node version manager
[ -s $HOME/.nvm/nvm.sh ] && . $HOME/.nvm/nvm.sh
[ -f $NVM_DIR/bash_completion ] && . $NVM_DIR/bash_completion
# rbenv
if type rbenv >/dev/null; then
eval "$(rbenv init -)"
fi
# ImageMagick
add_path_and_lib /usr/local/ImageMagick/bin
# MySQL
add_path_and_lib /usr/local/mysql/bin
# Self-contained Postgres.app
add_path /Applications/Postgres.app/Contents/MacOS/bin
# MongoDB
add_path /usr/local/mongodb/bin
# Switch between AWS account credentials
awsacct () {
if [ $# -eq 1 ]; then
local acct="$1"
local acctdir=$(awsacctdir $acct)
if [ ! -d $acctdir ]; then
echo "Error: No such dir $acctdir" >&2
unset AWS_ACCOUNT AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_DEFAULT_REGION
return 1
fi
export AWS_ACCOUNT=$acct
# Newer tools and unified CLI
. $acctdir/access_keys.txt
export AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_DEFAULT_REGION
ec2keypair # reset keys when switch accounts
fi
[ -t 0 ] && echo "AWS_ACCOUNT=$AWS_ACCOUNT"
}
# Switch AWS regions
awsregion () {
if [ $# -eq 1 ]; then
export AWS_DEFAULT_REGION=$1
ec2keypair # reset keys when switch regions
fi
[ -t 0 ] && echo "AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION"
}
awsacctdir () {
echo "$HOME/.awsacct/$1"
}
# My approach for ec2 is to launch instances with a custom "root" keypair,
# but the username may change based on AMI, so then just ssh ec2-user@whatevs
# Remember keypairs are mapped to IAM user + region so use both pieces.
ec2keypair () {
local user="${1:-root}"
if [ -z "$AWS_ACCOUNT" -o -z "$AWS_DEFAULT_REGION" ]; then
echo "Error: Set awsacct and awsregion before ec2keypair" >&2
return 1
fi
local acctdir=$(awsacctdir $AWS_ACCOUNT)
export EC2_ROOT_KEY="$acctdir/$user-$AWS_DEFAULT_REGION.pem"
if [ ! -f "$EC2_ROOT_KEY" ]; then
echo "Warning: EC2 key does not exist: $EC2_ROOT_KEY" >&2
fi
# To override root, use ubuntu@ or ec2-user@ or whatever
local ssh_cmd="ssh -i $EC2_ROOT_KEY -o StrictHostKeyChecking=no -l root"
alias ash=$ssh_cmd
alias async="rsync -av -e '$ssh_cmd'"
}
# Set default AWS region and account
export AWS_DEFAULT_REGION="us-west-2"
if [ -d "$HOME/.awsacct/default" ]; then
what=$(readlink $HOME/.awsacct/default)
awsacct $what
fi
# Use garnaat's unified CLI
complete -C aws_completer aws # bash tab completion
paws (){
aws "$@" | ruby -rjson -rawesome_print -e "ap JSON.parse(STDIN.read)"
}
complete -C aws_completer paws # bash tab completion
[ -f "$HOME/.git-completion.bash" ] && . "$HOME/.git-completion.bash"
# Easy unzipping
untar () {
if [ "$#" -eq 0 ]; then
echo "Usage: untar files ..." >&2
return 1
fi
for f
do
case $f in
*.zip) unzip $f;;
*.tar.gz|*.tgz) tar xzvf $f;;
*.tar.bz|*.tbz) bunzip -c $f | tar xvf -;;
*.tar.bz2|*.tbz2) bunzip2 -c $f | tar xvf -;;
*) echo "Unsupported file type: $f" >&2;;
esac
done
}
# shortcut to kill processes that tend to suck
fuck () {
local pn=
case "$1" in
chr*) pn="Google Chrome";;
cisc*) pn="Cisco AnyConnect Secure Mobility Client";;
esac
killall "$pn"
sleep 2
killall "$pn"
sleep 3
killall -9 "$pn"
}
# Postgres
if add_path /Library/PostgreSQL/9.0/bin; then
. /Library/PostgreSQL/9.0/pg_env.sh
fi
export JVA=209.40.197.81
alias jva="ssh -l janetvanarsdale $JVA"
alias rjva="ssh -l root $JVA"
# Workaround for ruby 2.0.0 rubygems issue
alias chef-solo='unset GEM_HOME GEM_PATH && \chef-solo'
alias knife='unset GEM_HOME GEM_PATH && \knife'
# Still needed for old games
if [ -d "/usr/local/oracle/10.2.0.4/client" ]; then
add_path_and_lib "$ORACLE_HOME/bin"
export ORACLE_HOME="/usr/local/oracle/10.2.0.4/client"
export TNS_ADMIN="$HOME/tnsadmin" # Directory
export NLS_LANG=".AL32UTF8"
fi
# For fucking with "go" the language
if [ -d $HOME/Workspace/go ]; then
export GOROOT=$HOME/Workspace/go
export GOOS=darwin
export GOARCH=386
export GOBIN=$HOME/bin
fi
### Added by the Heroku Toolbelt
add_path /usr/local/heroku/bin
-# The next line updates PATH for the Google Cloud SDK.
-. $HOME/Workspace/google-cloud-sdk/path.bash.inc
+# GCE
+if [ -d $HOME/Workspace/google-cloud-sdk ]; then
+ # The next line updates PATH for the Google Cloud SDK.
+ . $HOME/Workspace/google-cloud-sdk/path.bash.inc
-# The next line enables bash completion for gcloud.
-. $HOME/Workspace/google-cloud-sdk/completion.bash.inc
+ # The next line enables bash completion for gcloud.
+ . $HOME/Workspace/google-cloud-sdk/completion.bash.inc
+
+ alias gsh="ssh -i $HOME/.ssh/google_compute_engine -o StrictHostKeyChecking=no"
+fi
-alias gsh="ssh -i $HOME/.ssh/google_compute_engine -o StrictHostKeyChecking=no"
|
nateware/dotfiles
|
6df267fd91a6ffbe38d736f34fc8e897ae068235
|
a bit more cleanup and restructuring
|
diff --git a/.bashrc b/.bashrc
index d5b3606..280ca79 100644
--- a/.bashrc
+++ b/.bashrc
@@ -1,260 +1,263 @@
# ~/.bashrc
umask 022
# Add to PATH but only if it exists
add_path () {
err=0
for p
do
if [ -d $p ]; then
PATH="$p:$PATH"
else
err=1
fi
done
return $err
}
# Add to LD_LIB_PATH adjusting for platform
add_lib () {
[ -d "$1" ] || return 0
if [ "$OS" = Darwin ]; then
export DYLD_LIBRARY_PATH="$1:$DYLD_LIBRARY_PATH"
else
export LD_LIBRARY_PATH="$1:$DYLD_LIBRARY_PATH"
fi
return 0
}
# Guess
add_path_and_lib () {
if add_path "$1"; then
lib=${1%/bin}/lib
add_lib $lib
else
return 1
fi
}
# Aliases
alias ls='\ls -Gh'
alias ll='ls -al'
alias wget='curl -LO'
alias ldd='otool -L'
alias rsync='\rsync --exclude=.svn --exclude=.git --exclude=RCS'
alias vi='vim -b'
# Don't want to install rubydocs - TOO SLOW!
alias gi='gem install --no-ri --no-rdoc'
alias bi='bundle install --without=production:staging:assets'
alias bu='bundle update'
alias be='bundle exec'
alias ga='git ci -a -m'
alias gd='git pu && git push -f dev'
alias gp='git pu'
gap () {
ga "$*" && gp
}
gapd () {
gap "$*" && cap dev deploy
}
# Change to workspace directory
wd () {
if [ $# -eq 0 ]; then
pushd "$HOME/Workspace"
elif [ -d "$1" ]; then
# tab expansion
pushd "$1"
else
# wildcard
pushd "$HOME/Workspace/$1"*
fi
}
# Platform goodness
export OS=`uname`
[ "$OS" = Darwin ] && export JAVA_HOME=/Library/Java/Home
# Remember add_path unshifts, so the one you want first should be last
add_path \
/usr/local/git/bin \
/usr/local/bin \
/opt/local/sbin \
/opt/local/bin \
$HOME/sbin \
$HOME/bin
# Android tools
add_path $HOME/Workspace/adt-bundle-mac-x86_64-20130522/sdk/platform-tools
# Ruby version manager
[ -s $HOME/.rvm/scripts/rvm ] && . $HOME/.rvm/scripts/rvm
# Node version manager
[ -s $HOME/.nvm/nvm.sh ] && . $HOME/.nvm/nvm.sh
[ -f $NVM_DIR/bash_completion ] && . $NVM_DIR/bash_completion
# rbenv
if type rbenv >/dev/null; then
eval "$(rbenv init -)"
fi
# ImageMagick
add_path_and_lib /usr/local/ImageMagick/bin
# MySQL
add_path_and_lib /usr/local/mysql/bin
# Self-contained Postgres.app
add_path /Applications/Postgres.app/Contents/MacOS/bin
# MongoDB
add_path /usr/local/mongodb/bin
+# Switch between AWS account credentials
+awsacct () {
+ if [ $# -eq 1 ]; then
+ local acct="$1"
+ local acctdir=$(awsacctdir $acct)
+ if [ ! -d $acctdir ]; then
+ echo "Error: No such dir $acctdir" >&2
+ unset AWS_ACCOUNT AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_DEFAULT_REGION
+ return 1
+ fi
+
+ export AWS_ACCOUNT=$acct
+
+ # Newer tools and unified CLI
+ . $acctdir/access_keys.txt
+ export AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_DEFAULT_REGION
+
+ ec2keypair # reset keys when switch accounts
+ fi
+
+ [ -t 0 ] && echo "AWS_ACCOUNT=$AWS_ACCOUNT"
+}
+
+# Switch AWS regions
awsregion () {
if [ $# -eq 1 ]; then
export AWS_DEFAULT_REGION=$1
ec2keypair # reset keys when switch regions
fi
[ -t 0 ] && echo "AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION"
}
+awsacctdir () {
+ echo "$HOME/.awsacct/$1"
+}
+
+# My approach for ec2 is to launch instances with a custom "root" keypair,
+# but the username may change based on AMI, so then just ssh ec2-user@whatevs
+# Remember keypairs are mapped to IAM user + region so use both pieces.
ec2keypair () {
- # My approach for ec2 is to launch instances with a custom "root" keypair,
- # but the username may change based on AMI, so then just ssh ec2-user@whatevs
local user="${1:-root}"
if [ -z "$AWS_ACCOUNT" -o -z "$AWS_DEFAULT_REGION" ]; then
echo "Error: Set awsacct and awsregion before ec2keypair" >&2
return 1
fi
local acctdir=$(awsacctdir $AWS_ACCOUNT)
export EC2_ROOT_KEY="$acctdir/$user-$AWS_DEFAULT_REGION.pem"
if [ ! -f "$EC2_ROOT_KEY" ]; then
echo "Warning: EC2 key does not exist: $EC2_ROOT_KEY" >&2
fi
# To override root, use ubuntu@ or ec2-user@ or whatever
local ssh_cmd="ssh -i $EC2_ROOT_KEY -o StrictHostKeyChecking=no -l root"
alias ash=$ssh_cmd
alias async="rsync -av -e '$ssh_cmd'"
}
-awsacctdir () {
- echo "$HOME/.awsacct/$1"
-}
-
-awsacct () {
- if [ $# -eq 1 ]; then
- local acct="$1"
- local acctdir=$(awsacctdir $acct)
- if [ ! -d $acctdir ]; then
- echo "Error: No such dir $acctdir" >&2
- unset AWS_ACCOUNT AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_DEFAULT_REGION
- return 1
- fi
-
- export AWS_ACCOUNT=$acct
-
- # Newer tools and unified CLI
- . $acctdir/access_keys.txt
- export AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_DEFAULT_REGION
-
- ec2keypair # reset keys when switch accounts
- fi
-
- [ -t 0 ] && echo "AWS_ACCOUNT=$AWS_ACCOUNT"
-}
-
-# Set default EC2 region
+# Set default AWS region and account
export AWS_DEFAULT_REGION="us-west-2"
if [ -d "$HOME/.awsacct/default" ]; then
what=$(readlink $HOME/.awsacct/default)
awsacct $what
fi
# Use garnaat's unified CLI
complete -C aws_completer aws # bash tab completion
paws (){
aws "$@" | ruby -rjson -rawesome_print -e "ap JSON.parse(STDIN.read)"
}
complete -C aws_completer paws # bash tab completion
[ -f "$HOME/.git-completion.bash" ] && . "$HOME/.git-completion.bash"
# Easy unzipping
untar () {
if [ "$#" -eq 0 ]; then
echo "Usage: untar files ..." >&2
return 1
fi
for f
do
case $f in
*.zip) unzip $f;;
*.tar.gz|*.tgz) tar xzvf $f;;
*.tar.bz|*.tbz) bunzip -c $f | tar xvf -;;
*.tar.bz2|*.tbz2) bunzip2 -c $f | tar xvf -;;
*) echo "Unsupported file type: $f" >&2;;
esac
done
}
# shortcut to kill processes that tend to suck
fuck () {
local pn=
case "$1" in
chr*) pn="Google Chrome";;
cisc*) pn="Cisco AnyConnect Secure Mobility Client";;
esac
killall "$pn"
sleep 2
killall "$pn"
sleep 3
killall -9 "$pn"
}
# Postgres
if add_path /Library/PostgreSQL/9.0/bin; then
. /Library/PostgreSQL/9.0/pg_env.sh
fi
export JVA=209.40.197.81
alias jva="ssh -l janetvanarsdale $JVA"
alias rjva="ssh -l root $JVA"
# Workaround for ruby 2.0.0 rubygems issue
alias chef-solo='unset GEM_HOME GEM_PATH && \chef-solo'
alias knife='unset GEM_HOME GEM_PATH && \knife'
# Still needed for old games
if [ -d "/usr/local/oracle/10.2.0.4/client" ]; then
add_path_and_lib "$ORACLE_HOME/bin"
export ORACLE_HOME="/usr/local/oracle/10.2.0.4/client"
export TNS_ADMIN="$HOME/tnsadmin" # Directory
export NLS_LANG=".AL32UTF8"
fi
# For fucking with "go" the language
if [ -d $HOME/Workspace/go ]; then
export GOROOT=$HOME/Workspace/go
export GOOS=darwin
export GOARCH=386
export GOBIN=$HOME/bin
fi
### Added by the Heroku Toolbelt
add_path /usr/local/heroku/bin
# The next line updates PATH for the Google Cloud SDK.
-. /Users/nateware/Workspace/google-cloud-sdk/path.bash.inc
+. $HOME/Workspace/google-cloud-sdk/path.bash.inc
# The next line enables bash completion for gcloud.
-. /Users/nateware/Workspace/google-cloud-sdk/completion.bash.inc
+. $HOME/Workspace/google-cloud-sdk/completion.bash.inc
alias gsh="ssh -i $HOME/.ssh/google_compute_engine -o StrictHostKeyChecking=no"
|
nateware/dotfiles
|
26c8a857d5759268a80d67984ec412d141e4900b
|
cleanup awsacct switching functions
|
diff --git a/.bashrc b/.bashrc
index 378b7c1..d5b3606 100644
--- a/.bashrc
+++ b/.bashrc
@@ -1,262 +1,260 @@
# ~/.bashrc
umask 022
# Add to PATH but only if it exists
add_path () {
err=0
for p
do
if [ -d $p ]; then
PATH="$p:$PATH"
else
err=1
fi
done
return $err
}
# Add to LD_LIB_PATH adjusting for platform
add_lib () {
[ -d "$1" ] || return 0
if [ "$OS" = Darwin ]; then
export DYLD_LIBRARY_PATH="$1:$DYLD_LIBRARY_PATH"
else
export LD_LIBRARY_PATH="$1:$DYLD_LIBRARY_PATH"
fi
return 0
}
# Guess
add_path_and_lib () {
if add_path "$1"; then
lib=${1%/bin}/lib
add_lib $lib
else
return 1
fi
}
# Aliases
alias ls='\ls -Gh'
alias ll='ls -al'
alias wget='curl -LO'
alias ldd='otool -L'
alias rsync='\rsync --exclude=.svn --exclude=.git --exclude=RCS'
alias vi='vim -b'
# Don't want to install rubydocs - TOO SLOW!
alias gi='gem install --no-ri --no-rdoc'
alias bi='bundle install --without=production:staging:assets'
alias bu='bundle update'
alias be='bundle exec'
alias ga='git ci -a -m'
alias gd='git pu && git push -f dev'
alias gp='git pu'
gap () {
ga "$*" && gp
}
gapd () {
gap "$*" && cap dev deploy
}
# Change to workspace directory
wd () {
if [ $# -eq 0 ]; then
pushd "$HOME/Workspace"
elif [ -d "$1" ]; then
# tab expansion
pushd "$1"
else
# wildcard
pushd "$HOME/Workspace/$1"*
fi
}
# Platform goodness
export OS=`uname`
[ "$OS" = Darwin ] && export JAVA_HOME=/Library/Java/Home
# Remember add_path unshifts, so the one you want first should be last
add_path \
/usr/local/git/bin \
/usr/local/bin \
/opt/local/sbin \
/opt/local/bin \
$HOME/sbin \
$HOME/bin
# Android tools
add_path $HOME/Workspace/adt-bundle-mac-x86_64-20130522/sdk/platform-tools
# Ruby version manager
[ -s $HOME/.rvm/scripts/rvm ] && . $HOME/.rvm/scripts/rvm
# Node version manager
[ -s $HOME/.nvm/nvm.sh ] && . $HOME/.nvm/nvm.sh
[ -f $NVM_DIR/bash_completion ] && . $NVM_DIR/bash_completion
# rbenv
if type rbenv >/dev/null; then
eval "$(rbenv init -)"
fi
# ImageMagick
add_path_and_lib /usr/local/ImageMagick/bin
# MySQL
add_path_and_lib /usr/local/mysql/bin
# Self-contained Postgres.app
add_path /Applications/Postgres.app/Contents/MacOS/bin
# MongoDB
add_path /usr/local/mongodb/bin
-# Amazon EC2 CLI tools (official locations)
-export EC2_HOME=/usr/local/ec2-api-tools
-add_path "$EC2_HOME/bin" || unset EC2_HOME
-export RDS_HOME=/usr/local/rds-cli
-add_path "$RDS_HOME/bin" || unset RDS_HOME
-
-ec2region () {
+awsregion () {
if [ $# -eq 1 ]; then
- local reg=$1
- if [ "$reg" = default ]; then
- reg=$(<$EC2_ACCOUNT_DIR/default_region.txt)
- if [ $? -ne 0 ]; then
- echo "Warning: Defaulting to us-west-2 AWS region" >&2
- reg="us-west-2"
- fi
- fi
+ export AWS_DEFAULT_REGION=$1
+ ec2keypair # reset keys when switch regions
+ fi
- export EC2_REGION=$reg
- export EC2_URL="http://ec2.$EC2_REGION.amazonaws.com"
- export AWS_DEFAULT_REGION=$EC2_REGION
+ [ -t 0 ] && echo "AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION"
+}
- # My approach for ec2 is to launch with the custom "root" keypair,
- # but username may change based on AMI, so use just do ec2-user@whatevs
- export EC2_ROOT_KEY="$EC2_ACCOUNT_DIR/root-$EC2_REGION.pem"
- if [ ! -f "$EC2_ROOT_KEY" ]; then
- echo "Warning: EC2 key does not exist: $EC2_ROOT_KEY" >&2
- fi
+ec2keypair () {
+ # My approach for ec2 is to launch instances with a custom "root" keypair,
+ # but the username may change based on AMI, so then just ssh ec2-user@whatevs
+ local user="${1:-root}"
- # To override root, use ubuntu@ or ec2-user@ or whatever
- ssh_cmd="ssh -i $EC2_ROOT_KEY -o StrictHostKeyChecking=no -l root"
- alias ash=$ssh_cmd
- alias async="rsync -av -e '$ssh_cmd'"
+ if [ -z "$AWS_ACCOUNT" -o -z "$AWS_DEFAULT_REGION" ]; then
+ echo "Error: Set awsacct and awsregion before ec2keypair" >&2
+ return 1
+ fi
+ local acctdir=$(awsacctdir $AWS_ACCOUNT)
+
+ export EC2_ROOT_KEY="$acctdir/$user-$AWS_DEFAULT_REGION.pem"
+ if [ ! -f "$EC2_ROOT_KEY" ]; then
+ echo "Warning: EC2 key does not exist: $EC2_ROOT_KEY" >&2
fi
- [ -t 0 ] && echo "EC2_REGION=$EC2_REGION"
+ # To override root, use ubuntu@ or ec2-user@ or whatever
+ local ssh_cmd="ssh -i $EC2_ROOT_KEY -o StrictHostKeyChecking=no -l root"
+ alias ash=$ssh_cmd
+ alias async="rsync -av -e '$ssh_cmd'"
+}
+
+awsacctdir () {
+ echo "$HOME/.awsacct/$1"
}
-ec2acct () {
+awsacct () {
if [ $# -eq 1 ]; then
- local acctdir="$HOME/.ec2/$1"
+ local acct="$1"
+ local acctdir=$(awsacctdir $acct)
if [ ! -d $acctdir ]; then
echo "Error: No such dir $acctdir" >&2
+ unset AWS_ACCOUNT AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_DEFAULT_REGION
return 1
fi
- export EC2_ACCOUNT=$1
- export EC2_ACCOUNT_DIR=$acctdir
+ export AWS_ACCOUNT=$acct
# Newer tools and unified CLI
- export AWS_ACCESS_KEY_ID=$(<$EC2_ACCOUNT_DIR/access_key_id.txt)
- export AWS_SECRET_ACCESS_KEY=$(<$EC2_ACCOUNT_DIR/secret_access_key.txt)
+ . $acctdir/access_keys.txt
+ export AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_DEFAULT_REGION
- # Old style per-service CLI's
- export AWS_CREDENTIAL_FILE="$EC2_ACCOUNT_DIR/credential-file-path"
+ ec2keypair # reset keys when switch accounts
fi
- [ -t 0 ] && echo "EC2_ACCOUNT=$EC2_ACCOUNT"
+ [ -t 0 ] && echo "AWS_ACCOUNT=$AWS_ACCOUNT"
}
# Set default EC2 region
-if [ -d "$HOME/.ec2/default" ]; then
- what=$(readlink $HOME/.ec2/default)
- ec2acct $what
- ec2region default
+export AWS_DEFAULT_REGION="us-west-2"
+if [ -d "$HOME/.awsacct/default" ]; then
+ what=$(readlink $HOME/.awsacct/default)
+ awsacct $what
fi
# Use garnaat's unified CLI
complete -C aws_completer aws # bash tab completion
paws (){
aws "$@" | ruby -rjson -rawesome_print -e "ap JSON.parse(STDIN.read)"
}
complete -C aws_completer paws # bash tab completion
[ -f "$HOME/.git-completion.bash" ] && . "$HOME/.git-completion.bash"
# Easy unzipping
untar () {
if [ "$#" -eq 0 ]; then
echo "Usage: untar files ..." >&2
return 1
fi
for f
do
case $f in
*.zip) unzip $f;;
*.tar.gz|*.tgz) tar xzvf $f;;
*.tar.bz|*.tbz) bunzip -c $f | tar xvf -;;
*.tar.bz2|*.tbz2) bunzip2 -c $f | tar xvf -;;
*) echo "Unsupported file type: $f" >&2;;
esac
done
}
# shortcut to kill processes that tend to suck
fuck () {
local pn=
case "$1" in
chr*) pn="Google Chrome";;
cisc*) pn="Cisco AnyConnect Secure Mobility Client";;
esac
killall "$pn"
sleep 2
killall "$pn"
sleep 3
killall -9 "$pn"
}
# Postgres
if add_path /Library/PostgreSQL/9.0/bin; then
. /Library/PostgreSQL/9.0/pg_env.sh
fi
export JVA=209.40.197.81
alias jva="ssh -l janetvanarsdale $JVA"
alias rjva="ssh -l root $JVA"
# Workaround for ruby 2.0.0 rubygems issue
alias chef-solo='unset GEM_HOME GEM_PATH && \chef-solo'
alias knife='unset GEM_HOME GEM_PATH && \knife'
# Still needed for old games
if [ -d "/usr/local/oracle/10.2.0.4/client" ]; then
add_path_and_lib "$ORACLE_HOME/bin"
export ORACLE_HOME="/usr/local/oracle/10.2.0.4/client"
export TNS_ADMIN="$HOME/tnsadmin" # Directory
export NLS_LANG=".AL32UTF8"
fi
# For fucking with "go" the language
if [ -d $HOME/Workspace/go ]; then
export GOROOT=$HOME/Workspace/go
export GOOS=darwin
export GOARCH=386
export GOBIN=$HOME/bin
fi
### Added by the Heroku Toolbelt
add_path /usr/local/heroku/bin
# The next line updates PATH for the Google Cloud SDK.
. /Users/nateware/Workspace/google-cloud-sdk/path.bash.inc
# The next line enables bash completion for gcloud.
. /Users/nateware/Workspace/google-cloud-sdk/completion.bash.inc
alias gsh="ssh -i $HOME/.ssh/google_compute_engine -o StrictHostKeyChecking=no"
|
nateware/dotfiles
|
4abca086e920f56ed082fa3743ae557a44315acc
|
bash built-ins vs tons of cats
|
diff --git a/.bashrc b/.bashrc
index bb18603..0fa7a54 100644
--- a/.bashrc
+++ b/.bashrc
@@ -1,256 +1,255 @@
# ~/.bashrc
umask 022
# Add to PATH but only if it exists
add_path () {
err=0
for p
do
if [ -d $p ]; then
PATH="$p:$PATH"
else
err=1
fi
done
return $err
}
# Add to LD_LIB_PATH adjusting for platform
add_lib () {
[ -d "$1" ] || return 0
if [ "$OS" = Darwin ]; then
export DYLD_LIBRARY_PATH="$1:$DYLD_LIBRARY_PATH"
else
export LD_LIBRARY_PATH="$1:$DYLD_LIBRARY_PATH"
fi
return 0
}
# Guess
add_path_and_lib () {
if add_path "$1"; then
lib=${1%/bin}/lib
add_lib $lib
else
return 1
fi
}
# Aliases
alias ls='\ls -Gh'
alias ll='ls -al'
alias wget='curl -LO'
alias ldd='otool -L'
alias rsync='\rsync --exclude=.svn --exclude=.git --exclude=RCS'
alias vi='vim -b'
# Don't want to install rubydocs - TOO SLOW!
alias gi='gem install --no-ri --no-rdoc'
alias bi='bundle install --without=production:staging:assets'
alias bu='bundle update'
alias be='bundle exec'
alias ga='git ci -a -m'
alias gd='git pu && git push -f dev'
alias gp='git pu'
gap () {
ga "$*" && gp
}
gapd () {
gap "$*" && cap dev deploy
}
# Change to workspace directory
wd () {
if [ $# -eq 0 ]; then
pushd "$HOME/Workspace"
elif [ -d "$1" ]; then
# tab expansion
pushd "$1"
else
# wildcard
pushd "$HOME/Workspace/$1"*
fi
}
# Platform goodness
export OS=`uname`
[ "$OS" = Darwin ] && export JAVA_HOME=/Library/Java/Home
# Remember add_path unshifts, so the one you want first should be last
add_path \
/usr/local/git/bin \
/usr/local/bin \
/opt/local/sbin \
/opt/local/bin \
$HOME/sbin \
$HOME/bin
# Android tools
add_path $HOME/Workspace/adt-bundle-mac-x86_64-20130522/sdk/platform-tools
# Ruby version manager
[ -s $HOME/.rvm/scripts/rvm ] && . $HOME/.rvm/scripts/rvm
# Node version manager
[ -s $HOME/.nvm/nvm.sh ] && . $HOME/.nvm/nvm.sh
[ -f $NVM_DIR/bash_completion ] && . $NVM_DIR/bash_completion
# rbenv
#if add_path $HOME/.rbenv/bin; then
#eval "$(rbenv init -)"
#fi
# ImageMagick
add_path_and_lib /usr/local/ImageMagick/bin
# MySQL
add_path_and_lib /usr/local/mysql/bin
# Self-contained Postgres.app
add_path /Applications/Postgres.app/Contents/MacOS/bin
# MongoDB
add_path /usr/local/mongodb/bin
# Amazon EC2 CLI tools (official locations)
export EC2_HOME=/usr/local/ec2-api-tools
add_path "$EC2_HOME/bin" || unset EC2_HOME
export RDS_HOME=/usr/local/rds-cli
add_path "$RDS_HOME/bin" || unset RDS_HOME
ec2region () {
if [ $# -eq 1 ]; then
local reg=$1
if [ "$reg" = default ]; then
- reg=`cat $EC2_ACCOUNT_DIR/default_region.txt`
+ reg=$(<$EC2_ACCOUNT_DIR/default_region.txt)
if [ $? -ne 0 ]; then
echo "Warning: Defaulting to us-west-2 AWS region" >&2
reg="us-west-2"
fi
fi
export EC2_REGION=$reg
export EC2_URL="http://ec2.$EC2_REGION.amazonaws.com"
export AWS_DEFAULT_REGION=$EC2_REGION
# My approach for ec2 is to launch with the custom "root" keypair,
# but username may change based on AMI, so use just do ec2-user@whatevs
export EC2_ROOT_KEY="$EC2_ACCOUNT_DIR/root-$EC2_REGION.pem"
if [ ! -f "$EC2_ROOT_KEY" ]; then
echo "Warning: EC2 key does not exist: $EC2_ROOT_KEY" >&2
fi
# To override root, use ubuntu@ or ec2-user@ or whatever
ssh_cmd="ssh -i $EC2_ROOT_KEY -o StrictHostKeyChecking=no -l root"
alias ash=$ssh_cmd
alias async="rsync -av -e '$ssh_cmd'"
fi
- tty -s && echo "EC2_REGION=$EC2_REGION"
+ [ -t 0 ] && echo "EC2_REGION=$EC2_REGION"
}
ec2acct () {
if [ $# -eq 1 ]; then
local acctdir="$HOME/.ec2/$1"
if [ ! -d $acctdir ]; then
echo "Error: No such dir $acctdir" >&2
return 1
fi
export EC2_ACCOUNT=$1
export EC2_ACCOUNT_DIR=$acctdir
# Newer tools and unified CLI
- export AWS_ACCESS_KEY_ID=`cat $EC2_ACCOUNT_DIR/access_key_id.txt 2>/dev/null`
- export AWS_SECRET_ACCESS_KEY=`cat $EC2_ACCOUNT_DIR/secret_access_key.txt 2>/dev/null`
-
- export EC2_CERT=`ls -1 $EC2_ACCOUNT_DIR/cert-* 2>/dev/null | head -1`
- export EC2_PRIVATE_KEY=`echo $EC2_CERT | sed 's/cert-\(.*\).pem/pk-\1.pem/'`
+ export AWS_ACCESS_KEY_ID=$(<$EC2_ACCOUNT_DIR/access_key_id.txt)
+ export AWS_SECRET_ACCESS_KEY=$(<$EC2_ACCOUNT_DIR/secret_access_key.txt)
# Old style per-service CLI's
export AWS_CREDENTIAL_FILE="$EC2_ACCOUNT_DIR/credential-file-path"
fi
- tty -s && echo "EC2_ACCOUNT=$EC2_ACCOUNT"
+ [ -t 0 ] && echo "EC2_ACCOUNT=$EC2_ACCOUNT"
}
# Set default EC2 region
if [ -d "$HOME/.ec2/default" ]; then
- what=`readlink $HOME/.ec2/default`
+ what=$(readlink $HOME/.ec2/default)
ec2acct $what
ec2region default
fi
# Use garnaat's unified CLI
complete -C aws_completer aws # bash tab completion
paws (){
aws "$@" | ruby -rjson -rawesome_print -e "ap JSON.parse(STDIN.read)"
}
complete -C aws_completer paws # bash tab completion
[ -f "$HOME/.git-completion.bash" ] && . "$HOME/.git-completion.bash"
# Easy unzipping
untar () {
if [ "$#" -eq 0 ]; then
echo "Usage: untar files ..." >&2
return 1
fi
for f
do
case $f in
*.zip) unzip $f;;
*.tar.gz|*.tgz) tar xzvf $f;;
*.tar.bz|*.tbz) bunzip -c $f | tar xvf -;;
*.tar.bz2|*.tbz2) bunzip2 -c $f | tar xvf -;;
*) echo "Unsupported file type: $f" >&2;;
esac
done
}
# shortcut to kill processes that tend to suck
fuck () {
local pn=
case "$1" in
chr*) pn="Google Chrome";;
cisc*) pn="Cisco AnyConnect Secure Mobility Client";;
esac
killall "$pn"
sleep 2
killall "$pn"
sleep 3
killall -9 "$pn"
}
# Postgres
if add_path /Library/PostgreSQL/9.0/bin; then
. /Library/PostgreSQL/9.0/pg_env.sh
fi
export JVA=209.40.197.81
alias jva="ssh -l janetvanarsdale $JVA"
alias rjva="ssh -l root $JVA"
# Workaround for ruby 2.0.0 rubygems issue
alias chef-solo='unset GEM_HOME GEM_PATH && \chef-solo'
alias knife='unset GEM_HOME GEM_PATH && \knife'
# Still needed for old games
-export ORACLE_HOME="/usr/local/oracle/10.2.0.4/client"
-if [ -d "$ORACLE_HOME" ]; then
+if [ -d "/usr/local/oracle/10.2.0.4/client" ]; then
add_path_and_lib "$ORACLE_HOME/bin"
+ export ORACLE_HOME="/usr/local/oracle/10.2.0.4/client"
export TNS_ADMIN="$HOME/tnsadmin" # Directory
export NLS_LANG=".AL32UTF8"
fi
# For fucking with "go" the language
-export GOROOT=$HOME/Workspace/go
-export GOOS=darwin
-export GOARCH=386
-export GOBIN=$HOME/bin
+if [ -d $HOME/Workspace/go ]; then
+ export GOROOT=$HOME/Workspace/go
+ export GOOS=darwin
+ export GOARCH=386
+ export GOBIN=$HOME/bin
+fi
### Added by the Heroku Toolbelt
add_path /usr/local/heroku/bin
diff --git a/.vimrc b/.vimrc
index 6cb9824..85273e4 100644
--- a/.vimrc
+++ b/.vimrc
@@ -1,15 +1,16 @@
" mkdir -p ~/.vim/autoload ~/.vim/bundle
" curl -so ~/.vim/autoload/pathogen.vim https://raw.github.com/tpope/vim-pathogen/HEAD/autoload/pathogen.vim
+" cd ~/.vim/bundle
" git clone git://github.com/tpope/vim-fugitive.git
" git clone git://github.com/tpope/vim-rails.git
" git clone git://github.com/tpope/vim-rake.git
" git clone git://github.com/tpope/vim-surround.git
" git clone git://github.com/tpope/vim-repeat.git
" git clone git://github.com/tpope/vim-commentary.git
"
set nocp
set tabstop=2 shiftwidth=2 expandtab
call pathogen#infect()
syntax on
filetype plugin indent on
colorscheme slate
diff --git a/IR_Nateware.terminal b/IR_Nateware.terminal
index fc0f822..7a27089 100644
--- a/IR_Nateware.terminal
+++ b/IR_Nateware.terminal
@@ -1,438 +1,438 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ANSIBlackColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPECcw
LjMwNTg4MjM1MjkgMC4zMDU4ODIzNTI5IDAuMzA1ODgyMzUyOQAQAoAC0hAREhNaJGNs
YXNzbmFtZVgkY2xhc3Nlc1dOU0NvbG9yohIUWE5TT2JqZWN0XxAPTlNLZXllZEFyY2hp
dmVy0RcYVHJvb3SAAQgRGiMtMjc7QUhOW2KMjpCVoKmxtL3P0tcAAAAAAAABAQAAAAAA
AAAZAAAAAAAAAAAAAAAAAAAA2Q==
</data>
<key>ANSIBlueColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPECcw
LjU4ODIzNTI5NDEgMC43OTYwNzg0MzE0IDAuOTk2MDc4NDMxNAAQAoAC0hAREhNaJGNs
YXNzbmFtZVgkY2xhc3Nlc1dOU0NvbG9yohIUWE5TT2JqZWN0XxAPTlNLZXllZEFyY2hp
dmVy0RcYVHJvb3SAAQgRGiMtMjc7QUhOW2KMjpCVoKmxtL3P0tcAAAAAAAABAQAAAAAA
AAAZAAAAAAAAAAAAAAAAAAAA2Q==
</data>
<key>ANSIBrightBlackColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPECcw
LjQ4NjI3NDUwOTggMC40ODYyNzQ1MDk4IDAuNDg2Mjc0NTA5OAAQAoAC0hAREhNaJGNs
YXNzbmFtZVgkY2xhc3Nlc1dOU0NvbG9yohIUWE5TT2JqZWN0XxAPTlNLZXllZEFyY2hp
dmVy0RcYVHJvb3SAAQgRGiMtMjc7QUhOW2KMjpCVoKmxtL3P0tcAAAAAAAABAQAAAAAA
AAAZAAAAAAAAAAAAAAAAAAAA2Q==
</data>
<key>ANSIBrightBlueColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPECYw
LjcwOTgwMzkyMTYgMC44NjI3NDUwOTggMC45OTYwNzg0MzE0ABACgALSEBESE1okY2xh
c3NuYW1lWCRjbGFzc2VzV05TQ29sb3KiEhRYTlNPYmplY3RfEA9OU0tleWVkQXJjaGl2
ZXLRFxhUcm9vdIABCBEaIy0yNztBSE5bYouNj5SfqLCzvM7R1gAAAAAAAAEBAAAAAAAA
ABkAAAAAAAAAAAAAAAAAAADY
</data>
<key>ANSIBrightCyanColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPECcw
Ljg3NDUwOTgwMzkgMC44NzQ1MDk4MDM5IDAuOTk2MDc4NDMxNAAQAoAC0hAREhNaJGNs
YXNzbmFtZVgkY2xhc3Nlc1dOU0NvbG9yohIUWE5TT2JqZWN0XxAPTlNLZXllZEFyY2hp
dmVy0RcYVHJvb3SAAQgRGiMtMjc7QUhOW2KMjpCVoKmxtL3P0tcAAAAAAAABAQAAAAAA
AAAZAAAAAAAAAAAAAAAAAAAA2Q==
</data>
<key>ANSIBrightGreenColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPEBww
LjgwNzg0MzEzNzMgMSAwLjY3NDUwOTgwMzkAEAKAAtIQERITWiRjbGFzc25hbWVYJGNs
YXNzZXNXTlNDb2xvcqISFFhOU09iamVjdF8QD05TS2V5ZWRBcmNoaXZlctEXGFRyb290
gAEIERojLTI3O0FITltigYOFipWepqmyxMfMAAAAAAAAAQEAAAAAAAAAGQAAAAAAAAAA
AAAAAAAAAM4=
</data>
<key>ANSIBrightMagentaColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPEBwx
IDAuNjExNzY0NzA1OSAwLjk5NjA3ODQzMTQAEAKAAtIQERITWiRjbGFzc25hbWVYJGNs
YXNzZXNXTlNDb2xvcqISFFhOU09iamVjdF8QD05TS2V5ZWRBcmNoaXZlctEXGFRyb290
gAEIERojLTI3O0FITltigYOFipWepqmyxMfMAAAAAAAAAQEAAAAAAAAAGQAAAAAAAAAA
AAAAAAAAAM4=
</data>
<key>ANSIBrightRedColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPEBwx
IDAuNzEzNzI1NDkwMiAwLjY5MDE5NjA3ODQAEAKAAtIQERITWiRjbGFzc25hbWVYJGNs
YXNzZXNXTlNDb2xvcqISFFhOU09iamVjdF8QD05TS2V5ZWRBcmNoaXZlctEXGFRyb290
gAEIERojLTI3O0FITltigYOFipWepqmyxMfMAAAAAAAAAQEAAAAAAAAAGQAAAAAAAAAA
AAAAAAAAAM4=
</data>
<key>ANSIBrightWhiteColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NGMSAx
IDEAEAKAAtIQERITWiRjbGFzc25hbWVYJGNsYXNzZXNXTlNDb2xvcqISFFhOU09iamVj
dF8QD05TS2V5ZWRBcmNoaXZlctEXGFRyb290gAEIERojLTI3O0FITltiaWttcn2GjpGa
rK+0AAAAAAAAAQEAAAAAAAAAGQAAAAAAAAAAAAAAAAAAALY=
</data>
<key>ANSIBrightYellowColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPEBEx
IDEgMC43OTYwNzg0MzE0ABACgALSEBESE1okY2xhc3NuYW1lWCRjbGFzc2VzV05TQ29s
b3KiEhRYTlNPYmplY3RfEA9OU0tleWVkQXJjaGl2ZXLRFxhUcm9vdIABCBEaIy0yNztB
SE5bYnZ4en+Kk5uep7m8wQAAAAAAAAEBAAAAAAAAABkAAAAAAAAAAAAAAAAAAADD
</data>
<key>ANSICyanColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPECcw
Ljc3NjQ3MDU4ODIgMC43NzI1NDkwMTk2IDAuOTk2MDc4NDMxNAAQAoAC0hAREhNaJGNs
YXNzbmFtZVgkY2xhc3Nlc1dOU0NvbG9yohIUWE5TT2JqZWN0XxAPTlNLZXllZEFyY2hp
dmVy0RcYVHJvb3SAAQgRGiMtMjc7QUhOW2KMjpCVoKmxtL3P0tcAAAAAAAABAQAAAAAA
AAAZAAAAAAAAAAAAAAAAAAAA2Q==
</data>
<key>ANSIGreenColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPEBww
LjY1ODgyMzUyOTQgMSAwLjM3NjQ3MDU4ODIAEAKAAtIQERITWiRjbGFzc25hbWVYJGNs
YXNzZXNXTlNDb2xvcqISFFhOU09iamVjdF8QD05TS2V5ZWRBcmNoaXZlctEXGFRyb290
gAEIERojLTI3O0FITltigYOFipWepqmyxMfMAAAAAAAAAQEAAAAAAAAAGQAAAAAAAAAA
AAAAAAAAAM4=
</data>
<key>ANSIMagentaColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPEBwx
IDAuNDUwOTgwMzkyMiAwLjk5MjE1Njg2MjcAEAKAAtIQERITWiRjbGFzc25hbWVYJGNs
YXNzZXNXTlNDb2xvcqISFFhOU09iamVjdF8QD05TS2V5ZWRBcmNoaXZlctEXGFRyb290
gAEIERojLTI3O0FITltigYOFipWepqmyxMfMAAAAAAAAAQEAAAAAAAAAGQAAAAAAAAAA
AAAAAAAAAM4=
</data>
<key>ANSIRedColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPEBwx
IDAuNDIzNTI5NDExOCAwLjM3NjQ3MDU4ODIAEAKAAtIQERITWiRjbGFzc25hbWVYJGNs
YXNzZXNXTlNDb2xvcqISFFhOU09iamVjdF8QD05TS2V5ZWRBcmNoaXZlctEXGFRyb290
gAEIERojLTI3O0FITltigYOFipWepqmyxMfMAAAAAAAAAQEAAAAAAAAAGQAAAAAAAAAA
AAAAAAAAAM4=
</data>
<key>ANSIWhiteColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPECcw
LjkzMzMzMzMzMzMgMC45MzMzMzMzMzMzIDAuOTMzMzMzMzMzMwAQAoAC0hAREhNaJGNs
YXNzbmFtZVgkY2xhc3Nlc1dOU0NvbG9yohIUWE5TT2JqZWN0XxAPTlNLZXllZEFyY2hp
dmVy0RcYVHJvb3SAAQgRGiMtMjc7QUhOW2KMjpCVoKmxtL3P0tcAAAAAAAABAQAAAAAA
AAAZAAAAAAAAAAAAAAAAAAAA2Q==
</data>
<key>ANSIYellowColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPEBEx
IDEgMC43MTM3MjU0OTAyABACgALSEBESE1okY2xhc3NuYW1lWCRjbGFzc2VzV05TQ29s
b3KiEhRYTlNPYmplY3RfEA9OU0tleWVkQXJjaGl2ZXLRFxhUcm9vdIABCBEaIy0yNztB
SE5bYnZ4en+Kk5uep7m8wQAAAAAAAAEBAAAAAAAAABkAAAAAAAAAAAAAAAAAAADD
</data>
<key>BackgroundColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NGMCAw
IDAAEAGAAtIQERITWiRjbGFzc25hbWVYJGNsYXNzZXNXTlNDb2xvcqISFFhOU09iamVj
dF8QD05TS2V5ZWRBcmNoaXZlctEXGFRyb290gAEIERojLTI3O0FITltiaWttcn2GjpGa
rK+0AAAAAAAAAQEAAAAAAAAAGQAAAAAAAAAAAAAAAAAAALY=
</data>
<key>Bell</key>
<true/>
<key>CursorBlink</key>
<true/>
<key>CursorColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPECcw
- Ljk1MzE0NjIyOTYgMC42MDg3Mzc5OTk1IDAuMzUzMTMyNDk4MgAQAYAC0hAREhNaJGNs
+ Ljk0NzQxNDIzMjMgMC40ODYzODM2MTIyIDAuMTUxODA3NTAwOQAQAYAC0hAREhNaJGNs
YXNzbmFtZVgkY2xhc3Nlc1dOU0NvbG9yohIUWE5TT2JqZWN0XxAPTlNLZXllZEFyY2hp
dmVy0RcYVHJvb3SAAQgRGiMtMjc7QUhOW2KMjpCVoKmxtL3P0tcAAAAAAAABAQAAAAAA
AAAZAAAAAAAAAAAAAAAAAAAA2Q==
</data>
<key>CursorType</key>
<integer>1</integer>
<key>DisableANSIColor</key>
<false/>
<key>EscapeNonASCIICharacters</key>
<true/>
<key>Font</key>
<data>
YnBsaXN0MDDUAQIDBAUGGBlYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKQHCBESVSRudWxs1AkKCwwNDg8QVk5TU2l6ZVhOU2ZGbGFnc1ZOU05hbWVWJGNs
YXNzI0AoAAAAAAAAEBCAAoADVk1vbmFjb9ITFBUWWiRjbGFzc25hbWVYJGNsYXNzZXNW
TlNGb250ohUXWE5TT2JqZWN0XxAPTlNLZXllZEFyY2hpdmVy0RobVHJvb3SAAQgRGiMt
Mjc8QktSW2JpcnR2eH+Ej5ifoqu9wMUAAAAAAAABAQAAAAAAAAAcAAAAAAAAAAAAAAAA
AAAAxw==
</data>
<key>FontAntialias</key>
<true/>
<key>Linewrap</key>
<true/>
<key>ProfileCurrentVersion</key>
<real>2.02</real>
<key>SelectionColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
- AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPECcw
- Ljk3MjI3NzU4MjkgMC40ODcxODc0MzIgMC4wOTQxNjE2NjAyMwAQAYAC0hAREhNaJGNs
- YXNzbmFtZVgkY2xhc3Nlc1dOU0NvbG9yohIUWE5TT2JqZWN0XxAPTlNLZXllZEFyY2hp
- dmVy0RcYVHJvb3SAAQgRGiMtMjc7QUhOW2KMjpCVoKmxtL3P0tcAAAAAAAABAQAAAAAA
- AAAZAAAAAAAAAAAAAAAAAAAA2Q==
+ AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPECgw
+ LjkxOTI2Mzc1NjggMC4zOTExNTAzNzIyIDAuMDM1MDMxNTM2NTQAEAGAAtIQERITWiRj
+ bGFzc25hbWVYJGNsYXNzZXNXTlNDb2xvcqISFFhOU09iamVjdF8QD05TS2V5ZWRBcmNo
+ aXZlctEXGFRyb290gAEIERojLTI3O0FITltijY+RlqGqsrW+0NPYAAAAAAAAAQEAAAAA
+ AAAAGQAAAAAAAAAAAAAAAAAAANo=
</data>
<key>ShouldLimitScrollback</key>
<integer>0</integer>
<key>ShowActiveProcessInTitle</key>
<true/>
<key>ShowCommandKeyInTitle</key>
<false/>
<key>ShowDimensionsInTitle</key>
<false/>
<key>ShowShellCommandInTitle</key>
<false/>
<key>ShowTTYNameInTitle</key>
<false/>
<key>ShowWindowSettingsNameInTitle</key>
<false/>
<key>TerminalType</key>
<string>xterm-256color</string>
<key>TextBoldColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OV05TV2hpdGVcTlNDb2xvclNwYWNlViRjbGFzc0Ix
ABADgALSEBESE1okY2xhc3NuYW1lWCRjbGFzc2VzV05TQ29sb3KiEhRYTlNPYmplY3Rf
EA9OU0tleWVkQXJjaGl2ZXLRFxhUcm9vdIABCBEaIy0yNztBSFBdZGdpa3B7hIyPmKqt
sgAAAAAAAAEBAAAAAAAAABkAAAAAAAAAAAAAAAAAAAC0
</data>
<key>TextColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPECcw
LjkzMzMzMzMzMzMgMC45MzMzMzMzMzMzIDAuOTMzMzMzMzMzMwAQAoAC0hAREhNaJGNs
YXNzbmFtZVgkY2xhc3Nlc1dOU0NvbG9yohIUWE5TT2JqZWN0XxAPTlNLZXllZEFyY2hp
dmVy0RcYVHJvb3SAAQgRGiMtMjc7QUhOW2KMjpCVoKmxtL3P0tcAAAAAAAABAQAAAAAA
AAAZAAAAAAAAAAAAAAAAAAAA2Q==
</data>
<key>UseBoldFonts</key>
<true/>
<key>UseBrightBold</key>
<false/>
<key>VisualBell</key>
<false/>
<key>blackColour</key>
<data>
BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
ZmZmg5+cnj6Dn5yePoOfnJ4+AYY=
</data>
<key>blueColour</key>
<data>
BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
ZmZmg5eWFj+DzMtLP4P//n4/AYY=
</data>
<key>brightBlackColour</key>
<data>
BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
ZmZmg/n4+D6D+fj4PoP5+Pg+AYY=
</data>
<key>brightBlueColour</key>
<data>
BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
ZmZmg7YuNj+D3d5cP4MAjn8/AYY=
</data>
<key>brightCyanColour</key>
<data>
BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
ZmZmg+A7YD+D4FVgP4P/PX8/AYY=
</data>
<key>brightGreenColour</key>
<data>
BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
ZmZmg881Tz8Bg6w6LD8Bhg==
</data>
<key>brightMagentaColour</key>
<data>
BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
ZmZmAYOdAR0/g/8bfz8Bhg==
</data>
<key>brightRedColour</key>
<data>
BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
ZmZmAYO3tjY/g7GwMD8Bhg==
</data>
<key>brightWhiteColour</key>
<data>
BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
ZmZmAQEBAYY=
</data>
<key>brightYellowColour</key>
<data>
BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
ZmZmAQGDzbVMPwGG
</data>
<key>columnCount</key>
<integer>90</integer>
<key>cyanColour</key>
<data>
BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
ZmZmg8fGRj+DxsVFP4P//n4/AYY=
</data>
<key>greenColour</key>
<data>
BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
ZmZmg6moKD8Bg8HAwD4Bhg==
</data>
<key>keyMapBoundKeys</key>
<dict>
<key>$F708</key>
<string>[25~</string>
<key>$F709</key>
<string>[26~</string>
<key>$F70A</key>
<string>[28~</string>
<key>$F70B</key>
<string>[29~</string>
<key>$F70C</key>
<string>[31~</string>
<key>$F70D</key>
<string>[22~</string>
<key>$F70E</key>
<string>[33~</string>
<key>$F70F</key>
<string>[34~</string>
<key>$F729</key>
<string>[H</string>
<key>$F72B</key>
<string>[F</string>
<key>$F72C</key>
<string>[5~</string>
<key>$F72D</key>
<string>[6~</string>
<key>F704</key>
<string>OP</string>
<key>F705</key>
<string>OQ</string>
<key>F706</key>
<string>OR</string>
<key>F707</key>
<string>OS</string>
<key>F708</key>
<string>[15~</string>
<key>F709</key>
<string>[17~</string>
<key>F70A</key>
<string>[18~</string>
<key>F70B</key>
<string>[19~</string>
<key>F70C</key>
<string>[20~</string>
<key>F70D</key>
<string>[21~</string>
<key>F70E</key>
<string>[23~</string>
<key>F70F</key>
<string>[24~</string>
<key>F710</key>
<string>[25~</string>
<key>F711</key>
<string>[26~</string>
<key>F712</key>
<string>[28~</string>
<key>F713</key>
<string>[29~</string>
<key>F714</key>
<string>[31~</string>
<key>F715</key>
<string>[32~</string>
<key>F716</key>
<string>[33~</string>
<key>F717</key>
<string>[34~</string>
<key>F728</key>
<string>[3~</string>
<key>F729</key>
<string>[H</string>
<key>F72B</key>
<string>[F</string>
<key>F72C</key>
<string>scrollPageUp:</string>
<key>F72D</key>
<string>scrollPageDown:</string>
<key>^F702</key>
<string>[5D</string>
<key>^F703</key>
<string>[5C</string>
<key>~F704</key>
<string>[17~</string>
<key>~F705</key>
<string>[18~</string>
<key>~F706</key>
<string>[19~</string>
<key>~F707</key>
<string>[20~</string>
<key>~F708</key>
<string>[21~</string>
<key>~F709</key>
<string>[23~</string>
<key>~F70A</key>
<string>[24~</string>
<key>~F70B</key>
<string>[25~</string>
<key>~F70C</key>
<string>[26~</string>
<key>~F70D</key>
<string>[28~</string>
<key>~F70E</key>
<string>[29~</string>
<key>~F70F</key>
<string>[31~</string>
<key>~F710</key>
<string>[32~</string>
<key>~F711</key>
<string>[33~</string>
<key>~F712</key>
<string>[34~</string>
</dict>
<key>magentaColour</key>
<data>
BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
ZmZmAYPn5uY+g/79fT8Bhg==
</data>
<key>name</key>
<string>IR_Nateware</string>
<key>redColour</key>
<data>
BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
ZmZmAYPZ2Ng+g8HAwD4Bhg==
</data>
<key>rowCount</key>
<integer>40</integer>
<key>shellExitAction</key>
<integer>1</integer>
<key>type</key>
<string>Window Settings</string>
<key>whiteColour</key>
<data>
BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
ZmZmg+/7bj+D7/tuP4Pv+24/AYY=
</data>
<key>yellowColour</key>
<data>
BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
ZmZmAQGDt7Y2PwGG
</data>
</dict>
</plist>
|
nateware/dotfiles
|
058c64ba5ab09bbef7cc08f55774c57fe36f13ec
|
sublime and terminal
|
diff --git a/IR_Nateware.terminal b/IR_Nateware.terminal
index 4735613..fc0f822 100644
--- a/IR_Nateware.terminal
+++ b/IR_Nateware.terminal
@@ -1,438 +1,438 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ANSIBlackColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPECcw
LjMwNTg4MjM1MjkgMC4zMDU4ODIzNTI5IDAuMzA1ODgyMzUyOQAQAoAC0hAREhNaJGNs
YXNzbmFtZVgkY2xhc3Nlc1dOU0NvbG9yohIUWE5TT2JqZWN0XxAPTlNLZXllZEFyY2hp
dmVy0RcYVHJvb3SAAQgRGiMtMjc7QUhOW2KMjpCVoKmxtL3P0tcAAAAAAAABAQAAAAAA
AAAZAAAAAAAAAAAAAAAAAAAA2Q==
</data>
<key>ANSIBlueColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPECcw
LjU4ODIzNTI5NDEgMC43OTYwNzg0MzE0IDAuOTk2MDc4NDMxNAAQAoAC0hAREhNaJGNs
YXNzbmFtZVgkY2xhc3Nlc1dOU0NvbG9yohIUWE5TT2JqZWN0XxAPTlNLZXllZEFyY2hp
dmVy0RcYVHJvb3SAAQgRGiMtMjc7QUhOW2KMjpCVoKmxtL3P0tcAAAAAAAABAQAAAAAA
AAAZAAAAAAAAAAAAAAAAAAAA2Q==
</data>
<key>ANSIBrightBlackColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPECcw
LjQ4NjI3NDUwOTggMC40ODYyNzQ1MDk4IDAuNDg2Mjc0NTA5OAAQAoAC0hAREhNaJGNs
YXNzbmFtZVgkY2xhc3Nlc1dOU0NvbG9yohIUWE5TT2JqZWN0XxAPTlNLZXllZEFyY2hp
dmVy0RcYVHJvb3SAAQgRGiMtMjc7QUhOW2KMjpCVoKmxtL3P0tcAAAAAAAABAQAAAAAA
AAAZAAAAAAAAAAAAAAAAAAAA2Q==
</data>
<key>ANSIBrightBlueColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPECYw
LjcwOTgwMzkyMTYgMC44NjI3NDUwOTggMC45OTYwNzg0MzE0ABACgALSEBESE1okY2xh
c3NuYW1lWCRjbGFzc2VzV05TQ29sb3KiEhRYTlNPYmplY3RfEA9OU0tleWVkQXJjaGl2
ZXLRFxhUcm9vdIABCBEaIy0yNztBSE5bYouNj5SfqLCzvM7R1gAAAAAAAAEBAAAAAAAA
ABkAAAAAAAAAAAAAAAAAAADY
</data>
<key>ANSIBrightCyanColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPECcw
Ljg3NDUwOTgwMzkgMC44NzQ1MDk4MDM5IDAuOTk2MDc4NDMxNAAQAoAC0hAREhNaJGNs
YXNzbmFtZVgkY2xhc3Nlc1dOU0NvbG9yohIUWE5TT2JqZWN0XxAPTlNLZXllZEFyY2hp
dmVy0RcYVHJvb3SAAQgRGiMtMjc7QUhOW2KMjpCVoKmxtL3P0tcAAAAAAAABAQAAAAAA
AAAZAAAAAAAAAAAAAAAAAAAA2Q==
</data>
<key>ANSIBrightGreenColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPEBww
LjgwNzg0MzEzNzMgMSAwLjY3NDUwOTgwMzkAEAKAAtIQERITWiRjbGFzc25hbWVYJGNs
YXNzZXNXTlNDb2xvcqISFFhOU09iamVjdF8QD05TS2V5ZWRBcmNoaXZlctEXGFRyb290
gAEIERojLTI3O0FITltigYOFipWepqmyxMfMAAAAAAAAAQEAAAAAAAAAGQAAAAAAAAAA
AAAAAAAAAM4=
</data>
<key>ANSIBrightMagentaColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPEBwx
IDAuNjExNzY0NzA1OSAwLjk5NjA3ODQzMTQAEAKAAtIQERITWiRjbGFzc25hbWVYJGNs
YXNzZXNXTlNDb2xvcqISFFhOU09iamVjdF8QD05TS2V5ZWRBcmNoaXZlctEXGFRyb290
gAEIERojLTI3O0FITltigYOFipWepqmyxMfMAAAAAAAAAQEAAAAAAAAAGQAAAAAAAAAA
AAAAAAAAAM4=
</data>
<key>ANSIBrightRedColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPEBwx
IDAuNzEzNzI1NDkwMiAwLjY5MDE5NjA3ODQAEAKAAtIQERITWiRjbGFzc25hbWVYJGNs
YXNzZXNXTlNDb2xvcqISFFhOU09iamVjdF8QD05TS2V5ZWRBcmNoaXZlctEXGFRyb290
gAEIERojLTI3O0FITltigYOFipWepqmyxMfMAAAAAAAAAQEAAAAAAAAAGQAAAAAAAAAA
AAAAAAAAAM4=
</data>
<key>ANSIBrightWhiteColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NGMSAx
IDEAEAKAAtIQERITWiRjbGFzc25hbWVYJGNsYXNzZXNXTlNDb2xvcqISFFhOU09iamVj
dF8QD05TS2V5ZWRBcmNoaXZlctEXGFRyb290gAEIERojLTI3O0FITltiaWttcn2GjpGa
rK+0AAAAAAAAAQEAAAAAAAAAGQAAAAAAAAAAAAAAAAAAALY=
</data>
<key>ANSIBrightYellowColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPEBEx
IDEgMC43OTYwNzg0MzE0ABACgALSEBESE1okY2xhc3NuYW1lWCRjbGFzc2VzV05TQ29s
b3KiEhRYTlNPYmplY3RfEA9OU0tleWVkQXJjaGl2ZXLRFxhUcm9vdIABCBEaIy0yNztB
SE5bYnZ4en+Kk5uep7m8wQAAAAAAAAEBAAAAAAAAABkAAAAAAAAAAAAAAAAAAADD
</data>
<key>ANSICyanColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPECcw
Ljc3NjQ3MDU4ODIgMC43NzI1NDkwMTk2IDAuOTk2MDc4NDMxNAAQAoAC0hAREhNaJGNs
YXNzbmFtZVgkY2xhc3Nlc1dOU0NvbG9yohIUWE5TT2JqZWN0XxAPTlNLZXllZEFyY2hp
dmVy0RcYVHJvb3SAAQgRGiMtMjc7QUhOW2KMjpCVoKmxtL3P0tcAAAAAAAABAQAAAAAA
AAAZAAAAAAAAAAAAAAAAAAAA2Q==
</data>
<key>ANSIGreenColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPEBww
LjY1ODgyMzUyOTQgMSAwLjM3NjQ3MDU4ODIAEAKAAtIQERITWiRjbGFzc25hbWVYJGNs
YXNzZXNXTlNDb2xvcqISFFhOU09iamVjdF8QD05TS2V5ZWRBcmNoaXZlctEXGFRyb290
gAEIERojLTI3O0FITltigYOFipWepqmyxMfMAAAAAAAAAQEAAAAAAAAAGQAAAAAAAAAA
AAAAAAAAAM4=
</data>
<key>ANSIMagentaColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPEBwx
IDAuNDUwOTgwMzkyMiAwLjk5MjE1Njg2MjcAEAKAAtIQERITWiRjbGFzc25hbWVYJGNs
YXNzZXNXTlNDb2xvcqISFFhOU09iamVjdF8QD05TS2V5ZWRBcmNoaXZlctEXGFRyb290
gAEIERojLTI3O0FITltigYOFipWepqmyxMfMAAAAAAAAAQEAAAAAAAAAGQAAAAAAAAAA
AAAAAAAAAM4=
</data>
<key>ANSIRedColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPEBwx
IDAuNDIzNTI5NDExOCAwLjM3NjQ3MDU4ODIAEAKAAtIQERITWiRjbGFzc25hbWVYJGNs
YXNzZXNXTlNDb2xvcqISFFhOU09iamVjdF8QD05TS2V5ZWRBcmNoaXZlctEXGFRyb290
gAEIERojLTI3O0FITltigYOFipWepqmyxMfMAAAAAAAAAQEAAAAAAAAAGQAAAAAAAAAA
AAAAAAAAAM4=
</data>
<key>ANSIWhiteColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPECcw
LjkzMzMzMzMzMzMgMC45MzMzMzMzMzMzIDAuOTMzMzMzMzMzMwAQAoAC0hAREhNaJGNs
YXNzbmFtZVgkY2xhc3Nlc1dOU0NvbG9yohIUWE5TT2JqZWN0XxAPTlNLZXllZEFyY2hp
dmVy0RcYVHJvb3SAAQgRGiMtMjc7QUhOW2KMjpCVoKmxtL3P0tcAAAAAAAABAQAAAAAA
AAAZAAAAAAAAAAAAAAAAAAAA2Q==
</data>
<key>ANSIYellowColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPEBEx
IDEgMC43MTM3MjU0OTAyABACgALSEBESE1okY2xhc3NuYW1lWCRjbGFzc2VzV05TQ29s
b3KiEhRYTlNPYmplY3RfEA9OU0tleWVkQXJjaGl2ZXLRFxhUcm9vdIABCBEaIy0yNztB
SE5bYnZ4en+Kk5uep7m8wQAAAAAAAAEBAAAAAAAAABkAAAAAAAAAAAAAAAAAAADD
</data>
<key>BackgroundColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NGMCAw
IDAAEAGAAtIQERITWiRjbGFzc25hbWVYJGNsYXNzZXNXTlNDb2xvcqISFFhOU09iamVj
dF8QD05TS2V5ZWRBcmNoaXZlctEXGFRyb290gAEIERojLTI3O0FITltiaWttcn2GjpGa
rK+0AAAAAAAAAQEAAAAAAAAAGQAAAAAAAAAAAAAAAAAAALY=
</data>
<key>Bell</key>
<true/>
<key>CursorBlink</key>
<true/>
<key>CursorColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
- AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPEBcx
- IDAuNjQ3MDU4ODQgMC4zNzY0NzA2ABABgALSEBESE1okY2xhc3NuYW1lWCRjbGFzc2Vz
- V05TQ29sb3KiEhRYTlNPYmplY3RfEA9OU0tleWVkQXJjaGl2ZXLRFxhUcm9vdIABCBEa
- Iy0yNztBSE5bYnx+gIWQmaGkrb/CxwAAAAAAAAEBAAAAAAAAABkAAAAAAAAAAAAAAAAA
- AADJ
+ AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPECcw
+ Ljk1MzE0NjIyOTYgMC42MDg3Mzc5OTk1IDAuMzUzMTMyNDk4MgAQAYAC0hAREhNaJGNs
+ YXNzbmFtZVgkY2xhc3Nlc1dOU0NvbG9yohIUWE5TT2JqZWN0XxAPTlNLZXllZEFyY2hp
+ dmVy0RcYVHJvb3SAAQgRGiMtMjc7QUhOW2KMjpCVoKmxtL3P0tcAAAAAAAABAQAAAAAA
+ AAAZAAAAAAAAAAAAAAAAAAAA2Q==
</data>
<key>CursorType</key>
<integer>1</integer>
<key>DisableANSIColor</key>
<false/>
<key>EscapeNonASCIICharacters</key>
<true/>
<key>Font</key>
<data>
YnBsaXN0MDDUAQIDBAUGGBlYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKQHCBESVSRudWxs1AkKCwwNDg8QVk5TU2l6ZVhOU2ZGbGFnc1ZOU05hbWVWJGNs
YXNzI0AoAAAAAAAAEBCAAoADVk1vbmFjb9ITFBUWWiRjbGFzc25hbWVYJGNsYXNzZXNW
TlNGb250ohUXWE5TT2JqZWN0XxAPTlNLZXllZEFyY2hpdmVy0RobVHJvb3SAAQgRGiMt
Mjc8QktSW2JpcnR2eH+Ej5ifoqu9wMUAAAAAAAABAQAAAAAAAAAcAAAAAAAAAAAAAAAA
AAAAxw==
</data>
<key>FontAntialias</key>
<true/>
<key>Linewrap</key>
<true/>
<key>ProfileCurrentVersion</key>
<real>2.02</real>
<key>SelectionColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
- AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPECYw
- LjE3MjIwMTU4NjkgMC40MDY2OTU4MjIgMC4zNTIwNjU5NzU3ABABgALSEBESE1okY2xh
- c3NuYW1lWCRjbGFzc2VzV05TQ29sb3KiEhRYTlNPYmplY3RfEA9OU0tleWVkQXJjaGl2
- ZXLRFxhUcm9vdIABCBEaIy0yNztBSE5bYouNj5SfqLCzvM7R1gAAAAAAAAEBAAAAAAAA
- ABkAAAAAAAAAAAAAAAAAAADY
+ AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPECcw
+ Ljk3MjI3NzU4MjkgMC40ODcxODc0MzIgMC4wOTQxNjE2NjAyMwAQAYAC0hAREhNaJGNs
+ YXNzbmFtZVgkY2xhc3Nlc1dOU0NvbG9yohIUWE5TT2JqZWN0XxAPTlNLZXllZEFyY2hp
+ dmVy0RcYVHJvb3SAAQgRGiMtMjc7QUhOW2KMjpCVoKmxtL3P0tcAAAAAAAABAQAAAAAA
+ AAAZAAAAAAAAAAAAAAAAAAAA2Q==
</data>
<key>ShouldLimitScrollback</key>
<integer>0</integer>
<key>ShowActiveProcessInTitle</key>
<true/>
<key>ShowCommandKeyInTitle</key>
<false/>
<key>ShowDimensionsInTitle</key>
<false/>
<key>ShowShellCommandInTitle</key>
<false/>
<key>ShowTTYNameInTitle</key>
<false/>
<key>ShowWindowSettingsNameInTitle</key>
<false/>
<key>TerminalType</key>
<string>xterm-256color</string>
<key>TextBoldColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OV05TV2hpdGVcTlNDb2xvclNwYWNlViRjbGFzc0Ix
ABADgALSEBESE1okY2xhc3NuYW1lWCRjbGFzc2VzV05TQ29sb3KiEhRYTlNPYmplY3Rf
EA9OU0tleWVkQXJjaGl2ZXLRFxhUcm9vdIABCBEaIy0yNztBSFBdZGdpa3B7hIyPmKqt
sgAAAAAAAAEBAAAAAAAAABkAAAAAAAAAAAAAAAAAAAC0
</data>
<key>TextColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPECcw
LjkzMzMzMzMzMzMgMC45MzMzMzMzMzMzIDAuOTMzMzMzMzMzMwAQAoAC0hAREhNaJGNs
YXNzbmFtZVgkY2xhc3Nlc1dOU0NvbG9yohIUWE5TT2JqZWN0XxAPTlNLZXllZEFyY2hp
dmVy0RcYVHJvb3SAAQgRGiMtMjc7QUhOW2KMjpCVoKmxtL3P0tcAAAAAAAABAQAAAAAA
AAAZAAAAAAAAAAAAAAAAAAAA2Q==
</data>
<key>UseBoldFonts</key>
<true/>
<key>UseBrightBold</key>
<false/>
<key>VisualBell</key>
<false/>
<key>blackColour</key>
<data>
BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
ZmZmg5+cnj6Dn5yePoOfnJ4+AYY=
</data>
<key>blueColour</key>
<data>
BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
ZmZmg5eWFj+DzMtLP4P//n4/AYY=
</data>
<key>brightBlackColour</key>
<data>
BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
ZmZmg/n4+D6D+fj4PoP5+Pg+AYY=
</data>
<key>brightBlueColour</key>
<data>
BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
ZmZmg7YuNj+D3d5cP4MAjn8/AYY=
</data>
<key>brightCyanColour</key>
<data>
BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
ZmZmg+A7YD+D4FVgP4P/PX8/AYY=
</data>
<key>brightGreenColour</key>
<data>
BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
ZmZmg881Tz8Bg6w6LD8Bhg==
</data>
<key>brightMagentaColour</key>
<data>
BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
ZmZmAYOdAR0/g/8bfz8Bhg==
</data>
<key>brightRedColour</key>
<data>
BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
ZmZmAYO3tjY/g7GwMD8Bhg==
</data>
<key>brightWhiteColour</key>
<data>
BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
ZmZmAQEBAYY=
</data>
<key>brightYellowColour</key>
<data>
BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
ZmZmAQGDzbVMPwGG
</data>
<key>columnCount</key>
<integer>90</integer>
<key>cyanColour</key>
<data>
BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
ZmZmg8fGRj+DxsVFP4P//n4/AYY=
</data>
<key>greenColour</key>
<data>
BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
ZmZmg6moKD8Bg8HAwD4Bhg==
</data>
<key>keyMapBoundKeys</key>
<dict>
<key>$F708</key>
<string>[25~</string>
<key>$F709</key>
<string>[26~</string>
<key>$F70A</key>
<string>[28~</string>
<key>$F70B</key>
<string>[29~</string>
<key>$F70C</key>
<string>[31~</string>
<key>$F70D</key>
<string>[22~</string>
<key>$F70E</key>
<string>[33~</string>
<key>$F70F</key>
<string>[34~</string>
<key>$F729</key>
<string>[H</string>
<key>$F72B</key>
<string>[F</string>
<key>$F72C</key>
<string>[5~</string>
<key>$F72D</key>
<string>[6~</string>
<key>F704</key>
<string>OP</string>
<key>F705</key>
<string>OQ</string>
<key>F706</key>
<string>OR</string>
<key>F707</key>
<string>OS</string>
<key>F708</key>
<string>[15~</string>
<key>F709</key>
<string>[17~</string>
<key>F70A</key>
<string>[18~</string>
<key>F70B</key>
<string>[19~</string>
<key>F70C</key>
<string>[20~</string>
<key>F70D</key>
<string>[21~</string>
<key>F70E</key>
<string>[23~</string>
<key>F70F</key>
<string>[24~</string>
<key>F710</key>
<string>[25~</string>
<key>F711</key>
<string>[26~</string>
<key>F712</key>
<string>[28~</string>
<key>F713</key>
<string>[29~</string>
<key>F714</key>
<string>[31~</string>
<key>F715</key>
<string>[32~</string>
<key>F716</key>
<string>[33~</string>
<key>F717</key>
<string>[34~</string>
<key>F728</key>
<string>[3~</string>
<key>F729</key>
<string>[H</string>
<key>F72B</key>
<string>[F</string>
<key>F72C</key>
<string>scrollPageUp:</string>
<key>F72D</key>
<string>scrollPageDown:</string>
<key>^F702</key>
<string>[5D</string>
<key>^F703</key>
<string>[5C</string>
<key>~F704</key>
<string>[17~</string>
<key>~F705</key>
<string>[18~</string>
<key>~F706</key>
<string>[19~</string>
<key>~F707</key>
<string>[20~</string>
<key>~F708</key>
<string>[21~</string>
<key>~F709</key>
<string>[23~</string>
<key>~F70A</key>
<string>[24~</string>
<key>~F70B</key>
<string>[25~</string>
<key>~F70C</key>
<string>[26~</string>
<key>~F70D</key>
<string>[28~</string>
<key>~F70E</key>
<string>[29~</string>
<key>~F70F</key>
<string>[31~</string>
<key>~F710</key>
<string>[32~</string>
<key>~F711</key>
<string>[33~</string>
<key>~F712</key>
<string>[34~</string>
</dict>
<key>magentaColour</key>
<data>
BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
ZmZmAYPn5uY+g/79fT8Bhg==
</data>
<key>name</key>
- <string>IR Nateware</string>
+ <string>IR_Nateware</string>
<key>redColour</key>
<data>
BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
ZmZmAYPZ2Ng+g8HAwD4Bhg==
</data>
<key>rowCount</key>
<integer>40</integer>
<key>shellExitAction</key>
<integer>1</integer>
<key>type</key>
<string>Window Settings</string>
<key>whiteColour</key>
<data>
BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
ZmZmg+/7bj+D7/tuP4Pv+24/AYY=
</data>
<key>yellowColour</key>
<data>
BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
ZmZmAQGDt7Y2PwGG
</data>
</dict>
</plist>
diff --git a/Sublime_User.json b/Sublime_User.json
new file mode 100644
index 0000000..ec1a9b9
--- /dev/null
+++ b/Sublime_User.json
@@ -0,0 +1,11 @@
+{
+ "color_scheme": "Packages/Color Scheme - Default/Sunburst.tmTheme",
+ "ignored_packages":
+ [
+ ],
+ "vintage_start_in_command_mode": true,
+ "auto_indent": true,
+ "detect_indentation": false,
+ "tab_size": 2,
+ "translate_tabs_to_spaces": true
+}
|
nateware/dotfiles
|
58792b8a0bf48e323b37462bef1fc6165a78a673
|
wd fix
|
diff --git a/.bashrc b/.bashrc
index e71b283..bb18603 100644
--- a/.bashrc
+++ b/.bashrc
@@ -1,252 +1,256 @@
# ~/.bashrc
umask 022
# Add to PATH but only if it exists
add_path () {
err=0
for p
do
if [ -d $p ]; then
PATH="$p:$PATH"
else
err=1
fi
done
return $err
}
# Add to LD_LIB_PATH adjusting for platform
add_lib () {
[ -d "$1" ] || return 0
if [ "$OS" = Darwin ]; then
export DYLD_LIBRARY_PATH="$1:$DYLD_LIBRARY_PATH"
else
export LD_LIBRARY_PATH="$1:$DYLD_LIBRARY_PATH"
fi
return 0
}
# Guess
add_path_and_lib () {
if add_path "$1"; then
lib=${1%/bin}/lib
add_lib $lib
else
return 1
fi
}
# Aliases
alias ls='\ls -Gh'
alias ll='ls -al'
alias wget='curl -LO'
alias ldd='otool -L'
alias rsync='\rsync --exclude=.svn --exclude=.git --exclude=RCS'
alias vi='vim -b'
# Don't want to install rubydocs - TOO SLOW!
alias gi='gem install --no-ri --no-rdoc'
alias bi='bundle install --without=production:staging:assets'
alias bu='bundle update'
alias be='bundle exec'
alias ga='git ci -a -m'
alias gd='git pu && git push -f dev'
alias gp='git pu'
gap () {
ga "$*" && gp
}
gapd () {
gap "$*" && cap dev deploy
}
# Change to workspace directory
wd () {
if [ $# -eq 0 ]; then
pushd "$HOME/Workspace"
+ elif [ -d "$1" ]; then
+ # tab expansion
+ pushd "$1"
else
+ # wildcard
pushd "$HOME/Workspace/$1"*
fi
}
# Platform goodness
export OS=`uname`
[ "$OS" = Darwin ] && export JAVA_HOME=/Library/Java/Home
# Remember add_path unshifts, so the one you want first should be last
add_path \
/usr/local/git/bin \
/usr/local/bin \
/opt/local/sbin \
/opt/local/bin \
$HOME/sbin \
$HOME/bin
# Android tools
add_path $HOME/Workspace/adt-bundle-mac-x86_64-20130522/sdk/platform-tools
# Ruby version manager
[ -s $HOME/.rvm/scripts/rvm ] && . $HOME/.rvm/scripts/rvm
# Node version manager
[ -s $HOME/.nvm/nvm.sh ] && . $HOME/.nvm/nvm.sh
[ -f $NVM_DIR/bash_completion ] && . $NVM_DIR/bash_completion
# rbenv
#if add_path $HOME/.rbenv/bin; then
#eval "$(rbenv init -)"
#fi
# ImageMagick
add_path_and_lib /usr/local/ImageMagick/bin
# MySQL
add_path_and_lib /usr/local/mysql/bin
# Self-contained Postgres.app
add_path /Applications/Postgres.app/Contents/MacOS/bin
# MongoDB
add_path /usr/local/mongodb/bin
# Amazon EC2 CLI tools (official locations)
export EC2_HOME=/usr/local/ec2-api-tools
add_path "$EC2_HOME/bin" || unset EC2_HOME
export RDS_HOME=/usr/local/rds-cli
add_path "$RDS_HOME/bin" || unset RDS_HOME
ec2region () {
if [ $# -eq 1 ]; then
local reg=$1
if [ "$reg" = default ]; then
reg=`cat $EC2_ACCOUNT_DIR/default_region.txt`
if [ $? -ne 0 ]; then
echo "Warning: Defaulting to us-west-2 AWS region" >&2
reg="us-west-2"
fi
fi
export EC2_REGION=$reg
export EC2_URL="http://ec2.$EC2_REGION.amazonaws.com"
export AWS_DEFAULT_REGION=$EC2_REGION
# My approach for ec2 is to launch with the custom "root" keypair,
# but username may change based on AMI, so use just do ec2-user@whatevs
export EC2_ROOT_KEY="$EC2_ACCOUNT_DIR/root-$EC2_REGION.pem"
if [ ! -f "$EC2_ROOT_KEY" ]; then
echo "Warning: EC2 key does not exist: $EC2_ROOT_KEY" >&2
fi
# To override root, use ubuntu@ or ec2-user@ or whatever
ssh_cmd="ssh -i $EC2_ROOT_KEY -o StrictHostKeyChecking=no -l root"
alias ash=$ssh_cmd
alias async="rsync -av -e '$ssh_cmd'"
fi
tty -s && echo "EC2_REGION=$EC2_REGION"
}
ec2acct () {
if [ $# -eq 1 ]; then
local acctdir="$HOME/.ec2/$1"
if [ ! -d $acctdir ]; then
echo "Error: No such dir $acctdir" >&2
return 1
fi
export EC2_ACCOUNT=$1
export EC2_ACCOUNT_DIR=$acctdir
# Newer tools and unified CLI
export AWS_ACCESS_KEY_ID=`cat $EC2_ACCOUNT_DIR/access_key_id.txt 2>/dev/null`
export AWS_SECRET_ACCESS_KEY=`cat $EC2_ACCOUNT_DIR/secret_access_key.txt 2>/dev/null`
export EC2_CERT=`ls -1 $EC2_ACCOUNT_DIR/cert-* 2>/dev/null | head -1`
export EC2_PRIVATE_KEY=`echo $EC2_CERT | sed 's/cert-\(.*\).pem/pk-\1.pem/'`
# Old style per-service CLI's
export AWS_CREDENTIAL_FILE="$EC2_ACCOUNT_DIR/credential-file-path"
fi
tty -s && echo "EC2_ACCOUNT=$EC2_ACCOUNT"
}
# Set default EC2 region
if [ -d "$HOME/.ec2/default" ]; then
what=`readlink $HOME/.ec2/default`
ec2acct $what
ec2region default
fi
# Use garnaat's unified CLI
complete -C aws_completer aws # bash tab completion
paws (){
aws "$@" | ruby -rjson -rawesome_print -e "ap JSON.parse(STDIN.read)"
}
complete -C aws_completer paws # bash tab completion
[ -f "$HOME/.git-completion.bash" ] && . "$HOME/.git-completion.bash"
# Easy unzipping
untar () {
if [ "$#" -eq 0 ]; then
echo "Usage: untar files ..." >&2
return 1
fi
for f
do
case $f in
*.zip) unzip $f;;
*.tar.gz|*.tgz) tar xzvf $f;;
*.tar.bz|*.tbz) bunzip -c $f | tar xvf -;;
*.tar.bz2|*.tbz2) bunzip2 -c $f | tar xvf -;;
*) echo "Unsupported file type: $f" >&2;;
esac
done
}
# shortcut to kill processes that tend to suck
fuck () {
local pn=
case "$1" in
chr*) pn="Google Chrome";;
cisc*) pn="Cisco AnyConnect Secure Mobility Client";;
esac
killall "$pn"
sleep 2
killall "$pn"
sleep 3
killall -9 "$pn"
}
# Postgres
if add_path /Library/PostgreSQL/9.0/bin; then
. /Library/PostgreSQL/9.0/pg_env.sh
fi
export JVA=209.40.197.81
alias jva="ssh -l janetvanarsdale $JVA"
alias rjva="ssh -l root $JVA"
# Workaround for ruby 2.0.0 rubygems issue
alias chef-solo='unset GEM_HOME GEM_PATH && \chef-solo'
alias knife='unset GEM_HOME GEM_PATH && \knife'
# Still needed for old games
export ORACLE_HOME="/usr/local/oracle/10.2.0.4/client"
if [ -d "$ORACLE_HOME" ]; then
add_path_and_lib "$ORACLE_HOME/bin"
export TNS_ADMIN="$HOME/tnsadmin" # Directory
export NLS_LANG=".AL32UTF8"
fi
# For fucking with "go" the language
export GOROOT=$HOME/Workspace/go
export GOOS=darwin
export GOARCH=386
export GOBIN=$HOME/bin
### Added by the Heroku Toolbelt
add_path /usr/local/heroku/bin
|
nateware/dotfiles
|
84aecab17771a714f01cba66648135a3314d0c15
|
bug-free terminal colors, ec2acct refactor for defaults, fancy PS1
|
diff --git a/.bash_profile b/.bash_profile
index afd8d1f..ffce8b5 100644
--- a/.bash_profile
+++ b/.bash_profile
@@ -1,40 +1,57 @@
# Must source manually
[ -f $HOME/.bashrc ] && . $HOME/.bashrc
-# Colors!
-c1="\033["
-c2="m"
-c_normal="${c1}0${c2}"
-c_bold="${c1}1${c2}"
-c_black="${c1}0;30${c2}"
-c_blue="${c1}0;34${c2}"
-c_green="${c1}0;32${c2}"
-c_cyan="${c1}0;36${c2}"
-c_red="${c1}0;31${c2}"
-c_purple="${c1}0;35${c2}"
-c_brown="${c1}0;33${c2}"
-c_gray="${c1}0;37${c2}"
-c_dark_gray="${c1}1;30${c2}"
-c_bold_blue="${c1}1;34${c2}"
-c_bold_green="${c1}1;32${c2}"
-c_bold_cyan="${c1}1;36${c2}"
-c_bold_red="${c1}1;31${c2}"
-c_bold_purple="${c1}1;35${c2}"
-c_bold_yellow="${c1}1;33${c2}"
-c_bold_white="${c1}1;37${c2}"
+# Old school 1986 style colors
+# c1="\033["
+# c2="m"
+# c_normal="${c1}0${c2}"
+# c_bold="${c1}1${c2}"
+# c_black="${c1}0;30${c2}"
+# c_blue="${c1}0;34${c2}"
+# c_green="${c1}0;32${c2}"
+# c_cyan="${c1}0;36${c2}"
+# c_red="${c1}0;31${c2}"
+# c_purple="${c1}0;35${c2}"
+# c_brown="${c1}0;33${c2}"
+# c_gray="${c1}0;37${c2}"
+# c_dark_gray="${c1}1;30${c2}"
+# c_bold_blue="${c1}1;34${c2}"
+# c_bold_green="${c1}1;32${c2}"
+# c_bold_cyan="${c1}1;36${c2}"
+# c_bold_red="${c1}1;31${c2}"
+# c_bold_purple="${c1}1;35${c2}"
+# c_bold_yellow="${c1}1;33${c2}"
+# c_bold_white="${c1}1;37${c2}"
+
+# http://stackoverflow.com/questions/4332478/read-the-current-text-color-in-a-xterm
+C_BLACK=$(tput setaf 0)
+C_RED=$(tput setaf 1)
+C_GREEN=$(tput setaf 2)
+C_YELLOW=$(tput setaf 3)
+C_LIME_YELLOW=$(tput setaf 190)
+C_POWDER_BLUE=$(tput setaf 153)
+C_BLUE=$(tput setaf 4)
+C_MAGENTA=$(tput setaf 5)
+C_CYAN=$(tput setaf 6)
+C_WHITE=$(tput setaf 7)
+C_BRIGHT=$(tput bold)
+C_NORMAL=$(tput sgr0)
+C_BLINK=$(tput blink)
+C_REVERSE=$(tput smso)
+C_UNDERLINE=$(tput smul)
# Prompt
-#export PS1='[\u@\h:\W]\$ '
-#export PS1="[$c_green\u$c_normal@$c_purple\h$c_normal:$c_blue\W$c_normal]\\\$ "
-export PS1='[\W]\$ '
+# The \[ \] parts are to fix bash prompt CLI issues
+# http://askubuntu.com/questions/111840/ps1-problem-messing-up-cli
+export PS1='[\[$C_BLUE\]\W\[$C_NORMAL\]]\[$C_GREEN\]\$\[$C_NORMAL\] '
-printf $c_red
+printf $C_RED
type ruby
-printf $c_normal
+printf $C_NORMAL
# Only sublime on login; vi otherwise
export EDITOR='subl -w'
[ -s $HOME/.nvm/nvm.sh ] && . $HOME/.nvm/nvm.sh # This loads NVM
diff --git a/.bashrc b/.bashrc
index 6981229..e71b283 100644
--- a/.bashrc
+++ b/.bashrc
@@ -1,246 +1,252 @@
# ~/.bashrc
umask 022
# Add to PATH but only if it exists
add_path () {
err=0
for p
do
if [ -d $p ]; then
PATH="$p:$PATH"
else
err=1
fi
done
return $err
}
# Add to LD_LIB_PATH adjusting for platform
add_lib () {
[ -d "$1" ] || return 0
if [ "$OS" = Darwin ]; then
export DYLD_LIBRARY_PATH="$1:$DYLD_LIBRARY_PATH"
else
export LD_LIBRARY_PATH="$1:$DYLD_LIBRARY_PATH"
fi
return 0
}
# Guess
add_path_and_lib () {
if add_path "$1"; then
lib=${1%/bin}/lib
add_lib $lib
else
return 1
fi
}
# Aliases
alias ls='\ls -Gh'
alias ll='ls -al'
alias wget='curl -LO'
alias ldd='otool -L'
alias rsync='\rsync --exclude=.svn --exclude=.git --exclude=RCS'
alias vi='vim -b'
# Don't want to install rubydocs - TOO SLOW!
alias gi='gem install --no-ri --no-rdoc'
-alias bi='bundle install --without=production'
+alias bi='bundle install --without=production:staging:assets'
alias bu='bundle update'
alias be='bundle exec'
alias ga='git ci -a -m'
alias gd='git pu && git push -f dev'
alias gp='git pu'
+
gap () {
ga "$*" && gp
}
gapd () {
gap "$*" && cap dev deploy
}
# Change to workspace directory
wd () {
if [ $# -eq 0 ]; then
pushd "$HOME/Workspace"
else
pushd "$HOME/Workspace/$1"*
fi
}
# Platform goodness
export OS=`uname`
[ "$OS" = Darwin ] && export JAVA_HOME=/Library/Java/Home
# Remember add_path unshifts, so the one you want first should be last
add_path \
/usr/local/git/bin \
/usr/local/bin \
/opt/local/sbin \
/opt/local/bin \
$HOME/sbin \
$HOME/bin
# Android tools
add_path $HOME/Workspace/adt-bundle-mac-x86_64-20130522/sdk/platform-tools
# Ruby version manager
[ -s $HOME/.rvm/scripts/rvm ] && . $HOME/.rvm/scripts/rvm
# Node version manager
[ -s $HOME/.nvm/nvm.sh ] && . $HOME/.nvm/nvm.sh
[ -f $NVM_DIR/bash_completion ] && . $NVM_DIR/bash_completion
# rbenv
#if add_path $HOME/.rbenv/bin; then
#eval "$(rbenv init -)"
#fi
# ImageMagick
add_path_and_lib /usr/local/ImageMagick/bin
# MySQL
add_path_and_lib /usr/local/mysql/bin
# Self-contained Postgres.app
add_path /Applications/Postgres.app/Contents/MacOS/bin
# MongoDB
add_path /usr/local/mongodb/bin
# Amazon EC2 CLI tools (official locations)
export EC2_HOME=/usr/local/ec2-api-tools
add_path "$EC2_HOME/bin" || unset EC2_HOME
export RDS_HOME=/usr/local/rds-cli
add_path "$RDS_HOME/bin" || unset RDS_HOME
ec2region () {
if [ $# -eq 1 ]; then
- export EC2_REGION=$1
+ local reg=$1
+ if [ "$reg" = default ]; then
+ reg=`cat $EC2_ACCOUNT_DIR/default_region.txt`
+ if [ $? -ne 0 ]; then
+ echo "Warning: Defaulting to us-west-2 AWS region" >&2
+ reg="us-west-2"
+ fi
+ fi
+
+ export EC2_REGION=$reg
export EC2_URL="http://ec2.$EC2_REGION.amazonaws.com"
export AWS_DEFAULT_REGION=$EC2_REGION
- ec2setenv
+
+ # My approach for ec2 is to launch with the custom "root" keypair,
+ # but username may change based on AMI, so use just do ec2-user@whatevs
+ export EC2_ROOT_KEY="$EC2_ACCOUNT_DIR/root-$EC2_REGION.pem"
+ if [ ! -f "$EC2_ROOT_KEY" ]; then
+ echo "Warning: EC2 key does not exist: $EC2_ROOT_KEY" >&2
+ fi
+
+ # To override root, use ubuntu@ or ec2-user@ or whatever
+ ssh_cmd="ssh -i $EC2_ROOT_KEY -o StrictHostKeyChecking=no -l root"
+ alias ash=$ssh_cmd
+ alias async="rsync -av -e '$ssh_cmd'"
fi
+
tty -s && echo "EC2_REGION=$EC2_REGION"
}
ec2acct () {
- if [ $# -ge 1 ]; then
- export EC2_ACCOUNT=$1
- if [ $# -eq 2 ]; then
- ec2region $2
- else
- ec2setenv
+ if [ $# -eq 1 ]; then
+ local acctdir="$HOME/.ec2/$1"
+ if [ ! -d $acctdir ]; then
+ echo "Error: No such dir $acctdir" >&2
+ return 1
fi
- fi
- tty -s && echo "EC2_ACCOUNT=$EC2_ACCOUNT"
-}
-# Amazon EC2 gems
-ec2setenv () {
- local acctdir="$HOME/.ec2/$EC2_ACCOUNT"
- if [ ! -d $acctdir ]; then
- echo "Error: No such dir $acctdir" >&2
- return 1
- fi
-
- # Newer tools and unified CLI
- export AWS_ACCESS_KEY_ID=`cat $acctdir/access_key_id.txt 2>/dev/null`
- export AWS_SECRET_ACCESS_KEY=`cat $acctdir/secret_access_key.txt 2>/dev/null`
+ export EC2_ACCOUNT=$1
+ export EC2_ACCOUNT_DIR=$acctdir
- export EC2_CERT=`ls -1 $acctdir/cert-* 2>/dev/null | head -1`
- export EC2_PRIVATE_KEY=`echo $EC2_CERT | sed 's/cert-\(.*\).pem/pk-\1.pem/'`
+ # Newer tools and unified CLI
+ export AWS_ACCESS_KEY_ID=`cat $EC2_ACCOUNT_DIR/access_key_id.txt 2>/dev/null`
+ export AWS_SECRET_ACCESS_KEY=`cat $EC2_ACCOUNT_DIR/secret_access_key.txt 2>/dev/null`
- # Old style per-service CLI's
- export AWS_CREDENTIAL_FILE="$acctdir/credential-file-path"
+ export EC2_CERT=`ls -1 $EC2_ACCOUNT_DIR/cert-* 2>/dev/null | head -1`
+ export EC2_PRIVATE_KEY=`echo $EC2_CERT | sed 's/cert-\(.*\).pem/pk-\1.pem/'`
- # My approach for ec2 is to launch with the custom "root" keypair,
- # but username may change based on AMI, so use just do ec2-user@whatevs
- export EC2_ROOT_KEY="$acctdir/root-$EC2_REGION.pem"
- if [ ! -f "$EC2_ROOT_KEY" ]; then
- echo "Warning: EC2 key does not exist: $EC2_ROOT_KEY" >&2
+ # Old style per-service CLI's
+ export AWS_CREDENTIAL_FILE="$EC2_ACCOUNT_DIR/credential-file-path"
fi
- # To override root, use ubuntu@ or ec2-user@ or whatever
- ssh_cmd="ssh -i $EC2_ROOT_KEY -o StrictHostKeyChecking=no -l root"
- alias ash=$ssh_cmd
- alias async="rsync -av -e '$ssh_cmd'"
+ tty -s && echo "EC2_ACCOUNT=$EC2_ACCOUNT"
}
# Set default EC2 region
-if [ -d "$HOME/.ec2" ]; then
- ec2acct work us-west-2
+if [ -d "$HOME/.ec2/default" ]; then
+ what=`readlink $HOME/.ec2/default`
+ ec2acct $what
+ ec2region default
fi
# Use garnaat's unified CLI
complete -C aws_completer aws # bash tab completion
paws (){
aws "$@" | ruby -rjson -rawesome_print -e "ap JSON.parse(STDIN.read)"
}
complete -C aws_completer paws # bash tab completion
[ -f "$HOME/.git-completion.bash" ] && . "$HOME/.git-completion.bash"
# Easy unzipping
untar () {
if [ "$#" -eq 0 ]; then
echo "Usage: untar files ..." >&2
return 1
fi
for f
do
case $f in
*.zip) unzip $f;;
*.tar.gz|*.tgz) tar xzvf $f;;
*.tar.bz|*.tbz) bunzip -c $f | tar xvf -;;
*.tar.bz2|*.tbz2) bunzip2 -c $f | tar xvf -;;
*) echo "Unsupported file type: $f" >&2;;
esac
done
}
# shortcut to kill processes that tend to suck
fuck () {
local pn=
case "$1" in
chr*) pn="Google Chrome";;
cisc*) pn="Cisco AnyConnect Secure Mobility Client";;
esac
killall "$pn"
sleep 2
killall "$pn"
sleep 3
killall -9 "$pn"
}
# Postgres
if add_path /Library/PostgreSQL/9.0/bin; then
. /Library/PostgreSQL/9.0/pg_env.sh
fi
export JVA=209.40.197.81
alias jva="ssh -l janetvanarsdale $JVA"
alias rjva="ssh -l root $JVA"
# Workaround for ruby 2.0.0 rubygems issue
alias chef-solo='unset GEM_HOME GEM_PATH && \chef-solo'
alias knife='unset GEM_HOME GEM_PATH && \knife'
# Still needed for old games
export ORACLE_HOME="/usr/local/oracle/10.2.0.4/client"
if [ -d "$ORACLE_HOME" ]; then
add_path_and_lib "$ORACLE_HOME/bin"
export TNS_ADMIN="$HOME/tnsadmin" # Directory
export NLS_LANG=".AL32UTF8"
fi
# For fucking with "go" the language
export GOROOT=$HOME/Workspace/go
export GOOS=darwin
export GOARCH=386
export GOBIN=$HOME/bin
### Added by the Heroku Toolbelt
add_path /usr/local/heroku/bin
|
nateware/dotfiles
|
caa8b96f3fa89f40c90b8e39c007b27c83247599
|
ruby relink and terminal settings
|
diff --git a/IR_Nateware.terminal b/IR_Nateware.terminal
new file mode 100644
index 0000000..4735613
--- /dev/null
+++ b/IR_Nateware.terminal
@@ -0,0 +1,438 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>ANSIBlackColor</key>
+ <data>
+ YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
+ AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPECcw
+ LjMwNTg4MjM1MjkgMC4zMDU4ODIzNTI5IDAuMzA1ODgyMzUyOQAQAoAC0hAREhNaJGNs
+ YXNzbmFtZVgkY2xhc3Nlc1dOU0NvbG9yohIUWE5TT2JqZWN0XxAPTlNLZXllZEFyY2hp
+ dmVy0RcYVHJvb3SAAQgRGiMtMjc7QUhOW2KMjpCVoKmxtL3P0tcAAAAAAAABAQAAAAAA
+ AAAZAAAAAAAAAAAAAAAAAAAA2Q==
+ </data>
+ <key>ANSIBlueColor</key>
+ <data>
+ YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
+ AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPECcw
+ LjU4ODIzNTI5NDEgMC43OTYwNzg0MzE0IDAuOTk2MDc4NDMxNAAQAoAC0hAREhNaJGNs
+ YXNzbmFtZVgkY2xhc3Nlc1dOU0NvbG9yohIUWE5TT2JqZWN0XxAPTlNLZXllZEFyY2hp
+ dmVy0RcYVHJvb3SAAQgRGiMtMjc7QUhOW2KMjpCVoKmxtL3P0tcAAAAAAAABAQAAAAAA
+ AAAZAAAAAAAAAAAAAAAAAAAA2Q==
+ </data>
+ <key>ANSIBrightBlackColor</key>
+ <data>
+ YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
+ AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPECcw
+ LjQ4NjI3NDUwOTggMC40ODYyNzQ1MDk4IDAuNDg2Mjc0NTA5OAAQAoAC0hAREhNaJGNs
+ YXNzbmFtZVgkY2xhc3Nlc1dOU0NvbG9yohIUWE5TT2JqZWN0XxAPTlNLZXllZEFyY2hp
+ dmVy0RcYVHJvb3SAAQgRGiMtMjc7QUhOW2KMjpCVoKmxtL3P0tcAAAAAAAABAQAAAAAA
+ AAAZAAAAAAAAAAAAAAAAAAAA2Q==
+ </data>
+ <key>ANSIBrightBlueColor</key>
+ <data>
+ YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
+ AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPECYw
+ LjcwOTgwMzkyMTYgMC44NjI3NDUwOTggMC45OTYwNzg0MzE0ABACgALSEBESE1okY2xh
+ c3NuYW1lWCRjbGFzc2VzV05TQ29sb3KiEhRYTlNPYmplY3RfEA9OU0tleWVkQXJjaGl2
+ ZXLRFxhUcm9vdIABCBEaIy0yNztBSE5bYouNj5SfqLCzvM7R1gAAAAAAAAEBAAAAAAAA
+ ABkAAAAAAAAAAAAAAAAAAADY
+ </data>
+ <key>ANSIBrightCyanColor</key>
+ <data>
+ YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
+ AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPECcw
+ Ljg3NDUwOTgwMzkgMC44NzQ1MDk4MDM5IDAuOTk2MDc4NDMxNAAQAoAC0hAREhNaJGNs
+ YXNzbmFtZVgkY2xhc3Nlc1dOU0NvbG9yohIUWE5TT2JqZWN0XxAPTlNLZXllZEFyY2hp
+ dmVy0RcYVHJvb3SAAQgRGiMtMjc7QUhOW2KMjpCVoKmxtL3P0tcAAAAAAAABAQAAAAAA
+ AAAZAAAAAAAAAAAAAAAAAAAA2Q==
+ </data>
+ <key>ANSIBrightGreenColor</key>
+ <data>
+ YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
+ AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPEBww
+ LjgwNzg0MzEzNzMgMSAwLjY3NDUwOTgwMzkAEAKAAtIQERITWiRjbGFzc25hbWVYJGNs
+ YXNzZXNXTlNDb2xvcqISFFhOU09iamVjdF8QD05TS2V5ZWRBcmNoaXZlctEXGFRyb290
+ gAEIERojLTI3O0FITltigYOFipWepqmyxMfMAAAAAAAAAQEAAAAAAAAAGQAAAAAAAAAA
+ AAAAAAAAAM4=
+ </data>
+ <key>ANSIBrightMagentaColor</key>
+ <data>
+ YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
+ AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPEBwx
+ IDAuNjExNzY0NzA1OSAwLjk5NjA3ODQzMTQAEAKAAtIQERITWiRjbGFzc25hbWVYJGNs
+ YXNzZXNXTlNDb2xvcqISFFhOU09iamVjdF8QD05TS2V5ZWRBcmNoaXZlctEXGFRyb290
+ gAEIERojLTI3O0FITltigYOFipWepqmyxMfMAAAAAAAAAQEAAAAAAAAAGQAAAAAAAAAA
+ AAAAAAAAAM4=
+ </data>
+ <key>ANSIBrightRedColor</key>
+ <data>
+ YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
+ AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPEBwx
+ IDAuNzEzNzI1NDkwMiAwLjY5MDE5NjA3ODQAEAKAAtIQERITWiRjbGFzc25hbWVYJGNs
+ YXNzZXNXTlNDb2xvcqISFFhOU09iamVjdF8QD05TS2V5ZWRBcmNoaXZlctEXGFRyb290
+ gAEIERojLTI3O0FITltigYOFipWepqmyxMfMAAAAAAAAAQEAAAAAAAAAGQAAAAAAAAAA
+ AAAAAAAAAM4=
+ </data>
+ <key>ANSIBrightWhiteColor</key>
+ <data>
+ YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
+ AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NGMSAx
+ IDEAEAKAAtIQERITWiRjbGFzc25hbWVYJGNsYXNzZXNXTlNDb2xvcqISFFhOU09iamVj
+ dF8QD05TS2V5ZWRBcmNoaXZlctEXGFRyb290gAEIERojLTI3O0FITltiaWttcn2GjpGa
+ rK+0AAAAAAAAAQEAAAAAAAAAGQAAAAAAAAAAAAAAAAAAALY=
+ </data>
+ <key>ANSIBrightYellowColor</key>
+ <data>
+ YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
+ AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPEBEx
+ IDEgMC43OTYwNzg0MzE0ABACgALSEBESE1okY2xhc3NuYW1lWCRjbGFzc2VzV05TQ29s
+ b3KiEhRYTlNPYmplY3RfEA9OU0tleWVkQXJjaGl2ZXLRFxhUcm9vdIABCBEaIy0yNztB
+ SE5bYnZ4en+Kk5uep7m8wQAAAAAAAAEBAAAAAAAAABkAAAAAAAAAAAAAAAAAAADD
+ </data>
+ <key>ANSICyanColor</key>
+ <data>
+ YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
+ AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPECcw
+ Ljc3NjQ3MDU4ODIgMC43NzI1NDkwMTk2IDAuOTk2MDc4NDMxNAAQAoAC0hAREhNaJGNs
+ YXNzbmFtZVgkY2xhc3Nlc1dOU0NvbG9yohIUWE5TT2JqZWN0XxAPTlNLZXllZEFyY2hp
+ dmVy0RcYVHJvb3SAAQgRGiMtMjc7QUhOW2KMjpCVoKmxtL3P0tcAAAAAAAABAQAAAAAA
+ AAAZAAAAAAAAAAAAAAAAAAAA2Q==
+ </data>
+ <key>ANSIGreenColor</key>
+ <data>
+ YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
+ AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPEBww
+ LjY1ODgyMzUyOTQgMSAwLjM3NjQ3MDU4ODIAEAKAAtIQERITWiRjbGFzc25hbWVYJGNs
+ YXNzZXNXTlNDb2xvcqISFFhOU09iamVjdF8QD05TS2V5ZWRBcmNoaXZlctEXGFRyb290
+ gAEIERojLTI3O0FITltigYOFipWepqmyxMfMAAAAAAAAAQEAAAAAAAAAGQAAAAAAAAAA
+ AAAAAAAAAM4=
+ </data>
+ <key>ANSIMagentaColor</key>
+ <data>
+ YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
+ AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPEBwx
+ IDAuNDUwOTgwMzkyMiAwLjk5MjE1Njg2MjcAEAKAAtIQERITWiRjbGFzc25hbWVYJGNs
+ YXNzZXNXTlNDb2xvcqISFFhOU09iamVjdF8QD05TS2V5ZWRBcmNoaXZlctEXGFRyb290
+ gAEIERojLTI3O0FITltigYOFipWepqmyxMfMAAAAAAAAAQEAAAAAAAAAGQAAAAAAAAAA
+ AAAAAAAAAM4=
+ </data>
+ <key>ANSIRedColor</key>
+ <data>
+ YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
+ AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPEBwx
+ IDAuNDIzNTI5NDExOCAwLjM3NjQ3MDU4ODIAEAKAAtIQERITWiRjbGFzc25hbWVYJGNs
+ YXNzZXNXTlNDb2xvcqISFFhOU09iamVjdF8QD05TS2V5ZWRBcmNoaXZlctEXGFRyb290
+ gAEIERojLTI3O0FITltigYOFipWepqmyxMfMAAAAAAAAAQEAAAAAAAAAGQAAAAAAAAAA
+ AAAAAAAAAM4=
+ </data>
+ <key>ANSIWhiteColor</key>
+ <data>
+ YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
+ AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPECcw
+ LjkzMzMzMzMzMzMgMC45MzMzMzMzMzMzIDAuOTMzMzMzMzMzMwAQAoAC0hAREhNaJGNs
+ YXNzbmFtZVgkY2xhc3Nlc1dOU0NvbG9yohIUWE5TT2JqZWN0XxAPTlNLZXllZEFyY2hp
+ dmVy0RcYVHJvb3SAAQgRGiMtMjc7QUhOW2KMjpCVoKmxtL3P0tcAAAAAAAABAQAAAAAA
+ AAAZAAAAAAAAAAAAAAAAAAAA2Q==
+ </data>
+ <key>ANSIYellowColor</key>
+ <data>
+ YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
+ AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPEBEx
+ IDEgMC43MTM3MjU0OTAyABACgALSEBESE1okY2xhc3NuYW1lWCRjbGFzc2VzV05TQ29s
+ b3KiEhRYTlNPYmplY3RfEA9OU0tleWVkQXJjaGl2ZXLRFxhUcm9vdIABCBEaIy0yNztB
+ SE5bYnZ4en+Kk5uep7m8wQAAAAAAAAEBAAAAAAAAABkAAAAAAAAAAAAAAAAAAADD
+ </data>
+ <key>BackgroundColor</key>
+ <data>
+ YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
+ AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NGMCAw
+ IDAAEAGAAtIQERITWiRjbGFzc25hbWVYJGNsYXNzZXNXTlNDb2xvcqISFFhOU09iamVj
+ dF8QD05TS2V5ZWRBcmNoaXZlctEXGFRyb290gAEIERojLTI3O0FITltiaWttcn2GjpGa
+ rK+0AAAAAAAAAQEAAAAAAAAAGQAAAAAAAAAAAAAAAAAAALY=
+ </data>
+ <key>Bell</key>
+ <true/>
+ <key>CursorBlink</key>
+ <true/>
+ <key>CursorColor</key>
+ <data>
+ YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
+ AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPEBcx
+ IDAuNjQ3MDU4ODQgMC4zNzY0NzA2ABABgALSEBESE1okY2xhc3NuYW1lWCRjbGFzc2Vz
+ V05TQ29sb3KiEhRYTlNPYmplY3RfEA9OU0tleWVkQXJjaGl2ZXLRFxhUcm9vdIABCBEa
+ Iy0yNztBSE5bYnx+gIWQmaGkrb/CxwAAAAAAAAEBAAAAAAAAABkAAAAAAAAAAAAAAAAA
+ AADJ
+ </data>
+ <key>CursorType</key>
+ <integer>1</integer>
+ <key>DisableANSIColor</key>
+ <false/>
+ <key>EscapeNonASCIICharacters</key>
+ <true/>
+ <key>Font</key>
+ <data>
+ YnBsaXN0MDDUAQIDBAUGGBlYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
+ AAGGoKQHCBESVSRudWxs1AkKCwwNDg8QVk5TU2l6ZVhOU2ZGbGFnc1ZOU05hbWVWJGNs
+ YXNzI0AoAAAAAAAAEBCAAoADVk1vbmFjb9ITFBUWWiRjbGFzc25hbWVYJGNsYXNzZXNW
+ TlNGb250ohUXWE5TT2JqZWN0XxAPTlNLZXllZEFyY2hpdmVy0RobVHJvb3SAAQgRGiMt
+ Mjc8QktSW2JpcnR2eH+Ej5ifoqu9wMUAAAAAAAABAQAAAAAAAAAcAAAAAAAAAAAAAAAA
+ AAAAxw==
+ </data>
+ <key>FontAntialias</key>
+ <true/>
+ <key>Linewrap</key>
+ <true/>
+ <key>ProfileCurrentVersion</key>
+ <real>2.02</real>
+ <key>SelectionColor</key>
+ <data>
+ YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
+ AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPECYw
+ LjE3MjIwMTU4NjkgMC40MDY2OTU4MjIgMC4zNTIwNjU5NzU3ABABgALSEBESE1okY2xh
+ c3NuYW1lWCRjbGFzc2VzV05TQ29sb3KiEhRYTlNPYmplY3RfEA9OU0tleWVkQXJjaGl2
+ ZXLRFxhUcm9vdIABCBEaIy0yNztBSE5bYouNj5SfqLCzvM7R1gAAAAAAAAEBAAAAAAAA
+ ABkAAAAAAAAAAAAAAAAAAADY
+ </data>
+ <key>ShouldLimitScrollback</key>
+ <integer>0</integer>
+ <key>ShowActiveProcessInTitle</key>
+ <true/>
+ <key>ShowCommandKeyInTitle</key>
+ <false/>
+ <key>ShowDimensionsInTitle</key>
+ <false/>
+ <key>ShowShellCommandInTitle</key>
+ <false/>
+ <key>ShowTTYNameInTitle</key>
+ <false/>
+ <key>ShowWindowSettingsNameInTitle</key>
+ <false/>
+ <key>TerminalType</key>
+ <string>xterm-256color</string>
+ <key>TextBoldColor</key>
+ <data>
+ YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
+ AAGGoKMHCA9VJG51bGzTCQoLDA0OV05TV2hpdGVcTlNDb2xvclNwYWNlViRjbGFzc0Ix
+ ABADgALSEBESE1okY2xhc3NuYW1lWCRjbGFzc2VzV05TQ29sb3KiEhRYTlNPYmplY3Rf
+ EA9OU0tleWVkQXJjaGl2ZXLRFxhUcm9vdIABCBEaIy0yNztBSFBdZGdpa3B7hIyPmKqt
+ sgAAAAAAAAEBAAAAAAAAABkAAAAAAAAAAAAAAAAAAAC0
+ </data>
+ <key>TextColor</key>
+ <data>
+ YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
+ AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPECcw
+ LjkzMzMzMzMzMzMgMC45MzMzMzMzMzMzIDAuOTMzMzMzMzMzMwAQAoAC0hAREhNaJGNs
+ YXNzbmFtZVgkY2xhc3Nlc1dOU0NvbG9yohIUWE5TT2JqZWN0XxAPTlNLZXllZEFyY2hp
+ dmVy0RcYVHJvb3SAAQgRGiMtMjc7QUhOW2KMjpCVoKmxtL3P0tcAAAAAAAABAQAAAAAA
+ AAAZAAAAAAAAAAAAAAAAAAAA2Q==
+ </data>
+ <key>UseBoldFonts</key>
+ <true/>
+ <key>UseBrightBold</key>
+ <false/>
+ <key>VisualBell</key>
+ <false/>
+ <key>blackColour</key>
+ <data>
+ BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
+ ZmZmg5+cnj6Dn5yePoOfnJ4+AYY=
+ </data>
+ <key>blueColour</key>
+ <data>
+ BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
+ ZmZmg5eWFj+DzMtLP4P//n4/AYY=
+ </data>
+ <key>brightBlackColour</key>
+ <data>
+ BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
+ ZmZmg/n4+D6D+fj4PoP5+Pg+AYY=
+ </data>
+ <key>brightBlueColour</key>
+ <data>
+ BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
+ ZmZmg7YuNj+D3d5cP4MAjn8/AYY=
+ </data>
+ <key>brightCyanColour</key>
+ <data>
+ BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
+ ZmZmg+A7YD+D4FVgP4P/PX8/AYY=
+ </data>
+ <key>brightGreenColour</key>
+ <data>
+ BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
+ ZmZmg881Tz8Bg6w6LD8Bhg==
+ </data>
+ <key>brightMagentaColour</key>
+ <data>
+ BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
+ ZmZmAYOdAR0/g/8bfz8Bhg==
+ </data>
+ <key>brightRedColour</key>
+ <data>
+ BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
+ ZmZmAYO3tjY/g7GwMD8Bhg==
+ </data>
+ <key>brightWhiteColour</key>
+ <data>
+ BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
+ ZmZmAQEBAYY=
+ </data>
+ <key>brightYellowColour</key>
+ <data>
+ BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
+ ZmZmAQGDzbVMPwGG
+ </data>
+ <key>columnCount</key>
+ <integer>90</integer>
+ <key>cyanColour</key>
+ <data>
+ BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
+ ZmZmg8fGRj+DxsVFP4P//n4/AYY=
+ </data>
+ <key>greenColour</key>
+ <data>
+ BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
+ ZmZmg6moKD8Bg8HAwD4Bhg==
+ </data>
+ <key>keyMapBoundKeys</key>
+ <dict>
+ <key>$F708</key>
+ <string>[25~</string>
+ <key>$F709</key>
+ <string>[26~</string>
+ <key>$F70A</key>
+ <string>[28~</string>
+ <key>$F70B</key>
+ <string>[29~</string>
+ <key>$F70C</key>
+ <string>[31~</string>
+ <key>$F70D</key>
+ <string>[22~</string>
+ <key>$F70E</key>
+ <string>[33~</string>
+ <key>$F70F</key>
+ <string>[34~</string>
+ <key>$F729</key>
+ <string>[H</string>
+ <key>$F72B</key>
+ <string>[F</string>
+ <key>$F72C</key>
+ <string>[5~</string>
+ <key>$F72D</key>
+ <string>[6~</string>
+ <key>F704</key>
+ <string>OP</string>
+ <key>F705</key>
+ <string>OQ</string>
+ <key>F706</key>
+ <string>OR</string>
+ <key>F707</key>
+ <string>OS</string>
+ <key>F708</key>
+ <string>[15~</string>
+ <key>F709</key>
+ <string>[17~</string>
+ <key>F70A</key>
+ <string>[18~</string>
+ <key>F70B</key>
+ <string>[19~</string>
+ <key>F70C</key>
+ <string>[20~</string>
+ <key>F70D</key>
+ <string>[21~</string>
+ <key>F70E</key>
+ <string>[23~</string>
+ <key>F70F</key>
+ <string>[24~</string>
+ <key>F710</key>
+ <string>[25~</string>
+ <key>F711</key>
+ <string>[26~</string>
+ <key>F712</key>
+ <string>[28~</string>
+ <key>F713</key>
+ <string>[29~</string>
+ <key>F714</key>
+ <string>[31~</string>
+ <key>F715</key>
+ <string>[32~</string>
+ <key>F716</key>
+ <string>[33~</string>
+ <key>F717</key>
+ <string>[34~</string>
+ <key>F728</key>
+ <string>[3~</string>
+ <key>F729</key>
+ <string>[H</string>
+ <key>F72B</key>
+ <string>[F</string>
+ <key>F72C</key>
+ <string>scrollPageUp:</string>
+ <key>F72D</key>
+ <string>scrollPageDown:</string>
+ <key>^F702</key>
+ <string>[5D</string>
+ <key>^F703</key>
+ <string>[5C</string>
+ <key>~F704</key>
+ <string>[17~</string>
+ <key>~F705</key>
+ <string>[18~</string>
+ <key>~F706</key>
+ <string>[19~</string>
+ <key>~F707</key>
+ <string>[20~</string>
+ <key>~F708</key>
+ <string>[21~</string>
+ <key>~F709</key>
+ <string>[23~</string>
+ <key>~F70A</key>
+ <string>[24~</string>
+ <key>~F70B</key>
+ <string>[25~</string>
+ <key>~F70C</key>
+ <string>[26~</string>
+ <key>~F70D</key>
+ <string>[28~</string>
+ <key>~F70E</key>
+ <string>[29~</string>
+ <key>~F70F</key>
+ <string>[31~</string>
+ <key>~F710</key>
+ <string>[32~</string>
+ <key>~F711</key>
+ <string>[33~</string>
+ <key>~F712</key>
+ <string>[34~</string>
+ </dict>
+ <key>magentaColour</key>
+ <data>
+ BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
+ ZmZmAYPn5uY+g/79fT8Bhg==
+ </data>
+ <key>name</key>
+ <string>IR Nateware</string>
+ <key>redColour</key>
+ <data>
+ BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
+ ZmZmAYPZ2Ng+g8HAwD4Bhg==
+ </data>
+ <key>rowCount</key>
+ <integer>40</integer>
+ <key>shellExitAction</key>
+ <integer>1</integer>
+ <key>type</key>
+ <string>Window Settings</string>
+ <key>whiteColour</key>
+ <data>
+ BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
+ ZmZmg+/7bj+D7/tuP4Pv+24/AYY=
+ </data>
+ <key>yellowColour</key>
+ <data>
+ BAtzdHJlYW10eXBlZIHoA4QBQISEhAdOU0NvbG9yAISECE5TT2JqZWN0AIWEAWMBhARm
+ ZmZmAQGDt7Y2PwGG
+ </data>
+</dict>
+</plist>
diff --git a/relink b/relink
index a83a90d..82b3d70 100755
--- a/relink
+++ b/relink
@@ -1,8 +1,13 @@
-#!/bin/sh
+#!/usr/bin/env ruby
-for f in $PWD/.[a-z]*
-do
- b=`basename $f`
- echo "$HOME/$b => $f"
- (cd $HOME && rm -f $b && ln -s $f)
-done
+# use ruby to get relative paths
+require 'pathname'
+
+Dir['.[a-z]*'].each do |file|
+ path = Pathname.new(Dir.pwd + '/' + file)
+ home = Pathname.new(ENV['HOME'])
+ rel = path.relative_path_from home
+ link = ENV['HOME'] + '/' + file
+ puts "#{link} -> #{rel}"
+ system "rm -f #{link} && ln -s #{rel} #{link}"
+end
|
nateware/dotfiles
|
4622c113679c52ad1f2150e5d7c5460fd1ead5d2
|
really?
|
diff --git a/.bash_profile b/.bash_profile
index b2679c6..afd8d1f 100644
--- a/.bash_profile
+++ b/.bash_profile
@@ -1,40 +1,40 @@
# Must source manually
[ -f $HOME/.bashrc ] && . $HOME/.bashrc
# Colors!
c1="\033["
c2="m"
c_normal="${c1}0${c2}"
c_bold="${c1}1${c2}"
c_black="${c1}0;30${c2}"
c_blue="${c1}0;34${c2}"
c_green="${c1}0;32${c2}"
c_cyan="${c1}0;36${c2}"
c_red="${c1}0;31${c2}"
c_purple="${c1}0;35${c2}"
c_brown="${c1}0;33${c2}"
c_gray="${c1}0;37${c2}"
c_dark_gray="${c1}1;30${c2}"
c_bold_blue="${c1}1;34${c2}"
c_bold_green="${c1}1;32${c2}"
c_bold_cyan="${c1}1;36${c2}"
c_bold_red="${c1}1;31${c2}"
c_bold_purple="${c1}1;35${c2}"
c_bold_yellow="${c1}1;33${c2}"
c_bold_white="${c1}1;37${c2}"
# Prompt
#export PS1='[\u@\h:\W]\$ '
-#export PS1="[$c_green\u$c_normal@$c_purple\h$c_normal:$c_blue\W$c_normal]\$ "
-export PS1="[\W]\$ "
+#export PS1="[$c_green\u$c_normal@$c_purple\h$c_normal:$c_blue\W$c_normal]\\\$ "
+export PS1='[\W]\$ '
printf $c_red
type ruby
printf $c_normal
# Only sublime on login; vi otherwise
export EDITOR='subl -w'
[ -s $HOME/.nvm/nvm.sh ] && . $HOME/.nvm/nvm.sh # This loads NVM
|
nateware/dotfiles
|
5e2d1070f38711b93de959c8ae485dcb21922182
|
untar bz2
|
diff --git a/.bashrc b/.bashrc
index 486c511..f6170ae 100644
--- a/.bashrc
+++ b/.bashrc
@@ -1,239 +1,240 @@
# ~/.bashrc
umask 022
# Add to PATH but only if it exists
add_path () {
err=0
for p
do
if [ -d $p ]; then
PATH="$p:$PATH"
else
err=1
fi
done
return $err
}
# Add to LD_LIB_PATH adjusting for platform
add_lib () {
[ -d "$1" ] || return 0
if [ "$OS" = Darwin ]; then
export DYLD_LIBRARY_PATH="$1:$DYLD_LIBRARY_PATH"
else
export LD_LIBRARY_PATH="$1:$DYLD_LIBRARY_PATH"
fi
return 0
}
# Guess
add_path_and_lib () {
if add_path "$1"; then
lib=${1%/bin}/lib
add_lib $lib
else
return 1
fi
}
# Aliases
alias ls='\ls -Gh'
alias ll='ls -al'
alias wget='curl -LO'
alias ldd='otool -L'
alias rsync='\rsync --exclude=.svn --exclude=.git --exclude=RCS'
alias vi='vim -b'
# Don't want to install rubydocs - TOO SLOW!
alias gi='gem install --no-ri --no-rdoc'
alias bi='bundle --without=production install'
alias bu='bundle --without=production update'
alias be='bundle exec'
alias ga='git ci -a -m'
alias gd='git pu && git push -f dev'
alias gp='git pu'
gap () {
ga "$*" && gp
}
gapd () {
gap "$*" && cap dev deploy
}
# Change to workspace directory
wd () {
if [ $# -eq 0 ]; then
pushd "$HOME/Workspace"
else
pushd "$HOME/Workspace/$1"*
fi
}
# Platform goodness
export OS=`uname`
[ "$OS" = Darwin ] && export JAVA_HOME=/Library/Java/Home
# Remember add_path unshifts, so the one you want first should be last
add_path \
/usr/local/git/bin \
/usr/local/bin \
/opt/local/sbin \
/opt/local/bin \
$HOME/sbin \
$HOME/bin
add_path $HOME/Workspace/adt-bundle-mac-x86_64-20130522/sdk/platform-tools
# For ruby version manager
[ -s $HOME/.rvm/scripts/rvm ] && . $HOME/.rvm/scripts/rvm
# Load node version manager
[ -s $HOME/.nvm/nvm.sh ] && . $HOME/.nvm/nvm.sh
# rbenv
#if add_path $HOME/.rbenv/bin; then
#eval "$(rbenv init -)"
#fi
# For Jeweler
export JEWELER_OPTS="--bundler --bacon --create-repo --user-name 'Nate Wiger' --user-email 'nwiger@gmail.com' --github-username nateware"
# ImageMagick
add_path_and_lib /usr/local/ImageMagick/bin
# MySQL
add_path /usr/local/mysql/bin
# Self-contained Postgres.app
add_path /Applications/Postgres.app/Contents/MacOS/bin
# MongoDB
add_path /usr/local/mongodb/bin
# Amazon EC2 CLI tools (official locations)
export EC2_HOME=/usr/local/ec2-api-tools
add_path "$EC2_HOME/bin" || unset EC2_HOME
export RDS_HOME=/usr/local/rds-cli
add_path "$RDS_HOME/bin" || unset RDS_HOME
ec2region () {
if [ $# -eq 1 ]; then
export EC2_REGION=$1
export EC2_URL="http://ec2.$EC2_REGION.amazonaws.com"
export AWS_DEFAULT_REGION=$EC2_REGION
ec2setenv
fi
tty -s && echo "EC2_REGION=$EC2_REGION"
}
ec2acct () {
if [ $# -ge 1 ]; then
export EC2_ACCOUNT=$1
if [ $# -eq 2 ]; then
ec2region $2
else
ec2setenv
fi
fi
tty -s && echo "EC2_ACCOUNT=$EC2_ACCOUNT"
}
# Amazon EC2 gems
ec2setenv () {
local acctdir="$HOME/.ec2/$EC2_ACCOUNT"
# Newer tools and unified CLI
export AWS_ACCESS_KEY_ID=`cat $acctdir/access_key_id.txt 2>/dev/null`
export AWS_SECRET_ACCESS_KEY=`cat $acctdir/secret_access_key.txt 2>/dev/null`
export EC2_CERT=`ls -1 $acctdir/cert-* 2>/dev/null | head -1`
export EC2_PRIVATE_KEY=`echo $EC2_CERT | sed 's/cert-\(.*\).pem/pk-\1.pem/'`
# Old style per-service CLI's
export AWS_CREDENTIAL_FILE="$acctdir/credential-file-path"
# My approach for ec2 is to launch with the custom "root" keypair,
# but username may change based on AMI, so use just do ec2-user@whatevs
export EC2_ROOT_KEY="$acctdir/root-$EC2_REGION.pem"
if [ ! -f "$EC2_ROOT_KEY" ]; then
echo "Warning: EC2 key does not exist: $EC2_ROOT_KEY" >&2
fi
# To override root, use ubuntu@ or ec2-user@ or whatever
ssh_cmd="ssh -i $EC2_ROOT_KEY -o StrictHostKeyChecking=no -l root"
alias ash=$ssh_cmd
alias async="rsync -av -e '$ssh_cmd'"
}
# Set default EC2 region
if [ -d "$HOME/.ec2" ]; then
ec2acct work us-west-2
fi
# Use garnaat's unified CLI
complete -C aws_completer aws # bash tab completion
paws (){
aws "$@" | ruby -rjson -rawesome_print -e "ap JSON.parse(STDIN.read)"
}
complete -C aws_completer paws # bash tab completion
[ -f "$HOME/.git-completion.bash" ] && . "$HOME/.git-completion.bash"
# Easy unzipping
untar () {
if [ "$#" -eq 0 ]; then
echo "Usage: untar files ..." >&2
return 1
fi
for f
do
case $f in
*.zip) unzip $f;;
- *.tar.gz|*.tgz) tar xzvf $f;;
- *.tar.bz|*.tbz) bunzip -c $f | tar xvf -;;
+ *.tar.gz|*.tgz) tar xzvf $f;;
+ *.tar.bz|*.tbz) bunzip -c $f | tar xvf -;;
+ *.tar.bz2|*.tbz2) bunzip2 -c $f | tar xvf -;;
*) echo "Unsupported file type: $f" >&2;;
esac
done
}
# shortcut to kill processes that tend to suck
fuck () {
local pn=
case "$1" in
chr*) pn="Google Chrome";;
cisc*) pn="Cisco AnyConnect Secure Mobility Client";;
esac
killall "$pn"
sleep 2
killall "$pn"
sleep 3
killall -9 "$pn"
}
# Postgres
if add_path /Library/PostgreSQL/9.0/bin; then
. /Library/PostgreSQL/9.0/pg_env.sh
fi
export JVA=209.40.197.81
alias jva="ssh -l janetvanarsdale $JVA"
alias rjva="ssh -l root $JVA"
# Still needed for old games
export ORACLE_HOME="/usr/local/oracle/10.2.0.4/client"
if [ -d "$ORACLE_HOME" ]; then
add_path_and_lib "$ORACLE_HOME/bin"
export TNS_ADMIN="$HOME/tnsadmin" # Directory
export NLS_LANG=".AL32UTF8"
fi
# For fucking with "go" the language
export GOROOT=$HOME/Workspace/go
export GOOS=darwin
export GOARCH=386
export GOBIN=$HOME/bin
### Added by the Heroku Toolbelt
export PATH="/usr/local/heroku/bin:$PATH"
|
nateware/dotfiles
|
46c2923a007aeb7f8a46523e7b354078552b91fe
|
minor cleanup and refactoring
|
diff --git a/.bash_profile b/.bash_profile
index 794063b..e26c378 100644
--- a/.bash_profile
+++ b/.bash_profile
@@ -1,40 +1,44 @@
# Must source manually
[ -f $HOME/.bashrc ] && . $HOME/.bashrc
# Colors!
c1="\033["
c2="m"
c_normal="${c1}0${c2}"
c_bold="${c1}1${c2}"
c_black="${c1}0;30${c2}"
c_blue="${c1}0;34${c2}"
c_green="${c1}0;32${c2}"
c_cyan="${c1}0;36${c2}"
c_red="${c1}0;31${c2}"
c_purple="${c1}0;35${c2}"
c_brown="${c1}0;33${c2}"
c_gray="${c1}0;37${c2}"
c_dark_gray="${c1}1;30${c2}"
c_bold_blue="${c1}1;34${c2}"
c_bold_green="${c1}1;32${c2}"
c_bold_cyan="${c1}1;36${c2}"
c_bold_red="${c1}1;31${c2}"
c_bold_purple="${c1}1;35${c2}"
c_bold_yellow="${c1}1;33${c2}"
c_bold_white="${c1}1;37${c2}"
# Prompt
#export PS1='[\u@\h:\W]\$ '
#export PS1="[$c_green\u$c_normal@$c_purple\h$c_normal:$c_blue\W$c_normal]\$ "
export PS1="[\W]\$ "
printf $c_red
type ruby
printf $c_normal
### Added by the Heroku Toolbelt
export PATH="/usr/local/heroku/bin:$PATH"
# MacPorts Installer addition
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
+
+# Only sublime on login; vi otherwise
+export EDITOR='subl -w'
+
diff --git a/.bashrc b/.bashrc
index f7e3e4d..486c511 100644
--- a/.bashrc
+++ b/.bashrc
@@ -1,228 +1,239 @@
# ~/.bashrc
umask 022
# Add to PATH but only if it exists
add_path () {
err=0
for p
do
if [ -d $p ]; then
PATH="$p:$PATH"
else
err=1
fi
done
return $err
}
# Add to LD_LIB_PATH adjusting for platform
add_lib () {
[ -d "$1" ] || return 0
if [ "$OS" = Darwin ]; then
export DYLD_LIBRARY_PATH="$1:$DYLD_LIBRARY_PATH"
else
export LD_LIBRARY_PATH="$1:$DYLD_LIBRARY_PATH"
fi
return 0
}
# Guess
add_path_and_lib () {
if add_path "$1"; then
lib=${1%/bin}/lib
add_lib $lib
else
return 1
fi
}
# Aliases
alias ls='\ls -Gh'
alias ll='ls -al'
alias wget='curl -LO'
alias ldd='otool -L'
alias rsync='\rsync --exclude=.svn --exclude=.git --exclude=RCS'
alias vi='vim -b'
# Don't want to install rubydocs - TOO SLOW!
alias gi='gem install --no-ri --no-rdoc'
alias bi='bundle --without=production install'
alias bu='bundle --without=production update'
alias be='bundle exec'
alias ga='git ci -a -m'
alias gd='git pu && git push -f dev'
alias gp='git pu'
gap () {
ga "$*" && gp
}
gapd () {
gap "$*" && cap dev deploy
}
# Change to workspace directory
wd () {
if [ $# -eq 0 ]; then
pushd "$HOME/Workspace"
else
pushd "$HOME/Workspace/$1"*
fi
}
# Platform goodness
export OS=`uname`
[ "$OS" = Darwin ] && export JAVA_HOME=/Library/Java/Home
# Remember add_path unshifts, so the one you want first should be last
add_path \
/usr/local/git/bin \
/usr/local/bin \
/opt/local/sbin \
/opt/local/bin \
$HOME/sbin \
$HOME/bin
+add_path $HOME/Workspace/adt-bundle-mac-x86_64-20130522/sdk/platform-tools
+
# For ruby version manager
[ -s $HOME/.rvm/scripts/rvm ] && . $HOME/.rvm/scripts/rvm
# Load node version manager
[ -s $HOME/.nvm/nvm.sh ] && . $HOME/.nvm/nvm.sh
# rbenv
#if add_path $HOME/.rbenv/bin; then
#eval "$(rbenv init -)"
#fi
# For Jeweler
export JEWELER_OPTS="--bundler --bacon --create-repo --user-name 'Nate Wiger' --user-email 'nwiger@gmail.com' --github-username nateware"
# ImageMagick
add_path_and_lib /usr/local/ImageMagick/bin
# MySQL
add_path /usr/local/mysql/bin
# Self-contained Postgres.app
add_path /Applications/Postgres.app/Contents/MacOS/bin
# MongoDB
add_path /usr/local/mongodb/bin
# Amazon EC2 CLI tools (official locations)
export EC2_HOME=/usr/local/ec2-api-tools
add_path "$EC2_HOME/bin" || unset EC2_HOME
export RDS_HOME=/usr/local/rds-cli
add_path "$RDS_HOME/bin" || unset RDS_HOME
ec2region () {
if [ $# -eq 1 ]; then
export EC2_REGION=$1
export EC2_URL="http://ec2.$EC2_REGION.amazonaws.com"
export AWS_DEFAULT_REGION=$EC2_REGION
ec2setenv
fi
tty -s && echo "EC2_REGION=$EC2_REGION"
}
ec2acct () {
if [ $# -ge 1 ]; then
export EC2_ACCOUNT=$1
if [ $# -eq 2 ]; then
ec2region $2
else
ec2setenv
fi
fi
tty -s && echo "EC2_ACCOUNT=$EC2_ACCOUNT"
}
# Amazon EC2 gems
ec2setenv () {
- export AWS_ACCESS_KEY_ID=`cat $HOME/.ec2/$EC2_ACCOUNT/access_key_id.txt`
- export AWS_SECRET_ACCESS_KEY=`cat $HOME/.ec2/$EC2_ACCOUNT/secret_access_key.txt`
+ local acctdir="$HOME/.ec2/$EC2_ACCOUNT"
+
+ # Newer tools and unified CLI
+ export AWS_ACCESS_KEY_ID=`cat $acctdir/access_key_id.txt 2>/dev/null`
+ export AWS_SECRET_ACCESS_KEY=`cat $acctdir/secret_access_key.txt 2>/dev/null`
- export EC2_CERT=`ls -1 $HOME/.ec2/$EC2_ACCOUNT/cert-* | head -1`
+ export EC2_CERT=`ls -1 $acctdir/cert-* 2>/dev/null | head -1`
export EC2_PRIVATE_KEY=`echo $EC2_CERT | sed 's/cert-\(.*\).pem/pk-\1.pem/'`
- # New paradigm for ec2 is to use the custom keypair, but username may change
- export EC2_ROOT_KEY="$HOME/.ec2/$EC2_ACCOUNT/root-$EC2_REGION.pem"
+ # Old style per-service CLI's
+ export AWS_CREDENTIAL_FILE="$acctdir/credential-file-path"
+
+ # My approach for ec2 is to launch with the custom "root" keypair,
+ # but username may change based on AMI, so use just do ec2-user@whatevs
+ export EC2_ROOT_KEY="$acctdir/root-$EC2_REGION.pem"
if [ ! -f "$EC2_ROOT_KEY" ]; then
echo "Warning: EC2 key does not exist: $EC2_ROOT_KEY" >&2
fi
# To override root, use ubuntu@ or ec2-user@ or whatever
ssh_cmd="ssh -i $EC2_ROOT_KEY -o StrictHostKeyChecking=no -l root"
alias ash=$ssh_cmd
alias async="rsync -av -e '$ssh_cmd'"
}
# Set default EC2 region
if [ -d "$HOME/.ec2" ]; then
ec2acct work us-west-2
fi
# Use garnaat's unified CLI
complete -C aws_completer aws # bash tab completion
paws (){
aws "$@" | ruby -rjson -rawesome_print -e "ap JSON.parse(STDIN.read)"
}
complete -C aws_completer paws # bash tab completion
+[ -f "$HOME/.git-completion.bash" ] && . "$HOME/.git-completion.bash"
+
# Easy unzipping
untar () {
if [ "$#" -eq 0 ]; then
echo "Usage: untar files ..." >&2
return 1
fi
for f
do
case $f in
*.zip) unzip $f;;
*.tar.gz|*.tgz) tar xzvf $f;;
*.tar.bz|*.tbz) bunzip -c $f | tar xvf -;;
*) echo "Unsupported file type: $f" >&2;;
esac
done
}
# shortcut to kill processes that tend to suck
fuck () {
local pn=
case "$1" in
chr*) pn="Google Chrome";;
cisc*) pn="Cisco AnyConnect Secure Mobility Client";;
esac
- killall $pn
+ killall "$pn"
sleep 2
- killall $pn
+ killall "$pn"
sleep 3
- killall -9 $pn
+ killall -9 "$pn"
}
# Postgres
if add_path /Library/PostgreSQL/9.0/bin; then
. /Library/PostgreSQL/9.0/pg_env.sh
fi
export JVA=209.40.197.81
alias jva="ssh -l janetvanarsdale $JVA"
alias rjva="ssh -l root $JVA"
# Still needed for old games
export ORACLE_HOME="/usr/local/oracle/10.2.0.4/client"
if [ -d "$ORACLE_HOME" ]; then
add_path_and_lib "$ORACLE_HOME/bin"
export TNS_ADMIN="$HOME/tnsadmin" # Directory
export NLS_LANG=".AL32UTF8"
fi
# For fucking with "go" the language
export GOROOT=$HOME/Workspace/go
export GOOS=darwin
export GOARCH=386
export GOBIN=$HOME/bin
### Added by the Heroku Toolbelt
export PATH="/usr/local/heroku/bin:$PATH"
diff --git a/.git-completion.bash b/.git-completion.bash
new file mode 100644
index 0000000..fd9a1d5
--- /dev/null
+++ b/.git-completion.bash
@@ -0,0 +1,2663 @@
+#!bash
+#
+# bash/zsh completion support for core Git.
+#
+# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
+# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
+# Distributed under the GNU General Public License, version 2.0.
+#
+# The contained completion routines provide support for completing:
+#
+# *) local and remote branch names
+# *) local and remote tag names
+# *) .git/remotes file names
+# *) git 'subcommands'
+# *) tree paths within 'ref:path/to/file' expressions
+# *) file paths within current working directory and index
+# *) common --long-options
+#
+# To use these routines:
+#
+# 1) Copy this file to somewhere (e.g. ~/.git-completion.sh).
+# 2) Add the following line to your .bashrc/.zshrc:
+# source ~/.git-completion.sh
+# 3) Consider changing your PS1 to also show the current branch,
+# see git-prompt.sh for details.
+
+case "$COMP_WORDBREAKS" in
+*:*) : great ;;
+*) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
+esac
+
+# __gitdir accepts 0 or 1 arguments (i.e., location)
+# returns location of .git repo
+__gitdir ()
+{
+ # Note: this function is duplicated in git-prompt.sh
+ # When updating it, make sure you update the other one to match.
+ if [ -z "${1-}" ]; then
+ if [ -n "${__git_dir-}" ]; then
+ echo "$__git_dir"
+ elif [ -n "${GIT_DIR-}" ]; then
+ test -d "${GIT_DIR-}" || return 1
+ echo "$GIT_DIR"
+ elif [ -d .git ]; then
+ echo .git
+ else
+ git rev-parse --git-dir 2>/dev/null
+ fi
+ elif [ -d "$1/.git" ]; then
+ echo "$1/.git"
+ else
+ echo "$1"
+ fi
+}
+
+# The following function is based on code from:
+#
+# bash_completion - programmable completion functions for bash 3.2+
+#
+# Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
+# © 2009-2010, Bash Completion Maintainers
+# <bash-completion-devel@lists.alioth.debian.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+# The latest version of this software can be obtained here:
+#
+# http://bash-completion.alioth.debian.org/
+#
+# RELEASE: 2.x
+
+# This function can be used to access a tokenized list of words
+# on the command line:
+#
+# __git_reassemble_comp_words_by_ref '=:'
+# if test "${words_[cword_-1]}" = -w
+# then
+# ...
+# fi
+#
+# The argument should be a collection of characters from the list of
+# word completion separators (COMP_WORDBREAKS) to treat as ordinary
+# characters.
+#
+# This is roughly equivalent to going back in time and setting
+# COMP_WORDBREAKS to exclude those characters. The intent is to
+# make option types like --date=<type> and <rev>:<path> easy to
+# recognize by treating each shell word as a single token.
+#
+# It is best not to set COMP_WORDBREAKS directly because the value is
+# shared with other completion scripts. By the time the completion
+# function gets called, COMP_WORDS has already been populated so local
+# changes to COMP_WORDBREAKS have no effect.
+#
+# Output: words_, cword_, cur_.
+
+__git_reassemble_comp_words_by_ref()
+{
+ local exclude i j first
+ # Which word separators to exclude?
+ exclude="${1//[^$COMP_WORDBREAKS]}"
+ cword_=$COMP_CWORD
+ if [ -z "$exclude" ]; then
+ words_=("${COMP_WORDS[@]}")
+ return
+ fi
+ # List of word completion separators has shrunk;
+ # re-assemble words to complete.
+ for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
+ # Append each nonempty word consisting of just
+ # word separator characters to the current word.
+ first=t
+ while
+ [ $i -gt 0 ] &&
+ [ -n "${COMP_WORDS[$i]}" ] &&
+ # word consists of excluded word separators
+ [ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
+ do
+ # Attach to the previous token,
+ # unless the previous token is the command name.
+ if [ $j -ge 2 ] && [ -n "$first" ]; then
+ ((j--))
+ fi
+ first=
+ words_[$j]=${words_[j]}${COMP_WORDS[i]}
+ if [ $i = $COMP_CWORD ]; then
+ cword_=$j
+ fi
+ if (($i < ${#COMP_WORDS[@]} - 1)); then
+ ((i++))
+ else
+ # Done.
+ return
+ fi
+ done
+ words_[$j]=${words_[j]}${COMP_WORDS[i]}
+ if [ $i = $COMP_CWORD ]; then
+ cword_=$j
+ fi
+ done
+}
+
+if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
+_get_comp_words_by_ref ()
+{
+ local exclude cur_ words_ cword_
+ if [ "$1" = "-n" ]; then
+ exclude=$2
+ shift 2
+ fi
+ __git_reassemble_comp_words_by_ref "$exclude"
+ cur_=${words_[cword_]}
+ while [ $# -gt 0 ]; do
+ case "$1" in
+ cur)
+ cur=$cur_
+ ;;
+ prev)
+ prev=${words_[$cword_-1]}
+ ;;
+ words)
+ words=("${words_[@]}")
+ ;;
+ cword)
+ cword=$cword_
+ ;;
+ esac
+ shift
+ done
+}
+fi
+
+__gitcompadd ()
+{
+ local i=0
+ for x in $1; do
+ if [[ "$x" == "$3"* ]]; then
+ COMPREPLY[i++]="$2$x$4"
+ fi
+ done
+}
+
+# Generates completion reply, appending a space to possible completion words,
+# if necessary.
+# It accepts 1 to 4 arguments:
+# 1: List of possible completion words.
+# 2: A prefix to be added to each possible completion word (optional).
+# 3: Generate possible completion matches for this word (optional).
+# 4: A suffix to be appended to each possible completion word (optional).
+__gitcomp ()
+{
+ local cur_="${3-$cur}"
+
+ case "$cur_" in
+ --*=)
+ ;;
+ *)
+ local c i=0 IFS=$' \t\n'
+ for c in $1; do
+ c="$c${4-}"
+ if [[ $c == "$cur_"* ]]; then
+ case $c in
+ --*=*|*.) ;;
+ *) c="$c " ;;
+ esac
+ COMPREPLY[i++]="${2-}$c"
+ fi
+ done
+ ;;
+ esac
+}
+
+# Generates completion reply from newline-separated possible completion words
+# by appending a space to all of them.
+# It accepts 1 to 4 arguments:
+# 1: List of possible completion words, separated by a single newline.
+# 2: A prefix to be added to each possible completion word (optional).
+# 3: Generate possible completion matches for this word (optional).
+# 4: A suffix to be appended to each possible completion word instead of
+# the default space (optional). If specified but empty, nothing is
+# appended.
+__gitcomp_nl ()
+{
+ local IFS=$'\n'
+ __gitcompadd "$1" "${2-}" "${3-$cur}" "${4- }"
+}
+
+# Generates completion reply with compgen from newline-separated possible
+# completion filenames.
+# It accepts 1 to 3 arguments:
+# 1: List of possible completion filenames, separated by a single newline.
+# 2: A directory prefix to be added to each possible completion filename
+# (optional).
+# 3: Generate possible completion matches for this word (optional).
+__gitcomp_file ()
+{
+ local IFS=$'\n'
+
+ # XXX does not work when the directory prefix contains a tilde,
+ # since tilde expansion is not applied.
+ # This means that COMPREPLY will be empty and Bash default
+ # completion will be used.
+ __gitcompadd "$1" "${2-}" "${3-$cur}" ""
+
+ # use a hack to enable file mode in bash < 4
+ compopt -o filenames +o nospace 2>/dev/null ||
+ compgen -f /non-existing-dir/ > /dev/null
+}
+
+# Execute 'git ls-files', unless the --committable option is specified, in
+# which case it runs 'git diff-index' to find out the files that can be
+# committed. It return paths relative to the directory specified in the first
+# argument, and using the options specified in the second argument.
+__git_ls_files_helper ()
+{
+ (
+ test -n "${CDPATH+set}" && unset CDPATH
+ cd "$1"
+ if [ "$2" == "--committable" ]; then
+ git diff-index --name-only --relative HEAD
+ else
+ # NOTE: $2 is not quoted in order to support multiple options
+ git ls-files --exclude-standard $2
+ fi
+ ) 2>/dev/null
+}
+
+
+# __git_index_files accepts 1 or 2 arguments:
+# 1: Options to pass to ls-files (required).
+# 2: A directory path (optional).
+# If provided, only files within the specified directory are listed.
+# Sub directories are never recursed. Path must have a trailing
+# slash.
+__git_index_files ()
+{
+ local dir="$(__gitdir)" root="${2-.}" file
+
+ if [ -d "$dir" ]; then
+ __git_ls_files_helper "$root" "$1" |
+ while read -r file; do
+ case "$file" in
+ ?*/*) echo "${file%%/*}" ;;
+ *) echo "$file" ;;
+ esac
+ done | sort | uniq
+ fi
+}
+
+__git_heads ()
+{
+ local dir="$(__gitdir)"
+ if [ -d "$dir" ]; then
+ git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
+ refs/heads
+ return
+ fi
+}
+
+__git_tags ()
+{
+ local dir="$(__gitdir)"
+ if [ -d "$dir" ]; then
+ git --git-dir="$dir" for-each-ref --format='%(refname:short)' \
+ refs/tags
+ return
+ fi
+}
+
+# __git_refs accepts 0, 1 (to pass to __gitdir), or 2 arguments
+# presence of 2nd argument means use the guess heuristic employed
+# by checkout for tracking branches
+__git_refs ()
+{
+ local i hash dir="$(__gitdir "${1-}")" track="${2-}"
+ local format refs
+ if [ -d "$dir" ]; then
+ case "$cur" in
+ refs|refs/*)
+ format="refname"
+ refs="${cur%/*}"
+ track=""
+ ;;
+ *)
+ for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
+ if [ -e "$dir/$i" ]; then echo $i; fi
+ done
+ format="refname:short"
+ refs="refs/tags refs/heads refs/remotes"
+ ;;
+ esac
+ git --git-dir="$dir" for-each-ref --format="%($format)" \
+ $refs
+ if [ -n "$track" ]; then
+ # employ the heuristic used by git checkout
+ # Try to find a remote branch that matches the completion word
+ # but only output if the branch name is unique
+ local ref entry
+ git --git-dir="$dir" for-each-ref --shell --format="ref=%(refname:short)" \
+ "refs/remotes/" | \
+ while read -r entry; do
+ eval "$entry"
+ ref="${ref#*/}"
+ if [[ "$ref" == "$cur"* ]]; then
+ echo "$ref"
+ fi
+ done | sort | uniq -u
+ fi
+ return
+ fi
+ case "$cur" in
+ refs|refs/*)
+ git ls-remote "$dir" "$cur*" 2>/dev/null | \
+ while read -r hash i; do
+ case "$i" in
+ *^{}) ;;
+ *) echo "$i" ;;
+ esac
+ done
+ ;;
+ *)
+ echo "HEAD"
+ git for-each-ref --format="%(refname:short)" -- "refs/remotes/$dir/" | sed -e "s#^$dir/##"
+ ;;
+ esac
+}
+
+# __git_refs2 requires 1 argument (to pass to __git_refs)
+__git_refs2 ()
+{
+ local i
+ for i in $(__git_refs "$1"); do
+ echo "$i:$i"
+ done
+}
+
+# __git_refs_remotes requires 1 argument (to pass to ls-remote)
+__git_refs_remotes ()
+{
+ local i hash
+ git ls-remote "$1" 'refs/heads/*' 2>/dev/null | \
+ while read -r hash i; do
+ echo "$i:refs/remotes/$1/${i#refs/heads/}"
+ done
+}
+
+__git_remotes ()
+{
+ local i IFS=$'\n' d="$(__gitdir)"
+ test -d "$d/remotes" && ls -1 "$d/remotes"
+ for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do
+ i="${i#remote.}"
+ echo "${i/.url*/}"
+ done
+}
+
+__git_list_merge_strategies ()
+{
+ git merge -s help 2>&1 |
+ sed -n -e '/[Aa]vailable strategies are: /,/^$/{
+ s/\.$//
+ s/.*://
+ s/^[ ]*//
+ s/[ ]*$//
+ p
+ }'
+}
+
+__git_merge_strategies=
+# 'git merge -s help' (and thus detection of the merge strategy
+# list) fails, unfortunately, if run outside of any git working
+# tree. __git_merge_strategies is set to the empty string in
+# that case, and the detection will be repeated the next time it
+# is needed.
+__git_compute_merge_strategies ()
+{
+ test -n "$__git_merge_strategies" ||
+ __git_merge_strategies=$(__git_list_merge_strategies)
+}
+
+__git_complete_revlist_file ()
+{
+ local pfx ls ref cur_="$cur"
+ case "$cur_" in
+ *..?*:*)
+ return
+ ;;
+ ?*:*)
+ ref="${cur_%%:*}"
+ cur_="${cur_#*:}"
+ case "$cur_" in
+ ?*/*)
+ pfx="${cur_%/*}"
+ cur_="${cur_##*/}"
+ ls="$ref:$pfx"
+ pfx="$pfx/"
+ ;;
+ *)
+ ls="$ref"
+ ;;
+ esac
+
+ case "$COMP_WORDBREAKS" in
+ *:*) : great ;;
+ *) pfx="$ref:$pfx" ;;
+ esac
+
+ __gitcomp_nl "$(git --git-dir="$(__gitdir)" ls-tree "$ls" 2>/dev/null \
+ | sed '/^100... blob /{
+ s,^.* ,,
+ s,$, ,
+ }
+ /^120000 blob /{
+ s,^.* ,,
+ s,$, ,
+ }
+ /^040000 tree /{
+ s,^.* ,,
+ s,$,/,
+ }
+ s/^.* //')" \
+ "$pfx" "$cur_" ""
+ ;;
+ *...*)
+ pfx="${cur_%...*}..."
+ cur_="${cur_#*...}"
+ __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
+ ;;
+ *..*)
+ pfx="${cur_%..*}.."
+ cur_="${cur_#*..}"
+ __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
+ ;;
+ *)
+ __gitcomp_nl "$(__git_refs)"
+ ;;
+ esac
+}
+
+
+# __git_complete_index_file requires 1 argument:
+# 1: the options to pass to ls-file
+#
+# The exception is --committable, which finds the files appropriate commit.
+__git_complete_index_file ()
+{
+ local pfx="" cur_="$cur"
+
+ case "$cur_" in
+ ?*/*)
+ pfx="${cur_%/*}"
+ cur_="${cur_##*/}"
+ pfx="${pfx}/"
+ ;;
+ esac
+
+ __gitcomp_file "$(__git_index_files "$1" "$pfx")" "$pfx" "$cur_"
+}
+
+__git_complete_file ()
+{
+ __git_complete_revlist_file
+}
+
+__git_complete_revlist ()
+{
+ __git_complete_revlist_file
+}
+
+__git_complete_remote_or_refspec ()
+{
+ local cur_="$cur" cmd="${words[1]}"
+ local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
+ if [ "$cmd" = "remote" ]; then
+ ((c++))
+ fi
+ while [ $c -lt $cword ]; do
+ i="${words[c]}"
+ case "$i" in
+ --mirror) [ "$cmd" = "push" ] && no_complete_refspec=1 ;;
+ --all)
+ case "$cmd" in
+ push) no_complete_refspec=1 ;;
+ fetch)
+ return
+ ;;
+ *) ;;
+ esac
+ ;;
+ -*) ;;
+ *) remote="$i"; break ;;
+ esac
+ ((c++))
+ done
+ if [ -z "$remote" ]; then
+ __gitcomp_nl "$(__git_remotes)"
+ return
+ fi
+ if [ $no_complete_refspec = 1 ]; then
+ return
+ fi
+ [ "$remote" = "." ] && remote=
+ case "$cur_" in
+ *:*)
+ case "$COMP_WORDBREAKS" in
+ *:*) : great ;;
+ *) pfx="${cur_%%:*}:" ;;
+ esac
+ cur_="${cur_#*:}"
+ lhs=0
+ ;;
+ +*)
+ pfx="+"
+ cur_="${cur_#+}"
+ ;;
+ esac
+ case "$cmd" in
+ fetch)
+ if [ $lhs = 1 ]; then
+ __gitcomp_nl "$(__git_refs2 "$remote")" "$pfx" "$cur_"
+ else
+ __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
+ fi
+ ;;
+ pull|remote)
+ if [ $lhs = 1 ]; then
+ __gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
+ else
+ __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
+ fi
+ ;;
+ push)
+ if [ $lhs = 1 ]; then
+ __gitcomp_nl "$(__git_refs)" "$pfx" "$cur_"
+ else
+ __gitcomp_nl "$(__git_refs "$remote")" "$pfx" "$cur_"
+ fi
+ ;;
+ esac
+}
+
+__git_complete_strategy ()
+{
+ __git_compute_merge_strategies
+ case "$prev" in
+ -s|--strategy)
+ __gitcomp "$__git_merge_strategies"
+ return 0
+ esac
+ case "$cur" in
+ --strategy=*)
+ __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
+ return 0
+ ;;
+ esac
+ return 1
+}
+
+__git_commands () {
+ if test -n "${GIT_TESTING_COMMAND_COMPLETION:-}"
+ then
+ printf "%s" "${GIT_TESTING_COMMAND_COMPLETION}"
+ else
+ git help -a|egrep '^ [a-zA-Z0-9]'
+ fi
+}
+
+__git_list_all_commands ()
+{
+ local i IFS=" "$'\n'
+ for i in $(__git_commands)
+ do
+ case $i in
+ *--*) : helper pattern;;
+ *) echo $i;;
+ esac
+ done
+}
+
+__git_all_commands=
+__git_compute_all_commands ()
+{
+ test -n "$__git_all_commands" ||
+ __git_all_commands=$(__git_list_all_commands)
+}
+
+__git_list_porcelain_commands ()
+{
+ local i IFS=" "$'\n'
+ __git_compute_all_commands
+ for i in $__git_all_commands
+ do
+ case $i in
+ *--*) : helper pattern;;
+ applymbox) : ask gittus;;
+ applypatch) : ask gittus;;
+ archimport) : import;;
+ cat-file) : plumbing;;
+ check-attr) : plumbing;;
+ check-ignore) : plumbing;;
+ check-ref-format) : plumbing;;
+ checkout-index) : plumbing;;
+ commit-tree) : plumbing;;
+ count-objects) : infrequent;;
+ credential-cache) : credentials helper;;
+ credential-store) : credentials helper;;
+ cvsexportcommit) : export;;
+ cvsimport) : import;;
+ cvsserver) : daemon;;
+ daemon) : daemon;;
+ diff-files) : plumbing;;
+ diff-index) : plumbing;;
+ diff-tree) : plumbing;;
+ fast-import) : import;;
+ fast-export) : export;;
+ fsck-objects) : plumbing;;
+ fetch-pack) : plumbing;;
+ fmt-merge-msg) : plumbing;;
+ for-each-ref) : plumbing;;
+ hash-object) : plumbing;;
+ http-*) : transport;;
+ index-pack) : plumbing;;
+ init-db) : deprecated;;
+ local-fetch) : plumbing;;
+ lost-found) : infrequent;;
+ ls-files) : plumbing;;
+ ls-remote) : plumbing;;
+ ls-tree) : plumbing;;
+ mailinfo) : plumbing;;
+ mailsplit) : plumbing;;
+ merge-*) : plumbing;;
+ mktree) : plumbing;;
+ mktag) : plumbing;;
+ pack-objects) : plumbing;;
+ pack-redundant) : plumbing;;
+ pack-refs) : plumbing;;
+ parse-remote) : plumbing;;
+ patch-id) : plumbing;;
+ peek-remote) : plumbing;;
+ prune) : plumbing;;
+ prune-packed) : plumbing;;
+ quiltimport) : import;;
+ read-tree) : plumbing;;
+ receive-pack) : plumbing;;
+ remote-*) : transport;;
+ repo-config) : deprecated;;
+ rerere) : plumbing;;
+ rev-list) : plumbing;;
+ rev-parse) : plumbing;;
+ runstatus) : plumbing;;
+ sh-setup) : internal;;
+ shell) : daemon;;
+ show-ref) : plumbing;;
+ send-pack) : plumbing;;
+ show-index) : plumbing;;
+ ssh-*) : transport;;
+ stripspace) : plumbing;;
+ symbolic-ref) : plumbing;;
+ tar-tree) : deprecated;;
+ unpack-file) : plumbing;;
+ unpack-objects) : plumbing;;
+ update-index) : plumbing;;
+ update-ref) : plumbing;;
+ update-server-info) : daemon;;
+ upload-archive) : plumbing;;
+ upload-pack) : plumbing;;
+ write-tree) : plumbing;;
+ var) : infrequent;;
+ verify-pack) : infrequent;;
+ verify-tag) : plumbing;;
+ *) echo $i;;
+ esac
+ done
+}
+
+__git_porcelain_commands=
+__git_compute_porcelain_commands ()
+{
+ __git_compute_all_commands
+ test -n "$__git_porcelain_commands" ||
+ __git_porcelain_commands=$(__git_list_porcelain_commands)
+}
+
+__git_pretty_aliases ()
+{
+ local i IFS=$'\n'
+ for i in $(git --git-dir="$(__gitdir)" config --get-regexp "pretty\..*" 2>/dev/null); do
+ case "$i" in
+ pretty.*)
+ i="${i#pretty.}"
+ echo "${i/ */}"
+ ;;
+ esac
+ done
+}
+
+__git_aliases ()
+{
+ local i IFS=$'\n'
+ for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do
+ case "$i" in
+ alias.*)
+ i="${i#alias.}"
+ echo "${i/ */}"
+ ;;
+ esac
+ done
+}
+
+# __git_aliased_command requires 1 argument
+__git_aliased_command ()
+{
+ local word cmdline=$(git --git-dir="$(__gitdir)" \
+ config --get "alias.$1")
+ for word in $cmdline; do
+ case "$word" in
+ \!gitk|gitk)
+ echo "gitk"
+ return
+ ;;
+ \!*) : shell command alias ;;
+ -*) : option ;;
+ *=*) : setting env ;;
+ git) : git itself ;;
+ *)
+ echo "$word"
+ return
+ esac
+ done
+}
+
+# __git_find_on_cmdline requires 1 argument
+__git_find_on_cmdline ()
+{
+ local word subcommand c=1
+ while [ $c -lt $cword ]; do
+ word="${words[c]}"
+ for subcommand in $1; do
+ if [ "$subcommand" = "$word" ]; then
+ echo "$subcommand"
+ return
+ fi
+ done
+ ((c++))
+ done
+}
+
+__git_has_doubledash ()
+{
+ local c=1
+ while [ $c -lt $cword ]; do
+ if [ "--" = "${words[c]}" ]; then
+ return 0
+ fi
+ ((c++))
+ done
+ return 1
+}
+
+# Try to count non option arguments passed on the command line for the
+# specified git command.
+# When options are used, it is necessary to use the special -- option to
+# tell the implementation were non option arguments begin.
+# XXX this can not be improved, since options can appear everywhere, as
+# an example:
+# git mv x -n y
+#
+# __git_count_arguments requires 1 argument: the git command executed.
+__git_count_arguments ()
+{
+ local word i c=0
+
+ # Skip "git" (first argument)
+ for ((i=1; i < ${#words[@]}; i++)); do
+ word="${words[i]}"
+
+ case "$word" in
+ --)
+ # Good; we can assume that the following are only non
+ # option arguments.
+ ((c = 0))
+ ;;
+ "$1")
+ # Skip the specified git command and discard git
+ # main options
+ ((c = 0))
+ ;;
+ ?*)
+ ((c++))
+ ;;
+ esac
+ done
+
+ printf "%d" $c
+}
+
+__git_whitespacelist="nowarn warn error error-all fix"
+
+_git_am ()
+{
+ local dir="$(__gitdir)"
+ if [ -d "$dir"/rebase-apply ]; then
+ __gitcomp "--skip --continue --resolved --abort"
+ return
+ fi
+ case "$cur" in
+ --whitespace=*)
+ __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
+ return
+ ;;
+ --*)
+ __gitcomp "
+ --3way --committer-date-is-author-date --ignore-date
+ --ignore-whitespace --ignore-space-change
+ --interactive --keep --no-utf8 --signoff --utf8
+ --whitespace= --scissors
+ "
+ return
+ esac
+}
+
+_git_apply ()
+{
+ case "$cur" in
+ --whitespace=*)
+ __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
+ return
+ ;;
+ --*)
+ __gitcomp "
+ --stat --numstat --summary --check --index
+ --cached --index-info --reverse --reject --unidiff-zero
+ --apply --no-add --exclude=
+ --ignore-whitespace --ignore-space-change
+ --whitespace= --inaccurate-eof --verbose
+ "
+ return
+ esac
+}
+
+_git_add ()
+{
+ case "$cur" in
+ --*)
+ __gitcomp "
+ --interactive --refresh --patch --update --dry-run
+ --ignore-errors --intent-to-add
+ "
+ return
+ esac
+
+ # XXX should we check for --update and --all options ?
+ __git_complete_index_file "--others --modified"
+}
+
+_git_archive ()
+{
+ case "$cur" in
+ --format=*)
+ __gitcomp "$(git archive --list)" "" "${cur##--format=}"
+ return
+ ;;
+ --remote=*)
+ __gitcomp_nl "$(__git_remotes)" "" "${cur##--remote=}"
+ return
+ ;;
+ --*)
+ __gitcomp "
+ --format= --list --verbose
+ --prefix= --remote= --exec=
+ "
+ return
+ ;;
+ esac
+ __git_complete_file
+}
+
+_git_bisect ()
+{
+ __git_has_doubledash && return
+
+ local subcommands="start bad good skip reset visualize replay log run"
+ local subcommand="$(__git_find_on_cmdline "$subcommands")"
+ if [ -z "$subcommand" ]; then
+ if [ -f "$(__gitdir)"/BISECT_START ]; then
+ __gitcomp "$subcommands"
+ else
+ __gitcomp "replay start"
+ fi
+ return
+ fi
+
+ case "$subcommand" in
+ bad|good|reset|skip|start)
+ __gitcomp_nl "$(__git_refs)"
+ ;;
+ *)
+ ;;
+ esac
+}
+
+_git_branch ()
+{
+ local i c=1 only_local_ref="n" has_r="n"
+
+ while [ $c -lt $cword ]; do
+ i="${words[c]}"
+ case "$i" in
+ -d|-m) only_local_ref="y" ;;
+ -r) has_r="y" ;;
+ esac
+ ((c++))
+ done
+
+ case "$cur" in
+ --set-upstream-to=*)
+ __gitcomp "$(__git_refs)" "" "${cur##--set-upstream-to=}"
+ ;;
+ --*)
+ __gitcomp "
+ --color --no-color --verbose --abbrev= --no-abbrev
+ --track --no-track --contains --merged --no-merged
+ --set-upstream-to= --edit-description --list
+ --unset-upstream
+ "
+ ;;
+ *)
+ if [ $only_local_ref = "y" -a $has_r = "n" ]; then
+ __gitcomp_nl "$(__git_heads)"
+ else
+ __gitcomp_nl "$(__git_refs)"
+ fi
+ ;;
+ esac
+}
+
+_git_bundle ()
+{
+ local cmd="${words[2]}"
+ case "$cword" in
+ 2)
+ __gitcomp "create list-heads verify unbundle"
+ ;;
+ 3)
+ # looking for a file
+ ;;
+ *)
+ case "$cmd" in
+ create)
+ __git_complete_revlist
+ ;;
+ esac
+ ;;
+ esac
+}
+
+_git_checkout ()
+{
+ __git_has_doubledash && return
+
+ case "$cur" in
+ --conflict=*)
+ __gitcomp "diff3 merge" "" "${cur##--conflict=}"
+ ;;
+ --*)
+ __gitcomp "
+ --quiet --ours --theirs --track --no-track --merge
+ --conflict= --orphan --patch
+ "
+ ;;
+ *)
+ # check if --track, --no-track, or --no-guess was specified
+ # if so, disable DWIM mode
+ local flags="--track --no-track --no-guess" track=1
+ if [ -n "$(__git_find_on_cmdline "$flags")" ]; then
+ track=''
+ fi
+ __gitcomp_nl "$(__git_refs '' $track)"
+ ;;
+ esac
+}
+
+_git_cherry ()
+{
+ __gitcomp "$(__git_refs)"
+}
+
+_git_cherry_pick ()
+{
+ local dir="$(__gitdir)"
+ if [ -f "$dir"/CHERRY_PICK_HEAD ]; then
+ __gitcomp "--continue --quit --abort"
+ return
+ fi
+ case "$cur" in
+ --*)
+ __gitcomp "--edit --no-commit --signoff --strategy= --mainline"
+ ;;
+ *)
+ __gitcomp_nl "$(__git_refs)"
+ ;;
+ esac
+}
+
+_git_clean ()
+{
+ case "$cur" in
+ --*)
+ __gitcomp "--dry-run --quiet"
+ return
+ ;;
+ esac
+
+ # XXX should we check for -x option ?
+ __git_complete_index_file "--others"
+}
+
+_git_clone ()
+{
+ case "$cur" in
+ --*)
+ __gitcomp "
+ --local
+ --no-hardlinks
+ --shared
+ --reference
+ --quiet
+ --no-checkout
+ --bare
+ --mirror
+ --origin
+ --upload-pack
+ --template=
+ --depth
+ --single-branch
+ --branch
+ "
+ return
+ ;;
+ esac
+}
+
+_git_commit ()
+{
+ case "$prev" in
+ -c|-C)
+ __gitcomp_nl "$(__git_refs)" "" "${cur}"
+ return
+ ;;
+ esac
+
+ case "$cur" in
+ --cleanup=*)
+ __gitcomp "default strip verbatim whitespace
+ " "" "${cur##--cleanup=}"
+ return
+ ;;
+ --reuse-message=*|--reedit-message=*|\
+ --fixup=*|--squash=*)
+ __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
+ return
+ ;;
+ --untracked-files=*)
+ __gitcomp "all no normal" "" "${cur##--untracked-files=}"
+ return
+ ;;
+ --*)
+ __gitcomp "
+ --all --author= --signoff --verify --no-verify
+ --edit --no-edit
+ --amend --include --only --interactive
+ --dry-run --reuse-message= --reedit-message=
+ --reset-author --file= --message= --template=
+ --cleanup= --untracked-files --untracked-files=
+ --verbose --quiet --fixup= --squash=
+ "
+ return
+ esac
+
+ if git rev-parse --verify --quiet HEAD >/dev/null; then
+ __git_complete_index_file "--committable"
+ else
+ # This is the first commit
+ __git_complete_index_file "--cached"
+ fi
+}
+
+_git_describe ()
+{
+ case "$cur" in
+ --*)
+ __gitcomp "
+ --all --tags --contains --abbrev= --candidates=
+ --exact-match --debug --long --match --always
+ "
+ return
+ esac
+ __gitcomp_nl "$(__git_refs)"
+}
+
+__git_diff_algorithms="myers minimal patience histogram"
+
+__git_diff_common_options="--stat --numstat --shortstat --summary
+ --patch-with-stat --name-only --name-status --color
+ --no-color --color-words --no-renames --check
+ --full-index --binary --abbrev --diff-filter=
+ --find-copies-harder
+ --text --ignore-space-at-eol --ignore-space-change
+ --ignore-all-space --exit-code --quiet --ext-diff
+ --no-ext-diff
+ --no-prefix --src-prefix= --dst-prefix=
+ --inter-hunk-context=
+ --patience --histogram --minimal
+ --raw
+ --dirstat --dirstat= --dirstat-by-file
+ --dirstat-by-file= --cumulative
+ --diff-algorithm=
+"
+
+_git_diff ()
+{
+ __git_has_doubledash && return
+
+ case "$cur" in
+ --diff-algorithm=*)
+ __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
+ return
+ ;;
+ --*)
+ __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
+ --base --ours --theirs --no-index
+ $__git_diff_common_options
+ "
+ return
+ ;;
+ esac
+ __git_complete_revlist_file
+}
+
+__git_mergetools_common="diffuse ecmerge emerge kdiff3 meld opendiff
+ tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc3 codecompare
+"
+
+_git_difftool ()
+{
+ __git_has_doubledash && return
+
+ case "$cur" in
+ --tool=*)
+ __gitcomp "$__git_mergetools_common kompare" "" "${cur##--tool=}"
+ return
+ ;;
+ --*)
+ __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex
+ --base --ours --theirs
+ --no-renames --diff-filter= --find-copies-harder
+ --relative --ignore-submodules
+ --tool="
+ return
+ ;;
+ esac
+ __git_complete_revlist_file
+}
+
+__git_fetch_options="
+ --quiet --verbose --append --upload-pack --force --keep --depth=
+ --tags --no-tags --all --prune --dry-run
+"
+
+_git_fetch ()
+{
+ case "$cur" in
+ --*)
+ __gitcomp "$__git_fetch_options"
+ return
+ ;;
+ esac
+ __git_complete_remote_or_refspec
+}
+
+__git_format_patch_options="
+ --stdout --attach --no-attach --thread --thread= --no-thread
+ --numbered --start-number --numbered-files --keep-subject --signoff
+ --signature --no-signature --in-reply-to= --cc= --full-index --binary
+ --not --all --cover-letter --no-prefix --src-prefix= --dst-prefix=
+ --inline --suffix= --ignore-if-in-upstream --subject-prefix=
+ --output-directory --reroll-count --to= --quiet --notes
+"
+
+_git_format_patch ()
+{
+ case "$cur" in
+ --thread=*)
+ __gitcomp "
+ deep shallow
+ " "" "${cur##--thread=}"
+ return
+ ;;
+ --*)
+ __gitcomp "$__git_format_patch_options"
+ return
+ ;;
+ esac
+ __git_complete_revlist
+}
+
+_git_fsck ()
+{
+ case "$cur" in
+ --*)
+ __gitcomp "
+ --tags --root --unreachable --cache --no-reflogs --full
+ --strict --verbose --lost-found
+ "
+ return
+ ;;
+ esac
+}
+
+_git_gc ()
+{
+ case "$cur" in
+ --*)
+ __gitcomp "--prune --aggressive"
+ return
+ ;;
+ esac
+}
+
+_git_gitk ()
+{
+ _gitk
+}
+
+__git_match_ctag() {
+ awk "/^${1////\\/}/ { print \$1 }" "$2"
+}
+
+_git_grep ()
+{
+ __git_has_doubledash && return
+
+ case "$cur" in
+ --*)
+ __gitcomp "
+ --cached
+ --text --ignore-case --word-regexp --invert-match
+ --full-name --line-number
+ --extended-regexp --basic-regexp --fixed-strings
+ --perl-regexp
+ --files-with-matches --name-only
+ --files-without-match
+ --max-depth
+ --count
+ --and --or --not --all-match
+ "
+ return
+ ;;
+ esac
+
+ case "$cword,$prev" in
+ 2,*|*,-*)
+ if test -r tags; then
+ __gitcomp_nl "$(__git_match_ctag "$cur" tags)"
+ return
+ fi
+ ;;
+ esac
+
+ __gitcomp_nl "$(__git_refs)"
+}
+
+_git_help ()
+{
+ case "$cur" in
+ --*)
+ __gitcomp "--all --info --man --web"
+ return
+ ;;
+ esac
+ __git_compute_all_commands
+ __gitcomp "$__git_all_commands $(__git_aliases)
+ attributes cli core-tutorial cvs-migration
+ diffcore gitk glossary hooks ignore modules
+ namespaces repository-layout tutorial tutorial-2
+ workflows
+ "
+}
+
+_git_init ()
+{
+ case "$cur" in
+ --shared=*)
+ __gitcomp "
+ false true umask group all world everybody
+ " "" "${cur##--shared=}"
+ return
+ ;;
+ --*)
+ __gitcomp "--quiet --bare --template= --shared --shared="
+ return
+ ;;
+ esac
+}
+
+_git_ls_files ()
+{
+ case "$cur" in
+ --*)
+ __gitcomp "--cached --deleted --modified --others --ignored
+ --stage --directory --no-empty-directory --unmerged
+ --killed --exclude= --exclude-from=
+ --exclude-per-directory= --exclude-standard
+ --error-unmatch --with-tree= --full-name
+ --abbrev --ignored --exclude-per-directory
+ "
+ return
+ ;;
+ esac
+
+ # XXX ignore options like --modified and always suggest all cached
+ # files.
+ __git_complete_index_file "--cached"
+}
+
+_git_ls_remote ()
+{
+ __gitcomp_nl "$(__git_remotes)"
+}
+
+_git_ls_tree ()
+{
+ __git_complete_file
+}
+
+# Options that go well for log, shortlog and gitk
+__git_log_common_options="
+ --not --all
+ --branches --tags --remotes
+ --first-parent --merges --no-merges
+ --max-count=
+ --max-age= --since= --after=
+ --min-age= --until= --before=
+ --min-parents= --max-parents=
+ --no-min-parents --no-max-parents
+"
+# Options that go well for log and gitk (not shortlog)
+__git_log_gitk_options="
+ --dense --sparse --full-history
+ --simplify-merges --simplify-by-decoration
+ --left-right --notes --no-notes
+"
+# Options that go well for log and shortlog (not gitk)
+__git_log_shortlog_options="
+ --author= --committer= --grep=
+ --all-match
+"
+
+__git_log_pretty_formats="oneline short medium full fuller email raw format:"
+__git_log_date_formats="relative iso8601 rfc2822 short local default raw"
+
+_git_log ()
+{
+ __git_has_doubledash && return
+
+ local g="$(git rev-parse --git-dir 2>/dev/null)"
+ local merge=""
+ if [ -f "$g/MERGE_HEAD" ]; then
+ merge="--merge"
+ fi
+ case "$cur" in
+ --pretty=*|--format=*)
+ __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
+ " "" "${cur#*=}"
+ return
+ ;;
+ --date=*)
+ __gitcomp "$__git_log_date_formats" "" "${cur##--date=}"
+ return
+ ;;
+ --decorate=*)
+ __gitcomp "long short" "" "${cur##--decorate=}"
+ return
+ ;;
+ --*)
+ __gitcomp "
+ $__git_log_common_options
+ $__git_log_shortlog_options
+ $__git_log_gitk_options
+ --root --topo-order --date-order --reverse
+ --follow --full-diff
+ --abbrev-commit --abbrev=
+ --relative-date --date=
+ --pretty= --format= --oneline
+ --cherry-pick
+ --graph
+ --decorate --decorate=
+ --walk-reflogs
+ --parents --children
+ $merge
+ $__git_diff_common_options
+ --pickaxe-all --pickaxe-regex
+ "
+ return
+ ;;
+ esac
+ __git_complete_revlist
+}
+
+__git_merge_options="
+ --no-commit --no-stat --log --no-log --squash --strategy
+ --commit --stat --no-squash --ff --no-ff --ff-only --edit --no-edit
+"
+
+_git_merge ()
+{
+ __git_complete_strategy && return
+
+ case "$cur" in
+ --*)
+ __gitcomp "$__git_merge_options"
+ return
+ esac
+ __gitcomp_nl "$(__git_refs)"
+}
+
+_git_mergetool ()
+{
+ case "$cur" in
+ --tool=*)
+ __gitcomp "$__git_mergetools_common tortoisemerge" "" "${cur##--tool=}"
+ return
+ ;;
+ --*)
+ __gitcomp "--tool="
+ return
+ ;;
+ esac
+}
+
+_git_merge_base ()
+{
+ __gitcomp_nl "$(__git_refs)"
+}
+
+_git_mv ()
+{
+ case "$cur" in
+ --*)
+ __gitcomp "--dry-run"
+ return
+ ;;
+ esac
+
+ if [ $(__git_count_arguments "mv") -gt 0 ]; then
+ # We need to show both cached and untracked files (including
+ # empty directories) since this may not be the last argument.
+ __git_complete_index_file "--cached --others --directory"
+ else
+ __git_complete_index_file "--cached"
+ fi
+}
+
+_git_name_rev ()
+{
+ __gitcomp "--tags --all --stdin"
+}
+
+_git_notes ()
+{
+ local subcommands='add append copy edit list prune remove show'
+ local subcommand="$(__git_find_on_cmdline "$subcommands")"
+
+ case "$subcommand,$cur" in
+ ,--*)
+ __gitcomp '--ref'
+ ;;
+ ,*)
+ case "$prev" in
+ --ref)
+ __gitcomp_nl "$(__git_refs)"
+ ;;
+ *)
+ __gitcomp "$subcommands --ref"
+ ;;
+ esac
+ ;;
+ add,--reuse-message=*|append,--reuse-message=*|\
+ add,--reedit-message=*|append,--reedit-message=*)
+ __gitcomp_nl "$(__git_refs)" "" "${cur#*=}"
+ ;;
+ add,--*|append,--*)
+ __gitcomp '--file= --message= --reedit-message=
+ --reuse-message='
+ ;;
+ copy,--*)
+ __gitcomp '--stdin'
+ ;;
+ prune,--*)
+ __gitcomp '--dry-run --verbose'
+ ;;
+ prune,*)
+ ;;
+ *)
+ case "$prev" in
+ -m|-F)
+ ;;
+ *)
+ __gitcomp_nl "$(__git_refs)"
+ ;;
+ esac
+ ;;
+ esac
+}
+
+_git_pull ()
+{
+ __git_complete_strategy && return
+
+ case "$cur" in
+ --*)
+ __gitcomp "
+ --rebase --no-rebase
+ $__git_merge_options
+ $__git_fetch_options
+ "
+ return
+ ;;
+ esac
+ __git_complete_remote_or_refspec
+}
+
+_git_push ()
+{
+ case "$prev" in
+ --repo)
+ __gitcomp_nl "$(__git_remotes)"
+ return
+ esac
+ case "$cur" in
+ --repo=*)
+ __gitcomp_nl "$(__git_remotes)" "" "${cur##--repo=}"
+ return
+ ;;
+ --*)
+ __gitcomp "
+ --all --mirror --tags --dry-run --force --verbose
+ --receive-pack= --repo= --set-upstream
+ "
+ return
+ ;;
+ esac
+ __git_complete_remote_or_refspec
+}
+
+_git_rebase ()
+{
+ local dir="$(__gitdir)"
+ if [ -d "$dir"/rebase-apply ] || [ -d "$dir"/rebase-merge ]; then
+ __gitcomp "--continue --skip --abort"
+ return
+ fi
+ __git_complete_strategy && return
+ case "$cur" in
+ --whitespace=*)
+ __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
+ return
+ ;;
+ --*)
+ __gitcomp "
+ --onto --merge --strategy --interactive
+ --preserve-merges --stat --no-stat
+ --committer-date-is-author-date --ignore-date
+ --ignore-whitespace --whitespace=
+ --autosquash
+ "
+
+ return
+ esac
+ __gitcomp_nl "$(__git_refs)"
+}
+
+_git_reflog ()
+{
+ local subcommands="show delete expire"
+ local subcommand="$(__git_find_on_cmdline "$subcommands")"
+
+ if [ -z "$subcommand" ]; then
+ __gitcomp "$subcommands"
+ else
+ __gitcomp_nl "$(__git_refs)"
+ fi
+}
+
+__git_send_email_confirm_options="always never auto cc compose"
+__git_send_email_suppresscc_options="author self cc bodycc sob cccmd body all"
+
+_git_send_email ()
+{
+ case "$cur" in
+ --confirm=*)
+ __gitcomp "
+ $__git_send_email_confirm_options
+ " "" "${cur##--confirm=}"
+ return
+ ;;
+ --suppress-cc=*)
+ __gitcomp "
+ $__git_send_email_suppresscc_options
+ " "" "${cur##--suppress-cc=}"
+
+ return
+ ;;
+ --smtp-encryption=*)
+ __gitcomp "ssl tls" "" "${cur##--smtp-encryption=}"
+ return
+ ;;
+ --thread=*)
+ __gitcomp "
+ deep shallow
+ " "" "${cur##--thread=}"
+ return
+ ;;
+ --*)
+ __gitcomp "--annotate --bcc --cc --cc-cmd --chain-reply-to
+ --compose --confirm= --dry-run --envelope-sender
+ --from --identity
+ --in-reply-to --no-chain-reply-to --no-signed-off-by-cc
+ --no-suppress-from --no-thread --quiet
+ --signed-off-by-cc --smtp-pass --smtp-server
+ --smtp-server-port --smtp-encryption= --smtp-user
+ --subject --suppress-cc= --suppress-from --thread --to
+ --validate --no-validate
+ $__git_format_patch_options"
+ return
+ ;;
+ esac
+ __git_complete_revlist
+}
+
+_git_stage ()
+{
+ _git_add
+}
+
+__git_config_get_set_variables ()
+{
+ local prevword word config_file= c=$cword
+ while [ $c -gt 1 ]; do
+ word="${words[c]}"
+ case "$word" in
+ --system|--global|--local|--file=*)
+ config_file="$word"
+ break
+ ;;
+ -f|--file)
+ config_file="$word $prevword"
+ break
+ ;;
+ esac
+ prevword=$word
+ c=$((--c))
+ done
+
+ git --git-dir="$(__gitdir)" config $config_file --list 2>/dev/null |
+ while read -r line
+ do
+ case "$line" in
+ *.*=*)
+ echo "${line/=*/}"
+ ;;
+ esac
+ done
+}
+
+_git_config ()
+{
+ case "$prev" in
+ branch.*.remote|branch.*.pushremote)
+ __gitcomp_nl "$(__git_remotes)"
+ return
+ ;;
+ branch.*.merge)
+ __gitcomp_nl "$(__git_refs)"
+ return
+ ;;
+ branch.*.rebase)
+ __gitcomp "false true"
+ return
+ ;;
+ remote.pushdefault)
+ __gitcomp_nl "$(__git_remotes)"
+ return
+ ;;
+ remote.*.fetch)
+ local remote="${prev#remote.}"
+ remote="${remote%.fetch}"
+ if [ -z "$cur" ]; then
+ __gitcomp_nl "refs/heads/" "" "" ""
+ return
+ fi
+ __gitcomp_nl "$(__git_refs_remotes "$remote")"
+ return
+ ;;
+ remote.*.push)
+ local remote="${prev#remote.}"
+ remote="${remote%.push}"
+ __gitcomp_nl "$(git --git-dir="$(__gitdir)" \
+ for-each-ref --format='%(refname):%(refname)' \
+ refs/heads)"
+ return
+ ;;
+ pull.twohead|pull.octopus)
+ __git_compute_merge_strategies
+ __gitcomp "$__git_merge_strategies"
+ return
+ ;;
+ color.branch|color.diff|color.interactive|\
+ color.showbranch|color.status|color.ui)
+ __gitcomp "always never auto"
+ return
+ ;;
+ color.pager)
+ __gitcomp "false true"
+ return
+ ;;
+ color.*.*)
+ __gitcomp "
+ normal black red green yellow blue magenta cyan white
+ bold dim ul blink reverse
+ "
+ return
+ ;;
+ diff.submodule)
+ __gitcomp "log short"
+ return
+ ;;
+ help.format)
+ __gitcomp "man info web html"
+ return
+ ;;
+ log.date)
+ __gitcomp "$__git_log_date_formats"
+ return
+ ;;
+ sendemail.aliasesfiletype)
+ __gitcomp "mutt mailrc pine elm gnus"
+ return
+ ;;
+ sendemail.confirm)
+ __gitcomp "$__git_send_email_confirm_options"
+ return
+ ;;
+ sendemail.suppresscc)
+ __gitcomp "$__git_send_email_suppresscc_options"
+ return
+ ;;
+ --get|--get-all|--unset|--unset-all)
+ __gitcomp_nl "$(__git_config_get_set_variables)"
+ return
+ ;;
+ *.*)
+ return
+ ;;
+ esac
+ case "$cur" in
+ --*)
+ __gitcomp "
+ --system --global --local --file=
+ --list --replace-all
+ --get --get-all --get-regexp
+ --add --unset --unset-all
+ --remove-section --rename-section
+ "
+ return
+ ;;
+ branch.*.*)
+ local pfx="${cur%.*}." cur_="${cur##*.}"
+ __gitcomp "remote pushremote merge mergeoptions rebase" "$pfx" "$cur_"
+ return
+ ;;
+ branch.*)
+ local pfx="${cur%.*}." cur_="${cur#*.}"
+ __gitcomp_nl "$(__git_heads)" "$pfx" "$cur_" "."
+ return
+ ;;
+ guitool.*.*)
+ local pfx="${cur%.*}." cur_="${cur##*.}"
+ __gitcomp "
+ argprompt cmd confirm needsfile noconsole norescan
+ prompt revprompt revunmerged title
+ " "$pfx" "$cur_"
+ return
+ ;;
+ difftool.*.*)
+ local pfx="${cur%.*}." cur_="${cur##*.}"
+ __gitcomp "cmd path" "$pfx" "$cur_"
+ return
+ ;;
+ man.*.*)
+ local pfx="${cur%.*}." cur_="${cur##*.}"
+ __gitcomp "cmd path" "$pfx" "$cur_"
+ return
+ ;;
+ mergetool.*.*)
+ local pfx="${cur%.*}." cur_="${cur##*.}"
+ __gitcomp "cmd path trustExitCode" "$pfx" "$cur_"
+ return
+ ;;
+ pager.*)
+ local pfx="${cur%.*}." cur_="${cur#*.}"
+ __git_compute_all_commands
+ __gitcomp_nl "$__git_all_commands" "$pfx" "$cur_"
+ return
+ ;;
+ remote.*.*)
+ local pfx="${cur%.*}." cur_="${cur##*.}"
+ __gitcomp "
+ url proxy fetch push mirror skipDefaultUpdate
+ receivepack uploadpack tagopt pushurl
+ " "$pfx" "$cur_"
+ return
+ ;;
+ remote.*)
+ local pfx="${cur%.*}." cur_="${cur#*.}"
+ __gitcomp_nl "$(__git_remotes)" "$pfx" "$cur_" "."
+ return
+ ;;
+ url.*.*)
+ local pfx="${cur%.*}." cur_="${cur##*.}"
+ __gitcomp "insteadOf pushInsteadOf" "$pfx" "$cur_"
+ return
+ ;;
+ esac
+ __gitcomp "
+ add.ignoreErrors
+ advice.commitBeforeMerge
+ advice.detachedHead
+ advice.implicitIdentity
+ advice.pushNonFastForward
+ advice.resolveConflict
+ advice.statusHints
+ alias.
+ am.keepcr
+ apply.ignorewhitespace
+ apply.whitespace
+ branch.autosetupmerge
+ branch.autosetuprebase
+ browser.
+ clean.requireForce
+ color.branch
+ color.branch.current
+ color.branch.local
+ color.branch.plain
+ color.branch.remote
+ color.decorate.HEAD
+ color.decorate.branch
+ color.decorate.remoteBranch
+ color.decorate.stash
+ color.decorate.tag
+ color.diff
+ color.diff.commit
+ color.diff.frag
+ color.diff.func
+ color.diff.meta
+ color.diff.new
+ color.diff.old
+ color.diff.plain
+ color.diff.whitespace
+ color.grep
+ color.grep.context
+ color.grep.filename
+ color.grep.function
+ color.grep.linenumber
+ color.grep.match
+ color.grep.selected
+ color.grep.separator
+ color.interactive
+ color.interactive.error
+ color.interactive.header
+ color.interactive.help
+ color.interactive.prompt
+ color.pager
+ color.showbranch
+ color.status
+ color.status.added
+ color.status.changed
+ color.status.header
+ color.status.nobranch
+ color.status.untracked
+ color.status.updated
+ color.ui
+ commit.status
+ commit.template
+ core.abbrev
+ core.askpass
+ core.attributesfile
+ core.autocrlf
+ core.bare
+ core.bigFileThreshold
+ core.compression
+ core.createObject
+ core.deltaBaseCacheLimit
+ core.editor
+ core.eol
+ core.excludesfile
+ core.fileMode
+ core.fsyncobjectfiles
+ core.gitProxy
+ core.ignoreCygwinFSTricks
+ core.ignoreStat
+ core.ignorecase
+ core.logAllRefUpdates
+ core.loosecompression
+ core.notesRef
+ core.packedGitLimit
+ core.packedGitWindowSize
+ core.pager
+ core.preferSymlinkRefs
+ core.preloadindex
+ core.quotepath
+ core.repositoryFormatVersion
+ core.safecrlf
+ core.sharedRepository
+ core.sparseCheckout
+ core.symlinks
+ core.trustctime
+ core.warnAmbiguousRefs
+ core.whitespace
+ core.worktree
+ diff.autorefreshindex
+ diff.external
+ diff.ignoreSubmodules
+ diff.mnemonicprefix
+ diff.noprefix
+ diff.renameLimit
+ diff.renames
+ diff.statGraphWidth
+ diff.submodule
+ diff.suppressBlankEmpty
+ diff.tool
+ diff.wordRegex
+ diff.algorithm
+ difftool.
+ difftool.prompt
+ fetch.recurseSubmodules
+ fetch.unpackLimit
+ format.attach
+ format.cc
+ format.headers
+ format.numbered
+ format.pretty
+ format.signature
+ format.signoff
+ format.subjectprefix
+ format.suffix
+ format.thread
+ format.to
+ gc.
+ gc.aggressiveWindow
+ gc.auto
+ gc.autopacklimit
+ gc.packrefs
+ gc.pruneexpire
+ gc.reflogexpire
+ gc.reflogexpireunreachable
+ gc.rerereresolved
+ gc.rerereunresolved
+ gitcvs.allbinary
+ gitcvs.commitmsgannotation
+ gitcvs.dbTableNamePrefix
+ gitcvs.dbdriver
+ gitcvs.dbname
+ gitcvs.dbpass
+ gitcvs.dbuser
+ gitcvs.enabled
+ gitcvs.logfile
+ gitcvs.usecrlfattr
+ guitool.
+ gui.blamehistoryctx
+ gui.commitmsgwidth
+ gui.copyblamethreshold
+ gui.diffcontext
+ gui.encoding
+ gui.fastcopyblame
+ gui.matchtrackingbranch
+ gui.newbranchtemplate
+ gui.pruneduringfetch
+ gui.spellingdictionary
+ gui.trustmtime
+ help.autocorrect
+ help.browser
+ help.format
+ http.lowSpeedLimit
+ http.lowSpeedTime
+ http.maxRequests
+ http.minSessions
+ http.noEPSV
+ http.postBuffer
+ http.proxy
+ http.sslCAInfo
+ http.sslCAPath
+ http.sslCert
+ http.sslCertPasswordProtected
+ http.sslKey
+ http.sslVerify
+ http.useragent
+ i18n.commitEncoding
+ i18n.logOutputEncoding
+ imap.authMethod
+ imap.folder
+ imap.host
+ imap.pass
+ imap.port
+ imap.preformattedHTML
+ imap.sslverify
+ imap.tunnel
+ imap.user
+ init.templatedir
+ instaweb.browser
+ instaweb.httpd
+ instaweb.local
+ instaweb.modulepath
+ instaweb.port
+ interactive.singlekey
+ log.date
+ log.decorate
+ log.showroot
+ mailmap.file
+ man.
+ man.viewer
+ merge.
+ merge.conflictstyle
+ merge.log
+ merge.renameLimit
+ merge.renormalize
+ merge.stat
+ merge.tool
+ merge.verbosity
+ mergetool.
+ mergetool.keepBackup
+ mergetool.keepTemporaries
+ mergetool.prompt
+ notes.displayRef
+ notes.rewrite.
+ notes.rewrite.amend
+ notes.rewrite.rebase
+ notes.rewriteMode
+ notes.rewriteRef
+ pack.compression
+ pack.deltaCacheLimit
+ pack.deltaCacheSize
+ pack.depth
+ pack.indexVersion
+ pack.packSizeLimit
+ pack.threads
+ pack.window
+ pack.windowMemory
+ pager.
+ pretty.
+ pull.octopus
+ pull.twohead
+ push.default
+ rebase.autosquash
+ rebase.stat
+ receive.autogc
+ receive.denyCurrentBranch
+ receive.denyDeleteCurrent
+ receive.denyDeletes
+ receive.denyNonFastForwards
+ receive.fsckObjects
+ receive.unpackLimit
+ receive.updateserverinfo
+ remote.pushdefault
+ remotes.
+ repack.usedeltabaseoffset
+ rerere.autoupdate
+ rerere.enabled
+ sendemail.
+ sendemail.aliasesfile
+ sendemail.aliasfiletype
+ sendemail.bcc
+ sendemail.cc
+ sendemail.cccmd
+ sendemail.chainreplyto
+ sendemail.confirm
+ sendemail.envelopesender
+ sendemail.from
+ sendemail.identity
+ sendemail.multiedit
+ sendemail.signedoffbycc
+ sendemail.smtpdomain
+ sendemail.smtpencryption
+ sendemail.smtppass
+ sendemail.smtpserver
+ sendemail.smtpserveroption
+ sendemail.smtpserverport
+ sendemail.smtpuser
+ sendemail.suppresscc
+ sendemail.suppressfrom
+ sendemail.thread
+ sendemail.to
+ sendemail.validate
+ showbranch.default
+ status.relativePaths
+ status.showUntrackedFiles
+ status.submodulesummary
+ submodule.
+ tar.umask
+ transfer.unpackLimit
+ url.
+ user.email
+ user.name
+ user.signingkey
+ web.browser
+ branch. remote.
+ "
+}
+
+_git_remote ()
+{
+ local subcommands="add rename remove set-head set-branches set-url show prune update"
+ local subcommand="$(__git_find_on_cmdline "$subcommands")"
+ if [ -z "$subcommand" ]; then
+ __gitcomp "$subcommands"
+ return
+ fi
+
+ case "$subcommand" in
+ rename|remove|set-url|show|prune)
+ __gitcomp_nl "$(__git_remotes)"
+ ;;
+ set-head|set-branches)
+ __git_complete_remote_or_refspec
+ ;;
+ update)
+ local i c='' IFS=$'\n'
+ for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
+ i="${i#remotes.}"
+ c="$c ${i/ */}"
+ done
+ __gitcomp "$c"
+ ;;
+ *)
+ ;;
+ esac
+}
+
+_git_replace ()
+{
+ __gitcomp_nl "$(__git_refs)"
+}
+
+_git_reset ()
+{
+ __git_has_doubledash && return
+
+ case "$cur" in
+ --*)
+ __gitcomp "--merge --mixed --hard --soft --patch"
+ return
+ ;;
+ esac
+ __gitcomp_nl "$(__git_refs)"
+}
+
+_git_revert ()
+{
+ case "$cur" in
+ --*)
+ __gitcomp "--edit --mainline --no-edit --no-commit --signoff"
+ return
+ ;;
+ esac
+ __gitcomp_nl "$(__git_refs)"
+}
+
+_git_rm ()
+{
+ case "$cur" in
+ --*)
+ __gitcomp "--cached --dry-run --ignore-unmatch --quiet"
+ return
+ ;;
+ esac
+
+ __git_complete_index_file "--cached"
+}
+
+_git_shortlog ()
+{
+ __git_has_doubledash && return
+
+ case "$cur" in
+ --*)
+ __gitcomp "
+ $__git_log_common_options
+ $__git_log_shortlog_options
+ --numbered --summary
+ "
+ return
+ ;;
+ esac
+ __git_complete_revlist
+}
+
+_git_show ()
+{
+ __git_has_doubledash && return
+
+ case "$cur" in
+ --pretty=*|--format=*)
+ __gitcomp "$__git_log_pretty_formats $(__git_pretty_aliases)
+ " "" "${cur#*=}"
+ return
+ ;;
+ --diff-algorithm=*)
+ __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}"
+ return
+ ;;
+ --*)
+ __gitcomp "--pretty= --format= --abbrev-commit --oneline
+ $__git_diff_common_options
+ "
+ return
+ ;;
+ esac
+ __git_complete_revlist_file
+}
+
+_git_show_branch ()
+{
+ case "$cur" in
+ --*)
+ __gitcomp "
+ --all --remotes --topo-order --current --more=
+ --list --independent --merge-base --no-name
+ --color --no-color
+ --sha1-name --sparse --topics --reflog
+ "
+ return
+ ;;
+ esac
+ __git_complete_revlist
+}
+
+_git_stash ()
+{
+ local save_opts='--keep-index --no-keep-index --quiet --patch'
+ local subcommands='save list show apply clear drop pop create branch'
+ local subcommand="$(__git_find_on_cmdline "$subcommands")"
+ if [ -z "$subcommand" ]; then
+ case "$cur" in
+ --*)
+ __gitcomp "$save_opts"
+ ;;
+ *)
+ if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
+ __gitcomp "$subcommands"
+ fi
+ ;;
+ esac
+ else
+ case "$subcommand,$cur" in
+ save,--*)
+ __gitcomp "$save_opts"
+ ;;
+ apply,--*|pop,--*)
+ __gitcomp "--index --quiet"
+ ;;
+ show,--*|drop,--*|branch,--*)
+ ;;
+ show,*|apply,*|drop,*|pop,*|branch,*)
+ __gitcomp_nl "$(git --git-dir="$(__gitdir)" stash list \
+ | sed -n -e 's/:.*//p')"
+ ;;
+ *)
+ ;;
+ esac
+ fi
+}
+
+_git_submodule ()
+{
+ __git_has_doubledash && return
+
+ local subcommands="add status init deinit update summary foreach sync"
+ if [ -z "$(__git_find_on_cmdline "$subcommands")" ]; then
+ case "$cur" in
+ --*)
+ __gitcomp "--quiet --cached"
+ ;;
+ *)
+ __gitcomp "$subcommands"
+ ;;
+ esac
+ return
+ fi
+}
+
+_git_svn ()
+{
+ local subcommands="
+ init fetch clone rebase dcommit log find-rev
+ set-tree commit-diff info create-ignore propget
+ proplist show-ignore show-externals branch tag blame
+ migrate mkdirs reset gc
+ "
+ local subcommand="$(__git_find_on_cmdline "$subcommands")"
+ if [ -z "$subcommand" ]; then
+ __gitcomp "$subcommands"
+ else
+ local remote_opts="--username= --config-dir= --no-auth-cache"
+ local fc_opts="
+ --follow-parent --authors-file= --repack=
+ --no-metadata --use-svm-props --use-svnsync-props
+ --log-window-size= --no-checkout --quiet
+ --repack-flags --use-log-author --localtime
+ --ignore-paths= --include-paths= $remote_opts
+ "
+ local init_opts="
+ --template= --shared= --trunk= --tags=
+ --branches= --stdlayout --minimize-url
+ --no-metadata --use-svm-props --use-svnsync-props
+ --rewrite-root= --prefix= --use-log-author
+ --add-author-from $remote_opts
+ "
+ local cmt_opts="
+ --edit --rmdir --find-copies-harder --copy-similarity=
+ "
+
+ case "$subcommand,$cur" in
+ fetch,--*)
+ __gitcomp "--revision= --fetch-all $fc_opts"
+ ;;
+ clone,--*)
+ __gitcomp "--revision= $fc_opts $init_opts"
+ ;;
+ init,--*)
+ __gitcomp "$init_opts"
+ ;;
+ dcommit,--*)
+ __gitcomp "
+ --merge --strategy= --verbose --dry-run
+ --fetch-all --no-rebase --commit-url
+ --revision --interactive $cmt_opts $fc_opts
+ "
+ ;;
+ set-tree,--*)
+ __gitcomp "--stdin $cmt_opts $fc_opts"
+ ;;
+ create-ignore,--*|propget,--*|proplist,--*|show-ignore,--*|\
+ show-externals,--*|mkdirs,--*)
+ __gitcomp "--revision="
+ ;;
+ log,--*)
+ __gitcomp "
+ --limit= --revision= --verbose --incremental
+ --oneline --show-commit --non-recursive
+ --authors-file= --color
+ "
+ ;;
+ rebase,--*)
+ __gitcomp "
+ --merge --verbose --strategy= --local
+ --fetch-all --dry-run $fc_opts
+ "
+ ;;
+ commit-diff,--*)
+ __gitcomp "--message= --file= --revision= $cmt_opts"
+ ;;
+ info,--*)
+ __gitcomp "--url"
+ ;;
+ branch,--*)
+ __gitcomp "--dry-run --message --tag"
+ ;;
+ tag,--*)
+ __gitcomp "--dry-run --message"
+ ;;
+ blame,--*)
+ __gitcomp "--git-format"
+ ;;
+ migrate,--*)
+ __gitcomp "
+ --config-dir= --ignore-paths= --minimize
+ --no-auth-cache --username=
+ "
+ ;;
+ reset,--*)
+ __gitcomp "--revision= --parent"
+ ;;
+ *)
+ ;;
+ esac
+ fi
+}
+
+_git_tag ()
+{
+ local i c=1 f=0
+ while [ $c -lt $cword ]; do
+ i="${words[c]}"
+ case "$i" in
+ -d|-v)
+ __gitcomp_nl "$(__git_tags)"
+ return
+ ;;
+ -f)
+ f=1
+ ;;
+ esac
+ ((c++))
+ done
+
+ case "$prev" in
+ -m|-F)
+ ;;
+ -*|tag)
+ if [ $f = 1 ]; then
+ __gitcomp_nl "$(__git_tags)"
+ fi
+ ;;
+ *)
+ __gitcomp_nl "$(__git_refs)"
+ ;;
+ esac
+}
+
+_git_whatchanged ()
+{
+ _git_log
+}
+
+__git_main ()
+{
+ local i c=1 command __git_dir
+
+ while [ $c -lt $cword ]; do
+ i="${words[c]}"
+ case "$i" in
+ --git-dir=*) __git_dir="${i#--git-dir=}" ;;
+ --bare) __git_dir="." ;;
+ --help) command="help"; break ;;
+ -c) c=$((++c)) ;;
+ -*) ;;
+ *) command="$i"; break ;;
+ esac
+ ((c++))
+ done
+
+ if [ -z "$command" ]; then
+ case "$cur" in
+ --*) __gitcomp "
+ --paginate
+ --no-pager
+ --git-dir=
+ --bare
+ --version
+ --exec-path
+ --exec-path=
+ --html-path
+ --info-path
+ --work-tree=
+ --namespace=
+ --no-replace-objects
+ --help
+ "
+ ;;
+ *) __git_compute_porcelain_commands
+ __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
+ esac
+ return
+ fi
+
+ local completion_func="_git_${command//-/_}"
+ declare -f $completion_func >/dev/null && $completion_func && return
+
+ local expansion=$(__git_aliased_command "$command")
+ if [ -n "$expansion" ]; then
+ completion_func="_git_${expansion//-/_}"
+ declare -f $completion_func >/dev/null && $completion_func
+ fi
+}
+
+__gitk_main ()
+{
+ __git_has_doubledash && return
+
+ local g="$(__gitdir)"
+ local merge=""
+ if [ -f "$g/MERGE_HEAD" ]; then
+ merge="--merge"
+ fi
+ case "$cur" in
+ --*)
+ __gitcomp "
+ $__git_log_common_options
+ $__git_log_gitk_options
+ $merge
+ "
+ return
+ ;;
+ esac
+ __git_complete_revlist
+}
+
+if [[ -n ${ZSH_VERSION-} ]]; then
+ echo "WARNING: this script is deprecated, please see git-completion.zsh" 1>&2
+
+ autoload -U +X compinit && compinit
+
+ __gitcomp ()
+ {
+ emulate -L zsh
+
+ local cur_="${3-$cur}"
+
+ case "$cur_" in
+ --*=)
+ ;;
+ *)
+ local c IFS=$' \t\n'
+ local -a array
+ for c in ${=1}; do
+ c="$c${4-}"
+ case $c in
+ --*=*|*.) ;;
+ *) c="$c " ;;
+ esac
+ array+=("$c")
+ done
+ compset -P '*[=:]'
+ compadd -Q -S '' -p "${2-}" -a -- array && _ret=0
+ ;;
+ esac
+ }
+
+ __gitcomp_nl ()
+ {
+ emulate -L zsh
+
+ local IFS=$'\n'
+ compset -P '*[=:]'
+ compadd -Q -S "${4- }" -p "${2-}" -- ${=1} && _ret=0
+ }
+
+ __gitcomp_file ()
+ {
+ emulate -L zsh
+
+ local IFS=$'\n'
+ compset -P '*[=:]'
+ compadd -Q -p "${2-}" -f -- ${=1} && _ret=0
+ }
+
+ _git ()
+ {
+ local _ret=1 cur cword prev
+ cur=${words[CURRENT]}
+ prev=${words[CURRENT-1]}
+ let cword=CURRENT-1
+ emulate ksh -c __${service}_main
+ let _ret && _default && _ret=0
+ return _ret
+ }
+
+ compdef _git git gitk
+ return
+fi
+
+__git_func_wrap ()
+{
+ local cur words cword prev
+ _get_comp_words_by_ref -n =: cur words cword prev
+ $1
+}
+
+# Setup completion for certain functions defined above by setting common
+# variables and workarounds.
+# This is NOT a public function; use at your own risk.
+__git_complete ()
+{
+ local wrapper="__git_wrap${2}"
+ eval "$wrapper () { __git_func_wrap $2 ; }"
+ complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
+ || complete -o default -o nospace -F $wrapper $1
+}
+
+# wrapper for backwards compatibility
+_git ()
+{
+ __git_wrap__git_main
+}
+
+# wrapper for backwards compatibility
+_gitk ()
+{
+ __git_wrap__gitk_main
+}
+
+__git_complete git __git_main
+__git_complete gitk __gitk_main
+
+# The following are necessary only for Cygwin, and only are needed
+# when the user has tab-completed the executable name and consequently
+# included the '.exe' suffix.
+#
+if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
+__git_complete git.exe __git_main
+fi
diff --git a/.gitconfig b/.gitconfig
index e428e45..a1c95ab 100644
--- a/.gitconfig
+++ b/.gitconfig
@@ -1,23 +1,25 @@
[user]
name = Nate Wiger
email = nwiger@gmail.com
[alias]
ci = commit
co = checkout
st = status
up = pull
pu = push -u origin
rv = checkout --
br = branch -a
hard = reset --hard origin/master
hist = log --since=1.day --relative-date --stat
mine = log --since=1.day --relative-date --stat --committer=nateware
+ undo = reset HEAD --
+ last = log -1 HEAD
#pu = !"git fetch origin -v; git fetch upstream -v; git merge upstream/master"
[color]
diff = auto
status = auto
branch = auto
[push]
- default = simple
+ default = current
[core]
excludesfile = /Users/nateware/.gitignore_global
|
nateware/dotfiles
|
9316c71102408822a24f9d3f6ae48cc3906378d7
|
aws setup, macports and fuck()
|
diff --git a/.bash_profile b/.bash_profile
index fcad07b..794063b 100644
--- a/.bash_profile
+++ b/.bash_profile
@@ -1,37 +1,40 @@
# Must source manually
[ -f $HOME/.bashrc ] && . $HOME/.bashrc
# Colors!
c1="\033["
c2="m"
c_normal="${c1}0${c2}"
c_bold="${c1}1${c2}"
c_black="${c1}0;30${c2}"
c_blue="${c1}0;34${c2}"
c_green="${c1}0;32${c2}"
c_cyan="${c1}0;36${c2}"
c_red="${c1}0;31${c2}"
c_purple="${c1}0;35${c2}"
c_brown="${c1}0;33${c2}"
c_gray="${c1}0;37${c2}"
c_dark_gray="${c1}1;30${c2}"
c_bold_blue="${c1}1;34${c2}"
c_bold_green="${c1}1;32${c2}"
c_bold_cyan="${c1}1;36${c2}"
c_bold_red="${c1}1;31${c2}"
c_bold_purple="${c1}1;35${c2}"
c_bold_yellow="${c1}1;33${c2}"
c_bold_white="${c1}1;37${c2}"
# Prompt
#export PS1='[\u@\h:\W]\$ '
#export PS1="[$c_green\u$c_normal@$c_purple\h$c_normal:$c_blue\W$c_normal]\$ "
export PS1="[\W]\$ "
printf $c_red
type ruby
printf $c_normal
### Added by the Heroku Toolbelt
export PATH="/usr/local/heroku/bin:$PATH"
+
+# MacPorts Installer addition
+export PATH=/opt/local/bin:/opt/local/sbin:$PATH
diff --git a/.bashrc b/.bashrc
index 3100b17..32ec5ab 100644
--- a/.bashrc
+++ b/.bashrc
@@ -1,184 +1,225 @@
# ~/.bashrc
umask 022
# Add to PATH but only if it exists
add_path () {
err=0
for p
do
if [ -d $p ]; then
PATH="$p:$PATH"
else
err=1
fi
done
return $err
}
# Add to LD_LIB_PATH adjusting for platform
add_lib () {
if [ "$OS" = Darwin ]; then
export DYLD_LIBRARY_PATH="$lib:$DYLD_LIBRARY_PATH"
else
export LD_LIBRARY_PATH="$lib:$DYLD_LIBRARY_PATH"
fi
return 0
}
# Guess
add_path_and_lib () {
if add_path "$1"; then
lib=${1%/bin}/lib
add_lib $lib
else
return 1
fi
}
# Aliases
alias ls='\ls -Gh'
alias ll='ls -al'
alias wget='curl -LO'
alias ldd='otool -L'
alias rsync='\rsync --exclude=.svn --exclude=.git --exclude=RCS'
alias vi='vim -b'
# Don't want to install rubydocs - TOO SLOW!
alias gi='gem install --no-ri --no-rdoc'
alias bi='bundle --without=production install'
alias bu='bundle --without=production update'
alias be='bundle exec'
alias ga='git ci -a -m'
alias gd='git pu && git push -f dev'
alias gp='git pu'
gap () {
ga "$*" && gp
}
gapd () {
gap "$*" && cap dev deploy
}
# Change to workspace directory
wd () {
if [ $# -eq 0 ]; then
pushd "$HOME/Workspace"
else
pushd "$HOME/Workspace/$1"*
fi
}
# Platform goodness
export OS=`uname`
[ "$OS" = Darwin ] && export JAVA_HOME=/Library/Java/Home
+# Remember add_path unshifts, so the one you want first should be last
+add_path \
+ /usr/local/git/bin \
+ /usr/local/bin \
+ /opt/local/sbin \
+ /opt/local/bin \
+ $HOME/sbin \
+ $HOME/bin
+
# For ruby version manager
[ -s $HOME/.rvm/scripts/rvm ] && . $HOME/.rvm/scripts/rvm
+# Load node version manager
+[ -s $HOME/.nvm/nvm.sh ] && . $HOME/.nvm/nvm.sh
+
+# rbenv
+#if add_path $HOME/.rbenv/bin; then
+ #eval "$(rbenv init -)"
+#fi
+
# For Jeweler
export JEWELER_OPTS="--bundler --bacon --create-repo --user-name 'Nate Wiger' --user-email 'nwiger@gmail.com' --github-username nateware"
# ImageMagick
add_path_and_lib /usr/local/ImageMagick/bin
# MySQL
add_path_and_lib /usr/local/mysql/bin
+# Self-contained Postgres.app
+add_path /Applications/Postgres.app/Contents/MacOS/bin
+
# MongoDB
add_path /usr/local/mongodb/bin
# Amazon EC2 CLI tools (official locations)
export EC2_HOME=/usr/local/ec2-api-tools
add_path "$EC2_HOME/bin" || unset EC2_HOME
export RDS_HOME=/usr/local/rds-cli
add_path "$RDS_HOME/bin" || unset RDS_HOME
ec2region () {
if [ $# -eq 1 ]; then
export EC2_REGION=$1
export EC2_URL="http://ec2.$EC2_REGION.amazonaws.com"
+ export AWS_DEFAULT_REGION=$EC2_REGION
ec2setenv
fi
tty -s && echo "EC2_REGION=$EC2_REGION"
}
+ec2acct () {
+ if [ $# -ge 1 ]; then
+ export EC2_ACCOUNT=$1
+ if [ $# -eq 2 ]; then
+ ec2region $2
+ else
+ ec2setenv
+ fi
+ fi
+ tty -s && echo "EC2_ACCOUNT=$EC2_ACCOUNT"
+}
+
# Amazon EC2 gems
ec2setenv () {
- export EC2_CERT=`ls -1 $HOME/.ec2/cert-* | head -1`
+ export AWS_ACCESS_KEY_ID=`cat $HOME/.ec2/$EC2_ACCOUNT/access_key_id.txt`
+ export AWS_SECRET_ACCESS_KEY=`cat $HOME/.ec2/$EC2_ACCOUNT/secret_access_key.txt`
+
+ export EC2_CERT=`ls -1 $HOME/.ec2/$EC2_ACCOUNT/cert-* | head -1`
export EC2_PRIVATE_KEY=`echo $EC2_CERT | sed 's/cert-\(.*\).pem/pk-\1.pem/'`
# New paradigm for ec2 is to use the custom keypair, but username may change
- export EC2_ROOT_KEY="$HOME/.ec2/root-$EC2_REGION.pem"
+ export EC2_ROOT_KEY="$HOME/.ec2/$EC2_ACCOUNT/root-$EC2_REGION.pem"
if [ ! -f "$EC2_ROOT_KEY" ]; then
- echo "Warning: EC2 key does not exist: $EC_ROOT_KEY" >&2
+ echo "Warning: EC2 key does not exist: $EC2_ROOT_KEY" >&2
fi
# To override root, use ubuntu@ or ec2-user@ or whatever
ssh_cmd="ssh -i $EC2_ROOT_KEY -o StrictHostKeyChecking=no -l root"
alias ash=$ssh_cmd
alias async="rsync -av -e '$ssh_cmd'"
}
# Set default EC2 region
-[ -d "$HOME/.ec2" ] && ec2region us-west-2
+if [ -d "$HOME/.ec2" ]; then
+ ec2acct work us-west-2
+fi
# Use garnaat's unified CLI
-export AWS_ACCESS_KEY_ID=`cat $HOME/.ec2/access_key_id.txt`
-export AWS_SECRET_ACCESS_KEY=`cat $HOME/.ec2/secret_access_key.txt`
complete -C aws_completer aws # bash tab completion
+paws (){
+ aws "$@" | ruby -rjson -rawesome_print -e "ap JSON.parse(STDIN.read)"
+}
+complete -C aws_completer paws # bash tab completion
# Easy unzipping
untar () {
if [ "$#" -eq 0 ]; then
echo "Usage: untar files ..." >&2
return 1
fi
for f
do
case $f in
*.zip) unzip $f;;
*.tar.gz|*.tgz) tar xzvf $f;;
*.tar.bz|*.tbz) bunzip -c $f | tar xvf -;;
*) echo "Unsupported file type: $f" >&2;;
esac
done
}
-
+# shortcut to kill processes that tend to suck
+fuck () {
+ local pn=
+ case "$1" in
+ chr*) pn="Google Chrome";;
+ cisc*) pn="Cisco AnyConnect Secure Mobility Client";;
+ esac
+ killall $pn
+ sleep 2
+ killall $pn
+ sleep 3
+ killall -9 $pn
+}
# Postgres
if add_path /Library/PostgreSQL/9.0/bin; then
. /Library/PostgreSQL/9.0/pg_env.sh
fi
-# Remember add_path prefixes, so the one you want first should be last
-add_path \
- /usr/local/pgsql/bin \
- /usr/local/git/bin \
- /usr/local/bin \
- /opt/local/sbin \
- /opt/local/bin \
- $HOME/sbin \
- $HOME/bin
-
export JVA=209.40.197.81
alias jva="ssh -l janetvanarsdale $JVA"
alias rjva="ssh -l root $JVA"
# Still needed for old games
export ORACLE_HOME="/usr/local/oracle/10.2.0.4/client"
if [ -d "$ORACLE_HOME" ]; then
add_path "$ORACLE_HOME/bin"
add_lib "$ORACLE_HOME/lib"
export TNS_ADMIN="$HOME/tnsadmin" # Directory
export NLS_LANG=".AL32UTF8"
fi
# For fucking with "go" the language
export GOROOT=$HOME/Workspace/go
export GOOS=darwin
export GOARCH=386
export GOBIN=$HOME/bin
-PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
diff --git a/.gitconfig b/.gitconfig
index 6b5b0b9..e428e45 100644
--- a/.gitconfig
+++ b/.gitconfig
@@ -1,21 +1,23 @@
[user]
name = Nate Wiger
email = nwiger@gmail.com
[alias]
ci = commit
co = checkout
st = status
up = pull
pu = push -u origin
rv = checkout --
br = branch -a
hard = reset --hard origin/master
hist = log --since=1.day --relative-date --stat
mine = log --since=1.day --relative-date --stat --committer=nateware
#pu = !"git fetch origin -v; git fetch upstream -v; git merge upstream/master"
[color]
diff = auto
status = auto
branch = auto
[push]
default = simple
+[core]
+ excludesfile = /Users/nateware/.gitignore_global
|
nateware/dotfiles
|
7de8859da3b67c0e297acdbe32705437c7621f2e
|
no dylib
|
diff --git a/.bashrc b/.bashrc
index 3100b17..c5bb1e9 100644
--- a/.bashrc
+++ b/.bashrc
@@ -1,184 +1,187 @@
# ~/.bashrc
umask 022
# Add to PATH but only if it exists
add_path () {
err=0
for p
do
if [ -d $p ]; then
PATH="$p:$PATH"
else
err=1
fi
done
return $err
}
# Add to LD_LIB_PATH adjusting for platform
add_lib () {
+ [ -d "$1" ] || return 0
if [ "$OS" = Darwin ]; then
- export DYLD_LIBRARY_PATH="$lib:$DYLD_LIBRARY_PATH"
+ export DYLD_LIBRARY_PATH="$1:$DYLD_LIBRARY_PATH"
else
- export LD_LIBRARY_PATH="$lib:$DYLD_LIBRARY_PATH"
+ export LD_LIBRARY_PATH="$1:$DYLD_LIBRARY_PATH"
fi
return 0
}
# Guess
add_path_and_lib () {
if add_path "$1"; then
lib=${1%/bin}/lib
add_lib $lib
else
return 1
fi
}
# Aliases
alias ls='\ls -Gh'
alias ll='ls -al'
alias wget='curl -LO'
alias ldd='otool -L'
alias rsync='\rsync --exclude=.svn --exclude=.git --exclude=RCS'
alias vi='vim -b'
# Don't want to install rubydocs - TOO SLOW!
alias gi='gem install --no-ri --no-rdoc'
alias bi='bundle --without=production install'
alias bu='bundle --without=production update'
alias be='bundle exec'
alias ga='git ci -a -m'
alias gd='git pu && git push -f dev'
alias gp='git pu'
gap () {
ga "$*" && gp
}
gapd () {
gap "$*" && cap dev deploy
}
# Change to workspace directory
wd () {
if [ $# -eq 0 ]; then
pushd "$HOME/Workspace"
else
pushd "$HOME/Workspace/$1"*
fi
}
# Platform goodness
export OS=`uname`
[ "$OS" = Darwin ] && export JAVA_HOME=/Library/Java/Home
# For ruby version manager
[ -s $HOME/.rvm/scripts/rvm ] && . $HOME/.rvm/scripts/rvm
# For Jeweler
export JEWELER_OPTS="--bundler --bacon --create-repo --user-name 'Nate Wiger' --user-email 'nwiger@gmail.com' --github-username nateware"
# ImageMagick
add_path_and_lib /usr/local/ImageMagick/bin
# MySQL
-add_path_and_lib /usr/local/mysql/bin
+add_path /usr/local/mysql/bin
# MongoDB
add_path /usr/local/mongodb/bin
# Amazon EC2 CLI tools (official locations)
export EC2_HOME=/usr/local/ec2-api-tools
add_path "$EC2_HOME/bin" || unset EC2_HOME
export RDS_HOME=/usr/local/rds-cli
add_path "$RDS_HOME/bin" || unset RDS_HOME
ec2region () {
if [ $# -eq 1 ]; then
export EC2_REGION=$1
export EC2_URL="http://ec2.$EC2_REGION.amazonaws.com"
ec2setenv
fi
tty -s && echo "EC2_REGION=$EC2_REGION"
}
# Amazon EC2 gems
ec2setenv () {
export EC2_CERT=`ls -1 $HOME/.ec2/cert-* | head -1`
export EC2_PRIVATE_KEY=`echo $EC2_CERT | sed 's/cert-\(.*\).pem/pk-\1.pem/'`
# New paradigm for ec2 is to use the custom keypair, but username may change
export EC2_ROOT_KEY="$HOME/.ec2/root-$EC2_REGION.pem"
if [ ! -f "$EC2_ROOT_KEY" ]; then
echo "Warning: EC2 key does not exist: $EC_ROOT_KEY" >&2
fi
# To override root, use ubuntu@ or ec2-user@ or whatever
ssh_cmd="ssh -i $EC2_ROOT_KEY -o StrictHostKeyChecking=no -l root"
alias ash=$ssh_cmd
alias async="rsync -av -e '$ssh_cmd'"
}
# Set default EC2 region
[ -d "$HOME/.ec2" ] && ec2region us-west-2
# Use garnaat's unified CLI
export AWS_ACCESS_KEY_ID=`cat $HOME/.ec2/access_key_id.txt`
export AWS_SECRET_ACCESS_KEY=`cat $HOME/.ec2/secret_access_key.txt`
complete -C aws_completer aws # bash tab completion
# Easy unzipping
untar () {
if [ "$#" -eq 0 ]; then
echo "Usage: untar files ..." >&2
return 1
fi
for f
do
case $f in
*.zip) unzip $f;;
*.tar.gz|*.tgz) tar xzvf $f;;
*.tar.bz|*.tbz) bunzip -c $f | tar xvf -;;
*) echo "Unsupported file type: $f" >&2;;
esac
done
}
# Postgres
if add_path /Library/PostgreSQL/9.0/bin; then
. /Library/PostgreSQL/9.0/pg_env.sh
fi
# Remember add_path prefixes, so the one you want first should be last
add_path \
/usr/local/pgsql/bin \
/usr/local/git/bin \
/usr/local/bin \
/opt/local/sbin \
/opt/local/bin \
$HOME/sbin \
$HOME/bin
export JVA=209.40.197.81
alias jva="ssh -l janetvanarsdale $JVA"
alias rjva="ssh -l root $JVA"
# Still needed for old games
export ORACLE_HOME="/usr/local/oracle/10.2.0.4/client"
if [ -d "$ORACLE_HOME" ]; then
- add_path "$ORACLE_HOME/bin"
- add_lib "$ORACLE_HOME/lib"
+ add_path_and_lib "$ORACLE_HOME/bin"
export TNS_ADMIN="$HOME/tnsadmin" # Directory
export NLS_LANG=".AL32UTF8"
fi
# For fucking with "go" the language
export GOROOT=$HOME/Workspace/go
export GOOS=darwin
export GOARCH=386
export GOBIN=$HOME/bin
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
+
+### Added by the Heroku Toolbelt
+export PATH="/usr/local/heroku/bin:$PATH"
|
nateware/dotfiles
|
c63fd8ce76f3a63a8429222bb0086cbd95cdf953
|
use aws-cli and remove github token
|
diff --git a/.bashrc b/.bashrc
index 17f50b0..22c46ca 100644
--- a/.bashrc
+++ b/.bashrc
@@ -1,186 +1,184 @@
# ~/.bashrc
umask 022
# Add to PATH but only if it exists
add_path () {
err=0
for p
do
if [ -d $p ]; then
PATH="$p:$PATH"
else
err=1
fi
done
return $err
}
# Add to LD_LIB_PATH adjusting for platform
add_lib () {
if [ "$OS" = Darwin ]; then
export DYLD_LIBRARY_PATH="$lib:$DYLD_LIBRARY_PATH"
else
export LD_LIBRARY_PATH="$lib:$DYLD_LIBRARY_PATH"
fi
return 0
}
# Guess
add_path_and_lib () {
if add_path "$1"; then
lib=${1%/bin}/lib
add_lib $lib
else
return 1
fi
}
# Aliases
alias ls='\ls -Gh'
alias ll='ls -al'
alias wget='curl -LO'
alias ldd='otool -L'
alias rsync='\rsync --exclude=.svn --exclude=.git --exclude=RCS'
alias vi='vim -b'
# Don't want to install rubydocs - TOO SLOW!
alias gi='gem install --no-ri --no-rdoc'
alias bi='bundle --without=production install'
alias bu='bundle --without=production update'
alias be='bundle exec'
alias ga='git ci -a -m'
alias gd='git pu && git push -f dev'
alias gp='git pu'
gap () {
ga "$*" && gp
}
gapd () {
gap "$*" && cap dev deploy
}
# Change to workspace directory
wd () {
if [ $# -eq 0 ]; then
pushd "$HOME/Workspace"
else
pushd "$HOME/Workspace/$1"*
fi
}
# Platform goodness
export OS=`uname`
[ "$OS" = Darwin ] && export JAVA_HOME=/Library/Java/Home
# For ruby version manager
[ -s $HOME/.rvm/scripts/rvm ] && . $HOME/.rvm/scripts/rvm
# For Jeweler
-export JEWELER_OPTS="--bundler --bacon --create-repo --user-name 'Nate Wiger' --user-email 'nate@wiger.org' --github-username nateware --github-token '`cat $HOME/.github-token`'"
+export JEWELER_OPTS="--bundler --bacon --create-repo --user-name 'Nate Wiger' --user-email 'nwiger@gmail.com' --github-username nateware"
# ImageMagick
add_path_and_lib /usr/local/ImageMagick/bin
# MySQL
add_path_and_lib /usr/local/mysql/bin
# MongoDB
add_path /usr/local/mongodb/bin
# Amazon EC2 CLI tools (official locations)
export EC2_HOME=/usr/local/ec2-api-tools
add_path "$EC2_HOME/bin" || unset EC2_HOME
export RDS_HOME=/usr/local/rds-cli
add_path "$RDS_HOME/bin" || unset RDS_HOME
ec2region () {
if [ $# -eq 1 ]; then
export EC2_REGION=$1
export EC2_URL="http://ec2.$EC2_REGION.amazonaws.com"
ec2setenv
fi
tty -s && echo "EC2_REGION=$EC2_REGION"
}
# Amazon EC2 gems
ec2setenv () {
export EC2_CERT=`ls -1 $HOME/.ec2/cert-*`
export EC2_PRIVATE_KEY=`echo $EC2_CERT | sed 's/cert-\(.*\).pem/pk-\1.pem/'`
# New paradigm for ec2 is to use the custom keypair, but username may change
export EC2_ROOT_KEY="$HOME/.ec2/root-$EC2_REGION.pem"
if [ ! -f "$EC2_ROOT_KEY" ]; then
echo "Warning: EC2 key does not exist: $EC_ROOT_KEY" >&2
fi
# To override root, use ubuntu@ or ec2-user@ or whatever
ssh_cmd="ssh -i $EC2_ROOT_KEY -o StrictHostKeyChecking=no -l root"
alias ash=$ssh_cmd
alias async="rsync -av -e '$ssh_cmd'"
}
# Set default EC2 region
[ -d "$HOME/.ec2" ] && ec2region us-west-2
-# Use the github aws-tools repo if available
-if [ -f "$HOME/Workspace/aws-cli-updater/aws-cli-env.sh" ]; then
- export AWS_ACCESS_KEY_ID=`cat $HOME/.ec2/access_key_id.txt`
- export AWS_SECRET_ACCESS_KEY=`cat $HOME/.ec2/secret_access_key.txt`
- . "$HOME/Workspace/aws-cli-updater/aws-cli-env.sh"
-fi
+# Use garnaat's unified CLI
+export AWS_ACCESS_KEY_ID=`cat $HOME/.ec2/access_key_id.txt`
+export AWS_SECRET_ACCESS_KEY=`cat $HOME/.ec2/secret_access_key.txt`
+complete -C aws_completer aws # bash tab completion
# Easy unzipping
untar () {
if [ "$#" -eq 0 ]; then
echo "Usage: untar files ..." >&2
return 1
fi
for f
do
case $f in
*.zip) unzip $f;;
*.tar.gz|*.tgz) tar xzvf $f;;
*.tar.bz|*.tbz) bunzip -c $f | tar xvf -;;
*) echo "Unsupported file type: $f" >&2;;
esac
done
}
# Postgres
if add_path /Library/PostgreSQL/9.0/bin; then
. /Library/PostgreSQL/9.0/pg_env.sh
fi
# Remember add_path prefixes, so the one you want first should be last
add_path \
/usr/local/pgsql/bin \
/usr/local/git/bin \
/usr/local/bin \
/opt/local/sbin \
/opt/local/bin \
$HOME/sbin \
$HOME/bin
export JVA=209.40.197.81
alias jva="ssh -l janetvanarsdale $JVA"
alias rjva="ssh -l root $JVA"
# Still needed for old games
export ORACLE_HOME="/usr/local/oracle/10.2.0.4/client"
if [ -d "$ORACLE_HOME" ]; then
add_path "$ORACLE_HOME/bin"
add_lib "$ORACLE_HOME/lib"
export TNS_ADMIN="$HOME/tnsadmin" # Directory
export NLS_LANG=".AL32UTF8"
fi
# For fucking with "go" the language
export GOROOT=$HOME/Workspace/go
export GOOS=darwin
export GOARCH=386
export GOBIN=$HOME/bin
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
|
nateware/dotfiles
|
1af5f07cce7986a64ad7771078aa5ee2c004d01b
|
tweaks
|
diff --git a/.bashrc b/.bashrc
index 57576c9..17f50b0 100644
--- a/.bashrc
+++ b/.bashrc
@@ -1,176 +1,186 @@
# ~/.bashrc
umask 022
# Add to PATH but only if it exists
add_path () {
err=0
for p
do
if [ -d $p ]; then
PATH="$p:$PATH"
else
err=1
fi
done
return $err
}
# Add to LD_LIB_PATH adjusting for platform
add_lib () {
if [ "$OS" = Darwin ]; then
export DYLD_LIBRARY_PATH="$lib:$DYLD_LIBRARY_PATH"
else
export LD_LIBRARY_PATH="$lib:$DYLD_LIBRARY_PATH"
fi
return 0
}
# Guess
add_path_and_lib () {
if add_path "$1"; then
lib=${1%/bin}/lib
add_lib $lib
else
return 1
fi
}
# Aliases
alias ls='\ls -Gh'
alias ll='ls -al'
alias wget='curl -LO'
alias ldd='otool -L'
alias rsync='\rsync --exclude=.svn --exclude=.git --exclude=RCS'
alias vi='vim -b'
# Don't want to install rubydocs - TOO SLOW!
alias gi='gem install --no-ri --no-rdoc'
alias bi='bundle --without=production install'
alias bu='bundle --without=production update'
alias be='bundle exec'
alias ga='git ci -a -m'
alias gd='git pu && git push -f dev'
alias gp='git pu'
gap () {
ga "$*" && gp
}
gapd () {
gap "$*" && cap dev deploy
}
# Change to workspace directory
wd () {
if [ $# -eq 0 ]; then
pushd "$HOME/Workspace"
else
pushd "$HOME/Workspace/$1"*
fi
}
# Platform goodness
export OS=`uname`
[ "$OS" = Darwin ] && export JAVA_HOME=/Library/Java/Home
# For ruby version manager
[ -s $HOME/.rvm/scripts/rvm ] && . $HOME/.rvm/scripts/rvm
# For Jeweler
export JEWELER_OPTS="--bundler --bacon --create-repo --user-name 'Nate Wiger' --user-email 'nate@wiger.org' --github-username nateware --github-token '`cat $HOME/.github-token`'"
# ImageMagick
add_path_and_lib /usr/local/ImageMagick/bin
# MySQL
add_path_and_lib /usr/local/mysql/bin
# MongoDB
add_path /usr/local/mongodb/bin
# Amazon EC2 CLI tools (official locations)
export EC2_HOME=/usr/local/ec2-api-tools
add_path "$EC2_HOME/bin" || unset EC2_HOME
export RDS_HOME=/usr/local/rds-cli
add_path "$RDS_HOME/bin" || unset RDS_HOME
ec2region () {
if [ $# -eq 1 ]; then
export EC2_REGION=$1
export EC2_URL="http://ec2.$EC2_REGION.amazonaws.com"
ec2setenv
fi
- echo "EC2_REGION=$EC2_REGION"
+ tty -s && echo "EC2_REGION=$EC2_REGION"
}
# Amazon EC2 gems
ec2setenv () {
export EC2_CERT=`ls -1 $HOME/.ec2/cert-*`
export EC2_PRIVATE_KEY=`echo $EC2_CERT | sed 's/cert-\(.*\).pem/pk-\1.pem/'`
# New paradigm for ec2 is to use the custom keypair, but username may change
export EC2_ROOT_KEY="$HOME/.ec2/root-$EC2_REGION.pem"
if [ ! -f "$EC2_ROOT_KEY" ]; then
echo "Warning: EC2 key does not exist: $EC_ROOT_KEY" >&2
fi
+ # To override root, use ubuntu@ or ec2-user@ or whatever
ssh_cmd="ssh -i $EC2_ROOT_KEY -o StrictHostKeyChecking=no -l root"
alias ash=$ssh_cmd
alias async="rsync -av -e '$ssh_cmd'"
-
- # Amazon Linux
- ssh_cmd="ssh -i $EC2_ROOT_KEY -o StrictHostKeyChecking=no -l ec2-user"
- alias esh=$ssh_cmd
- alias esync="rsync -av -e '$ssh_cmd'"
-
- # Ubuntu
- ssh_cmd="ssh -i $EC2_ROOT_KEY -o StrictHostKeyChecking=no -l ubuntu"
- alias ush=$ssh_cmd
- alias usync="rsync -av -e '$ssh_cmd'"
}
-if [ -d "$HOME/.ec2" ]; then
- ec2region us-west-2
-fi
+# Set default EC2 region
+[ -d "$HOME/.ec2" ] && ec2region us-west-2
# Use the github aws-tools repo if available
-if [ -f "$HOME/Workspace/aws-tools/aws-tools-env.sh" ]; then
+if [ -f "$HOME/Workspace/aws-cli-updater/aws-cli-env.sh" ]; then
export AWS_ACCESS_KEY_ID=`cat $HOME/.ec2/access_key_id.txt`
export AWS_SECRET_ACCESS_KEY=`cat $HOME/.ec2/secret_access_key.txt`
- . "$HOME/Workspace/aws-tools/aws-tools-env.sh"
+ . "$HOME/Workspace/aws-cli-updater/aws-cli-env.sh"
fi
+# Easy unzipping
+untar () {
+ if [ "$#" -eq 0 ]; then
+ echo "Usage: untar files ..." >&2
+ return 1
+ fi
+ for f
+ do
+ case $f in
+ *.zip) unzip $f;;
+ *.tar.gz|*.tgz) tar xzvf $f;;
+ *.tar.bz|*.tbz) bunzip -c $f | tar xvf -;;
+ *) echo "Unsupported file type: $f" >&2;;
+ esac
+ done
+}
+
+
+
+# Postgres
if add_path /Library/PostgreSQL/9.0/bin; then
. /Library/PostgreSQL/9.0/pg_env.sh
fi
# Remember add_path prefixes, so the one you want first should be last
add_path \
/usr/local/pgsql/bin \
/usr/local/git/bin \
/usr/local/bin \
/opt/local/sbin \
/opt/local/bin \
$HOME/sbin \
$HOME/bin
export JVA=209.40.197.81
alias jva="ssh -l janetvanarsdale $JVA"
alias rjva="ssh -l root $JVA"
# Still needed for old games
export ORACLE_HOME="/usr/local/oracle/10.2.0.4/client"
if [ -d "$ORACLE_HOME" ]; then
add_path "$ORACLE_HOME/bin"
add_lib "$ORACLE_HOME/lib"
export TNS_ADMIN="$HOME/tnsadmin" # Directory
export NLS_LANG=".AL32UTF8"
fi
# For fucking with "go" the language
export GOROOT=$HOME/Workspace/go
export GOOS=darwin
export GOARCH=386
export GOBIN=$HOME/bin
-
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
+
diff --git a/.gitconfig b/.gitconfig
index 595c154..6b5b0b9 100644
--- a/.gitconfig
+++ b/.gitconfig
@@ -1,21 +1,21 @@
[user]
- name = Nate Wiger
- email = nate@wiger.org
+ name = Nate Wiger
+ email = nwiger@gmail.com
[alias]
- ci = commit
- co = checkout
- st = status
- up = pull
- pu = push -u origin
- rv = checkout --
- br = branch -a
- hard = reset --hard origin/master
- hist = log --since=1.day --relative-date --stat
- mine = log --since=1.day --relative-date --stat --committer=nateware
- #pu = !"git fetch origin -v; git fetch upstream -v; git merge upstream/master"
+ ci = commit
+ co = checkout
+ st = status
+ up = pull
+ pu = push -u origin
+ rv = checkout --
+ br = branch -a
+ hard = reset --hard origin/master
+ hist = log --since=1.day --relative-date --stat
+ mine = log --since=1.day --relative-date --stat --committer=nateware
+ #pu = !"git fetch origin -v; git fetch upstream -v; git merge upstream/master"
[color]
- diff = auto
- status = auto
- branch = auto
+ diff = auto
+ status = auto
+ branch = auto
[push]
- default = simple
+ default = simple
|
nateware/dotfiles
|
18f53aec1a86ebf449bfc726c4ed3eb0e263c42a
|
rake and wd updates
|
diff --git a/.bashrc b/.bashrc
index 3cc4836..92a57cd 100644
--- a/.bashrc
+++ b/.bashrc
@@ -1,146 +1,141 @@
# ~/.bashrc
umask 022
# Add to PATH but only if it exists
add_path () {
err=0
for p
do
if [ -d $p ]; then
PATH="$p:$PATH"
else
err=1
fi
done
return $err
}
# Add to LD_LIB_PATH adjusting for platform
add_lib () {
if [ "$OS" = Darwin ]; then
export DYLD_LIBRARY_PATH="$lib:$DYLD_LIBRARY_PATH"
else
export LD_LIBRARY_PATH="$lib:$DYLD_LIBRARY_PATH"
fi
return 0
}
# Guess
add_path_and_lib () {
if add_path "$1"; then
lib=${1%/bin}/lib
add_lib $lib
else
return 1
fi
}
# Aliases
alias ls='\ls -Gh'
alias ll='ls -al'
alias wget='curl -LO'
alias ldd='otool -L'
alias rsync='\rsync --exclude=.svn --exclude=.git --exclude=RCS'
alias vi='vim -b'
# Don't want to install rubydocs - TOO SLOW!
alias gi='gem install --no-ri --no-rdoc'
alias bi='bundle --without=production'
alias bu='bundle --without=production'
alias be='bundle exec'
alias ga='git ci -a -m'
alias gd='git pu && git push -f dev'
alias gp='git pu'
# Change to workspace directory
wd () {
- pushd "$HOME/Workspace/$1"*
+ if [ $# -eq 0 ]; then
+ pushd "$HOME/Workspace"
+ else
+ pushd "$HOME/Workspace/$1"*
+ fi
}
# Platform goodness
export OS=`uname`
[ "$OS" = Darwin ] && export JAVA_HOME=/Library/Java/Home
# For ruby version manager
[ -s $HOME/.rvm/scripts/rvm ] && . $HOME/.rvm/scripts/rvm
# For Jeweler
export JEWELER_OPTS="--bundler --bacon --create-repo --user-name 'Nate Wiger' --user-email 'nate@wiger.org' --github-username nateware --github-token `cat $HOME/.github-token`"
# ImageMagick
add_path_and_lib /usr/local/ImageMagick/bin
# MySQL
add_path_and_lib /usr/local/mysql/bin
# MongoDB
add_path /usr/local/mongodb/bin
# Amazon EC2 CLI tools
export EC2_HOME=/usr/local/ec2-api-tools
add_path "$EC2_HOME/bin" || unset EC2_HOME
export RDS_HOME=/usr/local/rds-cli
add_path "$RDS_HOME/bin" || unset RDS_HOME
# Amazon EC2 gems
if [ -d "$HOME/.ec2" ]; then
export EC2_PRIVATE_KEY="$HOME/.ec2/pk-UO255XUYVOVVBXUWADA57YCL7XZZKQDE.pem"
export EC2_CERT="$HOME/.ec2/cert-UO255XUYVOVVBXUWADA57YCL7XZZKQDE.pem"
ec2_user=`cat $HOME/.ec2/ec2_user.txt`
alias ess="ssh -i $HOME/.ec2/id_rsa-$ec2_user-keypair -o StrictHostKeyChecking=no -l root"
alias esync="rsync -av -e 'ssh -i $HOME/.ec2/id_rsa-$ec2_user-keypair -o StrictHostKeyChecking=no -l root'"
alias pss="ssh -i $HOME/.ec2/id_rsa-$ec2_user-user -o StrictHostKeyChecking=no -l $ec2_user"
alias psync="rsync -av -e 'ssh -i $HOME/.ec2/id_rsa-$ec2_user-user -o StrictHostKeyChecking=no -l $ec2_user'"
# For amazon-ec2 gem
export AMAZON_ACCESS_KEY_ID=`cat $HOME/.ec2/access_key_id.txt`
export AMAZON_SECRET_ACCESS_KEY=`cat $HOME/.ec2/secret_access_key.txt`
fi
# Sandbox
alias ash="ssh -i $HOME/.ec2/sandbox-keypair.pem -o StrictHostKeyChecking=no -l ubuntu"
alias async="rsync -a -e '$HOME/.ec2/sandbox-keypair.pem -o StrictHostKeyChecking=no -l ubuntu'"
if add_path /Library/PostgreSQL/9.0/bin; then
. /Library/PostgreSQL/9.0/pg_env.sh
fi
# Remember add_path prefixes, so the one you want first should be last
add_path \
/usr/local/pgsql/bin \
/usr/local/git/bin \
/usr/local/bin \
/opt/local/sbin \
/opt/local/bin \
$HOME/sbin \
$HOME/bin
export JVA=209.40.197.81
alias jva="ssh -l janetvanarsdale $JVA"
alias rjva="ssh -l root $JVA"
# Still needed for old games
export ORACLE_HOME="/usr/local/oracle/10.2.0.4/client"
if [ -d "$ORACLE_HOME" ]; then
add_path "$ORACLE_HOME/bin"
add_lib "$ORACLE_HOME/lib"
export TNS_ADMIN="$HOME/tnsadmin" # Directory
export NLS_LANG=".AL32UTF8"
fi
# For fucking with "go" the language
export GOROOT=$HOME/Workspace/go
export GOOS=darwin
export GOARCH=386
export GOBIN=$HOME/bin
-# Because I'm a moron
-rake () {
- if [ -f Gemfile ]; then
- bundle exec rake "$@"
- else
- \rake "$@"
- fi
-}
-
|
nateware/dotfiles
|
cf683b4d9b0066bc3c95c7af51bd0f4ffa156604
|
new aliases
|
diff --git a/.bashrc b/.bashrc
index be14fef..a7d594e 100644
--- a/.bashrc
+++ b/.bashrc
@@ -1,146 +1,152 @@
# ~/.bashrc
umask 022
# Add to PATH but only if it exists
add_path () {
err=0
for p
do
if [ -d $p ]; then
PATH="$p:$PATH"
else
err=1
fi
done
return $err
}
# Add to LD_LIB_PATH adjusting for platform
add_lib () {
if [ "$OS" = Darwin ]; then
export DYLD_LIBRARY_PATH="$lib:$DYLD_LIBRARY_PATH"
else
export LD_LIBRARY_PATH="$lib:$DYLD_LIBRARY_PATH"
fi
return 0
}
# Guess
add_path_and_lib () {
if add_path "$1"; then
lib=${1%/bin}/lib
add_lib $lib
else
return 1
fi
}
# Aliases
alias ls='\ls -Gh'
alias ll='ls -al'
alias wget='curl -LO'
alias ldd='otool -L'
alias rsync='\rsync --exclude=.svn --exclude=.git --exclude=RCS'
alias vi='vim -b'
# Don't want to install rubydocs - TOO SLOW!
alias gi='gem install --no-ri --no-rdoc'
alias bi='bundle --without=production install'
alias bu='bundle --without=production update'
alias be='bundle exec'
alias ga='git ci -a -m'
alias gd='git pu && git push -f dev'
alias gp='git pu'
+gap () {
+ ga "$*" && gp
+}
+gapd () {
+ gap "$*" && cap dev deploy
+}
# Change to workspace directory
wd () {
pushd "$HOME/Workspace/$1"*
}
# Platform goodness
export OS=`uname`
[ "$OS" = Darwin ] && export JAVA_HOME=/Library/Java/Home
# For ruby version manager
[ -s $HOME/.rvm/scripts/rvm ] && . $HOME/.rvm/scripts/rvm
# For Jeweler
export JEWELER_OPTS="--bundler --bacon --create-repo --user-name 'Nate Wiger' --user-email 'nate@wiger.org' --github-username nateware --github-token `cat $HOME/.github-token`"
# ImageMagick
add_path_and_lib /usr/local/ImageMagick/bin
# MySQL
add_path_and_lib /usr/local/mysql/bin
# MongoDB
add_path /usr/local/mongodb/bin
# Amazon EC2 CLI tools
export EC2_HOME=/usr/local/ec2-api-tools
add_path "$EC2_HOME/bin" || unset EC2_HOME
export RDS_HOME=/usr/local/rds-cli
add_path "$RDS_HOME/bin" || unset RDS_HOME
# Amazon EC2 gems
if [ -d "$HOME/.ec2" ]; then
export EC2_PRIVATE_KEY="$HOME/.ec2/pk-UO255XUYVOVVBXUWADA57YCL7XZZKQDE.pem"
export EC2_CERT="$HOME/.ec2/cert-UO255XUYVOVVBXUWADA57YCL7XZZKQDE.pem"
ec2_user=`cat $HOME/.ec2/ec2_user.txt`
alias ess="ssh -i $HOME/.ec2/id_rsa-$ec2_user-keypair -o StrictHostKeyChecking=no -l root"
alias esync="rsync -av -e 'ssh -i $HOME/.ec2/id_rsa-$ec2_user-keypair -o StrictHostKeyChecking=no -l root'"
alias pss="ssh -i $HOME/.ec2/id_rsa-$ec2_user-user -o StrictHostKeyChecking=no -l $ec2_user"
alias psync="rsync -av -e 'ssh -i $HOME/.ec2/id_rsa-$ec2_user-user -o StrictHostKeyChecking=no -l $ec2_user'"
# For amazon-ec2 gem
export AMAZON_ACCESS_KEY_ID=`cat $HOME/.ec2/access_key_id.txt`
export AMAZON_SECRET_ACCESS_KEY=`cat $HOME/.ec2/secret_access_key.txt`
fi
# Sandbox
alias ash="ssh -i $HOME/.ec2/sandbox-keypair.pem -o StrictHostKeyChecking=no -l ubuntu"
alias async="rsync -a -e '$HOME/.ec2/sandbox-keypair.pem -o StrictHostKeyChecking=no -l ubuntu'"
if add_path /Library/PostgreSQL/9.0/bin; then
. /Library/PostgreSQL/9.0/pg_env.sh
fi
# Remember add_path prefixes, so the one you want first should be last
add_path \
/usr/local/pgsql/bin \
/usr/local/git/bin \
/usr/local/bin \
/opt/local/sbin \
/opt/local/bin \
$HOME/sbin \
$HOME/bin
export JVA=209.40.197.81
alias jva="ssh -l janetvanarsdale $JVA"
alias rjva="ssh -l root $JVA"
# Still needed for old games
export ORACLE_HOME="/usr/local/oracle/10.2.0.4/client"
if [ -d "$ORACLE_HOME" ]; then
add_path "$ORACLE_HOME/bin"
add_lib "$ORACLE_HOME/lib"
export TNS_ADMIN="$HOME/tnsadmin" # Directory
export NLS_LANG=".AL32UTF8"
fi
# For fucking with "go" the language
export GOROOT=$HOME/Workspace/go
export GOOS=darwin
export GOARCH=386
export GOBIN=$HOME/bin
# Because I'm a moron
rake () {
if [ -f Gemfile ]; then
bundle exec rake "$@"
else
\rake "$@"
fi
}
|
nateware/dotfiles
|
65380a645c4ac0509fa3c5086523ed1c3da25c81
|
alias reshuffle
|
diff --git a/.bashrc b/.bashrc
index bfadd28..72d48b7 100644
--- a/.bashrc
+++ b/.bashrc
@@ -1,134 +1,140 @@
# ~/.bashrc
umask 022
-alias ls='\ls -Gh'
-alias ll='ls -al'
-alias wget='curl -LO'
-alias ldd='otool -L'
-alias rsync='\rsync --exclude=.svn --exclude=.git --exclude=RCS'
-alias vi='vim -b'
-
-# Don't want local rubydocs - TOO SLOW!
-alias gi='gem install --no-ri --no-rdoc'
-alias bi='bundle --without=production'
-alias bu='bundle --without=production'
-alias be='bundle exec'
-alias ga='git ci -a -m'
-alias gd='git pu && git push -f dev'
-alias gp='git pu'
-
-# Platform goodness
-export OS=`uname`
-[ "$OS" = Darwin ] && export JAVA_HOME=/Library/Java/Home
-
-# For ruby version manager
-[ -s $HOME/.rvm/scripts/rvm ] && . $HOME/.rvm/scripts/rvm
-
-# For Jeweler
-export JEWELER_OPTS="--bundler --bacon --create-repo --user-name 'Nate Wiger' --user-email 'nate@wiger.org' --github-username nateware --github-token `cat $HOME/.github-token`"
-
# Add to PATH but only if it exists
add_path () {
err=0
for p
do
if [ -d $p ]; then
PATH="$p:$PATH"
else
err=1
fi
done
return $err
}
# Add to LD_LIB_PATH adjusting for platform
add_lib () {
if [ "$OS" = Darwin ]; then
export DYLD_LIBRARY_PATH="$lib:$DYLD_LIBRARY_PATH"
else
export LD_LIBRARY_PATH="$lib:$DYLD_LIBRARY_PATH"
fi
return 0
}
# Guess
add_path_and_lib () {
if add_path "$1"; then
lib=${1%/bin}/lib
add_lib $lib
else
return 1
fi
}
+# Aliases
+alias ls='\ls -Gh'
+alias ll='ls -al'
+alias wget='curl -LO'
+alias ldd='otool -L'
+alias rsync='\rsync --exclude=.svn --exclude=.git --exclude=RCS'
+alias vi='vim -b'
+
+# Don't want to install rubydocs - TOO SLOW!
+alias gi='gem install --no-ri --no-rdoc'
+alias bi='bundle --without=production'
+alias bu='bundle --without=production'
+alias be='bundle exec'
+alias ga='git ci -a -m'
+alias gd='git pu && git push -f dev'
+alias gp='git pu'
+
+# Change to workspace directory
+wd () {
+ pushd "$HOME/Workspace/$1"*
+}
+
+# Platform goodness
+export OS=`uname`
+[ "$OS" = Darwin ] && export JAVA_HOME=/Library/Java/Home
+
+# For ruby version manager
+[ -s $HOME/.rvm/scripts/rvm ] && . $HOME/.rvm/scripts/rvm
+
+# For Jeweler
+export JEWELER_OPTS="--bundler --bacon --create-repo --user-name 'Nate Wiger' --user-email 'nate@wiger.org' --github-username nateware --github-token `cat $HOME/.github-token`"
+
# ImageMagick
add_path_and_lib /usr/local/ImageMagick/bin
# MySQL
add_path_and_lib /usr/local/mysql/bin
# MongoDB
add_path /usr/local/mongodb/bin
# Amazon EC2 CLI tools
export EC2_HOME=/usr/local/ec2-api-tools
add_path "$EC2_HOME/bin" || unset EC2_HOME
# Amazon EC2 gems
if [ -d "$HOME/.ec2" ]; then
export EC2_PRIVATE_KEY="$HOME/.ec2/pk-UO255XUYVOVVBXUWADA57YCL7XZZKQDE.pem"
export EC2_CERT="$HOME/.ec2/cert-UO255XUYVOVVBXUWADA57YCL7XZZKQDE.pem"
ec2_user=`cat $HOME/.ec2/ec2_user.txt`
alias ess="ssh -i $HOME/.ec2/id_rsa-$ec2_user-keypair -o StrictHostKeyChecking=no -l root"
alias esync="rsync -av -e 'ssh -i $HOME/.ec2/id_rsa-$ec2_user-keypair -o StrictHostKeyChecking=no -l root'"
alias pss="ssh -i $HOME/.ec2/id_rsa-$ec2_user-user -o StrictHostKeyChecking=no -l $ec2_user"
alias psync="rsync -av -e 'ssh -i $HOME/.ec2/id_rsa-$ec2_user-user -o StrictHostKeyChecking=no -l $ec2_user'"
# For amazon-ec2 gem
export AMAZON_ACCESS_KEY_ID=`cat $HOME/.ec2/access_key_id.txt`
export AMAZON_SECRET_ACCESS_KEY=`cat $HOME/.ec2/secret_access_key.txt`
fi
if add_path /Library/PostgreSQL/9.0/bin; then
. /Library/PostgreSQL/9.0/pg_env.sh
fi
# Remember add_path prefixes, so the one you want first should be last
add_path \
/usr/local/pgsql/bin \
/usr/local/git/bin \
/usr/local/bin \
/opt/local/sbin \
/opt/local/bin \
$HOME/sbin \
$HOME/bin
export JVA=209.40.197.81
alias jva="ssh -l janetvanarsdale $JVA"
alias rjva="ssh -l root $JVA"
# Still needed for old games
export ORACLE_HOME="/usr/local/oracle/10.2.0.4/client"
if [ -d "$ORACLE_HOME" ]; then
add_path "$ORACLE_HOME/bin"
add_lib "$ORACLE_HOME/lib"
export TNS_ADMIN="$HOME/tnsadmin" # Directory
export NLS_LANG=".AL32UTF8"
fi
# For fucking with "go" the language
export GOROOT=$HOME/Workspace/go
export GOOS=darwin
export GOARCH=386
export GOBIN=$HOME/bin
# Because I'm a moron
rake () {
if [ -f Gemfile ]; then
bundle exec rake "$@"
else
\rake "$@"
fi
}
|
nateware/dotfiles
|
5b547290d2dc79463a427bbaf932f95026482434
|
moved to 1.9.3 using rvm --default
|
diff --git a/.bash_profile b/.bash_profile
index e3edd7d..f431589 100644
--- a/.bash_profile
+++ b/.bash_profile
@@ -1,38 +1,33 @@
# Must source manually
[ -f $HOME/.bashrc ] && . $HOME/.bashrc
# Colors!
c1="\033["
c2="m"
c_normal="${c1}0${c2}"
c_bold="${c1}1${c2}"
c_black="${c1}0;30${c2}"
c_blue="${c1}0;34${c2}"
c_green="${c1}0;32${c2}"
c_cyan="${c1}0;36${c2}"
c_red="${c1}0;31${c2}"
c_purple="${c1}0;35${c2}"
c_brown="${c1}0;33${c2}"
c_gray="${c1}0;37${c2}"
c_dark_gray="${c1}1;30${c2}"
c_bold_blue="${c1}1;34${c2}"
c_bold_green="${c1}1;32${c2}"
c_bold_cyan="${c1}1;36${c2}"
c_bold_red="${c1}1;31${c2}"
c_bold_purple="${c1}1;35${c2}"
c_bold_yellow="${c1}1;33${c2}"
c_bold_white="${c1}1;37${c2}"
# Prompt
export PS1='[\u@\h:\W]\$ '
export PS1="[$c_green\u$c_normal@$c_purple\h$c_normal:$c_blue\W$c_normal]\$ "
-# Ruby version
-use_ruby=ruby-1.9.2-p290
-printf "Setting rvm ruby to: $c_red$use_ruby$c_normal\n"
-rvm $use_ruby
printf $c_red
type ruby
printf $c_normal
-
|
nateware/dotfiles
|
51b5b384f12f9def6dd0b5d2fb0153d55b4479b8
|
vim and git
|
diff --git a/.bashrc b/.bashrc
index 53c3031..6a75dc7 100644
--- a/.bashrc
+++ b/.bashrc
@@ -1,130 +1,133 @@
# ~/.bashrc
umask 022
alias ls='\ls -Gh'
alias ll='ls -al'
alias wget='curl -LO'
alias ldd='otool -L'
alias rsync='\rsync --exclude=.svn --exclude=.git --exclude=RCS'
# Don't want local rubydocs - TOO SLOW!
alias gi='gem install --no-ri --no-rdoc'
alias bi='bundle --without=production'
alias bu='bundle --without=production'
alias be='bundle exec'
+alias ga='git ci -a -m'
+alias gd='git pu && git push -f dev'
+alias gp='git pu'
# Platform goodness
export OS=`uname`
[ "$OS" = Darwin ] && export JAVA_HOME=/Library/Java/Home
# For ruby version manager
[ -s $HOME/.rvm/scripts/rvm ] && . $HOME/.rvm/scripts/rvm
# For Jeweler
export JEWELER_OPTS="--bundler --bacon --create-repo --user-name 'Nate Wiger' --user-email 'nate@wiger.org' --github-username nateware --github-token `cat $HOME/.github-token`"
# Add to PATH but only if it exists
add_path () {
err=0
for p
do
if [ -d $p ]; then
PATH="$p:$PATH"
else
err=1
fi
done
return $err
}
# Add to LD_LIB_PATH adjusting for platform
add_lib () {
if [ "$OS" = Darwin ]; then
export DYLD_LIBRARY_PATH="$lib:$DYLD_LIBRARY_PATH"
else
export LD_LIBRARY_PATH="$lib:$DYLD_LIBRARY_PATH"
fi
return 0
}
# Guess
add_path_and_lib () {
if add_path "$1"; then
lib=${1%/bin}/lib
add_lib $lib
else
return 1
fi
}
# ImageMagick
add_path_and_lib /usr/local/ImageMagick/bin
# MySQL
add_path_and_lib /usr/local/mysql/bin
# MongoDB
add_path /usr/local/mongodb/bin
# Amazon EC2 CLI tools
export EC2_HOME=/usr/local/ec2-api-tools
add_path "$EC2_HOME/bin" || unset EC2_HOME
# Amazon EC2 gems
if [ -d "$HOME/.ec2" ]; then
export EC2_PRIVATE_KEY="$HOME/.ec2/pk-UO255XUYVOVVBXUWADA57YCL7XZZKQDE.pem"
export EC2_CERT="$HOME/.ec2/cert-UO255XUYVOVVBXUWADA57YCL7XZZKQDE.pem"
ec2_user=`cat $HOME/.ec2/ec2_user.txt`
alias ess="ssh -i $HOME/.ec2/id_rsa-$ec2_user-keypair -o StrictHostKeyChecking=no -l root"
alias esync="rsync -av -e 'ssh -i $HOME/.ec2/id_rsa-$ec2_user-keypair -o StrictHostKeyChecking=no -l root'"
alias pss="ssh -i $HOME/.ec2/id_rsa-$ec2_user-user -o StrictHostKeyChecking=no -l $ec2_user"
alias psync="rsync -av -e 'ssh -i $HOME/.ec2/id_rsa-$ec2_user-user -o StrictHostKeyChecking=no -l $ec2_user'"
# For amazon-ec2 gem
export AMAZON_ACCESS_KEY_ID=`cat $HOME/.ec2/access_key_id.txt`
export AMAZON_SECRET_ACCESS_KEY=`cat $HOME/.ec2/secret_access_key.txt`
fi
if add_path /Library/PostgreSQL/9.0/bin; then
. /Library/PostgreSQL/9.0/pg_env.sh
fi
# Remember add_path prefixes, so the one you want first should be last
add_path \
/usr/local/pgsql/bin \
/usr/local/git/bin \
/usr/local/bin \
/opt/local/sbin \
/opt/local/bin \
$HOME/sbin \
$HOME/bin
export JVA=209.40.197.81
alias jva="ssh -l janetvanarsdale $JVA"
alias rjva="ssh -l root $JVA"
# Still needed for old games
export ORACLE_HOME="/usr/local/oracle/10.2.0.4/client"
if [ -d "$ORACLE_HOME" ]; then
add_path "$ORACLE_HOME/bin"
add_lib "$ORACLE_HOME/lib"
export TNS_ADMIN="$HOME/tnsadmin" # Directory
export NLS_LANG=".AL32UTF8"
fi
# For fucking with "go" the language
export GOROOT=$HOME/Workspace/go
export GOOS=darwin
export GOARCH=386
export GOBIN=$HOME/bin
# Because I'm a moron
rake () {
if [ -f Gemfile ]; then
bundle exec rake "$@"
else
\rake "$@"
fi
}
diff --git a/.vimrc b/.vimrc
index 4791bd6..1a24baf 100644
--- a/.vimrc
+++ b/.vimrc
@@ -1,14 +1,15 @@
" mkdir -p ~/.vim/autoload ~/.vim/bundle
" curl -so ~/.vim/autoload/pathogen.vim https://raw.github.com/tpope/vim-pathogen/HEAD/autoload/pathogen.vim
" git clone git://github.com/tpope/vim-fugitive.git
" git clone git://github.com/tpope/vim-rails.git
" git clone git://github.com/tpope/vim-rake.git
" git clone git://github.com/tpope/vim-surround.git
" git clone git://github.com/tpope/vim-repeat.git
" git clone git://github.com/tpope/vim-commentary.git
"
set nocp
-set ts=2 et
+set ts=2 et shiftwidth=2
call pathogen#infect()
syntax on
filetype plugin indent on
+colorscheme slate
|
nateware/dotfiles
|
4096862d3636047a72955df7b9c0aabcde68f71e
|
more bundle aliases
|
diff --git a/.bashrc b/.bashrc
index 01811e0..53c3031 100644
--- a/.bashrc
+++ b/.bashrc
@@ -1,129 +1,130 @@
# ~/.bashrc
umask 022
alias ls='\ls -Gh'
alias ll='ls -al'
alias wget='curl -LO'
alias ldd='otool -L'
alias rsync='\rsync --exclude=.svn --exclude=.git --exclude=RCS'
# Don't want local rubydocs - TOO SLOW!
alias gi='gem install --no-ri --no-rdoc'
-alias bd='bundle --without=production'
+alias bi='bundle --without=production'
+alias bu='bundle --without=production'
alias be='bundle exec'
# Platform goodness
export OS=`uname`
[ "$OS" = Darwin ] && export JAVA_HOME=/Library/Java/Home
# For ruby version manager
[ -s $HOME/.rvm/scripts/rvm ] && . $HOME/.rvm/scripts/rvm
# For Jeweler
export JEWELER_OPTS="--bundler --bacon --create-repo --user-name 'Nate Wiger' --user-email 'nate@wiger.org' --github-username nateware --github-token `cat $HOME/.github-token`"
# Add to PATH but only if it exists
add_path () {
err=0
for p
do
if [ -d $p ]; then
PATH="$p:$PATH"
else
err=1
fi
done
return $err
}
# Add to LD_LIB_PATH adjusting for platform
add_lib () {
if [ "$OS" = Darwin ]; then
export DYLD_LIBRARY_PATH="$lib:$DYLD_LIBRARY_PATH"
else
export LD_LIBRARY_PATH="$lib:$DYLD_LIBRARY_PATH"
fi
return 0
}
# Guess
add_path_and_lib () {
if add_path "$1"; then
lib=${1%/bin}/lib
add_lib $lib
else
return 1
fi
}
# ImageMagick
add_path_and_lib /usr/local/ImageMagick/bin
# MySQL
add_path_and_lib /usr/local/mysql/bin
# MongoDB
add_path /usr/local/mongodb/bin
# Amazon EC2 CLI tools
export EC2_HOME=/usr/local/ec2-api-tools
add_path "$EC2_HOME/bin" || unset EC2_HOME
# Amazon EC2 gems
if [ -d "$HOME/.ec2" ]; then
export EC2_PRIVATE_KEY="$HOME/.ec2/pk-UO255XUYVOVVBXUWADA57YCL7XZZKQDE.pem"
export EC2_CERT="$HOME/.ec2/cert-UO255XUYVOVVBXUWADA57YCL7XZZKQDE.pem"
ec2_user=`cat $HOME/.ec2/ec2_user.txt`
alias ess="ssh -i $HOME/.ec2/id_rsa-$ec2_user-keypair -o StrictHostKeyChecking=no -l root"
alias esync="rsync -av -e 'ssh -i $HOME/.ec2/id_rsa-$ec2_user-keypair -o StrictHostKeyChecking=no -l root'"
alias pss="ssh -i $HOME/.ec2/id_rsa-$ec2_user-user -o StrictHostKeyChecking=no -l $ec2_user"
alias psync="rsync -av -e 'ssh -i $HOME/.ec2/id_rsa-$ec2_user-user -o StrictHostKeyChecking=no -l $ec2_user'"
# For amazon-ec2 gem
export AMAZON_ACCESS_KEY_ID=`cat $HOME/.ec2/access_key_id.txt`
export AMAZON_SECRET_ACCESS_KEY=`cat $HOME/.ec2/secret_access_key.txt`
fi
if add_path /Library/PostgreSQL/9.0/bin; then
. /Library/PostgreSQL/9.0/pg_env.sh
fi
# Remember add_path prefixes, so the one you want first should be last
add_path \
/usr/local/pgsql/bin \
/usr/local/git/bin \
/usr/local/bin \
/opt/local/sbin \
/opt/local/bin \
$HOME/sbin \
$HOME/bin
export JVA=209.40.197.81
alias jva="ssh -l janetvanarsdale $JVA"
alias rjva="ssh -l root $JVA"
# Still needed for old games
export ORACLE_HOME="/usr/local/oracle/10.2.0.4/client"
if [ -d "$ORACLE_HOME" ]; then
add_path "$ORACLE_HOME/bin"
add_lib "$ORACLE_HOME/lib"
export TNS_ADMIN="$HOME/tnsadmin" # Directory
export NLS_LANG=".AL32UTF8"
fi
# For fucking with "go" the language
export GOROOT=$HOME/Workspace/go
export GOOS=darwin
export GOARCH=386
export GOBIN=$HOME/bin
# Because I'm a moron
rake () {
if [ -f Gemfile ]; then
bundle exec rake "$@"
else
\rake "$@"
fi
}
|
nateware/dotfiles
|
f4fb7f23438481630830a056a052213ff8a775cc
|
vim bundle
|
diff --git a/.vimrc b/.vimrc
new file mode 100644
index 0000000..4791bd6
--- /dev/null
+++ b/.vimrc
@@ -0,0 +1,14 @@
+" mkdir -p ~/.vim/autoload ~/.vim/bundle
+" curl -so ~/.vim/autoload/pathogen.vim https://raw.github.com/tpope/vim-pathogen/HEAD/autoload/pathogen.vim
+" git clone git://github.com/tpope/vim-fugitive.git
+" git clone git://github.com/tpope/vim-rails.git
+" git clone git://github.com/tpope/vim-rake.git
+" git clone git://github.com/tpope/vim-surround.git
+" git clone git://github.com/tpope/vim-repeat.git
+" git clone git://github.com/tpope/vim-commentary.git
+"
+set nocp
+set ts=2 et
+call pathogen#infect()
+syntax on
+filetype plugin indent on
|
nateware/dotfiles
|
895ad72dd70c83dbfdb922879b95982a35982709
|
added moron catch for rake
|
diff --git a/.bashrc b/.bashrc
index 9d77794..01811e0 100644
--- a/.bashrc
+++ b/.bashrc
@@ -1,120 +1,129 @@
# ~/.bashrc
umask 022
alias ls='\ls -Gh'
alias ll='ls -al'
alias wget='curl -LO'
alias ldd='otool -L'
alias rsync='\rsync --exclude=.svn --exclude=.git --exclude=RCS'
# Don't want local rubydocs - TOO SLOW!
alias gi='gem install --no-ri --no-rdoc'
alias bd='bundle --without=production'
alias be='bundle exec'
# Platform goodness
export OS=`uname`
[ "$OS" = Darwin ] && export JAVA_HOME=/Library/Java/Home
# For ruby version manager
[ -s $HOME/.rvm/scripts/rvm ] && . $HOME/.rvm/scripts/rvm
# For Jeweler
export JEWELER_OPTS="--bundler --bacon --create-repo --user-name 'Nate Wiger' --user-email 'nate@wiger.org' --github-username nateware --github-token `cat $HOME/.github-token`"
# Add to PATH but only if it exists
add_path () {
err=0
for p
do
if [ -d $p ]; then
PATH="$p:$PATH"
else
err=1
fi
done
return $err
}
# Add to LD_LIB_PATH adjusting for platform
add_lib () {
if [ "$OS" = Darwin ]; then
export DYLD_LIBRARY_PATH="$lib:$DYLD_LIBRARY_PATH"
else
export LD_LIBRARY_PATH="$lib:$DYLD_LIBRARY_PATH"
fi
return 0
}
# Guess
add_path_and_lib () {
if add_path "$1"; then
lib=${1%/bin}/lib
add_lib $lib
else
return 1
fi
}
# ImageMagick
add_path_and_lib /usr/local/ImageMagick/bin
# MySQL
add_path_and_lib /usr/local/mysql/bin
# MongoDB
add_path /usr/local/mongodb/bin
# Amazon EC2 CLI tools
export EC2_HOME=/usr/local/ec2-api-tools
add_path "$EC2_HOME/bin" || unset EC2_HOME
# Amazon EC2 gems
if [ -d "$HOME/.ec2" ]; then
export EC2_PRIVATE_KEY="$HOME/.ec2/pk-UO255XUYVOVVBXUWADA57YCL7XZZKQDE.pem"
export EC2_CERT="$HOME/.ec2/cert-UO255XUYVOVVBXUWADA57YCL7XZZKQDE.pem"
ec2_user=`cat $HOME/.ec2/ec2_user.txt`
alias ess="ssh -i $HOME/.ec2/id_rsa-$ec2_user-keypair -o StrictHostKeyChecking=no -l root"
alias esync="rsync -av -e 'ssh -i $HOME/.ec2/id_rsa-$ec2_user-keypair -o StrictHostKeyChecking=no -l root'"
alias pss="ssh -i $HOME/.ec2/id_rsa-$ec2_user-user -o StrictHostKeyChecking=no -l $ec2_user"
alias psync="rsync -av -e 'ssh -i $HOME/.ec2/id_rsa-$ec2_user-user -o StrictHostKeyChecking=no -l $ec2_user'"
# For amazon-ec2 gem
export AMAZON_ACCESS_KEY_ID=`cat $HOME/.ec2/access_key_id.txt`
export AMAZON_SECRET_ACCESS_KEY=`cat $HOME/.ec2/secret_access_key.txt`
fi
if add_path /Library/PostgreSQL/9.0/bin; then
. /Library/PostgreSQL/9.0/pg_env.sh
fi
# Remember add_path prefixes, so the one you want first should be last
add_path \
/usr/local/pgsql/bin \
/usr/local/git/bin \
/usr/local/bin \
/opt/local/sbin \
/opt/local/bin \
$HOME/sbin \
$HOME/bin
export JVA=209.40.197.81
alias jva="ssh -l janetvanarsdale $JVA"
alias rjva="ssh -l root $JVA"
# Still needed for old games
export ORACLE_HOME="/usr/local/oracle/10.2.0.4/client"
if [ -d "$ORACLE_HOME" ]; then
add_path "$ORACLE_HOME/bin"
add_lib "$ORACLE_HOME/lib"
export TNS_ADMIN="$HOME/tnsadmin" # Directory
export NLS_LANG=".AL32UTF8"
fi
# For fucking with "go" the language
export GOROOT=$HOME/Workspace/go
export GOOS=darwin
export GOARCH=386
export GOBIN=$HOME/bin
+# Because I'm a moron
+rake () {
+ if [ -f Gemfile ]; then
+ bundle exec rake "$@"
+ else
+ \rake "$@"
+ fi
+}
+
|
nateware/dotfiles
|
364043997f2093c7020f5f6bfb1c6424675036bf
|
added bundle exec alias
|
diff --git a/.bashrc b/.bashrc
index eaeae35..9d77794 100644
--- a/.bashrc
+++ b/.bashrc
@@ -1,119 +1,120 @@
# ~/.bashrc
umask 022
alias ls='\ls -Gh'
alias ll='ls -al'
alias wget='curl -LO'
alias ldd='otool -L'
alias rsync='\rsync --exclude=.svn --exclude=.git --exclude=RCS'
# Don't want local rubydocs - TOO SLOW!
alias gi='gem install --no-ri --no-rdoc'
alias bd='bundle --without=production'
+alias be='bundle exec'
# Platform goodness
export OS=`uname`
[ "$OS" = Darwin ] && export JAVA_HOME=/Library/Java/Home
# For ruby version manager
[ -s $HOME/.rvm/scripts/rvm ] && . $HOME/.rvm/scripts/rvm
# For Jeweler
export JEWELER_OPTS="--bundler --bacon --create-repo --user-name 'Nate Wiger' --user-email 'nate@wiger.org' --github-username nateware --github-token `cat $HOME/.github-token`"
# Add to PATH but only if it exists
add_path () {
err=0
for p
do
if [ -d $p ]; then
PATH="$p:$PATH"
else
err=1
fi
done
return $err
}
# Add to LD_LIB_PATH adjusting for platform
add_lib () {
if [ "$OS" = Darwin ]; then
export DYLD_LIBRARY_PATH="$lib:$DYLD_LIBRARY_PATH"
else
export LD_LIBRARY_PATH="$lib:$DYLD_LIBRARY_PATH"
fi
return 0
}
# Guess
add_path_and_lib () {
if add_path "$1"; then
lib=${1%/bin}/lib
add_lib $lib
else
return 1
fi
}
# ImageMagick
add_path_and_lib /usr/local/ImageMagick/bin
# MySQL
add_path_and_lib /usr/local/mysql/bin
# MongoDB
add_path /usr/local/mongodb/bin
# Amazon EC2 CLI tools
export EC2_HOME=/usr/local/ec2-api-tools
add_path "$EC2_HOME/bin" || unset EC2_HOME
# Amazon EC2 gems
if [ -d "$HOME/.ec2" ]; then
export EC2_PRIVATE_KEY="$HOME/.ec2/pk-UO255XUYVOVVBXUWADA57YCL7XZZKQDE.pem"
export EC2_CERT="$HOME/.ec2/cert-UO255XUYVOVVBXUWADA57YCL7XZZKQDE.pem"
ec2_user=`cat $HOME/.ec2/ec2_user.txt`
alias ess="ssh -i $HOME/.ec2/id_rsa-$ec2_user-keypair -o StrictHostKeyChecking=no -l root"
alias esync="rsync -av -e 'ssh -i $HOME/.ec2/id_rsa-$ec2_user-keypair -o StrictHostKeyChecking=no -l root'"
alias pss="ssh -i $HOME/.ec2/id_rsa-$ec2_user-user -o StrictHostKeyChecking=no -l $ec2_user"
alias psync="rsync -av -e 'ssh -i $HOME/.ec2/id_rsa-$ec2_user-user -o StrictHostKeyChecking=no -l $ec2_user'"
# For amazon-ec2 gem
export AMAZON_ACCESS_KEY_ID=`cat $HOME/.ec2/access_key_id.txt`
export AMAZON_SECRET_ACCESS_KEY=`cat $HOME/.ec2/secret_access_key.txt`
fi
if add_path /Library/PostgreSQL/9.0/bin; then
. /Library/PostgreSQL/9.0/pg_env.sh
fi
# Remember add_path prefixes, so the one you want first should be last
add_path \
/usr/local/pgsql/bin \
/usr/local/git/bin \
/usr/local/bin \
/opt/local/sbin \
/opt/local/bin \
$HOME/sbin \
$HOME/bin
export JVA=209.40.197.81
alias jva="ssh -l janetvanarsdale $JVA"
alias rjva="ssh -l root $JVA"
# Still needed for old games
export ORACLE_HOME="/usr/local/oracle/10.2.0.4/client"
if [ -d "$ORACLE_HOME" ]; then
add_path "$ORACLE_HOME/bin"
add_lib "$ORACLE_HOME/lib"
export TNS_ADMIN="$HOME/tnsadmin" # Directory
export NLS_LANG=".AL32UTF8"
fi
# For fucking with "go" the language
export GOROOT=$HOME/Workspace/go
export GOOS=darwin
export GOARCH=386
export GOBIN=$HOME/bin
|
nateware/dotfiles
|
df59ec14f512d8930b02ad888dfe379071759477
|
added helper funcs for paths/libs
|
diff --git a/.bashrc b/.bashrc
index 38f440c..234a87c 100644
--- a/.bashrc
+++ b/.bashrc
@@ -1,78 +1,116 @@
# ~/.bashrc
umask 022
alias ls='\ls -Gh'
alias ll='ls -al'
alias wget='curl -LO'
alias ldd='otool -L'
alias rsync='\rsync --exclude=.svn --exclude=.git --exclude=RCS'
# Don't want local rubydocs - TOO SLOW!
alias gi='gem install --no-ri --no-rdoc'
alias bd='bundle --without=production'
+# Platform goodness
+export OS=`uname`
+[ "$OS" = Darwin ] && export JAVA_HOME=/Library/Java/Home
+
# For ruby version manager
[ -s $HOME/.rvm/scripts/rvm ] && . $HOME/.rvm/scripts/rvm
# For Jeweler
export JEWELER_OPTS='--bacon --create-repo --gemcutter'
+# Add to PATH but only if it exists
+add_path () {
+ err=0
+ for p
+ do
+ if [ -d $p ]; then
+ PATH="$p:$PATH"
+ else
+ err=1
+ fi
+ done
+ return $err
+}
+
+# Add to LD_LIB_PATH adjusting for platform
+add_lib () {
+ if [ "$OS" = Darwin ]; then
+ export DYLD_LIBRARY_PATH="$lib:$DYLD_LIBRARY_PATH"
+ else
+ export LD_LIBRARY_PATH="$lib:$DYLD_LIBRARY_PATH"
+ fi
+ return 0
+}
+
+# Guess
+add_path_and_lib () {
+ if add_path "$1"; then
+ lib=${1%/bin}/lib
+ add_lib $lib
+ else
+ return 1
+ fi
+}
+
# ImageMagick
-export PATH="/usr/local/ImageMagick/bin:$PATH"
-export DYLD_LIBRARY_PATH="/usr/local/ImageMagick/lib"
+add_path_and_lib /usr/local/ImageMagick/bin
# MySQL
-export PATH="/usr/local/mysql/bin:$PATH"
-export DYLD_LIBRARY_PATH="/usr/local/mysql/lib"
+add_path_and_lib /usr/local/mysql/bin
# MongoDB
-export PATH="$PATH:/usr/local/mongodb/bin"
-
-# For Amazon EC2
-export EC2_PRIVATE_KEY="$HOME/.ec2/pk-UO255XUYVOVVBXUWADA57YCL7XZZKQDE.pem"
-export EC2_CERT="$HOME/.ec2/cert-UO255XUYVOVVBXUWADA57YCL7XZZKQDE.pem"
-ec2_user=`cat $HOME/.ec2/ec2_user.txt`
-alias ess="ssh -i $HOME/.ec2/id_rsa-$ec2_user-keypair -o StrictHostKeyChecking=no -l root"
-alias esync="rsync -av -e 'ssh -i $HOME/.ec2/id_rsa-$ec2_user-keypair -o StrictHostKeyChecking=no -l root'"
-alias pss="ssh -i $HOME/.ec2/id_rsa-$ec2_user-user -o StrictHostKeyChecking=no -l $ec2_user"
-alias psync="rsync -av -e 'ssh -i $HOME/.ec2/id_rsa-$ec2_user-user -o StrictHostKeyChecking=no -l $ec2_user'"
-
-# For amazon-ec2 gem
-export AMAZON_ACCESS_KEY_ID=`cat $HOME/.ec2/access_key_id.txt`
-export AMAZON_SECRET_ACCESS_KEY=`cat $HOME/.ec2/secret_access_key.txt`
-
-# Tools for EC2
-export EC2_HOME=/usr/local/ec2-api-tools
-export PATH="$PATH:$EC2_HOME/bin"
-export JAVA_HOME=/Library/Java/Home
+add_path /usr/local/mongodb/bin
-# Put our ~/bin *first*
-export PATH=`echo "
+# Amazon EC2 CLI tools
+export EC2_HOME=/usr/local/ec2-api-tools
+add_path "$EC2_HOME/bin" || unset EC2_HOME
+
+# Amazon EC2 gems
+if [ -d "$HOME/.ec2" ]; then
+ export EC2_PRIVATE_KEY="$HOME/.ec2/pk-UO255XUYVOVVBXUWADA57YCL7XZZKQDE.pem"
+ export EC2_CERT="$HOME/.ec2/cert-UO255XUYVOVVBXUWADA57YCL7XZZKQDE.pem"
+ ec2_user=`cat $HOME/.ec2/ec2_user.txt`
+ alias ess="ssh -i $HOME/.ec2/id_rsa-$ec2_user-keypair -o StrictHostKeyChecking=no -l root"
+ alias esync="rsync -av -e 'ssh -i $HOME/.ec2/id_rsa-$ec2_user-keypair -o StrictHostKeyChecking=no -l root'"
+ alias pss="ssh -i $HOME/.ec2/id_rsa-$ec2_user-user -o StrictHostKeyChecking=no -l $ec2_user"
+ alias psync="rsync -av -e 'ssh -i $HOME/.ec2/id_rsa-$ec2_user-user -o StrictHostKeyChecking=no -l $ec2_user'"
+
+ # For amazon-ec2 gem
+ export AMAZON_ACCESS_KEY_ID=`cat $HOME/.ec2/access_key_id.txt`
+ export AMAZON_SECRET_ACCESS_KEY=`cat $HOME/.ec2/secret_access_key.txt`
+fi
+
+# Remember add_path prefixes, so the one you want first should be last
+add_path \
+ /Library/PostgreSQL/9.0/bin \
+ /usr/local/pgsql/bin \
+ /usr/local/git/bin \
+ /usr/local/bin \
+ /opt/local/sbin \
+ /opt/local/bin \
+ $HOME/sbin \
$HOME/bin
- $HOME/sbin
- /opt/local/bin
- /opt/local/sbin
- /usr/local/bin
- /usr/local/git/bin
- /usr/local/pgsql/bin
- $PATH
-" | tr -s '[:space:]' ':'`
export JVA=209.40.197.81
alias jva="ssh -l janetvanarsdale $JVA"
alias rjva="ssh -l root $JVA"
# Still needed for old games
export ORACLE_HOME="/usr/local/oracle/10.2.0.4/client"
-export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:$ORACLE_HOME/lib"
-export TNS_ADMIN="$HOME/tnsadmin" # Directory
-export NLS_LANG=".AL32UTF8"
-PATH="$PATH:$ORACLE_HOME/bin"
+if [ -d "$ORACLE_HOME" ]; then
+ add_path "$ORACLE_HOME/bin"
+ add_lib "$ORACLE_HOME/lib"
+ export TNS_ADMIN="$HOME/tnsadmin" # Directory
+ export NLS_LANG=".AL32UTF8"
+fi
# For fucking with "go" the language
export GOROOT=$HOME/Workspace/go
export GOOS=darwin
export GOARCH=386
export GOBIN=$HOME/bin
diff --git a/.gitconfig b/.gitconfig
index 2ec1d72..d0dfffd 100644
--- a/.gitconfig
+++ b/.gitconfig
@@ -1,18 +1,19 @@
[user]
- name = Nate Wiger
- email = nate@wiger.org
+ name = Nate Wiger
+ email = nate@wiger.org
[alias]
- ci = commit
- co = checkout
- st = status
- up = pull
- rv = checkout --
- br = branch -a
- hard = reset --hard origin/master
- hist = log --since=1.day --relative-date --stat
- mine = log --since=1.day --relative-date --stat --committer=nateware
- pu = !"git fetch origin -v; git fetch upstream -v; git merge upstream/master"
+ ci = commit
+ co = checkout
+ st = status
+ up = pull
+ pu = push -u origin
+ rv = checkout --
+ br = branch -a
+ hard = reset --hard origin/master
+ hist = log --since=1.day --relative-date --stat
+ mine = log --since=1.day --relative-date --stat --committer=nateware
+ #pu = !"git fetch origin -v; git fetch upstream -v; git merge upstream/master"
[color]
- diff = auto
- status = auto
- branch = auto
+ diff = auto
+ status = auto
+ branch = auto
|
nateware/dotfiles
|
a2a8c1d02129daa3764acbab6d24ed73abcf495a
|
added gitconfig to get highlighting
|
diff --git a/.gitconfig b/.gitconfig
new file mode 100644
index 0000000..2ec1d72
--- /dev/null
+++ b/.gitconfig
@@ -0,0 +1,18 @@
+[user]
+ name = Nate Wiger
+ email = nate@wiger.org
+[alias]
+ ci = commit
+ co = checkout
+ st = status
+ up = pull
+ rv = checkout --
+ br = branch -a
+ hard = reset --hard origin/master
+ hist = log --since=1.day --relative-date --stat
+ mine = log --since=1.day --relative-date --stat --committer=nateware
+ pu = !"git fetch origin -v; git fetch upstream -v; git merge upstream/master"
+[color]
+ diff = auto
+ status = auto
+ branch = auto
|
nateware/dotfiles
|
d483e20ed068da5349adabfe82a6bd5fd755c6d7
|
added colors to prompt because I am bored
|
diff --git a/.bash_profile b/.bash_profile
index 114a666..e3edd7d 100644
--- a/.bash_profile
+++ b/.bash_profile
@@ -1,7 +1,38 @@
+
+# Must source manually
[ -f $HOME/.bashrc ] && . $HOME/.bashrc
+# Colors!
+c1="\033["
+c2="m"
+c_normal="${c1}0${c2}"
+c_bold="${c1}1${c2}"
+c_black="${c1}0;30${c2}"
+c_blue="${c1}0;34${c2}"
+c_green="${c1}0;32${c2}"
+c_cyan="${c1}0;36${c2}"
+c_red="${c1}0;31${c2}"
+c_purple="${c1}0;35${c2}"
+c_brown="${c1}0;33${c2}"
+c_gray="${c1}0;37${c2}"
+c_dark_gray="${c1}1;30${c2}"
+c_bold_blue="${c1}1;34${c2}"
+c_bold_green="${c1}1;32${c2}"
+c_bold_cyan="${c1}1;36${c2}"
+c_bold_red="${c1}1;31${c2}"
+c_bold_purple="${c1}1;35${c2}"
+c_bold_yellow="${c1}1;33${c2}"
+c_bold_white="${c1}1;37${c2}"
+
+# Prompt
+export PS1='[\u@\h:\W]\$ '
+export PS1="[$c_green\u$c_normal@$c_purple\h$c_normal:$c_blue\W$c_normal]\$ "
+
+# Ruby version
use_ruby=ruby-1.9.2-p290
-echo "Setting rvm ruby to: $use_ruby"
+printf "Setting rvm ruby to: $c_red$use_ruby$c_normal\n"
rvm $use_ruby
+printf $c_red
type ruby
+printf $c_normal
diff --git a/.bashrc b/.bashrc
index b591f08..38f440c 100644
--- a/.bashrc
+++ b/.bashrc
@@ -1,79 +1,78 @@
# ~/.bashrc
umask 022
-export PS1='[\u@\h:\W]\$ '
alias ls='\ls -Gh'
alias ll='ls -al'
alias wget='curl -LO'
alias ldd='otool -L'
alias rsync='\rsync --exclude=.svn --exclude=.git --exclude=RCS'
# Don't want local rubydocs - TOO SLOW!
alias gi='gem install --no-ri --no-rdoc'
alias bd='bundle --without=production'
# For ruby version manager
[ -s $HOME/.rvm/scripts/rvm ] && . $HOME/.rvm/scripts/rvm
# For Jeweler
export JEWELER_OPTS='--bacon --create-repo --gemcutter'
# ImageMagick
export PATH="/usr/local/ImageMagick/bin:$PATH"
export DYLD_LIBRARY_PATH="/usr/local/ImageMagick/lib"
# MySQL
export PATH="/usr/local/mysql/bin:$PATH"
export DYLD_LIBRARY_PATH="/usr/local/mysql/lib"
# MongoDB
export PATH="$PATH:/usr/local/mongodb/bin"
# For Amazon EC2
export EC2_PRIVATE_KEY="$HOME/.ec2/pk-UO255XUYVOVVBXUWADA57YCL7XZZKQDE.pem"
export EC2_CERT="$HOME/.ec2/cert-UO255XUYVOVVBXUWADA57YCL7XZZKQDE.pem"
ec2_user=`cat $HOME/.ec2/ec2_user.txt`
alias ess="ssh -i $HOME/.ec2/id_rsa-$ec2_user-keypair -o StrictHostKeyChecking=no -l root"
alias esync="rsync -av -e 'ssh -i $HOME/.ec2/id_rsa-$ec2_user-keypair -o StrictHostKeyChecking=no -l root'"
alias pss="ssh -i $HOME/.ec2/id_rsa-$ec2_user-user -o StrictHostKeyChecking=no -l $ec2_user"
alias psync="rsync -av -e 'ssh -i $HOME/.ec2/id_rsa-$ec2_user-user -o StrictHostKeyChecking=no -l $ec2_user'"
# For amazon-ec2 gem
export AMAZON_ACCESS_KEY_ID=`cat $HOME/.ec2/access_key_id.txt`
export AMAZON_SECRET_ACCESS_KEY=`cat $HOME/.ec2/secret_access_key.txt`
# Tools for EC2
export EC2_HOME=/usr/local/ec2-api-tools
export PATH="$PATH:$EC2_HOME/bin"
export JAVA_HOME=/Library/Java/Home
# Put our ~/bin *first*
export PATH=`echo "
$HOME/bin
$HOME/sbin
/opt/local/bin
/opt/local/sbin
/usr/local/bin
/usr/local/git/bin
/usr/local/pgsql/bin
$PATH
" | tr -s '[:space:]' ':'`
export JVA=209.40.197.81
alias jva="ssh -l janetvanarsdale $JVA"
alias rjva="ssh -l root $JVA"
# Still needed for old games
export ORACLE_HOME="/usr/local/oracle/10.2.0.4/client"
export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:$ORACLE_HOME/lib"
export TNS_ADMIN="$HOME/tnsadmin" # Directory
export NLS_LANG=".AL32UTF8"
PATH="$PATH:$ORACLE_HOME/bin"
# For fucking with "go" the language
export GOROOT=$HOME/Workspace/go
export GOOS=darwin
export GOARCH=386
export GOBIN=$HOME/bin
|
nateware/dotfiles
|
1496cd45679a3ce64aff744ca441af330d94d45e
|
umask and bundle alias
|
diff --git a/.bashrc b/.bashrc
index 9cf8b5e..c26daa8 100644
--- a/.bashrc
+++ b/.bashrc
@@ -1,79 +1,81 @@
# ~/.bashrc
+umask 022
export PS1='[\u@\h:\W]\$ '
alias ls='\ls -Gh'
alias ll='ls -al'
alias wget='curl -LO'
alias ldd='otool -L'
alias rsync='\rsync --exclude=.svn --exclude=.git --exclude=RCS'
# Don't want local rubydocs - TOO SLOW!
alias gi='gem install --no-ri --no-rdoc'
+alias bd='bundle --without=production'
# For Jeweler
export JEWELER_OPTS='--bacon --create-repo --gemcutter'
# ImageMagick
export PATH="/usr/local/ImageMagick/bin:$PATH"
export DYLD_LIBRARY_PATH="/usr/local/ImageMagick/lib"
# MySQL
export PATH="/usr/local/mysql/bin:$PATH"
export DYLD_LIBRARY_PATH="/usr/local/mysql/lib"
# MongoDB
export PATH="$PATH:/usr/local/mongodb/bin"
# For Amazon EC2
export EC2_PRIVATE_KEY="$HOME/.ec2/pk-UO255XUYVOVVBXUWADA57YCL7XZZKQDE.pem"
export EC2_CERT="$HOME/.ec2/cert-UO255XUYVOVVBXUWADA57YCL7XZZKQDE.pem"
ec2_user=`cat $HOME/.ec2/ec2_user.txt`
alias ess="ssh -i $HOME/.ec2/id_rsa-$ec2_user-keypair -o StrictHostKeyChecking=no -l root"
alias esync="rsync -av -e 'ssh -i $HOME/.ec2/id_rsa-$ec2_user-keypair -o StrictHostKeyChecking=no -l root'"
alias pss="ssh -i $HOME/.ec2/id_rsa-$ec2_user-user -o StrictHostKeyChecking=no -l $ec2_user"
alias psync="rsync -av -e 'ssh -i $HOME/.ec2/id_rsa-$ec2_user-user -o StrictHostKeyChecking=no -l $ec2_user'"
# For amazon-ec2 gem
export AMAZON_ACCESS_KEY_ID=`cat $HOME/.ec2/access_key_id.txt`
export AMAZON_SECRET_ACCESS_KEY=`cat $HOME/.ec2/secret_access_key.txt`
export PLAYCO_ROOT=$HOME/Workspace/playerconnect
if [ -d $PLAYCO_ROOT ]; then
for file in $PLAYCO_ROOT/util/sh/*.sh
do
. $file
done
fi
# Tools for EC2
export EC2_HOME=/usr/local/ec2-api-tools-current
export PATH="$PATH:$EC2_HOME/bin"
export JAVA_HOME=/Library/Java/Home
# Put our ~/bin *first*
export PATH="$HOME/bin:$HOME/sbin:/usr/local/bin:/usr/local/mysql/bin:/usr/local/git/bin:/usr/local/pgsql/bin:$PATH:/opt/local/bin:/opt/local/sbin"
# For ruby version manager
[ -s $HOME/.rvm/scripts/rvm ] && . $HOME/.rvm/scripts/rvm
# Still needed for old games
export ORACLE_HOME="/usr/local/oracle/10.2.0.4/client"
export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:$ORACLE_HOME/lib"
export TNS_ADMIN="$HOME/Workspace/playerconnect/base/webservices/trunk/config"
export NLS_LANG=".AL32UTF8"
PATH="$PATH:$ORACLE_HOME/bin"
function g {
local current_link="$HOME/Workspace/current"
if [ ! -d "$current_link" ]; then
echo "No valid current project symlink: $current_link" >&2
return
else
local project=`readlink $current_link`
[[ "$project" = /* ]] || project="$HOME/Workspace/$project"
echo cd $project
cd $project
fi
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.