private DateTime GetStartTime(DateTime lastEndTime) { DateTime startTime; if (lastEndTime == DateTime.MinValue) { if (string.IsNullOrEmpty(this.applicationType)) { // We are processing Windows Fabric traces. Start retrieving // traces right from the beginning. startTime = DateTime.MinValue; } else { // We are processing application traces. Start retrieving // traces from the earliest time that an instance of this // application was activated. startTime = AppActivationTable.GetEtwTracesStartTimeForApplicationType(this.applicationType); if (startTime.Equals(DateTime.MaxValue)) { // We were unable to retrieve the earliest time that // an instance of this application was activated. So // we'll start processing application traces from a // few minutes ago. startTime = DateTime.UtcNow.AddMinutes(DefaultAppEtwTracesStartTimeOffsetMinutes); this.traceSource.WriteWarning( "Unable to retrieve ETW traces processing start time for application type {0}.", this.applicationType); } } } else { if (string.IsNullOrEmpty(this.applicationType)) { // We are processing Windows Fabric traces. Start retrieving // traces one tick after the timestamp where we left off previously. startTime = lastEndTime.AddTicks(1); } else { // We are processing application traces. Start retrieving // traces from the later of the following timestamps: // #1. The earliest time that an instance of this application was activated. // #2. One tick after the timestamp where we left off previously startTime = AppActivationTable.GetEtwTracesStartTimeForApplicationType(this.applicationType); if (startTime.Equals(DateTime.MaxValue) // We were unable to determine #1 above || (startTime.CompareTo(lastEndTime) <= 0)) { startTime = lastEndTime.AddTicks(1); } } } return(startTime); }
internal void DeleteApplicationInstance(string applicationInstanceId) { AppInstance appInstance; lock (this.applicationInstances) { appInstance = this.applicationInstances[applicationInstanceId]; this.applicationInstances.Remove(applicationInstanceId); } Utility.TraceSource.WriteInfo( TraceType, "Deleting data collector for application instance {0} ...", applicationInstanceId); appInstance.FlushData(); appInstance.Dispose(); AppActivationTable.RemoveRecord(applicationInstanceId); }
internal void CreateApplicationInstance( string applicationInstanceId, DateTime activationTime, AppConfig appConfig, string servicePackageName, ServiceConfig serviceConfig) { if (false == activationTime.Equals(DateTime.MaxValue)) { AppActivationTable.AddRecord(applicationInstanceId, appConfig.ApplicationType, activationTime); } AppInstance appInstance = new AppInstance(applicationInstanceId, appConfig, servicePackageName, serviceConfig, this.diskSpaceManager); lock (this.applicationInstances) { this.applicationInstances[applicationInstanceId] = appInstance; } Utility.TraceSource.WriteInfo( TraceType, "Created data collector for application instance {0}.", applicationInstanceId); }
internal ServicePackageTableManager(AppInstanceManager appInstanceMgr) { this.applicationInstanceManager = appInstanceMgr; this.servicePackageTable = new ServicePackageTable(); // Get the interval at which we need to read ETL files int servicePackageNotificationIntervalSeconds = Utility.GetUnencryptedConfigValue( HostingSectionName, ServicePackageNotificationIntervalInSecondsParamName, DefaultServicePackageNotificationIntervalInSeconds); this.maxServicePackageInactiveTimeSeconds = servicePackageNotificationIntervalSeconds * MaxServicePackageInactiveTimeMultiplier; Utility.TraceSource.WriteInfo( TraceType, "Interval at which we check for inactive service packages: {0} seconds.", servicePackageNotificationIntervalSeconds); Utility.TraceSource.WriteInfo( TraceType, "Maximum time for which a service package can remain inactive before being deleted: {0} seconds.", this.maxServicePackageInactiveTimeSeconds); // Create the folder where the backup files are stored string tableBackupDirectory = Path.Combine( Utility.LogDirectory, AppInstanceDataDirName, AppInstanceTableDirName); FabricDirectory.CreateDirectory(tableBackupDirectory); // Initialize the application activation table AppActivationTable.Initialize(tableBackupDirectory); // Retrieve the file where we last saved the service package table this.tableBackup = new ServicePackageTableBackup( tableBackupDirectory, this.AddOrUpdateServicePackage); // Initialize the service package table from the file that we last saved. if (false == this.tableBackup.Read()) { Utility.TraceSource.WriteError( TraceType, "Unable to initialize service package table from backup file on disk."); } // Initialize the timestamp up to which ETW events can be read Utility.ApplicationEtwTracesEndTime = this.tableBackup.LatestBackupTime.Timestamp; // Compute the directory containing ETL files containing information about // application instances string etlFileDirectory = Path.Combine( Utility.LogDirectory, AppInstanceDataDirName, AppInstanceDataEtlDirName); FabricDirectory.CreateDirectory(etlFileDirectory); #if !DotNetCoreClrLinux // Create the object that reads events from ETL files. this.etlFileReader = new AppInstanceEtlFileDataReader( etlFileDirectory, this.tableBackup, this.AddOrUpdateServicePackage, this.RemoveServicePackage); #endif long inactiveServicePackageScanIntervalMillisec = ((long)servicePackageNotificationIntervalSeconds) * 1000; this.inactiveServicePackageScanTimer = new DcaTimer( InactiveServicePackageScanTimerId, this.MarkInactiveServicePackagesForDeletion, inactiveServicePackageScanIntervalMillisec); this.inactiveServicePackageScanTimer.Start(); }