NaCl tips; æ¨æºåºåã§ã®ãã°æ¡ããå©ãæ§ãªã®ã§
å æ¥NaClã§std::coutããã¨ãã¹ãããã¦ã§ããã©ã¦ã¶ã¼ã®ã³ã³ã½ã¼ã«ã«åºåãå¾ãããäºã確èªãã¾ãããJavaScriptã¸ã¡ãã»ã¼ã¸ã³ã°ãã¦console.logã¸åºãæ¹æ³ãèãã¦å± ãã®ã§ãããåªã§ããè² è·ãæããããªãJavaScriptã«å¤§éã®ãããã°ãã°ãã¡ãã»ã¼ã¸ã³ã°ããã¨ããconsole.logããæä½æ¥ã§ãã°ãååãã¦ç¢ºèªããã¨ãã¤ã±ããã¤ã®ã§å·®ãå½ããstd::coutã§ããããprintfãããã°ãããããã°ãåãããäºã«ãã¾ããã
ä»ãæãæ®éã®OSã¯POSIXæºæ ãªã®ã§teeã³ãã³ããããã©ãã¨ããäºã¯ç¡ã使ããçãªã®ã§ãchromiumã®ãã°ã¯teeã§æ¨æºåºåã¨ãã¡ã¤ã«ã«åå¾ããã°éçºæã®ç°¡æãããã°ç¨ã«å¤§éã®ãã°ãåããã¦ããã»ã©åé¡ç¡ã解æã§ãã¾ããã³ã³ã½ã¼ã«ã§ãªã¢ã«ã¿ã¤ã ç£è¦ãã§ãã¾ãã
ãã¬ã¼(ã¨ããããä»æ§)
#define WRP_PRODUCT_NAME "Labyrinthian" namespace wrp { #if !defined(WRP_PRODUCT_NAME) #define WRP_PRODUCT_NAME "UNKNOWN PRODUCT" #endif class log{ decltype(std::chrono::system_clock::now()) start; std::string object_name; void* object_address; static int nesting_counter; public: std::stringstream buffer; explicit log(std::string object_name_ = "", void* object_address_ = 0) : start(std::chrono::system_clock::now()) , object_name(object_name_) , object_address(object_address_) { ++nesting_counter; } ~log(){ auto end = std::chrono::system_clock::now(); std::string indent; for(auto n = nesting_counter; n; --n) indent += " "; std::cout << indent << "[" WRP_PRODUCT_NAME "] " << object_name << " " << object_address << "\n" << indent << "start: " << duration_cast<unit>(start.time_since_epoch()).count() << "\n" << indent << "end : " << duration_cast<unit>(end.time_since_epoch()).count() << "\n" << indent << "dt : " << duration_cast<unit>((end - start)).count() << "\n" ; std::string b; while(std::getline(buffer, b)) std::cout << indent << b << "\n"; std::cout << std::flush; --nesting_counter; } auto operator<<(const bool v) -> decltype(buffer<<v) { return buffer << v; } auto operator<<(const char* v) -> decltype(buffer<<v) { return buffer << v; } auto operator<<(std::string& v) -> decltype(buffer<<v) { return buffer << v; } auto operator<<(int& v) -> decltype(buffer<<v){ return buffer << v; } }; int log::nesting_counter = -1; }
試ãã«åå¾ãããã°ã®åãã£ç«¯
[98,964327168:10:17:37.572582] Native Client module will be loaded at base address 0x00007fee00000000 [98,964048640:10:17:38.366746] NaClAbiStatHostDescStatXlateCtor: Unusual NaCl descriptor type (not constructible). The NaCl app has a file with st_mode = 010600. (This is normal for std{in,out,err}, or other inherited/injected files.) [Labyrinthian] Labyrinthian_instance 0x10070098 start: 987.287 end : 987.287 dt : 0.00015 [Labyrinthian] Init 0x10070098 start: 987.287 end : 987.287 dt : 4e-05 attribute#0 name: id value: nacl_targetattribute#1 name: type value: application/x-naclattribute#2 name: src value: Labyrinthian.nmfattribute#3 name: @dev value: [Labyrinthian] DidChangeView(const pp::Rect&, const pp::Rect&) 0x10070098 start: 987.288 end : 987.288 dt : 0 [Labyrinthian] DidChangeView(const pp::View&) 0x10070098 start: 987.287 end : 987.288 dt : 0.00012 [Labyrinthian] HandleInputEvent 0x10070098 start: 1028.32 end : 1028.32 dt : 8e-05 type: 3 time: 41574.815489768982
ãã¾ã: Makefileã«ã¦
- test-server
.PHONY: test-server test-server: all _site darkhttpd _site --index main.html --port 12345
- test-client
.PHONY: test-client test-client: @ if [ -f test-client.log ]; then rm -v test-client.log; fi; chromium-dev "http://localhost:12345" | tee test-client.log
ã³ã³ã½ã¼ã«ã®ãã°åºåãæ··ããã¨èªãããããããªãã®ã§ã`make test-server`ã¨`make test-client`åå¥ã®ç«¯æ«ã¨ãã¥ã¬ã¼ã¿âã並ã¹ã¦ãã¹ãããæãã
ãã¾ãã®ãã¾ã: NaClã«ãããstd::chrono::system_clock
ã©ãããå°ãªãã¨ãchromium-dev 20.0.1115.1ã§ãã¹ãããNaClã§ã¯ãstd::chrono::system_clock::now()ãã¦time_since_spoch()ãã¦ãã¦ã§ããã©ã¦ã¶ã¼ã®ããã»ã¹ãèµ·åãã¦ããã®çµéæéãåå¾ããæ§ã ãç¸å¯¾çãªæéåå¾ã«ã¯å°ããªããã©ãã¡ãã£ã¨ããã¯ã©ããªã®ããã¨ã»ï½ã»ï¼