# Interval Profile Dumping

The _PGOPTI_Set_Interval_Prof_Dump() function activates Interval Profile Dumping and sets the approximate frequency at which dumps occur. This function is used in non-terminating applications.

The prototype of the function call is listed below.

Syntax
`void _PGOPTI_Set_Interval_Prof_Dump(int interval);`

This function is used in non-terminating applications.

The `interval` parameter specifies the time interval at which profile dumping occurs and is measured in milliseconds. For example, if interval is set to 5000, then a profile dump and reset will occur approximately every 5 seconds. The interval is approximate because the time-check controlling the dump and reset is only performed upon entry to any instrumented function in your application.

Setting the interval to zero or a negative number will disable interval profile dumping, and setting a very small value for the interval may cause the instrumented application to spend nearly all of its time dumping profile information. Be sure to set interval to a large enough value so that the application can perform actual work and substantial profile information is collected.

The following example demonstrates one way of using interval profile dumping in non-terminating code.

Example
    #include <stdio.h>
    // The next include is to access
    // _PGOPTI_Set_Interval_Prof_Dump_All
    #include <pgouser.h>
    int returnValue() { return 100; }
    int main() {
      int ans;
      printf("CTRL-C to quit.\n");
      _PGOPTI_Set_Interval_Prof_Dump(5000);
      while (1)
        ans = returnValue();
    }

You can compile the code shown above by entering commands similar to the following:

Operating System | Example
--- | ---
Linux* |
    icc -prof-gen -o intrumented_number number.c
macOS* |
    icc -prof-gen -o intrumented_number number.c
Windows* |
    icl /Qprof-gen /Feinstrumented_number number.c

When compiled, the code shown above will dump profile information a .dyn file about every five seconds until the program is ended.

You can use the profmerge and proforder Tools tool to merge the .dyn files.

## Recommended usage

Call this function at the start of a non-terminating user application to initiate interval profile dumping. Note that an alternative method of initiating interval profile dumping is by setting the environment variable INTEL_PROF_DUMP_INTERVAL to the desired interval value prior to starting the application.

Using interval profile dumping, you should be able to profile a non-terminating application with minimal changes to the application source code.

To control the behavior during dumping, you may use the environment variable INTEL_PROF_DUMP_CUMULATIVE. When `INTEL_PROF_DUMP_INTERVAL` or the API routine `_PGOPTI_SET_INTERVAL_PROF_DUMP` are used without `INTEL_PROF_DUMP_CUMULATIVE`, the counters are reset after each dump, and a new .dyn file will be created containing the data collected during each interval. This may result in a potentially large number of .dyn files that need to be stored and merged together by profmerge.

When `INTEL_PROF_DUMP_CUMULATIVE` is set (to any value), the .dyn file dump will be created at a specified interval as before, but the data will not be reset following the dump, and only the most recent .dyn file will be kept on the file system. This allows for the ability to create a .dyn file for a non-terminating application that contains all the accumulated counts to that point, but without the need for storage and merging of a large set of .dyn files.

Parent topic: PGO API Support