leopard, 一个在线代码调试框架

来源:互联网 发布:淘宝 口头禅 编辑:程序博客网 时间:2024/06/05 02:54

leopard是一个在线代码调试框架。

如果你有下列需求,可以使用这个框架

(1)动态修改线上程序的一些配置参数,比如说,线程池的数目,timeout的阈值等

(2)得到线上程序的一些状态,比如,搜索引擎中,一个请求对应的排序后文档列表


leopard提供了一个注册callback机制,用户只需提供实现自己的callback函数,并注册到一个唯一的路径,就可以在线的按照指定的路径来请求函数,并得到相应的结果。


leopard使用非常简单,直接嵌入到你的程序中即可。具体使用步骤可以参考提供的例子。


#include <string>#include <utility>#include <vector>#include <boost/bind.hpp>#include "cpp_leopard/leopard/leopard.h"using namespace cpp_leopard::leopard;using namespace std;// Note:// For convenience, this file unit does not follow the// google coding style in a way.typedef vector<pair<string, string> > vector_pair_type;string non_member_function(const vector_pair_type& parameters) {  return "A non-member function";;}class Foo { public:  string operator() (const vector_pair_type& parameters) {    return "A function object";  }  string NonStaticMemberFunction(const vector_pair_type& parameters) const {    return "A non-static member function";  }  static string StaticMemberFunction(const vector_pair_type& parameters) {    return "A static member function";  }};int main() {  AbstractHttpServer& server = GetDefaultServer();  RegisterCommonHandlers(&server);  if (!server.Start()) {    return -1;  }  // Register a free function(non-member function)  server.RegisterHandler("/function/non_member_function",                         non_member_function);  // Register a functor(function object)  server.RegisterHandler("/function/function_object", Foo());  // Register a static member function  server.RegisterHandler("/function/static_member_function",                         Foo::StaticMemberFunction);  // Register a member function with boost::bind or std::bindxxx  // Note: I have a while loop below, so the local var 'foo' will  // never be destroyed. It's just an example here. Beware don't  // do this in your project.  Foo foo;  server.RegisterHandler("/function/non_static_member_function",                         boost::bind(&Foo::NonStaticMemberFunction, &foo, _1));  while (true) {    sleep(10);  }}


注意:

(1)提供了C++的版本,后续会推出java等版本。

(2)不支持跨平台,目前仅支持unix/linux平台

(3)leopard采用腾讯开源的blade编译工具进行编译

(4)非常轻量级,基本不会影响线上程序的性能

(5)leopard采用一个轻量级的web server,mongoose来提供http通信服务。 用户也可以定制,只需实现相应的接口即可。

(6)线程安全


具体项目已开源在github上,请关注https://github.com/JianboZhu/leopard

原创粉丝点击