* Initialize function call usage data. * Called by the executor before invoking a function. */
| 1924 | * Called by the executor before invoking a function. |
| 1925 | */ |
| 1926 | void |
| 1927 | pgstat_init_function_usage(FunctionCallInfo fcinfo, |
| 1928 | PgStat_FunctionCallUsage *fcu) |
| 1929 | { |
| 1930 | PgStat_BackendFunctionEntry *htabent; |
| 1931 | bool found; |
| 1932 | |
| 1933 | if (pgstat_track_functions <= fcinfo->flinfo->fn_stats) |
| 1934 | { |
| 1935 | /* stats not wanted */ |
| 1936 | fcu->fs = NULL; |
| 1937 | return; |
| 1938 | } |
| 1939 | |
| 1940 | if (!pgStatFunctions) |
| 1941 | { |
| 1942 | /* First time through - initialize function stat table */ |
| 1943 | HASHCTL hash_ctl; |
| 1944 | |
| 1945 | hash_ctl.keysize = sizeof(Oid); |
| 1946 | hash_ctl.entrysize = sizeof(PgStat_BackendFunctionEntry); |
| 1947 | pgStatFunctions = hash_create("Function stat entries", |
| 1948 | PGSTAT_FUNCTION_HASH_SIZE, |
| 1949 | &hash_ctl, |
| 1950 | HASH_ELEM | HASH_BLOBS); |
| 1951 | } |
| 1952 | |
| 1953 | /* Get the stats entry for this function, create if necessary */ |
| 1954 | htabent = hash_search(pgStatFunctions, &fcinfo->flinfo->fn_oid, |
| 1955 | HASH_ENTER, &found); |
| 1956 | if (!found) |
| 1957 | MemSet(&htabent->f_counts, 0, sizeof(PgStat_FunctionCounts)); |
| 1958 | |
| 1959 | fcu->fs = &htabent->f_counts; |
| 1960 | |
| 1961 | /* save stats for this function, later used to compensate for recursion */ |
| 1962 | fcu->save_f_total_time = htabent->f_counts.f_total_time; |
| 1963 | |
| 1964 | /* save current backend-wide total time */ |
| 1965 | fcu->save_total = total_func_time; |
| 1966 | |
| 1967 | /* get clock time as of function start */ |
| 1968 | INSTR_TIME_SET_CURRENT(fcu->f_start); |
| 1969 | } |
| 1970 | |
| 1971 | /* |
| 1972 | * find_funcstat_entry - find any existing PgStat_BackendFunctionEntry entry |
no test coverage detected