zoukankan      html  css  js  c++  java
  • Babelfish 基本试用

    测试使用docker 部署

    docker-compose文件

    注意网络模型选择的host,同时配置了opentracing 服务

    version: "3"
    services:
      bblfsh:
        image: bblfsh/bblfshd
        privileged: true
        environment:
        - "JAEGER_AGENT_HOST=localhost"
        - "JAEGER_AGENT_PORT=6831"
        - "JAEGER_SAMPLER_TYPE=const"
        - "JAEGER_SAMPLER_PARAM=1"
        network_mode: "host"
        ports:
        - "9432:9432"
        volumes:
        - "/var/lib/bblfshd:/var/lib/bblfshd"
        - "/var/run/docker.sock:/var/run/docker.sock"
      jaeger:
        image: jaegertracing/all-in-one:1.8
        ports:
        - "5775:5775/udp"
        - "6831:6831/udp"
        - "6832:6832/udp"
        - "5778:5778"
        - "16686:16686"
        - "14268:14268"
        - "9411:9411"
     
     

    安装驱动

    对于语言解析处理的docker 镜像,inside 容器,为了简单,添加的只有golang 的
    如果网络比较好的话,可以安装所有的,使用--all参数,或者推荐的 --recommended

     
    bblfshctl driver install docker://bblfsh/go-driver:latest

    解析 golang 语言

    inside 容器,因为按照其他语言的驱动有点慢,所以自己copy 一个golang 代码文件到容器,同时
    只安装了简单的golang driver

    • 准备golang 代码
      main.go
     
    package main
    import "fmt"
    func main() {
     fmt.Println("demoapp")
    }
     
     

    拷贝文件
    注意修改为自己的容器id

    <wiz_code_mirror>
     
     
     
     
     
    docker cp main.go 4116cc1ee650:/opt/
     
     
    • 指定解析
    bblfshctl parse /opt/main.go
    • 生成的代码ast 解析
      比较多,保留部分
     
    Status: Ok
    Elapsed: 1.099302113s
    Module {
    . Roles: File,Module
    . Children: {
    . . 0: Expr {
    . . . Roles: Expression
    . . . StartPosition: {
    . . . . Offset: 0
    . . . . Line: 1
    . . . . Col: 1
    . . . }
    . . . Properties: {
    . . . . internalRole: body
    . . . }
    . . . Children: {
    . . . . 0: Call {
    . . . . . Roles: Function,Call,Expression
    . . . . . StartPosition: {
    . . . . . . Offset: 0
    . . . . . . Line: 1
    . . . . . . Col: 1
    . . . . . }
    . . . . . Properties: {
    . . . . . . internalRole: value
    . . . . . }
    . . . . . Children: {
    . . . . . . 0: Name {
    . . . . . . . Roles: Identifier,Expression,Call,Callee
    . . . . . . . TOKEN "print"
    . . . . . . . StartPosition: {
    . . . . . . . . Offset: 0
    . . . . . . . . Line: 1
    . . . . . . . . Col: 1
    . . . . . . . }
    。。。。
     
     
    • opentracing 统计分析
      不同driver 的请求

      golang 解析的请求链路

    说明

    Babelfish 的功能很强大, 对于我们分析代码是很方便的,同时生产环境,建议的方式是使用client 调用grpc 服务,同时官方也提供了
    一个web 的dashboard ,方便我们测试

    参考资料

    https://doc.bblf.sh/using-babelfish/advanced-usage.html

  • 相关阅读:
    Codeforces Round #277 (Div. 2) D. Valid Sets 暴力
    Codeforces Round #277 (Div. 2) B. OR in Matrix 贪心
    Codeforces Round #277 (Div. 2) A. Calculating Function 水题
    套题 Codeforces Round #277 (Div. 2)
    模板 读入挂
    Codeforces Round #276 (Div. 1) B. Maximum Value 筛倍数
    Codeforces Round #276 (Div. 1) A. Bits 二进制 贪心
    json转字符串 —— jsonObj.toJSONString()与JSON.stringify(jsonObj)
    JSONP跨域提交表单
    jquery ajaxSubmit
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/10274092.html
Copyright © 2011-2022 走看看