Scala counts the execution time of each job in DataStage log and the total time in a batch job __scala

Source: Internet
Author: User
Package com.x.h Import java.io.File import scala.io.Source/** * Created by xxxxx on 3/7/2017. * Read logs and anlysis the interval time * NOTES://LTSGDB001B/8525691C004D9994/0000035F7480610585255D74006B9E95/5A5A50
    0686EEF43F852580DC000884BB */Object Anlysissnslogs extends app{getthelastedfile def getthelastedfile (): Unit ={ var file = new file ("C:\\users\\ibm_admin\\desktop\\cognos\\datastage\\anlysislogs") for (F <-file.listfiles ()

  {//Here can be added according to the article title timestamp get the latest article add sorting function println (f.getname.tostring.substring (0,8)) Readfiles (f.tostring)} def readfiles (file:string): Unit ={Import scala.collection.mutable//scala lists are similar to arrays, all of which are of the same type, but they are also different:
    The list is immutable, the value cannot be changed once it is defined, and then the list has a recursive structure (that is, a linked table structure) and the array is not.
    var jobName =new Array[string] (30)//Here is the definition of an array or problematic var job = 0 var jobtime =new array[string] (30)//There is a problem defining the array here. var job1 = 0 Val Source = source.fromfile (file) for (line <-source.getlines ()) {if (line.coNtains ("STATUS for JOB:") {//Find the line containing a specific string jobName (Job) = line.toString.substring Job +=1
      } if (Line.contains ("Job elapsed Time=")) {jobtime (JOB1) = line.toString.substring () job1 +=1 } val Lastarray = JobName.toList.zip (jobtime.tolist) for (loop <-0 to Job-1) {//the array defined above has an exception, the There are real array lengths println (Lastarray (loop). _1.tostring + ":" + Lastarray (loop). _2)}//Lastarray.foreach (x => PR Intln (x._1.tostring + ":" + x._2)) var totaltime = 0 for (getTime <-0 to Job1-1) {val times = Jobtime (g ettime). Split (":") TotalTime + + (0). toint * 3600 + times (1). ToInt * (2). ToInt//Calculation total time} p RINTLN ("Total times is:" + totaltime/3600 + ":" + ((totaltime%3600)/60) + ":" + ((totaltime%3600)%60))//Standard Time total T IME Is:6:28:8}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.