-
Notifications
You must be signed in to change notification settings - Fork 795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Export stats #2326
Merged
Merged
Export stats #2326
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ccae9d7
Implement currently_processing_block_id
theoreticalbts dd1f58b
Change applied_block(signed_block&) to post_apply_block(block_notific…
theoreticalbts d65ef58
Remove unused on_pending signal
theoreticalbts a4e290e
Cleanup signal handling
theoreticalbts b779039
Implement pre_apply_block signal
theoreticalbts cf020bc
Get rid of special handling for group == -1
theoreticalbts e548eae
Implement block_data_export plugin
theoreticalbts 9354983
Implement stats_export_plugin
theoreticalbts e72236a
Add block_data_export_plugin to APPBASE_PLUGIN_REQUIRES
theoreticalbts File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
file(GLOB HEADERS "include/steem/plugins/stats_export/*.hpp") | ||
|
||
add_library( stats_export_plugin | ||
stats_export_plugin.cpp | ||
) | ||
|
||
target_link_libraries( stats_export_plugin block_data_export_plugin chain_plugin steem_chain steem_protocol ) | ||
target_include_directories( stats_export_plugin | ||
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) | ||
|
||
if( CLANG_TIDY_EXE ) | ||
set_target_properties( | ||
stats_export_plugin PROPERTIES | ||
CXX_CLANG_TIDY "${DO_CLANG_TIDY}" | ||
) | ||
endif( CLANG_TIDY_EXE ) | ||
|
||
install( TARGETS | ||
stats_export_plugin | ||
|
||
RUNTIME DESTINATION bin | ||
LIBRARY DESTINATION lib | ||
ARCHIVE DESTINATION lib | ||
) |
33 changes: 33 additions & 0 deletions
33
libraries/plugins/stats_export/include/steem/plugins/stats_export/stats_export_plugin.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#pragma once | ||
#include <appbase/application.hpp> | ||
|
||
#include <steem/plugins/chain/chain_plugin.hpp> | ||
|
||
namespace steem { namespace plugins { namespace stats_export { | ||
|
||
namespace detail { class stats_export_plugin_impl; } | ||
|
||
using namespace appbase; | ||
|
||
#define STEEM_STATS_EXPORT_PLUGIN_NAME "stats_export" | ||
|
||
class stats_export_plugin : public appbase::plugin< stats_export_plugin > | ||
{ | ||
public: | ||
stats_export_plugin(); | ||
virtual ~stats_export_plugin(); | ||
|
||
APPBASE_PLUGIN_REQUIRES( (steem::plugins::chain::chain_plugin) ) | ||
|
||
static const std::string& name() { static std::string name = STEEM_STATS_EXPORT_PLUGIN_NAME; return name; } | ||
|
||
virtual void set_program_options( options_description& cli, options_description& cfg ) override; | ||
virtual void plugin_initialize( const variables_map& options ) override; | ||
virtual void plugin_startup() override; | ||
virtual void plugin_shutdown() override; | ||
|
||
private: | ||
std::unique_ptr< detail::stats_export_plugin_impl > my; | ||
}; | ||
|
||
} } } // steem::plugins::stats_export |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"plugin_name": "stats_export", | ||
"plugin_namespace": "stats_export", | ||
"plugin_project": "stats_export_plugin" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
|
||
#include <steem/plugins/block_data_export/block_data_export_plugin.hpp> | ||
#include <steem/plugins/block_data_export/exportable_block_data.hpp> | ||
|
||
#include <steem/plugins/stats_export/stats_export_plugin.hpp> | ||
|
||
#include <steem/chain/account_object.hpp> | ||
#include <steem/chain/database.hpp> | ||
#include <steem/chain/global_property_object.hpp> | ||
#include <steem/chain/index.hpp> | ||
#include <steem/chain/operation_notification.hpp> | ||
|
||
#include <fstream> | ||
#include <iostream> | ||
#include <sstream> | ||
|
||
namespace steem { namespace plugins { namespace stats_export { | ||
|
||
using steem::chain::block_notification; | ||
using steem::chain::database; | ||
using steem::chain::dynamic_global_property_object; | ||
|
||
using steem::protocol::account_name_type; | ||
using steem::protocol::authority; | ||
using steem::protocol::signed_transaction; | ||
|
||
using steem::plugins::block_data_export::block_data_export_plugin; | ||
using steem::plugins::block_data_export::exportable_block_data; | ||
|
||
using steem::plugins::chain::chain_plugin; | ||
|
||
namespace detail { | ||
|
||
struct api_stats_transaction_data_object | ||
{ | ||
account_name_type user; | ||
uint32_t size = 0; | ||
}; | ||
|
||
class api_stats_export_data_object | ||
: public exportable_block_data | ||
{ | ||
public: | ||
api_stats_export_data_object() {} | ||
virtual ~api_stats_export_data_object() {} | ||
|
||
virtual void to_variant( fc::variant& v )const override | ||
{ | ||
fc::to_variant( *this, v ); | ||
} | ||
|
||
dynamic_global_property_object global_properties; | ||
std::vector< api_stats_transaction_data_object > transaction_stats; | ||
uint64_t free_memory = 0; | ||
}; | ||
|
||
} } } } | ||
|
||
FC_REFLECT( steem::plugins::stats_export::detail::api_stats_transaction_data_object, (user)(size) ) | ||
FC_REFLECT( steem::plugins::stats_export::detail::api_stats_export_data_object, (global_properties)(transaction_stats)(free_memory) ) | ||
|
||
namespace steem { namespace plugins { namespace stats_export { namespace detail { | ||
|
||
class stats_export_plugin_impl | ||
{ | ||
public: | ||
stats_export_plugin_impl( stats_export_plugin& _plugin ) : | ||
_db( appbase::app().get_plugin< chain_plugin >().db() ), | ||
_self( _plugin ), | ||
_export_plugin( appbase::app().get_plugin< block_data_export_plugin >() ) | ||
{} | ||
|
||
void on_post_apply_block( const block_notification& note ); | ||
|
||
database& _db; | ||
stats_export_plugin& _self; | ||
boost::signals2::connection _post_apply_block_conn; | ||
|
||
block_data_export_plugin& _export_plugin; | ||
}; | ||
|
||
account_name_type get_transaction_user( const signed_transaction& tx ) | ||
{ | ||
flat_set< account_name_type > active; | ||
flat_set< account_name_type > owner; | ||
flat_set< account_name_type > posting; | ||
vector< authority > other; | ||
|
||
tx.get_required_authorities( active, owner, posting, other ); | ||
|
||
for( const account_name_type& name : posting ) | ||
return name; | ||
for( const account_name_type& name : active ) | ||
return name; | ||
for( const account_name_type& name : owner ) | ||
return name; | ||
return account_name_type(); | ||
} | ||
|
||
void stats_export_plugin_impl::on_post_apply_block( const block_notification& note ) | ||
{ | ||
std::shared_ptr< api_stats_export_data_object > stats = _export_plugin.find_export_data< api_stats_export_data_object >( STEEM_STATS_EXPORT_PLUGIN_NAME ); | ||
if( !stats ) | ||
return; | ||
|
||
stats->global_properties = _db.get_dynamic_global_properties(); | ||
for( const signed_transaction& tx : note.block.transactions ) | ||
{ | ||
stats->transaction_stats.emplace_back(); | ||
|
||
api_stats_transaction_data_object& tx_stats = stats->transaction_stats.back(); | ||
tx_stats.user = get_transaction_user( tx ); | ||
tx_stats.size = fc::raw::pack_size( tx ); | ||
} | ||
|
||
stats->free_memory = _db.get_free_memory(); | ||
} | ||
|
||
} // detail | ||
|
||
stats_export_plugin::stats_export_plugin() {} | ||
stats_export_plugin::~stats_export_plugin() {} | ||
|
||
void stats_export_plugin::set_program_options( options_description& cli, options_description& cfg ) | ||
{ | ||
/* | ||
cfg.add_options() | ||
("block-log-info-print-interval-seconds", boost::program_options::value< int32_t >()->default_value(60*60*24), "How often to print out stats_export (default 1 day)") | ||
("block-log-info-print-irreversible", boost::program_options::value< bool >()->default_value(true), "Whether to defer printing until block is irreversible") | ||
("block-log-info-print-file", boost::program_options::value< string >()->default_value("ILOG"), "Where to print (filename or special sink ILOG, STDOUT, STDERR)") | ||
; | ||
*/ | ||
} | ||
|
||
void stats_export_plugin::plugin_initialize( const boost::program_options::variables_map& options ) | ||
{ | ||
my = std::make_unique< detail::stats_export_plugin_impl >( *this ); | ||
try | ||
{ | ||
ilog( "Initializing stats_export plugin" ); | ||
my->_post_apply_block_conn = my->_db.add_post_apply_block_handler( | ||
[&]( const block_notification& note ){ my->on_post_apply_block( note ); }, *this ); | ||
my->_export_plugin.register_export_data_factory( STEEM_STATS_EXPORT_PLUGIN_NAME, | ||
[]() -> std::shared_ptr< exportable_block_data > { return std::make_shared< detail::api_stats_export_data_object >(); } ); | ||
} | ||
FC_CAPTURE_AND_RETHROW() | ||
} | ||
|
||
void stats_export_plugin::plugin_startup() {} | ||
|
||
void stats_export_plugin::plugin_shutdown() | ||
{ | ||
chain::util::disconnect_signal( my->_post_apply_block_conn ); | ||
} | ||
|
||
} } } // steem::plugins::stats_export |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because you are using the
block_data_export_plugin
as a dependency, you should specify it inAPPBASE_PLUGIN_REQUIRES