Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

swh:1:snp:158a3f36b0bd3da461fb7458de44cfa2c94e4270
  • Code
  • Branches (0)
  • Releases (20)
    • Branches
    • Releases
      • 1.18.0-6ubuntu14.1
      • 1.18.0-6ubuntu14
      • 1.18.0-6ubuntu11.1
      • 1.18.0-6ubuntu11
      • 1.18.0-6ubuntu8.2
      • 1.18.0-6ubuntu8
      • 1.18.0-0ubuntu1.3
      • 1.17.10-0ubuntu1
      • 1.14.0-0ubuntu1.10
      • 1.10.3-0ubuntu0.16.04.5
      • 1.9.15-0ubuntu1
      • 1.4.6-1ubuntu3.9
      • 1.4.6-1ubuntu3
    • 3f4fece
    • /
    • src
    • /
    • misc
    • /
    • ngx_google_perftools_module.c
    Raw File Download

    To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
    Select below a type of object currently browsed in order to display its associated SWHID and permalink.

    • content
    • directory
    • snapshot
    • release
    content badge
    swh:1:cnt:f2f8221b560587ada36764713602d410d4ef4d7c
    directory badge
    swh:1:dir:dc1b4be19b2e17b02c3ebddfb4764fda84244a0f
    snapshot badge
    swh:1:snp:158a3f36b0bd3da461fb7458de44cfa2c94e4270
    release badge
    swh:1:rel:768dfd8ff182940cf6903371cdbfcde764231226

    This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
    Select below a type of object currently browsed in order to generate citations for them.

    • content
    • directory
    • snapshot
    • release
    Generate software citation in BibTex format (requires biblatex-software package)
    Generating citation ...
    Generate software citation in BibTex format (requires biblatex-software package)
    Generating citation ...
    Generate software citation in BibTex format (requires biblatex-software package)
    Generating citation ...
    Generate software citation in BibTex format (requires biblatex-software package)
    Generating citation ...
    ngx_google_perftools_module.c
    
    /*
     * Copyright (C) Igor Sysoev
     * Copyright (C) Nginx, Inc.
     */
    
    
    #include <ngx_config.h>
    #include <ngx_core.h>
    
    /*
     * declare Profiler interface here because
     * <google/profiler.h> is C++ header file
     */
    
    int ProfilerStart(u_char* fname);
    void ProfilerStop(void);
    void ProfilerRegisterThread(void);
    
    
    static void *ngx_google_perftools_create_conf(ngx_cycle_t *cycle);
    static ngx_int_t ngx_google_perftools_worker(ngx_cycle_t *cycle);
    
    
    typedef struct {
        ngx_str_t  profiles;
    } ngx_google_perftools_conf_t;
    
    
    static ngx_command_t  ngx_google_perftools_commands[] = {
    
        { ngx_string("google_perftools_profiles"),
          NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
          ngx_conf_set_str_slot,
          0,
          offsetof(ngx_google_perftools_conf_t, profiles),
          NULL },
    
        ngx_null_command
    };
    
    
    static ngx_core_module_t  ngx_google_perftools_module_ctx = {
        ngx_string("google_perftools"),
        ngx_google_perftools_create_conf,
        NULL
    };
    
    
    ngx_module_t  ngx_google_perftools_module = {
        NGX_MODULE_V1,
        &ngx_google_perftools_module_ctx,      /* module context */
        ngx_google_perftools_commands,         /* module directives */
        NGX_CORE_MODULE,                       /* module type */
        NULL,                                  /* init master */
        NULL,                                  /* init module */
        ngx_google_perftools_worker,           /* init process */
        NULL,                                  /* init thread */
        NULL,                                  /* exit thread */
        NULL,                                  /* exit process */
        NULL,                                  /* exit master */
        NGX_MODULE_V1_PADDING
    };
    
    
    static void *
    ngx_google_perftools_create_conf(ngx_cycle_t *cycle)
    {
        ngx_google_perftools_conf_t  *gptcf;
    
        gptcf = ngx_pcalloc(cycle->pool, sizeof(ngx_google_perftools_conf_t));
        if (gptcf == NULL) {
            return NULL;
        }
    
        /*
         * set by ngx_pcalloc()
         *
         *     gptcf->profiles = { 0, NULL };
         */
    
        return gptcf;
    }
    
    
    static ngx_int_t
    ngx_google_perftools_worker(ngx_cycle_t *cycle)
    {
        u_char                       *profile;
        ngx_google_perftools_conf_t  *gptcf;
    
        gptcf = (ngx_google_perftools_conf_t *)
                    ngx_get_conf(cycle->conf_ctx, ngx_google_perftools_module);
    
        if (gptcf->profiles.len == 0) {
            return NGX_OK;
        }
    
        profile = ngx_alloc(gptcf->profiles.len + NGX_INT_T_LEN + 2, cycle->log);
        if (profile == NULL) {
            return NGX_OK;
        }
    
        if (getenv("CPUPROFILE")) {
            /* disable inherited Profiler enabled in master process */
            ProfilerStop();
        }
    
        ngx_sprintf(profile, "%V.%d%Z", &gptcf->profiles, ngx_pid);
    
        if (ProfilerStart(profile)) {
            /* start ITIMER_PROF timer */
            ProfilerRegisterThread();
    
        } else {
            ngx_log_error(NGX_LOG_CRIT, cycle->log, ngx_errno,
                          "ProfilerStart(%s) failed", profile);
        }
    
        ngx_free(profile);
    
        return NGX_OK;
    }
    
    
    /* ProfilerStop() is called on Profiler destruction */
    

    back to top

    Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
    The source code of Software Heritage itself is available on our development forge.
    The source code files archived by Software Heritage are available under their own copyright and licenses.
    Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API